Skip to content

Commit

Permalink
Stablecoin V2: Optimism Pipeline (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 authored Jul 19, 2024
1 parent d03bff8 commit 26207da
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 0 deletions.
11 changes: 11 additions & 0 deletions macros/address_balances/address_balances_by_token.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
{% if is_incremental() %}
where block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
{% if chain in ('optimism') %}
-- Some chains had a re-genesis event, if this is the case we need to include the genesis balances

union all
select address, contract_address, block_timestamp, balance as flow
from {{ref("fact_"~chain~"_genesis_stablecoin_balances")}}
{% if is_incremental() %}
where block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
{% endif %}

),
credit_debits_and_latest_balances as (
select address, contract_address, block_timestamp, flow
Expand Down
11 changes: 11 additions & 0 deletions macros/stablecoins/genesis_stablecoin_balances.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% macro genesis_stablecoin_balances(source_table, genesis_timestamp) %}

select
'{{genesis_timestamp}}'::timestamp as block_timestamp
, lower(value:contract_address::string) as contract_address
, lower(value:address::string) as address
, value:balance::float as balance
from {{ source("PROD_LANDING", source_table)}},
lateral flatten(input => parse_json(source_json))
where extraction_date = (select max(extraction_date) from {{ source("PROD_LANDING", source_table)}})
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized="incremental",
unique_key="unique_id",
database="optimism",
schema="core",
alias="ez_stablecoin_metrics_by_address",
snowflake_warehouse="STABLECOIN_V2_LG_2",
)
}}


{{stablecoin_metrics("optimism")}}
7 changes: 7 additions & 0 deletions models/staging/optimism/__optimism__sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ sources:
database: PC_DBT_DB
tables:
- name: dim_optimism_current_balances
- name: PROD_LANDING
schema: PROD_LANDING
database: LANDING_DATABASE
tables:
- name: raw_optimism_genesis_dai_stablecoin_balances
- name: raw_optimism_genesis_usdce_stablecoin_balances
- name: raw_optimism_genesis_usdt_stablecoin_balances
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ config(materialized="table") }}

{% set genesis_timestamp = "2021-11-10 00:00:00.000" %}

with
dai as ({{genesis_stablecoin_balances("raw_optimism_genesis_dai_stablecoin_balances", genesis_timestamp)}})

, usdce as ({{genesis_stablecoin_balances("raw_optimism_genesis_usdce_stablecoin_balances", genesis_timestamp)}})

, usdt as ({{genesis_stablecoin_balances("raw_optimism_genesis_usdt_stablecoin_balances", genesis_timestamp)}})

select * from dai
union all
select * from usdce
union all
select * from usdt
10 changes: 10 additions & 0 deletions models/staging/optimism/fact_optimism_stablecoin_balances.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{
config(
materialized="incremental",
unique_key="unique_id",
snowflake_warehouse="STABLECOIN_V2_LG_2",
)
}}


{{stablecoin_balances("optimism")}}
10 changes: 10 additions & 0 deletions models/staging/optimism/fact_optimism_stablecoin_metrics_all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{
config(
materialized="incremental",
unique_key="unique_id",
snowflake_warehouse="STABLECOIN_V2_LG_2",
)
}}


{{stablecoin_metrics_all("optimism")}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{
config(
materialized="incremental",
unique_key="unique_id",
snowflake_warehouse="STABLECOIN_V2_LG_2",
)
}}


{{stablecoin_metrics_p2p("optimism")}}
10 changes: 10 additions & 0 deletions models/staging/optimism/fact_optimism_stablecoin_metrics_p2p.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{
config(
materialized="incremental",
unique_key="unique_id",
snowflake_warehouse="STABLECOIN_V2_LG_2",
)
}}


{{stablecoin_metrics_p2p("optimism")}}

0 comments on commit 26207da

Please sign in to comment.