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

This commit is contained in:
mingda
2020-11-18 17:58:36 +08:00
17 changed files with 954 additions and 104 deletions

View File

@@ -0,0 +1,29 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {Ownable} from "./Ownable.sol";
interface IGasPriceSource {
function setGasPrice(uint256) external;
function getGasPrice() external view returns (uint256);
}
contract GasPriceSource is IGasPriceSource, Ownable {
uint256 public _GAS_PRICE_;
function setGasPrice(uint256 gasPrice) external override {
_GAS_PRICE_ = gasPrice;
}
function getGasPrice() external override view returns (uint256) {
return _GAS_PRICE_;
}
}

View File

@@ -12,18 +12,26 @@ import {IERC20} from "../intf/IERC20.sol";
import {SafeERC20} from "./SafeERC20.sol";
library UniversalERC20 {
using SafeMath for uint256;
using SafeERC20 for IERC20;
IERC20 private constant ZERO_ADDRESS = IERC20(0x0000000000000000000000000000000000000000);
IERC20 private constant ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
function universalTransfer(IERC20 token, address to, uint256 amount) internal {
function universalTransfer(
IERC20 token,
address to,
uint256 amount
) internal {
universalTransfer(token, to, amount, false);
}
function universalTransfer(IERC20 token, address to, uint256 amount, bool mayFail) internal returns(bool) {
function universalTransfer(
IERC20 token,
address to,
uint256 amount,
bool mayFail
) internal returns (bool) {
if (amount == 0) {
return true;
}
@@ -41,13 +49,33 @@ library UniversalERC20 {
}
}
function universalApprove(IERC20 token, address to, uint256 amount) internal {
function universalApprove(
IERC20 token,
address to,
uint256 amount
) internal {
if (token != ZERO_ADDRESS && token != ETH_ADDRESS) {
token.safeApprove(to, amount);
if (amount == 0) {
token.safeApprove(to, 0);
return;
}
uint256 allowance = token.allowance(address(this), to);
if (allowance < amount) {
if (allowance > 0) {
token.safeApprove(to, 0);
}
token.safeApprove(to, amount);
}
}
}
function universalTransferFrom(IERC20 token, address from, address to, uint256 amount) internal {
function universalTransferFrom(
IERC20 token,
address from,
address to,
uint256 amount
) internal {
if (amount == 0) {
return;
}
@@ -72,4 +100,4 @@ library UniversalERC20 {
return token.balanceOf(who);
}
}
}
}