From eba59077c75ddf6b0268ea627514b8b9fc4576aa Mon Sep 17 00:00:00 2001 From: owen05 Date: Thu, 27 May 2021 14:49:51 +0800 Subject: [PATCH] deploy dropsV2 on kovan --- config/bsc-config.js | 8 +- config/kovan-config.js | 8 +- .../DODODrops/DODODropsV2/DropsFeeModel.sol | 2 +- deploy-drops.txt | 14 ++ migrations/6_deploy_dropsV2.js | 162 ++++++++++++++++++ test/DODODrops/dropsV2.test.ts | 23 ++- truffle-config.js | 3 +- 7 files changed, 211 insertions(+), 9 deletions(-) create mode 100644 deploy-drops.txt create mode 100644 migrations/6_deploy_dropsV2.js diff --git a/config/bsc-config.js b/config/bsc-config.js index a0c8521..31754d5 100644 --- a/config/bsc-config.js +++ b/config/bsc-config.js @@ -75,13 +75,17 @@ module.exports = { DODONFTRegistry: "", DODONFTProxy: "", - //================= MysteryBox ================= + //================= DropsV1 ================= // MysteryBoxV1: "0xc25286ef3BaE3f6Fe2d6d0A6e2acAd0301AF97b8", //波老师 MysteryBoxV1: "0xDf7E00Cd0bb91D1502a1A14575E58b5d8f20C8D4", //KAVA RandomGenerator: "0x7C062B9C584fA6eC2504270790D38240A2c5fE72", RandomPool: [ "0x82aff931d74f0645ce80e8f419b94c8f93952686", "0x327134de48fcdd75320f4c32498d1980470249ae" - ] + ], + + //================= DropsV2 ================== + DropsFeeModel: "", + DropsProxy: "" } } \ No newline at end of file diff --git a/config/kovan-config.js b/config/kovan-config.js index b17f615..2839dda 100644 --- a/config/kovan-config.js +++ b/config/kovan-config.js @@ -73,7 +73,7 @@ module.exports = { DODONFTRegistry: "0x579eBcC668b5517F733587091C35D495FE8d6b68", DODONFTProxy: "0xe121c6C90735e2Ca12e21708F2F379A55Ce61426", - //================= MysteryBox ================= + //================= DropsV1 ================= // MysteryBoxV1: "0x47d2b27525b93A9c9E03001E1D19310A08748D55",//波老师 MysteryBoxV1: "0xd56Fd300aE2e4C46cd34460776007dCE1C4F2043", RandomGenerator: "0x53F54E4760FA5f839e5624782D032495613DF218", @@ -81,6 +81,10 @@ module.exports = { "0xa2e0ef85618732d80e5ef362773da1c92e8b1c57", "0xaCfc959e0E85726d09A36E6DFdD56FB2e5dB8F77", "0x7A733869CB210393f3c02B740c58498EB1f8815C" - ] + ], + + //================= DropsV2 ================== + DropsFeeModel: "0xDBe1C360050638C9d0f28f23B51b198C8B70D9eA", + DropsProxy: "0xa3a23cee044F995a97D86defeABf769bAd57c7c8" } } \ No newline at end of file diff --git a/contracts/DODODrops/DODODropsV2/DropsFeeModel.sol b/contracts/DODODrops/DODODropsV2/DropsFeeModel.sol index c3801b1..817e655 100644 --- a/contracts/DODODrops/DODODropsV2/DropsFeeModel.sol +++ b/contracts/DODODrops/DODODropsV2/DropsFeeModel.sol @@ -31,7 +31,7 @@ contract DropsFeeModel is InitializableOwnable { mapping(address => DropBoxInfo) dropBoxes; - function addMysteryBoxInfo(address dropBox, uint256 globalFee, address feeAddr, address priceAddr) external onlyOwner { + function addDropBoxInfo(address dropBox, uint256 globalFee, address feeAddr, address priceAddr) external onlyOwner { DropBoxInfo memory dropBoxInfo = DropBoxInfo({ isSet: true, globalFee: globalFee, diff --git a/deploy-drops.txt b/deploy-drops.txt new file mode 100644 index 0000000..a45d080 --- /dev/null +++ b/deploy-drops.txt @@ -0,0 +1,14 @@ +==================================================== +network type: kovan +Deploy time: 2021/5/27 下午2:08:33 +Deploy type: Drops_V2 +DropsFeeModelAddress: 0xDBe1C360050638C9d0f28f23B51b198C8B70D9eA +Init DropsFeeModel Tx: 0xd53bf7c0258fb92f11c0cfd46d016627e1c42daf1d8ba39ecc09d2992370e965 +DropsERC721Address: 0xaF5801b7814926DD1D6a69C1D3a3429784131E2A +Init DropsERC721 Tx: 0x9d1711c4bb1bc158482e362c07744b7abdf142d1f03abcca2b4b6b4e88cf4586 +DropsProxyAddress: 0xa3a23cee044F995a97D86defeABf769bAd57c7c8 +BaseDropsAddress: 0xbe7a24D7E4af1C509D97d6972898389821143844 +Init BaseDrops Tx: 0x53876ec779656923d19304c951f9eee3de7c12b22d7bc0e33e185a0f30788a30 +DODOApproveProxy unlockAddProxy tx: 0x4bdefa4cdd3ea157228532b881816343bc08e6b4997085ba12340311f1756802 +DODOApproveProxy addDODOProxy tx: 0xfded36432e52dd6b631e0f9ed375a38b9d921ac7a8a848b54082c95c34e63bca +AddMinter DropsERC721 Tx: 0x3b1272e13bd90268b25d03732f1719b7fcc5e4f4ba74981ca32f3062c24fc36e diff --git a/migrations/6_deploy_dropsV2.js b/migrations/6_deploy_dropsV2.js new file mode 100644 index 0000000..4a1d87b --- /dev/null +++ b/migrations/6_deploy_dropsV2.js @@ -0,0 +1,162 @@ +const fs = require("fs"); +const { deploySwitch } = require('../truffle-config.js') +const file = fs.createWriteStream("../deploy-drops.txt", { 'flags': 'a' }); +let logger = new console.Console(file, file); +const { GetConfig } = require("../configAdapter.js") + +const DODOApproveProxy = artifacts.require("DODOApproveProxy"); +const DropsFeeModel = artifacts.require("DropsFeeModel"); +const DropsERC721 = artifacts.require("DropsERC721"); +const DropsERC1155 = artifacts.require("DropsERC1155"); +const DODODropsProxy = artifacts.require("DODODropsProxy") +const BaseDrops = artifacts.require("BaseDrops"); +const RandomGenerator = artifacts.require("RandomGenerator"); + +module.exports = async (deployer, network, accounts) => { + let CONFIG = GetConfig(network, accounts) + if (CONFIG == null) return; + //Need Deploy first + let WETHAddress = CONFIG.WETH; + let DODOApproveProxyAddress = CONFIG.DODOApproveProxy; + + if (DODOApproveProxyAddress == "" || WETHAddress == "") return; + + let DropsFeeModelAddress = CONFIG.DropsFeeModel; + let DropsProxyAddress = CONFIG.DropsProxy; + + + let RandomGeneratorAddress = CONFIG.RandomGenerator; + let RandomPool = CONFIG.RandomPool; + + let multiSigAddress = CONFIG.multiSigAddress; + let defaultMaintainer = CONFIG.defaultMaintainer; + + //配置信息 + var isProb = false; + var isReveal = true; + var curTime = Math.floor(new Date().getTime() / 1000) + var baseUri = "" + var name = "DROPS" + var symbol = "DROPS" + var buyToken = "0x854b0f89BAa9101e49Bfb357A38071C9db5d0DFa" //Kovan DODO + var sellTimeIntervals = [curTime + 60 * 10, curTime + 60 * 60, curTime + 60 * 120] + var sellPrices = ["1000000000000000000", "2000000000000000000", "0"] + var sellAmount = [30, 30, 0] + var redeemTime = curTime + 60 * 10 + var probIntervals = [4, 10, 50, 100, 105] + var tokenIdMaps = [ + [0], + [1, 38], + [3, 4, 5], + [6, 7], + [19, 30, 35, 40] + ] + var tokenIdList = [1, 2, 3, 4, 5, 6, 7, 8] + + if (deploySwitch.Drops_V2) { + logger.log("===================================================="); + logger.log("network type: " + network); + logger.log("Deploy time: " + new Date().toLocaleString()); + logger.log("Deploy type: Drops_V2"); + + if (DropsFeeModelAddress == "") { + await deployer.deploy(DropsFeeModel); + DropsFeeModelAddress = DropsFeeModel.address; + logger.log("DropsFeeModelAddress: ", DropsFeeModelAddress); + const DropsFeeModelInstance = await DropsFeeModel.at(DropsFeeModelAddress); + var tx = await DropsFeeModelInstance.initOwner(multiSigAddress); + logger.log("Init DropsFeeModel Tx:", tx.tx); + } + + if (!isReveal) { + if (RandomGeneratorAddress == "") { + await deployer.deploy(RandomGenerator, RandomPool); + RandomGeneratorAddress = RandomGenerator.address; + logger.log("RandomGeneratorAddress: ", RandomGeneratorAddress); + } + } else { + RandomGeneratorAddress = "0x0000000000000000000000000000000000000000" + } + + var nftContractAddress = ""; + if (isProb) { + await deployer.deploy(DropsERC1155); + DropsERC1155Address = DropsERC1155.address; + logger.log("DropsERC1155Address: ", DropsERC1155Address); + const DropsERC1155Instance = await DropsERC1155.at(DropsERC1155Address); + var tx = await DropsERC1155Instance.init(multiSigAddress, baseUri); + logger.log("Init DropsERC1155 Tx:", tx.tx); + nftContractAddress = DropsERC1155Address; + } else { + await deployer.deploy(DropsERC721); + DropsERC721Address = DropsERC721.address; + logger.log("DropsERC721Address: ", DropsERC721Address); + const DropsERC721Instance = await DropsERC721.at(DropsERC721Address); + var tx = await DropsERC721Instance.init(multiSigAddress, name, symbol, baseUri); + logger.log("Init DropsERC721 Tx:", tx.tx); + nftContractAddress = DropsERC721Address; + } + + if (DropsProxyAddress == "") { + await deployer.deploy( + DODODropsProxy, + DODOApproveProxyAddress + ); + DropsProxyAddress = DODODropsProxy.address; + logger.log("DropsProxyAddress: ", DropsProxyAddress); + } + + await deployer.deploy(BaseDrops); + BaseDropsAddress = BaseDrops.address; + logger.log("BaseDropsAddress: ", BaseDropsAddress); + + //drops init + var addrList = [ + multiSigAddress, + buyToken, + DropsFeeModelAddress, + defaultMaintainer, + RandomGeneratorAddress, + nftContractAddress + ] + + const BaseDropsInstance = await BaseDrops.at(BaseDropsAddress); + var tx = await BaseDropsInstance.init( + addrList, + sellTimeIntervals, + sellPrices, + sellAmount, + redeemTime, + isReveal, + isProb + ); + logger.log("Init BaseDrops Tx:", tx.tx); + + + if (network == 'kovan') { + + const DODOApproveProxyInstance = await DODOApproveProxy.at(DODOApproveProxyAddress); + var tx = await DODOApproveProxyInstance.unlockAddProxy(DropsProxyAddress); + logger.log("DODOApproveProxy unlockAddProxy tx: ", tx.tx); + + tx = await DODOApproveProxyInstance.addDODOProxy(); + logger.log("DODOApproveProxy addDODOProxy tx: ", tx.tx); + + + if (isProb) { + const DropsERC1155Instance = await DropsERC1155.at(DropsERC1155Address); + var tx = await DropsERC1155Instance.addMintAccount(DropsProxyAddress); + logger.log("AddMinter DropsERC1155 Tx:", tx.tx); + + await BaseDropsInstance.setProbInfo(probIntervals, tokenIdMaps); + + } else { + const DropsERC721Instance = await DropsERC721.at(DropsERC721Address); + var tx = await DropsERC721Instance.addMintAccount(DropsProxyAddress); + logger.log("AddMinter DropsERC721 Tx:", tx.tx); + + await BaseDropsInstance.setFixedAmountInfo(tokenIdList); + } + } + } +}; diff --git a/test/DODODrops/dropsV2.test.ts b/test/DODODrops/dropsV2.test.ts index a1fb2f7..a7dc61f 100644 --- a/test/DODODrops/dropsV2.test.ts +++ b/test/DODODrops/dropsV2.test.ts @@ -4,7 +4,7 @@ SPDX-License-Identifier: Apache-2.0 */ -import { decimalStr } from '../utils/Converter'; +import { decimalStr, fromWei} from '../utils/Converter'; import { logGas } from '../utils/Log'; import { assert } from 'chai'; import { Contract } from 'web3-eth-contract'; @@ -257,10 +257,27 @@ describe("DODODropsV2", () => { assert(tokenId, '10') }) - //TODO: it("withdraw", async () => { + await init(ctx, ctxDVM, true, true); + await setProbMap(ctx); + await ctx.EVM.increaseTime(10); + await logGas(await ctx.DropsProxy.methods.buyTickets(ctx.DropsV2.options.address, 2), ctx.sendParam(user1), "buyTickets-user1"); + await logGas(await ctx.DropsProxy.methods.buyTickets(ctx.DropsV2.options.address, 3), ctx.sendParam(user2), "buyTickets-user2"); + var b_drops_balance = await ctx.DODO.methods.balanceOf(ctx.DropsV2.options.address).call() + var b_owner = await ctx.DODO.methods.balanceOf(ctx.Deployer).call(); + + await ctx.DropsV2.methods.withdraw().send(ctx.sendParam(ctx.Deployer)); + + var a_drops_balance = await ctx.DODO.methods.balanceOf(ctx.DropsV2.options.address).call() + var a_owner = await ctx.DODO.methods.balanceOf(ctx.Deployer).call(); + + console.log("b_drops_balance:", fromWei(b_drops_balance, 'ether')) + console.log("a_drops_balance:", fromWei(a_drops_balance, 'ether')) + + console.log("b_owner:", fromWei(b_owner, 'ether')) + console.log("a_owner:", fromWei(a_owner, 'ether')) + assert(a_owner, decimalStr("0.00005")) }) - }); }); diff --git a/truffle-config.js b/truffle-config.js index 4cef526..33031ce 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -61,7 +61,8 @@ module.exports = { CpProxy: false, ERC20V2Factory: false, DEPLOY_NFT: false, - MYSTERYBOX_V1: false + MYSTERYBOX_V1: false, + Drops_V2: true }, networks: {