Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Artemis-xyz/dbt into featur…
Browse files Browse the repository at this point in the history
…e/add_sso_setup_to_dbt_profile
  • Loading branch information
akan72 committed Dec 19, 2024
2 parents bd062c5 + 60c45eb commit 2a25670
Show file tree
Hide file tree
Showing 31 changed files with 622 additions and 0 deletions.
82 changes: 82 additions & 0 deletions macros/solana_utils/get_solana_token_mints_burns_transfers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{% macro get_solana_token_mints_burns_transfers(token_address) %}
-- mints
SELECT
m.block_timestamp,
m.tx_id,
m.block_id,
index,
inner_index,
'mint' as action,
m.mint,
m.token_account as tx_to_account,
null as tx_from_account,
m.mint_amount as amount_native,
m.mint_authority as token_authority,
fact_token_mint_actions_id as unique_id
from
solana_flipside.defi.fact_token_mint_actions m
where
1 = 1
and mint = '{{ token_address }}'
{% if is_incremental() %}
and block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% else %}
and block_timestamp >= '2022-11-01'
{% endif %}


union all

-- transfers
SELECT
tf.block_timestamp,
tf.tx_id,
tf.block_id,
SPLIT_PART(index, '.', 1) as index,
COALESCE(NULLIF(SPLIT_PART(index, '.', 2), ''), 0) as inner_index,
'transfer' as action,
tf.mint,
tf.tx_to as tx_to_account,
tf.tx_from as tx_from_account,
tf.amount as amount_native,
null as token_authority,
fact_transfers_id as unique_id
from
solana_flipside.core.fact_transfers tf
where
1 = 1
and mint = '{{ token_address }}'
{% if is_incremental() %}
and block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% else %}
and block_timestamp >= '2022-11-01'
{% endif %}

union all

-- burns
SELECT
b.block_timestamp,
b.tx_id,
b.block_id,
index,
inner_index,
'burn' as action,
b.mint,
null as tx_to_account,
b.token_account as tx_from_account,
b.burn_amount as amount_native,
b.burn_authority as token_authority,
fact_token_burn_actions_id as unique_id
from
solana_flipside.defi.fact_token_burn_actions b
where
1 = 1
and mint = '{{ token_address }}'
{% if is_incremental() %}
and block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% else %}
and block_timestamp >= '2022-11-01'
{% endif %}

{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{config(materialized='table')}}
-- BLOCKBUSTER
-- DORA THE EXPLORER
-- OLD MACDONALD
-- SOLANA TRENCH WARRIOR
select from_address as address, app, count(distinct tx_hash) as interactions
from {{ref('ez_base_transactions')}}
where block_timestamp > '2023-12-31' and app is not null
group by 1, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{config(materialized='table')}}

-- BOB THE BUILDER
select from_address as address, count(distinct to_address) as contract_deployments
from base_flipside.core.fact_traces
where type in ('CREATE', 'CREATE2')
and block_timestamp > '2023-12-31'
group by 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{config(materialized='table')}}

-- BOTEMUS PRIME
select block_timestamp::date as date, from_address as address, count(distinct tx_hash) as daily_interactions
from {{ ref('ez_base_transactions') }}
where block_timestamp > '2023-12-31'
group by 1, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{config(materialized='table')}}
-- BOOMER
select from_address as address, array_agg(distinct symbol) as symbols, max(stablecoin_supply) as max_stablecoin_supply
from {{ref('ez_base_stablecoin_metrics_by_address')}}
where date > '2023-12-31'
group by 1
26 changes: 26 additions & 0 deletions models/artemis_wrapped/aggregate/agg_base_tokens_held.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{config(materialized='table')}}
--WOLF OF WALLSTREET
--RUGGED RAT
with
tokens as (
select contract_address, symbol
from (
values
('0x4ed4e862860bed51a9570b96d89af5e1b0efefed', 'DEGEN')
, ('0x52b492a33e447cdb854c7fc19f1e57e8bfa1777d', 'PEPE')
, ('0xb1a03eda10342529bbf8eb700a06c60441fef25d', 'MIGGLES')
, ('0xac1bd2486aaf3b5c0fc3fd868558b082a531b2b4', 'TOSHI')
, ('0x9a26f5433671751c3276a065f57e5a02d2817973', 'KEYCAT')
, ('0x2f20cf3466f80a5f7f532fca553c8cbc9727fef6', 'AKUMA')
, ('0xfad8cb754230dbfd249db0e8eccb5142dd675a0d', 'AEROBUD')
, ('0x23a96680ccde03bd4bdd9a3e9a0cb56a5d27f7c9', 'HENLO')
, ('0x6921b130d297cc43754afba22e5eac0fbf8db75b', 'DOGINME')
, ('0x768be13e1680b5ebe0024c42c896e3db59ec0149', 'SKI')
, ('0x532f27101965dd16442e59d40670faf5ebb142e4', 'BRETT')
) as t(contract_address, symbol)
)
select lower(address) as address, symbol, min(block_timestamp) as first_seen, coalesce(max(block_timestamp), sysdate()) as last_interaction_timestamp
from {{ ref('fact_base_address_balances_by_token') }} t
inner join tokens on lower(t.contract_address) = lower(tokens.contract_address)
where block_timestamp > '2023-12-31'
group by 1, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{config(materialized='table', snowflake_warehouse='BALANCES_LG')}}

