theericstonenet borrowing usd
Updated 2022-07-07
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
›
⌄
with borrowing as (select
date_trunc('day',block_timestamp) as block_date,
sum(amount_usd) as borrowing_usd
from anchor.borrows b
group by 1),
repayment as (select
date_trunc('day',block_timestamp) as block_date,
sum(amount_usd) as repayment_usd
from anchor.repay b
group by 1),
luna_price as (select
date_trunc('day',block_timestamp) as block_date,
symbol,
avg(price_usd) as price_usd
from terra.oracle_prices
where symbol = 'LUNA'
group by 1, 2
),
luna_price_change as (select
one.block_date,
two.block_date as previous_block_date,
((one.price_usd - two.price_usd) / (two.price_usd)) * 100 as percentage_change
from luna_price one
inner join luna_price two
on one.block_date = dateadd(day, 1, two.block_date)
)
select b.block_date,
sum(borrowing_usd) over (order by b.block_date) as borrowing_usd,
sum(repayment_usd) over (order by b.block_date) as repayment_usd,
sum(borrowing_usd-repayment_usd)over (order by b.block_date) as net_borrowing_usd
from borrowing b
inner join repayment r
on b.block_date = r.block_date
where b.block_date > current_date - 180
Run a query to Download Data