From 25525f87ee9aed98292bfa16e390d8ce12698c4e Mon Sep 17 00:00:00 2001 From: owen05 Date: Thu, 25 Feb 2021 21:34:58 +0800 Subject: [PATCH] update cp quota --- contracts/{lib => DODOFee}/FeeRateImpl.sol | 71 ++++++++++++---------- contracts/DODOFee/vDODOQuota.sol | 34 +++++++++++ deploy-detail-v2.0.txt | 66 ++++++++++++-------- kovan-mock-v2.0.txt | 7 +++ migrations/3_deploy_v2.js | 30 +++++++++ migrations/4_deploy_v2_mock.js | 36 +++++++---- truffle-config.js | 9 ++- 7 files changed, 184 insertions(+), 69 deletions(-) rename contracts/{lib => DODOFee}/FeeRateImpl.sol (53%) create mode 100644 contracts/DODOFee/vDODOQuota.sol diff --git a/contracts/lib/FeeRateImpl.sol b/contracts/DODOFee/FeeRateImpl.sol similarity index 53% rename from contracts/lib/FeeRateImpl.sol rename to contracts/DODOFee/FeeRateImpl.sol index 9462129..51af2b9 100644 --- a/contracts/lib/FeeRateImpl.sol +++ b/contracts/DODOFee/FeeRateImpl.sol @@ -8,9 +8,9 @@ pragma solidity 0.6.9; pragma experimental ABIEncoderV2; -import {InitializableOwnable} from "./InitializableOwnable.sol"; +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; import {IERC20} from "../intf/IERC20.sol"; -import {SafeMath} from "./SafeMath.sol"; +import {SafeMath} from "../lib/SafeMath.sol"; interface ICrowdPooling { function _QUOTE_RESERVE_() external view returns (uint256); @@ -22,7 +22,7 @@ interface IFee { } interface IQuota { - function getUserQuota(address user) external view returns (uint256); + function getUserQuota(address user) external view returns (int); } contract FeeRateImpl is InitializableOwnable { @@ -30,28 +30,28 @@ contract FeeRateImpl is InitializableOwnable { struct CPPoolInfo { address quoteToken; - uint256 globalQuota; + int globalQuota; address feeAddr; address quotaAddr; } mapping(address => CPPoolInfo) cpPools; - function addCpPoolInfo(address cpPool, address quoteToken, uint256 globalQuota, address feeAddr, address quotaAddr) external onlyOwner { + function addCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external onlyOwner { CPPoolInfo memory cpPoolInfo = CPPoolInfo({ quoteToken: quoteToken, - globalQuota: globalQuota, feeAddr: feeAddr, - quotaAddr: quotaAddr + quotaAddr: quotaAddr, + globalQuota: globalQuota }); cpPools[cpPool] = cpPoolInfo; } - function setCpPoolInfo(address cpPool, address quoteToken, uint256 globalQuota, address feeAddr, address quotaAddr) external onlyOwner { + function setCpPoolInfo(address cpPool, address quoteToken, int globalQuota, address feeAddr, address quotaAddr) external onlyOwner { cpPools[cpPool].quoteToken = quoteToken; - cpPools[cpPool].globalQuota = globalQuota; cpPools[cpPool].feeAddr = feeAddr; cpPools[cpPool].quotaAddr = quotaAddr; + cpPools[cpPool].globalQuota = globalQuota; } function getFeeRate(address pool, address user) external view returns (uint256) { @@ -64,43 +64,48 @@ contract FeeRateImpl is InitializableOwnable { uint256 userStake = ICrowdPooling(pool).getShares(user); address feeAddr = cpPoolInfo.feeAddr; address quotaAddr = cpPoolInfo.quotaAddr; - uint256 curQuota = cpPoolInfo.globalQuota; + int curQuota = cpPoolInfo.globalQuota; if(quotaAddr != address(0)) curQuota = IQuota(quotaAddr).getUserQuota(user); - if(curQuota != 0 && userInput.add(userStake) > curQuota) { - return 2 * 10**18; //over hardcap, will revert + require(curQuota == -1 || (curQuota != -1 && int(userInput.add(userStake)) <= curQuota), "DODOFeeImpl: EXCEED_YOUR_QUOTA"); + + if(feeAddr == address(0)) { + return 0; } else { - if(feeAddr == address(0)) { - return 0; - }else { - return IFee(feeAddr).getUserFee(user); - } + return IFee(feeAddr).getUserFee(user); } } } - function getCPInfoByUser(address pool, address user) external view returns(bool isHaveCap, uint256 curQuota, uint256 userFee) { + function getCPInfoByUser(address pool, address user) external view returns (bool isHaveCap, int curQuota, uint256 userFee) { CPPoolInfo memory cpPoolInfo = cpPools[pool]; - address quotaAddr = cpPoolInfo.quotaAddr; - curQuota = cpPoolInfo.globalQuota; - if(quotaAddr != address(0)) - curQuota = IQuota(quotaAddr).getUserQuota(user); - - if(curQuota == 0) { + if(cpPoolInfo.quoteToken == address(0)) { isHaveCap = false; + curQuota = -1; + userFee = 0; }else { - isHaveCap = true; - uint256 userStake = ICrowdPooling(pool).getShares(user); - curQuota = curQuota.sub(userStake); + address quotaAddr = cpPoolInfo.quotaAddr; + curQuota = cpPoolInfo.globalQuota; + if(quotaAddr != address(0)) + curQuota = IQuota(quotaAddr).getUserQuota(user); + + if(curQuota == -1) { + isHaveCap = false; + }else { + isHaveCap = true; + uint256 userStake = ICrowdPooling(pool).getShares(user); + curQuota = int(uint256(curQuota).sub(userStake)); + } + + address feeAddr = cpPoolInfo.feeAddr; + if(feeAddr == address(0)) { + userFee = 0; + } else { + userFee = IFee(feeAddr).getUserFee(user); + } } - address feeAddr = cpPoolInfo.feeAddr; - if(feeAddr == address(0)) { - userFee = 0; - } else { - userFee = IFee(feeAddr).getUserFee(user); - } } } diff --git a/contracts/DODOFee/vDODOQuota.sol b/contracts/DODOFee/vDODOQuota.sol new file mode 100644 index 0000000..7713fd1 --- /dev/null +++ b/contracts/DODOFee/vDODOQuota.sol @@ -0,0 +1,34 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; + +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; +import {IERC20} from "../intf/IERC20.sol"; +import {SafeMath} from "../lib/SafeMath.sol"; + + +contract vDODOQuota is InitializableOwnable { + using SafeMath for uint256; + address public immutable _VDODO_TOKEN_; + uint256 public _QUOTA_RATIO_; + uint256 public _BASE_QUOTA_; + + constructor(address vdodoToken) public { + _VDODO_TOKEN_ = vdodoToken; + } + + function setParams(uint256 quotaRatio, uint256 baseQuota) external onlyOwner { + _QUOTA_RATIO_ = quotaRatio; + _BASE_QUOTA_ = baseQuota; + } + + function getUserQuota(address user) external view returns (int) { + uint256 vDODOAmount = IERC20(_VDODO_TOKEN_).balanceOf(user); + return int(vDODOAmount.div(_QUOTA_RATIO_).add(_BASE_QUOTA_)); + } +} diff --git a/deploy-detail-v2.0.txt b/deploy-detail-v2.0.txt index fdea061..3b604ff 100644 --- a/deploy-detail-v2.0.txt +++ b/deploy-detail-v2.0.txt @@ -641,30 +641,6 @@ DODOApproveProxy Init tx: 0x34e33c12750fff4abd34dd368157ad1b2101597f44a3f978372 DODOApprove Init tx: 0x1f8ac1bbf54e3b42dc3657485fd837efba382a73342e2ced29b6e9fbdb4edeb4 DODOIncentive ChangeProxy tx: 0xd0427f9a814efb822a36ebf17bbf637d066887adacf636c32455a165d30b768 ==================================================== -network type: kovan -Deploy time: 2021/2/13 下午12:25:44 -==================================================== -network type: live -Deploy time: 2021/2/13 下午9:53:52 -==================================================== -network type: bsclive -Deploy time: 2021/2/13 下午10:20:14 -==================================================== -network type: bsclive -Deploy time: 2021/2/13 下午10:24:45 -==================================================== -network type: kovan -Deploy time: 2021/2/14 上午10:48:12 -==================================================== -network type: kovan -Deploy time: 2021/2/15 下午4:54:39 -==================================================== -network type: kovan -Deploy time: 2021/2/15 下午5:10:10 -==================================================== -network type: live -Deploy time: 2021/2/15 下午5:15:29 -==================================================== network type: bsclive Deploy time: 2021/2/16 下午4:51:26 Deploy type: V2 @@ -677,3 +653,45 @@ Init CpFactory Tx: 0x2b5cb91e706a48090fe066582b41a6bb2e3d789423e6b61c6244e1fb672 DODOV2RouteHelper Address: 0x1dc8D1f1600B7C1D39e6b60FBC7b021Bc4F9C993 DODOV2Proxy02 Address: 0x8F8Dd7DB1bDA5eD3da8C9daf3bfa471c12d58486 Init DODOProxyV2 Tx: 0x1985f2e208d58ab2353eae96231ee3a11e1213a5e31f654274a40bbb2b4e9c8a +==================================================== +network type: heco +Deploy time: 2021/2/24 上午10:39:36 +DODOCalleeHelperAddress: 0xBD5Cc9CF41a7dEDaa7dfa6da189D3a522fe262d1 +==================================================== +network type: heco +Deploy time: 2021/2/24 下午12:25:32 +Deploy type: V2 +DODOSellHelper Address: 0xA0Bb1FbC23a547a8D448C7c8a2336F69A9dBa1AF +DODOV1RouterHelper Address: 0xFB973C79C665C0AC69E74C67be90D4C7A6f23c59 +CloneFactoryAddress: 0x5dCEAe50CF8C3B885430E0E79226C513Db0318f2 +DefaultMtFeeRateAddress: 0x07911226E710dd0b9B1c4a2Dd3c85DeFd821D492 +Init DefaultMtFeeRateAddress Tx: 0xd4961aaf52e89e3be9a91a0a8571e358dc016cfdd1b56c52acc94df95e45335a +DefaultPermissionAddress: 0xC142FBA5948c372f49aDa159748EA224de6cC9AA +Init DefaultPermissionAddress Tx: 0xa3df5a8516a918a526ddfa862a587e0f1a7016750cf9cb8e8ab9cf17bde814f4 +DvmTemplateAddress: 0x13742E431830980c59Ca8d8eC4D001F64C0D0f09 +DppTemplateAddress: 0x78ce7b5ff3b6329BBc15Eb1ddEF5fdaDF04D4012 +DppAdminTemplateAddress: 0x3232fd648997F89E614A021fdAc756d61F9030A1 +CpTemplateAddress: 0x02869989ecc2D310C360861Ec2779f7027F65190 +DODOApprove Address: 0x67E849C7BC9735BFC8f6399171A94EA3BD80A19F +DODOApproveProxy Address: 0x053b27B5b93f6F213084d8e2e1c9317D4B4Ffb28 +DODOIncentiveAddress: 0x94290Bf438697Fa684d8CE0aC07c09f0e82D4f74 +DODOIncentive Init tx: 0xbb17230cb5536f05f89e8038700ae9c8978da502b38fc086471f72e620ce395d +DvmFactoryAddress: 0x496F9267054106Ea74F44BEFc2E3ea88126EB08f +Init DvmFactory Tx: 0x5b0f2a300240567afb73b00ad9aae58721ae14330127ab9f144f74421f39ac03 +DppFactoryAddress: 0xc18dd66CD9C9D1D8540ADbDe46C9a238C2713ff1 +Init DppFactory Tx: 0x04b6fbe1e8049d5e1078bde94f9e73846ac29c35e4b548c96ee9252daf712e81 +CpFactoryAddress: 0x5949a2840865f5d9DdB37c2419060663473f3392 +Init CpFactory Tx: 0x0b490e17b11b9bd4f3265749ca1c2684ab855c8e01d72c0a0657c060303de009 +DODOV2RouteHelper Address: 0x01330a505D1A5EA2d91EA50f3f2742150fba93da +DODOV2Proxy02 Address: 0x9c7300731971d083FA640b12ef0BCbFD6D8DB232 +Init DODOProxyV2 Tx: 0x1e92e187a7e9124c98036ddb5cff6a801355c28c54bf7a957ae96ae5bbd3f33a +==================================================== +network type: heco +Deploy time: 2021/2/24 下午2:37:23 +Deploy type: V2 - Adapter +DODOV1Adapter Address: 0x9B63602c1FEd8292b76fb611B5de66a8fB7F8a77 +DODOV2Adapter Address: 0xF68a04C267e492A21F0818C357f83c665230C5ad +UniAdapter Address: 0xDfa10eC79CE97689a7FeD409aEc3174681EF9602 +==================================================== +network type: heco +Deploy time: 2021/2/25 下午12:09:54 diff --git a/kovan-mock-v2.0.txt b/kovan-mock-v2.0.txt index 9e9d305..4f5b716 100644 --- a/kovan-mock-v2.0.txt +++ b/kovan-mock-v2.0.txt @@ -514,3 +514,10 @@ Mock POOL Tx: V2 Approve:0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA Tx: 0x29017dc8173e6e65768ef17baeffdb006e88d36088be0cc97a53c365ac929e60 Create DPP: 0xd8C30a4E866B188F16aD266dC3333BD47F34ebaE-0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b Pool:0x210912095691C9b0e318c22e49d94170ACAaCd0a Tx: 0x5bf334d720433b4fbfb71a4f75f5755ccd39f0977e59b74e78df083b03d9d9f5 Create DPP: 0xd7f02D1b4F9495B549787808503Ecfd231C3fbDA-0x5eca15b12d959dfcf9c71c59f8b467eb8c6efd0b Pool:0x25F03Cc8d661D04513D17497dDE752BDF96A8459 Tx: 0xb15244e5e51f2e593adee05c337c00b265636869c59af6589ca49b82f56a86a7 +==================================================== +network type: heco +Deploy time: 2021/2/25 下午12:09:59 +Mock TOKEN Tx: V2 +ERC20TemplateAddress: 0x62E1622a47C9Fe74B2cF0BaDe5Ecb8669ff9bFBF +MintableERC20TemplateAddress: 0xdd9dE5eD7A11b1Ed3314CD7f754f27A15DeDC63f +ERC20FactoryAddress: 0x8476DE046e1923adD9002A73133230B9e5BE4127 diff --git a/migrations/3_deploy_v2.js b/migrations/3_deploy_v2.js index 8f97fc0..73e0a6b 100644 --- a/migrations/3_deploy_v2.js +++ b/migrations/3_deploy_v2.js @@ -158,6 +158,36 @@ module.exports = async (deployer, network, accounts) => { //Account multiSigAddress = "0xcaa42F09AF66A8BAE3A7445a7f63DAD97c11638b"; defaultMaintainer = "0xcaa42F09AF66A8BAE3A7445a7f63DAD97c11638b"; + } else if (network == 'heco') { + //Helper + DODOSellHelperAddress = "0xA0Bb1FbC23a547a8D448C7c8a2336F69A9dBa1AF"; + WETHAddress = "0x5545153ccfca01fbd7dd11c0b23ba694d9509a6f"; + chiAddress = "0x0000000000000000000000000000000000000000"; + DODOCalleeHelperAddress = "0xbd5cc9cf41a7dedaa7dfa6da189d3a522fe262d1"; + DODORouteV2HelperAddress = ""; + DODOV1PmmHelperAddress = "0xFB973C79C665C0AC69E74C67be90D4C7A6f23c59"; + //Template + CloneFactoryAddress = "0x5dCEAe50CF8C3B885430E0E79226C513Db0318f2"; + DefaultMtFeeRateAddress = "0x07911226E710dd0b9B1c4a2Dd3c85DeFd821D492"; + DefaultPermissionAddress = "0xC142FBA5948c372f49aDa159748EA224de6cC9AA"; + + DvmTemplateAddress = "0x13742E431830980c59Ca8d8eC4D001F64C0D0f09"; + DppTemplateAddress = ""; + DppAdminTemplateAddress = "0x3232fd648997F89E614A021fdAc756d61F9030A1"; + CpTemplateAddress = "0x02869989ecc2D310C360861Ec2779f7027F65190"; + //Factory + DvmFactoryAddress = ""; + DppFactoryAddress = ""; + CpFactoryAddress = ""; + //Proxy + DODOApproveAddress = ""; + DODOApproveProxyAddress = ""; + DODOIncentiveAddress = "0x94290Bf438697Fa684d8CE0aC07c09f0e82D4f74"; + DODOTokenAddress = "0x7d5DF05F987f9B9dD2a13deF1793f943Ad2A5e93"; + //Account + // multiSigAddress = "0xD93c8D2429a6b0269527f148F3A0e5D187B0b1Ca"; + multiSigAddress = accounts[0]; + defaultMaintainer = accounts[0]; } else return; logger.log("===================================================="); diff --git a/migrations/4_deploy_v2_mock.js b/migrations/4_deploy_v2_mock.js index 0b32fea..2b2e5ca 100644 --- a/migrations/4_deploy_v2_mock.js +++ b/migrations/4_deploy_v2_mock.js @@ -58,18 +58,32 @@ const POOL_PARAM = [ ]; module.exports = async (deployer, network, accounts) => { - if (network != "kovan") return; - let CloneFactoryAddress = "0xf7959fe661124C49F96CF30Da33729201aEE1b27"; - let ERC20TemplateAddress = "0x77d2e257241e6971688b08bdA9F658F065d7bb41"; - let MintableERC20TemplateAddress = "0xA45a64DAba80757432fA4d654Df12f65f020C13C"; - let ERC20FactoryAddress = "0xCb1A2f64EfB02803276BFB5a8D511C4D950282a0"; - - let DPPFactoryAddress = "0x9fA487762d4329eBDD83a00a82C8a02719Fdf512"; - let DVMFactoryAddress = "0x322F8014C125Da09314d3a68d4d9F427823F17FD"; - let DODOApproveAddress = "0x4A354b8d0DDb7083f066bDaC1f50d23DE221B01C"; - let DODOProxyV2Address = "0x5b3faEAa344F8134a7E0A269a9dFb3C7898b090D"; + // if (network != "kovan") return; + let CloneFactoryAddress = ""; + let ERC20TemplateAddress = ""; + let MintableERC20TemplateAddress = ""; + let ERC20FactoryAddress = ""; + let DPPFactoryAddress = ""; + let DVMFactoryAddress = ""; + let DODOApproveAddress = ""; + let DODOProxyV2Address = ""; + if (network == "kovan") { + CloneFactoryAddress = "0xf7959fe661124C49F96CF30Da33729201aEE1b27"; + ERC20TemplateAddress = "0x77d2e257241e6971688b08bdA9F658F065d7bb41"; + MintableERC20TemplateAddress = "0xA45a64DAba80757432fA4d654Df12f65f020C13C"; + ERC20FactoryAddress = "0xCb1A2f64EfB02803276BFB5a8D511C4D950282a0"; + DPPFactoryAddress = "0x9fA487762d4329eBDD83a00a82C8a02719Fdf512"; + DVMFactoryAddress = "0x322F8014C125Da09314d3a68d4d9F427823F17FD"; + DODOApproveAddress = "0x4A354b8d0DDb7083f066bDaC1f50d23DE221B01C"; + DODOProxyV2Address = "0x5b3faEAa344F8134a7E0A269a9dFb3C7898b090D"; + } else if (network == "heco") { + CloneFactoryAddress = "0x5dCEAe50CF8C3B885430E0E79226C513Db0318f2"; + ERC20TemplateAddress = ""; + MintableERC20TemplateAddress = ""; + ERC20FactoryAddress = ""; + } const provider = new Web3.providers.HttpProvider("https://kovan.infura.io/v3/22d4a3b2df0e47b78d458f43fe50a199"); @@ -262,7 +276,7 @@ module.exports = async (deployer, network, accounts) => { const ERC20FactoryInstance = await ERC20Factory.at(ERC20FactoryAddress); const totalSupply = web3.utils.toWei("0", 'ether'); - for (let i = 0; i < 1; i++) { + for (let i = 0; i < 0; i++) { // var tx = await ERC20FactoryInstance.createStdERC20(totalSupply, 'DODO Bird', 'DODO', 18); var tx = await ERC20FactoryInstance.createMintableERC20(totalSupply, 'DODO Bird', 'DODO', 18); // var tx = await ERC20FactoryInstance.createStdERC20(totalSupply, 'USDT Token', 'USDT', 6); diff --git a/truffle-config.js b/truffle-config.js index db998b1..55c71ab 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -41,7 +41,7 @@ module.exports = { DEPLOY_V1: false, DEPLOY_V2: false, ADAPTER: false, - MOCK_TOKEN: false, + MOCK_TOKEN: true, MOCK_V2_POOL: false, MOCK_V2_SWAP: false, MANUAL_ADD_POOL: false, @@ -98,6 +98,13 @@ module.exports = { timeoutBlocks: 200, skipDryRun: true }, + heco: { + provider: function () { + return new HDWalletProvider(privKey, "https://http-mainnet.hecochain.com"); + }, + gasPrice: 1500000000, + network_id: 128 + }, coverage: { host: "127.0.0.1", port: 6545,