Skip to content

"execution reverted" when using make_trade()  #329

Open

Description

@ggiv

Hello!
When trying to execute a swap using the make_trade() method I consistently get "web3.exceptions.ContractLogicError: execution reverted" error

This is the code that can be used to reproduce the error:

import os
from uniswap import Uniswap

weth_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # WETH
token_address = "0x4d224452801ACEd8B2F0aebE155379bb5D594381" # APE

uniswap = Uniswap(
    address=os.environ.get('WALLET_ADDRESS'), 
    private_key=os.environ.get('WALLET_PRIVATE_KEY'),
    provider=os.environ.get('PROVIDER_URL'),
    version=3
)

tx = uniswap.make_trade(weth_address, token_address, qty=9000000000000000, slippage=0.3, fee=10000000)
print(tx)

Checking the APE/WETH pair on the Uniswap UI it seems to exist and also has good amount of liquidity.

Am I doing something wrong there?

Here is the full trace of the error:

File "/home/example/example.py", line 17, in <module>
   tx = uniswap.make_trade(weth_address, token_address, qty=9000000000000000, slippage=0.3, fee=10000000)
 File "/home/example/venv/lib64/python3.10/site-packages/uniswap/decorators.py", line 38, in approved
   return method(self, *args, **kwargs)
 File "/home/example/venv/lib64/python3.10/site-packages/uniswap/uniswap.py", line 476, in make_trade
   return self._token_to_token_swap_input(
 File "/home/example/venv/lib64/python3.10/site-packages/uniswap/uniswap.py", line 766, in _token_to_token_swap_input
   * self._get_token_token_input_price(
 File "/home/example/venv/lib64/python3.10/site-packages/uniswap/uniswap.py", line 340, in _get_token_token_input_price
   ).call()
 File "/home/example/venv/lib64/python3.10/site-packages/web3/contract/contract.py", line 461, in call
   return call_contract_function(
 File "/home/example/venv/lib64/python3.10/site-packages/web3/contract/utils.py", line 96, in call_contract_function
   return_data = w3.eth.call(
 File "/home/example/venv/lib64/python3.10/site-packages/web3/eth/eth.py", line 255, in call
   return self._durin_call(transaction, block_identifier, state_override)
 File "/home/example/venv/lib64/python3.10/site-packages/web3/eth/eth.py", line 274, in _durin_call
   return self._call(transaction, block_identifier, state_override)
 File "/home/example/venv/lib64/python3.10/site-packages/web3/module.py", line 68, in caller
   result = w3.manager.request_blocking(
 File "/home/example/venv/lib64/python3.10/site-packages/web3/manager.py", line 232, in request_blocking
   return self.formatted_response(
 File "/home/example/venv/lib64/python3.10/site-packages/web3/manager.py", line 197, in formatted_response
   apply_error_formatters(error_formatters, response)
 File "/home/example/venv/lib64/python3.10/site-packages/web3/manager.py", line 73, in apply_error_formatters
   formatted_resp = pipe(response, error_formatters)
 File "cytoolz/functoolz.pyx", line 666, in cytoolz.functoolz.pipe
 File "cytoolz/functoolz.pyx", line 641, in cytoolz.functoolz.c_pipe
 File "/home/example/venv/lib64/python3.10/site-packages/web3/_utils/method_formatters.py", line 766, in raise_contract_logic_error_on_revert
   raise ContractLogicError("execution reverted")
web3.exceptions.ContractLogicError: execution reverted

Activity

  1. starascendin commented on Apr 24, 2023

    @starascendin

    you might have to double check on the router abi vs the ones from this package

  2. ggiv commented on Apr 24, 2023

    @ggiv
    Author

    Thanks @starascendin ! The ABI and the router address looks correct to me. I am testing this on mainnet.

  3. liquid-8 commented on Apr 27, 2023

    @liquid-8
    Member

    tx = uniswap.make_trade(weth_address, token_address, qty=9000000000000000, slippage=0.3, fee=10000000)

    Not sure if fee param should be like that, more like 10,000 for 1% pools. I would recommend checking docs just in case.

  4. sitwano commented on May 30, 2023

    @sitwano

    tx = uniswap.make_trade(weth_address, token_address, qty=9000000000000000, slippage=0.3, fee=10000000)

    Also it looks like your slippage is also calculated wrong. It should be 0.3/100 as far I understand the docs.

  5. Lv5Electro commented on Sep 6, 2023

    @Lv5Electro

    I got the same error,this is my args

    w3 = Web3(Web3.HTTPProvider('https://rpc-mainnet.maticvigil.com',
                                request_kwargs={"proxies": proxies}))
    w3.middleware_onion.inject(geth_poa_middleware, layer=0)
    
    uniswap = Uniswap(address=address, private_key=private_key, version=3, web3=w3)
    
    # Compare the results with the output of:
    # https://app.uniswap.org/#/swap?use=v3&inputCurrency=ETH&outputCurrency=0x7d29a64504629172a429e64183d6673b9dacbfce
    qty = 5 * 10 ** 18
    
    amp = w3.to_checksum_address("0x0621d647cecbFb64b79E44302c1933cB4f27054d")
    matic = w3.to_checksum_address("0x0000000000000000000000000000000000001010")
    
    # impact = uniswap.estimate_price_impact(amp, matic, qty, fee=10000)
    # print(f"Impact for buying Matic on v3 with {qty / 10 ** 18} ETH:  {impact}")
    
    data = uniswap.make_trade(amp, matic, qty=qty, slippage=0.1, fee=3000)
    print(data)
    

    this was traded on polygon

  6. Lv5Electro commented on Sep 6, 2023

    @Lv5Electro

    I got the same error,this is my args

    w3 = Web3(Web3.HTTPProvider('https://rpc-mainnet.maticvigil.com',
                                request_kwargs={"proxies": proxies}))
    w3.middleware_onion.inject(geth_poa_middleware, layer=0)
    
    uniswap = Uniswap(address=address, private_key=private_key, version=3, web3=w3)
    
    # Compare the results with the output of:
    # https://app.uniswap.org/#/swap?use=v3&inputCurrency=ETH&outputCurrency=0x7d29a64504629172a429e64183d6673b9dacbfce
    qty = 5 * 10 ** 18
    
    amp = w3.to_checksum_address("0x0621d647cecbFb64b79E44302c1933cB4f27054d")
    matic = w3.to_checksum_address("0x0000000000000000000000000000000000001010")
    
    # impact = uniswap.estimate_price_impact(amp, matic, qty, fee=10000)
    # print(f"Impact for buying Matic on v3 with {qty / 10 ** 18} ETH:  {impact}")
    
    data = uniswap.make_trade(amp, matic, qty=qty, slippage=0.1, fee=3000)
    print(data)
    

    this was traded on polygon

    I solved this problem. I set in the constants.py ETH_ADDRESS = "0x0000000000000000000000000000000000001010"
    but I have a new problem #346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions