Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridges: Adding Rainbow Bridge #85

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ with
ref("fact_polygon_pos_bridge_flows"),
ref("fact_starknet_bridge_flows"),
ref("fact_zksync_era_bridge_flows"),
ref("fact_rainbow_bridge_flows"),
]
)
}}
Expand Down
2 changes: 1 addition & 1 deletion models/projects/cctp/core/ez_cctp_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with
select
bridge_volume.date as date,
'cctp' as protocol,
'bridge' as category,
'Bridge' as category,
bridge_volume.bridge_volume,
bridge_dau.bridge_dau
from bridge_volume
Expand Down
2 changes: 1 addition & 1 deletion models/projects/cctp/core/ez_cctp_metrics_by_chain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ with
select
date,
'cctp' as protocol,
'bridge' as category,
'Bridge' as category,
chain,
inflow,
outflow
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{
config(
materialized="table",
snowflake_warehouse="RAINBOW_BRIDGE",
database="rainbow_bridge",
schema="core",
alias="ez_metrics",
)
}}

with
bridge_volume as (
select date, bridge_volume
from {{ ref("fact_rainbow_bridge_bridge_volume") }}
where chain is null
),
bridge_dau as (
select date, bridge_dau
from {{ ref("fact_rainbow_bridge_bridge_dau") }}
)
select
bridge_volume.date as date,
'rainbow_bridge' 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())
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{
config(
materialized="table",
snowflake_warehouse="RAINBOW_BRIDGE",
database="rainbow_bridge",
schema="core",
alias="ez_metrics_by_chain",
)
}}

with
bridge_volume as (
select date, chain, inflow, outflow
from {{ ref("fact_rainbow_bridge_bridge_volume") }}
where chain is not null
)
select
date,
'rainbow_bridge' as protocol,
'Bridge' as category,
chain,
inflow,
outflow
from bridge_volume
where date < to_date(sysdate())
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
models:
- name: fact_rainbow_bridge_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
models:
- name: fact_rainbow_bridge_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
with
daily_addresses as (
select
date_trunc('day', block_timestamp) as date,
count(distinct user) as bridge_dau
from
(
select block_timestamp, depositor as user
from {{ ref("fact_rainbow_bridge_transfers") }}

union

select block_timestamp, recipient as user
from {{ ref("fact_rainbow_bridge_transfers") }}
) t
group by 1
order by 1 asc
)

select date, bridge_dau, 'rainbow_bridge' as app, null as chain, 'Bridge' as category
from daily_addresses
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
from {{ ref("fact_rainbow_bridge_flows") }}
group by 1
),

outflows as (
select date, source_chain as chain, sum(amount_usd) as outflow
from {{ ref("fact_rainbow_bridge_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_rainbow_bridge_flows") }}
where chain is not null
group by 1, 2
)

select
date,
null as chain,
null as inflow,
null as outflow,
bridge_volume,
null as fees,
'rainbow_bridge' 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,
'rainbow_bridge' as app,
'Bridge' as category
from outflows t1
full join inflows t2 on t1.date = t2.date and t1.chain = t2.chain
33 changes: 33 additions & 0 deletions models/staging/rainbow_bridge/fact_rainbow_bridge_flows.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{ config(
materialized="table",
snowflake_warehouse="RAINBOW_BRIDGE",
) }}
with
dim_contracts as (
select distinct address, chain, category
from {{ ref("dim_contracts_gold") }}
where category is not null and chain is not null
),

volume_and_fees_by_chain_and_symbol as (
select
date_trunc('hour', block_timestamp) as hour,
source_chain,
destination_chain,
coalesce(c.category, 'Not Categorized') as category,
amount_usd
from {{ ref("fact_rainbow_bridge_transfers") }} t
left join dim_contracts c on lower(t.token_address) = lower(c.address) and c.chain = 'ethereum' --only using l1token
)

select
date_trunc('day', hour) as date,
'rainbow_bridge' as app,
source_chain,
destination_chain,
category,
sum(amount_usd) as amount_usd,
null as fee_usd
from volume_and_fees_by_chain_and_symbol
group by 1, 2, 3, 4, 5
order by date asc, source_chain asc
74 changes: 74 additions & 0 deletions models/staging/rainbow_bridge/fact_rainbow_bridge_transfers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{ config(
materialized="incremental",
snowflake_warehouse="RAINBOW_BRIDGE",
) }}
with
rainbow_bridge_transfers as (
select
block_timestamp,
tx_hash,
event_index,
origin_from_address as depositor,
origin_from_address as recipient, -- assume it is the same person recievied the token on the other end (may need to adjust)
coalesce(decoded_log:"amount"::bigint, decoded_log:"value"::bigint, decoded_log:"wad"::bigint, decoded_log:"_value"::bigint, decoded_log:"_amount"::bigint, decoded_log:"tokens"::bigint) as amount,
contract_address as token_address,
'ethereum' as source_chain,
'near' as destination_chain,
decoded_log
from ethereum_flipside.core.ez_decoded_event_logs
where origin_to_address='0x23ddd3e3692d1861ed57ede224608875809e127f'
and origin_function_signature='0x0889bfe7'
and event_name='Transfer'
{% if is_incremental() %}
and block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
union all
select
block_timestamp,
tx_hash,
event_index,
origin_from_address as depositor,
origin_from_address as recipient, -- assume it is the same person recievied the token on the other end (may need to adjust)
coalesce(decoded_log:"amount"::bigint, decoded_log:"value"::bigint, decoded_log:"wad"::bigint, decoded_log:"_value"::bigint, decoded_log:"_amount"::bigint, decoded_log:"tokens"::bigint) as amount,
contract_address as token_address,
'near' as source_chain,
'ethereum' as destination_chain,
decoded_log
from ethereum_flipside.core.ez_decoded_event_logs
where origin_to_address='0x23ddd3e3692d1861ed57ede224608875809e127f'
and origin_function_signature='0x4a00c629'
and event_name='Transfer'
{% if is_incremental() %}
and block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
),
ethereum_to_near_recipient as (
select
tx_hash,
decoded_log:"accountId"::string as depositor
from ethereum_flipside.core.ez_decoded_event_logs
where origin_to_address='0x23ddd3e3692d1861ed57ede224608875809e127f'
and origin_function_signature='0x0889bfe7'
and event_name='Locked'
{% if is_incremental() %}
and block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
)

select
block_timestamp,
t.tx_hash,
event_index,
coalesce(r.depositor, t.depositor) as depositor,
recipient,
t.token_address,
amount,
coalesce((amount / power(10, p.decimals)) * price, 0) as amount_usd,
source_chain,
destination_chain,
decoded_log
from rainbow_bridge_transfers t
left join ethereum_to_near_recipient r on t.tx_hash = r.tx_hash
left join ethereum_flipside.price.ez_hourly_token_prices p
on date_trunc('hour', t.block_timestamp) = p.hour
and lower(t.token_address) = lower(p.token_address)
Loading