Spent way too long trying to figure this out. I have a contract that mocks "plain no flashloan" arbitrage, it has this test function
function test(
IRouter02 _target,
address[] memory _path,
uint256 _qtyIn,
uint256 _qtyOut
) external onlyOwner {
_target.swapExactTokensForTokens(
_qtyIn,
_qtyOut,
_path,
address(this),
block.timestamp + 60
);
}
The goal is to supply it with a path, and make it swap back into the original token. If the path is "A -> B -> A", then we start with token A and end with token A.
However, executing this, always returns the INSUFFICINET_INPUT_AMOUNT
even when the _qtyOut
is set zero.
Using getAmountsOut
, I can see that the correct values are returned.
This same function works just fine if I do not include the cycle, i.e. "A -> B" works