From 872ba086599854ae460728d06f76297d6ec2a80b Mon Sep 17 00:00:00 2001 From: Son Do Date: Tue, 10 Dec 2024 10:53:08 -0500 Subject: [PATCH 1/2] Added Base Wallet Data --- macros/wallets/get_wallet_dex_trades.sql | 23 +++-- macros/wallets/get_wallet_stablecoin_data.sql | 14 +-- models/projects/base/core/ez_address.sql | 93 +++++++++++++++++++ .../wallets/dim_base_wallets_cex_funded.sql | 38 ++++++++ .../wallets/dim_base_wallets_dex_trade.sql | 15 +++ .../dim_base_wallets_fundamental_metrics.sql | 21 +++++ .../dim_base_wallets_stablecoin_metrics.sql | 15 +++ 7 files changed, 200 insertions(+), 19 deletions(-) create mode 100644 models/projects/base/core/ez_address.sql create mode 100644 models/staging/base/wallets/dim_base_wallets_cex_funded.sql create mode 100644 models/staging/base/wallets/dim_base_wallets_dex_trade.sql create mode 100644 models/staging/base/wallets/dim_base_wallets_fundamental_metrics.sql create mode 100644 models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql diff --git a/macros/wallets/get_wallet_dex_trades.sql b/macros/wallets/get_wallet_dex_trades.sql index 99de77c3..fc62491d 100644 --- a/macros/wallets/get_wallet_dex_trades.sql +++ b/macros/wallets/get_wallet_dex_trades.sql @@ -1,15 +1,14 @@ {% macro get_wallet_dex_trades(chain) %} select - origin_from_address as address, - count(*) number_dex_trades, - count(distinct pool_name) distinct_pools, - sum(amount_in_usd) total_dex_volume, - avg(amount_in_usd) avg_dex_trade, - count(distinct platform) distinct_dex_platforms, - count(distinct token_out) distint_token_out, - count(distinct token_in) distinct_token_in, - max(amount_in_usd) max_dex_trade, - count(distinct date(block_timestamp)) distinct_days_traded - from flipside_{{ chain }}.silver_dex.complete_dex_swaps - group by 1 + origin_from_address as address + , count(distinct tx_hash) as number_dex_trades + , count(distinct pool_name) as distinct_pools + , sum(coalesce(amount_out_usd, amount_in_usd)) as total_dex_volume + , avg(coalesce(amount_out_usd, amount_in_usd)) as avg_dex_trade + , count(distinct token_out) distint_token_out + , 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 + 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 60fd167e..be9822bb 100644 --- a/macros/wallets/get_wallet_stablecoin_data.sql +++ b/macros/wallets/get_wallet_stablecoin_data.sql @@ -1,32 +1,32 @@ {% macro get_wallet_stablecoin_metrics(chain) %} with stablecoin_transfers as ( - select * from fact_{{ chain }}_stablecoin_transfers + select * from {{chain}}.prod_raw.ez_stablecoin_transfers ), -- stablecoin data generic_stablecoin_data as ( select - from_address as address, + from_address::text as address, avg(amount) as avg_stablecoin_send, - mode(to_address) as top_stablecoin_to_address, + mode(to_address)::text as top_stablecoin_to_address, count(*) as number_of_stablecoin_transfers_txns, count(distinct to_address) as unique_count_to_address, min(block_timestamp) as first_stablecoin_transfer_date, max(block_timestamp) as latest_stablecoin_transfer_date, - min_by(to_address, block_timestamp) as first_stablecoin_to_address + min_by(to_address, block_timestamp)::text as first_stablecoin_to_address from stablecoin_transfers group by from_address ), generic_stablecoin_received as ( select - to_address as address, + to_address::text as address, avg(amount) as avg_stablecoin_received, - mode(from_address) as top_stablecoin_from_address, + mode(from_address)::text as top_stablecoin_from_address, count(*) as number_of_stablecoin_received_txns, count(distinct from_address) as unique_count_from_address, min(block_timestamp) as first_stablecoin_received_date, max(block_timestamp) as latest_stablecoin_received_date, - min_by(from_address, block_timestamp) as first_stablecoin_from_address + min_by(from_address, block_timestamp)::text as first_stablecoin_from_address from stablecoin_transfers group by to_address ) diff --git a/models/projects/base/core/ez_address.sql b/models/projects/base/core/ez_address.sql new file mode 100644 index 00000000..76579146 --- /dev/null +++ b/models/projects/base/core/ez_address.sql @@ -0,0 +1,93 @@ +{{ + config( + materialized="table", + snowflake_warehouse="BASE", + database="base", + schema="core", + alias="ez_address", + ) +}} + +select + coalesce(fundamental.address, stablecoin.address, dex.address, cex.address) as address, + app_used, + category_used, + total_gas_spent_usd, + total_gas_spent_native, + total_txns, + distinct_to_address, + latest_transaction_timestamp, + first_transaction_timestamp, + first_app, + top_app, + top_to_address, + first_native_transfer, + first_native_received, + first_bridge_used, + top_from_address, + first_from_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, + indodax_transfer_amt, + simpleswap_transfer_amt, + hotbit_transfer_amt, + mexc_transfer_amt, + bitso_transfer_amt, + bitget_transfer_amt, + catex_transfer_amt, + coindcx_transfer_amt, + coinbase_transfer_amt, + swissborg_transfer_amt, + btse_transfer_amt, + cryptocom_transfer_amt, + maskex_transfer_amt, + woonetwork_transfer_amt, + lbank_transfer_amt, + mxc_transfer_amt, + gateio_transfer_amt, + fixedfloat_transfer_amt, + bitfinex_transfer_amt, + maicoin_transfer_amt, + phemex_transfer_amt, + bingx_transfer_amt, + bitbee_transfer_amt, + bybit_transfer_amt, + binance_transfer_amt, + bitbank_transfer_amt, + juno_transfer_amt, + okx_transfer_amt, + cumberland_transfer_amt, + kraken_transfer_amt, + huobi_transfer_amt, + bilaxy_transfer_amt, + 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 {{ ref("dim_base_wallets_fundamental_metrics") }} as fundamental +full join + {{ ref("dim_base_wallets_stablecoin_metrics") }} as stablecoin + on fundamental.address = stablecoin.address +full join + {{ ref("dim_base_wallets_dex_trade") }} as dex + on fundamental.address = dex.address +full join + {{ ref("dim_base_wallets_cex_funded") }} as cex + on fundamental.address = cex.address diff --git a/models/staging/base/wallets/dim_base_wallets_cex_funded.sql b/models/staging/base/wallets/dim_base_wallets_cex_funded.sql new file mode 100644 index 00000000..a1b63ae1 --- /dev/null +++ b/models/staging/base/wallets/dim_base_wallets_cex_funded.sql @@ -0,0 +1,38 @@ +{{ config(materialized="table", snowflake_warehouse="BASE_MD") }} + +with wallet_cex_data as ({{ get_wallet_cex_amount_funded("base") }}) +select + address, + indodax_transfer_amt, + simpleswap_transfer_amt, + hotbit_transfer_amt, + mexc_transfer_amt, + bitso_transfer_amt, + bitget_transfer_amt, + catex_transfer_amt, + coindcx_transfer_amt, + coinbase_transfer_amt, + swissborg_transfer_amt, + btse_transfer_amt, + cryptocom_transfer_amt, + maskex_transfer_amt, + woonetwork_transfer_amt, + lbank_transfer_amt, + mxc_transfer_amt, + gateio_transfer_amt, + fixedfloat_transfer_amt, + bitfinex_transfer_amt, + maicoin_transfer_amt, + phemex_transfer_amt, + bingx_transfer_amt, + bitbee_transfer_amt, + bybit_transfer_amt, + binance_transfer_amt, + bitbank_transfer_amt, + juno_transfer_amt, + okx_transfer_amt, + cumberland_transfer_amt, + kraken_transfer_amt, + huobi_transfer_amt, + bilaxy_transfer_amt +from wallet_cex_data diff --git a/models/staging/base/wallets/dim_base_wallets_dex_trade.sql b/models/staging/base/wallets/dim_base_wallets_dex_trade.sql new file mode 100644 index 00000000..a96cc1ed --- /dev/null +++ b/models/staging/base/wallets/dim_base_wallets_dex_trade.sql @@ -0,0 +1,15 @@ +{{ config(materialized="table", snowflake_warehouse="BASE_MD") }} + +with wallet_dex_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 +from wallet_dex_data diff --git a/models/staging/base/wallets/dim_base_wallets_fundamental_metrics.sql b/models/staging/base/wallets/dim_base_wallets_fundamental_metrics.sql new file mode 100644 index 00000000..e1e72c31 --- /dev/null +++ b/models/staging/base/wallets/dim_base_wallets_fundamental_metrics.sql @@ -0,0 +1,21 @@ +{{ config(materialized="table", snowflake_warehouse="BASE_MD") }} +with wallet_fundamental_data as ({{ get_wallet_fundamental_metrics("base") }}) +select + address, + app_used, + category_used, + total_gas_spent_usd, + total_gas_spent_native, + total_txns, + distinct_to_address, + latest_transaction_timestamp, + first_transaction_timestamp, + first_app, + top_app, + top_to_address, + first_native_transfer, + first_native_received, + first_bridge_used, + top_from_address, + first_from_address +from wallet_fundamental_data diff --git a/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql b/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql new file mode 100644 index 00000000..47913379 --- /dev/null +++ b/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql @@ -0,0 +1,15 @@ +{{ config(materialized="table", snowflake_warehouse="BASE_MD") }} + +with wallet_stablecoin_data as ({{ get_wallet_dex_trades("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 +from wallet_stablecoin_data From 40a7b1f6387fbababb7809909133ce2d5a98f116 Mon Sep 17 00:00:00 2001 From: Son Do Date: Tue, 10 Dec 2024 13:02:08 -0500 Subject: [PATCH 2/2] 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