5
5
from typing import List ,Any ,Optional ,Union ,Tuple ,Dict
6
6
7
7
from web3 import Web3
8
- from web3 .eth import Contract
9
- from web3 .contract import ContractFunction
8
+ from web3 .contract import Contract
9
+ from web3 .contract . contract import ContractFunction
10
10
from web3 .exceptions import BadFunctionCallOutput ,ContractLogicError
11
11
from web3 .types import (
12
12
TxParams ,
34
34
_netid_to_name ,
35
35
_poolmanager_contract_addresses ,
36
36
ETH_ADDRESS ,
37
+ NOHOOK_ADDRESS ,
37
38
)
38
39
39
40
logger = logging .getLogger (__name__ )
@@ -86,17 +87,22 @@ def __init__(
86
87
87
88
self .last_nonce :Nonce = self .w3 .eth .get_transaction_count (self .address )
88
89
90
+ max_approval_hex = f"0x{ 64 * 'f' } "
91
+ self .max_approval_int = int (max_approval_hex ,16 )
92
+ max_approval_check_hex = f"0x{ 15 * '0' } { 49 * 'f' } "
93
+ self .max_approval_check_int = int (max_approval_check_hex ,16 )
94
+
89
95
if poolmanager_contract_addr is None :
90
96
poolmanager_contract_addr = _poolmanager_contract_addresses [self .network ]
91
97
92
- self .poolmanager_contract = _load_contract (
98
+ self .router = _load_contract (
93
99
self .w3 ,
94
100
abi_name = "uniswap-v4/poolmanager" ,
95
101
address = _str_to_addr (poolmanager_contract_addr ),
96
102
)
97
103
98
104
if hasattr (self ,"poolmanager_contract" ):
99
- logger .info (f"Using pool manager contract:{ self .poolmanager_contract } " )
105
+ logger .info (f"Using pool manager contract:{ self .router } " )
100
106
101
107
# ------ Contract calls ------------------------------------------------------------
102
108
@@ -109,9 +115,8 @@ def get_price(
109
115
qty :int ,
110
116
fee :int ,
111
117
tick_spacing :int ,
112
- zero_to_one :bool = true ,
113
118
sqrt_price_limit_x96 :int = 0 ,
114
- zero_for_one :bool = true ,
119
+ zero_for_one :bool = True ,
115
120
hooks :AddressLike = NOHOOK_ADDRESS ,
116
121
)-> int :
117
122
"""
@@ -285,7 +290,7 @@ def swap(
285
290
fee :int ,
286
291
tick_spacing :int ,
287
292
sqrt_price_limit_x96 :int = 0 ,
288
- zero_for_one :bool = true ,
293
+ zero_for_one :bool = True ,
289
294
hooks :AddressLike = NOHOOK_ADDRESS ,
290
295
)-> HexBytes :
291
296
"""
@@ -593,7 +598,7 @@ def get_token(self, address: AddressLike, abi_name: str = "erc20") -> ERC20Token
593
598
return ERC20Token (symbol ,address ,name ,decimals )
594
599
595
600
def get_pool_id (self ,currency0 :AddressLike ,currency1 :AddressLike ,fee :int ,tickSpacing :int ,hooks :AddressLike = ETH )-> bytes :
596
- if currency0 > currency1 :
601
+ if int ( currency0 ) > ( currency1 ) :
597
602
currency0 ,currency1 = currency1 ,currency0
598
603
return self .w3 .keccak_solidity (["address" ,"address" ,"int24" ,"int24" ,"address" ], [(currency0 ,currency1 ,fee ,tickSpacing ,hooks )])
599
604