Skip to content

Commit

Permalink
only fetch listed tokens for pools
Browse files Browse the repository at this point in the history
  • Loading branch information
callmephilip committed Nov 21, 2023
1 parent b3d4649 commit 1b6da45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bots/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def from_tuple(
@classmethod
@cache_in_seconds(SUGAR_LPS_CACHE_MINUTES * 60)
async def get_pools(cls) -> List["LiquidityPool"]:
tokens = await Token.get_all_tokens()
tokens = await Token.get_all_listed_tokens()
prices = await Price.get_prices(tokens)

tokens = {t.token_address: t for t in tokens}
Expand Down Expand Up @@ -278,6 +278,9 @@ def match_score(query: str, symbol: str):
return fuzz.token_sort_ratio(query, symbol)

pools = await cls.get_pools()
pools = list(
filter(lambda p: p.token0 is not None and p.token1 is not None, pools)
)
pools_with_ratio = list(map(lambda p: (p, match_score(query, p.symbol)), pools))
pools_with_ratio.sort(key=lambda p: p[1], reverse=True)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ async def test_liquidity_pool_stats():
for pool in pools:
tvl = await LiquidityPool.tvl([pool])
fields = [
pool.token0,
pool.token1,
# XX: these can be None for non listed tokens
# pool.token0,
# pool.token1,
pool.is_stable,
pool.pool_fee_percentage,
pool.apr(tvl),
Expand Down

0 comments on commit 1b6da45

Please sign in to comment.