simplify code to reduce deploy gas cost

This commit is contained in:
mingda
2020-07-11 16:21:54 +08:00
parent a955c7faca
commit 2c8ba643a8
7 changed files with 17 additions and 32 deletions

View File

@@ -38,8 +38,7 @@ contract DODOZoo is Ownable {
uint256 k,
uint256 gasPriceLimit
) public onlyOwner returns (address) {
require(!isDODORegistered(baseToken, quoteToken), "DODO_IS_REGISTERED");
require(baseToken != quoteToken, "BASE_IS_SAME_WITH_QUOTE");
require(!isDODORegistered(baseToken, quoteToken), "DODO_REGISTERED");
address newBornDODO = address(new DODO());
IDODO(newBornDODO).init(
supervisor,

View File

@@ -49,12 +49,12 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
// ============ Modifiers ============
modifier depositQuoteAllowed() {
require(_DEPOSIT_QUOTE_ALLOWED_, "DEPOSIT_QUOTE_TOKEN_NOT_ALLOWED");
require(_DEPOSIT_QUOTE_ALLOWED_, "DEPOSIT_QUOTE_NOT_ALLOWED");
_;
}
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
uint256 penalty = getWithdrawQuotePenalty(amount);
require(penalty < amount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
require(penalty < amount, "PENALTY_EXCEED");
// settlement
_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
uint256 penalty = getWithdrawBasePenalty(amount);
require(penalty <= amount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
require(penalty <= amount, "PENALTY_EXCEED");
// settlement
_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
uint256 penalty = getWithdrawQuotePenalty(withdrawAmount);
require(penalty <= withdrawAmount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
require(penalty <= withdrawAmount, "PENALTY_EXCEED");
// settlement
_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
uint256 penalty = getWithdrawBasePenalty(withdrawAmount);
require(penalty <= withdrawAmount, "COULD_NOT_AFFORD_LIQUIDITY_PENALTY");
require(penalty <= withdrawAmount, "PENALTY_EXCEED");
// settlement
_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) {
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) {
uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
uint256 price = getOraclePrice();
@@ -292,7 +292,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
}
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) {
uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
uint256 price = getOraclePrice();

View File

@@ -48,7 +48,7 @@ contract Pricing is Storage {
view
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);
payQuoteToken = _RAboveIntegrate(targetBaseTokenAmount, targetBaseTokenAmount, B2);
return payQuoteToken;
@@ -111,7 +111,7 @@ contract Pricing is Storage {
uint256 baseBalance,
uint256 targetBaseAmount
) 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);
return _RAboveIntegrate(targetBaseAmount, baseBalance, B2);
}

View File

@@ -113,7 +113,7 @@ contract Settlement is Storage {
// claim remaining assets after final settlement
function claim() external preventReentrant {
require(_CLOSED_, "DODO_IS_NOT_CLOSED");
require(_CLOSED_, "DODO_NOT_CLOSED");
require(!_CLAIMED_[msg.sender], "ALREADY_CLAIMED");
_CLAIMED_[msg.sender] = true;
uint256 quoteAmount = DecimalMath.mul(

View File

@@ -72,16 +72,16 @@ contract Storage is Ownable, ReentrancyGuard {
}
modifier notClosed() {
require(!_CLOSED_, "DODO_IS_CLOSED");
require(!_CLOSED_, "DODO_CLOSED");
_;
}
// ============ Helper Functions ============
function _checkDODOParameters() internal view returns (uint256) {
require(_K_ < DecimalMath.ONE, "K_MUST_BE_LESS_THAN_ONE");
require(_K_ > 0, "K_MUST_BE_GREATER_THAN_ZERO");
require(_LP_FEE_RATE_.add(_MT_FEE_RATE_) < DecimalMath.ONE, "FEE_MUST_BE_LESS_THAN_ONE");
require(_K_ < DecimalMath.ONE, "K>=1");
require(_K_ > 0, "K=0");
require(_LP_FEE_RATE_.add(_MT_FEE_RATE_) < DecimalMath.ONE, "FEE_RATE>=1");
}
function getOraclePrice() public view returns (uint256) {

View File

@@ -70,18 +70,4 @@ interface IERC20 {
address recipient,
uint256 amount
) 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);
}

View File

@@ -24,7 +24,7 @@ contract ReentrancyGuard {
}
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.NOT_ENTERED;