Skip to content

Commit

Permalink
forSwaps now supports pagination...
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Sep 12, 2023
1 parent 9ea531a commit e35b853
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,11 @@ def toMigrate(_account: address) -> DynArray[Lp, MAX_POOLS]:

@external
@view
def forSwaps() -> DynArray[SwapLp, MAX_POOLS]:
def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
"""
@notice Returns a compiled list of pools for swaps from all pool factories
@param _limit The max amount of tokens to return
@param _offset The amount of pools to skip
@return `SwapLp` structs
"""
factories_count: uint256 = self.registry.poolFactoriesLength()
Expand All @@ -317,8 +319,8 @@ def forSwaps() -> DynArray[SwapLp, MAX_POOLS]:
else:
pools_count = factory.allPoolsLength()

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

pool_addr: address = empty(address)
Expand All @@ -330,10 +332,7 @@ def forSwaps() -> DynArray[SwapLp, MAX_POOLS]:

pool: IPool = IPool(pool_addr)

reserve0: uint256 = pool.reserve0()
reserve1: uint256 = pool.reserve1()

if (reserve0 > 0 and reserve1 > 0) or pool_addr == self.convertor:
if pool.reserve0() > 0 or pool_addr == self.convertor:
pools.append(SwapLp({
lp: pool_addr,
stable: pool.stable(),
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 `0x7F45F1eA57E9231f846B2b4f5F8138F94295A726`
`LpSugar.vy` is deployed at `0x4D996E294B00cE8287C16A2b9A4e637ecA5c939f`

It allows fetching on-chain pools data.
The returned data/struct of type `Lp` values represent:
Expand Down

0 comments on commit e35b853

Please sign in to comment.