diff --git a/macros/wallets/get_wallet_dex_trades.sql b/macros/wallets/get_wallet_dex_trades.sql index 99de77c3..bc7e1e2d 100644 --- a/macros/wallets/get_wallet_dex_trades.sql +++ b/macros/wallets/get_wallet_dex_trades.sql @@ -1,15 +1,15 @@ {% 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 + , 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 60fd167e..90bdec06 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 {{ref("ez_" ~ chain ~ "_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_base_address.sql b/models/projects/base/core/ez_base_address.sql new file mode 100644 index 00000000..4e681897 --- /dev/null +++ b/models/projects/base/core/ez_base_address.sql @@ -0,0 +1,97 @@ +{{ + config( + materialized="table", + snowflake_warehouse="BASE_MD", + 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 +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_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..32b0aac0 --- /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_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_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..e9242190 --- /dev/null +++ b/models/staging/base/wallets/dim_base_wallets_stablecoin_metrics.sql @@ -0,0 +1,20 @@ +{{ config(materialized="table", snowflake_warehouse="BASE_MD") }} + +with wallet_stablecoin_data as ({{ get_wallet_stablecoin_metrics("base") }}) +select + address, + 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