-
Notifications
You must be signed in to change notification settings - Fork 9
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 #84 from Artemis-xyz/sm-add-cctp
Bridges: adding CCTP
- Loading branch information
Showing
10 changed files
with
338 additions
and
32 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
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,29 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="CCTP", | ||
database="cctp", | ||
schema="core", | ||
alias="ez_metrics", | ||
) | ||
}} | ||
|
||
with | ||
bridge_volume as ( | ||
select date, bridge_volume | ||
from {{ ref("fact_cctp_bridge_volume") }} | ||
where chain is null | ||
), | ||
bridge_dau as ( | ||
select date, bridge_dau | ||
from {{ ref("fact_cctp_bridge_dau") }} | ||
) | ||
select | ||
bridge_volume.date as date, | ||
'cctp' as protocol, | ||
'bridge' as category, | ||
bridge_volume.bridge_volume, | ||
bridge_dau.bridge_dau | ||
from bridge_volume | ||
left join bridge_dau on bridge_volume.date = bridge_dau.date | ||
where bridge_volume.date < to_date(sysdate()) |
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,25 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="CCTP", | ||
database="cctp", | ||
schema="core", | ||
alias="ez_metrics_by_chain", | ||
) | ||
}} | ||
|
||
with | ||
bridge_volume as ( | ||
select date, chain, inflow, outflow | ||
from {{ ref("fact_cctp_bridge_volume") }} | ||
where chain is not null | ||
) | ||
select | ||
date, | ||
'cctp' as protocol, | ||
'bridge' as category, | ||
chain, | ||
inflow, | ||
outflow | ||
from bridge_volume | ||
where date < to_date(sysdate()) |
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,38 @@ | ||
models: | ||
- name: fact_cctp_bridge_dau | ||
tests: | ||
- "dbt_expectations.expect_table_row_count_to_be_between:": | ||
min_value: 1 | ||
max_value: 1000000 | ||
columns: | ||
- name: APP | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist | ||
- name: DATE | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist | ||
- dbt_expectations.expect_row_values_to_have_recent_data: | ||
datepart: day | ||
interval: 3 | ||
severity: warn | ||
- name: BRIDGE_DAU | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist | ||
- dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs: | ||
date_column_name: DATE | ||
period: day | ||
lookback_periods: 1 | ||
trend_periods: 14 | ||
test_periods: 28 | ||
sigma_threshold: 3 | ||
take_logs: true | ||
severity: warn | ||
- name: CHAIN | ||
tests: | ||
- dbt_expectations.expect_column_to_exist | ||
- name: CATEGORY | ||
tests: | ||
- dbt_expectations.expect_column_to_exist |
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,38 @@ | ||
models: | ||
- name: fact_cctp_bridge_volume | ||
tests: | ||
- "dbt_expectations.expect_table_row_count_to_be_between:": | ||
min_value: 1 | ||
max_value: 1000000 | ||
columns: | ||
- name: APP | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist | ||
- name: DATE | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist | ||
- dbt_expectations.expect_row_values_to_have_recent_data: | ||
datepart: day | ||
interval: 3 | ||
severity: warn | ||
- name: BRIDGE_VOLUME | ||
tests: | ||
- dbt_expectations.expect_column_to_exist | ||
- name: FEES | ||
tests: | ||
- dbt_expectations.expect_column_to_exist | ||
- name: INFLOW | ||
tests: | ||
- dbt_expectations.expect_column_to_exist | ||
- name: OUTFLOW | ||
tests: | ||
- dbt_expectations.expect_column_to_exist | ||
- name: CHAIN | ||
tests: | ||
- dbt_expectations.expect_column_to_exist | ||
- name: CATEGORY | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist |
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,19 @@ | ||
with | ||
daily_addresses as ( | ||
select block_timestamp::date as date, count(distinct user) as bridge_dau | ||
from | ||
( | ||
select block_timestamp, sender as user | ||
from {{ ref("fact_cctp_transfers") }} | ||
|
||
union | ||
|
||
select block_timestamp, reciepient as user | ||
from {{ ref("fact_cctp_transfers") }} | ||
) t | ||
group by 1 | ||
order by 1 asc | ||
) | ||
|
||
select date, bridge_dau, 'cctp' as app, null as chain, 'Bridge' as category | ||
from daily_addresses |
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,45 @@ | ||
with | ||
protocol_volume_and_fees as ( | ||
select date, sum(amount_usd) as bridge_volume, sum(fee_usd) as fees | ||
from {{ ref("fact_cctp_flows") }} | ||
group by 1 | ||
), | ||
|
||
outflows as ( | ||
select date, source_chain as chain, sum(amount_usd) as outflow | ||
from {{ ref("fact_cctp_flows") }} | ||
where chain is not null | ||
group by 1, 2 | ||
), | ||
|
||
inflows as ( | ||
select date, destination_chain as chain, sum(amount_usd) as inflow | ||
from {{ ref("fact_cctp_flows") }} | ||
where chain is not null | ||
group by 1, 2 | ||
) | ||
|
||
select | ||
date, | ||
null as chain, | ||
null as inflow, | ||
null as outflow, | ||
bridge_volume, | ||
fees, | ||
'cctp' as app, | ||
'Bridge' as category | ||
from protocol_volume_and_fees | ||
|
||
union | ||
|
||
select | ||
coalesce(t1.date, t2.date) as date, | ||
coalesce(t1.chain, t2.chain) as chain, | ||
coalesce(t2.inflow, 0) as inflow, | ||
coalesce(t1.outflow, 0) as outflow, | ||
null as bridge_volume, | ||
null as fees, | ||
'cctp' as app, | ||
'Bridge' as category | ||
from outflows t1 | ||
full join inflows t2 on t1.date = t2.date and t1.chain = t2.chain |
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="table", | ||
snowflake_warehouse="CCTP", | ||
)}} | ||
with | ||
chain_id_map as ( | ||
select chain_id, chain | ||
from ( | ||
values | ||
(0, 'ethereum'), | ||
(1, 'avalanche'), | ||
(2, 'optimism'), | ||
(3, 'arbitrum'), | ||
(4, 'noble'), | ||
(5, 'solana'), | ||
(6, 'base'), | ||
(7, 'polygon') | ||
|
||
) as t(chain_id, chain) | ||
), | ||
volume_by_chain_and_symbol as ( | ||
select | ||
block_timestamp::date as date, | ||
c1.chain as source_chain, | ||
c2.chain as destination_chain, | ||
'Stablecoin' as category, | ||
amount_usd | ||
from {{ ref("fact_cctp_transfers")}} t | ||
left join chain_id_map c1 on t.source_domain_id = c1.chain_id | ||
left join chain_id_map c2 on t.destination_domain_id = c2.chain_id | ||
) | ||
select | ||
date, | ||
'cctp' as app, | ||
source_chain, | ||
destination_chain, | ||
category, | ||
sum(amount_usd) as amount_usd, | ||
null as fee_usd | ||
from volume_by_chain_and_symbol | ||
where source_chain is not null and destination_chain is not null | ||
group by 1, 2, 3, 4, 5 |
Oops, something went wrong.