Skip to content
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