From 40a7b1f6387fbababb7809909133ce2d5a98f116 Mon Sep 17 00:00:00 2001 From: Son Do Date: Tue, 10 Dec 2024 13:02:08 -0500 Subject: [PATCH] Added Base user analytics --- macros/wallets/get_wallet_dex_trades.sql | 3 ++- macros/wallets/get_wallet_stablecoin_data.sql | 2 +- .../{ez_address.sql => ez_base_address.sql} | 6 ++++- models/projects/base/raw/ez_base_balances.sql | 20 +++++++++++++++ .../wallets/dim_base_wallets_dex_trade.sql | 2 +- .../dim_base_wallets_stablecoin_metrics.sql | 25 +++++++++++-------- 6 files changed, 44 insertions(+), 14 deletions(-) rename models/projects/base/core/{ez_address.sql => ez_base_address.sql} (93%) create mode 100644 models/projects/base/raw/ez_base_balances.sql diff --git a/macros/wallets/get_wallet_dex_trades.sql b/macros/wallets/get_wallet_dex_trades.sql index fc62491d..bc7e1e2d 100644 --- a/macros/wallets/get_wallet_dex_trades.sql +++ b/macros/wallets/get_wallet_dex_trades.sql @@ -9,6 +9,7 @@ , count(distinct token_in) distinct_token_in , max(coalesce(amount_out_usd, amount_in_usd)) as max_dex_trade , count(distinct date(block_timestamp)) as distinct_days_traded - from select * from {{chain}}_flipside.defi.ez_dex_swaps + , count(distinct platform) distinct_dex_platforms + from {{chain}}_flipside.defi.ez_dex_swaps group by origin_from_address {% endmacro %} diff --git a/macros/wallets/get_wallet_stablecoin_data.sql b/macros/wallets/get_wallet_stablecoin_data.sql index be9822bb..90bdec06 100644 --- a/macros/wallets/get_wallet_stablecoin_data.sql +++ b/macros/wallets/get_wallet_stablecoin_data.sql @@ -1,7 +1,7 @@ {% macro get_wallet_stablecoin_metrics(chain) %} with stablecoin_transfers as ( - select * from {{chain}}.prod_raw.ez_stablecoin_transfers + select * from {{ref("ez_" ~ chain ~ "_stablecoin_transfers")}} ), -- stablecoin data generic_stablecoin_data as ( diff --git a/models/projects/base/core/ez_address.sql b/models/projects/base/core/ez_base_address.sql similarity index 93% rename from models/projects/base/core/ez_address.sql rename to models/projects/base/core/ez_base_address.sql index 76579146..4e681897 100644 --- a/models/projects/base/core/ez_address.sql +++ b/models/projects/base/core/ez_base_address.sql @@ -1,7 +1,7 @@ {{ config( materialized="table", - snowflake_warehouse="BASE", + snowflake_warehouse="BASE_MD", database="base", schema="core", alias="ez_address", @@ -91,3 +91,7 @@ full join full join {{ ref("dim_base_wallets_cex_funded") }} as cex on fundamental.address = cex.address +WHERE fundamental.address is not null + or stablecoin.address is not null + or dex.address is not null + or cex.address is not null diff --git a/models/projects/base/raw/ez_base_balances.sql b/models/projects/base/raw/ez_base_balances.sql new file mode 100644 index 00000000..da98577a --- /dev/null +++ b/models/projects/base/raw/ez_base_balances.sql @@ -0,0 +1,20 @@ +{{ + config( + materialized="incremental", + unique_key=["address", "contract_address", "block_timestamp"], + snowflake_warehouse="BASE", + database="base", + schema="core", + alias="ez_balances", + ) +}} + +select + address, + contract_address, + block_timestamp, + balance_token +from {{ref("fact_base_address_balances_by_token")}} +{% if is_incremental() %} + where block_timestamp >= dateadd('day', -7, to_date(sysdate())) +{% endif %} diff --git a/models/staging/base/wallets/dim_base_wallets_dex_trade.sql b/models/staging/base/wallets/dim_base_wallets_dex_trade.sql index a96cc1ed..32b0aac0 100644 --- a/models/staging/base/wallets/dim_base_wallets_dex_trade.sql +++ b/models/staging/base/wallets/dim_base_wallets_dex_trade.sql @@ -1,6 +1,6 @@ {{ config(materialized="table", snowflake_warehouse="BASE_MD") }} -with wallet_dex_data as ({{ get_wallet_stablecoin_metrics("base") }}) +with wallet_dex_data as ({{ get_wallet_dex_trades("base") }}) select address, number_dex_trades, diff --git a/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql b/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql index 47913379..e9242190 100644 --- a/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql +++ b/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql @@ -1,15 +1,20 @@ {{ config(materialized="table", snowflake_warehouse="BASE_MD") }} -with wallet_stablecoin_data as ({{ get_wallet_dex_trades("base") }}) +with wallet_stablecoin_data as ({{ get_wallet_stablecoin_metrics("base") }}) select address, - number_dex_trades, - distinct_pools, - total_dex_volume, - avg_dex_trade, - distinct_dex_platforms, - distint_token_out, - distinct_token_in, - max_dex_trade, - distinct_days_traded + first_stablecoin_to_address, + first_stablecoin_from_address, + avg_stablecoin_send, + avg_stablecoin_received, + top_stablecoin_to_address, + top_stablecoin_from_address, + number_of_stablecoin_transfers_txns, + number_of_stablecoin_received_txns, + unique_count_to_address, + unique_count_from_address, + first_stablecoin_transfer_date, + latest_stablecoin_transfer_date, + first_stablecoin_received_date, + latest_stablecoin_received_date from wallet_stablecoin_data