From db8459ad09097fb7c647e4c30666f990d1be28c2 Mon Sep 17 00:00:00 2001 From: "pauljanicot@yahoo.com" Date: Fri, 15 Nov 2024 18:14:41 +0000 Subject: [PATCH] Added filter by x largest pools --- .../curve_largest_2token_pools_4232976.sql | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/cowamm/profitability/competitor_kpis/curve/curve_largest_2token_pools_4232976.sql b/cowamm/profitability/competitor_kpis/curve/curve_largest_2token_pools_4232976.sql index bd93b6be..90b3cdd1 100644 --- a/cowamm/profitability/competitor_kpis/curve/curve_largest_2token_pools_4232976.sql +++ b/cowamm/profitability/competitor_kpis/curve/curve_largest_2token_pools_4232976.sql @@ -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}} +)