update nftProxy && deploy kovan

This commit is contained in:
owen05
2021-04-08 00:31:25 +08:00
parent 3c027c7882
commit 906fcf7687
10 changed files with 284 additions and 59 deletions

View File

@@ -59,5 +59,19 @@ module.exports = {
//Account
multiSigAddress: "",
defaultMaintainer: "",
//================== NFT ====================
ConstFeeRateModel: "0xBDAcEcF886a4F0C509260d9678D5673C3E8fa4b7",
FeeDistributor: "0x989F9eFaA19c6A06945Db4439b9a7935dD573A66",
Fragment: "0x36ed21f19B0cf0c1E571A8C3A6953a5778E48B5a",
NFTCollateralVault: "0x78B7AFf2E5fA95B1E7E16679645FB65a850ed6AB",
InitializableERC721: "0xBF243C5626A0766031d57269c01F6eFd57B603fc",
InitializableERC1155: "0x33221F3aFC8b5F7eEB1bf6e836ECB0bA6a78759b",
NFTTokenFactory: "0x57d7A27e9E7206F28fe98D0A0228a03afF5b6e77",
DODONFTRegistry: "0xF405372b7808363DCfbb5Eb81204889B7a69Aa3e",
DODONFTProxy: "0x41Eb1FFC3d6474Ee4f4Aaf335a09cD411ADDDf1f",
}
}

View File

@@ -14,6 +14,7 @@ interface IDODONFTRegistry {
function addRegistry(
address vault,
address fragment,
address quoteToken,
address feeDistributor,
address dvm
) external;
@@ -38,6 +39,9 @@ contract DODONFTRegistry is InitializableOwnable {
// Vault -> Frag
mapping(address => address) public _VAULT_FRAG_REGISTRY_;
// base -> quote -> DVM address list
mapping(address => mapping(address => address[])) public _REGISTRY_;
// ============ Events ============
event NewRegistry(
@@ -55,6 +59,7 @@ contract DODONFTRegistry is InitializableOwnable {
function addRegistry(
address vault,
address fragment,
address quoteToken,
address feeDistributor,
address dvm
) external {
@@ -62,6 +67,7 @@ contract DODONFTRegistry is InitializableOwnable {
_FRAG_FEE_REGISTRY_[fragment] = feeDistributor;
_DVM_FEE_REGISTRY_[dvm] = feeDistributor;
_VAULT_FRAG_REGISTRY_[vault] = fragment;
_REGISTRY_[fragment][quoteToken].push(dvm);
emit NewRegistry(vault, fragment, feeDistributor, dvm);
}
@@ -83,4 +89,20 @@ contract DODONFTRegistry is InitializableOwnable {
function removeWhiteList (address contractAddr) public onlyOwner {
isAdminListed[contractAddr] = false;
}
function getDODOPool(address baseToken, address quoteToken)
external
view
returns (address[] memory pools)
{
return _REGISTRY_[baseToken][quoteToken];
}
function getDODOPoolBidirection(address token0, address token1)
external
view
returns (address[] memory baseToken0Pool, address[] memory baseToken1Pool)
{
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
}
}

View File

@@ -49,8 +49,7 @@ contract Fragment is InitializableERC20 {
address collateralVault,
uint256 totalSupply,
uint256 ownerRatio,
uint256 buyoutTimestamp,
bool isOpenBuyout
uint256 buyoutTimestamp
) external {
require(!_FRAG_INITIALIZED_, "DODOFragment: ALREADY_INITIALIZED");
_FRAG_INITIALIZED_ = true;
@@ -61,7 +60,6 @@ contract Fragment is InitializableERC20 {
_VAULT_PRE_OWNER_ = vaultPreOwner;
_COLLATERAL_VAULT_ = collateralVault;
_BUYOUT_TIMESTAMP_ = buyoutTimestamp;
_IS_OPEN_BUYOUT_ = isOpenBuyout;
// init FRAG meta data
string memory prefix = "FRAG_";
@@ -81,7 +79,7 @@ contract Fragment is InitializableERC20 {
function buyout(address newVaultOwner) external {
require(_IS_OPEN_BUYOUT_, "DODOFragment: NOT_SUPPORT_BUYOUT");
require(_BUYOUT_TIMESTAMP_ == 0, "DODOFragment: NOT_SUPPORT_BUYOUT");
require(block.timestamp > _BUYOUT_TIMESTAMP_, "DODOFragment: BUYOUT_NOT_START");
require(!_IS_BUYOUT_, "DODOFragment: ALREADY_BUYOUT");
_IS_BUYOUT_ = true;
@@ -133,7 +131,7 @@ contract Fragment is InitializableERC20 {
}
function getBuyoutRequirement() external view returns (uint256 requireQuote){
require(_IS_OPEN_BUYOUT_, "NOT SUPPORT BUYOUT");
require(_BUYOUT_TIMESTAMP_ == 0, "NOT SUPPORT BUYOUT");
require(!_IS_BUYOUT_, "ALREADY BUYOUT");
uint256 price = IDVM(_DVM_).getMidPrice();
requireQuote = DecimalMath.mulCeil(price, totalSupply);

View File

@@ -16,8 +16,7 @@ interface IFragment {
address collateralVault,
uint256 totalSupply,
uint256 ownerRatio,
uint256 buyoutTimestamp,
bool isOpenBuyout
uint256 buyoutTimestamp
) external;
function buyout(address newVaultOwner) external;

View File

@@ -13,7 +13,8 @@ import {IERC20} from "../../intf/IERC20.sol";
import {IWETH} from "../../intf/IWETH.sol";
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
import {ICollateralVault} from "../../CollateralVault/intf/ICollateralVault.sol";
import {IDODOV2} from "../intf/IDODOV2.sol";
import {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol";
import {IConstFeeRateModel} from "../../lib/ConstFeeRateModel.sol";
import {IFragment} from "../../GeneralizedFragment/intf/IFragment.sol";
import {IFeeDistributor} from "../../intf/IFeeDistributor.sol";
import {IDODONFTRegistry} from "../../Factory/Registries/DODONFTRegistry.sol";
@@ -41,15 +42,20 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
address public immutable _CLONE_FACTORY_;
address public immutable _DVM_FACTORY_;
address public immutable _NFT_REGISTY_;
address public immutable _DEFAULT_MAINTAINER_;
address public _VAULT_TEMPLATE_;
address public _FRAG_TEMPLATE_;
address public _FEE_TEMPLATE_;
address public _DVM_TEMPLATE_;
address public _MTFEE_TEMPLATE_;
// ============ Events ============
event ChangeVaultTemplate(address newVaultTemplate);
event ChangeFragTemplate(address newFragTemplate);
event ChangeFeeTemplate(address newFeeTemplate);
event ChangeMtFeeTemplate(address newMtFeeTemplate);
event ChangeDvmTemplate(address newDvmTemplate);
event CreateNFTCollateralVault(address creator, address vault, string name, string baseURI);
event CreateFragment(address vault, address fragment, address dvm, address feeDistributor);
event Buyout(address from, address fragment, uint256 amount);
@@ -65,18 +71,24 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
address payable weth,
address dodoApproveProxy,
address dvmFactory,
address defaultMaintainer,
address vaultTemplate,
address fragTemplate,
address feeTemplate,
address dvmTemplate,
address mtFeeTemplate,
address nftRegistry
) public {
_CLONE_FACTORY_ = cloneFactory;
_WETH_ = weth;
_DODO_APPROVE_PROXY_ = dodoApproveProxy;
_DVM_FACTORY_ = dvmFactory;
_DEFAULT_MAINTAINER_ = defaultMaintainer;
_VAULT_TEMPLATE_ = vaultTemplate;
_FRAG_TEMPLATE_ = fragTemplate;
_FEE_TEMPLATE_ = feeTemplate;
_DVM_TEMPLATE_ = dvmTemplate;
_MTFEE_TEMPLATE_ = mtFeeTemplate;
_NFT_REGISTY_ = nftRegistry;
}
@@ -88,45 +100,15 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
function createFragment(
address quoteToken,
address collateralVault,
address vaultPreOwner,
address stakeToken,
uint256[] calldata dvmParams, //0 - lpFeeRate, 1 - I, 2 - K
uint256[] calldata dvmParams, //0 - lpFeeRate, 1 - mtFeeRate 2 - I, 3 - K
uint256[] calldata fragParams, //0 - totalSupply, 1 - ownerRatio, 2 - buyoutTimestamp
bool isOpenBuyout
bool isOpenTwap
) external returns (address newFragment, address newDvm, address newFeeDistributor) {
require(msg.sender == collateralVault, "NEED_BE_CALLED_BY_VAULT");
newFragment = ICloneFactory(_CLONE_FACTORY_).clone(_FRAG_TEMPLATE_);
address _quoteToken = quoteToken == _ETH_ADDRESS_ ? _WETH_ : quoteToken;
{
uint256[] memory _dvmParams = dvmParams;
uint256[] memory _fragParams = fragParams;
newDvm = IDODOV2(_DVM_FACTORY_).createDODOVendingMachine(
newFragment,
_quoteToken,
_dvmParams[0],
_dvmParams[1],
_dvmParams[2],
false
);
IFragment(newFragment).init(
newDvm,
vaultPreOwner,
msg.sender,
_fragParams[0],
_fragParams[1],
_fragParams[2],
isOpenBuyout
);
}
ICollateralVault(msg.sender).directTransferOwnership(newFragment);
if(stakeToken == address(0)) {
newFeeDistributor = address(0);
} else {
@@ -134,7 +116,34 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
IFeeDistributor(newFeeDistributor).init(newFragment, _quoteToken, stakeToken);
}
IDODONFTRegistry(_NFT_REGISTY_).addRegistry(msg.sender, newFragment, newFeeDistributor, newDvm);
{
uint256[] memory _dvmParams = dvmParams;
uint256[] memory _fragParams = fragParams;
newDvm = ICloneFactory(_CLONE_FACTORY_).clone(_DVM_TEMPLATE_);
IDVM(newDvm).init(
newFeeDistributor == address(0) ? _DEFAULT_MAINTAINER_ : newFeeDistributor,
newFragment,
_quoteToken,
_dvmParams[0],
_createConstantMtFeeRateModel(_dvmParams[1]),
_dvmParams[2],
_dvmParams[3],
isOpenTwap
);
IFragment(newFragment).init(
newDvm,
vaultPreOwner,
msg.sender,
_fragParams[0],
_fragParams[1],
_fragParams[2]
);
}
ICollateralVault(msg.sender).directTransferOwnership(newFragment);
IDODONFTRegistry(_NFT_REGISTY_).addRegistry(msg.sender, newFragment, _quoteToken, newFeeDistributor, newDvm);
emit CreateFragment(msg.sender, newFragment, newDvm, newFeeDistributor);
}
@@ -175,6 +184,23 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
emit ChangeFeeTemplate(newFeeTemplate);
}
function updateMtFeeTemplate(address newMtFeeTemplate) external onlyOwner {
_MTFEE_TEMPLATE_ = newMtFeeTemplate;
emit ChangeMtFeeTemplate(newMtFeeTemplate);
}
function updateDvmTemplate(address newDvmTemplate) external onlyOwner {
_DVM_TEMPLATE_ = newDvmTemplate;
emit ChangeDvmTemplate(newDvmTemplate);
}
//============= Internal ================
function _createConstantMtFeeRateModel(uint256 mtFee) internal returns (address mtFeeModel) {
mtFeeModel = ICloneFactory(_CLONE_FACTORY_).clone(_MTFEE_TEMPLATE_);
IConstFeeRateModel(mtFeeModel).init(mtFee);
}
function _deposit(
address from,

View File

@@ -60,7 +60,7 @@ contract DODOUpCpProxy is ReentrancyGuard {
newUpCrowdPooling = IDODOV2(_UPCP_FACTORY_).createCrowdPooling();
IERC20(_baseToken).safeTransferFrom(msg.sender, newUpCrowdPooling, baseInAmount);
IERC20(_baseToken).transferFrom(msg.sender, newUpCrowdPooling, baseInAmount);
newUpCrowdPooling.transfer(msg.value);

View File

@@ -6,31 +6,21 @@
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
interface IConstFeeRateModel {
function init(address owner, uint256 feeRate) external;
function init(uint256 feeRate) external;
function setFeeRate(uint256 newFeeRate) external;
function getFeeRate(address trader) external view returns (uint256);
function getFeeRate(address) external view returns (uint256);
}
contract ConstFeeRateModel is InitializableOwnable {
contract ConstFeeRateModel {
uint256 public _FEE_RATE_;
function init(address owner, uint256 feeRate) external {
initOwner(owner);
function init(uint256 feeRate) external {
_FEE_RATE_ = feeRate;
}
function setFeeRate(uint256 newFeeRate) external onlyOwner {
_FEE_RATE_ = newFeeRate;
}
function getFeeRate(address trader) external view returns (uint256) {
function getFeeRate(address) external view returns (uint256) {
return _FEE_RATE_;
}
}

28
deploy-nft.txt Normal file
View File

@@ -0,0 +1,28 @@
====================================================
network type: kovan
Deploy time: 2021/4/8 上午12:06:20
Deploy type: NFT
multiSigAddress: 0x7e83d9d94837eE82F0cc18a691da6f42F03F1d86
ERC721Address: 0xBF243C5626A0766031d57269c01F6eFd57B603fc
ERC1155Address: 0x33221F3aFC8b5F7eEB1bf6e836ECB0bA6a78759b
NFTTokenFactoryAddress: 0x57d7A27e9E7206F28fe98D0A0228a03afF5b6e77
DODONFTRegistryAddress: 0xF405372b7808363DCfbb5Eb81204889B7a69Aa3e
Init DODONFTRegistryAddress Tx: 0x1a017ebc84e8d59bc06c7b5cd104c698b4e4b2f821c4bdc0b6012ccd486dbfc1
NFTTokenFactoryAddress: 0x78B7AFf2E5fA95B1E7E16679645FB65a850ed6AB
FragmentAddress: 0x36ed21f19B0cf0c1E571A8C3A6953a5778E48B5a
====================================================
network type: kovan
Deploy time: 2021/4/8 上午12:19:47
Deploy type: NFT
multiSigAddress: 0x7e83d9d94837eE82F0cc18a691da6f42F03F1d86
FeeDistributorAddress: 0x989F9eFaA19c6A06945Db4439b9a7935dD573A66
ConstFeeRateModelAddress: 0xBDAcEcF886a4F0C509260d9678D5673C3E8fa4b7
DODONFTProxyAddress: 0x41Eb1FFC3d6474Ee4f4Aaf335a09cD411ADDDf1f
Init DODONFTProxyAddress Tx: 0x59a518cd75786b533090c83ebf8addd56ded77586ecea8d3556bf4ff37024f8e
====================================================
network type: kovan
Deploy time: 2021/4/8 上午12:27:57
Deploy type: NFT
multiSigAddress: 0x7e83d9d94837eE82F0cc18a691da6f42F03F1d86
DODOApproveProxy unlockAddProxy tx: 0xfda8786e258102a264db7642e6dcdd86780f30747eb3fc8f9bea2db7dfa8aefa
DODOApproveProxy addDODOProxy tx: 0x899bfa16da6c91141e120bb00687c614fbbe8181bdbcb027315fcc0c9a9a76c5

148
migrations/5_deploy_nft.js Normal file
View File

@@ -0,0 +1,148 @@
const fs = require("fs");
const { deploySwitch } = require('../truffle-config.js')
const file = fs.createWriteStream("../deploy-nft.txt", { 'flags': 'a' });
let logger = new console.Console(file, file);
const { GetConfig } = require("../configAdapter.js")
const DODOApproveProxy = artifacts.require("DODOApproveProxy");
const ConstFeeRateModel = artifacts.require("ConstFeeRateModel");
const NFTCollateralVault = artifacts.require("NFTCollateralVault");
const Fragment = artifacts.require("Fragment");
const FeeDistributor = artifacts.require("FeeDistributor");
const DODONFTRegistry = artifacts.require("DODONFTRegistry");
const DODONFTProxy = artifacts.require("DODONFTProxy");
const InitializableERC721 = artifacts.require("InitializableERC721");
const InitializableERC1155 = artifacts.require("InitializableERC1155");
const NFTTokenFactory = artifacts.require("NFTTokenFactory");
module.exports = async (deployer, network, accounts) => {
let CONFIG = GetConfig(network, accounts)
if (CONFIG == null) return;
//Need Deploy first
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;
let ConstFeeRateModelAddress = CONFIG.ConstFeeRateModel;
let FeeDistributorAddress = CONFIG.FeeDistributor;
let FragmentAddress = CONFIG.Fragment;
let NFTCollateralVaultAddress = CONFIG.NFTCollateralVault;
let DODONFTRegistryAddress = CONFIG.DODONFTRegistry;
let DODONFTProxyAddress = CONFIG.DODONFTProxy;
let ERC721Address = CONFIG.InitializableERC721;
let ERC1155Address = CONFIG.InitializableERC1155;
let NFTTokenFactoryAddress = CONFIG.NFTTokenFactory;
let multiSigAddress = CONFIG.multiSigAddress;
let defaultMaintainer = CONFIG.defaultMaintainer;
if (deploySwitch.DEPLOY_NFT) {
logger.log("====================================================");
logger.log("network type: " + network);
logger.log("Deploy time: " + new Date().toLocaleString());
logger.log("Deploy type: NFT");
logger.log("multiSigAddress: ", multiSigAddress)
//ERC721
if (ERC721Address == "") {
await deployer.deploy(InitializableERC721);
ERC721Address = InitializableERC721.address;
logger.log("ERC721Address: ", ERC721Address);
}
//ERC1155
if (ERC1155Address == "") {
await deployer.deploy(InitializableERC1155);
ERC1155Address = InitializableERC1155.address;
logger.log("ERC1155Address: ", ERC1155Address);
}
//NFTTokenFactory
if (NFTTokenFactoryAddress == "") {
await deployer.deploy(
NFTTokenFactory,
CloneFactoryAddress,
ERC721Address,
ERC1155Address
);
NFTTokenFactoryAddress = NFTTokenFactory.address;
logger.log("NFTTokenFactoryAddress: ", NFTTokenFactoryAddress);
}
//NFTRegister
if (DODONFTRegistryAddress == "") {
await deployer.deploy(DODONFTRegistry);
DODONFTRegistryAddress = DODONFTRegistry.address;
logger.log("DODONFTRegistryAddress: ", DODONFTRegistryAddress);
const DODONFTRegistrynstance = await DODONFTRegistry.at(DODONFTRegistryAddress);
var tx = await DODONFTRegistrynstance.initOwner(multiSigAddress);
logger.log("Init DODONFTRegistryAddress Tx:", tx.tx);
}
//Vault
if (NFTCollateralVaultAddress == "") {
await deployer.deploy(NFTCollateralVault);
NFTTokenFactoryAddress = NFTCollateralVault.address;
logger.log("NFTTokenFactoryAddress: ", NFTTokenFactoryAddress);
}
//Frag
if (FragmentAddress == "") {
await deployer.deploy(Fragment);
FragmentAddress = Fragment.address;
logger.log("FragmentAddress: ", FragmentAddress);
}
//FeeDistributor
if (FeeDistributorAddress == "") {
await deployer.deploy(FeeDistributor);
FeeDistributorAddress = FeeDistributor.address;
logger.log("FeeDistributorAddress: ", FeeDistributorAddress);
}
//ConstMtFeeModel
if (ConstFeeRateModelAddress == "") {
await deployer.deploy(ConstFeeRateModel);
ConstFeeRateModelAddress = ConstFeeRateModel.address;
logger.log("ConstFeeRateModelAddress: ", ConstFeeRateModelAddress);
}
if (DODONFTProxyAddress == "") {
await deployer.deploy(
DODONFTProxy,
CloneFactoryAddress,
WETHAddress,
DODOApproveProxyAddress,
DvmFactoryAddress,
defaultMaintainer,
NFTCollateralVaultAddress,
FragmentAddress,
FeeDistributorAddress,
DVMTemplateAddress,
ConstFeeRateModelAddress,
DODONFTRegistryAddress
);
DODONFTProxyAddress = DODONFTProxy.address;
logger.log("DODONFTProxyAddress: ", DODONFTProxyAddress);
const DODONFTProxyInstance = await DODONFTProxy.at(DODONFTProxyAddress);
var tx = await DODONFTProxyInstance.initOwner(multiSigAddress);
logger.log("Init DODONFTProxyAddress Tx:", tx.tx);
}
if (network == 'kovan' || network == 'mbtestnet') {
const DODOApproveProxyInstance = await DODOApproveProxy.at(DODOApproveProxyAddress);
var tx = await DODOApproveProxyInstance.unlockAddProxy(DODONFTProxyAddress);
logger.log("DODOApproveProxy unlockAddProxy tx: ", tx.tx);
tx = await DODOApproveProxyInstance.addDODOProxy();
logger.log("DODOApproveProxy addDODOProxy tx: ", tx.tx);
}
}
};

View File

@@ -75,7 +75,7 @@ export class DPPContext {
this.Web3 = getDefaultWeb3();
this.DPP = await contracts.newContract(contracts.DPP_NAME);
var lpFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME);
// var lpFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME);
var mtFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME);
var permissionManager = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME);
var gasPriceSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME);
@@ -96,7 +96,7 @@ export class DPPContext {
this.SpareAccounts = allAccounts.slice(2, 10);
await gasPriceSource.methods.init(this.Deployer, MAX_UINT256).send(this.sendParam(this.Deployer));
await lpFeeRateModel.methods.init(this.DPP.options.address, config.lpFeeRate).send(this.sendParam(this.Deployer));
// await lpFeeRateModel.methods.init(this.DPP.options.address, config.lpFeeRate).send(this.sendParam(this.Deployer));
await mtFeeRateModel.methods.init(this.DPP.options.address, config.mtFeeRate).send(this.sendParam(this.Deployer));
await kSource.methods.init(this.DPP.options.address, config.k).send(this.sendParam(this.Deployer));