Merge branch 'main' of dodo:DODOEX/contractV2

This commit is contained in:
tracy
2023-10-23 06:51:59 +08:00
9 changed files with 2324 additions and 5780 deletions

102
config/scroll-config.js Normal file
View File

@@ -0,0 +1,102 @@
module.exports = {
SCROLL_CONFIG: {
//TOKEN
WETH: "0x5300000000000000000000000000000000000004",
CHI: "",
DODO: "",
//Helper
DODOSellHelper: "0x8eA40e8Da3ae64Bad5E77a5f7DB346499F543baC",
DODOCalleeHelper: "0x44023441f2Bad375b6b5C6354B03c3E9AD01E269",
DODOV1PmmHelper: "0x17644d3B366273faC75A07996E2F90A99A2946a7",
DODOV2RouteHelper: "0xf5048d8F9163AF17Db522Abe9FaF37735C911320",
ERC20Helper: "0xB5c7BA1EAde74800cD6cf5F56b1c4562De373780",
DODOSwapCalcHelper: "0xbcd2FDC3B884Cf0dfD932f55Ec2Fe1fB7e8c62Da",
MultiCall: "0xf5Ec1a19e1570bDf0A3AaA6585274f27027270b1",
MultiCallWithValid: "0x6433407a29706Bbdd43b36cd402a53A174f066a1",
CurveSample: "",
//Template
CloneFactory: "0x628E5081bA93b1c4F58E54e7175088B1ACe58852",
FeeRateModel: "0x7B07164ecFaF0F0D85DFC062Bc205a4674c75Aa0",
FeeRateDIP3Impl: "0x4aAe1d041C01078725dB016BA4D4F72455CaF931",
UserQuota: "",
PermissionManager: "0x5fe43C0EbfE66b83C10A9A37AD1E4aC640AAAA65",
DVM: "0x1fC8EC204549C865a17b4059A57decA66A4Bd4cC",
DPP: "",
DSP: "0x24549FC74B3076A962624A26370ed556c467F74C",
DPPAdmin: "",
DPPAdvanced: "0x297da061D1dE0132D241Fafed224288B34d81005",
DPPAdvancedAdmin: "0xCD536b4DECFD2fa0443666B6becD145F8aDe2E48",
CP: "0x3dD629473A2eD7f3C6299FFD9F3e0C283d073f11",
ERC20MineV2: "0x5B2fd46E6E3Ff1E479d651ec0b210882Aa9871dF",
ERC20MineV3: "0xAC716E87b0853C0712674e8E3a8435a489F276b4",
ERC20: "0x8414560d69650bC0c915d5d4385e1714a23cbe81",
CustomERC20: "0xEAC4BFef7D1c872Ed705B01856af7f9802adC596",
CustomMintableERC20: "0x04f7BaE2A4c05cd567F762E33450deBCebdC89EA",
//Factory
DVMFactory: "0x5a0C840a7089aa222c4458b3BE0947fe5a5006DE",
DPPFactory: "0x31AC053c31a77055b2ae2d3899091C0A9c19cE3a",
DSPFactory: "0x7E9c460d0A10bd0605B15F0d0388e307d34a62E6",
CrowdPoolingFactory: "0x4632e6EBd4a01eBF54739A9D71a62CEdb29E9183",
ERC20Factory: "",
ERC20V2Factory: "",
ERC20V3Factory: "0x1F076a800005c758a505E759720eb6737136e893",
DODOMineV2Factory: "0xAE1E7e4c5743321d2a8ceeD179264998a56CF1d9",
DODOMineV3Registry: "0xD63c8Bf9ACaFfE6da2a4043F1C94CC3a55F28117",
//Approve
DODOApprove: "0x20E77aD760eC9E922Fd2dA8847ABFbB2471B92CD",
DODOApproveProxy: "0x0218E24dd47f9a1D05418eAa5B9cEDB13Ca48492",
//Periphery
DODOIncentive: "",
//Adpater
DODOV1Adapter: "",
DODOV2Adapter: "0x716fcc67dcA500A91B4a28c9255262c398D8f971",
UniAdapter: "",
CurveAdapter: "",
//Proxy
DODOV2Proxy: "0xe49781e6186214d88aACFd9eBc8cE40E3CDc066D",
DSPProxy: "0x7Dd8c909E1F48a68FfEF03492761AF17B1496EDc",
CpProxy: "0xc4A1a152812dE96b2B1861E433f42290CDD7f113",
DPPProxy: "0x99d69565EdA438E3ebAA0627A407968ABD0f755b",
RouteProxy: "",
FeeRouteProxy1: "0x4e998615aD430C1cA46A69d813edE6EB3EC55eDb", // for front-end
FeeRouteProxy2: "0xf0512872fEc0173d1d99c2dd8CDCb770054b675b", // for widget
DODOMineV3Proxy: "0x14F7B8Fb0c1447DdE7bcf92a8d9BB058c8A5FE64",
//vDODO
DODOCirculationHelper: "",
Governance: "",
dodoTeam: "",
vDODOToken: "",
//Account
multiSigAddress: "0xa7b9C3a116b20bEDDdBE4d90ff97157f67F0bD97",
defaultMaintainer: "0xa7b9C3a116b20bEDDdBE4d90ff97157f67F0bD97",
//================== NFT ====================
BuyoutModel: "",
Fragment: "",
NFTCollateralVault: "",
DODONFTRouteHelper: "",
DodoNftErc721: "",
DodoNftErc1155: "",
DODONFTRegistry: "",
DODONFTProxy: "",
//=================== NFTPool ==================
DODONFTApprove: "",
DODONFTPoolProxy: "",
FilterAdmin: "",
FilterERC721V1: "",
FilterERC1155V1: "",
NFTPoolController: ""
}
}

