文件 1 的 1:undb_trader.sol
pragma solidity ^0.6.0;
contract Ownable {
address public owner;
constructor () public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "You is not owner");
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
}
interface ROUTER{
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
interface ERC20{
function balanceOf(address account) external returns (uint256);
function allowance(address owner, address spender) external returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
contract AUtrader is Ownable {
bool isBlocked = false;
address internal constant UNDB_ADDRESS = 0xd03B6ae96CaE26b743A6207DceE7Cbe60a425c70;
uint private licencePrice = 0;
struct FeeAddress {
address payable recipient;
bool isExist;
}
mapping (address => FeeAddress) public addresses;
ERC20 private UNDB;
constructor() public {
UNDB = ERC20(UNDB_ADDRESS);
attachAddress(msg.sender);
}
function exchange(address[] memory path, uint amountIn, uint minOutAmount, address routerAddress, bool isDeflToken) public payable returns(bool){
FeeAddress storage recipientEL = addresses[msg.sender];
require(recipientEL.isExist, "Not attached feeAddress");
require(!isBlocked, "Contract is blocked");
address recipient = recipientEL.recipient;
uint deadline = now + 120;
ERC20 token = ERC20(path[0]);
require(UNDB.balanceOf(recipient) >= licencePrice, "insufficient balance UNDB");
require(token.balanceOf(recipient) >= amountIn, "insufficient balance input token");
require(token.allowance(recipient, address(this)) >= amountIn, "Not approved amountIn");
TransferHelper.safeTransferFrom(path[0], recipient, address(this), amountIn);
if(token.allowance(address(this), routerAddress) < amountIn){
TransferHelper.safeApprove(path[0], routerAddress, amountIn * 100);
}
ROUTER router = ROUTER(routerAddress);
if(!isDeflToken){
router.swapExactTokensForTokens(amountIn, minOutAmount, path, recipient, deadline);
} else {
uint amountIn_ = token.balanceOf(address(this));
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amountIn_, minOutAmount, path, recipient, deadline);
}
}
function attachAddress(address payable feeAddress) public {
addresses[feeAddress] = FeeAddress(msg.sender, true);
}
function licencePriceChange(uint newPrice) public onlyOwner{
licencePrice = newPrice;
}
function toggleBlock() public onlyOwner {
isBlocked = !isBlocked;
}
function blockStatus() public view onlyOwner returns (bool) {
return isBlocked;
}
}
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelperUNDB::safeApprove: approve failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelperUNDB::transferFrom: transferFrom failed'
);
}
}
{
"compilationTarget": {
"browser/undb_trader.sol": "AUtrader"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}