Merge branch 'master' of github.com:DODOEX/dodo-smart-contract

This commit is contained in:
mingda
2020-09-15 10:36:31 +08:00
12 changed files with 2013 additions and 760 deletions

View File

@@ -16,6 +16,7 @@ import {LiquidityProvider} from "./impl/LiquidityProvider.sol";
import {Admin} from "./impl/Admin.sol";
import {DODOLpToken} from "./impl/DODOLpToken.sol";
/**
* @title DODO
* @author DODO Breeder
@@ -48,11 +49,18 @@ contract DODO is Admin, Trader, LiquidityProvider {
_QUOTE_TOKEN_ = quoteToken;
_ORACLE_ = oracle;
_DEPOSIT_BASE_ALLOWED_ = true;
_DEPOSIT_QUOTE_ALLOWED_ = true;
_TRADE_ALLOWED_ = true;
_DEPOSIT_BASE_ALLOWED_ = false;
_DEPOSIT_QUOTE_ALLOWED_ = false;
_TRADE_ALLOWED_ = false;
_GAS_PRICE_LIMIT_ = gasPriceLimit;
// Advanced controls are disabled by default
_BUYING_ALLOWED_ = true;
_SELLING_ALLOWED_ = true;
uint256 MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
_BASE_BALANCE_LIMIT_ = MAX_INT;
_QUOTE_BALANCE_LIMIT_ = MAX_INT;
_LP_FEE_RATE_ = lpFeeRate;
_MT_FEE_RATE_ = mtFeeRate;
_K_ = k;

View File

@@ -10,6 +10,7 @@ pragma experimental ABIEncoderV2;
import {Storage} from "./Storage.sol";
/**
* @title Admin
* @author DODO Breeder
@@ -92,4 +93,30 @@ contract Admin is Storage {
function enableBaseDeposit() external onlyOwner notClosed {
_DEPOSIT_BASE_ALLOWED_ = true;
}
// ============ Advanced Control Functions ============
function disableBuying() external onlySupervisorOrOwner {
_BUYING_ALLOWED_ = false;
}
function enableBuying() external onlyOwner notClosed {
_BUYING_ALLOWED_ = true;
}
function disableSelling() external onlySupervisorOrOwner {
_SELLING_ALLOWED_ = false;
}
function enableSelling() external onlyOwner notClosed {
_SELLING_ALLOWED_ = true;
}
function setBaseBalanceLimit(uint256 newBaseBalanceLimit) external onlyOwner notClosed {
_BASE_BALANCE_LIMIT_ = newBaseBalanceLimit;
}
function setQuoteBalanceLimit(uint256 newQuoteBalanceLimit) external onlyOwner notClosed {
_QUOTE_BALANCE_LIMIT_ = newQuoteBalanceLimit;
}
}

View File

@@ -15,6 +15,7 @@ import {Types} from "../lib/Types.sol";
import {IERC20} from "../intf/IERC20.sol";
import {Storage} from "./Storage.sol";
/**
* @title Settlement
* @author DODO Breeder
@@ -34,11 +35,16 @@ contract Settlement is Storage {
// ============ Assets IN/OUT Functions ============
function _baseTokenTransferIn(address from, uint256 amount) internal {
require(_BASE_BALANCE_.add(amount) <= _BASE_BALANCE_LIMIT_, "BASE_BALANCE_LIMIT_EXCEEDED");
IERC20(_BASE_TOKEN_).safeTransferFrom(from, address(this), amount);
_BASE_BALANCE_ = _BASE_BALANCE_.add(amount);
}
function _quoteTokenTransferIn(address from, uint256 amount) internal {
require(
_QUOTE_BALANCE_.add(amount) <= _QUOTE_BALANCE_LIMIT_,
"QUOTE_BALANCE_LIMIT_EXCEEDED"
);
IERC20(_QUOTE_TOKEN_).safeTransferFrom(from, address(this), amount);
_QUOTE_BALANCE_ = _QUOTE_BALANCE_.add(amount);
}

View File

@@ -16,6 +16,7 @@ import {IOracle} from "../intf/IOracle.sol";
import {IDODOLpToken} from "../intf/IDODOLpToken.sol";
import {Types} from "../lib/Types.sol";
/**
* @title Storage
* @author DODO Breeder
@@ -34,6 +35,12 @@ contract Storage is InitializableOwnable, ReentrancyGuard {
bool public _TRADE_ALLOWED_;
uint256 public _GAS_PRICE_LIMIT_;
// ============ Advanced Controls ============
bool public _BUYING_ALLOWED_;
bool public _SELLING_ALLOWED_;
uint256 public _BASE_BALANCE_LIMIT_;
uint256 public _QUOTE_BALANCE_LIMIT_;
// ============ Core Address ============
address public _SUPERVISOR_; // could freeze system in emergency
@@ -106,6 +113,6 @@ contract Storage is InitializableOwnable, ReentrancyGuard {
// ============ Version Control ============
function version() external pure returns (uint256) {
return 100; // 1.0.0
return 101; // 1.0.1
}
}

View File

@@ -16,6 +16,7 @@ import {Storage} from "./Storage.sol";
import {Pricing} from "./Pricing.sol";
import {Settlement} from "./Settlement.sol";
/**
* @title Trader
* @author DODO Breeder
@@ -40,6 +41,16 @@ contract Trader is Storage, Pricing, Settlement {
_;
}
modifier buyingAllowed() {
require(_BUYING_ALLOWED_, "BUYING_NOT_ALLOWED");
_;
}
modifier sellingAllowed() {
require(_SELLING_ALLOWED_, "SELLING_NOT_ALLOWED");
_;
}
modifier gasPriceLimit() {
require(tx.gasprice <= _GAS_PRICE_LIMIT_, "GAS_PRICE_EXCEED");
_;
@@ -51,7 +62,7 @@ contract Trader is Storage, Pricing, Settlement {
uint256 amount,
uint256 minReceiveQuote,
bytes calldata data
) external tradeAllowed gasPriceLimit preventReentrant returns (uint256) {
) external tradeAllowed sellingAllowed gasPriceLimit preventReentrant returns (uint256) {
// query price
(
uint256 receiveQuote,
@@ -95,7 +106,7 @@ contract Trader is Storage, Pricing, Settlement {
uint256 amount,
uint256 maxPayQuote,
bytes calldata data
) external tradeAllowed gasPriceLimit preventReentrant returns (uint256) {
) external tradeAllowed buyingAllowed gasPriceLimit preventReentrant returns (uint256) {
// query price
(
uint256 payQuote,