simplify code to reduce deploy gas cost
This commit is contained in:
@@ -38,8 +38,7 @@ contract DODOZoo is Ownable {
|
|||||||
uint256 k,
|
uint256 k,
|
||||||
uint256 gasPriceLimit
|
uint256 gasPriceLimit
|
||||||
) public onlyOwner returns (address) {
|
) public onlyOwner returns (address) {
|
||||||
require(!isDODORegistered(baseToken, quoteToken), "DODO_IS_REGISTERED");
|
require(!isDODORegistered(baseToken, quoteToken), "DODO_REGISTERED");
|
||||||
require(baseToken != quoteToken, "BASE_IS_SAME_WITH_QUOTE");
|
|
||||||
address newBornDODO = address(new DODO());
|
address newBornDODO = address(new DODO());
|
||||||
IDODO(newBornDODO).init(
|
IDODO(newBornDODO).init(
|
||||||
supervisor,
|
supervisor,
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
// ============ Modifiers ============
|
// ============ Modifiers ============
|
||||||
|
|
||||||
modifier depositQuoteAllowed() {
|
modifier depositQuoteAllowed() {
|
||||||
require(_DEPOSIT_QUOTE_ALLOWED_, "DEPOSIT_QUOTE_TOKEN_NOT_ALLOWED");
|
require(_DEPOSIT_QUOTE_ALLOWED_, "DEPOSIT_QUOTE_NOT_ALLOWED");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifier depositBaseAllowed() {
|
modifier depositBaseAllowed() {
|
||||||
require(_DEPOSIT_BASE_ALLOWED_, "DEPOSIT_BASE_TOKEN_NOT_ALLOWED");
|
require(_DEPOSIT_BASE_ALLOWED_, "DEPOSIT_BASE_NOT_ALLOWED");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
|
|
||||||
// handle penalty, penalty may exceed amount
|
// handle penalty, penalty may exceed amount
|
||||||
uint256 penalty = getWithdrawQuotePenalty(amount);
|
uint256 penalty = getWithdrawQuotePenalty(amount);
|
||||||
require(penalty < amount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
|
require(penalty < amount, "PENALTY_EXCEED");
|
||||||
|
|
||||||
// settlement
|
// settlement
|
||||||
_TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(amount);
|
_TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(amount);
|
||||||
@@ -172,7 +172,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
|
|
||||||
// handle penalty, penalty may exceed amount
|
// handle penalty, penalty may exceed amount
|
||||||
uint256 penalty = getWithdrawBasePenalty(amount);
|
uint256 penalty = getWithdrawBasePenalty(amount);
|
||||||
require(penalty <= amount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
|
require(penalty <= amount, "PENALTY_EXCEED");
|
||||||
|
|
||||||
// settlement
|
// settlement
|
||||||
_TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(amount);
|
_TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(amount);
|
||||||
@@ -194,7 +194,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
|
|
||||||
// handle penalty, penalty may exceed amount
|
// handle penalty, penalty may exceed amount
|
||||||
uint256 penalty = getWithdrawQuotePenalty(withdrawAmount);
|
uint256 penalty = getWithdrawQuotePenalty(withdrawAmount);
|
||||||
require(penalty <= withdrawAmount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
|
require(penalty <= withdrawAmount, "PENALTY_EXCEED");
|
||||||
|
|
||||||
// settlement
|
// settlement
|
||||||
_TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(withdrawAmount);
|
_TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(withdrawAmount);
|
||||||
@@ -214,7 +214,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
|
|
||||||
// handle penalty, penalty may exceed amount
|
// handle penalty, penalty may exceed amount
|
||||||
uint256 penalty = getWithdrawBasePenalty(withdrawAmount);
|
uint256 penalty = getWithdrawBasePenalty(withdrawAmount);
|
||||||
require(penalty <= withdrawAmount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
|
require(penalty <= withdrawAmount, "PENALTY_EXCEED");
|
||||||
|
|
||||||
// settlement
|
// settlement
|
||||||
_TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(withdrawAmount);
|
_TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(withdrawAmount);
|
||||||
@@ -269,7 +269,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWithdrawQuotePenalty(uint256 amount) public view returns (uint256 penalty) {
|
function getWithdrawQuotePenalty(uint256 amount) public view returns (uint256 penalty) {
|
||||||
require(amount <= _QUOTE_BALANCE_, "DODO_QUOTE_TOKEN_BALANCE_NOT_ENOUGH");
|
require(amount <= _QUOTE_BALANCE_, "DODO_QUOTE_BALANCE_NOT_ENOUGH");
|
||||||
if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
|
if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
|
||||||
uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
|
uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
|
||||||
uint256 price = getOraclePrice();
|
uint256 price = getOraclePrice();
|
||||||
@@ -292,7 +292,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWithdrawBasePenalty(uint256 amount) public view returns (uint256 penalty) {
|
function getWithdrawBasePenalty(uint256 amount) public view returns (uint256 penalty) {
|
||||||
require(amount <= _BASE_BALANCE_, "DODO_BASE_TOKEN_BALANCE_NOT_ENOUGH");
|
require(amount <= _BASE_BALANCE_, "DODO_BASE_BALANCE_NOT_ENOUGH");
|
||||||
if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
|
if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
|
||||||
uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
|
uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
|
||||||
uint256 price = getOraclePrice();
|
uint256 price = getOraclePrice();
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ contract Pricing is Storage {
|
|||||||
view
|
view
|
||||||
returns (uint256 payQuoteToken)
|
returns (uint256 payQuoteToken)
|
||||||
{
|
{
|
||||||
require(amount < targetBaseTokenAmount, "DODO_BASE_TOKEN_BALANCE_NOT_ENOUGH");
|
require(amount < targetBaseTokenAmount, "DODO_BASE_BALANCE_NOT_ENOUGH");
|
||||||
uint256 B2 = targetBaseTokenAmount.sub(amount);
|
uint256 B2 = targetBaseTokenAmount.sub(amount);
|
||||||
payQuoteToken = _RAboveIntegrate(targetBaseTokenAmount, targetBaseTokenAmount, B2);
|
payQuoteToken = _RAboveIntegrate(targetBaseTokenAmount, targetBaseTokenAmount, B2);
|
||||||
return payQuoteToken;
|
return payQuoteToken;
|
||||||
@@ -111,7 +111,7 @@ contract Pricing is Storage {
|
|||||||
uint256 baseBalance,
|
uint256 baseBalance,
|
||||||
uint256 targetBaseAmount
|
uint256 targetBaseAmount
|
||||||
) internal view returns (uint256 payQuoteToken) {
|
) internal view returns (uint256 payQuoteToken) {
|
||||||
require(amount < baseBalance, "DODO_BASE_TOKEN_BALANCE_NOT_ENOUGH");
|
require(amount < baseBalance, "DODO_BASE_BALANCE_NOT_ENOUGH");
|
||||||
uint256 B2 = baseBalance.sub(amount);
|
uint256 B2 = baseBalance.sub(amount);
|
||||||
return _RAboveIntegrate(targetBaseAmount, baseBalance, B2);
|
return _RAboveIntegrate(targetBaseAmount, baseBalance, B2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ contract Settlement is Storage {
|
|||||||
|
|
||||||
// claim remaining assets after final settlement
|
// claim remaining assets after final settlement
|
||||||
function claim() external preventReentrant {
|
function claim() external preventReentrant {
|
||||||
require(_CLOSED_, "DODO_IS_NOT_CLOSED");
|
require(_CLOSED_, "DODO_NOT_CLOSED");
|
||||||
require(!_CLAIMED_[msg.sender], "ALREADY_CLAIMED");
|
require(!_CLAIMED_[msg.sender], "ALREADY_CLAIMED");
|
||||||
_CLAIMED_[msg.sender] = true;
|
_CLAIMED_[msg.sender] = true;
|
||||||
uint256 quoteAmount = DecimalMath.mul(
|
uint256 quoteAmount = DecimalMath.mul(
|
||||||
|
|||||||
@@ -72,16 +72,16 @@ contract Storage is Ownable, ReentrancyGuard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modifier notClosed() {
|
modifier notClosed() {
|
||||||
require(!_CLOSED_, "DODO_IS_CLOSED");
|
require(!_CLOSED_, "DODO_CLOSED");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Helper Functions ============
|
// ============ Helper Functions ============
|
||||||
|
|
||||||
function _checkDODOParameters() internal view returns (uint256) {
|
function _checkDODOParameters() internal view returns (uint256) {
|
||||||
require(_K_ < DecimalMath.ONE, "K_MUST_BE_LESS_THAN_ONE");
|
require(_K_ < DecimalMath.ONE, "K>=1");
|
||||||
require(_K_ > 0, "K_MUST_BE_GREATER_THAN_ZERO");
|
require(_K_ > 0, "K=0");
|
||||||
require(_LP_FEE_RATE_.add(_MT_FEE_RATE_) < DecimalMath.ONE, "FEE_MUST_BE_LESS_THAN_ONE");
|
require(_LP_FEE_RATE_.add(_MT_FEE_RATE_) < DecimalMath.ONE, "FEE_RATE>=1");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOraclePrice() public view returns (uint256) {
|
function getOraclePrice() public view returns (uint256) {
|
||||||
|
|||||||
@@ -70,18 +70,4 @@ interface IERC20 {
|
|||||||
address recipient,
|
address recipient,
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) external returns (bool);
|
) external returns (bool);
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Emitted when `value` tokens are moved from one account (`from`) to
|
|
||||||
* another (`to`).
|
|
||||||
*
|
|
||||||
* Note that `value` may be zero.
|
|
||||||
*/
|
|
||||||
event Transfer(address indexed from, address indexed to, uint256 value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
|
|
||||||
* a call to {approve}. `value` is the new allowance.
|
|
||||||
*/
|
|
||||||
event Approval(address indexed owner, address indexed spender, uint256 value);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ contract ReentrancyGuard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modifier preventReentrant() {
|
modifier preventReentrant() {
|
||||||
require(_ENTER_STATUS_ != Types.EnterStatus.ENTERED, "ReentrancyGuard: reentrant call");
|
require(_ENTER_STATUS_ != Types.EnterStatus.ENTERED, "REENTRANT");
|
||||||
_ENTER_STATUS_ = Types.EnterStatus.ENTERED;
|
_ENTER_STATUS_ = Types.EnterStatus.ENTERED;
|
||||||
_;
|
_;
|
||||||
_ENTER_STATUS_ = Types.EnterStatus.NOT_ENTERED;
|
_ENTER_STATUS_ = Types.EnterStatus.NOT_ENTERED;
|
||||||
|
|||||||
Reference in New Issue
Block a user