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

This commit is contained in:
牛涛涛
2020-12-21 23:27:36 +08:00
10 changed files with 141 additions and 77 deletions

View File

@@ -69,12 +69,22 @@ contract CPFunding is CPStorage {
// if quote = m*base i = 1
// if quote > m*base reverse
{
uint256 avgPrice = DecimalMath.divCeil(poolQuote, _UNUSED_BASE_);
uint256 baseDepth = DecimalMath.mulFloor(avgPrice, poolBase);
address _poolBaseToken;
address _poolQuoteToken;
uint256 _poolI;
if (poolQuote.mul(_UNUSED_BASE_) == poolQuote.mul(poolBase)) {
uint256 avgPrice = _UNUSED_BASE_ == 0
? _I_
: DecimalMath.divCeil(poolQuote, _UNUSED_BASE_);
uint256 baseDepth = DecimalMath.mulFloor(avgPrice, poolBase);
if (poolQuote == 0) {
// ask side only DVM
_poolBaseToken = address(_BASE_TOKEN_);
_poolQuoteToken = address(_QUOTE_TOKEN_);
_poolI = _I_;
} else if (poolQuote.mul(_UNUSED_BASE_) == poolQuote.mul(poolBase)) {
// standard bonding curve
_poolBaseToken = address(_BASE_TOKEN_);
_poolQuoteToken = address(_QUOTE_TOKEN_);
_poolI = 1;

View File

@@ -38,10 +38,9 @@ contract DPPAdmin is InitializableOwnable {
//For Rebase Token
function sync() external notFreezed onlyOwner {
IDPP(_DPP_).sync();
IDPP(_DPP_).ratioSync();
}
function setFreezeTimestamp(uint256 timestamp) external notFreezed onlyOwner {
_FREEZE_TIMESTAMP_ = timestamp;
}
@@ -111,17 +110,18 @@ contract DPPAdmin is InitializableOwnable {
operator == _OPERATOR_),
"RESET FORBIDDEN"
);
return IDPP(_DPP_).reset(
msg.sender,
newLpFeeRate,
newMtFeeRate,
newI,
newK,
baseOutAmount,
quoteOutAmount,
minBaseReserve,
minQuoteReserve
);
return
IDPP(_DPP_).reset(
msg.sender,
newLpFeeRate,
newMtFeeRate,
newI,
newK,
baseOutAmount,
quoteOutAmount,
minBaseReserve,
minQuoteReserve
);
}
// ============ Admin Version Control ============

View File

@@ -23,10 +23,7 @@ contract DPPVault is DPPStorage {
// ============ Events ============
event Reset(
uint256 newLpFeeRate,
uint256 newMtFeeRate
);
event Reset(uint256 newLpFeeRate, uint256 newMtFeeRate);
// ============ View Functions ============
@@ -35,14 +32,22 @@ contract DPPVault is DPPStorage {
quoteReserve = _QUOTE_RESERVE_;
}
function getUserFeeRate(address user) external view returns (uint256 lpFeeRate, uint256 mtFeeRate) {
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) {
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));
isSellAllow = (!_SELLING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
}
// ============ Get Input ============
@@ -57,7 +62,7 @@ contract DPPVault is DPPStorage {
// ============ Set States ============
function sync() external preventReentrant onlyOwner {
function ratioSync() external preventReentrant onlyOwner {
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
if (baseBalance != _BASE_RESERVE_) {
@@ -95,7 +100,10 @@ contract DPPVault is DPPStorage {
uint256 minBaseReserve,
uint256 minQuoteReserve
) public preventReentrant onlyOwner returns (bool) {
require(_BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve, "Reserve amount is not enough");
require(
_BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve,
"RESERVE_AMOUNT_IS_NOT_ENOUGH"
);
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);
_I_.set(newI);

View File

@@ -45,7 +45,7 @@ interface IDPP {
function setSell(bool open) external;
function sync() external;
function ratioSync() external;
//==============================

View File

@@ -43,7 +43,7 @@ library DODOMath {
require(V0 > 0, "TARGET_IS_ZERO");
uint256 fairAmount = i.mul(V1.sub(V2)); // i*delta
if (k == 0) {
return fairAmount;
return fairAmount.div(DecimalMath.ONE);
}
uint256 V0V0V1V2 = DecimalMath.divFloor(V0.mul(V0).div(V1), V2);
uint256 penalty = DecimalMath.mulFloor(k, V0V0V1V2); // k(V0^2/V1/V2)