Skip to content

Commit

Permalink
Merge pull request #17 from aerodrome-finance/max-pools-refactor
Browse files Browse the repository at this point in the history
MAX_POOLS refactor
  • Loading branch information
ethzoomer authored Sep 11, 2024
2 parents 643ab02 + 9615bdd commit fe06759
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
24 changes: 13 additions & 11 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

MAX_FACTORIES: public(constant(uint256)) = 10
MAX_POOLS: public(constant(uint256)) = 2000
MAX_ITERATIONS: public(constant(uint256)) = 8000
MAX_TOKENS: public(constant(uint256)) = 2000
MAX_LPS: public(constant(uint256)) = 500
MAX_EPOCHS: public(constant(uint256)) = 200
Expand Down Expand Up @@ -265,8 +266,8 @@ def _pools(_limit: uint256, _offset: uint256)\
factories: DynArray[address, MAX_FACTORIES] = self.registry.poolFactories()
factories_count: uint256 = len(factories)

placeholder: address[4] = empty(address[4])
to_skip: uint256 = _offset
visited: uint256 = 0

pools: DynArray[address[4], MAX_POOLS] = \
empty(DynArray[address[4], MAX_POOLS])
Expand All @@ -279,18 +280,19 @@ def _pools(_limit: uint256, _offset: uint256)\
pools_count: uint256 = factory.allPoolsLength()
nfpm: address = self._fetch_nfpm(factory.address)

for pindex in range(0, MAX_POOLS):
if pindex >= pools_count or len(pools) >= _limit + _offset:
for pindex in range(0, MAX_ITERATIONS):
if pindex >= pools_count or visited >= _limit + _offset or len(pools) >= MAX_POOLS:
break

# Since the convertor pool, first pool on one of the factories...
if pindex == 0 and factory.allPools(0) == self.convertor:
continue

visited += 1

# Basically skip calls for offset records...
if to_skip > 0:
to_skip -= 1
pools.append(placeholder)
continue

pool_addr: address = factory.allPools(pindex)
Expand Down Expand Up @@ -324,8 +326,8 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
nfpm: address = self._fetch_nfpm(factory.address)
pools_count: uint256 = factory.allPoolsLength()

for pindex in range(0, MAX_POOLS):
if pindex >= pools_count:
for pindex in range(0, MAX_ITERATIONS):
if pindex >= pools_count or len(pools) >= MAX_POOLS:
break

# If no pools to process are left...
Expand Down Expand Up @@ -394,7 +396,7 @@ def tokens(_limit: uint256, _offset: uint256, _account: address, \
col.append(self._token(_addresses[index], _account))
seen.append(_addresses[index])

for index in range(_offset, _offset + MAX_TOKENS):
for index in range(0, MAX_POOLS):
if len(col) >= _limit or index >= pools_count:
break

Expand Down Expand Up @@ -444,7 +446,7 @@ def all(_limit: uint256, _offset: uint256) -> DynArray[Lp, MAX_LPS]:
pools: DynArray[address[4], MAX_POOLS] = self._pools(_limit, _offset)
pools_count: uint256 = len(pools)

for index in range(_offset, _offset + MAX_POOLS):
for index in range(0, MAX_POOLS):
if len(col) == _limit or index >= pools_count:
break

Expand All @@ -471,7 +473,7 @@ def byIndex(_index: uint256) -> Lp:
"""
# Basically index is the limit and the offset is always one...
# This will fire if _index is out of bounds
pool_data: address[4] = self._pools(1, _index)[_index]
pool_data: address[4] = self._pools(1, _index)[0]
pool: IPool = IPool(pool_data[1])
token0: address = pool.token0()
token1: address = pool.token1()
Expand Down Expand Up @@ -954,7 +956,7 @@ def epochsLatest(_limit: uint256, _offset: uint256) \

col: DynArray[LpEpoch, MAX_POOLS] = empty(DynArray[LpEpoch, MAX_POOLS])

for index in range(_offset, _offset + MAX_POOLS):
for index in range(0, MAX_POOLS):
if counted == _limit or index >= pools_count:
break

Expand Down Expand Up @@ -1117,7 +1119,7 @@ def rewards(_limit: uint256, _offset: uint256, _venft_id: uint256) \

col: DynArray[Reward, MAX_POOLS] = empty(DynArray[Reward, MAX_POOLS])

for pindex in range(_offset, _offset + MAX_POOLS):
for pindex in range(0, MAX_POOLS):
if counted == _limit or pindex >= pools_count:
break

Expand Down
2 changes: 1 addition & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CONVERTOR_ADDRESS=0x1111111111111111111111111111111111111111
RELAY_REGISTRY_ADDRESSES=0x05e41604B9463e2224227053980dfF3f57fb6dB5,0xD308aBCe663302d3b86b36d332CEFd8A4F62C5Ed
SLIPSTREAM_HELPER_ADDRESS=0x6d2D739bf37dFd93D804523c2dfA948EAf32f8E1
GOVERNOR_ADDRESS=0x94C012A23A8A65A6f40608dA30534a46a433F410
LP_SUGAR_ADDRESS=0x68c19e13618C41158fE4bAba1B8fb3A9c74bDb0A
LP_SUGAR_ADDRESS=0xcDF4AA33Bafba3e5dc5B3ae54ab67324Ef956ABD
VE_SUGAR_ADDRESS=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5
RELAY_SUGAR_ADDRESS=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Below is the list of datasets we support.

### Liquidity Pools Data

`LpSugar.vy` is deployed at `0x68c19e13618C41158fE4bAba1B8fb3A9c74bDb0A`
`LpSugar.vy` is deployed at `0xcDF4AA33Bafba3e5dc5B3ae54ab67324Ef956ABD`

It allows fetching on-chain pools data.
The returned data/struct of type `Lp` values represent:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_lp_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ def test_tokens(sugar_contract, TokenStruct, LpStruct):
assert token1.token_address == first_lp.token1


def test_tokens_large_limit(sugar_contract, TokenStruct):
many_tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(2000, 1000, ADDRESS_ZERO, [])
))

assert many_tokens is not None
assert len(many_tokens) > 100

token0 = many_tokens[0]

assert token0.symbol is not None
assert token0.decimals > 0


def test_all(sugar_contract, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
Expand Down

0 comments on commit fe06759

Please sign in to comment.