0

I get this error when executing swap token for ether on arb detection.

Error Message: execution reverted
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
at 
getReserves()
at 
Opcode: [STATICCALL]
in 
0xbc03cf2c6443d9bb25c8fd9b701d9eb22f85f584
Opcode: [CALL]
in 
0xbc03cf2c6443d9bb25c8fd9b701d9eb22f85f584

In nodejs, the error response is:

err...Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x1c668xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "blockNumber": 8143875,
  "contractAddress": null,
  "cumulativeGasUsed": 922169,
  "from": "0xab3388xxxxxxxxxxxxx",
  "gasUsed": 922169,
  "logsBloom": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000

Since my buy token function in solidity works normally when I call it from truffle console, I was wondering what could be a likely cause.

Here is the buy token function:

function buyCryptoOnUniswap(uint256 etherCost , address cryptoToken) public payable returns (uint256) {
//address cryptoToken = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa;

if(etherCost > address(this).balance){
    return 0;
}
 
    uint deadline = now + 300; // using 'now' for convenience, for mainnet pass deadline from frontend!

   
    uint[] memory amounts = usi.swapExactETHForTokens.value(etherCost)(0, getPathForETHToToken(cryptoToken), address(this), deadline);
    uint256 outputTokenCount = uint256(amounts[amounts.length - 1]);

    return outputTokenCount;
}

Here is a typical transaction that depicts this. I hope someone can clue me in on particular or likely causes of such.

Thanks.

UPDATE

With guidance from @goodvibration, I found that the error seems to be from this portion of code instead:

   function buyCryptoOnKyber(uint256 etherCost , address cryptoToken) public payable returns(uint256){
    //address cryptoToken = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa;
    if(etherCost > address(this).balance){
        return 0;
    }
    KyberNetworkProxyInterface proxy = getKyberExchange();
    ERC20 token = ERC20(cryptoToken);
      
        uint minRate;
        (, minRate) = proxy.getExpectedRate(ETH_TOKEN_ADDRESS, token, etherCost);
    
        //will send back tokens to this contract's address
        uint destAmount = proxy.swapEtherToToken.value(etherCost)(token, minRate);
    
        //send received tokens to destination address
       require(token.transfer(address(this), destAmount));
       
    
        // refund leftover ETH to user
        //msg.sender.call.value(address(this).balance)("");
    
    
    }
    
    function kyberToUniSwapArb(address fromAddress,address toAddress, uint ethAmount) public payable returns (uint256){
     
        uint256 cryptoAmountPurchased = buyCryptoOnKyber( ethAmount , fromAddress);
    
         sellCryptoOnUniswap(cryptoAmountPurchased , toAddress);
    
        }

function sellCryptoOnUniswap(uint256 cryptoQty , address cryptoToken) public payable returns(uint256){
///selling code
}

EDIT

  • Please share your function call (i.e., what parameters you are passing to this function). – goodvibration Jul 5 '20 at 7:12
  • The values are being passed from a lender's callback and it reverts before I can make anything tangible out of it. I however suspect it is a parametric issue as seen in this online debugger's output: dashboard.tenderly.co/tx/ropsten/… Hope you can make something out of it – gbenroscience Jul 5 '20 at 7:58
  • The transaction is to this contract. Please verify it on Etherscan. – goodvibration Jul 5 '20 at 8:20
  • I cant verify it yet for reasons. Can I post the executeOperation callback instead since that is where the errors occur? executeOperation is where the issues occur. – gbenroscience Jul 5 '20 at 8:40
  • Sure, but that's partial information, so not necessarily will others be able to help you with the problem. – goodvibration Jul 5 '20 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.