From ab23b0489e8ea2eb963a165e55eae1855523529d Mon Sep 17 00:00:00 2001 From: liquid-8 Date: Thu, 6 Jun 2024 02:36:03 +0300 Subject: [PATCH] typing fixes --- uniswap/types.py | 3 --- uniswap/uniswap4.py | 6 ++++-- uniswap/util.py | 7 +++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/uniswap/types.py b/uniswap/types.py index a0a2a38c..a43c1324 100644 --- a/uniswap/types.py +++ b/uniswap/types.py @@ -46,6 +46,3 @@ class UniswapV4_PathKey: tickSpacing : int # The hooks of the pool hooks : List[Address] - - def __repr__(self) -> Tuple[Address, Address, int, int, List[Address]]: - return (self.currency0, self.currency1, self.fee, self.tickSpacing, self.hooks) \ No newline at end of file diff --git a/uniswap/uniswap4.py b/uniswap/uniswap4.py index 873b00e2..6babcaa8 100644 --- a/uniswap/uniswap4.py +++ b/uniswap/uniswap4.py @@ -215,9 +215,10 @@ def get_quote_exact_input( :path is a swap route """ + quote_path = [item.astulpe() for item in path] quote_params = { "exactCurrency": currency, - "path": path, + "path": quote_path, "recipient": self.address, "exactAmount": qty, } @@ -238,9 +239,10 @@ def get_quote_exact_output( :path is a swap route """ + quote_path = [item.astulpe() for item in path] quote_params = { "exactCurrency": currency, - "path": path, + "path": quote_path, "recipient": self.address, "exactAmount": qty, } diff --git a/uniswap/util.py b/uniswap/util.py index 1be2f993..7a50c5d9 100644 --- a/uniswap/util.py +++ b/uniswap/util.py @@ -81,8 +81,11 @@ def _encode_path(token_in: AddressLike, route: List[Tuple[int, AddressLike]]) -> # Adapted from: https://github.com/Uniswap/v3-sdk/blob/main/src/utils/encodeSqrtRatioX96.ts -def decode_sqrt_ratioX96(amount_0: int, amount_1: int) -> int: - return int(amount_0 * amount_0 * 10**amount_1 >> 192) +def decode_sqrt_ratioX96(sqrtPriceX96: int) -> float: + Q96 = 2**96 + ratio = sqrtPriceX96 / Q96 + price = ratio**2 + return price # Adapted from: https://github.com/Uniswap/v3-sdk/blob/main/src/utils/encodeSqrtRatioX96.ts def encode_sqrt_ratioX96(amount_0: int, amount_1: int) -> int: