Skip to content

Commit

Permalink
Add base user data (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny77D authored Dec 10, 2024
1 parent e3ed9ac commit 53277b0
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 19 deletions.
24 changes: 12 additions & 12 deletions macros/wallets/get_wallet_dex_trades.sql
Original file line number Diff line number Diff line change
@@ -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 %}
14 changes: 7 additions & 7 deletions macros/wallets/get_wallet_stablecoin_data.sql
Original file line number Diff line number Diff line change
@@ -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
)
Expand Down
97 changes: 97 additions & 0 deletions models/projects/base/core/ez_base_address.sql
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions models/projects/base/raw/ez_base_balances.sql
Original file line number Diff line number Diff line change
@@ -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 %}
38 changes: 38 additions & 0 deletions models/staging/base/wallets/dim_base_wallets_cex_funded.sql
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions models/staging/base/wallets/dim_base_wallets_dex_trade.sql
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 53277b0

Please sign in to comment.