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

Commitf28ec7e

Browse files
authored
Merge pull request#396 from liquid-8/dev
final fixes and clean-ups
2 parentsb7bb565 +7383ee0 commitf28ec7e

File tree

2 files changed

+74
-14
lines changed

2 files changed

+74
-14
lines changed

‎uniswap/types.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __repr__(self) -> str:
3535
returnf"Tick info (liquidityGross:{self.liquidityGross}; liquidityNet:{self.liquidityNet}; feeGrowthOutside0X128:{self.feeGrowthOutside0X128}; feeGrowthOutside1X128:{self.feeGrowthOutside1X128!r})"
3636

3737
@dataclass
38-
classUniswapV4_PathKey:
38+
classUniswapV4_path_key:
3939
# The lower currency of the pool, sorted numerically
4040
currency0 :Address
4141
# The higher currency of the pool, sorted numerically

‎uniswap/uniswap4.py‎

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Nonce,
1818
HexBytes,
1919
)
20-
from .typesimportAddressLike,UniswapV4_slot0,UniswapV4_position_info,UniswapV4_tick_info,UniswapV4_PathKey
20+
from .typesimportAddressLike,UniswapV4_slot0,UniswapV4_position_info,UniswapV4_tick_info,UniswapV4_path_key
2121
from .tokenimportERC20Token
2222
from .exceptionsimportInvalidToken,InsufficientBalance
2323
from .utilimport (
@@ -210,7 +210,7 @@ def get_quote_exact_input(
210210
self,
211211
currency:AddressLike,# input token
212212
qty:int,
213-
path :List[UniswapV4_PathKey],
213+
path :List[UniswapV4_path_key],
214214
)->Any:
215215
"""
216216
:path is a swap route
@@ -234,7 +234,7 @@ def get_quote_exact_output(
234234
self,
235235
currency:AddressLike,# input token
236236
qty:int,
237-
path :List[UniswapV4_PathKey],
237+
path :List[UniswapV4_path_key],
238238
)->Any:
239239
"""
240240
:path is a swap route
@@ -384,6 +384,7 @@ def swap(
384384
qty:int,
385385
fee:int,
386386
tick_spacing:int,
387+
hook_data :bytes,
387388
sqrt_price_limit_x96:int=0,
388389
zero_for_one:bool=True,
389390
hooks:Union[AddressLike,str,None]=NOHOOK_ADDRESS,
@@ -437,6 +438,7 @@ def initialize(
437438
fee:int,
438439
tick_spacing:int,
439440
sqrt_price_limit_x96:int,
441+
hook_data :bytes,
440442
hooks:Union[AddressLike,str,None]=NOHOOK_ADDRESS,
441443
gas:Optional[Wei]=None,
442444
max_fee:Optional[Wei]=None,
@@ -467,6 +469,7 @@ def initialize(
467469
{
468470
"key":pool_key,
469471
"sqrtPriceX96":sqrt_price_limit_x96,
472+
"hookData":hook_data,
470473
}
471474
),
472475
self._get_tx_params(gas=gas,max_fee=max_fee,priority_fee=priority_fee),
@@ -476,10 +479,12 @@ def donate(
476479
self,
477480
currency0:ERC20Token,
478481
currency1:ERC20Token,
479-
qty:int,
482+
qty1:int,
483+
qty2:int,
480484
fee:int,
481485
tick_spacing:int,
482486
sqrt_price_limit_x96:int,
487+
hook_data :bytes,
483488
hooks:Union[AddressLike,str,None]=NOHOOK_ADDRESS,
484489
gas:Optional[Wei]=None,
485490
max_fee:Optional[Wei]=None,
@@ -509,13 +514,15 @@ def donate(
509514
self.router.functions.donate(
510515
{
511516
"key":pool_key,
512-
"sqrtPriceX96":sqrt_price_limit_x96,
517+
"amount0":qty1,
518+
"amount1":qty2,
519+
"hookData":hook_data,
513520
}
514521
),
515522
self._get_tx_params(gas=gas,max_fee=max_fee,priority_fee=priority_fee),
516523
)
517524

518-
defmodify_position(
525+
defmodify_liquidity(
519526
self,
520527
currency0:ERC20Token,
521528
currency1:ERC20Token,
@@ -524,6 +531,8 @@ def modify_position(
524531
tick_spacing:int,
525532
tick_upper:int,
526533
tick_lower:int,
534+
salt :int,
535+
hook_data :bytes,
527536
hooks:Union[AddressLike,str,None]=NOHOOK_ADDRESS,
528537
gas:Optional[Wei]=None,
529538
max_fee:Optional[Wei]=None,
@@ -550,26 +559,27 @@ def modify_position(
550559
"hooks":hooks,
551560
}
552561

553-
modify_position_params= {
562+
modify_liquidity_params= {
554563
"tickLower":tick_lower,
555564
"tickUpper":tick_upper,
556565
"liquidityDelta":qty,
566+
"salt":salt,
557567
}
558568

559569
returnself._build_and_send_tx(
560-
self.router.functions.modifyPosition(
570+
self.router.functions.modifyLiquidity(
561571
{
562572
"key":pool_key,
563573
"params":modify_position_params,
574+
"hookData":hook_data,
564575
}
565576
),
566577
self._get_tx_params(value=Wei(qty),gas=gas,max_fee=max_fee,priority_fee=priority_fee),
567578
)
568579

569580
defsettle(
570581
self,
571-
currency0:ERC20Token,
572-
qty:int,
582+
currency0:Union[AddressLike,str,None],
573583
gas:Optional[Wei]=None,
574584
max_fee:Optional[Wei]=None,
575585
priority_fee:Optional[Wei]=None,
@@ -589,7 +599,7 @@ def settle(
589599

590600
deftake(
591601
self,
592-
currency0:ERC20Token,
602+
currency0:Union[AddressLike,str,None],
593603
to:AddressLike,
594604
qty:int,
595605
gas:Optional[Wei]=None,
@@ -612,6 +622,56 @@ def take(
612622
self._get_tx_params(gas=gas,max_fee=max_fee,priority_fee=priority_fee),
613623
)
614624

625+
defmint(
626+
self,
627+
currency0:Union[AddressLike,str,None],
628+
id:int,
629+
qty:int,
630+
gas:Optional[Wei]=None,
631+
max_fee:Optional[Wei]=None,
632+
priority_fee:Optional[Wei]=None,
633+
)->HexBytes:
634+
"""
635+
:Called by the user to net out some value owed to the user
636+
:Can also be used as a mechanism for _free_ flash loans
637+
"""
638+
639+
returnself._build_and_send_tx(
640+
self.router.functions.mint(
641+
{
642+
"currency ":currency0,
643+
"id ":id,
644+
"amount ":qty,
645+
}
646+
),
647+
self._get_tx_params(gas=gas,max_fee=max_fee,priority_fee=priority_fee),
648+
)
649+
650+
defburn(
651+
self,
652+
currency0:Union[AddressLike,str,None],
653+
id:int,
654+
qty:int,
655+
gas:Optional[Wei]=None,
656+
max_fee:Optional[Wei]=None,
657+
priority_fee:Optional[Wei]=None,
658+
)->HexBytes:
659+
"""
660+
:Called by the user to net out some value owed to the user
661+
:Can also be used as a mechanism for _free_ flash loans
662+
"""
663+
664+
returnself._build_and_send_tx(
665+
self.router.functions.burn(
666+
{
667+
"currency ":currency0,
668+
"id ":id,
669+
"amount ":qty,
670+
}
671+
),
672+
self._get_tx_params(gas=gas,max_fee=max_fee,priority_fee=priority_fee),
673+
)
674+
615675
# ------ Wallet balance ------------------------------------------------------------
616676
defget_eth_balance(self)->Wei:
617677
"""Get the balance of ETH for your address."""
@@ -715,8 +775,8 @@ def get_token(self, address: AddressLike, abi_name: str = "erc20") -> ERC20Token
715775
symbol=_symbol
716776
returnERC20Token(symbol,address,name,decimals)
717777

718-
defget_pool_id(self,currency0:AddressLike,currency1:AddressLike,fee :int,tickSpacing :int,hooks :Union[AddressLike,str,None]=NOHOOK_ADDRESS)->bytes:
719-
ifint(currency0)>int(currency1):
778+
defget_pool_id(self,currency0:str,currency1:str,fee :int,tickSpacing :int,hooks :Union[AddressLike,str,None]=NOHOOK_ADDRESS)->bytes:
779+
ifint(currency0,16)>int(currency1,16):
720780
currency0 ,currency1=currency1 ,currency0
721781
pool_id=bytes(self.w3.solidity_keccak(["address","address","int24","int24","address"], [(currency0,currency1,fee,tickSpacing,hooks)]))
722782
returnpool_id

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp