Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user