Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2

This commit is contained in:
mingda
2020-12-18 16:14:16 +08:00
34 changed files with 720 additions and 204 deletions

View File

@@ -15,12 +15,6 @@ import {IExternalValue} from "../../lib/ExternalValue.sol";
contract DVMAdmin is InitializableOwnable {
address public _DVM_;
// ============ Events ============
event SetLpFeeRate(uint256 newLpFeeRate);
event SetMtFeeRate(uint256 newMtFeeRate);
function init(address owner, address dvm) external {
initOwner(owner);
_DVM_ = dvm;
@@ -31,8 +25,7 @@ contract DVMAdmin is InitializableOwnable {
// }
function setLpFeeRateValue(uint256 newLpFeeRate) external onlyOwner {
IExternalValue(IDVM(_DVM_)._LP_FEE_RATE_MODEL_()).set(newLpFeeRate);
emit SetLpFeeRate(newLpFeeRate);
IDVM(_DVM_).setLpFeeRateValue(newLpFeeRate);
}
// function setMtFeeRateModel(address newMtFeeRateModel) external onlyOwner {
@@ -40,8 +33,7 @@ contract DVMAdmin is InitializableOwnable {
// }
function setMtFeeRateValue(uint256 newMtFeeRate) external onlyOwner {
IExternalValue(IDVM(_DVM_)._MT_FEE_RATE_MODEL_()).set(newMtFeeRate);
emit SetMtFeeRate(newMtFeeRate);
IDVM(_DVM_).setMtFeeRateValue(newMtFeeRate);
}
// function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {

View File

@@ -15,14 +15,9 @@ import {IDODOCallee} from "../../intf/IDODOCallee.sol";
contract DVMFunding is DVMVault {
// ============ Events ============
event BuyShares(address indexed to, uint256 increaseShares, uint256 totalShares);
event BuyShares(address to, uint256 increaseShares, uint256 totalShares);
event SellShares(
address indexed payer,
address indexed to,
uint256 decreaseShares,
uint256 totalShares
);
event SellShares(address payer, address to, uint256 decreaseShares, uint256 totalShares);
// ============ Buy & Sell Shares ============
@@ -50,8 +45,8 @@ contract DVMFunding is DVMVault {
// 在提币的时候向下取整。因此永远不会出现balance为0但totalsupply不为0的情况
// 但有可能出现reserve>0但totalSupply=0的场景
if (totalSupply == 0) {
require(baseBalance >= 10**3); // 以免出现balance很大但shares很小的情况
shares = baseBalance;
require(baseBalance >= 10**3, "INSUFFICIENT_LIQUIDITY_MINED");
shares = baseBalance; // 以免出现balance很大但shares很小的情况
} else if (baseReserve > 0 && quoteReserve == 0) {
// case 2. supply when quote reserve is 0
shares = baseInput.mul(totalSupply).div(baseReserve);
@@ -62,7 +57,6 @@ contract DVMFunding is DVMVault {
uint256 mintRatio = quoteInputRatio < baseInputRatio ? quoteInputRatio : baseInputRatio;
shares = DecimalMath.mulFloor(totalSupply, mintRatio);
}
require(shares > 0, "INSUFFICIENT_LIQUIDITY_MINED");
_mint(to, shares);
_sync();
emit BuyShares(to, shares, _SHARES_[to]);

View File

@@ -80,6 +80,10 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
event SetSell(bool allow);
event SetLpFeeRate(uint256 newValue);
event SetMtFeeRate(uint256 newValue);
// ============ Setting Functions ============
function setLpFeeRateModel(address newLpFeeRateModel) external onlyOwner {
@@ -92,6 +96,16 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
_MT_FEE_RATE_MODEL_ = IFeeRateModel(newMtFeeRateModel);
}
function setLpFeeRateValue(uint256 newLpFeeRate) external onlyOwner {
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
emit SetLpFeeRate(newLpFeeRate);
}
function setMtFeeRateValue(uint256 newMtFeeRate) external onlyOwner {
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);
emit SetMtFeeRate(newMtFeeRate);
}
function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {
emit SetTradePermissionManager(address(_TRADE_PERMISSION_), newTradePermissionManager);
_TRADE_PERMISSION_ = IPermissionManager(newTradePermissionManager);

View File

@@ -28,6 +28,13 @@ contract DVMTrader is DVMVault {
address trader
);
event DODOFlashLoan(
address borrower,
address assetTo,
uint256 baseAmount,
uint256 quoteAmount
);
// ============ Modifiers ============
modifier isBuyAllow(address trader) {
@@ -70,7 +77,7 @@ contract DVMTrader is DVMVault {
address(_QUOTE_TOKEN_),
baseInput,
receiveQuoteAmount,
tx.origin
msg.sender
);
}
@@ -94,7 +101,7 @@ contract DVMTrader is DVMVault {
address(_BASE_TOKEN_),
quoteInput,
receiveBaseAmount,
tx.origin
msg.sender
);
}
@@ -112,7 +119,7 @@ contract DVMTrader is DVMVault {
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
// no input -> pure loss
require(
baseBalance >= _BASE_RESERVE_ || quoteBalance >= _QUOTE_RESERVE_,
@@ -147,11 +154,13 @@ contract DVMTrader is DVMVault {
address(_QUOTE_TOKEN_),
baseInput,
receiveQuoteAmount,
tx.origin
msg.sender
);
}
_sync();
emit DODOFlashLoan(msg.sender, assetTo, baseAmount, quoteAmount);
}
// ============ Query Functions ============

View File

@@ -35,6 +35,16 @@ contract DVMVault is DVMStorage {
quoteReserve = _QUOTE_RESERVE_;
}
function getUserFeeRate(address user) external view returns (uint256 lpFeeRate, uint256 mtFeeRate) {
lpFeeRate = _LP_FEE_RATE_MODEL_.getFeeRate(user);
mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(user);
}
function getUserTradePermission(address user) external view returns (bool isBuyAllow, bool isSellAllow) {
isBuyAllow = (!_BUYING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
isSellAllow = (!_SELLING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
}
// ============ Asset In ============
function getBaseInput() public view returns (uint256 input) {

View File

@@ -41,7 +41,11 @@ interface IDVM {
//=========== admin ==========
function setLpFeeRateModel(address newLpFeeRateModel) external;
function setLpFeeRateValue(uint256 newLpFeeRate) external;
function setMtFeeRateModel(address newMtFeeRateModel) external;
function setMtFeeRateValue(uint256 newMtFeeRate) external;
function setTradePermissionManager(address newTradePermissionManager) external;