Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00a97bd

Browse files
committed
fix: changed to using new names in updated web3py versions
1 parent38b7870 commit00a97bd

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

‎uniswap/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def _coerce_to_checksum(addr: str) -> str:
2828
raiseValueError(
2929
"token was not an address, and a shorthand was not found in the token db"
3030
)
31-
ifWeb3.isChecksumAddress(addr):
31+
ifWeb3.is_checksum_address(addr):
3232
returnaddr
3333
else:
34-
returnWeb3.toChecksumAddress(addr)
34+
returnWeb3.to_checksum_address(addr)
3535

3636

3737
@click.group()

‎uniswap/tokens.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
tokens_mainnet:Dict[str,ChecksumAddress]= {
8-
k:Web3.toChecksumAddress(v)
8+
k:Web3.to_checksum_address(v)
99
fork,vin {
1010
"ETH":"0x0000000000000000000000000000000000000000",
1111
"WETH":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
@@ -18,7 +18,7 @@
1818
}
1919

2020
tokens_rinkeby:Dict[str,ChecksumAddress]= {
21-
k:Web3.toChecksumAddress(v)
21+
k:Web3.to_checksum_address(v)
2222
fork,vin {
2323
"ETH":"0x0000000000000000000000000000000000000000",
2424
"DAI":"0x2448eE2641d78CC42D7AD76498917359D961A783",
@@ -27,7 +27,7 @@
2727
}
2828

2929
tokens_arbitrum:Dict[str,ChecksumAddress]= {
30-
k:Web3.toChecksumAddress(v)
30+
k:Web3.to_checksum_address(v)
3131
fork,vin {
3232
"ETH":"0x0000000000000000000000000000000000000000",
3333
"WETH":"0x82af49447d8a07e3bd95bd0d56f35241523fbab1",

‎uniswap/uniswap.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
fromweb3importWeb3
99
fromweb3._utils.abiimportmap_abi_data
1010
fromweb3._utils.normalizersimportBASE_RETURN_NORMALIZERS
11-
fromweb3.contractimportContract,ContractFunction
11+
fromweb3.contractimportContract
12+
fromweb3.contract.base_contractimportBaseContractFunction
1213
fromweb3.exceptionsimportBadFunctionCallOutput,ContractLogicError
1314
fromweb3.typesimport (
1415
TxParams,
@@ -18,7 +19,6 @@
1819
)
1920
frometh_typing.evmimportAddress,ChecksumAddress
2021
fromhexbytesimportHexBytes
21-
2222
from .typesimportAddressLike
2323
from .tokenimportERC20Token
2424
from .exceptionsimportInvalidToken,InsufficientBalance
@@ -1435,12 +1435,12 @@ def _deadline(self) -> int:
14351435
returnint(time.time())+10*60
14361436

14371437
def_build_and_send_tx(
1438-
self,function:ContractFunction,tx_params:Optional[TxParams]=None
1438+
self,function:BaseContractFunction,tx_params:Optional[TxParams]=None
14391439
)->HexBytes:
14401440
"""Build and send a transaction."""
14411441
ifnottx_params:
14421442
tx_params=self._get_tx_params()
1443-
transaction=function.build_transaction(tx_params)
1443+
transaction=function._build_transaction(tx_params)
14441444

14451445
if"gas"notintx_params:
14461446
# `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(
14651465
logger.debug(f"nonce:{tx_params['nonce']}")
14661466
self.last_nonce=Nonce(tx_params["nonce"]+1)
14671467

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:
14691471
"""Get generic transaction parameters."""
14701472
params:TxParams= {
14711473
"from":_addr_to_str(self.address),
@@ -1569,7 +1571,7 @@ def multicall(
15691571
block_identifier="latest"
15701572
)
15711573
decoded_results= [
1572-
self.w3.codec.decode_abi(output_types,multicall_result)
1574+
self.w3.codec.decode(output_types,multicall_result)
15731575
formulticall_resultinresults
15741576
]
15751577
normalized_results= [
@@ -1669,7 +1671,7 @@ def create_pool_instance(
16691671
)
16701672
receipt=self.w3.eth.wait_for_transaction_receipt(tx)
16711673

1672-
event_logs=self.factory_contract.events.PoolCreated().processReceipt(receipt)
1674+
event_logs=self.factory_contract.events.PoolCreated().process_receipt(receipt)
16731675
pool_address=event_logs[0]["args"]["pool"]
16741676
pool_instance=_load_contract(
16751677
self.w3,abi_name="uniswap-v3/pool",address=pool_address
@@ -1823,27 +1825,27 @@ def get_raw_price(
18231825

18241826
ifself.version==2:
18251827
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),
18281830
]
18291831
pair_token=self.factory_contract.functions.getPair(*params).call()
18301832
token_in_erc20=_load_contract_erc20(
1831-
self.w3,self.w3.toChecksumAddress(token_in)
1833+
self.w3,self.w3.to_checksum_address(token_in)
18321834
)
18331835
token_in_balance=int(
18341836
token_in_erc20.functions.balanceOf(
1835-
self.w3.toChecksumAddress(pair_token)
1837+
self.w3.to_checksum_address(pair_token)
18361838
).call()
18371839
)
18381840
token_in_decimals=self.get_token(token_in).decimals
18391841
token_in_balance=token_in_balance/ (10**token_in_decimals)
18401842

18411843
token_out_erc20=_load_contract_erc20(
1842-
self.w3,self.w3.toChecksumAddress(token_out)
1844+
self.w3,self.w3.to_checksum_address(token_out)
18431845
)
18441846
token_out_balance=int(
18451847
token_out_erc20.functions.balanceOf(
1846-
self.w3.toChecksumAddress(pair_token)
1848+
self.w3.to_checksum_address(pair_token)
18471849
).call()
18481850
)
18491851
token_out_decimals=self.get_token(token_out).decimals
@@ -1852,15 +1854,15 @@ def get_raw_price(
18521854
raw_price=token_out_balance/token_in_balance
18531855
else:
18541856
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),
18571859
fee,
18581860
]
18591861
pool_address=self.factory_contract.functions.getPool(*params).call()
18601862
pool_contract=_load_contract(
18611863
self.w3,abi_name="uniswap-v3/pool",address=pool_address
18621864
)
1863-
t0=pool_contract.functions.token0().call()
1865+
#t0 = pool_contract.functions.token0().call()
18641866
t1=pool_contract.functions.token1().call()
18651867
ift1.lower()==token_in.lower():
18661868
den0=self.get_token(token_in).decimals
@@ -1953,7 +1955,9 @@ def _token_address_from_exchange(self, exchange_addr: AddressLike) -> Address:
19531955
@functools.lru_cache()
19541956
@supports([1])
19551957
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,
19571961
)->Contract:
19581962
ifnotex_addrandtoken_addr:
19591963
ex_addr=self._exchange_address_from_token(token_addr)

‎uniswap/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
importfunctools
55
importlru
66

7-
fromtypingimportAny,Generator,Sequence,Union,List,Tuple,Type,Dict,cast
7+
fromtypingimportAny,Generator,List,Sequence,Tuple,Union
88

99
fromweb3importWeb3
1010
fromweb3.exceptionsimportNameNotFound
@@ -18,7 +18,7 @@
1818

1919
def_get_eth_simple_cache_middleware()->Middleware:
2020
returnconstruct_simple_cache_middleware(
21-
cache_class=cast(Type[Dict[Any,Any]],functools.partial(lru.LRU,256)),
21+
cache=functools.partial(lru.LRU,256),# type: ignore
2222
rpc_whitelist=SIMPLE_CACHE_RPC_WHITELIST,
2323
)
2424

@@ -37,10 +37,10 @@ def _str_to_addr(s: Union[AddressLike, str]) -> Address:
3737
def_addr_to_str(a:AddressLike)->str:
3838
ifisinstance(a,bytes):
3939
# Address or ChecksumAddress
40-
addr:str=Web3.toChecksumAddress("0x"+bytes(a).hex())
40+
addr:str=Web3.to_checksum_address("0x"+bytes(a).hex())
4141
returnaddr
4242
elifisinstance(a,str)anda.startswith("0x"):
43-
addr=Web3.toChecksumAddress(a)
43+
addr=Web3.to_checksum_address(a)
4444
returnaddr
4545

4646
raiseNameNotFound(a)
@@ -63,7 +63,7 @@ def _load_abi(name: str) -> str:
6363

6464
@functools.lru_cache()
6565
def_load_contract(w3:Web3,abi_name:str,address:AddressLike)->Contract:
66-
address=Web3.toChecksumAddress(address)
66+
address=Web3.to_checksum_address(address)
6767
returnw3.eth.contract(address=address,abi=_load_abi(abi_name))# type: ignore
6868

6969

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp