From 94ba7fbd21adddcc7ecdcea467dd8efd961098ec Mon Sep 17 00:00:00 2001 From: owen05 Date: Thu, 4 Mar 2021 15:28:42 +0800 Subject: [PATCH] add upCpFactory --- .../SmartRoute => archive}/DODOV1Proxy01.sol | 0 .../SmartRoute => archive}/DODOV1Proxy02.sol | 0 .../SmartRoute => archive}/DODOV1Proxy03.sol | 0 .../SmartRoute => archive}/DODOV1Proxy04.sol | 0 .../SmartRoute => archive}/DODOV2Proxy01.sol | 0 contracts/Factory/UpCrowdPoolingFactory.sol | 186 ++++++++++++++++++ deploy-detail-periphery.txt | 12 ++ migrations/4_deploy_periphery.js | 29 ++- truffle-config.js | 5 +- 9 files changed, 229 insertions(+), 3 deletions(-) rename {contracts/SmartRoute => archive}/DODOV1Proxy01.sol (100%) rename {contracts/SmartRoute => archive}/DODOV1Proxy02.sol (100%) rename {contracts/SmartRoute => archive}/DODOV1Proxy03.sol (100%) rename {contracts/SmartRoute => archive}/DODOV1Proxy04.sol (100%) rename {contracts/SmartRoute => archive}/DODOV2Proxy01.sol (100%) create mode 100644 contracts/Factory/UpCrowdPoolingFactory.sol diff --git a/contracts/SmartRoute/DODOV1Proxy01.sol b/archive/DODOV1Proxy01.sol similarity index 100% rename from contracts/SmartRoute/DODOV1Proxy01.sol rename to archive/DODOV1Proxy01.sol diff --git a/contracts/SmartRoute/DODOV1Proxy02.sol b/archive/DODOV1Proxy02.sol similarity index 100% rename from contracts/SmartRoute/DODOV1Proxy02.sol rename to archive/DODOV1Proxy02.sol diff --git a/contracts/SmartRoute/DODOV1Proxy03.sol b/archive/DODOV1Proxy03.sol similarity index 100% rename from contracts/SmartRoute/DODOV1Proxy03.sol rename to archive/DODOV1Proxy03.sol diff --git a/contracts/SmartRoute/DODOV1Proxy04.sol b/archive/DODOV1Proxy04.sol similarity index 100% rename from contracts/SmartRoute/DODOV1Proxy04.sol rename to archive/DODOV1Proxy04.sol diff --git a/contracts/SmartRoute/DODOV2Proxy01.sol b/archive/DODOV2Proxy01.sol similarity index 100% rename from contracts/SmartRoute/DODOV2Proxy01.sol rename to archive/DODOV2Proxy01.sol diff --git a/contracts/Factory/UpCrowdPoolingFactory.sol b/contracts/Factory/UpCrowdPoolingFactory.sol new file mode 100644 index 0000000..2e238f4 --- /dev/null +++ b/contracts/Factory/UpCrowdPoolingFactory.sol @@ -0,0 +1,186 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; +import {ICloneFactory} from "../lib/CloneFactory.sol"; +import {ICP} from "../CrowdPooling/intf/ICP.sol"; +import {SafeMath} from "../lib/SafeMath.sol"; +import {IERC20} from "../intf/IERC20.sol"; +import {DecimalMath} from "../lib/DecimalMath.sol"; + +/** + * @title UpCrowdPoolingFacotry + * @author DODO Breeder + * + * @notice Create And Register vary price CP Pools + */ +contract UpCrowdPoolingFactory is InitializableOwnable { + using SafeMath for uint256; + // ============ Templates ============ + + address public immutable _CLONE_FACTORY_; + address public immutable _DVM_FACTORY_; + address public immutable _DEFAULT_MAINTAINER_; + address public immutable _DEFAULT_MT_FEE_RATE_MODEL_; + address public immutable _DEFAULT_PERMISSION_MANAGER_; + address public _CP_TEMPLATE_; + + // ============ Settings ============= + + uint256 public _FREEZE_DURATION_ = 30 days; + uint256 public _CALM_DURATION_ = 0; + uint256 public _VEST_DURATION_ = 0; + uint256 public _K_ = 0; + uint256 public _CLIFF_RATE_ = 10**18; + + + // ============ Registry ============ + + // base -> quote -> CP address list + mapping(address => mapping(address => address[])) public _REGISTRY_; + // creator -> CP address list + mapping(address => address[]) public _USER_REGISTRY_; + + // ============ modifiers =========== + + modifier valueCheck( + address cpAddress, + address baseToken, + uint256[] memory timeLine, + uint256[] memory valueList) + { + require(timeLine[2] == _CALM_DURATION_, "CP_FACTORY : PHASE_CALM_DURATION_INVALID"); + require(timeLine[4] == _VEST_DURATION_, "CP_FACTORY : VEST_DURATION_INVALID"); + require(valueList[1] == _K_, "CP_FACTORY : K_INVALID"); + require(valueList[3] == _CLIFF_RATE_, "CP_FACTORY : CLIFF_RATE_INVALID"); + require(timeLine[3]>= _FREEZE_DURATION_, "CP_FACTORY : FREEZE_DURATION_INVALID"); + _; + } + + // ============ Events ============ + + event NewCP( + address baseToken, + address quoteToken, + address creator, + address cp + ); + + constructor( + address cloneFactory, + address cpTemplate, + address dvmFactory, + address defaultMaintainer, + address defaultMtFeeRateModel, + address defaultPermissionManager + ) public { + _CLONE_FACTORY_ = cloneFactory; + _CP_TEMPLATE_ = cpTemplate; + _DVM_FACTORY_ = dvmFactory; + _DEFAULT_MAINTAINER_ = defaultMaintainer; + _DEFAULT_MT_FEE_RATE_MODEL_ = defaultMtFeeRateModel; + _DEFAULT_PERMISSION_MANAGER_ = defaultPermissionManager; + } + + // ============ Functions ============ + + function createCrowdPooling() external returns (address newCrowdPooling) { + newCrowdPooling = ICloneFactory(_CLONE_FACTORY_).clone(_CP_TEMPLATE_); + } + + function initCrowdPooling( + address cpAddress, + address creator, + address baseToken, + address quoteToken, + uint256[] memory timeLine, + uint256[] memory valueList, + bool isOpenTWAP + ) external valueCheck(cpAddress,baseToken,timeLine,valueList) { + { + address[] memory addressList = new address[](7); + addressList[0] = creator; + addressList[1] = _DEFAULT_MAINTAINER_; + addressList[2] = baseToken; + addressList[3] = quoteToken; + addressList[4] = _DEFAULT_PERMISSION_MANAGER_; + addressList[5] = _DEFAULT_MT_FEE_RATE_MODEL_; + addressList[6] = _DVM_FACTORY_; + + if(valueList[0] == 0) valueList[0] = uint112(-1); + + ICP(cpAddress).init( + addressList, + timeLine, + valueList, + isOpenTWAP + ); + } + + _REGISTRY_[baseToken][quoteToken].push(cpAddress); + _USER_REGISTRY_[creator].push(cpAddress); + + emit NewCP(baseToken, quoteToken, creator, cpAddress); + } + + // ============ View Functions ============ + + function getCrowdPooling(address baseToken, address quoteToken) + external + view + returns (address[] memory pools) + { + return _REGISTRY_[baseToken][quoteToken]; + } + + function getCrowdPoolingBidirection(address token0, address token1) + external + view + returns (address[] memory baseToken0Pools, address[] memory baseToken1Pools) + { + return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]); + } + + function getCrowdPoolingByUser(address user) + external + view + returns (address[] memory pools) + { + return _USER_REGISTRY_[user]; + } + + // ============ Owner Functions ============ + + function updateCPTemplate(address _newCPTemplate) external onlyOwner { + _CP_TEMPLATE_ = _newCPTemplate; + } + + function setFreezeDuration(uint256 _newFreeDuration) public onlyOwner { + _FREEZE_DURATION_ = _newFreeDuration; + } + + function setCalmDuration(uint256 _newCalmDuration) public onlyOwner { + _CALM_DURATION_ = _newCalmDuration; + } + + function setVestDuration(uint256 _newVestDuration) public onlyOwner { + _VEST_DURATION_ = _newVestDuration; + } + + function setK(uint256 _newK) public onlyOwner { + require(_newK <= 10**18, "CP_FACTORY : INVALID"); + _K_ = _newK; + } + + function setCliffRate(uint256 _newCliffRate) public onlyOwner { + require(_newCliffRate <= 10**18, "CP_FACTORY : INVALID"); + _CLIFF_RATE_ = _newCliffRate; + } +} diff --git a/deploy-detail-periphery.txt b/deploy-detail-periphery.txt index 8f9419b..ced498b 100644 --- a/deploy-detail-periphery.txt +++ b/deploy-detail-periphery.txt @@ -178,3 +178,15 @@ network type: mbdev Deploy time: 2021/3/3 下午11:03:01 Deploy type: WETH9 WETH9Address: 0x42e2EE7Ba8975c473157634Ac2AF4098190fc741 +==================================================== +network type: bsclive +Deploy time: 2021/3/4 下午2:17:56 +Deploy type: UpCrowdPoolingFactory +UpCrowdPoolingFactory address: 0x69f52AC40185A2A005D49114F0B77b7bA856F0a0 +Init UpCpFactory Tx: 0x64d621c61b16c60523bc3b9afadd7dc50b78ecbf038f2a66ee28cf53729f330b +==================================================== +network type: live +Deploy time: 2021/3/4 下午3:10:50 +Deploy type: UpCrowdPoolingFactory +UpCrowdPoolingFactory address: 0xD734a08359296e44b87F4d404135cd0832A7a363 +Init UpCpFactory Tx: 0x58798e736d419ef9ce9753fc32a847d2a5a65957623a83e3d258ef2a1c9f8ca8 diff --git a/migrations/4_deploy_periphery.js b/migrations/4_deploy_periphery.js index 5a831a6..01ce19b 100644 --- a/migrations/4_deploy_periphery.js +++ b/migrations/4_deploy_periphery.js @@ -11,6 +11,7 @@ const DODOMine = artifacts.require("DODOMine"); const FeeRateImpl = artifacts.require("FeeRateImpl"); const WETH9 = artifacts.require("WETH9"); const DODOToken = artifacts.require("DODOToken"); +const UpCrowdPoolingFactory = artifacts.require("UpCrowdPoolingFactory"); module.exports = async (deployer, network, accounts) => { let CONFIG = GetConfig(network, accounts) @@ -24,8 +25,34 @@ module.exports = async (deployer, network, accounts) => { let vDODOTokenAddress = CONFIG.vDODOToken; let dodoTeam = CONFIG.dodoTeam; - let multiSigAddress = CONFIG.multiSigAddress; + let CloneFactoryAddress = CONFIG.CloneFactory; + let DefaultMtFeeRateAddress = CONFIG.FeeRateModel; + let DefaultPermissionAddress = CONFIG.PermissionManager; + let CpTemplateAddress = CONFIG.CP; + let DvmFactoryAddress = CONFIG.DVMFactory; + let multiSigAddress = CONFIG.multiSigAddress; + let defaultMaintainer = CONFIG.defaultMaintainer; + + if (deploySwitch.UpCP) { + logger.log("===================================================="); + logger.log("network type: " + network); + logger.log("Deploy time: " + new Date().toLocaleString()); + logger.log("Deploy type: UpCrowdPoolingFactory"); + await deployer.deploy( + UpCrowdPoolingFactory, + CloneFactoryAddress, + CpTemplateAddress, + DvmFactoryAddress, + defaultMaintainer, + DefaultMtFeeRateAddress, + DefaultPermissionAddress + ); + logger.log("UpCrowdPoolingFactory address: ", UpCrowdPoolingFactory.address); + const UpCpFactoryInstance = await UpCrowdPoolingFactory.at(UpCrowdPoolingFactory.address); + var tx = await UpCpFactoryInstance.initOwner(multiSigAddress); + logger.log("Init UpCpFactory Tx:", tx.tx); + } if (deploySwitch.FEERATEIMPL) { logger.log("===================================================="); diff --git a/truffle-config.js b/truffle-config.js index 1a60260..78001ae 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -48,7 +48,8 @@ module.exports = { MINE: false, FEERATEIMPL: false, WETH: false, - DODO: false + DODO: false, + UpCP: false }, networks: { @@ -83,7 +84,7 @@ module.exports = { return new HDWalletProvider(privKey, "https://mainnet.infura.io/v3/" + infuraId); }, gas: 6000000, - gasPrice: 120000000000, + gasPrice: 90000000000, network_id: 1, skipDryRun: true },