Skip to content

Commit

Permalink
fix: MAX_POOLS length check
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer committed Sep 10, 2024
1 parent c0c30d3 commit 9615bdd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _pools(_limit: uint256, _offset: uint256)\
nfpm: address = self._fetch_nfpm(factory.address)

for pindex in range(0, MAX_ITERATIONS):
if pindex >= pools_count or visited >= _limit + _offset:
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...
Expand Down Expand Up @@ -327,7 +327,7 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
pools_count: uint256 = factory.allPoolsLength()

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

# If no pools to process are left...
Expand Down Expand Up @@ -396,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(0, MAX_TOKENS):
for index in range(0, MAX_POOLS):
if len(col) >= _limit or index >= 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=0x08483151e59375a03E82C180BBc4c79E5CB8C60D
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 `0x08483151e59375a03E82C180BBc4c79E5CB8C60D`
`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 9615bdd

Please sign in to comment.