update buyout

This commit is contained in:
owen05
2021-04-28 15:07:28 +08:00
parent fd0790fb44
commit 2485ab6b56
4 changed files with 30 additions and 7 deletions

View File

@@ -26,11 +26,13 @@ contract Fragment is InitializableERC20 {
bool public _IS_OPEN_BUYOUT_;
uint256 public _BUYOUT_TIMESTAMP_;
uint256 public _BUYOUT_PRICE_;
uint256 public _DEFAULT_BUYOUT_FEE_;
address public _COLLATERAL_VAULT_;
address public _VAULT_PRE_OWNER_;
address public _QUOTE_;
address public _DVM_;
address public _DEFAULT_MAINTAINER_;
bool internal _FRAG_INITIALIZED_;
@@ -49,7 +51,9 @@ contract Fragment is InitializableERC20 {
address collateralVault,
uint256 _totalSupply,
uint256 ownerRatio,
uint256 buyoutTimestamp
uint256 buyoutTimestamp,
address defaultMaintainer,
uint256 defaultBuyoutFee
) external {
require(!_FRAG_INITIALIZED_, "DODOFragment: ALREADY_INITIALIZED");
_FRAG_INITIALIZED_ = true;
@@ -60,6 +64,8 @@ contract Fragment is InitializableERC20 {
_VAULT_PRE_OWNER_ = vaultPreOwner;
_COLLATERAL_VAULT_ = collateralVault;
_BUYOUT_TIMESTAMP_ = buyoutTimestamp;
_DEFAULT_MAINTAINER_ = defaultMaintainer;
_DEFAULT_BUYOUT_FEE_ = defaultBuyoutFee;
// init FRAG meta data
string memory prefix = "FRAG_";
@@ -99,11 +105,14 @@ contract Fragment is InitializableERC20 {
);
uint256 redeemFrag = totalSupply.sub(balances[address(this)]).sub(balances[_VAULT_PRE_OWNER_]);
uint256 preOwnerQuote = payQuote.sub(DecimalMath.mulCeil(_BUYOUT_PRICE_, redeemFrag));
uint256 ownerQuoteWithoutFee = IERC20(_QUOTE_).balanceOf(address(this)).sub(DecimalMath.mulCeil(_BUYOUT_PRICE_, redeemFrag));
_clearBalance(address(this));
_clearBalance(_VAULT_PRE_OWNER_);
IERC20(_QUOTE_).safeTransfer(_VAULT_PRE_OWNER_, preOwnerQuote);
uint256 buyoutFee = DecimalMath.mulFloor(ownerQuoteWithoutFee, _DEFAULT_BUYOUT_FEE_);
IERC20(_QUOTE_).safeTransfer(_DEFAULT_MAINTAINER_, buyoutFee);
IERC20(_QUOTE_).safeTransfer(_VAULT_PRE_OWNER_, ownerQuoteWithoutFee.sub(buyoutFee));
ICollateralVault(_COLLATERAL_VAULT_).directTransferOwnership(newVaultOwner);

View File

@@ -16,7 +16,9 @@ interface IFragment {
address collateralVault,
uint256 totalSupply,
uint256 ownerRatio,
uint256 buyoutTimestamp
uint256 buyoutTimestamp,
address defaultMaintainer,
uint256 defaultBuyoutFee
) external;
function buyout(address newVaultOwner) external;

View File

@@ -49,6 +49,8 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
address public _DVM_TEMPLATE_;
address public _MTFEE_TEMPLATE_;
uint256 public _DEFAULT_BUYOUT_FEE_;
// ============ Events ============
event ChangeVaultTemplate(address newVaultTemplate);
event ChangeFragTemplate(address newFragTemplate);
@@ -59,6 +61,7 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
event CreateFragment(address vault, address fragment, address dvm, address feeDistributor);
event Buyout(address from, address fragment, uint256 amount);
event Stake(address from, address feeDistributor, uint256 amount);
event ChangeBuyoutFee(uint256 newBuyoutFee);
// ============ Modifiers ============
@@ -140,7 +143,9 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
msg.sender,
_fragParams[0],
_fragParams[1],
_fragParams[2]
_fragParams[2],
_DEFAULT_MAINTAINER_,
_DEFAULT_BUYOUT_FEE_
);
}
@@ -220,6 +225,12 @@ contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
emit ChangeDvmTemplate(newDvmTemplate);
}
function updateBuyoutFee(uint256 buyoutFee) external onlyOwner {
_DEFAULT_BUYOUT_FEE_ = buyoutFee;
emit ChangeBuyoutFee(buyoutFee);
}
//============= Internal ================
function _createConstantMtFeeRateModel(uint256 mtFee) internal returns (address mtFeeModel) {

View File

@@ -285,13 +285,14 @@ describe("DODONFT", () => {
await getUserBalance(fragAddress, fragInstance, ctx.USDT, "FRAG Before");
var requireQuote = await fragInstance.methods.getBuyoutRequirement().call();
await logGas(await ctx.NFTProxy.methods.buyout(fragAddress, requireQuote, 0), ctx.sendParam(buyer), "buyout");
await logGas(await ctx.NFTProxy.methods.buyout(fragAddress, requireQuote, 0, Math.floor(new Date().getTime() / 1000 + 60 * 10)), ctx.sendParam(buyer), "buyout");
let [authorFrag, authorQuote] = await getUserBalance(author, fragInstance, ctx.USDT, "Author After");
await getUserBalance(buyer, fragInstance, ctx.USDT, "Buyer After");
await getUserBalance(dvmAddress, fragInstance, ctx.USDT, "DVM After");
await getUserBalance(fragAddress, fragInstance, ctx.USDT, "FRAG After");
assert(authorQuote, "2034932000");
// assert(authorQuote, "2034932000");
assert(authorQuote, "10174055148");
assert(authorFrag, "0");
var vaultNewOwner = await vaultInstance.methods._OWNER_().call();