Hi, I’m trying to integrate with 1Inch on-chain, using solidity. I’m using the mainnet forking capabilities of Hardhat to test the integration. I have successfully been able to swap two tokens if I call the one inch contract from an EOA in my tests. However, calling the same function from my contract, under what I believe is the same circumstances, is resulting in Transaction reverted without a reason
, which is maddening.
I am first calling the “getExpectedReturn” function, as this article and the 1inch docs seem to indicate. And indeed that works for my test EOA. I have approved the one inch contract for the ERC20’s in question from my smart contract. And I’m also fairly sure the swap part within the one inch contract itself is working, because I was at one point getting the “the return amount is < min specified”, but I just set the min (what they call "return amount) to be 1, and that is when I started getting the “transaction reverted without a reason” bug.
I have also tried changing my gas settings within Hardhat, to no avail, and tried verbose logging, which doesn’t seem to help much.
Any ideas would be very much appreciated! Thanks so much!
Environment
Hardhat: ^2.02
Using truffle contracts in my tests.
Details
Code to reproduce
Here is the relevant smart contract code:
function payWithSwap(
address creditLineAddress,
uint256 amount,
IERC20 fromToken,
uint256 returnAmount,
uint256[] memory distribution
) external onlyAdmin {
address oneInch = config.oneInchAddress();
fromToken.approve(oneInch, uint256(-1));
fromToken.transferFrom(msg.sender, address(this), amount);
swap(fromToken, IERC20(config.usdcAddress()), amount, returnAmount, distribution);
}
function swap(
IERC20 fromToken,
IERC20 toToken,
uint256 amount,
uint256 returnAmount,
uint256[] memory distribution
) internal {
config.getExchange().swap(
fromToken,
toToken,
amount,
10,
distribution,
0
);
}
And my test code looks like the following:
const expectedReturn = await oneSplit.getExpectedReturn(busd.address, usdc.address, bigVal(rawAmount), 10, 0, {from: bwr})
await expectAction(() => {
return bwrCon.payWithSwap(
cl.address,
bigVal(rawAmount),
busdAddress,
expectedReturn.returnAmount,
expectedReturn.distribution,
{from: bwr}
)
}).to.succeed()