I have written a smart contract which the purpose of swapping via 1inch exchange. I have deployed the contract to a locally forked mainnet using ganache-cli and successfully pre-funded my contract. However, when executing the swap function, the transaction reverts with the following message: Error: Returned error: VM Exception while processing transaction: revert SafeERC20: low-level call failed. This is the code I am having problems with:
function swapOnOneInch(
address fromToken,
address toToken,
uint256 originAmount,
uint256 minTargetAmount,
uint256[] memory exchangeDistribution
) internal {
uint minOut = 99 * minTargetAmount / 100;
bytes memory _data = abi.encodeWithSignature(
"swap(address,address,uint256,uint256,uint256[],uint256)",
fromToken,
toToken,
originAmount,
// Set to 99% of the minTargetAmount, to give us a
// 1% price/slippage buffer
minOut,
exchangeDistribution,
0
);
invoke(0x50FDA034C0Ce7a8f7EFDAebDA7Aa7cA21CC1267e, _data);
}
I have been looking all around the internet and could not find a useful solution. Does someone understand where the error might be? Any help is much appreciated :)