sebateau22-AHIL_deposit_range_BTC_6to12
Updated 2024-10-23
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
›
⌄
-- forked from IL_deposit_range_BTC_3to6 @ https://flipsidecrypto.xyz/studio/queries/53b90441-38d1-4676-86c5-329080c99425
-- forked from IL_deposit_range_BTC_v2 @ https://flipsidecrypto.xyz/studio/queries/7a373565-add9-4f19-86b1-07332d251477
WITH weekly_prices AS (
-- Step 1: Collect the weekly average prices of BTC and RUNE and compute r_final (Price of BTC / Price of RUNE)
SELECT
DATE_TRUNC('week', DAY) AS week,
AVG(RUNE_PRICE_USD) AS avg_rune_price,
AVG(ASSET_PRICE_USD) AS avg_btc_price,
-- Compute r_final: Price of BTC / Price of RUNE
(AVG(ASSET_PRICE_USD) / AVG(RUNE_PRICE_USD)) AS r_final
FROM thorchain.defi.fact_daily_pool_stats
WHERE POOL_NAME = 'BTC.BTC'
AND DAY >= '2022-01-01'
GROUP BY week
),
liquidity_additions AS (
-- Step 2: Collect all add_liquidity events between January 2024 and today, and compute r_initial for each event
SELECT
tx_id,
from_address,
pool_name,
asset_amount,
rune_amount,
asset_amount_usd,
rune_amount_usd,
block_timestamp,
-- Week of the event
DATE_TRUNC('week', block_timestamp) AS event_week,
-- Initial price of BTC and RUNE at the time of liquidity addition
(asset_amount_usd / asset_amount) AS initial_btc_price,
(rune_amount_usd / rune_amount) AS initial_rune_price,
-- Compute r_initial: Initial Price of BTC / Initial Price of RUNE
((asset_amount_usd / asset_amount) / (rune_amount_usd / rune_amount)) AS r_initial
FROM thorchain.defi.fact_liquidity_actions
QueryRunArchived: QueryRun has been archived