I am building a contract to automatically swap a token with fee on transfer (I am using as a test this token t: 0x576e2BeD8F7b46D34016198911Cdf9886f78bea7
) via UniswapRouter02 swapExactTokensForTokensSupportingFeeOnTransferTokens. The recipient of the swap should be my contract as further functions have to be applied. I am using this address for UniswapRouter02 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
. I am running a local fork of Ethereum through HardHat.
In Solidity I am using this snippet:
function swapExactInputSingleHopV2(uint amountIn, uint amountOutMin, address t) public {
IERC20(t).transferFrom(msg.sender, myContractAddress, amountIn);
IERC20(t).approve(routerV2, amountIn);
address[] memory path = new address[](2);
path[0] = t;
path[1] = weth;
ISwapRouter02V2(routerV2).swapExactTokensForTokensSupportingFeeOnTransferTokens(amountIn, amountOutMin, path, myContractAddress, block.timestamp);
}
interface ISwapRouter02V2 {
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
While through ethers.js I am approving the following:
await tContract.connect(connectedWallet).approve(myContractAddress, ethers.utils.parseUnits("10000.0", 9).toString());
await tContract.connect(connectedWallet).approve(routerV2, ethers.utils.parseUnits("10000.0", 9).toString());
When testing on Remix IDE (pragma solidity >=0.8.2 <0.9.0; using 0.8.26, default version cancun), I call swapExactInputSingleHopV2, and it works correctly only for amounts <100 of the token t, while it throws TransferHelper: TRANSFER_FROM_FAILED
for any other amount higher than 99, despite having approved way more than 10000 * 10^9.
Do you have any idea on how to solve this problem?
MisterBob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.