1818)
1919from .types import AddressLike ,UniswapV4_slot0 ,UniswapV4_position_info ,UniswapV4_tick_info
2020from .token import ERC20Token
21- from .tokens import tokens ,tokens_rinkeby
2221from .exceptions import InvalidToken ,InsufficientBalance
2322from .util import (
2423_str_to_addr ,
@@ -116,7 +115,7 @@ def get_price(
116115tick_spacing :int ,
117116sqrt_price_limit_x96 :int = 0 ,
118117zero_for_one :bool = True ,
119- hooks :AddressLike = NOHOOK_ADDRESS ,
118+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
120119 )-> int :
121120"""
122121 :if `zero_to_one` is true: given `qty` amount of the input `token0`, returns the maximum output amount of output `token1`.
@@ -127,8 +126,8 @@ def get_price(
127126raise ValueError
128127
129128pool_key = {
130- "currency0" :currency0 . address ,
131- "currency1" :currency1 . address ,
129+ "currency0" :currency0 ,
130+ "currency1" :currency1 ,
132131"fee" :fee ,
133132"tickSpacing" :tick_spacing ,
134133"hooks" :hooks ,
@@ -146,7 +145,7 @@ def get_price(
146145"key" :pool_key ,
147146"params" :swap_params ,
148147 }
149- ).buildTransaction (tx_params )
148+ ).build_transaction (tx_params )
150149# Uniswap3 uses 20% margin for transactions
151150transaction ["gas" ]= Wei (int (self .w3 .eth .estimate_gas (transaction )* 1.2 ))
152151signed_txn = self .w3 .eth .account .sign_transaction (
@@ -156,7 +155,7 @@ def get_price(
156155try :
157156price = self .w3 .eth .call (signed_txn )
158157except ContractLogicError as revert :
159- price = self .w3 .codec .decode_abi (["int128[]" ,"uint160" ,"uint32" ],revert .data )[1 ]
158+ price = int ( self .w3 .codec .decode_abi (["int128[]" ,"uint160" ,"uint32" ],revert .data )[1 ])
160159return price
161160
162161def get_slot0 (
@@ -165,7 +164,7 @@ def get_slot0(
165164currency1 :AddressLike ,# output token
166165fee :int ,
167166tick_spacing :int ,
168- hooks :AddressLike = NOHOOK_ADDRESS ,
167+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
169168 )-> UniswapV4_slot0 :
170169"""
171170 :Get the current value in slot0 of the given pool
@@ -181,13 +180,13 @@ def get_liquidity(
181180currency1 :AddressLike ,# output token
182181fee :int ,
183182tick_spacing :int ,
184- hooks :AddressLike = NOHOOK_ADDRESS ,
183+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
185184 )-> int :
186185"""
187186 :Get the current value of liquidity of the given pool
188187 """
189188pool_id = get_pool_id (currency0 ,currency1 ,fee ,tick_spacing ,hooks )
190- liquidity = self .router .functions .getLiquidity (pool_id ).call ()
189+ liquidity = int ( self .router .functions .getLiquidity (pool_id ).call () )
191190return liquidity
192191
193192def get_liquidity_for_position (
@@ -196,16 +195,16 @@ def get_liquidity_for_position(
196195currency1 :AddressLike ,# output token
197196fee :int ,
198197tick_spacing :int ,
199- owner :AddressLike ,# output token
198+ owner :AddressLike ,
200199tick_lower :int ,
201200tick_upper :int ,
202- hooks :AddressLike = NOHOOK_ADDRESS ,
201+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
203202 )-> int :
204203"""
205204 :Get the current value of liquidity for the specified pool and position
206205 """
207206pool_id = get_pool_id (currency0 ,currency1 ,fee ,tick_spacing ,hooks )
208- liquidity = self .router .functions .getLiquidity (pool_id ,owner ,tick_lower ,tick_upper ).call ()
207+ liquidity = int ( self .router .functions .getLiquidity (pool_id ,owner ,tick_lower ,tick_upper ).call () )
209208return liquidity
210209
211210def get_position (
@@ -217,7 +216,7 @@ def get_position(
217216owner :AddressLike ,# output token
218217tick_lower :int ,
219218tick_upper :int ,
220- hooks :AddressLike = NOHOOK_ADDRESS ,
219+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
221220 )-> UniswapV4_position_info :
222221"""
223222 :Get the current value of liquidity for the specified pool and position
@@ -233,7 +232,7 @@ def get_pool_tick_info(
233232fee :int ,
234233tick_spacing :int ,
235234tick :int ,
236- hooks :AddressLike = NOHOOK_ADDRESS ,
235+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
237236 )-> UniswapV4_tick_info :
238237"""
239238 :Get the current value of liquidity for the specified pool and position
@@ -249,13 +248,13 @@ def get_pool_bitmap_info(
249248fee :int ,
250249tick_spacing :int ,
251250word :int ,
252- hooks :AddressLike = NOHOOK_ADDRESS ,
251+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
253252 )-> int :
254253"""
255254 :Get the current value of liquidity for the specified pool and position
256255 """
257256pool_id = get_pool_id (currency0 ,currency1 ,fee ,tick_spacing ,hooks )
258- bitmap_info = self .router .functions .getPoolBitmapInfo (pool_id ,word ).call ()
257+ bitmap_info = int ( self .router .functions .getPoolBitmapInfo (pool_id ,word ).call () )
259258return bitmap_info
260259
261260def currency_delta (
@@ -285,12 +284,12 @@ def swap(
285284self ,
286285currency0 :ERC20Token ,
287286currency1 :ERC20Token ,
288- qty :Union [ int , Wei ] ,
287+ qty :int ,
289288fee :int ,
290289tick_spacing :int ,
291290sqrt_price_limit_x96 :int = 0 ,
292291zero_for_one :bool = True ,
293- hooks :AddressLike = NOHOOK_ADDRESS ,
292+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
294293 )-> HexBytes :
295294"""
296295 :Swap against the given pool
@@ -334,11 +333,11 @@ def initialize(
334333self ,
335334currency0 :ERC20Token ,
336335currency1 :ERC20Token ,
337- qty :Union [ int , Wei ] ,
336+ qty :int ,
338337fee :int ,
339338tick_spacing :int ,
340339sqrt_price_limit_x96 :int ,
341- hooks :AddressLike = NOHOOK_ADDRESS ,
340+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
342341 )-> HexBytes :
343342"""
344343 :Initialize the state for a given pool key
@@ -374,11 +373,11 @@ def donate(
374373self ,
375374currency0 :ERC20Token ,
376375currency1 :ERC20Token ,
377- qty :Union [ int , Wei ] ,
376+ qty :int ,
378377fee :int ,
379378tick_spacing :int ,
380379sqrt_price_limit_x96 :int ,
381- hooks :AddressLike = NOHOOK_ADDRESS ,
380+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
382381 )-> HexBytes :
383382"""
384383 :Donate the given currency amounts to the pool with the given pool key
@@ -414,12 +413,12 @@ def modify_position(
414413self ,
415414currency0 :ERC20Token ,
416415currency1 :ERC20Token ,
417- qty :Union [ int , Wei ] ,
416+ qty :int ,
418417fee :int ,
419418tick_spacing :int ,
420419tick_upper :int ,
421420tick_lower :int ,
422- hooks :AddressLike = NOHOOK_ADDRESS ,
421+ hooks :Union [ AddressLike , str , None ] = NOHOOK_ADDRESS ,
423422 )-> HexBytes :
424423"""
425424 :Modify the liquidity for the given pool
@@ -461,7 +460,7 @@ def modify_position(
461460def settle (
462461self ,
463462currency0 :ERC20Token ,
464- qty :Union [ int , Wei ] ,
463+ qty :int ,
465464 )-> HexBytes :
466465"""
467466 :Called by the user to pay what is owed
@@ -480,7 +479,7 @@ def take(
480479self ,
481480currency0 :ERC20Token ,
482481to :AddressLike ,
483- qty :Union [ int , Wei ] ,
482+ qty :int ,
484483 )-> HexBytes :
485484"""
486485 :Called by the user to net out some value owed to the user
@@ -597,7 +596,7 @@ def get_token(self, address: AddressLike, abi_name: str = "erc20") -> ERC20Token
597596return ERC20Token (symbol ,address ,name ,decimals )
598597
599598def get_pool_id (self ,currency0 :AddressLike ,currency1 :AddressLike ,fee :int ,tickSpacing :int ,hooks :AddressLike = ETH )-> bytes :
600- if int (currency0 )> (currency1 ):
599+ if int (currency0 )> int (currency1 ):
601600currency0 ,currency1 = currency1 ,currency0
602601return self .w3 .solidity_keccak (["address" ,"address" ,"int24" ,"int24" ,"address" ], [(currency0 ,currency1 ,fee ,tickSpacing ,hooks )])
603602