8
8
from web3 import Web3
9
9
from web3 ._utils .abi import map_abi_data
10
10
from web3 ._utils .normalizers import BASE_RETURN_NORMALIZERS
11
- from web3 .contract import Contract ,ContractFunction
11
+ from web3 .contract import Contract
12
+ from web3 .contract .base_contract import BaseContractFunction
12
13
from web3 .exceptions import BadFunctionCallOutput ,ContractLogicError
13
14
from web3 .types import (
14
15
TxParams ,
18
19
)
19
20
from eth_typing .evm import Address ,ChecksumAddress
20
21
from hexbytes import HexBytes
21
-
22
22
from .types import AddressLike
23
23
from .token import ERC20Token
24
24
from .exceptions import InvalidToken ,InsufficientBalance
@@ -1435,12 +1435,12 @@ def _deadline(self) -> int:
1435
1435
return int (time .time ())+ 10 * 60
1436
1436
1437
1437
def _build_and_send_tx (
1438
- self ,function :ContractFunction ,tx_params :Optional [TxParams ]= None
1438
+ self ,function :BaseContractFunction ,tx_params :Optional [TxParams ]= None
1439
1439
)-> HexBytes :
1440
1440
"""Build and send a transaction."""
1441
1441
if not tx_params :
1442
1442
tx_params = self ._get_tx_params ()
1443
- transaction = function .build_transaction (tx_params )
1443
+ transaction = function ._build_transaction (tx_params )
1444
1444
1445
1445
if "gas" not in tx_params :
1446
1446
# `use_estimate_gas` needs to be True for networks like Arbitrum (can't assume 250000 gas),
@@ -1465,7 +1465,9 @@ def _build_and_send_tx(
1465
1465
logger .debug (f"nonce:{ tx_params ['nonce' ]} " )
1466
1466
self .last_nonce = Nonce (tx_params ["nonce" ]+ 1 )
1467
1467
1468
- def _get_tx_params (self ,value :Wei = Wei (0 ),gas :Optional [Wei ]= None )-> TxParams :
1468
+ def _get_tx_params (
1469
+ self ,value :Wei = Wei (0 ),gas :Optional [Wei ]= None
1470
+ )-> TxParams :
1469
1471
"""Get generic transaction parameters."""
1470
1472
params :TxParams = {
1471
1473
"from" :_addr_to_str (self .address ),
@@ -1569,7 +1571,7 @@ def multicall(
1569
1571
block_identifier = "latest"
1570
1572
)
1571
1573
decoded_results = [
1572
- self .w3 .codec .decode_abi (output_types ,multicall_result )
1574
+ self .w3 .codec .decode (output_types ,multicall_result )
1573
1575
for multicall_result in results
1574
1576
]
1575
1577
normalized_results = [
@@ -1669,7 +1671,7 @@ def create_pool_instance(
1669
1671
)
1670
1672
receipt = self .w3 .eth .wait_for_transaction_receipt (tx )
1671
1673
1672
- event_logs = self .factory_contract .events .PoolCreated ().processReceipt (receipt )
1674
+ event_logs = self .factory_contract .events .PoolCreated ().process_receipt (receipt )
1673
1675
pool_address = event_logs [0 ]["args" ]["pool" ]
1674
1676
pool_instance = _load_contract (
1675
1677
self .w3 ,abi_name = "uniswap-v3/pool" ,address = pool_address
@@ -1823,27 +1825,27 @@ def get_raw_price(
1823
1825
1824
1826
if self .version == 2 :
1825
1827
params :Iterable [Union [ChecksumAddress ,Optional [int ]]]= [
1826
- self .w3 .toChecksumAddress (token_in ),
1827
- self .w3 .toChecksumAddress (token_out ),
1828
+ self .w3 .to_checksum_address (token_in ),
1829
+ self .w3 .to_checksum_address (token_out ),
1828
1830
]
1829
1831
pair_token = self .factory_contract .functions .getPair (* params ).call ()
1830
1832
token_in_erc20 = _load_contract_erc20 (
1831
- self .w3 ,self .w3 .toChecksumAddress (token_in )
1833
+ self .w3 ,self .w3 .to_checksum_address (token_in )
1832
1834
)
1833
1835
token_in_balance = int (
1834
1836
token_in_erc20 .functions .balanceOf (
1835
- self .w3 .toChecksumAddress (pair_token )
1837
+ self .w3 .to_checksum_address (pair_token )
1836
1838
).call ()
1837
1839
)
1838
1840
token_in_decimals = self .get_token (token_in ).decimals
1839
1841
token_in_balance = token_in_balance / (10 ** token_in_decimals )
1840
1842
1841
1843
token_out_erc20 = _load_contract_erc20 (
1842
- self .w3 ,self .w3 .toChecksumAddress (token_out )
1844
+ self .w3 ,self .w3 .to_checksum_address (token_out )
1843
1845
)
1844
1846
token_out_balance = int (
1845
1847
token_out_erc20 .functions .balanceOf (
1846
- self .w3 .toChecksumAddress (pair_token )
1848
+ self .w3 .to_checksum_address (pair_token )
1847
1849
).call ()
1848
1850
)
1849
1851
token_out_decimals = self .get_token (token_out ).decimals
@@ -1852,15 +1854,15 @@ def get_raw_price(
1852
1854
raw_price = token_out_balance / token_in_balance
1853
1855
else :
1854
1856
params = [
1855
- self .w3 .toChecksumAddress (token_in ),
1856
- self .w3 .toChecksumAddress (token_out ),
1857
+ self .w3 .to_checksum_address (token_in ),
1858
+ self .w3 .to_checksum_address (token_out ),
1857
1859
fee ,
1858
1860
]
1859
1861
pool_address = self .factory_contract .functions .getPool (* params ).call ()
1860
1862
pool_contract = _load_contract (
1861
1863
self .w3 ,abi_name = "uniswap-v3/pool" ,address = pool_address
1862
1864
)
1863
- t0 = pool_contract .functions .token0 ().call ()
1865
+ # t0 = pool_contract.functions.token0().call()
1864
1866
t1 = pool_contract .functions .token1 ().call ()
1865
1867
if t1 .lower ()== token_in .lower ():
1866
1868
den0 = self .get_token (token_in ).decimals
@@ -1953,7 +1955,9 @@ def _token_address_from_exchange(self, exchange_addr: AddressLike) -> Address:
1953
1955
@functools .lru_cache ()
1954
1956
@supports ([1 ])
1955
1957
def _exchange_contract (
1956
- self ,token_addr :Optional [AddressLike ]= None ,ex_addr :Optional [AddressLike ]= None
1958
+ self ,
1959
+ token_addr :Optional [AddressLike ]= None ,
1960
+ ex_addr :Optional [AddressLike ]= None ,
1957
1961
)-> Contract :
1958
1962
if not ex_addr and token_addr :
1959
1963
ex_addr = self ._exchange_address_from_token (token_addr )