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
22 changes: 11 additions & 11 deletions uniswap/uniswap4.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
provider: Optional[str] = None,
web3: Optional[Web3] = None,
default_slippage: float = 0.01,
poolmanager_contract_addr: Optional[str] = None,
poolmanager_contract_addr: Optional[AddressLike,str] = None,
) -> None:
"""
:param address: The public address of the ETH wallet to use.
Expand Down Expand Up @@ -155,7 +155,7 @@ def get_price(
try:
price = int(self.w3.eth.call(signed_txn))
except ContractLogicError as revert:
price = int(self.w3.codec.decode_abi(["int128[]","uint160","uint32"], revert.data)[1])
price = int(self.w3.codec.decode(["int128[]","uint160","uint32"], bytes(revert))[1])
return price

def get_slot0(
Expand All @@ -170,7 +170,7 @@ def get_slot0(
:Get the current value in slot0 of the given pool
"""

pool_id = get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
pool_id = self.get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
slot0 = UniswapV4_slot0(*self.router.functions.getSlot0(pool_id).call())
return slot0

Expand All @@ -185,7 +185,7 @@ def get_liquidity(
"""
:Get the current value of liquidity of the given pool
"""
pool_id = get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
pool_id = self.get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
liquidity = int(self.router.functions.getLiquidity(pool_id).call())
return liquidity

Expand All @@ -203,7 +203,7 @@ def get_liquidity_for_position(
"""
:Get the current value of liquidity for the specified pool and position
"""
pool_id = get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
pool_id = self.get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
liquidity = int(self.router.functions.getLiquidity(pool_id,owner,tick_lower,tick_upper).call())
return liquidity

Expand All @@ -221,7 +221,7 @@ def get_position(
"""
:Get the current value of liquidity for the specified pool and position
"""
pool_id = get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
pool_id = self.get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
liquidity = UniswapV4_position_info(*self.router.functions.getPosition(pool_id,owner,tick_lower,tick_upper).call())
return liquidity

Expand All @@ -237,7 +237,7 @@ def get_pool_tick_info(
"""
:Get the current value of liquidity for the specified pool and position
"""
pool_id = get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
pool_id = self.get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
tick_info = UniswapV4_tick_info(*self.router.functions.getPoolTickInfo(pool_id,tick).call())
return tick_info

Expand All @@ -253,7 +253,7 @@ def get_pool_bitmap_info(
"""
:Get the current value of liquidity for the specified pool and position
"""
pool_id = get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
pool_id = self.get_pool_id(currency0, currency1, fee, tick_spacing, hooks)
bitmap_info = int(self.router.functions.getPoolBitmapInfo(pool_id, word).call())
return bitmap_info

Expand Down Expand Up @@ -515,7 +515,7 @@ def get_token_balance(self, token: AddressLike) -> int:
def approve(self, token: AddressLike, max_approval: Optional[int] = None) -> None:
"""Give an exchange/router max approval of a token."""
max_approval = self.max_approval_int if not max_approval else max_approval
contract_addr = poolmanager_contract_addr
contract_addr = self.poolmanager_contract_addr
function = _load_contract_erc20(self.w3, token).functions.approve(
contract_addr, max_approval
)
Expand All @@ -537,7 +537,7 @@ def _build_and_send_tx(
"""Build and send a transaction."""
if not tx_params:
tx_params = self._get_tx_params()
transaction = function.buildTransaction(tx_params)
transaction = function.build_transaction(tx_params)
# Uniswap3 uses 20% margin for transactions
transaction["gas"] = Wei(int(self.w3.eth.estimate_gas(transaction) * 1.2))
signed_txn = self.w3.eth.account.sign_transaction(
Expand Down Expand Up @@ -570,7 +570,7 @@ def get_token(self, address: AddressLike, abi_name: str = "erc20") -> ERC20Token
# FIXME: This function should always return the same output for the same input
# and would therefore benefit from caching
if address == ETH_ADDRESS:
return ERC20Token("ETH", ETH_ADDRESS, "Ether", 18)
return ERC20Token("ETH", address, "Ether", 18)
token_contract = _load_contract(self.w3, abi_name, address=address)
try:
_name = token_contract.functions.name().call()
Expand Down