This commit is contained in:
Eric Laurello 2025-07-24 08:37:06 -04:00
parent c1ec444b95
commit ec9f01baf5

View File

@ -41,7 +41,6 @@ WHERE
{% if is_incremental() %}
AND modified_timestamp >= '{{ max_mod }}'
AND block_timestamp :: DATE >= '2025-01-01'
{% endif %}
{% endset %}
@ -64,19 +63,14 @@ FROM
{% endif %}) {% endset %}
{% endif %}
{#
{% set xfer_query %}
CREATE
OR REPLACE temporary TABLE silver.ez_stable_token_flows___xfer_intermediate_tmp AS #}
WITH base AS (
WITH xfer AS (
SELECT
A.blockchain,
A.block_timestamp :: DATE AS block_date,
tx_hash,
A.address AS token_address,
from_address,
to_address,
amount_usd
SUM(
amount_usd
) AS stablecoin_transfer_volume_usd
FROM
{{ ref('silver__transfers') }} A
JOIN silver.ez_stable_token_flows__intermediate_tmp b
@ -89,62 +83,11 @@ WITH base AS (
AND A.block_timestamp :: DATE >= stbl.price_date
WHERE
{{ date_filter }}
AND to_address <> from_address
) {# {% endset %}
{% do run_query(xfer_query) %}
#},
xfer_ua AS (
SELECT
blockchain,
block_date,
tx_hash,
token_address,
from_address AS user_address,
amount_usd * -1 AS amount_usd
FROM
base {# silver.ez_stable_token_flows___xfer_intermediate_tmp #}
UNION ALL
SELECT
blockchain,
block_date,
tx_hash,
token_address,
to_address AS user_address,
amount_usd AS amount_usd
FROM
base {# silver.ez_stable_token_flows___xfer_intermediate_tmp #}
),
xfer_tx_roll AS (
SELECT
blockchain,
block_date,
tx_hash,
token_address,
user_address,
SUM(amount_usd) AS amount_usd
FROM
xfer_ua
AND amount_usd < 500000000 -- $500M cap
GROUP BY
blockchain,
block_date,
tx_hash,
token_address,
user_address
),
xfer_day_roll AS (
SELECT
blockchain,
block_date,
token_address,
SUM(
amount_usd
) AS amount_usd
FROM
xfer_tx_roll
GROUP BY
blockchain,
block_date,
token_address
A.blockchain,
A.block_timestamp :: DATE,
A.address
)
SELECT
A.blockchain,
@ -152,14 +95,14 @@ SELECT
A.token_address,
b.symbol,
COALESCE(
amount_usd,
stablecoin_transfer_volume_usd,
0
) AS stablecoin_transfer_volume_usd,
{{ dbt_utils.generate_surrogate_key(['a.blockchain','a.block_date','a.token_address']) }} AS ez_stablecoin_token_flows_daily_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp
FROM
xfer_day_roll A
xfer A
JOIN {{ ref('silver__tokens_enhanced') }}
b
ON A.blockchain = b.blockchain