princefarzam7-Day Moving Average of Staking APY by Reward Type
Updated 2022-01-19
999
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
›
⌄
WITH STAKED_LUNA AS ( -- find total amount of staked luna
SELECT
date,
sum(balance) as luna_stake_balance
FROM terra.daily_balances
WHERE DATEDIFF(day, date, GETDATE()) between 0 and 90 -- PAST 90 DAYS
AND BALANCE > 0 AND balance_type = 'staked' AND currency = 'LUNA'
AND address != 'terra1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3nln0mh'
GROUP BY date
ORDER BY 1
),
REWARDS AS ( -- rewards, including other stable currencies
SELECT -- rewards
date(block_timestamp) as date_reward,
event_attributes:"amount"[0]:denom::string as denom_reward,
sum(event_attributes:"amount"[0]:amount)/pow(10,6) as amount_reward
FROM terra.transitions
WHERE DATEDIFF(day, block_timestamp, GETDATE()) between 0 and 90 -- PAST 90 DAYS
AND event = 'rewards'
GROUP BY 1,2
),
COMMISSION AS ( -- comissions, extracted from validators
SELECT
date(block_timestamp) as date_commission,
event_attributes:"amount"[0]:denom as denom_comm,
sum(event_attributes:"amount"[0]:amount)/pow(10,6) as amount_comm
FROM terra.transitions
WHERE DATEDIFF(day, block_timestamp, GETDATE()) between 0 and 90 -- PAST 90 DAYS
AND event = 'commission'
GROUP BY 1,2
),
LUNA_RATE AS ( -- LUNA rates of rewards
Select
date(block_timestamp) as date,
currency,
symbol,
Run a query to Download Data