View File

@@ -17,6 +17,7 @@ const { BASE_CONFIG } = require("./config/base-config");
const { SCROLL_SEPOLIA_CONFIG } = require("./config/scroll-sepolia-config"); const { SCROLL_SEPOLIA_CONFIG } = require("./config/scroll-sepolia-config");
const { MANTA_TESTNET_CONFIG } = require("./config/manta-testnet-config"); const { MANTA_TESTNET_CONFIG } = require("./config/manta-testnet-config");
const { OPTIMISM_CONFIG } = require("./config/optimism-config"); const { OPTIMISM_CONFIG } = require("./config/optimism-config");
const { SCROLL_CONFIG } = require("./config/scroll-config");
exports.GetConfig = function (network, accounts) { exports.GetConfig = function (network, accounts) {
var CONFIG = {} var CONFIG = {}
@@ -61,7 +62,7 @@ exports.GetConfig = function (network, accounts) {
CONFIG = BASE_CONFIG CONFIG = BASE_CONFIG
break; break;
case "dashboard": case "dashboard":
CONFIG = CFX_CONFIG CONFIG = SCROLL_CONFIG
break; break;
//testnet //testnet
case "kovan": case "kovan":

View File

@@ -15,20 +15,26 @@ import {UniversalERC20} from "../lib/UniversalERC20.sol";
import {SafeERC20} from "../../lib/SafeERC20.sol"; import {SafeERC20} from "../../lib/SafeERC20.sol";
import {TickMath} from '../../external/uniswap/TickMath.sol'; import {TickMath} from '../../external/uniswap/TickMath.sol';
import {IWETH} from "../../intf/IWETH.sol"; import {IWETH} from "../../intf/IWETH.sol";
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
import {PoolAddress} from '../../external/uniswap/PoolAddress.sol';
// to adapter like dodo V1 // to adapter like dodo V1
contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback { contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback, InitializableOwnable {
using SafeMath for uint; using SafeMath for uint;
// ============ Storage ============ // ============ Storage ============
address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public immutable _WETH_; address public immutable _WETH_;
address public immutable _V3_FACTORY_;
constructor ( constructor (
address payable weth address payable weth,
address factory
) public { ) public {
_WETH_ = weth; _WETH_ = weth;
_V3_FACTORY_ = factory;
initOwner(msg.sender);
} }
function _uniV3Swap(address to, address pool, uint160 sqrtX96, bytes memory data) internal { function _uniV3Swap(address to, address pool, uint160 sqrtX96, bytes memory data) internal {
@@ -37,8 +43,6 @@ contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback {
uint256 sellAmount = IERC20(fromToken).balanceOf(address(this)); uint256 sellAmount = IERC20(fromToken).balanceOf(address(this));
bool zeroForOne = fromToken < toToken; bool zeroForOne = fromToken < toToken;
// transfer
//IERC20(fromToken).transfer(pool, sellAmount);
// swap // swap
IUniV3(pool).swap( IUniV3(pool).swap(
to, to,
@@ -70,6 +74,9 @@ contract UniV3Adapter is IDODOAdapter, IUniswapV3SwapCallback {
) external override { ) external override {
require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported
(address tokenIn, address tokenOut, uint24 fee) = abi.decode(_data, (address, address, uint24)); (address tokenIn, address tokenOut, uint24 fee) = abi.decode(_data, (address, address, uint24));
// verifyCallback
address poolAddress = PoolAddress.computeAddress(_V3_FACTORY_, PoolAddress.getPoolKey(tokenIn, tokenOut, fee));
require(msg.sender == poolAddress || msg.sender == _OWNER_, "not available call address");
(bool isExactInput, uint256 amountToPay) = (bool isExactInput, uint256 amountToPay) =
amount0Delta > 0 amount0Delta > 0

View File

@@ -1,7 +1,3 @@
/**
*Submitted for verification at Etherscan.io on 2019-06-10
*/
pragma solidity 0.6.9; pragma solidity 0.6.9;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
@@ -10,11 +6,13 @@ pragma experimental ABIEncoderV2;
/// @author Joshua Levine <joshua@makerdao.com> /// @author Joshua Levine <joshua@makerdao.com>
/// @author Nick Johnson <arachnid@notdot.net> /// @author Nick Johnson <arachnid@notdot.net>
// WithValid
contract Multicall { contract Multicall {
struct Call { struct Call {
address target; address target;
bytes callData; bytes callData;
} }
function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) { function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) {
blockNumber = block.number; blockNumber = block.number;
returnData = new bytes[](calls.length); returnData = new bytes[](calls.length);

View File

@@ -0,0 +1,47 @@
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
/// @title Multicall - Aggregate results from multiple read-only function calls
/// @author Michael Elliot <mike@makerdao.com>
/// @author Joshua Levine <joshua@makerdao.com>
/// @author Nick Johnson <arachnid@notdot.net>
// WithValid
contract Multicall {
struct Call {
address target;
bytes callData;
}
function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData, bool[] memory dataValid) {
blockNumber = block.number;
returnData = new bytes[](calls.length);
dataValid = new bool[](calls.length);
for(uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
dataValid[i] = success;
returnData[i] = ret;
}
}
// Helper functions
function getEthBalance(address addr) public view returns (uint256 balance) {
balance = addr.balance;
}
function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
blockHash = blockhash(blockNumber);
}
function getLastBlockHash() public view returns (bytes32 blockHash) {
blockHash = blockhash(block.number - 1);
}
function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
timestamp = block.timestamp;
}
function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
difficulty = block.difficulty;
}
function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
gaslimit = block.gaslimit;
}
function getCurrentBlockCoinbase() public view returns (address coinbase) {
coinbase = block.coinbase;
}
}

View File

@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
/// @notice The identifying key of the pool
struct PoolKey {
address token0;
address token1;
uint24 fee;
}
/// @notice Returns PoolKey: the ordered tokens with the matched fee levels
/// @param tokenA The first token of a pool, unsorted
/// @param tokenB The second token of a pool, unsorted
/// @param fee The fee level of the pool
/// @return Poolkey The pool details with ordered token0 and token1 assignments
function getPoolKey(
address tokenA,
address tokenB,
uint24 fee
) internal pure returns (PoolKey memory) {
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
}
/// @notice Deterministically computes the pool address given the factory and PoolKey
/// @param factory The Uniswap V3 factory contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
require(key.token0 < key.token1);
pool = address(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encode(key.token0, key.token1, key.fee)),
POOL_INIT_CODE_HASH
)
)
)
);
}
}

View File

@@ -475,18 +475,22 @@ module.exports = async (deployer, network, accounts) => {
} }
//Adapter //Adapter
/*
if (DODOV1AdpaterAddress == "") { if (DODOV1AdpaterAddress == "") {
await deployer.deploy(DODOV1Adapter, DODOSellHelperAddress); await deployer.deploy(DODOV1Adapter, DODOSellHelperAddress);
logger.log("DODOV1Adapter Address: ", DODOV1Adapter.address); logger.log("DODOV1Adapter Address: ", DODOV1Adapter.address);
} }
*/
if (DODOV2AdapterAddress == "") { if (DODOV2AdapterAddress == "") {
await deployer.deploy(DODOV2Adapter) await deployer.deploy(DODOV2Adapter)
logger.log("DODOV2Adapter Address: ", DODOV2Adapter.address); logger.log("DODOV2Adapter Address: ", DODOV2Adapter.address);
} }
/*
if (UniAdapterAddress == "") { if (UniAdapterAddress == "") {
await deployer.deploy(UniAdapter) await deployer.deploy(UniAdapter)
logger.log("UniAdapter Address: ", UniAdapter.address); logger.log("UniAdapter Address: ", UniAdapter.address);
} }
*/
//Proxy //Proxy
@@ -578,25 +582,31 @@ module.exports = async (deployer, network, accounts) => {
logger.log("DODOApproveProxy Init tx: ", tx.tx); logger.log("DODOApproveProxy Init tx: ", tx.tx);
//Approve init //Approve init
console.log("DODOApprove init");
const DODOApproveInstance = await DODOApprove.at(DODOApproveAddress); const DODOApproveInstance = await DODOApprove.at(DODOApproveAddress);
tx = await DODOApproveInstance.init(multiSigAddress, DODOApproveProxyAddress); tx = await DODOApproveInstance.init(multiSigAddress, DODOApproveProxyAddress);
logger.log("DODOApprove Init tx: ", tx.tx); logger.log("DODOApprove Init tx: ", tx.tx);
//DODOMineV2Factory set owner
console.log("DODOMineV2Factory set owner");
const dodoMineV2FactoryInstance = await DODOMineV2Factory.at(DODOMineV2FactoryAddress);
var tx = await dodoMineV2FactoryInstance.initOwner(multiSigAddress);
logger.log("Init DODOMineV2Factory Tx:", tx.tx);
//Set FeeRateImpl //Set FeeRateImpl, need owner
console.log("Set FeeRateImpl");
const FeeRateModelInstance = await FeeRateModelTemplate.at(DefaultMtFeeRateAddress); const FeeRateModelInstance = await FeeRateModelTemplate.at(DefaultMtFeeRateAddress);
tx = await FeeRateModelInstance.setFeeProxy(FeeRateDIP3ImplAddress); tx = await FeeRateModelInstance.setFeeProxy(FeeRateDIP3ImplAddress);
logger.log("Set FeeRateImpl tx: ", tx.tx); logger.log("Set FeeRateImpl tx: ", tx.tx);
//ERC20V3Factory set fee //ERC20V3Factory set fee
// console.log("ERC20V3Factory set fee");
// const ERC20V3FactoryInstance = await ERC20V3Factory.at(ERC20V3FactoryAddress); // const ERC20V3FactoryInstance = await ERC20V3Factory.at(ERC20V3FactoryAddress);
// tx = await ERC20V3FactoryInstance.changeCreateFee("100000000000000000"); // tx = await ERC20V3FactoryInstance.changeCreateFee("100000000000000000");
// logger.log("Set ERC20V3 fee tx: ", tx.tx); // logger.log("Set ERC20V3 fee tx: ", tx.tx);
//DODOMineV2Factory set owner
const dodoMineV2FactoryInstance = await DODOMineV2Factory.at(DODOMineV2FactoryAddress);
var tx = await dodoMineV2FactoryInstance.initOwner(multiSigAddress);
logger.log("Init DODOMineV2Factory Tx:", tx.tx);
//DODOMineV3Registry add Proxy as admin //DODOMineV3Registry add Proxy as admin
const dodoMineV3RegistryInstance = await DODOMineV3Registry.at(DODOMineV3RegistryAddress); const dodoMineV3RegistryInstance = await DODOMineV3Registry.at(DODOMineV3RegistryAddress);

7861
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -56,6 +56,6 @@
"prettier-plugin-solidity": "^1.0.0-alpha.52", "prettier-plugin-solidity": "^1.0.0-alpha.52",
"solidity-coverage": "^0.7.7", "solidity-coverage": "^0.7.7",
"truffle-assertions": "^0.9.2", "truffle-assertions": "^0.9.2",
"truffle-plugin-verify": "^0.6.4" "truffle-plugin-verify": "^0.5.33"
} }
} }