angealTotal DAI Discount
Updated 2023-03-13
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 28074afe-52a2-4a33-b191-0d905fc174f4
-- assuming people bought USDC at a discount right before payment,
-- how much $ did they save?
WITH
prices AS (
SELECT
recorded_hour,
'DAI' AS token_symbol,
avg(close) AS price
FROM
crosschain.core.fact_hourly_prices
WHERE
recorded_hour > current_date - 3
AND id IN ('dai', '4943')
GROUP BY
recorded_hour,
token_symbol
),
hourly_repayments AS (
SELECT
'aave' AS protocol,
symbol AS token_symbol,
date_trunc('hour', block_timestamp) AS hour,
sum(repayed_tokens) AS tokens_repaid,
count(tx_hash) AS n_repayments
FROM
ethereum.aave.ez_repayments
WHERE
block_timestamp > current_date - 3
AND symbol IN ('USDC', 'DAI')
GROUP BY
protocol,
token_symbol,
hour
UNION
Run a query to Download Data