Skip to content

Commit

Permalink
refactor: add custom token addresses to tokens()
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer committed Jan 16, 2024
1 parent b219d77 commit 448198a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
31 changes: 9 additions & 22 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:

@external
@view
def tokens(_limit: uint256, _offset: uint256, _account: address)\
def tokens(_limit: uint256, _offset: uint256, _account: address, _addresses: DynArray[address, MAX_TOKENS]) \
-> DynArray[Token, MAX_TOKENS]:
"""
@notice Returns a collection of tokens data based on available pools
Expand All @@ -351,9 +351,17 @@ def tokens(_limit: uint256, _offset: uint256, _account: address)\
"""
pools: DynArray[address[3], MAX_POOLS] = self._pools()
pools_count: uint256 = len(pools)
addresses_count: uint256 = len(_addresses)
col: DynArray[Token, MAX_TOKENS] = empty(DynArray[Token, MAX_TOKENS])
seen: DynArray[address, MAX_TOKENS] = empty(DynArray[address, MAX_TOKENS])

for index in range(0, MAX_TOKENS):
if len(col) >= _limit or index >= addresses_count:
break

col.append(self._token(_addresses[index], _account))
seen.append(_addresses[index])

for index in range(_offset, _offset + MAX_TOKENS):
if len(col) >= _limit or index >= pools_count:
break
Expand All @@ -374,27 +382,6 @@ def tokens(_limit: uint256, _offset: uint256, _account: address)\

return col

@external
@view
def tokensByAddress(_addresses: DynArray[address, MAX_TOKENS], _account: address)\
-> DynArray[Token, MAX_TOKENS]:
"""
@notice Returns a collection of tokens data based on given addresses
@param _addresses The tokens to return data of
@param _account The account to check the balances
@return Array for Token structs
"""
tokens_count: uint256 = len(_addresses)
col: DynArray[Token, MAX_TOKENS] = empty(DynArray[Token, MAX_TOKENS])

for index in range(0, MAX_TOKENS):
if index == MAX_TOKENS or index >= tokens_count:
break

col.append(self._token(_addresses[index], _account))

return col

@internal
@view
def _token(_address: address, _account: address) -> Token:
Expand Down
14 changes: 12 additions & 2 deletions 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 `0xc1300feCf066aC49a067F094747a5d150E878528`
`LpSugar.vy` is deployed at `0xE180829A166d1e0bec705C1eB25758F645C9E317`

It allows fetching on-chain pools data.
The returned data/struct of type `Lp` values represent:
Expand Down Expand Up @@ -67,7 +67,17 @@ The returned data/struct of type `Lp` values represent:
* `alm_vault` - ALM vault address on v3 if it exists, empty address on v2
* `alm_reserve0` - ALM vault token0 reserves on v3, 0 on v2
* `alm_reserve1` - ALM vault token1 reserves on v3, 0 on v2
* `positions` - a list of account pool position data, it is a struct of type `Position`
* `positions` - a list of account pool position data, it is a struct of type `Position` with the following values:
* `id` - NFT ID on v3 pools, 0 on v2 pools
* `manager` - NFT position manager on v3 pools, router on v2 pools
* `liquidity` - liquidity value on v3, total supply of LP tokens on v2
* `staked` - 0/1 for staked/unstaked state on v3, amount of staked tokens on v2
* `unstaked_earned0` - unstaked token0 fees earned
* `unstaked_earned1` - unstaked token1 fees earned
* `emissions_earned` - emissions earned from staked position
* `tick_lower` - lower tick of position on v3, 0 on v2
* `tick_upper` - upper tick of position on v3, 0 on v2
* `alm` - true if position is deposited into ALM on v3, false on v2

---

Expand Down

0 comments on commit 448198a

Please sign in to comment.