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

Commit8188da6

Browse files
authored
Merge pull request#368 from liquid-8/dev
and more
2 parentsf06e3d1 +fd3f932 commit8188da6

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

‎uniswap/uniswap4.py‎

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
)
1919
from .typesimportAddressLike,UniswapV4_slot0,UniswapV4_position_info,UniswapV4_tick_info
2020
from .tokenimportERC20Token
21-
from .tokensimporttokens,tokens_rinkeby
2221
from .exceptionsimportInvalidToken,InsufficientBalance
2322
from .utilimport (
2423
_str_to_addr,
@@ -116,7 +115,7 @@ def get_price(
116115
tick_spacing:int,
117116
sqrt_price_limit_x96:int=0,
118117
zero_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(
127126
raiseValueError
128127

129128
pool_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
151150
transaction["gas"]=Wei(int(self.w3.eth.estimate_gas(transaction)*1.2))
152151
signed_txn=self.w3.eth.account.sign_transaction(
@@ -156,7 +155,7 @@ def get_price(
156155
try:
157156
price=self.w3.eth.call(signed_txn)
158157
exceptContractLogicErrorasrevert:
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])
160159
returnprice
161160

162161
defget_slot0(
@@ -165,7 +164,7 @@ def get_slot0(
165164
currency1:AddressLike,# output token
166165
fee:int,
167166
tick_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(
181180
currency1:AddressLike,# output token
182181
fee:int,
183182
tick_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
"""
189188
pool_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())
191190
returnliquidity
192191

193192
defget_liquidity_for_position(
@@ -196,16 +195,16 @@ def get_liquidity_for_position(
196195
currency1:AddressLike,# output token
197196
fee:int,
198197
tick_spacing:int,
199-
owner:AddressLike,# output token
198+
owner:AddressLike,
200199
tick_lower:int,
201200
tick_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
"""
207206
pool_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())
209208
returnliquidity
210209

211210
defget_position(
@@ -217,7 +216,7 @@ def get_position(
217216
owner:AddressLike,# output token
218217
tick_lower:int,
219218
tick_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(
233232
fee:int,
234233
tick_spacing:int,
235234
tick: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(
249248
fee:int,
250249
tick_spacing:int,
251250
word: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
"""
257256
pool_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())
259258
returnbitmap_info
260259

261260
defcurrency_delta(
@@ -285,12 +284,12 @@ def swap(
285284
self,
286285
currency0:ERC20Token,
287286
currency1:ERC20Token,
288-
qty:Union[int,Wei],
287+
qty:int,
289288
fee:int,
290289
tick_spacing:int,
291290
sqrt_price_limit_x96:int=0,
292291
zero_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(
334333
self,
335334
currency0:ERC20Token,
336335
currency1:ERC20Token,
337-
qty:Union[int,Wei],
336+
qty:int,
338337
fee:int,
339338
tick_spacing:int,
340339
sqrt_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(
374373
self,
375374
currency0:ERC20Token,
376375
currency1:ERC20Token,
377-
qty:Union[int,Wei],
376+
qty:int,
378377
fee:int,
379378
tick_spacing:int,
380379
sqrt_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(
414413
self,
415414
currency0:ERC20Token,
416415
currency1:ERC20Token,
417-
qty:Union[int,Wei],
416+
qty:int,
418417
fee:int,
419418
tick_spacing:int,
420419
tick_upper:int,
421420
tick_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(
461460
defsettle(
462461
self,
463462
currency0: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(
480479
self,
481480
currency0:ERC20Token,
482481
to: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
597596
returnERC20Token(symbol,address,name,decimals)
598597

599598
defget_pool_id(self,currency0:AddressLike,currency1:AddressLike,fee :int,tickSpacing :int,hooks :AddressLike=ETH)->bytes:
600-
ifint(currency0)> (currency1):
599+
ifint(currency0)>int(currency1):
601600
currency0 ,currency1=currency1 ,currency0
602601
returnself.w3.solidity_keccak(["address","address","int24","int24","address"], [(currency0,currency1,fee,tickSpacing,hooks)])
603602

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp