From cb41f52b41ab374e49681a24f485fb0b57461153 Mon Sep 17 00:00:00 2001 From: "pauljanicot@yahoo.com" Date: Mon, 18 Nov 2024 11:47:37 +0000 Subject: [PATCH] Added/propagated through queries number_of_pools parameter and various comments --- .../curve/curve_kpis_4232873.sql | 6 ++++-- .../curve_largest_2token_pools_4232976.sql | 4 +++- .../pancakeswap/pancakeswap_kpis_4232738.sql | 20 ++++++++++--------- .../pancakeswap_largest_pools_4232597.sql | 9 ++++++--- .../pancakeswap/pancakeswap_syncs_4232660.sql | 8 ++++++-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/cowamm/profitability/competitor_kpis/curve/curve_kpis_4232873.sql b/cowamm/profitability/competitor_kpis/curve/curve_kpis_4232873.sql index b903486e..d0a16a28 100644 --- a/cowamm/profitability/competitor_kpis/curve/curve_kpis_4232873.sql +++ b/cowamm/profitability/competitor_kpis/curve/curve_kpis_4232873.sql @@ -1,6 +1,7 @@ -- Computes volume, tvl and APR for Curve pools -- APR is measured as the fees earned per $ invested, over the last 24 hours, projected over 1 year --- Input: blockchain +-- Parameters: +-- {{blockchain}}: The blockchain to query select r.contract_address, sum(amount_usd) as volume, @@ -18,7 +19,8 @@ where and tvl > 0 group by r.contract_address --- NOw include pools which did not trade during the specified timeframe +-- Now include pools which did not trade during the specified timeframe +-- This allows to include a performance metric for every pool even the less active ones union distinct select contract_address, 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 90b3cdd1..7d60de6a 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 @@ -1,5 +1,7 @@ -- Finds all the curve pools with 2 tokens and their TVLs --- Input: blockchain +-- Parameters: +-- {{blockchain}}: The blockchain to query +-- {{number_of_pools}}: The number of largest pools to return with -- filters pools with 2 tokens diff --git a/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_kpis_4232738.sql b/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_kpis_4232738.sql index e88d6d47..66321ea4 100644 --- a/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_kpis_4232738.sql +++ b/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_kpis_4232738.sql @@ -1,10 +1,10 @@ -- Computes volume, tvl and APR for Pancakeswap pools -- APR is measured as the fees earned per $ invested, over the last 24 hours, projected over 1 year --- Input: blockchain +-- Parameters: +-- {{blockchain}}: The blockchain to query -with -- select the pool with the largest latest k -pool as ( +with pool as ( select contract_address, token0, @@ -62,18 +62,20 @@ select contract_address, sum((volume_in + volume_out) / 2) as volume, avg(tvl) as tvl, - 365*sum((volume_in + volume_out) / 2 / tvl) * 0.003 as apr, + 365 * sum((volume_in + volume_out) / 2 / tvl) * 0.003 as apr, 0.003 as fee from tvl_volume_per_swap - where evt_block_time >= date_add('day', -1, now()) +where evt_block_time >= date_add('day', -1, now()) group by contract_address +-- Now include pools which did not trade during the specified timeframe +-- This allows to include a performance metric for every pool even the less active ones union -select - pool_address as contract_address, - 0 as volume, +select + pool_address as contract_address, + 0 as volume, tvl, 0 as apr, 0.003 as fee -from "query_4232597(blockchain='{{blockchain}}')" +from "query_4232597(blockchain='{{blockchain}}', number_of_pools = '500')" where pool_address not in (select contract_address from tvl_volume_per_swap) diff --git a/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_largest_pools_4232597.sql b/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_largest_pools_4232597.sql index 1b2269c0..0e34fcd7 100644 --- a/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_largest_pools_4232597.sql +++ b/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_largest_pools_4232597.sql @@ -1,13 +1,15 @@ -- Computes the TVL for every Pancakeswap pool -- Then returns the top {{number_of_pools}} pools by TVL --- Input: blockchain, number_of_pools to return +-- Parameters: +-- {{blockchain}}: The blockchain to query +-- {{number_of_pools}}: The number of largest pools to return with -- finds the pools which have been active since 2024-10-01 data as ( select p.contract_address as pool_address, - p.call_block_time as time, + p.call_block_time as block_time, p.output__reserve0 as balance0, p.output__reserve1 as balance1, rank() over (partition by p.contract_address order by p.call_block_time desc) as latest @@ -35,6 +37,7 @@ t1 as ( --computes the tvl for each pool -- for each pool we could get multiple balance values if the function was called multiple times in a same block -- we arbitrarily choose the maximum value for each pool +-- This decision does not have much impact on metrics, as it is just to rank the pools. recent_tvl as ( select pool_address, @@ -56,7 +59,7 @@ recent_tvl as ( inner join prices.usd_latest as p1 on token1 = p1.contract_address where latest = 1 - group by 1, 2, 4 + group by pool_address, token0, token1 ) select * from recent_tvl diff --git a/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_syncs_4232660.sql b/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_syncs_4232660.sql index 89cf836b..cccb8f7d 100644 --- a/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_syncs_4232660.sql +++ b/cowamm/profitability/competitor_kpis/pancakeswap/pancakeswap_syncs_4232660.sql @@ -1,4 +1,8 @@ --- Finds the pancakeswap v2 pool address given tokens specified in query parameters (regardless of order) +-- This query finds all the sync event which happens after a swap and reference the new reserves of the pool +-- Parameters: +-- {{blockchain}}: The blockchain to query + +-- Finds the pools with the largest tvl with pools as ( select substr(data, 13, 20) as contract_address, @@ -8,7 +12,7 @@ with pools as ( where topic0 = 0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9 -- PairCreated -- topic1: 0x0...0, topic2: 0x0...0 - and substr(data, 13, 20) in (select pool_address from "query_4232597(blockchain='{{blockchain}}')") + and substr(data, 13, 20) in (select pool_address from "query_4232597(blockchain='{{blockchain}}', number_of_pools = '500')") ) select