From d295533e882c02c8c2fa648961ffe7e338faff84 Mon Sep 17 00:00:00 2001 From: owen05 Date: Tue, 9 Nov 2021 21:05:54 +0800 Subject: [PATCH] add new features on cp --- config/rinkeby-config.js | 8 +++--- contracts/CrowdPooling/impl/CP.sol | 12 +++++---- contracts/CrowdPooling/impl/CPFunding.sol | 3 +++ contracts/CrowdPooling/impl/CPStorage.sol | 4 ++- contracts/CrowdPooling/impl/CPVesting.sol | 7 ++++- contracts/CrowdPooling/intf/ICP.sol | 2 +- contracts/Factory/CrowdPoolingFactory.sol | 27 ++++++++++++------- contracts/Factory/UpCrowdPoolingFactory.sol | 28 +++++++++++++------- contracts/SmartRoute/intf/IDODOV2.sol | 5 ++-- contracts/SmartRoute/proxies/DODOCpProxy.sol | 22 +++++++++------ 10 files changed, 75 insertions(+), 43 deletions(-) diff --git a/config/rinkeby-config.js b/config/rinkeby-config.js index 7b4bc06..0c0f43c 100644 --- a/config/rinkeby-config.js +++ b/config/rinkeby-config.js @@ -21,7 +21,7 @@ module.exports = { DPP: "0x604BFaDa2EAC7E011DdF9aA8848b38e8b02aDdD2", DSP: "0xe2C23cBF03930418BF97e173FE3E950aD29fdb06", DPPAdmin: "0x2FF619B4Cfe36b0F92dD933256B1581a3269a5F4", - CP: "0x6850eE8cF963B913a8eC3610B5f128C3100178E5", + CP: "0xce1560Ab8F39918F440C5B4b6B2b95A137F84013", ERC20MineV3: "0xd5Bbb5497d0503a8d0CB5A9410EcFfF840Fe0012", ERC20: "0x7119D1Ec8235bd0a82289fDb1cCAa4bD4D1e0605", CustomERC20: "0xBcCd9698CF3Be0b37d227406699aEaa3D6C413A1", @@ -32,8 +32,8 @@ module.exports = { DVMFactory: "0x17DddEFA0c82E0c850a4Adac2aFE3F1fe977A242", DPPFactory: "0x510b49803E356C750f3a93bA5508C0FFD9f71bDD", DSPFactory: "0xa1ab675cB49BA0DC3F39fA4C20E216572A8dD3c8", - CrowdPoolingFactory: "0xDD43520779dDCfbDe373174Ee36aEaD39771cD4f", - UpCpFactory: "0xb09E91505347234Cb722D67042290f50F1C13749", + CrowdPoolingFactory: "0x45CF2EB0DB78ad56450060557BC8D4F386F826cf", + UpCpFactory: "0x9DbbfFE2C5BA6c931C518199C861ff0b6067c2EB", ERC20Factory: "0x48476599281CB7DD46dbE47264C4594d1d2E19A8", ERC20V2Factory: "0x7A22e361cB74E69B5B1C800A3aAbE3E50e84F4F6", DODOMineV3Registry: "0xeA12A4F762B6D8e2a122847aB1ecF60BB690fEd8", @@ -54,7 +54,7 @@ module.exports = { //Proxy DODOV2Proxy: "0xba001E96AF87bF9d8D0BDA667067A9921FE6d294", DSPProxy: "0x0f6345D1d07C134BB0973AD102F38eA9195F6f78", - CpProxy: "0x2E483CBb9e76fE6543168DEd698d9244EE1ED8Dd", + CpProxy: "0xa2846A259a05b949DE6e3599eE5cFaA818199E9C", DPPProxy: "0x45136c2455Dd2631E31ab884cf167eC618CCf39a", RouteProxy: "0xe2b538a781eB5a115a1359B8f363B9703Fd19dE6", DODOMineV3Proxy: "0xcb15BBb59AC8a4B64A4db9B8d9F66c397d89Bd22", diff --git a/contracts/CrowdPooling/impl/CP.sol b/contracts/CrowdPooling/impl/CP.sol index 8cc4f13..856aff7 100644 --- a/contracts/CrowdPooling/impl/CP.sol +++ b/contracts/CrowdPooling/impl/CP.sol @@ -29,7 +29,7 @@ contract CP is CPVesting { address[] calldata addressList, uint256[] calldata timeLine, uint256[] calldata valueList, - bool isOpenTWAP + bool[] calldata switches //0 isOverCapStop 1 isOpenTWAP ) external { /* Address List @@ -59,9 +59,10 @@ contract CP is CPVesting { 2. phase calm duration 3. freeze duration 4. vesting duration + 5. claim lock duration */ - require(timeLine.length == 5, "LIST_LENGTH_WRONG"); + require(timeLine.length == 6, "LIST_LENGTH_WRONG"); _PHASE_BID_STARTTIME_ = timeLine[0]; _PHASE_BID_ENDTIME_ = _PHASE_BID_STARTTIME_.add(timeLine[1]); @@ -69,7 +70,7 @@ contract CP is CPVesting { _FREEZE_DURATION_ = timeLine[3]; _VESTING_DURATION_ = timeLine[4]; - + _CLAIM_LOCK_DURATION_ = timeLine[5]; require(block.timestamp <= _PHASE_BID_STARTTIME_, "TIMELINE_WRONG"); /* @@ -93,7 +94,8 @@ contract CP is CPVesting { _TOTAL_BASE_ = _BASE_TOKEN_.balanceOf(address(this)); - _IS_OPEN_TWAP_ = isOpenTWAP; + _IS_OVERCAP_STOP = switches[0]; + _IS_OPEN_TWAP_ = switches[1]; require(address(this).balance == _SETTEL_FUND_, "SETTLE_FUND_NOT_MATCH"); } @@ -101,6 +103,6 @@ contract CP is CPVesting { // ============ Version Control ============ function version() virtual external pure returns (string memory) { - return "CP 1.0.0"; + return "CP 1.0.1"; } } diff --git a/contracts/CrowdPooling/impl/CPFunding.sol b/contracts/CrowdPooling/impl/CPFunding.sol index f6cc7d3..df232d3 100644 --- a/contracts/CrowdPooling/impl/CPFunding.sol +++ b/contracts/CrowdPooling/impl/CPFunding.sol @@ -31,6 +31,9 @@ contract CPFunding is CPStorage { modifier isBidderAllow(address bidder) { require(_BIDDER_PERMISSION_.isAllowed(bidder), "BIDDER_NOT_ALLOWED"); + if(_IS_OVERCAP_STOP) { + require(_QUOTE_TOKEN_.balanceOf(address(this)) < _POOL_QUOTE_CAP_, "ALREADY_OVER_CAP"); + } _; } diff --git a/contracts/CrowdPooling/impl/CPStorage.sol b/contracts/CrowdPooling/impl/CPStorage.sol index 6fd73d0..f497427 100644 --- a/contracts/CrowdPooling/impl/CPStorage.sol +++ b/contracts/CrowdPooling/impl/CPStorage.sol @@ -23,6 +23,7 @@ contract CPStorage is InitializableOwnable, ReentrancyGuard { uint256 internal constant _SETTLEMENT_EXPIRE_ = 86400 * 7; uint256 internal constant _SETTEL_FUND_ = 200 finney; bool public _IS_OPEN_TWAP_ = false; + bool public _IS_OVERCAP_STOP = false; // ============ Timeline ============ @@ -68,12 +69,13 @@ contract CPStorage is InitializableOwnable, ReentrancyGuard { uint256 public _K_; uint256 public _I_; - // ============ LP Token Vesting ============ + // ============ LP Token Vesting && Claim Params ============ uint256 public _TOTAL_LP_AMOUNT_; uint256 public _FREEZE_DURATION_; uint256 public _VESTING_DURATION_; uint256 public _CLIFF_RATE_; + uint256 public _CLAIM_LOCK_DURATION_; // ============ Modifiers ============ diff --git a/contracts/CrowdPooling/impl/CPVesting.sol b/contracts/CrowdPooling/impl/CPVesting.sol index 2f9373c..86a7c67 100644 --- a/contracts/CrowdPooling/impl/CPVesting.sol +++ b/contracts/CrowdPooling/impl/CPVesting.sol @@ -40,6 +40,11 @@ contract CPVesting is CPFunding { _; } + modifier afterClaimLockDuration() { + require(_SETTLED_ && block.timestamp >= _SETTLED_TIME_.add(_CLAIM_LOCK_DURATION_), "CLAIM_LOCKED"); + _; + } + modifier afterFreeze() { require(_SETTLED_ && block.timestamp >= _SETTLED_TIME_.add(_FREEZE_DURATION_), "FREEZED"); _; @@ -47,7 +52,7 @@ contract CPVesting is CPFunding { // ============ Bidder Functions ============ - function bidderClaim(address to,bytes calldata data) external afterSettlement { + function bidderClaim(address to,bytes calldata data) external afterClaimLockDuration { require(!_CLAIMED_[msg.sender], "ALREADY_CLAIMED"); _CLAIMED_[msg.sender] = true; diff --git a/contracts/CrowdPooling/intf/ICP.sol b/contracts/CrowdPooling/intf/ICP.sol index 5499461..469ffd2 100644 --- a/contracts/CrowdPooling/intf/ICP.sol +++ b/contracts/CrowdPooling/intf/ICP.sol @@ -13,7 +13,7 @@ interface ICP { address[] calldata addressList, uint256[] calldata timeLine, uint256[] calldata valueList, - bool isOpenTWAP + bool[] calldata switches ) external; function bid(address to) external; diff --git a/contracts/Factory/CrowdPoolingFactory.sol b/contracts/Factory/CrowdPoolingFactory.sol index 436b378..bb2c3fb 100644 --- a/contracts/Factory/CrowdPoolingFactory.sol +++ b/contracts/Factory/CrowdPoolingFactory.sol @@ -41,6 +41,7 @@ contract CrowdPoolingFactory is InitializableOwnable { uint256 public _K_ = 0; uint256 public _CLIFF_RATE_ = 10**18; + mapping(address => address) liquidityProtectWhitelist; // ============ Registry ============ @@ -52,6 +53,7 @@ contract CrowdPoolingFactory is InitializableOwnable { // ============ modifiers =========== modifier valueCheck( + address creator, address cpAddress, address baseToken, uint256[] memory timeLine, @@ -64,7 +66,9 @@ contract CrowdPoolingFactory is InitializableOwnable { uint256 baseTokenBalance = IERC20(baseToken).balanceOf(cpAddress); require(valueList[0].mul(100) <= baseTokenBalance.mul(valueList[2]).div(10**18).mul(_CAP_RATIO_),"CP_FACTORY : QUOTE_CAP_INVALID"); - require(timeLine[3]>= _FREEZE_DURATION_, "CP_FACTORY : FREEZE_DURATION_INVALID"); + if(liquidityProtectWhitelist[creator] != baseToken) { + require(timeLine[3]>= _FREEZE_DURATION_, "CP_FACTORY : FREEZE_DURATION_INVALID"); + } _; } @@ -102,18 +106,17 @@ contract CrowdPoolingFactory is InitializableOwnable { function initCrowdPooling( address cpAddress, address creator, - address baseToken, - address quoteToken, + address[] memory tokens,//0 baseToken 1 quoteToken uint256[] memory timeLine, uint256[] memory valueList, - bool isOpenTWAP - ) external valueCheck(cpAddress,baseToken,timeLine,valueList) { + bool[] memory switches + ) external valueCheck(creator,cpAddress,tokens[0],timeLine,valueList) { { address[] memory addressList = new address[](7); addressList[0] = creator; addressList[1] = _DEFAULT_MAINTAINER_; - addressList[2] = baseToken; - addressList[3] = quoteToken; + addressList[2] = tokens[0]; + addressList[3] = tokens[1]; addressList[4] = _DEFAULT_PERMISSION_MANAGER_; addressList[5] = _DEFAULT_MT_FEE_RATE_MODEL_; addressList[6] = _DVM_FACTORY_; @@ -122,14 +125,14 @@ contract CrowdPoolingFactory is InitializableOwnable { addressList, timeLine, valueList, - isOpenTWAP + switches ); } - _REGISTRY_[baseToken][quoteToken].push(cpAddress); + _REGISTRY_[tokens[0]][tokens[1]].push(cpAddress); _USER_REGISTRY_[creator].push(cpAddress); - emit NewCP(baseToken, quoteToken, creator, cpAddress); + emit NewCP(tokens[0], tokens[1], creator, cpAddress); } // ============ View Functions ============ @@ -159,6 +162,10 @@ contract CrowdPoolingFactory is InitializableOwnable { } // ============ Owner Functions ============ + + function setLiquidityProtectWhitelist(address creator, address baseToken) external onlyOwner { + liquidityProtectWhitelist[creator] = baseToken; + } function updateCPTemplate(address _newCPTemplate) external onlyOwner { _CP_TEMPLATE_ = _newCPTemplate; diff --git a/contracts/Factory/UpCrowdPoolingFactory.sol b/contracts/Factory/UpCrowdPoolingFactory.sol index 4cc9ae9..ce1ac5b 100644 --- a/contracts/Factory/UpCrowdPoolingFactory.sol +++ b/contracts/Factory/UpCrowdPoolingFactory.sol @@ -38,6 +38,7 @@ contract UpCrowdPoolingFactory is InitializableOwnable { uint256 public _VEST_DURATION_ = 0; uint256 public _CLIFF_RATE_ = 10**18; + mapping(address => address) liquidityProtectWhitelist; // ============ Registry ============ @@ -49,6 +50,7 @@ contract UpCrowdPoolingFactory is InitializableOwnable { // ============ modifiers =========== modifier valueCheck( + address creator, address cpAddress, address baseToken, uint256[] memory timeLine, @@ -57,7 +59,10 @@ contract UpCrowdPoolingFactory is InitializableOwnable { require(timeLine[2] <= _CALM_DURATION_, "CP_FACTORY : PHASE_CALM_DURATION_INVALID"); require(timeLine[4] == _VEST_DURATION_, "CP_FACTORY : VEST_DURATION_INVALID"); require(valueList[3] == _CLIFF_RATE_, "CP_FACTORY : CLIFF_RATE_INVALID"); - require(timeLine[3] >= _FREEZE_DURATION_, "CP_FACTORY : FREEZE_DURATION_INVALID"); + + if(liquidityProtectWhitelist[creator] != baseToken) { + require(timeLine[3]>= _FREEZE_DURATION_, "CP_FACTORY : FREEZE_DURATION_INVALID"); + } _; } @@ -95,18 +100,17 @@ contract UpCrowdPoolingFactory is InitializableOwnable { function initCrowdPooling( address cpAddress, address creator, - address baseToken, - address quoteToken, + address[] memory tokens,//0 baseToken 1 quoteToken uint256[] memory timeLine, uint256[] memory valueList, - bool isOpenTWAP - ) external valueCheck(cpAddress,baseToken,timeLine,valueList) { + bool[] memory switches + ) external valueCheck(creator,cpAddress,tokens[0],timeLine,valueList) { { address[] memory addressList = new address[](7); addressList[0] = creator; addressList[1] = _DEFAULT_MAINTAINER_; - addressList[2] = baseToken; - addressList[3] = quoteToken; + addressList[2] = tokens[0]; + addressList[3] = tokens[1]; addressList[4] = _DEFAULT_PERMISSION_MANAGER_; addressList[5] = _DEFAULT_MT_FEE_RATE_MODEL_; addressList[6] = _DVM_FACTORY_; @@ -117,14 +121,14 @@ contract UpCrowdPoolingFactory is InitializableOwnable { addressList, timeLine, valueList, - isOpenTWAP + switches ); } - _REGISTRY_[baseToken][quoteToken].push(cpAddress); + _REGISTRY_[tokens[0]][tokens[1]].push(cpAddress); _USER_REGISTRY_[creator].push(cpAddress); - emit NewCP(baseToken, quoteToken, creator, cpAddress); + emit NewCP(tokens[0], tokens[1], creator, cpAddress); } // ============ View Functions ============ @@ -154,6 +158,10 @@ contract UpCrowdPoolingFactory is InitializableOwnable { } // ============ Owner Functions ============ + + function setLiquidityProtectWhitelist(address creator, address baseToken) external onlyOwner { + liquidityProtectWhitelist[creator] = baseToken; + } function updateCPTemplate(address _newCPTemplate) external onlyOwner { _CP_TEMPLATE_ = _newCPTemplate; diff --git a/contracts/SmartRoute/intf/IDODOV2.sol b/contracts/SmartRoute/intf/IDODOV2.sol index 3038bab..9c9c688 100644 --- a/contracts/SmartRoute/intf/IDODOV2.sol +++ b/contracts/SmartRoute/intf/IDODOV2.sol @@ -87,11 +87,10 @@ interface IDODOV2 { function initCrowdPooling( address cpAddress, address creator, - address baseToken, - address quoteToken, + address[] memory tokens, uint256[] memory timeLine, uint256[] memory valueList, - bool isOpenTWAP + bool[] memory switches ) external; function bid(address to) external; diff --git a/contracts/SmartRoute/proxies/DODOCpProxy.sol b/contracts/SmartRoute/proxies/DODOCpProxy.sol index 3a7811b..5615d69 100644 --- a/contracts/SmartRoute/proxies/DODOCpProxy.sol +++ b/contracts/SmartRoute/proxies/DODOCpProxy.sol @@ -63,7 +63,7 @@ contract DODOCpProxy is ReentrancyGuard { uint256 baseInAmount, uint256[] memory timeLine, uint256[] memory valueList, - bool isOpenTWAP, + bool[] memory switches, uint256 deadLine ) external payable preventReentrant judgeExpired(deadLine) returns (address payable newUpCrowdPooling) { address _baseToken = baseToken; @@ -82,14 +82,17 @@ contract DODOCpProxy is ReentrancyGuard { (bool success, ) = newUpCrowdPooling.call{value: msg.value}(""); require(success, "DODOCpProxy: Transfer failed"); + address[] memory tokens = new address[](2); + tokens[0] = _baseToken; + tokens[1] = _quoteToken; + IDODOV2(_UPCP_FACTORY_).initCrowdPooling( newUpCrowdPooling, msg.sender, - _baseToken, - _quoteToken, + tokens, timeLine, valueList, - isOpenTWAP + switches ); } @@ -101,7 +104,7 @@ contract DODOCpProxy is ReentrancyGuard { uint256 baseInAmount, uint256[] memory timeLine, uint256[] memory valueList, - bool isOpenTWAP, + bool[] memory switches, uint256 deadLine ) external payable preventReentrant judgeExpired(deadLine) returns (address payable newCrowdPooling) { address _baseToken = baseToken; @@ -120,14 +123,17 @@ contract DODOCpProxy is ReentrancyGuard { (bool success, ) = newCrowdPooling.call{value: msg.value}(""); require(success, "DODOCpProxy: Transfer failed"); + address[] memory tokens = new address[](2); + tokens[0] = _baseToken; + tokens[1] = _quoteToken; + IDODOV2(_CP_FACTORY_).initCrowdPooling( newCrowdPooling, msg.sender, - _baseToken, - _quoteToken, + tokens, timeLine, valueList, - isOpenTWAP + switches ); }