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

Problems with some transaction simulations on polygon pos mainnet (network ID: 137) #4

Open
OliverLaiGHong opened this issue May 26, 2024 · 0 comments

Comments

@OliverLaiGHong
Copy link

Download date of both pyrevm and pyrevm_contract (Don't know where to find the version numbers): Around May 22, 2024

Issue:

I'm using it on my Polygon POS full node, and I connect it to my bor, which is working well with web3.py.

Wrapped Matic deposit (wrapping the native coin):

Code:

# INITIALIZE THE TEST
from pyrevm_contract import Revm, Contract
import json

my_wallet = '0x00000000000000000000000000000000000021E8'

matic_address = "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"

with open('./path/to/wrapped_matic_abi/file', 'r') as matic_abi_file:
    matic_abi = json.load(matic_abi_file)

revm = Revm("http://localhost:8545", block_number="latest")
revm.set_balance(my_wallet, 60000000 * 10**18)


# TRYING TO WRAP 500 NATIVE MATICS TO WRAPPED MATIC ON POLYGON NETWORK
wmatic_pyrevm = Contract(matic_address, matic_abi)
wmatic_pyrevm.deposit(value=500*10**18, caller=my_wallet)
wmatic_bal = wmatic_pyrevm.balanceOf(my_wallet)
print(f'{wmatic_bal=} ie {wmatic_bal/10**18}')

Result:

$ python scripts/report_pyrevm_contract_issue.py 
wmatic_bal=0 ie 0.0

It still has 0 wmatics.

Uniswap _V3:

# INITIALIZE THE TEST

from pyrevm_contract import Revm, Contract
import json
import time

my_wallet = '0x00000000000000000000000000000000000021E8'

matic_address = "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"
dai_address = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'
weth_address = '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'

QUICK_SWAP_ROUTER_ADDRESS = '0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff'
UNISWAP_V3_ROUTER_ADDRESS = '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'

with open('./path/to/abi_quickswap_router/abi/file', 'r') as quick_swap_router_abi_file:
    quickswap_router_abi = json.load(quick_swap_router_abi_file)

with open('./path/to/uniswapv3_router/abi/file', 'r') as uniswap_v3_router_file:
    uniswap_v3_router_abi = json.load(uniswap_v3_router_file)

with open('./path/to/wrapped_ether/abi/file', 'r') as weth_abi_file:
    weth_abi = json.load(weth_abi_file)

revm = Revm("http://localhost:8545", block_number="latest")
revm.set_balance(my_wallet, 60000000 * 10**18)

quickswap_pyrevm = Contract(QUICK_SWAP_ROUTER_ADDRESS, quickswap_router_abi)
uniswap_v3_pyrevm = Contract(UNISWAP_V3_ROUTER_ADDRESS, uniswap_v3_router_abi)
weth = Contract(weth_address, weth_abi)


# SWAP THE NATIVE MATIC TO WETH AND CHECK IF IT IS SUCCESSFUL BY QUERYING FOR ITS BALANCE (ON MY END, IT'S SUCESSFUL)
quickswap_amount_out = quickswap_pyrevm.swapExactETHForTokens(0, [matic_address, weth_address], my_wallet, int(time.time()+10), value=int(9999*10**18), caller=my_wallet)[1]
print(f'{quickswap_amount_out=} ie {quickswap_amount_out/10**18}')
weth_bal = weth.balanceOf(my_wallet)
print(f'{weth_bal=} ie {weth_bal/10**18}')


# THE PROBLEM IS HERE WHEN TRYING TO SWAP THE OBTAINED WETH TO DAI. IT CANNOT SWAP ON UNISWAP V3
tokenIn = weth_address
tokenOut = dai_address
fee = 10000
receipient = my_wallet
amountIn = int(0.01 * 10**18)
amountOutMinimum = 0
sqrtPriceLimitX96 = 0

v3_swap_params = (
    tokenIn,
    tokenOut,
    fee,
    receipient,
    amountIn,
    amountOutMinimum,
    sqrtPriceLimitX96
)
result_amountOut_pyrevm = uniswap_v3_pyrevm.exactInputSingle(v3_swap_params, caller=my_wallet)
print(f'{result_amountOut_pyrevm=}')

# ERRORS WHEN SETTING DIFFERENT FEES (WHEN FEE = 1000, IT EVEN REVERTS WITH EMPTY DATA)
'''
fee = 100, 500, 3000, 10000
$ python scripts/report_pyrevm_contract_issue.py 
quickswap_amount_out=1912674628298783777 ie 1.9126746282987839
weth_bal=1912674628298783777 ie 1.9126746282987839
Traceback (most recent call last):
  File "/root/arb_folder/play_ape/scripts/report_pyrevm_contract_issue.py", line 56, in <module>
    result_amountOut_pyrevm = uniswap_v3_pyrevm.exactInputSingle(v3_swap_params, caller=my_wallet)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/py_envs/py311testinstall/lib/python3.11/site-packages/pyrevm_contract/contract.py", line 33, in <lambda>
    return lambda *args, **kwargs: self.call_function(func, args, kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/py_envs/py311testinstall/lib/python3.11/site-packages/pyrevm_contract/contract.py", line 65, in call_function
    raw_output = self.revm.message_call(
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/py_envs/py311testinstall/lib/python3.11/site-packages/pyrevm_contract/revm.py", line 32, in message_call
    return self.revm.message_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Revert { gas_used: 117275, output: 0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000035354460000000000000000000000000000000000000000000000000000000000 }

fee = 1000
$ python scripts/report_pyrevm_contract_issue.py 
quickswap_amount_out=1911997972166540009 ie 1.91199797216654
weth_bal=1911997972166540009 ie 1.91199797216654
Traceback (most recent call last):
  File "/root/arb_folder/play_ape/scripts/report_pyrevm_contract_issue.py", line 58, in <module>
    result_amountOut_pyrevm = uniswap_v3_pyrevm.exactInputSingle(v3_swap_params, caller=my_wallet)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/py_envs/py311testinstall/lib/python3.11/site-packages/pyrevm_contract/contract.py", line 33, in <lambda>
    return lambda *args, **kwargs: self.call_function(func, args, kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/py_envs/py311testinstall/lib/python3.11/site-packages/pyrevm_contract/contract.py", line 65, in call_function
    raw_output = self.revm.message_call(
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/py_envs/py311testinstall/lib/python3.11/site-packages/pyrevm_contract/revm.py", line 32, in message_call
    return self.revm.message_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Revert { gas_used: 29450, output: 0x }
'''
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

2 participants
@OliverLaiGHong and others