From 2e1b0e0e9b6543d1014cc66f3ab13de0a327d86f Mon Sep 17 00:00:00 2001 From: owen05 Date: Thu, 8 Apr 2021 16:16:11 +0800 Subject: [PATCH] ing --- contracts/SmartRoute/proxies/DODONFTProxy.sol | 3 - migrations/5_deploy_nft.js | 4 +- test/DODONFT/collateralVault.test.ts | 0 test/DODONFT/feeDistributer.test.ts | 0 test/DODONFT/fragment.test.ts | 0 test/DODONFT/nftProxy.test.ts | 69 ++++++++ test/DODONFT/nftTokenFactory.test.ts | 0 test/utils/Contracts.ts | 11 +- test/utils/NFTContext.ts | 153 ++++++++++++++++++ test/utils/ProxyContextV2.ts | 2 +- 10 files changed, 234 insertions(+), 8 deletions(-) create mode 100644 test/DODONFT/collateralVault.test.ts create mode 100644 test/DODONFT/feeDistributer.test.ts create mode 100644 test/DODONFT/fragment.test.ts create mode 100644 test/DODONFT/nftProxy.test.ts create mode 100644 test/DODONFT/nftTokenFactory.test.ts create mode 100644 test/utils/NFTContext.ts diff --git a/contracts/SmartRoute/proxies/DODONFTProxy.sol b/contracts/SmartRoute/proxies/DODONFTProxy.sol index 3306d54..a47f1e1 100644 --- a/contracts/SmartRoute/proxies/DODONFTProxy.sol +++ b/contracts/SmartRoute/proxies/DODONFTProxy.sol @@ -40,7 +40,6 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable { address public immutable _WETH_; address public immutable _DODO_APPROVE_PROXY_; address public immutable _CLONE_FACTORY_; - address public immutable _DVM_FACTORY_; address public immutable _NFT_REGISTY_; address public immutable _DEFAULT_MAINTAINER_; @@ -70,7 +69,6 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable { address cloneFactory, address payable weth, address dodoApproveProxy, - address dvmFactory, address defaultMaintainer, address vaultTemplate, address fragTemplate, @@ -82,7 +80,6 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable { _CLONE_FACTORY_ = cloneFactory; _WETH_ = weth; _DODO_APPROVE_PROXY_ = dodoApproveProxy; - _DVM_FACTORY_ = dvmFactory; _DEFAULT_MAINTAINER_ = defaultMaintainer; _VAULT_TEMPLATE_ = vaultTemplate; _FRAG_TEMPLATE_ = fragTemplate; diff --git a/migrations/5_deploy_nft.js b/migrations/5_deploy_nft.js index baca296..0e2eb95 100644 --- a/migrations/5_deploy_nft.js +++ b/migrations/5_deploy_nft.js @@ -23,10 +23,9 @@ module.exports = async (deployer, network, accounts) => { let WETHAddress = CONFIG.WETH; let DVMTemplateAddress = CONFIG.DVM; let CloneFactoryAddress = CONFIG.CloneFactory; - let DvmFactoryAddress = CONFIG.DVMFactory; let DODOApproveProxyAddress = CONFIG.DODOApproveProxy; - if (DvmFactoryAddress == "" || DODOApproveProxyAddress == "" || CloneFactoryAddress == "") return; + if (DODOApproveProxyAddress == "" || CloneFactoryAddress == "") return; let ConstFeeRateModelAddress = CONFIG.ConstFeeRateModel; let FeeDistributorAddress = CONFIG.FeeDistributor; @@ -119,7 +118,6 @@ module.exports = async (deployer, network, accounts) => { CloneFactoryAddress, WETHAddress, DODOApproveProxyAddress, - DvmFactoryAddress, defaultMaintainer, NFTCollateralVaultAddress, FragmentAddress, diff --git a/test/DODONFT/collateralVault.test.ts b/test/DODONFT/collateralVault.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/DODONFT/feeDistributer.test.ts b/test/DODONFT/feeDistributer.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/DODONFT/fragment.test.ts b/test/DODONFT/fragment.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/DODONFT/nftProxy.test.ts b/test/DODONFT/nftProxy.test.ts new file mode 100644 index 0000000..05dd655 --- /dev/null +++ b/test/DODONFT/nftProxy.test.ts @@ -0,0 +1,69 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ +import { decimalStr, mweiStr } from '../utils/Converter'; +import { logGas } from '../utils/Log'; +import { NFTContext, getDODONftContext } from '../utils/NFTContext'; +import { assert } from 'chai'; +import * as contracts from '../utils/Contracts'; +import { Contract } from 'web3-eth-contract'; + +let author: string; +let user1: string; +let user2: string; + +async function init(ctx: NFTContext): Promise { + author = ctx.SpareAccounts[1]; + user1 = ctx.SpareAccounts[2]; + user2 = ctx.SpareAccounts[3]; + + await ctx.mintTestToken(user1, ctx.USDT, mweiStr("10000")); + await ctx.mintTestToken(user2, ctx.USDT, mweiStr("10000")); + + await ctx.approveProxy(user1); + await ctx.approveProxy(user2); +} + + +describe("DODONFTProxy", () => { + let snapshotId: string; + let ctx: NFTContext; + + + before(async () => { + let ETH = await contracts.newContract( + contracts.WETH_CONTRACT_NAME + ); + ctx = await getDODONftContext(ETH.options.address); + await init(ctx); + }); + + beforeEach(async () => { + snapshotId = await ctx.EVM.snapshot(); + }); + + afterEach(async () => { + await ctx.EVM.reset(snapshotId); + }); + + describe("DODONFTProxy", () => { + it("createNFTVault", async () => { + + }); + + it("buyout", async () => { + + }); + + it("AddLiquidity", async () => { + + }); + + it("AddLiquidity", async () => { + + }); + }); +}); diff --git a/test/DODONFT/nftTokenFactory.test.ts b/test/DODONFT/nftTokenFactory.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/utils/Contracts.ts b/test/utils/Contracts.ts index e560aad..1d1d43c 100644 --- a/test/utils/Contracts.ts +++ b/test/utils/Contracts.ts @@ -32,7 +32,6 @@ export const DVM_VAULT_NAME = "DVMVault" export const DVM_NAME = "DVM" export const DVM_FACTORY_NAME = "DVMFactory" export const DVM_PROXY_NAME = "DVMProxy" -export const CONST_FEE_RATE_MODEL_NAME = "ConstFeeRateModel" export const PERMISSION_MANAGER_NAME = "PermissionManager" export const EXTERNAL_VALUE_NAME = "ExternalValue" export const FEE_RATE_MODEL_NAME = "FeeRateModel" @@ -55,6 +54,16 @@ export const DODO_PROXY_NAME = "DODOV2Proxy02" export const ERC20_MINE = "ERC20Mine" export const VDODO_MINE = "vDODOMine" +export const NFT_VAULT = "NFTCollateralVault" +export const NFT_FEE = "FeeDistributor" +export const NFT_FRAG = "Fragment" +export const ERC721 = "InitializableERC721" +export const ERC1155 = "InitializableERC1155" +export const CONST_FEE_RATE_MODEL_NAME = "ConstFeeRateModel" +export const NFT_TOKEN_FACTORY = "NFTTokenFactory" +export const NFT_REGISTER = "DODONFTRegistry" +export const NFT_PROXY = "DODONFTProxy" + interface ContractJson { abi: any; networks: { [network: number]: any }; diff --git a/test/utils/NFTContext.ts b/test/utils/NFTContext.ts new file mode 100644 index 0000000..c7cdf2b --- /dev/null +++ b/test/utils/NFTContext.ts @@ -0,0 +1,153 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +import BigNumber from 'bignumber.js'; +import Web3 from 'web3'; +import { Contract } from 'web3-eth-contract'; + +import * as contracts from './Contracts'; +import { decimalStr, mweiStr, MAX_UINT256 } from './Converter'; +import { EVM, getDefaultWeb3 } from './EVM'; +import * as log from './Log'; + +BigNumber.config({ + EXPONENTIAL_AT: 1000, + DECIMAL_PLACES: 80, +}); + + +export class NFTContext { + EVM: EVM; + Web3: Web3; + NFTTokenFacotry: Contract; + + NFTRegister: Contract; + CollatteralVault: Contract; + Fragment: Contract; + NFTFee: Contract; + + NFTProxy: Contract; + DODOApprove: Contract; + DODOApproveProxy: Contract; + + //token + USDT: Contract; + WETH: Contract; + + Deployer: string; + Maintainer: string; + SpareAccounts: string[]; + + constructor() { } + + async init(weth: string) { + this.EVM = new EVM(); + this.Web3 = getDefaultWeb3(); + const allAccounts = await this.Web3.eth.getAccounts(); + this.Deployer = allAccounts[0]; + this.Maintainer = allAccounts[1]; + this.SpareAccounts = allAccounts.slice(2, 10); + + this.WETH = contracts.getContractWithAddress(contracts.WETH_CONTRACT_NAME, weth); + + this.USDT = await contracts.newContract( + contracts.MINTABLE_ERC20_CONTRACT_NAME, + ["USDT Token", "USDT", 6] + ); + + var cloneFactory = await contracts.newContract( + contracts.CLONE_FACTORY_CONTRACT_NAME + ); + var dvmTemplate = await contracts.newContract(contracts.DVM_NAME) + var constFeeTemplate = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME) + + var ERC721Template = await contracts.newContract(contracts.ERC721) + var ERC1155Template = await contracts.newContract(contracts.ERC1155) + + + this.NFTTokenFacotry = await contracts.newContract(contracts.NFT_TOKEN_FACTORY, + [ + cloneFactory.options.address, + ERC721Template.options.address, + ERC1155Template.options.address + ] + ) + + this.DODOApprove = await contracts.newContract( + contracts.SMART_APPROVE + ); + + this.DODOApproveProxy = await contracts.newContract( + contracts.SMART_APPROVE_PROXY, + [this.DODOApprove.options.address] + ) + + + this.NFTRegister = await contracts.newContract(contracts.NFT_REGISTER) + await this.NFTRegister.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer)); + + + this.CollatteralVault = await contracts.newContract( + contracts.NFT_VAULT + ); + + this.Fragment = await contracts.newContract(contracts.NFT_FRAG) + + this.NFTFee = await contracts.newContract(contracts.NFT_FEE) + + this.NFTProxy = await contracts.newContract(contracts.NFT_PROXY, + [ + cloneFactory.options.address, + this.WETH.options.address, + this.DODOApproveProxy.options.address, + this.Deployer, + this.CollatteralVault.options.address, + this.Fragment.options.address, + this.NFTFee.options.address, + dvmTemplate.options.address, + constFeeTemplate.options.address, + this.NFTRegister.options.address + ] + ) + + await this.NFTProxy.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer)); + + + await this.DODOApprove.methods.init(this.Deployer, this.DODOApproveProxy.options.address).send(this.sendParam(this.Deployer)); + await this.DODOApproveProxy.methods.init(this.Deployer, [this.NFTProxy.options.address]).send(this.sendParam(this.Deployer)); + + console.log(log.blueText("[Init DODONFT context]")); + } + + sendParam(sender, value = "0") { + return { + from: sender, + gas: process.env["COVERAGE"] ? 10000000000 : 7000000, + gasPrice: mweiStr("1000"), + value: decimalStr(value), + }; + } + + async mintTestToken(to: string, token: Contract, amount: string) { + await token.methods.mint(to, amount).send(this.sendParam(this.Deployer)); + } + + async approveProxy(account: string) { + await this.USDT.methods + .approve(this.DODOApprove.options.address, MAX_UINT256) + .send(this.sendParam(account)); + await this.WETH.methods + .approve(this.DODOApprove.options.address, MAX_UINT256) + .send(this.sendParam(account)); + } +} + +export async function getDODONftContext(weth: string): Promise { + var context = new NFTContext(); + await context.init(weth); + return context; +} diff --git a/test/utils/ProxyContextV2.ts b/test/utils/ProxyContextV2.ts index 7fee40a..b97c69c 100644 --- a/test/utils/ProxyContextV2.ts +++ b/test/utils/ProxyContextV2.ts @@ -162,7 +162,7 @@ export class ProxyContext { [this.WETH.options.address] ) - console.log(log.blueText("[Init DVM context]")); + console.log(log.blueText("[Init ProxyV2 context]")); } sendParam(sender, value = "0") {