set gas price to external contract
This commit is contained in:
@@ -10,6 +10,7 @@ pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IFeeRateModel} from "../../intf/IFeeRateModel.sol";
|
||||
import {IPermissionManager} from "../../lib/PermissionManager.sol";
|
||||
import {IGasPriceSource} from "../../lib/GasPriceSource.sol";
|
||||
import {DVMTrader} from "./DVMTrader.sol";
|
||||
import {DVMFunding} from "./DVMFunding.sol";
|
||||
import {DVMVault} from "./DVMVault.sol";
|
||||
@@ -22,6 +23,7 @@ contract DVM is DVMTrader, DVMFunding {
|
||||
address lpFeeRateModel,
|
||||
address mtFeeRateModel,
|
||||
address tradePermissionManager,
|
||||
address gasPriceSource,
|
||||
uint256 i,
|
||||
uint256 k
|
||||
) external {
|
||||
@@ -32,10 +34,10 @@ contract DVM is DVMTrader, DVMFunding {
|
||||
_LP_FEE_RATE_MODEL_ = IFeeRateModel(lpFeeRateModel);
|
||||
_MT_FEE_RATE_MODEL_ = IFeeRateModel(mtFeeRateModel);
|
||||
_TRADE_PERMISSION_ = IPermissionManager(tradePermissionManager);
|
||||
_GAS_PRICE_LIMIT_ = IGasPriceSource(gasPriceSource);
|
||||
_MAINTAINER_ = maintainer;
|
||||
_I_ = i;
|
||||
_K_ = k;
|
||||
_GAS_PRICE_LIMIT_ = uint256(-1);
|
||||
}
|
||||
|
||||
// ============ Version Control ============
|
||||
|
||||
@@ -14,6 +14,7 @@ import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {DODOMath} from "../../lib/DODOMath.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
import {IPermissionManager} from "../../lib/PermissionManager.sol";
|
||||
import {IGasPriceSource} from "../../lib/GasPriceSource.sol";
|
||||
import {IFeeRateModel} from "../../intf/IFeeRateModel.sol";
|
||||
import {DVMVault} from "./DVMVault.sol";
|
||||
|
||||
@@ -22,7 +23,7 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||
|
||||
// ============ Variables for Control ============
|
||||
|
||||
uint256 public _GAS_PRICE_LIMIT_;
|
||||
IGasPriceSource public _GAS_PRICE_LIMIT_;
|
||||
|
||||
// ============ Advanced Controls ============
|
||||
|
||||
@@ -62,6 +63,11 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||
_;
|
||||
}
|
||||
|
||||
modifier limitGasPrice() {
|
||||
require(tx.gasprice <= _GAS_PRICE_LIMIT_.getGasPrice(), "GAS_PRICE_EXCEED");
|
||||
_;
|
||||
}
|
||||
|
||||
// ============ Helper Functions ============
|
||||
|
||||
function calculateBase0(uint256 baseAmount, uint256 quoteAmount) public view returns (uint256) {
|
||||
@@ -93,8 +99,8 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||
_MAINTAINER_ = newMaintainer;
|
||||
}
|
||||
|
||||
function setGasPriceLimit(uint256 newGasPriceLimit) external onlyOwner {
|
||||
_GAS_PRICE_LIMIT_ = newGasPriceLimit;
|
||||
function setGasPriceSource(address newGasPriceLimitSource) external onlyOwner {
|
||||
_GAS_PRICE_LIMIT_ = IGasPriceSource(newGasPriceLimitSource);
|
||||
}
|
||||
|
||||
function setBuy(bool open) external onlyOwner {
|
||||
|
||||
@@ -20,6 +20,7 @@ contract DVMTrader is DVMStorage {
|
||||
function sellBase(address to)
|
||||
external
|
||||
preventReentrant
|
||||
limitGasPrice
|
||||
isSellAllow(to)
|
||||
returns (uint256 receiveQuoteAmount)
|
||||
{
|
||||
@@ -37,6 +38,7 @@ contract DVMTrader is DVMStorage {
|
||||
function sellQuote(address to)
|
||||
external
|
||||
preventReentrant
|
||||
limitGasPrice
|
||||
isBuyAllow(to)
|
||||
returns (uint256 receiveBaseAmount)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user