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

final fixes and clean-ups#396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
liquid-8 merged 1 commit intouniswap-python:dev/v4fromliquid-8:dev
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionuniswap/types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,7 @@ def __repr__(self) -> str:
return f"Tick info (liquidityGross: {self.liquidityGross}; liquidityNet: {self.liquidityNet}; feeGrowthOutside0X128: {self.feeGrowthOutside0X128}; feeGrowthOutside1X128: {self.feeGrowthOutside1X128!r})"

@dataclass
classUniswapV4_PathKey:
classUniswapV4_path_key:
# The lower currency of the pool, sorted numerically
currency0 : Address
# The higher currency of the pool, sorted numerically
Expand Down
86 changes: 73 additions & 13 deletionsuniswap/uniswap4.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@
Nonce,
HexBytes,
)
from .types import AddressLike, UniswapV4_slot0, UniswapV4_position_info, UniswapV4_tick_info,UniswapV4_PathKey
from .types import AddressLike, UniswapV4_slot0, UniswapV4_position_info, UniswapV4_tick_info,UniswapV4_path_key
from .token import ERC20Token
from .exceptions import InvalidToken, InsufficientBalance
from .util import (
Expand DownExpand Up@@ -210,7 +210,7 @@ def get_quote_exact_input(
self,
currency: AddressLike, # input token
qty: int,
path : List[UniswapV4_PathKey],
path : List[UniswapV4_path_key],
) -> Any:
"""
:path is a swap route
Expand All@@ -234,7 +234,7 @@ def get_quote_exact_output(
self,
currency: AddressLike, # input token
qty: int,
path : List[UniswapV4_PathKey],
path : List[UniswapV4_path_key],
) -> Any:
"""
:path is a swap route
Expand DownExpand Up@@ -384,6 +384,7 @@ def swap(
qty: int,
fee: int,
tick_spacing: int,
hook_data : bytes,
sqrt_price_limit_x96: int = 0,
zero_for_one: bool = True,
hooks: Union[AddressLike, str, None] = NOHOOK_ADDRESS,
Expand DownExpand Up@@ -437,6 +438,7 @@ def initialize(
fee: int,
tick_spacing: int,
sqrt_price_limit_x96: int,
hook_data : bytes,
hooks: Union[AddressLike, str, None] = NOHOOK_ADDRESS,
gas: Optional[Wei] = None,
max_fee: Optional[Wei] = None,
Expand DownExpand Up@@ -467,6 +469,7 @@ def initialize(
{
"key": pool_key,
"sqrtPriceX96": sqrt_price_limit_x96,
"hookData": hook_data,
}
),
self._get_tx_params(gas = gas, max_fee = max_fee, priority_fee = priority_fee),
Expand All@@ -476,10 +479,12 @@ def donate(
self,
currency0: ERC20Token,
currency1: ERC20Token,
qty: int,
qty1: int,
qty2: int,
fee: int,
tick_spacing: int,
sqrt_price_limit_x96: int,
hook_data : bytes,
hooks: Union[AddressLike, str, None] = NOHOOK_ADDRESS,
gas: Optional[Wei] = None,
max_fee: Optional[Wei] = None,
Expand DownExpand Up@@ -509,13 +514,15 @@ def donate(
self.router.functions.donate(
{
"key": pool_key,
"sqrtPriceX96": sqrt_price_limit_x96,
"amount0": qty1,
"amount1": qty2,
"hookData": hook_data,
}
),
self._get_tx_params(gas = gas, max_fee = max_fee, priority_fee = priority_fee),
)

defmodify_position(
defmodify_liquidity(
self,
currency0: ERC20Token,
currency1: ERC20Token,
Expand All@@ -524,6 +531,8 @@ def modify_position(
tick_spacing: int,
tick_upper: int,
tick_lower: int,
salt : int,
hook_data : bytes,
hooks: Union[AddressLike, str, None] = NOHOOK_ADDRESS,
gas: Optional[Wei] = None,
max_fee: Optional[Wei] = None,
Expand All@@ -550,26 +559,27 @@ def modify_position(
"hooks": hooks,
}

modify_position_params = {
modify_liquidity_params = {
"tickLower": tick_lower,
"tickUpper": tick_upper,
"liquidityDelta": qty,
"salt": salt,
}

return self._build_and_send_tx(
self.router.functions.modifyPosition(
self.router.functions.modifyLiquidity(
{
"key": pool_key,
"params": modify_position_params,
"hookData": hook_data,
}
),
self._get_tx_params(value=Wei(qty), gas = gas, max_fee = max_fee, priority_fee = priority_fee),
)

def settle(
self,
currency0: ERC20Token,
qty: int,
currency0: Union[AddressLike, str, None],
gas: Optional[Wei] = None,
max_fee: Optional[Wei] = None,
priority_fee: Optional[Wei] = None,
Expand All@@ -589,7 +599,7 @@ def settle(

def take(
self,
currency0:ERC20Token,
currency0:Union[AddressLike, str, None],
to: AddressLike,
qty: int,
gas: Optional[Wei] = None,
Expand All@@ -612,6 +622,56 @@ def take(
self._get_tx_params(gas = gas, max_fee = max_fee, priority_fee = priority_fee),
)

def mint(
self,
currency0: Union[AddressLike, str, None],
id: int,
qty: int,
gas: Optional[Wei] = None,
max_fee: Optional[Wei] = None,
priority_fee: Optional[Wei] = None,
) -> HexBytes:
"""
:Called by the user to net out some value owed to the user
:Can also be used as a mechanism for _free_ flash loans
"""

return self._build_and_send_tx(
self.router.functions.mint(
{
"currency ": currency0,
"id ": id,
"amount ": qty,
}
),
self._get_tx_params(gas = gas, max_fee = max_fee, priority_fee = priority_fee),
)

def burn(
self,
currency0: Union[AddressLike, str, None],
id: int,
qty: int,
gas: Optional[Wei] = None,
max_fee: Optional[Wei] = None,
priority_fee: Optional[Wei] = None,
) -> HexBytes:
"""
:Called by the user to net out some value owed to the user
:Can also be used as a mechanism for _free_ flash loans
"""

return self._build_and_send_tx(
self.router.functions.burn(
{
"currency ": currency0,
"id ": id,
"amount ": qty,
}
),
self._get_tx_params(gas = gas, max_fee = max_fee, priority_fee = priority_fee),
)

# ------ Wallet balance ------------------------------------------------------------
def get_eth_balance(self) -> Wei:
"""Get the balance of ETH for your address."""
Expand DownExpand Up@@ -715,8 +775,8 @@ def get_token(self, address: AddressLike, abi_name: str = "erc20") -> ERC20Token
symbol = _symbol
return ERC20Token(symbol, address, name, decimals)

def get_pool_id(self, currency0:AddressLike, currency1:AddressLike, fee : int, tickSpacing : int, hooks : Union[AddressLike, str, None] = NOHOOK_ADDRESS) -> bytes:
if int(currency0) > int(currency1):
def get_pool_id(self, currency0:str, currency1:str, fee : int, tickSpacing : int, hooks : Union[AddressLike, str, None] = NOHOOK_ADDRESS) -> bytes:
if int(currency0, 16) > int(currency1, 16):
currency0 , currency1 = currency1 , currency0
pool_id = bytes(self.w3.solidity_keccak(["address", "address", "int24", "int24", "address"], [(currency0, currency1, fee, tickSpacing, hooks)]))
return pool_id
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp