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

@@ -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_;
}
}