0

I am trying to build a bot that can perform tri-arbitrage trades and I ran into an issue that I don't really understand when trying to interact with the Uniswap v2 router in my contract to estimate a trade.

I am running this on a hardhat forked Ethereum mainnet and this is the error I'm currently getting;

In my terminal

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="estimateTriDexTrade(address,address,address,address,address,address,uint256)", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)

In the hardhat node console

 Error: Transaction reverted without a reason string
  at <UnrecognizedContract>.<unknown> (0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f)
  at FlashLoanAb.getAmountOutMin (contracts/FlashLoanAb.sol:93)
  at FlashLoanAb.estimateTriDexTrade (contracts/FlashLoanAb.sol:110)

This the UniswapRouter interfaces I'm using in my contract

interface IUniswapV2Router {
    function getAmountsOut(
        uint256 amountIn,
        address[] memory path
    ) external view returns (uint256[] memory amounts);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);
}

interface IUniswapV2Pair {
    function token0() external view returns (address);

    function token1() external view returns (address);

    function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external;
}

These are the function calls

    function getAmountOutMin(
        address router,
        address _tokenIn,
        address _tokenOut,
        uint256 _amount
    ) public view returns (uint256) {
        address[] memory path;
        path = new address[](2);
        path[0] = _tokenIn;
        path[1] = _tokenOut;
        uint256[] memory amountOutMins = IUniswapV2Router(router).getAmountsOut(
            _amount,
            path
        );
        return amountOutMins[path.length - 1];
    }
  function estimateTriDexTrade(
        address _router1,
        address _router2,
        address _router3,
        address _token1,
        address _token2,
        address _token3,
        uint256 _amount
    ) external view returns (uint256) {
        console.log(_amount);
        uint amtBack1 = getAmountOutMin(_router1, _token1, _token2, _amount);
        uint amtBack2 = getAmountOutMin(_router2, _token2, _token3, amtBack1);
        uint amtBack3 = getAmountOutMin(_router3, _token3, _token1, amtBack2);
        return amtBack3;
    }

These are the router addresses I'm

  "routers": [
    {
      "dex": "1inch",
      "address": "0x1111111254EEB25477B68fb85Ed929f73A960582"
    },
    {
      "dex": "sushiswap",
      "address": "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"
    },
    {
      "dex": "uniswap",
      "address": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"
    }
  ],

I followed the link suggested in the error logs and read about the CALL_EXCEPTION error code in the ethers documentation but the common causes don't seem to apply here, tried the suggested debugging solution and I can access other functions in the contract just these that are throwing error.

I'm still kinda wet behind the ears when it comes to solidity and blockchain so I don't really understand what it is that I'm doing wrong. Am I interacting with the contract wrongly, or passing the wrong variables? Can someone please enlighten me, thanks.

contract in IDE

1 Answer 1

1

It's hard to say for sure, but it looks like the address you have for sushiSwap in your router addresses isn't being recognised - evident from the error at <UnrecognizedContract>.<unknown> (0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f).

I would try to check the address is correct, and if still facing problems, omit it from your router addresses and/or change the places where it's being invoked, perhaps at lines 93 & 110 (given error codes).

1
  • I have confirmed that this is the correct sushiswap router and Its not just sushiswap, all the dex throws this error and Those lines are empty spaces after the functions I dont know why its referencing those. I would add a screenshot of the contract in my IDE
    – ccurves
    Commented Dec 3, 2022 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.