-
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.
Merge pull request #131 from Synthetixio/feat/add-acc-activity-models
Transformers - Add Account Activity models & tests
- Loading branch information
Showing
15 changed files
with
620 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...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,42 @@ | ||
{{ config( | ||
materialized = "view", | ||
tags = ["core", "account_activity", "daily", "arbitrum", "mainnet"] | ||
) }} | ||
|
||
with delegated as ( | ||
select distinct | ||
block_timestamp, | ||
account_id, | ||
'Delegated' as account_action | ||
from {{ ref('core_delegation_updated_arbitrum_mainnet') }} | ||
), | ||
|
||
withdrawn as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Withdrawn' as account_action | ||
from {{ ref('core_withdrawn_arbitrum_mainnet') }} | ||
), | ||
|
||
claimed as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Claimed' as account_action | ||
from {{ ref('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 |
52 changes: 52 additions & 0 deletions
52
...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,52 @@ | ||
{{ config( | ||
materialized = "view", | ||
tags = ["core", "active_stakers", "daily", "arbitrum", "mainnet"] | ||
) }} | ||
|
||
with delegation_updated as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
amount | ||
from {{ ref('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 |
30 changes: 30 additions & 0 deletions
30
transformers/synthetix/models/marts/arbitrum/mainnet/core/schema.yml
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
42 changes: 42 additions & 0 deletions
42
...nthetix/models/marts/arbitrum/sepolia/core/fct_core_account_activity_arbitrum_sepolia.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,42 @@ | ||
{{ config( | ||
materialized = "view", | ||
tags = ["core", "account_activity", "daily", "arbitrum", "sepolia"] | ||
) }} | ||
|
||
with delegated as ( | ||
select distinct | ||
block_timestamp, | ||
account_id, | ||
'Delegated' as account_action | ||
from {{ ref('core_delegation_updated_arbitrum_sepolia') }} | ||
), | ||
|
||
withdrawn as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Withdrawn' as account_action | ||
from {{ ref('core_withdrawn_arbitrum_sepolia') }} | ||
), | ||
|
||
claimed as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Claimed' as account_action | ||
from {{ ref('core_rewards_claimed_arbitrum_sepolia') }} | ||
), | ||
|
||
combined as ( | ||
select * from delegated | ||
union all | ||
select * from withdrawn | ||
union all | ||
select * from claimed | ||
) | ||
|
||
select | ||
block_timestamp, | ||
account_action, | ||
account_id | ||
from combined |
52 changes: 52 additions & 0 deletions
52
...tix/models/marts/arbitrum/sepolia/core/fct_core_active_stakers_daily_arbitrum_sepolia.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,52 @@ | ||
{{ config( | ||
materialized = "view", | ||
tags = ["core", "active_stakers", "daily", "arbitrum", "sepolia"] | ||
) }} | ||
|
||
with delegation_updated as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
amount | ||
from {{ ref('core_delegation_updated_arbitrum_sepolia') }} | ||
), | ||
|
||
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 |
30 changes: 30 additions & 0 deletions
30
transformers/synthetix/models/marts/arbitrum/sepolia/core/schema.yml
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
42 changes: 42 additions & 0 deletions
42
...rmers/synthetix/models/marts/base/mainnet/core/fct_core_account_activity_base_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,42 @@ | ||
{{ config( | ||
materialized = "view", | ||
tags = ["core", "account_activity", "daily", "base", "mainnet"] | ||
) }} | ||
|
||
with delegated as ( | ||
select distinct | ||
block_timestamp, | ||
account_id, | ||
'Delegated' as account_action | ||
from {{ ref('core_delegation_updated_base_mainnet') }} | ||
), | ||
|
||
withdrawn as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Withdrawn' as account_action | ||
from {{ ref('core_withdrawn_base_mainnet') }} | ||
), | ||
|
||
claimed as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
'Claimed' as account_action | ||
from {{ ref('core_rewards_claimed_base_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 |
52 changes: 52 additions & 0 deletions
52
...s/synthetix/models/marts/base/mainnet/core/fct_core_active_stakers_daily_base_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,52 @@ | ||
{{ config( | ||
materialized = "view", | ||
tags = ["core", "active_stakers", "daily", "base", "mainnet"] | ||
) }} | ||
|
||
with delegation_updated as ( | ||
select | ||
block_timestamp, | ||
account_id, | ||
amount | ||
from {{ ref('core_delegation_updated_base_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 |
30 changes: 30 additions & 0 deletions
30
transformers/synthetix/models/marts/base/mainnet/core/schema.yml
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
Oops, something went wrong.