Skip to content

Commit

Permalink
Merge pull request #131 from Synthetixio/feat/add-acc-activity-models
Browse files Browse the repository at this point in the history
Transformers - Add Account Activity models & tests
  • Loading branch information
Tburm authored Oct 15, 2024
2 parents 68317d5 + ef1b0a1 commit 8d6df01
Show file tree
Hide file tree
Showing 15 changed files with 620 additions and 0 deletions.
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
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
version: 2
models:
- name: fct_core_account_activity_arbitrum_mainnet
description: "Daily number of accounts by action (Delegated, Withdrawn, Claimed)"
columns:
- name: block_timestamp
description: "Block timestamp"
data_type: timestamp with time zone
tests:
- not_null
- name: account_action
description: "Type of LP action"
data_type: text
tests:
- not_null
- accepted_values:
values: ["Delegated", "Withdrawn", "Claimed"]
- name: account_id
description: "ID of the account"
data_type: numeric
tests:
- not_null
- name: fct_core_active_stakers_daily_arbitrum_mainnet
description: "Daily number of active stakers"
columns:
- name: block_date
description: "Date"
data_type: date
tests:
- not_null
- name: nof_stakers_daily
description: "Number of active stakers daily"
- name: fct_pool_rewards_arbitrum_mainnet
columns:
- name: ts
Expand Down
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
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
version: 2
models:
- name: fct_core_account_activity_arbitrum_sepolia
description: "Daily number of accounts by action (Delegated, Withdrawn, Claimed)"
columns:
- name: block_timestamp
description: "Block timestamp"
data_type: timestamp with time zone
tests:
- not_null
- name: account_action
description: "Type of LP action"
data_type: text
tests:
- not_null
- accepted_values:
values: ["Delegated", "Withdrawn", "Claimed"]
- name: account_id
description: "ID of the account"
data_type: numeric
tests:
- not_null
- name: fct_core_active_stakers_daily_arbitrum_sepolia
description: "Daily number of active stakers"
columns:
- name: block_date
description: "Date"
data_type: date
tests:
- not_null
- name: nof_stakers_daily
description: "Number of active stakers daily"
- name: fct_pool_rewards_arbitrum_sepolia
columns:
- name: ts
Expand Down
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
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 transformers/synthetix/models/marts/base/mainnet/core/schema.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
version: 2
models:
- name: fct_core_account_activity_base_mainnet
description: "Daily number of accounts by action (Delegated, Withdrawn, Claimed)"
columns:
- name: block_timestamp
description: "Block timestamp"
data_type: timestamp with time zone
tests:
- not_null
- name: account_action
description: "Type of LP action"
data_type: text
tests:
- not_null
- accepted_values:
values: ["Delegated", "Withdrawn", "Claimed"]
- name: account_id
description: "ID of the account"
data_type: numeric
tests:
- not_null
- name: fct_core_active_stakers_daily_base_mainnet
description: "Daily number of active stakers"
columns:
- name: block_date
description: "Date"
data_type: date
tests:
- not_null
- name: nof_stakers_daily
description: "Number of active stakers daily"
- name: fct_core_vault_collateral_base_mainnet
columns:
- name: ts
Expand Down
Loading

0 comments on commit 8d6df01

Please sign in to comment.