合约代码如下:
function swapExactTokensForETHV3(
address tokenIn,
uint256 amountIn,
uint256 amountOutMin,
uint256 deadline,
uint24 fee,
uint256 feePercentage
) external payable{
require(feePercentage > 0 && feePercentage < 10000, "Fee percentage must be between 0 and 10000");
// Interface for the ERC20 token
IERC20 token = IERC20(tokenIn);
// Transfer tokens to this contract
require(token.transferFrom(msg.sender, address(this), amountIn), "transferFrom failed");
// Check if the contract has enough allowance, otherwise approve the maximum amount
uint256 swapAllowance = token.allowance(address(this), address(uniswapV3Router));
if (swapAllowance < amountIn) {
token.approve(address(uniswapV3Router), type(uint256).max);
}
// ExactInputSingleParams
IUniswapV3Router.ExactInputSingleParams memory params = IUniswapV3Router.ExactInputSingleParams(
tokenIn,
address(iWETH),
fee,
address(this),
deadline,
amountIn,
amountOutMin,
0
);
}
我先将数量为amountIn的代币转入合约,然后用amountIn发起swap,但是会出现转入合约的amountIn 为100,swap传入的amountIn为0.0002的情况,这是为什么呢,amountIn的值为何会改变?