From d463dadf910e56e02a77ce83879604bba3587e01 Mon Sep 17 00:00:00 2001 From: mingda Date: Thu, 10 Dec 2020 19:46:06 +0800 Subject: [PATCH] CA add owner ratio & mt fee --- contracts/CallAuction/impl/CA.sol | 30 +++++++++++++++--------- contracts/CallAuction/impl/CAFunding.sol | 10 +++++--- contracts/CallAuction/impl/CAStorage.sol | 7 ++++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/contracts/CallAuction/impl/CA.sol b/contracts/CallAuction/impl/CA.sol index 4b9e049..1df62dc 100644 --- a/contracts/CallAuction/impl/CA.sol +++ b/contracts/CallAuction/impl/CA.sol @@ -11,6 +11,7 @@ pragma experimental ABIEncoderV2; import {CAVesting} from "./CAVesting.sol"; import {IERC20} from "../../intf/IERC20.sol"; import {IPermissionManager} from "../../lib/PermissionManager.sol"; +import {IFeeRateModel} from "../../lib/FeeRateModel.sol"; contract CA is CAVesting { function init( @@ -23,19 +24,23 @@ contract CA is CAVesting { /* Address List 0. owner - 1. baseToken - 2. quoteToken - 3. basePayBack - 4. quotePayBack - 5. permissionManager + 1. maintainer + 2. baseToken + 3. quoteToken + 4. basePayBack + 5. quotePayBack + 6. permissionManager + 7. feeRateModel */ initOwner(addressList[0]); - _BASE_TOKEN_ = IERC20(addressList[1]); - _QUOTE_TOKEN_ = IERC20(addressList[2]); - _BASE_PAY_BACK_ = addressList[3]; - _QUOTE_PAY_BACK_ = addressList[4]; - _BIDDER_PERMISSION_ = IPermissionManager(addressList[5]); + _MAINTAINER_ = addressList[1]; + _BASE_TOKEN_ = IERC20(addressList[2]); + _QUOTE_TOKEN_ = IERC20(addressList[3]); + _BASE_PAY_BACK_ = addressList[4]; + _QUOTE_PAY_BACK_ = addressList[5]; + _BIDDER_PERMISSION_ = IPermissionManager(addressList[6]); + _MT_FEE_RATE_MODEL_ = IFeeRateModel(addressList[7]); /* Time Line @@ -67,13 +72,15 @@ contract CA is CAVesting { 1. cliff rate 2. k 3. i + 4. owner ratio */ require( valueList[1] <= 10**18 && valueList[2] <= 10**18 && valueList[3] > 0 && - valueList[3] <= 10**36, + valueList[3] <= 10**36 && + valueList[4] <= 10**18, "VALUE_RANGE_WRONG" ); @@ -81,6 +88,7 @@ contract CA is CAVesting { _CLIFF_RATE_ = valueList[1]; _K_ = valueList[2]; _I_ = valueList[3]; + _OWNER_RATIO_ = valueList[4]; // ============ External Call Data ============ diff --git a/contracts/CallAuction/impl/CAFunding.sol b/contracts/CallAuction/impl/CAFunding.sol index 8fc8278..a9899f0 100644 --- a/contracts/CallAuction/impl/CAFunding.sol +++ b/contracts/CallAuction/impl/CAFunding.sol @@ -35,8 +35,10 @@ contract CAFunding is CAStorage { function bid(address to) external phaseBid preventReentrant isBidderAllow(to) { uint256 input = _getQuoteInput(); - _QUOTE_SHARES_[to] = _QUOTE_SHARES_[to].add(input); - _TOTAL_QUOTE_SHARES_ = _TOTAL_QUOTE_SHARES_.add(input); + uint256 mtFee = DecimalMath.mulFloor(input, _MT_FEE_RATE_MODEL_.getFeeRate(to)); + _transferQuoteOut(_MAINTAINER_, mtFee); + _QUOTE_SHARES_[to] = _QUOTE_SHARES_[to].add(input.sub(mtFee)); + _TOTAL_QUOTE_SHARES_ = _TOTAL_QUOTE_SHARES_.add(input.sub(mtFee)); _sync(); } @@ -64,7 +66,9 @@ contract CAFunding is CAStorage { // 3. used quote token uint256 usedQuote = _QUOTE_CAP_ <= quoteBalance ? _QUOTE_CAP_ : quoteBalance; - _transferQuoteOut(_QUOTE_PAY_BACK_, usedQuote); + uint256 ownerQuote = DecimalMath.mulFloor(usedQuote, _OWNER_RATIO_); + _transferQuoteOut(_OWNER_, ownerQuote); + _transferQuoteOut(_QUOTE_PAY_BACK_, usedQuote.sub(usedQuote)); // 4. leave unused quote token in contract _TOTAL_UNUSED_QUOTE_ = quoteBalance.sub(usedQuote); diff --git a/contracts/CallAuction/impl/CAStorage.sol b/contracts/CallAuction/impl/CAStorage.sol index c458c39..75e7c6f 100644 --- a/contracts/CallAuction/impl/CAStorage.sol +++ b/contracts/CallAuction/impl/CAStorage.sol @@ -11,6 +11,7 @@ pragma experimental ABIEncoderV2; import {InitializableOwnable} from "../../lib/InitializableOwnable.sol"; import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol"; import {IPermissionManager} from "../../lib/PermissionManager.sol"; +import {IFeeRateModel} from "../../lib/FeeRateModel.sol"; import {SafeMath} from "../../lib/SafeMath.sol"; import {IERC20} from "../../intf/IERC20.sol"; @@ -34,6 +35,7 @@ contract CAStorage is InitializableOwnable, ReentrancyGuard { // ============ Distribution Parameters ============ uint256 _QUOTE_CAP_; + uint256 _OWNER_RATIO_; address public _BASE_PAY_BACK_; address public _QUOTE_PAY_BACK_; bytes _BASE_PAY_BACK_CALL_DATA_; @@ -48,6 +50,11 @@ contract CAStorage is InitializableOwnable, ReentrancyGuard { mapping(address => uint256) internal _QUOTE_SHARES_; mapping(address => bool) internal _QUOTE_CLAIMED_; mapping(address => uint256) internal _CLAIMED_BASE_; + + // ============ Advanced Control ============ + + address public _MAINTAINER_; + IFeeRateModel public _MT_FEE_RATE_MODEL_; IPermissionManager public _BIDDER_PERMISSION_; // ============ Time Lock ============