From a1a51d9b5ad1222cda59bb3dcd7c5c354a3a772c Mon Sep 17 00:00:00 2001 From: tracy <25892474+traceurl@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:27:46 +0800 Subject: [PATCH] add global quota to cp init --- contracts/DODOFee/FeeRateDIP3Impl.sol | 17 ++++++++++++++++- contracts/Factory/CrowdPoolingFactory.sol | 10 +++++++++- contracts/SmartRoute/proxies/DODOCpProxy.sol | 6 ++++-- contracts/lib/FeeRateModel.sol | 5 +++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/contracts/DODOFee/FeeRateDIP3Impl.sol b/contracts/DODOFee/FeeRateDIP3Impl.sol index 380c191..0a45a83 100644 --- a/contracts/DODOFee/FeeRateDIP3Impl.sol +++ b/contracts/DODOFee/FeeRateDIP3Impl.sol @@ -49,11 +49,16 @@ contract FeeRateDIP3Impl is InitializableOwnable { mapping(address => CPPoolInfo) cpPools; mapping(address => uint256) public specPoolList; + mapping (address => bool) public isAdminListed; + // ============ Events ============= + event AddAdmin(address admin); + event RemoveAdmin(address admin); // ============ Ownable Functions ============ - function addCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external onlyOwner { + function addCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external { + require(isAdminListed[msg.sender], "ACCESS_DENIED"); CPPoolInfo memory cpPoolInfo = CPPoolInfo({ quoteToken: quoteToken, feeAddr: feeAddr, @@ -79,6 +84,16 @@ contract FeeRateDIP3Impl is InitializableOwnable { specPoolList[poolAddr] = mtFeeRate; } + function addAdminList (address userAddr) external onlyOwner { + isAdminListed[userAddr] = true; + emit AddAdmin(userAddr); + } + + function removeAdminList (address userAddr) external onlyOwner { + isAdminListed[userAddr] = false; + emit RemoveAdmin(userAddr); + } + // ============ View Functions ============ function getFeeRate(address pool, address user) external view returns (uint256) { diff --git a/contracts/Factory/CrowdPoolingFactory.sol b/contracts/Factory/CrowdPoolingFactory.sol index d56cfdd..267793d 100644 --- a/contracts/Factory/CrowdPoolingFactory.sol +++ b/contracts/Factory/CrowdPoolingFactory.sol @@ -15,6 +15,11 @@ import {SafeMath} from "../lib/SafeMath.sol"; import {IERC20} from "../intf/IERC20.sol"; import {DecimalMath} from "../lib/DecimalMath.sol"; +interface IFeeRateModel { + function getFeeRate(address trader) external view returns (uint256); + function addCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external; +} + /** * @title CrowdPoolingFacotry * @author DODO Breeder @@ -106,7 +111,8 @@ contract CrowdPoolingFactory is InitializableOwnable { address[] memory tokens,//0 baseToken 1 quoteToken uint256[] memory timeLine, uint256[] memory valueList, - bool[] memory switches + bool[] memory switches, + int globalQuota ) external valueCheck(cpAddress,tokens[0],timeLine,valueList) { { address[] memory addressList = new address[](7); @@ -124,6 +130,8 @@ contract CrowdPoolingFactory is InitializableOwnable { valueList, switches ); + + IFeeRateModel(_DEFAULT_MT_FEE_RATE_MODEL_).addCpPoolInfo(cpAddress, tokens[1], globalQuota, address(0), address(0)); } _REGISTRY_[tokens[0]][tokens[1]].push(cpAddress); diff --git a/contracts/SmartRoute/proxies/DODOCpProxy.sol b/contracts/SmartRoute/proxies/DODOCpProxy.sol index 9912fa8..ee1790a 100644 --- a/contracts/SmartRoute/proxies/DODOCpProxy.sol +++ b/contracts/SmartRoute/proxies/DODOCpProxy.sol @@ -61,7 +61,8 @@ contract DODOCpProxy is ReentrancyGuard { uint256[] memory timeLine, uint256[] memory valueList, bool[] memory switches, - uint256 deadLine + uint256 deadLine, + int globalQuota ) external payable preventReentrant judgeExpired(deadLine) returns (address payable newCrowdPooling) { address _baseToken = baseToken; address _quoteToken = quoteToken == _ETH_ADDRESS_ ? _WETH_ : quoteToken; @@ -89,7 +90,8 @@ contract DODOCpProxy is ReentrancyGuard { tokens, timeLine, valueList, - switches + switches, + globalQuota ); } diff --git a/contracts/lib/FeeRateModel.sol b/contracts/lib/FeeRateModel.sol index e64387d..551a5c1 100644 --- a/contracts/lib/FeeRateModel.sol +++ b/contracts/lib/FeeRateModel.sol @@ -12,6 +12,7 @@ import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; interface IFeeRateImpl { function getFeeRate(address pool, address trader) external view returns (uint256); + function addCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external; } interface IFeeRateModel { @@ -30,4 +31,8 @@ contract FeeRateModel is InitializableOwnable { return 0; return IFeeRateImpl(feeRateImpl).getFeeRate(msg.sender,trader); } + + function addCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external { + IFeeRateImpl(feeRateImpl).addCpPoolInfo(cpPool, quoteToken, globalQuota, feeAddr, quotaAddr); + } }