mlhUntitled Query
Updated 2022-09-19Copy Reference Fork
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
›
⌄
with arbi_raw as (--credit to akbaridria
select block_timestamp::date as date,
case when token_in = '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8' then amount_in/amount_out else amount_out/amount_in end as price,
row_number() over (partition by block_timestamp::date order by block_timestamp) as nomor_asc,
row_number() over (partition by block_timestamp::date order by block_timestamp desc) as nomor_dsc
from arbitrum.sushi.ez_swaps
where contract_address = '0x905dfcd5649217c42684f23958568e533c711aa3'
and amount_in_usd is not null
and amount_out_usd is not null
),
max_min_arbi as (select date,
max(price) as max_price,
min(price) as min_price
from arbi_raw
group by 1
),
first_arbi as (select *
from arbi_raw where nomor_asc = 1
),
last_arbi as (select * from arbi_raw where nomor_dsc = 1
),
fix_arbi as (select a.date,
'sushi' as label,
(max_price + min_price + b.price + c.price)/4 as price
from max_min_arbi a join first_arbi b on a.date = b.date
join last_arbi c on a.date = c.date
),
impermanent_arbi as (select
a.date,
(2*(sqrt((a.price/b.price))/(a.price/b.price + 1)) - 1)*100 as Impermanent_Loss_arbi
from fix_arbi a join fix_arbi b on a.label = b.label and b.date = (select min(date) from fix_arbi)
),
ethereum_raw as (
select block_timestamp::date as date,
Run a query to Download Data