diff --git a/macros/rwa/ez_rwa_by_chain.sql b/macros/rwa/ez_rwa_by_chain.sql new file mode 100644 index 00000000..d579b57b --- /dev/null +++ b/macros/rwa/ez_rwa_by_chain.sql @@ -0,0 +1,16 @@ +{% macro ez_rwa_by_chain(issuer_id) %} + +select + tvl.date, + tvl.chain, + tvl.symbol, + tvl.issuer_friendly_name, + sum(tvl.tokenized_supply_change) as tokenized_supply_change, + sum(tvl.tokenized_mcap_change) as tokenized_mcap_change, + sum(tvl.tokenized_supply) as tokenized_supply, + sum(tvl.tokenized_mcap) as tokenized_mcap, +from {{ ref('fact_' ~ issuer_id ~ '_tvl_by_chain') }} tvl +where date < to_date(sysdate()) +group by 1, 2, 3, 4 + +{% endmacro %} diff --git a/macros/rwa/ez_rwa_by_product.sql b/macros/rwa/ez_rwa_by_product.sql new file mode 100644 index 00000000..3147c6a4 --- /dev/null +++ b/macros/rwa/ez_rwa_by_product.sql @@ -0,0 +1,14 @@ +{% macro ez_rwa_by_product(issuer_id) %} + +select + tvl.date, + tvl.issuer_friendly_name, + tvl.symbol, + sum(tvl.tokenized_supply_change) as tokenized_supply_change, + sum(tvl.tokenized_mcap_change) as tokenized_mcap_change, + sum(tvl.tokenized_supply) as tokenized_supply, + sum(tvl.tokenized_mcap) as tokenized_mcap, +from {{ ref('fact_' ~ issuer_id ~ '_tvl_by_product') }} tvl +where date < to_date(sysdate()) +group by 1, 2, 3 +{% endmacro %} diff --git a/macros/rwa/rwa_balances.sql b/macros/rwa/rwa_balances.sql new file mode 100644 index 00000000..e4f836e8 --- /dev/null +++ b/macros/rwa/rwa_balances.sql @@ -0,0 +1,173 @@ +{% macro rwa_balances(chain) %} + -- This macro takes our balances table and forward fills the values for each address for each rwa + + {% set new_rwa_address = '' %} + +with + rwa_balances as ( + select + block_timestamp + , t1.contract_address + , symbol + , address + {% if chain in ('solana') %} + , amount as rwa_supply_native + {% else %} + , balance_token / pow(10, num_decimals) as rwa_supply_native + {% endif %} + from {{ ref("fact_" ~ chain ~ "_address_balances_by_token")}} t1 + inner join {{ ref("fact_" ~ chain ~ "_rwa_addresses")}} t2 + on lower(t1.contract_address) = lower(t2.contract_address) + where block_timestamp < to_date(sysdate()) + {% if new_rwa_address != '' %} + and lower(t1.contract_address) = lower('{{ new_rwa_address }}') + {% endif %} + {% if is_incremental() and new_rwa_address == '' %} + and block_timestamp > (select dateadd('day', -3, max(date)) from {{ this }}) + {% endif %} + ) + {% if is_incremental() and new_rwa_address == '' %} + --Get the most recent data in the existing table + , stale_rwa_balances as ( + select + date as block_timestamp + , t.contract_address + , t.symbol + , t.address + , t.rwa_supply_native + from {{ this }} t + where date = (select dateadd('day', -3, max(date)) from {{ this }}) + ) + {% endif %} + , heal_balance_table as ( + -- rwa_balances and stale_rwa_balances do not over lap + -- rwa_balances select every row greater than the most recent date in the table + -- stale_rwa_balances selects the most recent date in the table + select + block_timestamp + , contract_address + , symbol + , address + , rwa_supply_native + from rwa_balances + {% if is_incremental() and new_rwa_address == '' %} + union + select + block_timestamp + , contract_address + , symbol + , address + , rwa_supply_native + from stale_rwa_balances + {% endif %} + ) + -- get the latest balance for each address for each date + , balances as ( + select + block_timestamp::date as date + , contract_address + , symbol + , address + , rwa_supply_native + from ( + select + block_timestamp + , contract_address + , symbol + , address + , rwa_supply_native + , row_number() over (partition by block_timestamp::date, contract_address, address, symbol order by block_timestamp desc) AS rn + from heal_balance_table + ) + where rn = 1 + ) + , date_range as ( + select + min(block_timestamp)::date as date + , contract_address + , symbol + , address + from heal_balance_table + group by contract_address, address, symbol + + union all + + select + dateadd(day, 1, date) as date + , contract_address + , symbol + , address + from date_range + where date < dateadd(day, -1, to_date(sysdate())) + ) + , historical_supply_by_address_balances as ( + select + date + , address + , contract_address + , symbol + , coalesce( + rwa_supply_native, + LAST_VALUE(balances.rwa_supply_native ignore nulls) over ( + partition by contract_address, address, symbol + order by date + rows between unbounded preceding and current row + ) + ) as rwa_supply_native + from date_range + left join balances using (date, contract_address, symbol, address) + ) + , rwa_balances_with_price as ( + select + st.date + , address + , st.contract_address + , st.symbol + , coalesce( d.shifted_token_price_usd, + case + when c.coingecko_id in ('blackrock-usd-institutional-digital-liquidity-fund', 'franklin-onchain-u-s-government-money-fund') + then 1 + when c.coingecko_id = 'hashnote-usyc' + then coalesce(h.rate, 1) + when c.coingecko_id = 'ousg' + then o.price + end + ) as price + , rwa_supply_native + , rwa_supply_native * + coalesce( d.shifted_token_price_usd, + case + when c.coingecko_id in ('blackrock-usd-institutional-digital-liquidity-fund', 'franklin-onchain-u-s-government-money-fund') + then 1 + when c.coingecko_id = 'hashnote-usyc' + then coalesce(h.rate, 1) + when c.coingecko_id = 'ousg' + then o.price + end + ) as rwa_supply_usd + from historical_supply_by_address_balances st + left join {{ ref( "fact_" ~ chain ~ "_rwa_addresses") }} c + on lower(st.contract_address) = lower(c.contract_address) + left join {{ ref( "fact_coingecko_token_date_adjusted_gold") }} d + on lower(c.coingecko_id) = lower(d.coingecko_id) + and st.date = d.date::date + left join {{ ref( "fact_hashnote_usyc_rate") }} h + on st.date = h.date + and st.symbol = 'USYC' + left join {{ ref( "fact_ousg_prices") }} o + on st.date = o.date + and st.symbol = 'OUSG' + ) +select + date + , address + , contract_address + , symbol + , price + , rwa_supply_native + , rwa_supply_usd + , '{{ chain }}' as chain + , date || '-' || address || '-' || contract_address as unique_id +from rwa_balances_with_price +where date < to_date(sysdate()) +{% endmacro %} \ No newline at end of file diff --git a/macros/rwa/rwa_data_by_chain_for_issuer.sql b/macros/rwa/rwa_data_by_chain_for_issuer.sql new file mode 100644 index 00000000..ede83df7 --- /dev/null +++ b/macros/rwa/rwa_data_by_chain_for_issuer.sql @@ -0,0 +1,15 @@ +{% macro rwa_data_by_chain_for_issuer(issuer_id) %} + select + date + , chain + , symbol + , issuer_friendly_name + , avg(price) as price + , sum(rwa_supply_usd) as tokenized_mcap + , sum(net_rwa_supply_usd_change) as tokenized_mcap_change + , sum(rwa_supply_native) as tokenized_supply + , sum(net_rwa_supply_native_change) as tokenized_supply_change + from {{ ref( "agg_rwa_by_product_and_chain") }} + where issuer_id = '{{ issuer_id }}' + group by 1, 2, 3, 4 +{% endmacro %} diff --git a/macros/rwa/rwa_data_by_product_for_issuer.sql b/macros/rwa/rwa_data_by_product_for_issuer.sql new file mode 100644 index 00000000..a8db5cf7 --- /dev/null +++ b/macros/rwa/rwa_data_by_product_for_issuer.sql @@ -0,0 +1,15 @@ +{% macro rwa_data_by_product_for_issuer(issuer_id) %} + select + date + , chain + , symbol + , issuer_friendly_name + , avg(price) as price + , sum(rwa_supply_usd) as tokenized_mcap + , sum(net_rwa_supply_usd_change) as tokenized_mcap_change + , sum(rwa_supply_native) as tokenized_supply + , sum(net_rwa_supply_native_change) as tokenized_supply_change + from {{ ref( "agg_rwa_by_product_and_chain") }} + where issuer_id = '{{ issuer_id }}' + group by 1, 2, 3, 4 +{% endmacro %} diff --git a/macros/rwa/rwa_supply_by_date_and_chain.sql b/macros/rwa/rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..0ce1d92b --- /dev/null +++ b/macros/rwa/rwa_supply_by_date_and_chain.sql @@ -0,0 +1,24 @@ +{% macro rwa_supply_by_date_and_chain(chain) %} +with rwa_balances as ( + select + date + , chain + , symbol + , avg(price) as price + , sum(rwa_supply_native) as rwa_supply_native + , sum(rwa_supply_usd) as rwa_supply_usd + from {{ ref("fact_" ~ chain ~ "_rwa_balances") }} + where rwa_supply_native >= 1e-9 + group by 1, 2, 3 +) +select + date + , chain + , symbol + , price + , rwa_supply_native - lag(rwa_supply_native) over (partition by symbol order by date) as net_rwa_supply_native_change + , rwa_supply_usd - lag(rwa_supply_usd) over (partition by symbol order by date) as net_rwa_supply_usd_change + , rwa_supply_native + , rwa_supply_usd +from rwa_balances +{% endmacro %} diff --git a/models/projects/blackrock/core/ez_blackrock_metrics_by_chain.sql b/models/projects/blackrock/core/ez_blackrock_metrics_by_chain.sql new file mode 100644 index 00000000..b7022dc1 --- /dev/null +++ b/models/projects/blackrock/core/ez_blackrock_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'blackrock', + schema = 'core', + snowflake_warehouse = 'BLACKROCK', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('blackrock') }} diff --git a/models/projects/blackrock/core/ez_blackrock_metrics_by_product.sql b/models/projects/blackrock/core/ez_blackrock_metrics_by_product.sql new file mode 100644 index 00000000..53ef2baf --- /dev/null +++ b/models/projects/blackrock/core/ez_blackrock_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'blackrock', + schema = 'core', + snowflake_warehouse = 'BLACKROCK', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('blackrock') }} diff --git a/models/projects/franklin_templeton/ez_franklin_templeton_metrics_by_chain.sql b/models/projects/franklin_templeton/ez_franklin_templeton_metrics_by_chain.sql new file mode 100644 index 00000000..4537f34e --- /dev/null +++ b/models/projects/franklin_templeton/ez_franklin_templeton_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'franklin_templeton', + schema = 'core', + snowflake_warehouse = 'FRANKLIN_TEMPLETON', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('franklin_templeton') }} diff --git a/models/projects/franklin_templeton/ez_franklin_templeton_metrics_by_product.sql b/models/projects/franklin_templeton/ez_franklin_templeton_metrics_by_product.sql new file mode 100644 index 00000000..e88e7d35 --- /dev/null +++ b/models/projects/franklin_templeton/ez_franklin_templeton_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'franklin_templeton', + schema = 'core', + snowflake_warehouse = 'FRANKLIN_TEMPLETON', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('franklin_templeton') }} diff --git a/models/projects/hashnote/core/ez_hashnote_metrics_by_chain.sql b/models/projects/hashnote/core/ez_hashnote_metrics_by_chain.sql new file mode 100644 index 00000000..5204abc4 --- /dev/null +++ b/models/projects/hashnote/core/ez_hashnote_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'hashnote', + schema = 'core', + snowflake_warehouse = 'HASHNOTE', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('hashnote') }} diff --git a/models/projects/hashnote/core/ez_hashnote_metrics_by_product.sql b/models/projects/hashnote/core/ez_hashnote_metrics_by_product.sql new file mode 100644 index 00000000..c6ad4a26 --- /dev/null +++ b/models/projects/hashnote/core/ez_hashnote_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'hashnote', + schema = 'core', + snowflake_warehouse = 'HASHNOTE', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('hashnote') }} diff --git a/models/projects/ondo/core/ez_ondo_metrics_by_chain.sql b/models/projects/ondo/core/ez_ondo_metrics_by_chain.sql new file mode 100644 index 00000000..05fcbde9 --- /dev/null +++ b/models/projects/ondo/core/ez_ondo_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'ondo', + schema = 'core', + snowflake_warehouse = 'ONDO', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('ondo') }} \ No newline at end of file diff --git a/models/projects/ondo/core/ez_ondo_metrics_by_product.sql b/models/projects/ondo/core/ez_ondo_metrics_by_product.sql new file mode 100644 index 00000000..029f38e0 --- /dev/null +++ b/models/projects/ondo/core/ez_ondo_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'ondo', + schema = 'core', + snowflake_warehouse = 'ONDO', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('ondo') }} diff --git a/models/projects/openeden/ez_openeden_metrics_by_chain.sql b/models/projects/openeden/ez_openeden_metrics_by_chain.sql new file mode 100644 index 00000000..4afd175d --- /dev/null +++ b/models/projects/openeden/ez_openeden_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'openeden', + schema = 'core', + snowflake_warehouse = 'OPENEDEN', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('openeden') }} diff --git a/models/projects/openeden/ez_openeden_metrics_by_product.sql b/models/projects/openeden/ez_openeden_metrics_by_product.sql new file mode 100644 index 00000000..18cf4170 --- /dev/null +++ b/models/projects/openeden/ez_openeden_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'openeden', + schema = 'core', + snowflake_warehouse = 'OPENEDEN', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('openeden') }} \ No newline at end of file diff --git a/models/projects/paxos/core/ez_paxos_metrics_by_chain.sql b/models/projects/paxos/core/ez_paxos_metrics_by_chain.sql new file mode 100644 index 00000000..c0f604ab --- /dev/null +++ b/models/projects/paxos/core/ez_paxos_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'paxos', + schema = 'core', + snowflake_warehouse = 'PAXOS', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('paxos') }} diff --git a/models/projects/paxos/core/ez_paxos_metrics_by_product.sql b/models/projects/paxos/core/ez_paxos_metrics_by_product.sql new file mode 100644 index 00000000..e2ff121d --- /dev/null +++ b/models/projects/paxos/core/ez_paxos_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'paxos', + schema = 'core', + snowflake_warehouse = 'PAXOS', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('paxos') }} diff --git a/models/projects/tether/ez_tether_metrics_by_chain.sql b/models/projects/tether/ez_tether_metrics_by_chain.sql new file mode 100644 index 00000000..06c6e59b --- /dev/null +++ b/models/projects/tether/ez_tether_metrics_by_chain.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'tether', + schema = 'core', + snowflake_warehouse = 'TETHER', + alias = 'ez_metrics_by_chain' + ) +}} + +{{ ez_rwa_by_chain('tether') }} diff --git a/models/projects/tether/ez_tether_metrics_by_product.sql b/models/projects/tether/ez_tether_metrics_by_product.sql new file mode 100644 index 00000000..9256f07b --- /dev/null +++ b/models/projects/tether/ez_tether_metrics_by_product.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized = 'table', + database = 'tether', + schema = 'core', + snowflake_warehouse = 'TETHER', + alias = 'ez_metrics_by_product' + ) +}} + +{{ ez_rwa_by_product('tether') }} diff --git a/models/staging/blackrock/fact_blackrock_tvl_by_chain.sql b/models/staging/blackrock/fact_blackrock_tvl_by_chain.sql new file mode 100644 index 00000000..bfc8710c --- /dev/null +++ b/models/staging/blackrock/fact_blackrock_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="BLACKROCK", + ) +}} + +{{ rwa_data_by_chain_for_issuer("blackrock") }} \ No newline at end of file diff --git a/models/staging/blackrock/fact_blackrock_tvl_by_product.sql b/models/staging/blackrock/fact_blackrock_tvl_by_product.sql new file mode 100644 index 00000000..e28fc1c2 --- /dev/null +++ b/models/staging/blackrock/fact_blackrock_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="BLACKROCK", + ) +}} + +{{ rwa_data_by_product_for_issuer("blackrock") }} \ No newline at end of file diff --git a/models/staging/franklin_templeton/fact_franklin_templeton_tvl_by_chain.sql b/models/staging/franklin_templeton/fact_franklin_templeton_tvl_by_chain.sql new file mode 100644 index 00000000..c568bfa7 --- /dev/null +++ b/models/staging/franklin_templeton/fact_franklin_templeton_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="FRANKLIN_TEMPLETON", + ) +}} + +{{ rwa_data_by_chain_for_issuer("franklin_templeton") }} diff --git a/models/staging/franklin_templeton/fact_franklin_templeton_tvl_by_product.sql b/models/staging/franklin_templeton/fact_franklin_templeton_tvl_by_product.sql new file mode 100644 index 00000000..a304e9e3 --- /dev/null +++ b/models/staging/franklin_templeton/fact_franklin_templeton_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="FRANKLIN_TEMPLETON", + ) +}} + +{{ rwa_data_by_product_for_issuer("franklin_templeton") }} diff --git a/models/staging/hashnote/fact_hashnote_tvl_by_chain.sql b/models/staging/hashnote/fact_hashnote_tvl_by_chain.sql new file mode 100644 index 00000000..114a4894 --- /dev/null +++ b/models/staging/hashnote/fact_hashnote_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="HASHNOTE", + ) +}} + +{{ rwa_data_by_chain_for_issuer("hashnote") }} \ No newline at end of file diff --git a/models/staging/hashnote/fact_hashnote_tvl_by_product.sql b/models/staging/hashnote/fact_hashnote_tvl_by_product.sql new file mode 100644 index 00000000..161b1d6b --- /dev/null +++ b/models/staging/hashnote/fact_hashnote_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="HASHNOTE", + ) +}} + +{{ rwa_data_by_product_for_issuer("hashnote") }} diff --git a/models/staging/ondo/fact_ondo_tvl_by_chain.sql b/models/staging/ondo/fact_ondo_tvl_by_chain.sql new file mode 100644 index 00000000..a5596293 --- /dev/null +++ b/models/staging/ondo/fact_ondo_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="ONDO", + ) +}} + +{{ rwa_data_by_chain_for_issuer("ondo") }} diff --git a/models/staging/ondo/fact_ondo_tvl_by_product.sql b/models/staging/ondo/fact_ondo_tvl_by_product.sql new file mode 100644 index 00000000..554ab6a9 --- /dev/null +++ b/models/staging/ondo/fact_ondo_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="ONDO", + ) +}} + +{{ rwa_data_by_product_for_issuer("ondo") }} \ No newline at end of file diff --git a/models/staging/openeden/fact_openeden_tvl_by_chain.sql b/models/staging/openeden/fact_openeden_tvl_by_chain.sql new file mode 100644 index 00000000..b57d0ce4 --- /dev/null +++ b/models/staging/openeden/fact_openeden_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="OPENEDEN", + ) +}} + +{{ rwa_data_by_chain_for_issuer("openeden") }} diff --git a/models/staging/openeden/fact_openeden_tvl_by_product.sql b/models/staging/openeden/fact_openeden_tvl_by_product.sql new file mode 100644 index 00000000..6e95883e --- /dev/null +++ b/models/staging/openeden/fact_openeden_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="OPENEDEN", + ) +}} + +{{ rwa_data_by_product_for_issuer("openeden") }} diff --git a/models/staging/paxos/fact_paxos_tvl_by_chain.sql b/models/staging/paxos/fact_paxos_tvl_by_chain.sql new file mode 100644 index 00000000..3b34dc17 --- /dev/null +++ b/models/staging/paxos/fact_paxos_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="PAXOS", + ) +}} + +{{ rwa_data_by_chain_for_issuer("paxos") }} \ No newline at end of file diff --git a/models/staging/paxos/fact_paxos_tvl_by_product.sql b/models/staging/paxos/fact_paxos_tvl_by_product.sql new file mode 100644 index 00000000..3ac0b760 --- /dev/null +++ b/models/staging/paxos/fact_paxos_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="PAXOS", + ) +}} + +{{ rwa_data_by_product_for_issuer("paxos") }} diff --git a/models/staging/rwa/addresses/dim_rwa_product_issuer_and_type.sql b/models/staging/rwa/addresses/dim_rwa_product_issuer_and_type.sql new file mode 100644 index 00000000..3144f95b --- /dev/null +++ b/models/staging/rwa/addresses/dim_rwa_product_issuer_and_type.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, issuer_id, issuer_friendly_name, product_type FROM + ( + VALUES + ('BUIDL', 'blackrock', 'BlackRock', 'Treasury'), + ('TBILL', 'openeden', 'OpenEden', 'Treasury'), + ('USDY', 'ondo', 'Ondo', 'Treasury'), + ('OUSG', 'ondo', 'Ondo', 'Treasury'), + ('USYC', 'hashnote', 'Hashnote', 'Treasury'), + ('FOBXX', 'franklin_templeton', 'Franklin Templeton', 'Treasury'), + ('PAXG', 'paxos', 'Paxos', 'Gold'), + ('XAUT', 'tether', 'Tether', 'Gold') + ) as results(symbol, issuer_id, issuer_friendly_name, product_type) diff --git a/models/staging/rwa/addresses/fact_arbitrum_rwa_addresses.sql b/models/staging/rwa/addresses/fact_arbitrum_rwa_addresses.sql new file mode 100644 index 00000000..899e04e8 --- /dev/null +++ b/models/staging/rwa/addresses/fact_arbitrum_rwa_addresses.sql @@ -0,0 +1,15 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('BUIDL', '0xa6525ae43edcd03dc08e775774dcabd3bb925872', 6, 'blackrock-usd-institutional-digital-liquidity-fund', 0), + ('TBILL', '0xf84d28a8d28292842dd73d1c5f99476a80b6666a', 6, 'openeden-tbill', 0), + ('USDY', '0x35e050d3c0ec2d29d269a8ecea763a183bdf9a9d', 18, 'ondo-us-dollar-yield', 0), + ('FOBXX', '0xb9e4765bce2609bc1949592059b17ea72fee6c6a', 18, 'franklin-onchain-u-s-government-money-fund', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_avalanche_rwa_addresses.sql b/models/staging/rwa/addresses/fact_avalanche_rwa_addresses.sql new file mode 100644 index 00000000..7b8e2303 --- /dev/null +++ b/models/staging/rwa/addresses/fact_avalanche_rwa_addresses.sql @@ -0,0 +1,13 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('BUIDL', '0x53fc82f14f009009b440a706e31c9021e1196a2f', 6, 'blackrock-usd-institutional-digital-liquidity-fund', 0), + ('FOBXX', '0xe08b4c1005603427420e64252a8b120cace4d122', 18, 'franklin-onchain-u-s-government-money-fund', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_base_rwa_addresses.sql b/models/staging/rwa/addresses/fact_base_rwa_addresses.sql new file mode 100644 index 00000000..9e08d8a8 --- /dev/null +++ b/models/staging/rwa/addresses/fact_base_rwa_addresses.sql @@ -0,0 +1,12 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('FOBXX', '0x60cfc2b186a4cf647486e42c42b11cc6d571d1e4', 18, 'franklin-onchain-u-s-government-money-fund', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_ethereum_rwa_addresses.sql b/models/staging/rwa/addresses/fact_ethereum_rwa_addresses.sql new file mode 100644 index 00000000..7886c39a --- /dev/null +++ b/models/staging/rwa/addresses/fact_ethereum_rwa_addresses.sql @@ -0,0 +1,18 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('BUIDL', '0x7712c34205737192402172409a8f7ccef8aa2aec', 6, 'blackrock-usd-institutional-digital-liquidity-fund', 0), + ('OUSG', '0x1b19c19393e2d034d8ff31ff34c81252fcbbee92', 18, 'ousg', 0), + ('USDY', '0x96f6ef951840721adbf46ac996b59e0235cb985c', 18, 'ondo-us-dollar-yield', 0), + ('USYC', '0x136471a34f6ef19fe571effc1ca711fdb8e49f2b', 6, 'hashnote-usyc', 0), + ('PAXG', '0x45804880de22913dafe09f4980848ece6ecbaf78', 18, 'pax-gold', 0), + ('XAUT', '0x68749665ff8d2d112fa859aa293f07a622782f38', 6, 'tether-gold', 0), + ('TBILL', '0xdd50c053c096cb04a3e3362e2b622529ec5f2e8a', 6, 'openeden-tbill', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_mantle_rwa_addresses.sql b/models/staging/rwa/addresses/fact_mantle_rwa_addresses.sql new file mode 100644 index 00000000..7e5b79cc --- /dev/null +++ b/models/staging/rwa/addresses/fact_mantle_rwa_addresses.sql @@ -0,0 +1,12 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('USDY', '0x5be26527e817998a7206475496fde1e68957c5a6', 18, 'ondo-us-dollar-yield', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_optimism_rwa_addresses.sql b/models/staging/rwa/addresses/fact_optimism_rwa_addresses.sql new file mode 100644 index 00000000..6edd50de --- /dev/null +++ b/models/staging/rwa/addresses/fact_optimism_rwa_addresses.sql @@ -0,0 +1,12 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('BUIDL', '0xa1cdab15bba75a80df4089cafba013e376957cf5', 6, 'blackrock-usd-institutional-digital-liquidity-fund', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_polygon_rwa_addresses.sql b/models/staging/rwa/addresses/fact_polygon_rwa_addresses.sql new file mode 100644 index 00000000..aa8c5adf --- /dev/null +++ b/models/staging/rwa/addresses/fact_polygon_rwa_addresses.sql @@ -0,0 +1,14 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('BUIDL', '0x2893ef551b6dd69f661ac00f11d93e5dc5dc0e99', 6, 'blackrock-usd-institutional-digital-liquidity-fund', 0), + ('OUSG', '0xba11c5effa33c4d6f8f593cfa394241cfe925811', 18, 'ousg', 0), + ('FOBXX', '0x408a634b8a8f0de729b48574a3a7ec3fe820b00a', 18, 'franklin-onchain-u-s-government-money-fund', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/addresses/fact_solana_rwa_addresses.sql b/models/staging/rwa/addresses/fact_solana_rwa_addresses.sql new file mode 100644 index 00000000..1b041657 --- /dev/null +++ b/models/staging/rwa/addresses/fact_solana_rwa_addresses.sql @@ -0,0 +1,13 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +SELECT symbol, contract_address, num_decimals, coingecko_id, initial_supply FROM + ( + VALUES + ('OUSG', 'i7u4r16TcsJTgq1kAG8opmVZyVnAKBwLKu6ZPMwzxNc', 6, 'ousg', 0), + ('USDY', 'A1KLoBrKBde8Ty9qtNQUtq3C2ortoC3u7twggz7sEto6', 6, 'ondo-us-dollar-yield', 0) + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/rwa/agg_rwa_by_product_and_chain.sql b/models/staging/rwa/agg_rwa_by_product_and_chain.sql new file mode 100644 index 00000000..e114f2ed --- /dev/null +++ b/models/staging/rwa/agg_rwa_by_product_and_chain.sql @@ -0,0 +1,39 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +with + chain_metrics as ( + {{ + dbt_utils.union_relations( + relations=[ + ref("fact_arbitrum_rwa_supply_by_date_and_chain"), + ref("fact_avalanche_rwa_supply_by_date_and_chain"), + ref("fact_base_rwa_supply_by_date_and_chain"), + ref("fact_mantle_rwa_supply_by_date_and_chain"), + ref("fact_optimism_rwa_supply_by_date_and_chain"), + ref("fact_polygon_rwa_supply_by_date_and_chain"), + ref("fact_ethereum_rwa_supply_by_date_and_chain"), + ref("fact_solana_rwa_supply_by_date_and_chain"), + ] + ) + }} + ) +SELECT + date + , chain + , i.symbol + , i.issuer_id + , i.issuer_friendly_name + , i.product_type + , price + , net_rwa_supply_native_change + , net_rwa_supply_usd_change + , rwa_supply_native + , rwa_supply_usd +FROM chain_metrics +left join {{ ref( "dim_rwa_product_issuer_and_type") }} i + on chain_metrics.symbol = i.symbol \ No newline at end of file diff --git a/models/staging/rwa/balances/fact_arbitrum_rwa_balances.sql b/models/staging/rwa/balances/fact_arbitrum_rwa_balances.sql new file mode 100644 index 00000000..351f809f --- /dev/null +++ b/models/staging/rwa/balances/fact_arbitrum_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("arbitrum")}} \ No newline at end of file diff --git a/models/staging/rwa/balances/fact_avalanche_rwa_balances.sql b/models/staging/rwa/balances/fact_avalanche_rwa_balances.sql new file mode 100644 index 00000000..316a93c5 --- /dev/null +++ b/models/staging/rwa/balances/fact_avalanche_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("avalanche")}} diff --git a/models/staging/rwa/balances/fact_base_rwa_balances.sql b/models/staging/rwa/balances/fact_base_rwa_balances.sql new file mode 100644 index 00000000..3d5d0714 --- /dev/null +++ b/models/staging/rwa/balances/fact_base_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("base")}} \ No newline at end of file diff --git a/models/staging/rwa/balances/fact_ethereum_rwa_balances.sql b/models/staging/rwa/balances/fact_ethereum_rwa_balances.sql new file mode 100644 index 00000000..fe90ceea --- /dev/null +++ b/models/staging/rwa/balances/fact_ethereum_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("ethereum")}} \ No newline at end of file diff --git a/models/staging/rwa/balances/fact_mantle_rwa_balances.sql b/models/staging/rwa/balances/fact_mantle_rwa_balances.sql new file mode 100644 index 00000000..b05a82c5 --- /dev/null +++ b/models/staging/rwa/balances/fact_mantle_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("mantle")}} \ No newline at end of file diff --git a/models/staging/rwa/balances/fact_optimism_rwa_balances.sql b/models/staging/rwa/balances/fact_optimism_rwa_balances.sql new file mode 100644 index 00000000..79005782 --- /dev/null +++ b/models/staging/rwa/balances/fact_optimism_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("optimism")}} diff --git a/models/staging/rwa/balances/fact_polygon_rwa_balances.sql b/models/staging/rwa/balances/fact_polygon_rwa_balances.sql new file mode 100644 index 00000000..345e0cef --- /dev/null +++ b/models/staging/rwa/balances/fact_polygon_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("polygon")}} diff --git a/models/staging/rwa/balances/fact_solana_rwa_balances.sql b/models/staging/rwa/balances/fact_solana_rwa_balances.sql new file mode 100644 index 00000000..b8ad93e2 --- /dev/null +++ b/models/staging/rwa/balances/fact_solana_rwa_balances.sql @@ -0,0 +1,9 @@ +{{ + config( + materialized="incremental", + unique_key="unique_id", + snowflake_warehouse="RWA", + ) +}} + +{{rwa_balances("solana")}} diff --git a/models/staging/rwa/fact_arbitrum_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_arbitrum_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..5b99293d --- /dev/null +++ b/models/staging/rwa/fact_arbitrum_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("arbitrum") }} diff --git a/models/staging/rwa/fact_avalanche_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_avalanche_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..d9794933 --- /dev/null +++ b/models/staging/rwa/fact_avalanche_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("avalanche") }} diff --git a/models/staging/rwa/fact_base_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_base_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..e06ff816 --- /dev/null +++ b/models/staging/rwa/fact_base_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("base") }} diff --git a/models/staging/rwa/fact_ethereum_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_ethereum_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..6cda1083 --- /dev/null +++ b/models/staging/rwa/fact_ethereum_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("ethereum") }} diff --git a/models/staging/rwa/fact_hashnote_usyc_rate.sql b/models/staging/rwa/fact_hashnote_usyc_rate.sql new file mode 100644 index 00000000..7260cebf --- /dev/null +++ b/models/staging/rwa/fact_hashnote_usyc_rate.sql @@ -0,0 +1,34 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +with raw as ( + select + date(block_timestamp) as date, + max_by(decoded_log:price::number /1e8, block_timestamp) as rate + from ethereum_flipside.core.ez_decoded_event_logs + where contract_address = lower('0x4c48bcb2160F8e0aDbf9D4F3B034f1e36d1f8b3e') + and event_name = 'BalanceReported' + group by 1 +) +, dates as ( + SELECT date FROM + pc_dbt_db.prod.dim_date_spine + WHERE date between + (SELECT MIN(date) FROM raw) + AND to_date(sysdate()) +) +, sparse as ( + SELECT + d.date, + rate + FROM dates d + LEFT JOIN raw s on d.date = s.date +) +SELECT + date, + COALESCE(rate, LAST_VALUE(rate IGNORE NULLS) OVER (ORDER BY date ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) as rate +FROM sparse \ No newline at end of file diff --git a/models/staging/rwa/fact_mantle_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_mantle_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..51885157 --- /dev/null +++ b/models/staging/rwa/fact_mantle_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("mantle") }} diff --git a/models/staging/rwa/fact_optimism_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_optimism_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..a7f08af6 --- /dev/null +++ b/models/staging/rwa/fact_optimism_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("optimism") }} diff --git a/models/staging/rwa/fact_ousg_prices.sql b/models/staging/rwa/fact_ousg_prices.sql new file mode 100644 index 00000000..907c55ee --- /dev/null +++ b/models/staging/rwa/fact_ousg_prices.sql @@ -0,0 +1,10 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +select date(hour) as date, avg(price) as price from ethereum_flipside.price.ez_prices_hourly +where symbol = 'OUSG' +group by 1 \ No newline at end of file diff --git a/models/staging/rwa/fact_polygon_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_polygon_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..c1ec17f7 --- /dev/null +++ b/models/staging/rwa/fact_polygon_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("polygon") }} diff --git a/models/staging/rwa/fact_solana_rwa_supply_by_date_and_chain.sql b/models/staging/rwa/fact_solana_rwa_supply_by_date_and_chain.sql new file mode 100644 index 00000000..3821c027 --- /dev/null +++ b/models/staging/rwa/fact_solana_rwa_supply_by_date_and_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="RWA", + ) +}} + +{{ rwa_supply_by_date_and_chain("solana") }} diff --git a/models/staging/tether/fact_tether_tvl_by_chain.sql b/models/staging/tether/fact_tether_tvl_by_chain.sql new file mode 100644 index 00000000..1f71b225 --- /dev/null +++ b/models/staging/tether/fact_tether_tvl_by_chain.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="TETHER", + ) +}} + +{{ rwa_data_by_chain_for_issuer("tether") }} \ No newline at end of file diff --git a/models/staging/tether/fact_tether_tvl_by_product.sql b/models/staging/tether/fact_tether_tvl_by_product.sql new file mode 100644 index 00000000..298bc0d6 --- /dev/null +++ b/models/staging/tether/fact_tether_tvl_by_product.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized="table", + snowflake_warehouse="TETHER", + ) +}} + +{{ rwa_data_by_product_for_issuer("tether") }}