diff --git a/config/bsc-config.js b/config/bsc-config.js index f59fe04..818e257 100644 --- a/config/bsc-config.js +++ b/config/bsc-config.js @@ -9,7 +9,7 @@ module.exports = { DODOSellHelper: "0x0F859706AeE7FcF61D5A8939E8CB9dBB6c1EDA33", DODOCalleeHelper: "0xaaffAd1017D6a13E026A00121BF258C616B25f7C", DODOV1PmmHelper: "0x2BBD66fC4898242BDBD2583BBe1d76E8b8f71445", - DODOV2RouteHelper: "0xd72b354BD39f8F11D0cA07bD5724896Bb1a42707", + DODOV2RouteHelper: "0xC1CCE4C003B10052f168072A4c3c02051053d957", //Template CloneFactory: "0x03E2427859119E497EB856a166F616a2Ce5f8c88", @@ -17,6 +17,7 @@ module.exports = { PermissionManager: "0x729f7f44bf64Ce814716b6261e267DbE6cdf021c", DVM: "0x409E377A7AfFB1FD3369cfc24880aD58895D1dD9", DPP: "0x85351262f7474Ebe23FfAcD633cf20A491F1325D", + DSP: "0xE3c91fDCe30DD5Aa95138D6c4d63f43a26e9066e", DPPAdmin: "0x44D5dF24d5Ef52A791D6436Fa45A8D426f6de34e", CP: "0x5D6e6A0BFB2176AFCc4FB809822D8e009216b245", ERC20: "0xef49a6dba1c8df859e49c17e9a485b439c7689d3", @@ -25,6 +26,7 @@ module.exports = { //Factory DVMFactory: "0x790B4A80Fb1094589A3c0eFC8740aA9b0C1733fB", DPPFactory: "0xAfe0A75DFFb395eaaBd0a7E1BBbd0b11f8609eeF", + DSPFactory: "0x0fb9815938Ad069Bf90E14FE6C596c514BEDe767", UpCpFactory: "0x4F57F6929E58AE564F6AB090fE0AEEcb39B0f270", CrowdPoolingFactory: "0x778DF5B12170e8af8dF94356BfC864E57CE185DC", ERC20Factory: "0x5e84190a270333aCe5B9202a3F4ceBf11b81bB01", @@ -44,6 +46,7 @@ module.exports = { //Proxy DODOV2Proxy: "", + DSPProxy: "0x2442A8B5cdf1E659F3F949A7E454Caa554D4E65a", //vDODO DODOCirculationHelper: "", diff --git a/config/eth-config.js b/config/eth-config.js index e5b3f45..a78f7b7 100644 --- a/config/eth-config.js +++ b/config/eth-config.js @@ -9,7 +9,7 @@ module.exports = { DODOSellHelper: "0x533da777aedce766ceae696bf90f8541a4ba80eb", DODOCalleeHelper: "0xef49a6DBa1C8DF859E49c17E9A485B439c7689d3", DODOV1PmmHelper: "0x6373ceB657C83C91088d328622573FB766064Ac4", - DODOV2RouteHelper: "0xeAB910bea37DD837dDCED91C8E99dBcC4DBcCc01", + DODOV2RouteHelper: "0x0672952Fab6BD1336C57AE09E49DB6D3e78B1896", //Template CloneFactory: "0x5e5a7b76462e4bdf83aa98795644281bdba80b88", @@ -17,6 +17,7 @@ module.exports = { PermissionManager: "0x6B208E08dcF6BD51F50C5Da09d15B2D8E5C46Cf2", DVM: "0x7cA7B5EAAf526d93705d28c1b47E9739595C90E7", DPP: "0xB76de21f04F677f07D9881174a1D8E624276314C", + DSP: "0x8735AAd3BEae15487a017EE32cb11d8fd593e036", DPPAdmin: "0x5515363c0412AdD5c72d3E302fE1bD7dCBCF93Fe", CP: "0x327344B382EE1b44FB0a72945fCDCC7243200dD7", ERC20: "0x85351262f7474ebe23ffacd633cf20a491f1325d", @@ -25,6 +26,7 @@ module.exports = { //Factory DVMFactory: "0x72d220cE168C4f361dD4deE5D826a01AD8598f6C", DPPFactory: "0x6B4Fa0bc61Eddc928e0Df9c7f01e407BfcD3e5EF", + DSPFactory: "0x6fdDB76c93299D985f4d3FC7ac468F9A168577A4", UpCpFactory: "0x78D338F9d54E9e41872E68cB1c01d9499d87eE52", CrowdPoolingFactory: "0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25", ERC20Factory: "0x44D5dF24d5Ef52A791D6436Fa45A8D426f6de34e", @@ -43,6 +45,7 @@ module.exports = { //Proxy DODOV2Proxy: "", + DSPProxy: "0x4599ed18F34cFE06820E3684bF0aACB8D75c644d", //vDODO DODOCirculationHelper: "0x357c5e9cfa8b834edcef7c7aabd8f9db09119d11", diff --git a/config/heco-config.js b/config/heco-config.js index 54d1768..732e8fd 100644 --- a/config/heco-config.js +++ b/config/heco-config.js @@ -9,7 +9,7 @@ module.exports = { DODOSellHelper: "0xA0Bb1FbC23a547a8D448C7c8a2336F69A9dBa1AF", DODOCalleeHelper: "0xbd5cc9cf41a7dedaa7dfa6da189d3a522fe262d1", DODOV1PmmHelper: "0xFB973C79C665C0AC69E74C67be90D4C7A6f23c59", - DODOV2RouteHelper: "0xd8E049732079a06a2483a3e1789755aD64dC03a9", + DODOV2RouteHelper: "", //Template CloneFactory: "0x5dCEAe50CF8C3B885430E0E79226C513Db0318f2", @@ -17,6 +17,7 @@ module.exports = { PermissionManager: "0xC142FBA5948c372f49aDa159748EA224de6cC9AA", DVM: "0x05061d7f9353a7B5EB550840974B71A7465c2E86", DPP: "0x824083c29f99cd1E31D4A6bD859b1B5C2F0EA3EE", + DSP: "", DPPAdmin: "0x3232fd648997F89E614A021fdAc756d61F9030A1", CP: "0x5B67cF070ce4303Ff4d450f21Cc371F9f0549335", ERC20: "0x62e1622a47c9fe74b2cf0bade5ecb8669ff9bfbf", @@ -25,6 +26,7 @@ module.exports = { //Factory DVMFactory: "0xd8c77CF0F01222b07B8343A681C46eFA3faEa985", DPPFactory: "0xF5420a3b91c457d336589217d45CcB8F7250eAed", + DSPFactory: "", UpCpFactory: "0xF7c3467786efAA9BD4022941ecd5a00C61b17FA9", CrowdPoolingFactory: "0x56133d0b63abf7A15D5697dD2dB9e04730f1A9C2", ERC20Factory: "0x2cCDF6F742afBe813B68Ec6bb421C1BEa74fBd46", @@ -43,6 +45,7 @@ module.exports = { //Proxy DODOV2Proxy: "0xAc7cC7d2374492De2D1ce21e2FEcA26EB0d113e7", + DSPProxy: "", //vDODO DODOCirculationHelper: "", diff --git a/config/kovan-config.js b/config/kovan-config.js index 3eecad3..695145c 100644 --- a/config/kovan-config.js +++ b/config/kovan-config.js @@ -9,7 +9,7 @@ module.exports = { DODOSellHelper: "0xbdEae617F2616b45DCB69B287D52940a76035Fe3", DODOCalleeHelper: "0x36ce1831941d35c3588759B2D084E240a094ad4A", DODOV1PmmHelper: "0xC972069473a686b1c11Bd9347D719c87e6745d39", - DODOV2RouteHelper: "0xcB3b6cdBe2e57D3e37feba0C55584992Cc1B973F", + DODOV2RouteHelper: "0x92a3E8c83D89aE6CdE4009e053b591fa0eC65e86", //Template CloneFactory: "0xf7959fe661124C49F96CF30Da33729201aEE1b27", @@ -17,6 +17,7 @@ module.exports = { PermissionManager: "0x82C87c5EB912762676E7a87Aad67D916317c7D0e", DVM: "0x7B1eD6Be684b9c691C6C4bd5ccd7bF3e0d4E06fC", DPP: "0xEAdc4943329Cb8139Ee3c8575f6a9B3659cd0591", + DSP: "0xAD4E649c1771F5175081c2CcAC183fDb91cfCd6c", DPPAdmin: "0xf63e41A459D9AEcaE4bAE1278ef0ae84F7F2DE56", CP: "0x6092eFEf82CaDcd07f3a545cBe6C83dae713aE0A", ERC20: "0x77d2e257241e6971688b08bda9f658f065d7bb41", @@ -25,6 +26,7 @@ module.exports = { //Factory DVMFactory: "0x322F8014C125Da09314d3a68d4d9F427823F17FD", DPPFactory: "0xC65F8087288aa0a118aa6F3228Ef9ecc8187F4b6", + DSPFactory: "0xd54d6b7261860a3a689135bA3D333D13b65F3CEe", CrowdPoolingFactory: "0x9e6E8985D52E91eDf1671f28Ca73bc4F3E219b72", UpCpFactory: "0x25AE560522165eacCFbF2287493AF12B8ad718e7", ERC20Factory: "0xCb1A2f64EfB02803276BFB5a8D511C4D950282a0", @@ -43,6 +45,7 @@ module.exports = { //Proxy DODOV2Proxy: "0x85CAA68ae47f047aa01C48BCaA711CA70a950fFb", + DSPProxy: "0xC5fF477667E29df8887D258CaE593e04A1961A69", //vDODO DODOCirculationHelper: "", diff --git a/contracts/DODOStablePool/intf/IDSP.sol b/contracts/DODOStablePool/intf/IDSP.sol index 0cfc8bf..f35c571 100644 --- a/contracts/DODOStablePool/intf/IDSP.sol +++ b/contracts/DODOStablePool/intf/IDSP.sol @@ -20,17 +20,19 @@ interface IDSP { bool isOpenTWAP ) external; - function _BASE_TOKEN_() external returns (address); + function _BASE_TOKEN_() external view returns (address); - function _QUOTE_TOKEN_() external returns (address); + function _QUOTE_TOKEN_() external view returns (address); - function _MT_FEE_RATE_MODEL_() external returns (address); + function _I_() external view returns (uint256); - function getVaultReserve() external returns (uint256 baseReserve, uint256 quoteReserve); + function _MT_FEE_RATE_MODEL_() external view returns (address); + + function getVaultReserve() external view returns (uint256 baseReserve, uint256 quoteReserve); function sellBase(address to) external returns (uint256); function sellQuote(address to) external returns (uint256); - function buyShares(address to) external returns (uint256); + function buyShares(address to) external returns (uint256,uint256,uint256); } diff --git a/contracts/SmartRoute/helper/DODOV2RouteHelper.sol b/contracts/SmartRoute/helper/DODOV2RouteHelper.sol index c2ebab0..5ead267 100644 --- a/contracts/SmartRoute/helper/DODOV2RouteHelper.sol +++ b/contracts/SmartRoute/helper/DODOV2RouteHelper.sol @@ -13,6 +13,7 @@ import {IDODOV2} from "../intf/IDODOV2.sol"; contract DODOV2RouteHelper { address public immutable _DVM_FACTORY_; address public immutable _DPP_FACTORY_; + address public immutable _DSP_FACTORY_; struct PairDetail { uint256 i; @@ -30,15 +31,18 @@ contract DODOV2RouteHelper { uint256 pairVersion; } - constructor(address dvmFactory,address dppFactory) public { + constructor(address dvmFactory,address dppFactory,address dspFactory) public { _DVM_FACTORY_ = dvmFactory; _DPP_FACTORY_ = dppFactory; + _DSP_FACTORY_ = dspFactory; } function getPairDetail(address token0,address token1,address userAddr) external view returns (PairDetail[] memory res) { (address[] memory baseToken0DVM, address[] memory baseToken1DVM) = IDODOV2(_DVM_FACTORY_).getDODOPoolBidirection(token0,token1); (address[] memory baseToken0DPP, address[] memory baseToken1DPP) = IDODOV2(_DPP_FACTORY_).getDODOPoolBidirection(token0,token1); - uint256 len = baseToken0DVM.length + baseToken1DVM.length + baseToken0DPP.length + baseToken1DPP.length; + (address[] memory baseToken0DSP, address[] memory baseToken1DSP) = IDODOV2(_DSP_FACTORY_).getDODOPoolBidirection(token0,token1); + + uint256 len = baseToken0DVM.length + baseToken1DVM.length + baseToken0DPP.length + baseToken1DPP.length + baseToken0DSP.length + baseToken1DSP.length; res = new PairDetail[](len); for(uint8 i = 0; i < len; i++) { PairDetail memory curRes = PairDetail(0,0,0,0,0,0,0,0,0,address(0),address(0),address(0),2); @@ -55,10 +59,18 @@ contract DODOV2RouteHelper { cur = baseToken0DPP[i - baseToken0DVM.length - baseToken1DVM.length]; curRes.baseToken = token0; curRes.quoteToken = token1; - } else { + } else if(i < baseToken0DVM.length + baseToken1DVM.length + baseToken0DPP.length + baseToken1DPP.length) { cur = baseToken1DPP[i - baseToken0DVM.length - baseToken1DVM.length - baseToken0DPP.length]; curRes.baseToken = token1; curRes.quoteToken = token0; + } else if(i < baseToken0DVM.length + baseToken1DVM.length + baseToken0DPP.length + baseToken1DPP.length + baseToken0DSP.length) { + cur = baseToken0DSP[i - baseToken0DVM.length - baseToken1DVM.length - baseToken0DPP.length - baseToken1DPP.length]; + curRes.baseToken = token0; + curRes.quoteToken = token1; + } else { + cur = baseToken1DSP[i - baseToken0DVM.length - baseToken1DVM.length - baseToken0DPP.length - baseToken1DPP.length - baseToken0DSP.length]; + curRes.baseToken = token1; + curRes.quoteToken = token0; } ( diff --git a/contracts/SmartRoute/proxies/DODODspProxy.sol b/contracts/SmartRoute/proxies/DODODspProxy.sol new file mode 100644 index 0000000..e134b24 --- /dev/null +++ b/contracts/SmartRoute/proxies/DODODspProxy.sol @@ -0,0 +1,197 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; + +import {IDODOApproveProxy} from "../DODOApproveProxy.sol"; +import {IERC20} from "../../intf/IERC20.sol"; +import {IWETH} from "../../intf/IWETH.sol"; +import {SafeMath} from "../../lib/SafeMath.sol"; +import {SafeERC20} from "../../lib/SafeERC20.sol"; +import {DecimalMath} from "../../lib/DecimalMath.sol"; +import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol"; +import {IDSP} from "../../DODOStablePool/intf/IDSP.sol"; +import {IDSPFactory} from "../../Factory/DSPFactory.sol"; + +/** + * @title DODODspProxy + * @author DODO Breeder + * + * @notice Entrance of DODO Stable Pair in DODO platform + */ +contract DODODspProxy is ReentrancyGuard { + using SafeMath for uint256; + + // ============ Storage ============ + + address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + address public immutable _WETH_; + address public immutable _DODO_APPROVE_PROXY_; + address public immutable _DSP_FACTORY_; + + // ============ Modifiers ============ + + modifier judgeExpired(uint256 deadLine) { + require(deadLine >= block.timestamp, "DODODspProxy: EXPIRED"); + _; + } + + fallback() external payable {} + + receive() external payable {} + + constructor( + address dspFactory, + address payable weth, + address dodoApproveProxy + ) public { + _DSP_FACTORY_ = dspFactory; + _WETH_ = weth; + _DODO_APPROVE_PROXY_ = dodoApproveProxy; + } + + // ============ DSP Functions (create & add liquidity) ============ + + function createDODOStablePair( + address baseToken, + address quoteToken, + uint256 baseInAmount, + uint256 quoteInAmount, + uint256 lpFeeRate, + uint256 i, + uint256 k, + bool isOpenTWAP, + uint256 deadLine + ) + external + payable + preventReentrant + judgeExpired(deadLine) + returns (address newDODOStablePair, uint256 shares) + { + { + address _baseToken = baseToken == _ETH_ADDRESS_ ? _WETH_ : baseToken; + address _quoteToken = quoteToken == _ETH_ADDRESS_ ? _WETH_ : quoteToken; + newDODOStablePair = IDSPFactory(_DSP_FACTORY_).createDODOStablePool( + _baseToken, + _quoteToken, + lpFeeRate, + i, + k, + isOpenTWAP + ); + } + + { + address _baseToken = baseToken; + address _quoteToken = quoteToken; + _deposit( + msg.sender, + newDODOStablePair, + _baseToken, + baseInAmount, + _baseToken == _ETH_ADDRESS_ + ); + _deposit( + msg.sender, + newDODOStablePair, + _quoteToken, + quoteInAmount, + _quoteToken == _ETH_ADDRESS_ + ); + } + + (shares, , ) = IDSP(newDODOStablePair).buyShares(msg.sender); + } + + function addDSPLiquidity( + address dspAddress, + uint256 baseInAmount, + uint256 quoteInAmount, + uint256 baseMinAmount, + uint256 quoteMinAmount, + uint8 flag, // 0 - ERC20, 1 - baseInETH, 2 - quoteInETH + uint256 deadLine + ) + external + payable + preventReentrant + judgeExpired(deadLine) + returns ( + uint256 shares, + uint256 baseAdjustedInAmount, + uint256 quoteAdjustedInAmount + ) + { + address _dsp = dspAddress; + (baseAdjustedInAmount, quoteAdjustedInAmount) = _addDSPLiquidity( + _dsp, + baseInAmount, + quoteInAmount + ); + require( + baseAdjustedInAmount >= baseMinAmount && quoteAdjustedInAmount >= quoteMinAmount, + "DODODspProxy: deposit amount is not enough" + ); + + _deposit(msg.sender, _dsp, IDSP(_dsp)._BASE_TOKEN_(), baseAdjustedInAmount, flag == 1); + _deposit(msg.sender, _dsp, IDSP(_dsp)._QUOTE_TOKEN_(), quoteAdjustedInAmount, flag == 2); + + (shares, , ) = IDSP(_dsp).buyShares(msg.sender); + + // refund dust eth + if (flag == 1 && msg.value > baseAdjustedInAmount) msg.sender.transfer(msg.value - baseAdjustedInAmount); + if (flag == 2 && msg.value > quoteAdjustedInAmount) msg.sender.transfer(msg.value - quoteAdjustedInAmount); + } + + + // =================== internal functions ===================== + + function _addDSPLiquidity( + address dspAddress, + uint256 baseInAmount, + uint256 quoteInAmount + ) internal view returns (uint256 baseAdjustedInAmount, uint256 quoteAdjustedInAmount) { + (uint256 baseReserve, uint256 quoteReserve) = IDSP(dspAddress).getVaultReserve(); + if (quoteReserve == 0 && baseReserve == 0) { + uint256 i = IDSP(dspAddress)._I_(); + uint256 shares = quoteInAmount < DecimalMath.mulFloor(baseInAmount, i) + ? DecimalMath.divFloor(quoteInAmount, i) + : baseInAmount; + baseAdjustedInAmount = shares; + quoteAdjustedInAmount = DecimalMath.mulFloor(shares, i); + } + if (quoteReserve > 0 && baseReserve > 0) { + uint256 baseIncreaseRatio = DecimalMath.divFloor(baseInAmount, baseReserve); + uint256 quoteIncreaseRatio = DecimalMath.divFloor(quoteInAmount, quoteReserve); + if (baseIncreaseRatio <= quoteIncreaseRatio) { + baseAdjustedInAmount = baseInAmount; + quoteAdjustedInAmount = DecimalMath.mulFloor(quoteReserve, baseIncreaseRatio); + } else { + quoteAdjustedInAmount = quoteInAmount; + baseAdjustedInAmount = DecimalMath.mulFloor(baseReserve, quoteIncreaseRatio); + } + } + } + + function _deposit( + address from, + address to, + address token, + uint256 amount, + bool isETH + ) internal { + if (isETH) { + if (amount > 0) { + IWETH(_WETH_).deposit{value: amount}(); + if (to != address(this)) SafeERC20.safeTransfer(IERC20(_WETH_), to, amount); + } + } else { + IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens(token, from, to, amount); + } + } +} diff --git a/deploy-detail-periphery.txt b/deploy-detail-periphery.txt index 1b4b8a7..385f280 100644 --- a/deploy-detail-periphery.txt +++ b/deploy-detail-periphery.txt @@ -353,3 +353,34 @@ Add rewardToken1 Tx: 0xe5127653d59ba4530be0e2d873adc80191005ee1b131db45deb06d141 network type: kovan Deploy time: 2021/4/12 下午8:32:13 Deploy type: ERC20Mine +DspTemplateAddress: 0x2f658Fd3f09b8Ec3C57c40AbBDecbBAF1Afaaa30 +DspTemplateAddress: 0x9359189E6B649ae16B7993d61F8b1BC98C86C614 +DspFactoryAddress: 0xE7A8A1cfb95fF12C48Ed7fA5769C6335e69CF45b +Init DspFactory Tx: 0x5e1fcea19e7d215f8d2a7287cf1fd25cee2aa2169061376d4d6606bad9fbcf2c +DspTemplateAddress: 0x1F0F58aa235ec44d36a8d6156488A62a23D33Fa2 +DspFactoryAddress: 0x5e675A237B4F333B252f63bA141cEfc0b3bdf836 +Init DspFactory Tx: 0xe436bc79ef476afc998cd8d0fca6010a452d6f1fc61669ed6b539327465843cc +DODOV2RouteHelper Address: 0x2b34f6dC371f2129Ad53EB70dB5Ae90235a93F22 +DspTemplateAddress: 0x20D68Cf24211F24Fa0F78a48ab44Dc7da5f55e38 +DspFactoryAddress: 0x08E485cF3A2d62DC43c37A783abBC85df540E821 +Init DspFactory Tx: 0xfe9538552ae4d41276117086bd07e9877ca977e91c927c1f5707c34fac9ce05b +DODOV2RouteHelper Address: 0xFA50887AA9b223B307A4130826de11BB2b6589cC +DspTemplateAddress: 0x7B85Ec7b03c8eeA3d51c61C915f897d8A8536F4E +DspFactoryAddress: 0x3Be227fA238A2961357df4623D21B56D3D7FE2eD +Init DspFactory Tx: 0x087fcb80b90c6347f54f29c54b45b359419f0cacff67972ebecfbf464bcf3c98 +DODOV2RouteHelper Address: 0xc2Af45eb3A272D49BD55945A83117daf6B4081fF +DODODspProxy Address: 0xA0d0304559f6179f917DFD9EF7831a4954a8faC1 +DspFactoryAddress: 0xd54d6b7261860a3a689135bA3D333D13b65F3CEe +Init DspFactory Tx: 0xc3a1f453103ac64f9f3dffc51559d16bf80044d732fcd47ca11b4ff5acee559b +DODOV2RouteHelper Address: 0x92a3E8c83D89aE6CdE4009e053b591fa0eC65e86 +DODODspProxy Address: 0xC5fF477667E29df8887D258CaE593e04A1961A69 +DspTemplateAddress: 0x7C073b1C1a7E68ffBCcca4E49c0592407380022a +DspFactoryAddress: 0xBb245F54569841906eC7eDFFf72a910557B81378 +DspFactoryAddress: 0x0fb9815938Ad069Bf90E14FE6C596c514BEDe767 +Init DspFactory Tx: 0x13f0c2ff5ba088d091937035a158818e3726c202e87057568921c7e0ea0543c6 +DODOV2RouteHelper Address: 0xC1CCE4C003B10052f168072A4c3c02051053d957 +DODODspProxy Address: 0x2442A8B5cdf1E659F3F949A7E454Caa554D4E65a +DspFactoryAddress: 0x6fdDB76c93299D985f4d3FC7ac468F9A168577A4 +Init DspFactory Tx: 0xed3706c06c19a02844ba17d6d0e141063b9d33c54bdce5843b972cedd1ec4d90 +DODOV2RouteHelper Address: 0x0672952Fab6BD1336C57AE09E49DB6D3e78B1896 +DODODspProxy Address: 0x4599ed18F34cFE06820E3684bF0aACB8D75c644d diff --git a/migrations/2_deploy_v2.js b/migrations/2_deploy_v2.js index c29c0e4..50e6313 100644 --- a/migrations/2_deploy_v2.js +++ b/migrations/2_deploy_v2.js @@ -27,7 +27,6 @@ const DODOProxyV2 = artifacts.require("DODOV2Proxy02"); const DODOIncentive = artifacts.require("DODOIncentive"); const DODOSellHelper = artifacts.require("DODOSellHelper"); const DODOCalleeHelper = artifacts.require("DODOCalleeHelper"); -const DODOV2RouteHelper = artifacts.require("DODOV2RouteHelper"); const DODOV1PmmHelper = artifacts.require("DODOV1PmmHelper"); const DODOV1Adapter = artifacts.require("DODOV1Adapter"); @@ -46,7 +45,7 @@ module.exports = async (deployer, network, accounts) => { //Helper let DODOSellHelperAddress = CONFIG.DODOSellHelper; let DODOCalleeHelperAddress = CONFIG.DODOCalleeHelper; - let DODORouteV2HelperAddress = CONFIG.DODOV2RouteHelper; + // let DODORouteV2HelperAddress = CONFIG.DODOV2RouteHelper; let DODOV1PmmHelperAddress = CONFIG.DODOV1PmmHelper; //Template @@ -259,11 +258,11 @@ module.exports = async (deployer, network, accounts) => { logger.log("Init CpFactory Tx:", tx.tx); } - if (DODORouteV2HelperAddress == "") { - await deployer.deploy(DODOV2RouteHelper, DvmFactoryAddress, DppFactoryAddress); - DODOV2RouteHelperAddress = DODOV2RouteHelper.address; - logger.log("DODOV2RouteHelper Address: ", DODOV2RouteHelperAddress); - } + // if (DODORouteV2HelperAddress == "") { + // await deployer.deploy(DODOV2RouteHelper, DvmFactoryAddress, DppFactoryAddress); + // DODOV2RouteHelperAddress = DODOV2RouteHelper.address; + // logger.log("DODOV2RouteHelper Address: ", DODOV2RouteHelperAddress); + // } //Proxy await deployer.deploy( diff --git a/migrations/4_deploy_periphery.js b/migrations/4_deploy_periphery.js index bad38db..1044d17 100644 --- a/migrations/4_deploy_periphery.js +++ b/migrations/4_deploy_periphery.js @@ -18,6 +18,11 @@ const CpFactory = artifacts.require("CrowdPoolingFactory"); const MultiCall = artifacts.require("Multicall"); const LockedTokenVault = artifacts.require("LockedTokenVault"); +const DspTemplate = artifacts.require("DSP"); +const DspFactory = artifacts.require("DSPFactory"); +const DODODspProxy = artifacts.require("DODODspProxy"); +const DODOV2RouteHelper = artifacts.require("DODOV2RouteHelper"); + const ERC20Mine = artifacts.require("ERC20Mine"); const vDODOMine = artifacts.require("vDODOMine"); @@ -25,9 +30,16 @@ module.exports = async (deployer, network, accounts) => { let CONFIG = GetConfig(network, accounts) if (CONFIG == null) return; + let WETHAddress = CONFIG.WETH; let DODOTokenAddress = CONFIG.DODO; let DODOApproveProxyAddress = CONFIG.DODOApproveProxy; + let DspTemplateAddress = CONFIG.DSP; + let DspFactoryAddress = CONFIG.DSPFactory; + let DvmFactoryAddress = CONFIG.DVMFactory; + let DppFactoryAddress = CONFIG.DPPFactory; + + let DODOCirculationHelperAddress = CONFIG.DODOCirculationHelper; let GovernanceAddress = CONFIG.Governance; let vDODOTokenAddress = CONFIG.vDODOToken; @@ -37,13 +49,12 @@ module.exports = async (deployer, network, accounts) => { let DefaultMtFeeRateAddress = CONFIG.FeeRateModel; let DefaultPermissionAddress = CONFIG.PermissionManager; let CpTemplateAddress = CONFIG.CP; - let DvmFactoryAddress = CONFIG.DVMFactory; let DvmTemplateAddress = CONFIG.DVM; let multiSigAddress = CONFIG.multiSigAddress; let defaultMaintainer = CONFIG.defaultMaintainer; - if(deploySwitch.ERC20Mine) { + if (deploySwitch.ERC20Mine) { logger.log("===================================================="); logger.log("network type: " + network); logger.log("Deploy time: " + new Date().toLocaleString()); @@ -80,13 +91,13 @@ module.exports = async (deployer, network, accounts) => { endBlock ); logger.log("Add rewardToken1 Tx:", tx.tx); - + //init //addToken //TransferToken } - if(deploySwitch.LockedVault) { + if (deploySwitch.LockedVault) { logger.log("===================================================="); logger.log("network type: " + network); logger.log("Deploy time: " + new Date().toLocaleString()); @@ -101,7 +112,48 @@ module.exports = async (deployer, network, accounts) => { logger.log("LockedVault address: ", LockedTokenVault.address); //TODO: approve && deposit } - + + if (deploySwitch.DSP) { + logger.log("===================================================="); + logger.log("network type: " + network); + logger.log("Deploy time: " + new Date().toLocaleString()); + logger.log("Deploy type: DSP"); + + if (DspTemplateAddress == "") { + await deployer.deploy(DspTemplate); + DspTemplateAddress = DspTemplate.address; + logger.log("DspTemplateAddress: ", DspTemplateAddress); + } + + if (DspFactoryAddress == "") { + await deployer.deploy( + DspFactory, + CloneFactoryAddress, + DspTemplateAddress, + defaultMaintainer, + DefaultMtFeeRateAddress + ); + DspFactoryAddress = DspFactory.address; + logger.log("DspFactoryAddress: ", DspFactoryAddress); + const DspFactoryInstance = await DspFactory.at(DspFactoryAddress); + var tx = await DspFactoryInstance.initOwner(multiSigAddress); + logger.log("Init DspFactory Tx:", tx.tx); + } + + await deployer.deploy(DODOV2RouteHelper, DvmFactoryAddress, DppFactoryAddress, DspFactoryAddress); + DODOV2RouteHelperAddress = DODOV2RouteHelper.address; + logger.log("DODOV2RouteHelper Address: ", DODOV2RouteHelperAddress); + + await deployer.deploy( + DODODspProxy, + DspFactoryAddress, + WETHAddress, + DODOApproveProxyAddress + ); + logger.log("DODODspProxy Address: ", DODODspProxy.address); + } + + if (deploySwitch.UpCP) { logger.log("===================================================="); logger.log("network type: " + network); diff --git a/truffle-config.js b/truffle-config.js index 6d5836c..44b8a0e 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -55,8 +55,9 @@ module.exports = { CP: false, CPFactory: false, MultiCall: false, + DSP: true, LockedVault: false, - ERC20Mine: true + ERC20Mine: false, }, networks: { @@ -91,7 +92,7 @@ module.exports = { return new HDWalletProvider(privKey, "https://mainnet.infura.io/v3/" + infuraId); }, gas: 6000000, - gasPrice: 200000000000, + gasPrice: 125000000000, network_id: 1, skipDryRun: true }, @@ -102,6 +103,7 @@ module.exports = { }, network_id: 56, confirmations: 10, + gasPrice: 5000000000, timeoutBlocks: 200, skipDryRun: true },