-
Notifications
You must be signed in to change notification settings - Fork 6
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
Stablecoins: Ethereum Breakdown Table #221
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3dde3d6
creating new stablecoin table
SebMelendez01 6feb076
updating to add pricing
SebMelendez01 f9f39e0
select explicitly
SebMelendez01 766de06
creating stablecoin balances
SebMelendez01 c7fb05f
update backfill code
SebMelendez01 6625e2f
finishing ethereum backfill
SebMelendez01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
132 changes: 132 additions & 0 deletions
132
macros/stablecoins/agg_daily_stablecoin_metrics_breakdown.sql
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,132 @@ | ||
{% macro agg_daily_stablecoin_metrics_breakdown(chain) %} | ||
with | ||
transfer_transactions as ( | ||
select | ||
* | ||
-- @anthony | ||
-- Can move into stablecoin transfers table if needed | ||
-- Logic is slightly different for solana tron and near | ||
-- Right now I am leaving it here so that we dont have to change the logic in the stablecoin transfers table | ||
|
||
--Average transfer volume is currently done in the API stablecoins.py with `_fetch_avg_transaction_size` | ||
, case | ||
{% if chain not in ('solana', 'tron', 'near') %} | ||
when | ||
to_address not in (select contract_address from {{ ref("dim_" ~ chain ~ "_contract_addresses") }}) | ||
and from_address not in (select contract_address from {{ ref("dim_" ~ chain ~ "_contract_addresses")}}) | ||
then 1 | ||
else 0 | ||
{% else %} | ||
when | ||
to_address in (select address from {{ ref("dim_" ~ chain ~ "_eoa_addresses") }}) | ||
and from_address in (select address from {{ ref("dim_" ~ chain ~ "_eoa_addresses") }}) | ||
then 1 | ||
else 0 | ||
{% endif %} | ||
end as is_p2p | ||
from {{ ref("fact_" ~ chain ~ "_stablecoin_transfers")}} | ||
{% if is_incremental() %} | ||
where block_timestamp >= ( | ||
select dateadd('day', -3, max(date)) | ||
from {{ this }} | ||
) | ||
{% endif %} | ||
), | ||
filtered_contracts as ( | ||
select * from pc_dbt_db.prod.dim_contracts_gold where chain = '{{ chain }}' | ||
), | ||
transfer_transactions_agg as ( | ||
select | ||
block_timestamp::date as date | ||
, transfer_transactions.from_address::string as from_address | ||
, transfer_transactions.contract_address as contract_address | ||
, transfer_transactions.symbol as symbol | ||
, sum(transfer_volume) as stablecoin_transfer_volume | ||
, sum( | ||
case | ||
when transfer_transactions.from_address is not null | ||
then 1 | ||
else 0 | ||
end | ||
) as stablecoin_daily_txns | ||
, count(distinct(to_address)) as stablecoin_dau | ||
, sum(transfer_volume * is_p2p) as p2p_stablecoin_transfer_volume | ||
, sum( | ||
case | ||
when transfer_transactions.from_address is not null and is_p2p = 1 | ||
then 1 | ||
else 0 | ||
end | ||
) as p2p_stablecoin_daily_txns | ||
, count( | ||
distinct case | ||
when is_p2p = 1 then to_address | ||
else null | ||
end | ||
) as p2p_stablecoin_dau | ||
from transfer_transactions | ||
group by 1, 2, 3, 4 | ||
), | ||
results as ( | ||
select | ||
transfer_transactions_agg.date | ||
--stablecoin idenifiers | ||
, transfer_transactions_agg.contract_address | ||
, transfer_transactions_agg.symbol as symbol | ||
--sender idenifiers | ||
, transfer_transactions_agg.from_address | ||
, filtered_contracts.name as contract_name | ||
, coalesce(filtered_contracts.name, transfer_transactions_agg.from_address) as contract | ||
, filtered_contracts.friendly_name as application | ||
, dim_apps_gold.icon as icon | ||
, filtered_contracts.app as app | ||
, filtered_contracts.category as category | ||
--metrics | ||
, coalesce(stablecoin_transfer_volume, 0) as stablecoin_transfer_volume | ||
, coalesce(stablecoin_daily_txns, 0) as stablecoin_daily_txns | ||
, coalesce(stablecoin_dau, 0) stablecoin_dau | ||
--p2p metrics | ||
, coalesce(p2p_stablecoin_transfer_volume, 0) as p2p_stablecoin_transfer_volume | ||
, coalesce(p2p_stablecoin_daily_txns, 0) as p2p_stablecoin_daily_txns | ||
, coalesce(p2p_stablecoin_dau, 0) as p2p_stablecoin_dau | ||
, '{{ chain }}' as chain | ||
from transfer_transactions_agg | ||
left join filtered_contracts | ||
on lower(transfer_transactions_agg.from_address) = lower(filtered_contracts.address) | ||
left join pc_dbt_db.prod.dim_apps_gold dim_apps_gold | ||
on filtered_contracts.app = dim_apps_gold.namespace | ||
), | ||
results_dollar_denom as ( | ||
select | ||
results.date | ||
, results.contract_address | ||
, results.symbol | ||
|
||
, from_address | ||
, contract_name | ||
, contract | ||
, application | ||
, icon | ||
, app | ||
, category | ||
, stablecoin_transfer_volume * coalesce( | ||
d.token_current_price, 1 | ||
) as stablecoin_transfer_volume | ||
, stablecoin_daily_txns | ||
, stablecoin_dau | ||
, p2p_stablecoin_transfer_volume * coalesce( | ||
d.token_current_price, 1 | ||
) as p2p_stablecoin_transfer_volume | ||
, p2p_stablecoin_daily_txns | ||
, p2p_stablecoin_dau | ||
, chain | ||
from results | ||
left join {{ ref( "fact_" ~ chain ~ "_stablecoin_contracts") }} c | ||
on lower(results.contract_address) = lower(c.contract_address) | ||
left join {{ ref( "fact_coingecko_token_realtime_data") }} d | ||
on lower(c.coingecko_id) = lower(d.token_id) | ||
) | ||
select * | ||
from results_dollar_denom | ||
where date < to_date(sysdate()) | ||
{% endmacro %} |
17 changes: 17 additions & 0 deletions
17
models/metrics/stablecoins/breakdowns/_test_agg_daily_stablecoin_breakdown_silver.yml
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,17 @@ | ||
models: | ||
- name: agg_daily_stablecoin_breakdown_silver | ||
tests: | ||
- "dbt_expectations.expect_grouped_row_values_to_have_recent_data": | ||
group_by: [CHAIN, SYMBOL] | ||
timestamp_column: "DATE" | ||
datepart: "day" | ||
interval: 2 | ||
columns: | ||
- name: "DATE" | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist | ||
- name: "CHAIN" | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_to_exist |
20 changes: 20 additions & 0 deletions
20
models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown.sql
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,20 @@ | ||
{{ config(materialized="table") }} | ||
select | ||
date | ||
, contract_address | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it appears @akan72's leading commas have become contagious i for one, support the people! SQL-fluff with leading commas coming soon |
||
, symbol | ||
, from_address | ||
, contract_name | ||
, contract | ||
, application | ||
, icon | ||
, app | ||
, category | ||
, stablecoin_transfer_volume | ||
, stablecoin_daily_txns | ||
, stablecoin_dau | ||
, p2p_stablecoin_transfer_volume | ||
, p2p_stablecoin_daily_txns | ||
, p2p_stablecoin_dau | ||
, chain | ||
from {{ ref("agg_daily_stablecoin_breakdown_silver") }} |
14 changes: 14 additions & 0 deletions
14
models/metrics/stablecoins/breakdowns/agg_daily_stablecoin_breakdown_silver.sql
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,14 @@ | ||
{{ config(materialized="table") }} | ||
with | ||
daily_data as ( | ||
{{ | ||
dbt_utils.union_relations( | ||
relations=[ | ||
ref("agg_ethereum_daily_stablecoin_metrics_breakdown"), | ||
] | ||
) | ||
}} | ||
) | ||
select *, date::string || '-' || chain || '-' || symbol || from_address || contract_address as unique_id | ||
from daily_data | ||
where date < to_date(sysdate()) |
9 changes: 9 additions & 0 deletions
9
models/staging/ethereum/agg_ethereum_daily_stablecoin_metrics_breakdown.sql
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,9 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
unique_key=["date", "symbol", "from_address"], | ||
snowflake_warehouse="BALANCES_LG", | ||
) | ||
}} | ||
|
||
{{ agg_daily_stablecoin_metrics_breakdown("ethereum") }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the big change right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this table replace
agg_chain_stablecoin_breakdown
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya plan is to use this table to power the entire stablecoin page and create a BAM for stablecoins. Still need to figure out the issue with total supply tho.