文件 3 的 3:test-chicontract.sol
pragma solidity 0.6.6;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC20/IERC20.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/TransferHelper.sol";
interface iCHI {
function freeFromUpTo(address from, uint256 value) external returns (uint256);
}
contract ChiTest{
address internal CHITOKEN = 0x0000000000004946c0e9F43F4Dee607b0eF1fA1c;
iCHI public CHI = iCHI(CHITOKEN);
address owner = msg.sender;
uint256 test = 0;
modifier discountCHI() {
uint256 gasStart = gasleft();
_;
uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length;
CHI.freeFromUpTo(address(this), (gasSpent + 14154) / 41947);
}
function recoverERC20(address tokenAddress) public {
TransferHelper.safeTransfer(tokenAddress,owner,getTokenBalance(tokenAddress));
}
function getTokenBalanceOfAddr(address tokenAddress,address dest) public view returns (uint256){
return IERC20(tokenAddress).balanceOf(dest);
}
function getTokenBalance(address tokenAddress) public view returns (uint256){
return getTokenBalanceOfAddr(tokenAddress,address(this));
}
function updateNum(uint256 newNum) external discountCHI{
test = newNum;
}
}
{
"compilationTarget": {
"browser/test-chicontract.sol": "ChiTest"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}