Skip to content

Commit

Permalink
Camelot Liquidity Pool manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Nov1kov committed Mar 10, 2024
1 parent dbb2494 commit c2362d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
34 changes: 25 additions & 9 deletions src/degenbot/uniswap/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..manager.token_manager import Erc20TokenHelperManager
from ..registry.all_pools import AllPools
from .abi import UNISWAP_V2_FACTORY_ABI
from .v2_liquidity_pool import LiquidityPool
from .v2_liquidity_pool import LiquidityPool, CamelotLiquidityPool
from .v3_functions import generate_v3_pool_address
from .v3_liquidity_pool import V3LiquidityPool
from .v3_snapshot import UniswapV3LiquiditySnapshot
Expand Down Expand Up @@ -227,14 +227,7 @@ def get_pool(
raise PoolNotAssociated(f"Pool {pool_address} is not associated with this DEX")

try:
pool_helper = LiquidityPool(
address=pool_address,
silent=silent,
state_block=state_block,
factory_address=self._factory_address,
factory_init_hash=self._factory_init_hash,
update_method=update_method,
)
pool_helper = self._create_pool(pool_address, silent, state_block, update_method)
except Exception as e:
self._untracked_pools.add(
pool_address
Expand All @@ -245,6 +238,29 @@ def get_pool(
self._add_pool(pool_helper)
return pool_helper

def _create_pool(self, pool_address, silent, state_block, update_method):
return LiquidityPool(
address=pool_address,
silent=silent,
state_block=state_block,
factory_address=self._factory_address,
factory_init_hash=self._factory_init_hash,
update_method=update_method,
)


class CamelotV2LiquidityPoolManager(UniswapV2LiquidityPoolManager):

def _create_pool(self, pool_address, silent, state_block, update_method):
return CamelotLiquidityPool(
address=pool_address,
silent=silent,
state_block=state_block,
factory_address=self._factory_address,
factory_init_hash=self._factory_init_hash,
update_method=update_method,
)


class UniswapV3LiquidityPoolManager(UniswapLiquidityPoolManager):
"""
Expand Down
23 changes: 8 additions & 15 deletions src/degenbot/uniswap/v2_liquidity_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(
silent: bool = False,
state_block: int | None = None,
empty: bool = False,
w3_contract: Contract | None = None,
update_reserves_on_start: bool | None = None, # deprecated
unload_brownie_contract_after_init: bool | None = None, # deprecated
) -> None:
Expand Down Expand Up @@ -122,7 +123,7 @@ def __init__(
self.abi = abi if abi is not None else UNISWAP_V2_POOL_ABI

_w3 = config.get_web3()
_w3_contract = self._w3_contract
_w3_contract = self._w3_contract if w3_contract is None else w3_contract

if factory_address:
if factory_init_hash is None:
Expand Down Expand Up @@ -792,19 +793,10 @@ def __init__(
update_method: str = "polling",
abi: List[Any] | None = None,
silent: bool = False,
update_reserves_on_start: bool | None = None, # deprecated
unload_brownie_contract_after_init: bool | None = None, # deprecated
state_block: int | None = None,
factory_address: str | None = None,
factory_init_hash: str | None = None,
) -> None:
if unload_brownie_contract_after_init is not None: # pragma: no cover
warnings.warn(
"unload_brownie_contract_after_init is no longer needed and is "
"ignored. Remove constructor argument to stop seeing this "
"message."
)

if update_reserves_on_start is not None: # pragma: no cover
warnings.warn("update_reserves_on_start has been deprecated.")

address = to_checksum_address(address)

if abi is None:
Expand All @@ -813,8 +805,6 @@ def __init__(
_w3 = config.get_web3()
_w3_contract = config.get_web3().eth.contract(address=address, abi=abi)

state_block = _w3.eth.get_block_number()

(
_,
_,
Expand All @@ -836,6 +826,9 @@ def __init__(
fee=(fee_token0, fee_token1),
silent=silent,
state_block=state_block,
factory_address=factory_address,
factory_init_hash=factory_init_hash,
w3_contract=_w3_contract,
)

self.stable_swap: bool = _w3_contract.functions.stableSwap().call()
Expand Down

0 comments on commit c2362d5

Please sign in to comment.