Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solana Daily Stablecoin Balances #7154

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 2

models:
- name: stablecoins_solana_balances
meta:
blockchain: solana
contributors: [synthquest]
config:
tags: ['solana','stablecoin']
description: >
stablecoin address balances on Solana
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns: ['day', 'token_balance_owner', 'token_balance', 'token_mint_address']
columns:
- &day
name: day
description: "Date of balance recorded"
- &token_balance_owner
name: token_balance_owner
description: "Owner address of token addresses"
- &symbol
name: symbol
description: "Stablecoin symbol"
- &token_balance
name: token_balance
description: "Stablecoin balance of all token addresses"
- &token_mint_address
name: token_mint_address
description: "Stablecoin token address"
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{
config(
schema = 'stablecoins_solana',
alias = 'balances',
materialized='incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['token_mint_address', 'token_balance_owner', 'day'],
post_hook='{{ expose_spells(\'["solana"]\',
"sector",
"stablecoins",
\'["synthquest"]\') }}')
}}

with
stablecoin_tokens as (
select
blockchain, symbol, address, decimals
from
{{ source('tokens_solana', 'stablecoins')}}
)

, updated_balances as (
select
day
, bal.token_balance_owner
, sd.symbol
, sum(coalesce(token_balance,0)) as token_balance
, token_mint_address
from {{ ref('solana_utils_daily_balances') }}
inner join (select address, symbol from stable_definitions) sd on sd.address = bal.token_mint_address
Synthquest marked this conversation as resolved.
Show resolved Hide resolved
where day > cast('2024-10-26' as timestamp)
group by 1,2,3,5
)

, time_table as (
select distinct day, token_balance_owner, token_mint_address, symbol
FROM unnest(SEQUENCE(CAST('2021-01-30 00:00' AS TIMESTAMP), current_date, INTERVAL '1' day)) AS t(day)
cross join (select distinct token_balance_owner, token_mint_address, symbol from balance_base)
)

, final as (

select tt.day, tt.token_balance_owner
, tt.symbol
, COALESCE(nf.token_balance, last_value(nf.token_balance) IGNORE NULLS OVER (PARTITION BY tt.token_balance_owner, tt.token_mint_address ORDER BY nf.block_time)) AS token_balance
, tt.token_mint_address

from time_table tt
left join balance_base nf on nf.day = tt.day and nf.token_balance_owner = tt.token_balance_owner and nf.token_mint_address = tt.token_mint_address
{% if is_incremental() %}
WHERE {{incremental_predicate('tt.day')}} and tt.day >= cast('2024-10-26' as timestamp)
{% endif %}
order by tt.day desc, token_balance desc
)

select day, token_balance_owner, symbol, token_balance, token_mint_address
from final
order by day desc
2 changes: 1 addition & 1 deletion dbt_subprojects/solana/models/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ sources:
description: "bubblegum cNFT minting decoded tables"
tables:
- name: bubblegum_call_mintV1
- name: bubblegum_call_mintToCollectionV1
- name: bubblegum_call_mintToCollectionV1
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ from (Values
, ('solana', 'USDY','A1KLoBrKBde8Ty9qtNQUtq3C2ortoC3u7twggz7sEto6', 6,'Dollar-Pegged', 'Ondo')
, ('solana', 'ZUSD','FrBfWJ4qE5sCzKm3k3JaAtqZcXUh4LvJygDeketsrsH4', 6,'Dollar-Pegged','GMO-Z')
, ('solana', 'PAI', 'Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS', 6,'Crypto Stablecoin', 'Parrot')
, ('solana', 'USDS', 'USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA', 6, 'Hybrid Stablecoin', 'Sky Protocol')
) as t(blockchain, symbol, address, decimals, backing, name)
3 changes: 2 additions & 1 deletion sources/_subprojects_outputs/solana/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ sources:
- name: vote_fees
- name: tokens_solana
tables:
- name: transfers
- name: transfers
- name: stablecoins
Loading