Skip to content

Commit 4b56931

Browse files
committed
Refactor
Set chain IDs attribute in constructor (typ across project) Remove ABI in Curve pool Use batched requests in more places Make web3 connection manager multi-chain Make token and pool registry singletons Move Aerodrome V3 tests Linting and cleanup
1 parent 9067712 commit 4b56931

37 files changed

+1187
-901
lines changed

src/degenbot/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# TODO:
2-
# - add all module folders to __all__
32
# - AllTokens and AllPools improvements
43
# - singleton created at import
54
# - make getter/setter methods with chain ID
@@ -33,8 +32,8 @@
3332
from .logging import logger
3433
from .managers.erc20_token_manager import Erc20TokenManager
3534
from .pancakeswap.pools import PancakeV3Pool
36-
from .registry.all_pools import AllPools
37-
from .registry.all_tokens import AllTokens
35+
from .registry.all_pools import pool_registry
36+
from .registry.all_tokens import token_registry
3837
from .sushiswap.managers import SushiswapV2PoolManager, SushiswapV3PoolManager
3938
from .sushiswap.pools import SushiswapV2Pool, SushiswapV3Pool
4039
from .transaction.uniswap_transaction import UniswapTransaction
@@ -62,18 +61,18 @@
6261
"get_web3",
6362
"logger",
6463
"pancakeswap",
64+
"pool_registry",
6565
"set_web3",
6666
"solidly",
6767
"sushiswap",
68+
"token_registry",
6869
"uniswap",
6970
"AerodromeV2Pool",
7071
"AerodromeV2PoolManager",
7172
"AerodromeV2PoolState",
7273
"AerodromeV3Pool",
7374
"AerodromeV3PoolManager",
7475
"AerodromeV3PoolState",
75-
"AllPools",
76-
"AllTokens",
7776
"AnvilFork",
7877
"ArbitrageCalculationResult",
7978
"BuilderEndpoint",

src/degenbot/aerodrome/managers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
from degenbot.exceptions import AddressMismatch, DegenbotError, ManagerError, PoolNotAssociated
1010
from degenbot.logging import logger
11-
from degenbot.registry.all_pools import AllPools
11+
from degenbot.registry.all_pools import pool_registry
1212

1313
from ..aerodrome.pools import AerodromeV2Pool, AerodromeV3Pool
14-
from ..config import get_web3
14+
from ..config import web3_connection_manager
1515
from ..functions import encode_function_calldata, get_number_for_block_identifier, raw_call
1616
from ..uniswap.managers import UniswapV2PoolManager, UniswapV3PoolManager
1717
from .functions import generate_aerodrome_v3_pool_address
@@ -36,7 +36,7 @@ def get_pair_from_factory( # type: ignore[override]
3636
function_arguments=[token0, token1, stable],
3737
),
3838
return_types=["address"],
39-
block_identifier=get_number_for_block_identifier(block_identifier),
39+
block_identifier=get_number_for_block_identifier(block_identifier, w3),
4040
)
4141
return cast(str, pool_address)
4242

@@ -54,7 +54,7 @@ def get_pool_from_tokens( # type: ignore[override]
5454
pool = self._build_pool(
5555
pool_address=to_checksum_address(
5656
self.get_pair_from_factory(
57-
w3=get_web3(),
57+
w3=web3_connection_manager.get_web3(self.chain_id),
5858
token0=to_checksum_address(token_addresses[0]),
5959
token1=to_checksum_address(token_addresses[1]),
6060
stable=stable,
@@ -92,8 +92,12 @@ def _build_pool(
9292
f"Pool address {pool_address} not associated with factory {self._factory_address}"
9393
)
9494

95-
# Check if the AllPools collection already has this pool
96-
if (known_pool_helper := AllPools(self._chain_id).get(pool_address)) is not None:
95+
# Check if the pool registry already has this pool
96+
if (
97+
known_pool_helper := pool_registry.get(
98+
pool_address=pool_address, chain_id=self._chain_id
99+
)
100+
) is not None:
97101
if TYPE_CHECKING:
98102
assert isinstance(known_pool_helper, AerodromeV3Pool)
99103
if known_pool_helper.factory == self._factory_address:

0 commit comments

Comments
 (0)