select value as address, app, count(distinct tx_hash) as interactions
from {{ref('ez_solana_transactions')}},
lateral flatten(input => signers)
where block_timestamp > '2023-12-31' and app is not null
group by 1, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{config(materialized='table')}}

select instruction:parsed:info:account::string as address, count(*) as contract_deployments
from solana_flipside.core.fact_events
where program_id = 'BPFLoaderUpgradeab1e11111111111111111111111'
group by 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{config(materialized='table', snowflake_warehouse='BALANCES_LG')}}

select block_timestamp::date as date, value as address, count(distinct tx_hash) as daily_interactions
from {{ ref('ez_solana_transactions') }},
lateral flatten(input => signers)
where block_timestamp > '2023-12-31'
group by 1, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{config(materialized='table')}}

select from_address as address, array_agg(distinct symbol) as symbols, max(stablecoin_supply) as max_stablecoin_supply
from {{ref('ez_solana_stablecoin_metrics_by_address')}}
where date > '2023-12-31'
group by 1
35 changes: 35 additions & 0 deletions models/artemis_wrapped/aggregate/agg_solana_tokens_held.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{config(materialized='table')}}
--WOLF OF WALLSTREET
--RUGGED RAT
with
tokens as (
select contract_address, symbol
from (
values
('DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', 'BONK')
, ('EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm', 'WIF')
, ('2qEHjDLDLbuBgRYvsxhc5D6uDWAivNFZGan56P1tpump', 'PNUT')
, ('7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr', 'POPCAT')
, ('9BB6NFEcjBCtnNLFko2FqVQBq8HHM13kCyYcdQbgpump', 'FARTCOIN')
, ('HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC', 'AI16Z')
, ('CzLSujWBLFsSjncfkh59rUFqvafWcY5tzedWJSuypump', 'GOAT')
, ('MEW1gQWJ3nEXg2qgERiKu7FAFj79PHvQVREQUzScPP5', 'MEW')
, ('63LfDmNb3MQ8mw9MtZ2To9bEA2M71kZUUGq5tiJxcqj9', 'GIGA')
, ('ukHH6c7mMyiWCf1b9pnWe25TSpkDDt3H5pQZgZ74J82', 'BOME')
, ('GJAFwWjJ3vnTsrQVabjBVK2TYB1YtRCQXRDfDgUnpump', 'ACT')
, ('8x5VqbHA8D7NkD52uNuS5nnt3PwA8pLD34ymskeSo2Wn', 'ZEREBRO')
, ('ED5nyyWEzpPPiWimP8vYm7sD7TD3LAt3Q3gRTWHzPJBY', 'MOODENG')
, ('Df6yfrKC8kZE3KNkrHERKzAetSxbrWeniQfyJY4Jpump', 'CHILLGUY')
, ('A8C3xuqscfmyLrte3VmTqrAq8kgMASius9AFNANwpump', 'FWOG')


, ('4GFe6MBDorSy5bLbiUMrgETr6pZcjyfxMDm5ehSgpump', 'HAWKTUAH')
, ('3an8rhdepsLCya22af7qDBKPbdomw8K4iCHXaA2Gpump', 'QUANT')

) as t(contract_address, symbol)
)
select lower(address) as address, symbol, min(block_timestamp) as first_seen, coalesce(max(block_timestamp), sysdate()) as last_interaction_timestamp
from {{ ref('fact_solana_address_balances_by_token') }} t
inner join tokens on lower(t.contract_address) = lower(tokens.contract_address)
where block_timestamp > '2023-12-31'
group by 1, 2
54 changes: 54 additions & 0 deletions models/artemis_wrapped/dim_artemis_wrapped.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{config(materialized='table')}}
with
categories as (
select
coalesce(
block_buster.address
, bob_the_builder.address
, botimus_prime.address
, terminally_based.address
, wolf_of_wallstreet.address
, dora_the_explorer.address
, old_mcdonald.address
, boomer.address
) as address
, coalesce(
block_buster.category
, bob_the_builder.category
, botimus_prime.category
, terminally_based.category
, wolf_of_wallstreet.category
, dora_the_explorer.category
, old_mcdonald.category
, boomer.category
) as category
, coalesce(
block_buster.reason::string
, bob_the_builder.reason::string
, botimus_prime.reason::string
, terminally_based.reason::string
, ARRAY_TO_STRING(wolf_of_wallstreet.reason, ', ')
, dora_the_explorer.reason::string
, ARRAY_TO_STRING(old_mcdonald.reason, ', ')
, ARRAY_TO_STRING(boomer.reason, ', ')
) as reason
from {{ref('dim_blockbuster')}} block_buster
full outer join {{ref('dim_bob_the_builder')}} bob_the_builder using(address)
full outer join {{ref('dim_botimus_prime')}} botimus_prime using(address)
full outer join {{ref('dim_terminally_based')}} terminally_based using(address)
full outer join {{ref('dim_wolf_of_wallstreet')}} wolf_of_wallstreet using(address)
full outer join {{ref('dim_dora_the_explorer')}} dora_the_explorer using(address)
full outer join {{ref('dim_old_mcdonald')}} old_mcdonald using(address)
full outer join {{ref('dim_boomer')}} boomer using(address)
)

