Skip to content

fix p1 #366

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Changes from all 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
21 changes: 13 additions & 8 deletions uniswap/uniswap4.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import List, Any, Optional, Union, Tuple, Dict

from web3 import Web3
from web3.eth import Contract
from web3.contract import ContractFunction
from web3.contract import Contract
from web3.contract.contract import ContractFunction
from web3.exceptions import BadFunctionCallOutput, ContractLogicError
from web3.types import (
TxParams,
Expand Down Expand Up @@ -34,6 +34,7 @@
_netid_to_name,
_poolmanager_contract_addresses,
ETH_ADDRESS,
NOHOOK_ADDRESS,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -86,17 +87,22 @@ def __init__(

self.last_nonce: Nonce = self.w3.eth.get_transaction_count(self.address)

max_approval_hex = f"0x{64 * 'f'}"
self.max_approval_int = int(max_approval_hex, 16)
max_approval_check_hex = f"0x{15 * '0'}{49 * 'f'}"
self.max_approval_check_int = int(max_approval_check_hex, 16)

if poolmanager_contract_addr is None:
poolmanager_contract_addr = _poolmanager_contract_addresses[self.network]

self.poolmanager_contract = _load_contract(
self.router = _load_contract(
self.w3,
abi_name="uniswap-v4/poolmanager",
address=_str_to_addr(poolmanager_contract_addr),
)

if hasattr(self, "poolmanager_contract"):
logger.info(f"Using pool manager contract: {self.poolmanager_contract}")
logger.info(f"Using pool manager contract: {self.router}")

# ------ Contract calls ------------------------------------------------------------

Expand All @@ -109,9 +115,8 @@ def get_price(
qty: int,
fee: int,
tick_spacing: int,
zero_to_one: bool = true,
sqrt_price_limit_x96: int = 0,
zero_for_one: bool = true,
zero_for_one: bool = True,
hooks: AddressLike = NOHOOK_ADDRESS,
) -> int:
"""
Expand Down Expand Up @@ -285,7 +290,7 @@ def swap(
fee: int,
tick_spacing: int,
sqrt_price_limit_x96: int = 0,
zero_for_one: bool = true,
zero_for_one: bool = True,
hooks: AddressLike = NOHOOK_ADDRESS,
) -> HexBytes:
"""
Expand Down Expand Up @@ -593,7 +598,7 @@ def get_token(self, address: AddressLike, abi_name: str = "erc20") -> ERC20Token
return ERC20Token(symbol, address, name, decimals)

def get_pool_id(self, currency0: AddressLike, currency1: AddressLike, fee : int, tickSpacing : int, hooks : AddressLike = ETH) -> bytes:
if currency0 > currency1:
if int(currency0) > (currency1):
currency0 , currency1 = currency1 , currency0
return self.w3.keccak_solidity(["address", "address", "int24", "int24", "address"], [(currency0, currency1, fee, tickSpacing, hooks)])

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy