如果想要通过合约进行交易,那么,首先应该将合约的 token
使用权限,赋给 dex
。
直接上合约。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| pragma solidity ^0.8.4;
interface functionContract { function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); }
contract MultiTrade {
constructor() { }
function getSelfApprovalAmount(address t,address b) view public returns (uint){ functionContract token = functionContract(t); return token.allowance(address(this),b); }
function getApprovalAmount(address t,address a,address b) view public returns (uint){ functionContract token = functionContract(t); return token.allowance(a,b); }
function setApproval(address token,address swapAddress) public{ functionContract tokenContract = functionContract(token); if(tokenContract.allowance(address(this),swapAddress) == 0){ tokenContract.approve(swapAddress,type(uint256).max); } } }
|