select
wrapped.address
, coalesce(category, 'NORMIE') as category
, reason
, total_txns
, total_gas_paid
, days_onchain
, apps_used
from {{ref('agg_artemis_wrapped_metrics')}} wrapped
left join categories on lower(wrapped.address) = lower(categories.address)
13 changes: 13 additions & 0 deletions models/artemis_wrapped/dim_blockbuster.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{config(materialized='table')}}

select lower(address) as address, 'THE_BLOCKBUSTER' as category, count(distinct app) as reason
from {{ ref('agg_base_app_interactions') }}
group by 1
having reason > 20

union all

select lower(address) as address, 'THE_BLOCKBUSTER' as category, count(distinct app) as reason
from {{ ref('agg_solana_app_interactions') }}
group by 1
having reason > 20
11 changes: 11 additions & 0 deletions models/artemis_wrapped/dim_bob_the_builder.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{config(materialized='table')}}

select lower(address) as address, 'BOB_THE_BUIDLER' as category, contract_deployments as reason
from {{ ref('agg_base_contract_deployments') }}
where contract_deployments > 5

union all

select lower(address) as address, 'BOB_THE_BUIDLER' as category, contract_deployments as reason
from {{ ref('agg_solana_contract_deployments') }}
where contract_deployments > 5
9 changes: 9 additions & 0 deletions models/artemis_wrapped/dim_boomer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{config(materialized='table')}}

select lower(address) as address, 'BOOMER' as category, symbols as reason
from {{ ref('agg_base_stablecoin_classification')}}

union all

select lower(address) as address, 'BOOMER' as category, symbols as reason
from {{ ref('agg_solana_stablecoin_classification')}}
14 changes: 14 additions & 0 deletions models/artemis_wrapped/dim_botimus_prime.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{config(materialized='table')}}

select lower(address) as address, 'BOTIMUS_PRIME' as category, count(distinct date) as reason
from {{ref('agg_base_daily_interactions')}}
where daily_interactions > 1000
group by 1

union all


select lower(address) as address, 'BOTIMUS_PRIME' as category, count(distinct date) as reason
from {{ref('agg_solana_daily_interactions')}}
where daily_interactions > 1000
group by 1
11 changes: 11 additions & 0 deletions models/artemis_wrapped/dim_dora_the_explorer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{config(materialized='table')}}

select lower(address) as address, 'DORA_THE_EXPLORER' as category, count(distinct app) as reason
from {{ ref('agg_base_app_interactions')}}
group by 1
having reason >= 3 and reason <= 20
union all
select lower(address) as address, 'DORA_THE_EXPLORER' as category, count(distinct app) as reason
from {{ ref('agg_solana_app_interactions')}}
group by 1
having reason >= 3 and reason <= 20
13 changes: 13 additions & 0 deletions models/artemis_wrapped/dim_old_mcdonald.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{config(materialized='table')}}

select lower(address) as address, 'OLD_MCDONALD' as category, array_agg(distinct app) as reason
from {{ ref('agg_base_app_interactions') }}
where app in ('aave', 'uniswap', 'aerodrome', 'sushiswap') and interactions > 5
group by 1

union all

select lower(address) as address, 'OLD_MCDONALD' as category, array_agg(distinct app) as reason
from {{ ref('agg_solana_app_interactions') }}
where app in ('jupiter', 'drift', 'magic_eden', 'kamino', 'selenium') and interactions > 5
group by 1
8 changes: 8 additions & 0 deletions models/artemis_wrapped/dim_rugged_rat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{config(materialized='table')}}

select lower(address) as address, 'RUGGED_RAT' as category, array_agg(distinct symbol) as reason
from {{ ref('agg_solana_tokens_held') }}
where
(symbol = 'HAWKTUAH' and first_seen <= '2024-11-26')
or (symbol = 'QUANT' and first_seen < '2024-11-21')
group by 1
8 changes: 8 additions & 0 deletions models/artemis_wrapped/dim_solana_trench_warrior.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{config(materialized='table')}}


select lower(address) as address, 'SOLANA_TRENCH_WARRIOR' as category, sum(interactions) as reason
from {{ ref('agg_solana_app_interactions') }}
where app in ('pumpdotfun', 'raydium')
group by 1
having reason > 300
7 changes: 7 additions & 0 deletions models/artemis_wrapped/dim_terminally_based.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{config(materialized='table')}}


select lower(address) as address, 'TERMINALLY_ONBASE' as category, count(distinct date) as reason
from {{ ref('agg_base_daily_interactions')}}
group by 1
having reason > 100
Loading

0 comments on commit 2a25670

Please sign in to comment.