-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e1b9996
Showing
4,074 changed files
with
65,951 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...nthetix/models/marts/arbitrum/mainnet/core/fct_core_account_activity_arbitrum_mainnet.sql
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 @@ | ||
|
||
|
||
with delegated as ( | ||
select distinct | ||
block_timestamp, | ||
account_id, | ||
'Delegated' as account_action | ||
from "analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet" | ||
), | ||
|
||
withdrawn as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Withdrawn' as account_action | ||
from "analytics"."prod_raw_arbitrum_mainnet"."core_withdrawn_arbitrum_mainnet" | ||
), | ||
|
||
claimed as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Claimed' as account_action | ||
from "analytics"."prod_raw_arbitrum_mainnet"."core_rewards_claimed_arbitrum_mainnet" | ||
), | ||
|
||
combined as ( | ||
select * from delegated | ||
union all | ||
select * from withdrawn | ||
union all | ||
select * from claimed | ||
) | ||
|
||
select | ||
block_timestamp, | ||
account_action, | ||
account_id | ||
from combined |
64 changes: 64 additions & 0 deletions
64
...hetix/models/marts/arbitrum/mainnet/core/fct_core_account_delegation_arbitrum_mainnet.sql
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,64 @@ | ||
with delegation_changes as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
pool_id, | ||
collateral_type, | ||
|
||
amount / 1e18 | ||
|
||
- LAG( | ||
amount / 1e18 | ||
, 1, 0) over ( | ||
partition by | ||
account_id, | ||
pool_id, | ||
collateral_type | ||
order by | ||
block_timestamp | ||
) as change_in_amount | ||
from | ||
"analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet" | ||
), | ||
|
||
cumulative_delegation as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
pool_id, | ||
collateral_type, | ||
SUM(change_in_amount) over ( | ||
partition by | ||
pool_id, | ||
account_id, | ||
collateral_type | ||
order by | ||
block_timestamp | ||
) as cumulative_amount_delegated, | ||
ROW_NUMBER() over ( | ||
partition by | ||
pool_id, | ||
account_id, | ||
collateral_type | ||
order by | ||
block_timestamp desc | ||
) as rn | ||
from | ||
delegation_changes | ||
) | ||
|
||
select | ||
block_timestamp as ts, | ||
pool_id, | ||
collateral_type, | ||
cumulative_amount_delegated as amount_delegated, | ||
CAST( | ||
account_id as text | ||
) as account_id | ||
from | ||
cumulative_delegation | ||
where | ||
rn = 1 | ||
order by | ||
block_timestamp, | ||
collateral_type |
49 changes: 49 additions & 0 deletions
49
...tix/models/marts/arbitrum/mainnet/core/fct_core_active_stakers_daily_arbitrum_mainnet.sql
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,49 @@ | ||
|
||
|
||
with delegation_updated as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
amount | ||
from "analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet" | ||
), | ||
|
||
dim as ( | ||
select | ||
d.block_date, | ||
accounts_unique.account_id | ||
from ( | ||
select | ||
generate_series( | ||
date_trunc('day', date('2023-12-15')), | ||
date_trunc('day', current_date), '1 day'::interval | ||
) as block_date | ||
) as d | ||
cross join ( | ||
select distinct account_id from delegation_updated | ||
) as accounts_unique | ||
), | ||
|
||
stakers as ( | ||
select | ||
dim.block_date, | ||
dim.account_id, | ||
case | ||
when coalesce(last(delegation_updated.amount) over ( | ||
partition by dim.account_id | ||
order by dim.block_date | ||
rows between unbounded preceding and current row | ||
), 0) = 0 then 0 | ||
else 1 | ||
end as is_staking | ||
from dim | ||
left join delegation_updated on | ||
dim.block_date = date(delegation_updated.block_timestamp) | ||
and dim.account_id = delegation_updated.account_id | ||
) | ||
|
||
select | ||
block_date, | ||
sum(is_staking) as nof_stakers_daily | ||
from stakers | ||
group by block_date |
234 changes: 234 additions & 0 deletions
234
compiled/synthetix/models/marts/arbitrum/mainnet/core/fct_core_apr_arbitrum_mainnet.sql
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,234 @@ | ||
|
||
|
||
with pnl_hourly as ( | ||
select | ||
ts, | ||
pool_id, | ||
collateral_type, | ||
collateral_value, | ||
debt, | ||
hourly_pnl, | ||
hourly_issuance, | ||
rewards_usd, | ||
hourly_pnl_pct, | ||
hourly_rewards_pct, | ||
hourly_total_pct, | ||
SUM( | ||
COALESCE( | ||
hourly_issuance, | ||
0 | ||
) | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
) as cumulative_issuance, | ||
SUM( | ||
hourly_pnl | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
) as cumulative_pnl | ||
from | ||
"analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet" | ||
), | ||
|
||
avg_returns as ( | ||
select | ||
ts, | ||
pool_id, | ||
collateral_type, | ||
AVG( | ||
hourly_pnl_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '24 HOURS' preceding | ||
and current row | ||
) as avg_24h_pnl_pct, | ||
AVG( | ||
hourly_pnl_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '7 DAYS' preceding | ||
and current row | ||
) as avg_7d_pnl_pct, | ||
AVG( | ||
hourly_pnl_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '28 DAYS' preceding | ||
and current row | ||
) as avg_28d_pnl_pct, | ||
AVG( | ||
hourly_rewards_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '24 HOURS' preceding | ||
and current row | ||
) as avg_24h_rewards_pct, | ||
AVG( | ||
hourly_rewards_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '7 DAYS' preceding | ||
and current row | ||
) as avg_7d_rewards_pct, | ||
AVG( | ||
hourly_rewards_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '28 DAYS' preceding | ||
and current row | ||
) as avg_28d_rewards_pct, | ||
AVG( | ||
hourly_total_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '24 HOURS' preceding | ||
and current row | ||
) as avg_24h_total_pct, | ||
AVG( | ||
hourly_total_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '7 DAYS' preceding | ||
and current row | ||
) as avg_7d_total_pct, | ||
AVG( | ||
hourly_total_pct | ||
) over ( | ||
partition by | ||
pool_id, | ||
collateral_type | ||
order by | ||
ts | ||
range between interval '28 DAYS' preceding | ||
and current row | ||
) as avg_28d_total_pct | ||
from | ||
pnl_hourly | ||
), | ||
|
||
apr_calculations as ( | ||
select | ||
pnl_hourly.ts, | ||
pnl_hourly.pool_id, | ||
pnl_hourly.collateral_type, | ||
pnl_hourly.collateral_value, | ||
pnl_hourly.debt, | ||
pnl_hourly.hourly_pnl, | ||
pnl_hourly.cumulative_pnl, | ||
pnl_hourly.hourly_issuance, | ||
pnl_hourly.cumulative_issuance, | ||
pnl_hourly.rewards_usd, | ||
pnl_hourly.hourly_pnl_pct, | ||
pnl_hourly.hourly_rewards_pct, | ||
-- total pnls | ||
avg_returns.avg_24h_total_pct * 24 * 365 as apr_24h, | ||
avg_returns.avg_7d_total_pct * 24 * 365 as apr_7d, | ||
avg_returns.avg_28d_total_pct * 24 * 365 as apr_28d, | ||
-- pool pnls | ||
avg_returns.avg_24h_pnl_pct * 24 * 365 as apr_24h_pnl, | ||
avg_returns.avg_7d_pnl_pct * 24 * 365 as apr_7d_pnl, | ||
avg_returns.avg_28d_pnl_pct * 24 * 365 as apr_28d_pnl, | ||
-- rewards pnls | ||
avg_returns.avg_24h_rewards_pct * 24 * 365 as apr_24h_rewards, | ||
avg_returns.avg_7d_rewards_pct * 24 * 365 as apr_7d_rewards, | ||
avg_returns.avg_28d_rewards_pct * 24 * 365 as apr_28d_rewards | ||
from | ||
pnl_hourly | ||
inner join avg_returns | ||
on | ||
pnl_hourly.ts = avg_returns.ts | ||
and pnl_hourly.pool_id = avg_returns.pool_id | ||
and pnl_hourly.collateral_type = avg_returns.collateral_type | ||
), | ||
|
||
apy_calculations as ( | ||
select | ||
*, | ||
(POWER(1 + apr_24h / 8760, 8760) - 1) as apy_24h, | ||
(POWER(1 + apr_7d / 8760, 8760) - 1) as apy_7d, | ||
(POWER(1 + apr_28d / 8760, 8760) - 1) as apy_28d, | ||
(POWER(1 + apr_24h_pnl / 8760, 8760) - 1) as apy_24h_pnl, | ||
(POWER(1 + apr_7d_pnl / 8760, 8760) - 1) as apy_7d_pnl, | ||
(POWER(1 + apr_28d_pnl / 8760, 8760) - 1) as apy_28d_pnl, | ||
(POWER(1 + apr_24h_rewards / 8760, 8760) - 1) as apy_24h_rewards, | ||
(POWER(1 + apr_7d_rewards / 8760, 8760) - 1) as apy_7d_rewards, | ||
(POWER(1 + apr_28d_rewards / 8760, 8760) - 1) as apy_28d_rewards | ||
from | ||
apr_calculations | ||
) | ||
|
||
select | ||
ts, | ||
pool_id, | ||
collateral_type, | ||
collateral_value, | ||
debt, | ||
hourly_issuance, | ||
hourly_pnl, | ||
cumulative_pnl, | ||
cumulative_issuance, | ||
rewards_usd, | ||
hourly_pnl_pct, | ||
hourly_rewards_pct, | ||
apr_24h, | ||
apy_24h, | ||
apr_7d, | ||
apy_7d, | ||
apr_28d, | ||
apy_28d, | ||
apr_24h_pnl, | ||
apy_24h_pnl, | ||
apr_7d_pnl, | ||
apy_7d_pnl, | ||
apr_28d_pnl, | ||
apy_28d_pnl, | ||
apr_24h_rewards, | ||
apy_24h_rewards, | ||
apr_7d_rewards, | ||
apy_7d_rewards, | ||
apr_28d_rewards, | ||
apy_28d_rewards | ||
from | ||
apy_calculations | ||
order by | ||
ts |
Oops, something went wrong.