Skip to content

Commit

Permalink
Added filter by x largest pools
Browse files Browse the repository at this point in the history
  • Loading branch information
PoloX2021 committed Nov 15, 2024
1 parent 7060d6d commit db8459a
Showing 1 changed file with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,39 @@ reserves as (
row_number() over (partition by tx_hash, contract_address order by evt_index desc) as row_num,
row_number() over (partition by contract_address order by block_time desc) as latest
from transfers
)
),

-- finds the TVL of the pools
select
r.contract_address,
token0,
token1,
block_time,
tx_hash,
reserve0,
reserve1,
fee,
latest,
(reserve0 * p0.price / pow(10, p0.decimals)) + (reserve1 * p1.price / pow(10, p1.decimals)) as tvl
from reserves as r
inner join prices.usd as p0
on
date_trunc('minute', block_time) = p0.minute
and token0 = p0.contract_address
inner join prices.usd as p1
on
date_trunc('minute', block_time) = p1.minute
and token1 = p1.contract_address
where row_num = 1
recent_tvl as (
select
r.contract_address,
token0,
token1,
block_time,
tx_hash,
reserve0,
reserve1,
fee,
latest,
(reserve0 * p0.price / pow(10, p0.decimals)) + (reserve1 * p1.price / pow(10, p1.decimals)) as tvl
from reserves as r
inner join prices.usd as p0
on
date_trunc('minute', block_time) = p0.minute
and token0 = p0.contract_address
inner join prices.usd as p1
on
date_trunc('minute', block_time) = p1.minute
and token1 = p1.contract_address
where row_num = 1
)


select * from recent_tvl
where contract_address in (
select contract_address
from recent_tvl
where latest = 1
order by tvl desc
limit {{number_of_pools}}
)

0 comments on commit db8459a

Please sign in to comment.