Multipartite2022-05-04 Kellen-origin Pool APY query derivative
Updated 2022-05-04
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
⌄
/*
Credit to Kellen:
https://thorchain.vision/console
https://discord.com/channels/838986635756044328/892129741790933092/971190095694684180
https://app.flipsidecrypto.com/velocity/queries/ec7b16e4-bad1-473c-9682-e9507cb08bf9
*/
WITH
base AS (
SELECT YEAR(day) AS year
, WEEKOFYEAR(day) AS week
, SPLIT(pool_name, '-')[0] AS pool_name
, MIN(day) AS day
, COUNT(DISTINCT day) AS n_days
, AVG((asset_liquidity * asset_price_usd) + (rune_liquidity * rune_price_usd)) AS liquidity_usd
, SUM(COALESCE(system_rewards_usd, 0)) AS system_rewards_usd
, SUM(COALESCE(total_swap_fees_usd, 0)) AS total_swap_fees_usd
FROM thorchain.daily_pool_stats
GROUP BY 1, 2, 3
ORDER BY 1 DESC, 2 DESC, 3
), w AS (
SELECT year
, week
, MIN(day) AS day
FROM base
GROUP BY 1, 2
),
intermediate AS
(
SELECT w.day
, pool_name
, total_swap_fees_usd
, system_rewards_usd
, n_days
Run a query to Download Data