'Sushiswap pairadress contract .estimateGas.swap throws server error

I'm working on an arbitrage trading bot, using ethers.js in my JavaScript file that is calling my flashloan smartcontract, testing on Kovan.

I deployed a flashloan smartcontract on the kovan network. 0x236f6860b31F6226d5937EC0Bd9465B12C2b20cA

In my JavaScript file, I want to estimate the gas that will be used when I call this contract. However, I'm always receiving a server error.

When I call this flashloan contract from my pair contract address, it does work. So I assume the problem is not inside the flashloan smartcontract that is called.

This is part of my code:

const provider = new ethers.providers.InfuraProvider("kovan", kovanKey);
const wallet = new ethers.Wallet(privateKey, provider);
let pairAd2 = "0x052AE8b0F7E5c610937920e46ED265c2063Cb7B8";
let  uniToken0Token1 = new ethers.Contract(
          pairAd2,
           UniV2Pair.abi, wallet,
         );
const gl = await uniToken0Token1.estimateGas.swap(
               0,
               10,
               flashLoanerAddress,
               ethers.utils.toUtf8Bytes('1')
             );

This will throw this error:

processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":45,\"error\":{\"code\":-32016,\"data\":\"Reverted\",\"message\":\"The execution failed due to an exception.\"}}", error={"code":-32016,"data":"Reverted"}, requestBody="{\"method\":\"eth_estimateGas\",\"params\":[{\"from\":\"0x8da6ae9837c8bb55fc6c0a0ec1ee3000942af8f4\",\"to\":\"0x4d027027af6dfa0a14332223fedfc8289d205088\",\"data\":\"0x022c0d9f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000236f6860b31f6226d5937ec0bd9465b12c2b20ca000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000013100000000000000000000000000000000000000000000000000000000000000\"}],\"id\":45,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://kovan.infura.io/v3/.................", code=SERVER_ERROR, version=web/5.5.1)
 reason: 'processing response error',
  code: 'SERVER_ERROR',
  body: '{"jsonrpc":"2.0","id":45,"error":{"code":-32016,"data":"Reverted","message":"The execution failed due to an exception."}}',
.
.
.
 code: -32016,
    data: 'Reverted'
  },
  requestBody: '{"method":"eth_estimateGas","params":[{"from":"0x8da6ae9837c8bb55fc6c0a0ec1ee3000942af8f4","to":"0x4d027027af6dfa0a14332223fedfc8289d205088","data":"0x022c0d9f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000236f6860b31f6226d5937ec0bd9465b12c2b20ca000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000013100000000000000000000000000000000000000000000000000000000000000"}],"id":45,"jsonrpc":"2.0"}',
  requestMethod: 'POST',
  url: 'https://kovan.infura.io/v3/......................'

Which I don't understand, I've been searching for days.

Or how can I see more information maybe about the error/cause?



Solution 1:[1]

here are some steps you can take, but not an accurate answer. maybe try getting your gas price from an oracle like https://www.gasprice.io/ then maybe add the right slippage percentage. if you haven't ,have a a look at how sushiswap subgraph works. https://thegraph.com/hosted-service/subgraph/sushiswap/exchange

if you look through sushiswap's interface on github, you can sort through various methods for 'gas', like run a search/find for the method calculateGasMargin and see how sushiswap is doing it. you can see they're using 'gasEstimate' instead of 'gasPrice', so on so forth.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 seems