-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mtitus6/main
Added price queries, added trades_peg_ratio, flipped price_peg_ratio over to price
- Loading branch information
Showing
18 changed files
with
772 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Dune query number - 3661946 */ | ||
with weth as ( | ||
select | ||
date_trunc('hour', minute) as hr, | ||
avg(price) as price | ||
from | ||
prices.usd | ||
where | ||
contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 | ||
and minute >= cast(current_timestamp - interval '1' year as timestamp) | ||
group by | ||
date_trunc('hour', minute) | ||
) | ||
, | ||
token as ( | ||
select | ||
date_trunc('hour', minute) as hr, | ||
contract_address, | ||
avg(price) as price | ||
from | ||
prices.usd | ||
where | ||
contract_address = 0xbe9895146f7af43049ca1c1ae358b0541ea49704 | ||
and minute >= cast(current_timestamp - interval '1' year as timestamp) | ||
group by | ||
date_trunc('hour', minute), | ||
contract_address | ||
) | ||
|
||
select | ||
token.hr, | ||
token.contract_address as token_contract_address, | ||
'cbETH' as token_name, | ||
token.price as price_usd, | ||
token.price / weth.price as price_eth | ||
from | ||
token | ||
inner join weth on | ||
token.hr = weth.hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* Dune query number - 3465286 */ | ||
with hours as ( | ||
select | ||
timestamp as hr, | ||
date_trunc('day', timestamp) as d | ||
from | ||
unnest( | ||
sequence( | ||
date_trunc('hour', cast(current_timestamp as timestamp) - interval '1' year), | ||
cast(current_timestamp as timestamp), | ||
interval '60' minute | ||
) | ||
) as tbl (timestamp) | ||
), | ||
|
||
peg as ( | ||
select | ||
hours.hr, | ||
peg.token_peg_eth | ||
from hours | ||
left join | ||
(select | ||
date_trunc('hour', t) as hr, | ||
token_peg_eth, | ||
lead(date_trunc('hour', t)) over (order by date_trunc('hour', t)) as next_hr | ||
from query_3465256) as peg on | ||
hours.hr >= peg.hr | ||
and hours.hr < peg.next_hr | ||
), | ||
|
||
trades as ( | ||
select | ||
date_trunc('hour', trades.t) as hr, | ||
sum(trades.token_trade_amount_eth) as token_trade_amount_eth, | ||
sum(trades.token_trade_amount) as token_trade_amount, | ||
sum(trades.token_trade_amount_eth) / sum(trades.token_trade_amount) as token_price_eth | ||
from query_3465242 as trades | ||
where trades.t > cast(current_timestamp as timestamp) - interval '1' year | ||
group by 1 | ||
), | ||
|
||
prices as ( | ||
select | ||
hours.hr, | ||
prices.token_price_eth, | ||
prices.token_trade_amount_eth, | ||
prices.token_trade_amount | ||
from hours | ||
left join | ||
(select | ||
hr, | ||
token_price_eth, | ||
token_trade_amount_eth, | ||
token_trade_amount, | ||
lead(hr) over (order by hr) as next_hr | ||
from trades) as prices on | ||
hours.hr >= prices.hr | ||
and hours.hr < prices.next_hr | ||
) | ||
|
||
select | ||
hours.hr, | ||
'cbETH' as token_name, | ||
prices.token_price_eth, | ||
avg(prices.token_price_eth) | ||
over (order by hours.hr rows between 5 preceding and current row) | ||
as token_price_eth_6hr_ma, | ||
prices.token_trade_amount_eth, | ||
prices.token_trade_amount, | ||
peg.token_peg_eth, | ||
prices.token_price_eth / peg.token_peg_eth as token_price_peg_ratio, | ||
avg(prices.token_price_eth) over (order by hours.hr rows between 5 preceding and current row) | ||
/ peg.token_peg_eth as token_price_peg_ratio_6hr_ma, | ||
(prices.token_price_eth / peg.token_peg_eth) - 1 as token_peg_pct_divergence, | ||
avg(prices.token_price_eth) over (order by hours.hr rows between 5 preceding and current row) / peg.token_peg_eth | ||
- 1 as token_peg_pct_divergence_6hr_ma | ||
from hours | ||
left join peg on hours.hr = peg.hr | ||
left join prices on hours.hr = prices.hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Dune query number - 3621788 */ | ||
select | ||
cast(evt_block_number as bigint) as block, | ||
evt_block_time as t, | ||
date_trunc('day', evt_block_time) as d, | ||
posttotalether / cast(posttotalshares as double) as token_peg_eth, | ||
0xae7ab96520de3a18e5e111b5eaab095312d7fe84 as token_contract_address, | ||
'stETH' as token_name | ||
from | ||
lido_ethereum.steth_evt_tokenrebased | ||
union all | ||
select | ||
cast(evt_block_number as bigint) as block, | ||
evt_block_time as t, | ||
date_trunc('day', evt_block_time) as d, | ||
posttotalpooledether / cast(totalshares as double) as token_peg_eth, | ||
0xae7ab96520de3a18e5e111b5eaab095312d7fe84 as token_contract_address, | ||
'stETH' as token_name | ||
from | ||
lido_ethereum.legacyoracle_evt_posttotalshares | ||
where | ||
evt_block_time >= cast('2022-09-01 00:00' as timestamp) | ||
and evt_block_time <= cast('2023-05-16 00:00' as timestamp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* Dune query number - 3664583 */ | ||
with weth as ( | ||
select | ||
date_trunc('hour', minute) as hr, | ||
avg(price) as price | ||
from | ||
prices.usd | ||
where | ||
contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 | ||
and minute >= cast(current_timestamp - interval '1' year as timestamp) | ||
group by | ||
date_trunc('hour', minute) | ||
) | ||
, | ||
token as ( | ||
select | ||
date_trunc('hour', minute) as hr, | ||
contract_address, | ||
avg(price) as price | ||
from | ||
prices.usd | ||
where | ||
contract_address = 0xae7ab96520de3a18e5e111b5eaab095312d7fe84 | ||
and minute >= cast(current_timestamp - interval '1' year as timestamp) | ||
group by | ||
date_trunc('hour', minute), | ||
contract_address | ||
) | ||
|
||
select | ||
token.hr, | ||
token.contract_address as token_contract_address, | ||
'stETH' as token_name, | ||
token.price as token_price_usd, | ||
weth.price as weth_price_usd, | ||
token.price / weth.price as token_price_eth | ||
from | ||
token | ||
inner join weth on | ||
token.hr = weth.hr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Dune query number - 3480205 */ | ||
with hours as ( | ||
select | ||
timestamp as hr, | ||
date_trunc('day', timestamp) as d | ||
from | ||
unnest( | ||
sequence( | ||
date_trunc('hour', cast(current_timestamp as timestamp) - interval '1' year), | ||
cast(current_timestamp as timestamp), | ||
interval '60' minute | ||
) | ||
) as tbl (timestamp) | ||
), | ||
|
||
peg as ( | ||
select | ||
hours.hr, | ||
peg.token_peg_eth | ||
from hours | ||
cross join (select distinct token_peg_eth from query_3480196) as peg | ||
), | ||
|
||
trades as ( | ||
select | ||
date_trunc('hour', trades.t) as hr, | ||
sum(trades.token_trade_amount_eth) as token_trade_amount_eth, | ||
sum(trades.token_trade_amount) as token_trade_amount, | ||
sum(trades.token_trade_amount_eth) / sum(trades.token_trade_amount) as token_price_eth | ||
from query_3480173 as trades | ||
where trades.t > cast(current_timestamp as timestamp) - interval '1' year | ||
group by 1 | ||
), | ||
|
||
prices as ( | ||
select | ||
hours.hr, | ||
prices.token_price_eth, | ||
prices.token_trade_amount_eth, | ||
prices.token_trade_amount | ||
from hours | ||
left join | ||
(select | ||
hr, | ||
token_price_eth, | ||
token_trade_amount_eth, | ||
token_trade_amount, | ||
lead(hr) over (order by hr) as next_hr | ||
from trades) as prices on | ||
hours.hr >= prices.hr | ||
and hours.hr < prices.next_hr | ||
) | ||
|
||
select | ||
hours.hr, | ||
'stETH' as token_name, | ||
prices.token_price_eth, | ||
avg(prices.token_price_eth) | ||
over (order by hours.hr rows between 5 preceding and current row) | ||
as token_price_eth_6hr_ma, | ||
prices.token_trade_amount_eth, | ||
prices.token_trade_amount, | ||
peg.token_peg_eth, | ||
prices.token_price_eth / peg.token_peg_eth as token_price_peg_ratio, | ||
avg(prices.token_price_eth) over (order by hours.hr rows between 5 preceding and current row) | ||
/ peg.token_peg_eth as token_price_peg_ratio_6hr_ma, | ||
(prices.token_price_eth / peg.token_peg_eth) - 1 as token_peg_pct_divergence, | ||
avg(prices.token_price_eth) over (order by hours.hr rows between 5 preceding and current row) / peg.token_peg_eth | ||
- 1 as token_peg_pct_divergence_6hr_ma | ||
from hours | ||
left join peg on hours.hr = peg.hr | ||
left join prices on hours.hr = prices.hr |
Oops, something went wrong.