diff --git a/contracts/NFTPool/impl/BaseFilterV1.sol b/contracts/NFTPool/impl/BaseFilterV1.sol index 438e967..5d00622 100644 --- a/contracts/NFTPool/impl/BaseFilterV1.sol +++ b/contracts/NFTPool/impl/BaseFilterV1.sol @@ -16,6 +16,8 @@ contract BaseFilterV1 is InitializableOwnable, ReentrancyGuard { using SafeMath for uint256; //=================== Storage =================== + string public _FILTER_NAME_; + address public _NFT_COLLECTION_; uint256 public _NFT_ID_START_; uint256 public _NFT_ID_END_ = uint256(-1); @@ -273,4 +275,11 @@ contract BaseFilterV1 is InitializableOwnable, ReentrancyGuard { _SPREAD_IDS_REGISTRY_[tokenIds[i]] = isRegistered[i]; } } + + function changeFilterName(string memory newFilterName) + external + onlySuperOwner + { + _FILTER_NAME_ = newFilterName; + } } diff --git a/contracts/NFTPool/impl/FilterERC1155V1.sol b/contracts/NFTPool/impl/FilterERC1155V1.sol index 54a4e5a..1cc53a2 100644 --- a/contracts/NFTPool/impl/FilterERC1155V1.sol +++ b/contracts/NFTPool/impl/FilterERC1155V1.sol @@ -21,11 +21,14 @@ contract FilterERC1155V1 is IERC1155Receiver, BaseFilterV1 { address filterAdmin, address nftCollection, bool[] memory toggles, + string memory filterName, uint256[] memory numParams, //0 - startId, 1 - endId, 2 - maxAmount, 3 - minAmount uint256[] memory priceRules, uint256[] memory spreadIds ) external { initOwner(filterAdmin); + + _FILTER_NAME_ = filterName; _NFT_COLLECTION_ = nftCollection; _changeNFTInPrice(priceRules[0], priceRules[1], toggles[0]); diff --git a/contracts/NFTPool/impl/FilterERC721V1.sol b/contracts/NFTPool/impl/FilterERC721V1.sol index 8a3d88a..a8a3493 100644 --- a/contracts/NFTPool/impl/FilterERC721V1.sol +++ b/contracts/NFTPool/impl/FilterERC721V1.sol @@ -24,13 +24,15 @@ contract FilterERC721V1 is IERC721Receiver, BaseFilterV1 { address filterAdmin, address nftCollection, bool[] memory toggles, + string memory filterName, uint256[] memory numParams, //0 - startId, 1 - endId, 2 - maxAmount, 3 - minAmount uint256[] memory priceRules, uint256[] memory spreadIds ) external { initOwner(filterAdmin); - _NFT_COLLECTION_ = nftCollection; + _FILTER_NAME_ = filterName; + _NFT_COLLECTION_ = nftCollection; _changeNFTInPrice(priceRules[0], priceRules[1], toggles[0]); _changeNFTRandomInPrice(priceRules[2], priceRules[3], toggles[1]); _changeNFTTargetOutPrice(priceRules[4], priceRules[5], toggles[2]); diff --git a/contracts/NFTPool/intf/IFilter.sol b/contracts/NFTPool/intf/IFilter.sol index f10cd89..048a9b4 100644 --- a/contracts/NFTPool/intf/IFilter.sol +++ b/contracts/NFTPool/intf/IFilter.sol @@ -8,6 +8,16 @@ pragma solidity 0.6.9; interface IFilter { + function init( + address filterAdmin, + address nftCollection, + bool[] memory toggles, + string memory filterName, + uint256[] memory numParams, + uint256[] memory priceRules, + uint256[] memory spreadIds + ) external; + function isNFTValid(address nftCollectionAddress, uint256 nftId) external view returns (bool); function _NFT_COLLECTION_() external view returns (address); diff --git a/contracts/SmartRoute/proxies/DODONFTPoolProxy.sol b/contracts/SmartRoute/proxies/DODONFTPoolProxy.sol index 596e774..edb8e27 100644 --- a/contracts/SmartRoute/proxies/DODONFTPoolProxy.sol +++ b/contracts/SmartRoute/proxies/DODONFTPoolProxy.sol @@ -16,17 +16,6 @@ import {IDODONFTApprove} from "../../intf/IDODONFTApprove.sol"; import {IERC20} from "../../intf/IERC20.sol"; import {SafeERC20} from "../../lib/SafeERC20.sol"; -interface IFilterV1 { - function init( - address filterAdmin, - address nftCollection, - bool[] memory toggles, - uint256[] memory numParams, - uint256[] memory priceRules, - uint256[] memory spreadIds - ) external; -} - contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable { using SafeMath for uint256; using SafeERC20 for IERC20; @@ -140,7 +129,7 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable { function createNewNFTPoolV1( address nftCollection, uint256 filterKey, //1 => FilterERC721V1, 2 => FilterERC1155V1 - string[] memory tokenInfo, + string[] memory infos, // 0 => filterName, 1 => fragName, 2 => fragSymbol uint256[] memory numParams,//0 - initSupply, 1 - fee bool[] memory toggles, uint256[] memory filterNumParams, //0 - startId, 1 - endId, 2 - maxAmount, 3 - minAmount @@ -154,6 +143,7 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable { newFilterAdmin, nftCollection, toggles, + infos[0], filterNumParams, priceRules, spreadIds @@ -165,8 +155,8 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable { IFilterAdmin(newFilterAdmin).init( msg.sender, numParams[0], - tokenInfo[0], - tokenInfo[1], + infos[1], + infos[2], numParams[1], _CONTROLLER_, _MAINTAINER_, @@ -180,15 +170,17 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable { address filterAdmin, address nftCollection, bool[] memory toggles, + string memory filterName, uint256[] memory numParams, //0 - startId, 1 - endId, 2 - maxAmount, 3 - minAmount uint256[] memory priceRules, uint256[] memory spreadIds ) public returns(address newFilterV1) { newFilterV1 = ICloneFactory(_CLONE_FACTORY_).clone(_FILTER_TEMPLATES_[key]); - IFilterV1(newFilterV1).init( + IFilter(newFilterV1).init( filterAdmin, nftCollection, toggles, + filterName, numParams, priceRules, spreadIds diff --git a/test/utils/Contracts.ts b/test/utils/Contracts.ts index 20190e9..939674b 100644 --- a/test/utils/Contracts.ts +++ b/test/utils/Contracts.ts @@ -74,6 +74,16 @@ export const DROPS_ERC1155 = "DropsERC1155" export const DROPS_FEE_MODEL = "DropsFeeModel" export const DROPS_PROXY = "DODODropsProxy" +export const DODO_NFT = "DODONFT" +export const DODO_NFT_1155 = "DODONFT1155" + +export const FILTER_ERC721_V1 = "FilterERC721" +export const FILTER_ERC1155_V1 = "FilterERC1155" +export const FILTER_ADMIN = "FilterAdmin" +export const CONTROLLER = "Controller" +export const DODO_NFT_APPROVE = "DODONFTApprove" +export const DODO_NFT_POOL_PROXY = "DODONFTPoolProxy" + interface ContractJson { abi: any; diff --git a/test/utils/NFTPoolContext.ts b/test/utils/NFTPoolContext.ts new file mode 100644 index 0000000..5949f03 --- /dev/null +++ b/test/utils/NFTPoolContext.ts @@ -0,0 +1,111 @@ +/* + + Copyright 2021 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 } from './Converter'; +import { EVM, getDefaultWeb3 } from './EVM'; +import * as log from './Log'; + +BigNumber.config({ + EXPONENTIAL_AT: 1000, + DECIMAL_PLACES: 80, +}); + + +export class NFTPoolContext { + EVM: EVM; + Web3: Web3; + + FilterAdmin: Contract; + FilterERC721V1: Contract; + FilterERC1155V1: Contract; + Controller: Contract; + DODONFTApprove: Contract; + DODONFTPoolProxy: Contract; + + //nft token + DodoNft: Contract; + DodoNft1155: Contract; + + Deployer: string; + Maintainer: string; + SpareAccounts: string[]; + + constructor() { } + + async init() { + 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.DodoNft = await contracts.newContract(contracts.DODO_NFT); + this.DodoNft1155 = await contracts.newContract(contracts.DODO_NFT_1155); + + await this.DodoNft.methods.init(this.Deployer, "DODONFT", "DODONFT").send(this.sendParam(this.Deployer)); + await this.DodoNft1155.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer)); + + var cloneFactory = await contracts.newContract( + contracts.CLONE_FACTORY_CONTRACT_NAME + ); + var filterAdminTemplate = await contracts.newContract(contracts.FILTER_ADMIN) + var filterERC721V1Template = await contracts.newContract(contracts.FILTER_ERC721_V1) + var filterERC1155V1Template = await contracts.newContract(contracts.FILTER_ERC1155_V1) + + this.Controller = await contracts.newContract(contracts.CONTROLLER) + await this.Controller.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer)); + + this.DODONFTApprove = await contracts.newContract( + contracts.DODO_NFT_APPROVE + ); + + this.DODONFTPoolProxy = await contracts.newContract(contracts.DODO_NFT_POOL_PROXY, + [ + cloneFactory.options.address, + filterAdminTemplate.options.address, + this.Controller.options.address, + this.Deployer, + this.DODONFTApprove.options.address, + "" //TODO:ERC721 => ERC20 + ] + ) + + await this.DODONFTPoolProxy.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer)); + await this.DODONFTPoolProxy.methods.setFilterTemplate(1, filterERC721V1Template.options.address).send(this.sendParam(this.Deployer)); + await this.DODONFTPoolProxy.methods.setFilterTemplate(2, filterERC1155V1Template.options.address).send(this.sendParam(this.Deployer)); + + await this.DODONFTApprove.methods.init(this.Deployer, [this.DODONFTPoolProxy.options.address]).send(this.sendParam(this.Deployer)); + + console.log(log.blueText("[Init NFTPool 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)); + } +} + +export async function getNFTPoolContext(weth: string): Promise { + var context = new NFTPoolContext(); + await context.init(); + return context; +} diff --git a/truffle-test.sh b/truffle-test.sh index d17e2ec..9770c14 100644 --- a/truffle-test.sh +++ b/truffle-test.sh @@ -71,12 +71,7 @@ then truffle test ./test/DODODrops/dropsV2.test.ts fi -# if [ "$1"x = "route-incentive"x ] -# then -# truffle test ./test/Route/Incentive.test.ts -# fi - -# if [ "$1"x = "route"x ] -# then -# truffle test ./test/Route/route.test.ts -# fi \ No newline at end of file +if [ "$1"x = "NFTPool"x ] +then + truffle test ./test/NFTPool/nftPool.test.ts +fi \ No newline at end of file