Files
dodo-contractV2/contracts/CrowdPooling/impl/CP.sol

118 lines
3.2 KiB
Solidity
Raw Normal View History

2020-12-12 15:53:42 +08:00
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {CPVesting} from "./CPVesting.sol";
import {IERC20} from "../../intf/IERC20.sol";
import {IPermissionManager} from "../../lib/PermissionManager.sol";
import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
import {SafeMath} from "../../lib/SafeMath.sol";
/**
* @title DODO CrowdPooling
* @author DODO Breeder
*
* @notice CrowdPooling initialization
*/
2020-12-12 15:53:42 +08:00
contract CP is CPVesting {
using SafeMath for uint256;
2021-12-05 11:19:11 +08:00
receive() external payable {
require(_INITIALIZED_ == false, "WE_NOT_SAVE_ETH_AFTER_INIT");
}
2020-12-30 17:05:31 +08:00
2020-12-12 15:53:42 +08:00
function init(
address[] calldata addressList,
uint256[] calldata timeLine,
2021-01-19 17:10:46 +08:00
uint256[] calldata valueList,
2021-11-09 21:05:54 +08:00
bool[] calldata switches //0 isOverCapStop 1 isOpenTWAP
2020-12-12 15:53:42 +08:00
) external {
/*
Address List
0. owner
1. maintainer
2. baseToken
3. quoteToken
4. permissionManager
5. feeRateModel
6. poolFactory
*/
2020-12-13 17:47:47 +08:00
require(addressList.length == 7, "LIST_LENGTH_WRONG");
2020-12-12 15:53:42 +08:00
initOwner(addressList[0]);
_MAINTAINER_ = addressList[1];
_BASE_TOKEN_ = IERC20(addressList[2]);
_QUOTE_TOKEN_ = IERC20(addressList[3]);
_BIDDER_PERMISSION_ = IPermissionManager(addressList[4]);
_MT_FEE_RATE_MODEL_ = IFeeRateModel(addressList[5]);
_POOL_FACTORY_ = addressList[6];
/*
Time Line
0. phase bid starttime
1. phase bid duration
2. phase calm duration
2020-12-18 18:31:45 +08:00
3. freeze duration
4. vesting duration
2021-11-29 17:19:41 +08:00
5. claim freeze duration
6. claim vesting duration
2020-12-12 15:53:42 +08:00
*/
2021-11-29 17:19:41 +08:00
require(timeLine.length == 7, "LIST_LENGTH_WRONG");
2020-12-12 15:53:42 +08:00
_PHASE_BID_STARTTIME_ = timeLine[0];
_PHASE_BID_ENDTIME_ = _PHASE_BID_STARTTIME_.add(timeLine[1]);
_PHASE_CALM_ENDTIME_ = _PHASE_BID_ENDTIME_.add(timeLine[2]);
2020-12-18 18:31:45 +08:00
_FREEZE_DURATION_ = timeLine[3];
_VESTING_DURATION_ = timeLine[4];
2021-11-29 17:19:41 +08:00
_TOKEN_CLAIM_DURATION_ = timeLine[5];
_TOKEN_VESTING_DURATION_ = timeLine[6];
2020-12-13 17:47:47 +08:00
require(block.timestamp <= _PHASE_BID_STARTTIME_, "TIMELINE_WRONG");
2020-12-12 15:53:42 +08:00
/*
Value List
0. pool quote cap
2020-12-18 18:31:45 +08:00
1. k
2. i
2021-11-29 17:19:41 +08:00
3. lp cliff rate
4. base token cliff rate
2021-12-02 16:15:22 +08:00
5. lp fee rate
2020-12-12 15:53:42 +08:00
*/
2021-12-02 16:15:22 +08:00
require(valueList.length == 6, "LIST_LENGTH_WRONG");
2020-12-12 15:53:42 +08:00
_POOL_QUOTE_CAP_ = valueList[0];
2020-12-18 18:31:45 +08:00
_K_ = valueList[1];
_I_ = valueList[2];
_CLIFF_RATE_ = valueList[3];
2021-11-29 17:19:41 +08:00
_TOKEN_CLIFF_RATE_ = valueList[4];
2021-12-02 16:15:22 +08:00
_POOL_FEE_RATE_ = valueList[5];
2020-12-12 15:53:42 +08:00
2020-12-18 16:08:02 +08:00
require(_I_ > 0 && _I_ <= 1e36, "I_VALUE_WRONG");
require(_K_ <= 1e18, "K_VALUE_WRONG");
require(_CLIFF_RATE_ <= 1e18, "CLIFF_RATE_WRONG");
2021-11-29 17:19:41 +08:00
require(_TOKEN_CLIFF_RATE_ <= 1e18, "TOKEN_CLIFF_RATE_WRONG");
2020-12-13 17:47:47 +08:00
2020-12-12 15:53:42 +08:00
_TOTAL_BASE_ = _BASE_TOKEN_.balanceOf(address(this));
2020-12-30 17:05:31 +08:00
2021-11-09 21:05:54 +08:00
_IS_OVERCAP_STOP = switches[0];
_IS_OPEN_TWAP_ = switches[1];
2021-01-19 17:10:46 +08:00
2020-12-30 17:05:31 +08:00
require(address(this).balance == _SETTEL_FUND_, "SETTLE_FUND_NOT_MATCH");
2020-12-12 15:53:42 +08:00
}
2021-06-28 23:20:15 +08:00
// ============ Version Control ============
function version() virtual external pure returns (string memory) {
2021-12-05 11:19:11 +08:00
return "CP 2.0.0";
2021-06-28 23:20:15 +08:00
}
2020-12-12 15:53:42 +08:00
}