Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"execution reverted" when using make_trade() #329

Open
ggiv opened this issue Apr 23, 2023 · 6 comments
Open

"execution reverted" when using make_trade() #329

ggiv opened this issue Apr 23, 2023 · 6 comments

Comments

@ggiv
Copy link

ggiv commented Apr 23, 2023

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
@starascendin
Copy link

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

@ggiv
Copy link
Author

ggiv commented Apr 24, 2023

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

@liquid-8
Copy link
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.

@sitwano
Copy link

sitwano commented May 30, 2023

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.

@Lv5Electro
Copy link

Lv5Electro commented Sep 6, 2023

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

@Lv5Electro
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants