From 673a1725a9f3940f05c4d26a181daf58d4730e89 Mon Sep 17 00:00:00 2001 From: synthquest Date: Mon, 18 Nov 2024 13:36:18 -0500 Subject: [PATCH 01/15] init solana stablecoin balances --- .../models/_sector/stablecoins/schema.yml | 30 ++++++++++ .../solana_stablecoins_balances.sql | 59 +++++++++++++++++++ .../models/_sector/stablecoins/sources.yml | 7 +++ 3 files changed, 96 insertions(+) create mode 100644 dbt_subprojects/solana/models/_sector/stablecoins/schema.yml create mode 100644 dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql create mode 100644 dbt_subprojects/solana/models/_sector/stablecoins/sources.yml diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml b/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml new file mode 100644 index 00000000000..7c7456734bc --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml @@ -0,0 +1,30 @@ +version: 2 + +models: + - name: solana_stablecoins_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" diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql new file mode 100644 index 00000000000..ca662e84840 --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql @@ -0,0 +1,59 @@ + {{ + config( + schema = 'stablecoins', + alias = 'stablecoins_balances', + materialized='incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['token_mint_address', 'token_balance_owner', 'day'], + post_hook='{{ expose_spells(\'["solana"]\', + "solana_utils", + "stablecoin", + \'["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 + 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 \ No newline at end of file diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/sources.yml b/dbt_subprojects/solana/models/_sector/stablecoins/sources.yml new file mode 100644 index 00000000000..c96a7cc200c --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/stablecoins/sources.yml @@ -0,0 +1,7 @@ +version: 2 + +sources: + - name: tokens_solana + description: "Solana tables" + tables: + - name: stablecoins \ No newline at end of file From 9f98bc271b69a6d14ee389ac5b01e3a7514a6def Mon Sep 17 00:00:00 2001 From: synthquest Date: Mon, 18 Nov 2024 13:42:56 -0500 Subject: [PATCH 02/15] update schema --- .../_sector/stablecoins/solana_stablecoins_balances.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql index ca662e84840..e75b06f9799 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql @@ -1,7 +1,7 @@ {{ config( - schema = 'stablecoins', - alias = 'stablecoins_balances', + schema = 'solana_stablecoins', + alias = 'balances', materialized='incremental', file_format = 'delta', incremental_strategy = 'merge', From 89eb889474630bc63cd477bfbb2f49682f2cb075 Mon Sep 17 00:00:00 2001 From: synthquest Date: Mon, 18 Nov 2024 13:49:37 -0500 Subject: [PATCH 03/15] fix naming --- dbt_subprojects/solana/models/_sector/stablecoins/schema.yml | 2 +- ...ablecoins_balances.sql => stablecoins_solana_balances.sql} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename dbt_subprojects/solana/models/_sector/stablecoins/{solana_stablecoins_balances.sql => stablecoins_solana_balances.sql} (97%) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml b/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml index 7c7456734bc..9ae948c8995 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml +++ b/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: solana_stablecoins_balances + - name: stablecoins_solana_balances meta: blockchain: solana contributors: [synthquest] diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql similarity index 97% rename from dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql rename to dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index e75b06f9799..f7a891ef2f2 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/solana_stablecoins_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -1,7 +1,7 @@ {{ config( - schema = 'solana_stablecoins', - alias = 'balances', + schema = 'stablecoins', + alias = 'solana_balances', materialized='incremental', file_format = 'delta', incremental_strategy = 'merge', From 9acd3cd19b94c49426937b97afc24b3ecbb61e0d Mon Sep 17 00:00:00 2001 From: synthquest Date: Mon, 18 Nov 2024 13:53:47 -0500 Subject: [PATCH 04/15] mooore name --- .../solana/models/_sector/stablecoins/{schema.yml => _schema.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dbt_subprojects/solana/models/_sector/stablecoins/{schema.yml => _schema.yml} (100%) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/schema.yml b/dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml similarity index 100% rename from dbt_subprojects/solana/models/_sector/stablecoins/schema.yml rename to dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml From de88d9030c2a1901c7b2e5e5ec2047422a53d9a8 Mon Sep 17 00:00:00 2001 From: synthquest Date: Tue, 19 Nov 2024 15:50:39 -0500 Subject: [PATCH 05/15] s --- .../models/_sector/stablecoins/stablecoins_solana_balances.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index f7a891ef2f2..9c847003789 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -8,7 +8,7 @@ unique_key = ['token_mint_address', 'token_balance_owner', 'day'], post_hook='{{ expose_spells(\'["solana"]\', "solana_utils", - "stablecoin", + "stablecoins", \'["synthquest"]\') }}') }} From fc87228586773e578a98aa85065670db3f57d231 Mon Sep 17 00:00:00 2001 From: synthquest Date: Tue, 19 Nov 2024 17:14:30 -0500 Subject: [PATCH 06/15] test --- .../stablecoins/{_schema.yml => stablecoins_solana_schema.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dbt_subprojects/solana/models/_sector/stablecoins/{_schema.yml => stablecoins_solana_schema.yml} (100%) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_schema.yml similarity index 100% rename from dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml rename to dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_schema.yml From 40c7b3e0a045e0348d1082d6b78a0d6bacd1de99 Mon Sep 17 00:00:00 2001 From: synthquest Date: Tue, 19 Nov 2024 17:17:09 -0500 Subject: [PATCH 07/15] one more test --- .../_sector/stablecoins/stablecoins_solana_balances.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index 9c847003789..2451fd358b9 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -1,7 +1,7 @@ {{ config( - schema = 'stablecoins', - alias = 'solana_balances', + schema = 'stablecoins_solana', + alias = 'balances', materialized='incremental', file_format = 'delta', incremental_strategy = 'merge', From 5ce2f67e5455d07c0745c851b0b956300be74fa0 Mon Sep 17 00:00:00 2001 From: synthquest Date: Tue, 19 Nov 2024 18:00:15 -0500 Subject: [PATCH 08/15] post fix --- .../models/_sector/stablecoins/stablecoins_solana_balances.sql | 2 +- .../solana/models/tokens/solana/tokens_solana_stablecoins.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index 2451fd358b9..1589d8bfe7d 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -7,7 +7,7 @@ incremental_strategy = 'merge', unique_key = ['token_mint_address', 'token_balance_owner', 'day'], post_hook='{{ expose_spells(\'["solana"]\', - "solana_utils", + "sector", "stablecoins", \'["synthquest"]\') }}') }} diff --git a/dbt_subprojects/solana/models/tokens/solana/tokens_solana_stablecoins.sql b/dbt_subprojects/solana/models/tokens/solana/tokens_solana_stablecoins.sql index cd8bc72c0d4..c6bafe818b9 100644 --- a/dbt_subprojects/solana/models/tokens/solana/tokens_solana_stablecoins.sql +++ b/dbt_subprojects/solana/models/tokens/solana/tokens_solana_stablecoins.sql @@ -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) From 7ecf155d8804a7818bc0ed9ceb088995557e2d23 Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 15:40:50 -0500 Subject: [PATCH 09/15] move sources to root --- .../solana/models/_sector/stablecoins/sources.yml | 7 ------- dbt_subprojects/solana/models/_sources.yml | 6 +++++- 2 files changed, 5 insertions(+), 8 deletions(-) delete mode 100644 dbt_subprojects/solana/models/_sector/stablecoins/sources.yml diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/sources.yml b/dbt_subprojects/solana/models/_sector/stablecoins/sources.yml deleted file mode 100644 index c96a7cc200c..00000000000 --- a/dbt_subprojects/solana/models/_sector/stablecoins/sources.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 - -sources: - - name: tokens_solana - description: "Solana tables" - tables: - - name: stablecoins \ No newline at end of file diff --git a/dbt_subprojects/solana/models/_sources.yml b/dbt_subprojects/solana/models/_sources.yml index 294bf600f1a..515708e25f0 100644 --- a/dbt_subprojects/solana/models/_sources.yml +++ b/dbt_subprojects/solana/models/_sources.yml @@ -39,4 +39,8 @@ sources: description: "bubblegum cNFT minting decoded tables" tables: - name: bubblegum_call_mintV1 - - name: bubblegum_call_mintToCollectionV1 \ No newline at end of file + - name: bubblegum_call_mintToCollectionV1 + - name: tokens_solana + description: "solana stablecoin token metadata" + tables: + - name: stablecoins From f1123d8bf4c10bb267bb75fff784efec37459180 Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 15:48:10 -0500 Subject: [PATCH 10/15] subfolder test --- .../{stablecoins_solana_schema.yml => solana/_schema.yml} | 0 .../stablecoins/{ => solana}/stablecoins_solana_balances.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename dbt_subprojects/solana/models/_sector/stablecoins/{stablecoins_solana_schema.yml => solana/_schema.yml} (100%) rename dbt_subprojects/solana/models/_sector/stablecoins/{ => solana}/stablecoins_solana_balances.sql (100%) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_schema.yml b/dbt_subprojects/solana/models/_sector/stablecoins/solana/_schema.yml similarity index 100% rename from dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_schema.yml rename to dbt_subprojects/solana/models/_sector/stablecoins/solana/_schema.yml diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/solana/stablecoins_solana_balances.sql similarity index 100% rename from dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql rename to dbt_subprojects/solana/models/_sector/stablecoins/solana/stablecoins_solana_balances.sql From 40f5325f5d0c250fb053c457d22db01b67fc2f28 Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 15:52:10 -0500 Subject: [PATCH 11/15] revert --- .../solana/models/_sector/stablecoins/{solana => }/_schema.yml | 0 .../stablecoins/{solana => }/stablecoins_solana_balances.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename dbt_subprojects/solana/models/_sector/stablecoins/{solana => }/_schema.yml (100%) rename dbt_subprojects/solana/models/_sector/stablecoins/{solana => }/stablecoins_solana_balances.sql (100%) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/solana/_schema.yml b/dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml similarity index 100% rename from dbt_subprojects/solana/models/_sector/stablecoins/solana/_schema.yml rename to dbt_subprojects/solana/models/_sector/stablecoins/_schema.yml diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/solana/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql similarity index 100% rename from dbt_subprojects/solana/models/_sector/stablecoins/solana/stablecoins_solana_balances.sql rename to dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql From e826db07d4757f65b772c0c5fea64eb71ddc9f80 Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 16:19:19 -0500 Subject: [PATCH 12/15] move2root --- dbt_subprojects/solana/models/_sources.yml | 4 ---- sources/_subprojects_outputs/solana/_sources.yml | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/solana/models/_sources.yml b/dbt_subprojects/solana/models/_sources.yml index 515708e25f0..33103b5f796 100644 --- a/dbt_subprojects/solana/models/_sources.yml +++ b/dbt_subprojects/solana/models/_sources.yml @@ -40,7 +40,3 @@ sources: tables: - name: bubblegum_call_mintV1 - name: bubblegum_call_mintToCollectionV1 - - name: tokens_solana - description: "solana stablecoin token metadata" - tables: - - name: stablecoins diff --git a/sources/_subprojects_outputs/solana/_sources.yml b/sources/_subprojects_outputs/solana/_sources.yml index 2390e29b3e9..c56b48950f9 100644 --- a/sources/_subprojects_outputs/solana/_sources.yml +++ b/sources/_subprojects_outputs/solana/_sources.yml @@ -7,4 +7,5 @@ sources: - name: vote_fees - name: tokens_solana tables: - - name: transfers \ No newline at end of file + - name: transfers + - name: stablecoins From 0aba8eb2ac539fbbbcb6645edf30614012a5cec2 Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 16:31:15 -0500 Subject: [PATCH 13/15] oof fix --- .../models/_sector/stablecoins/stablecoins_solana_balances.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index 1589d8bfe7d..5a70e34e6c6 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -28,7 +28,7 @@ with , 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 + inner join (select address, symbol from stablecoin_tokens) sd on sd.address = bal.token_mint_address where day > cast('2024-10-26' as timestamp) group by 1,2,3,5 ) From bbedd5cf8491b4e490a5f4b1c1e8d4612d7d5cc8 Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 16:34:57 -0500 Subject: [PATCH 14/15] table alias --- .../models/_sector/stablecoins/stablecoins_solana_balances.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index 5a70e34e6c6..948d7656c71 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -27,7 +27,7 @@ with , sd.symbol , sum(coalesce(token_balance,0)) as token_balance , token_mint_address - from {{ ref('solana_utils_daily_balances') }} + from {{ ref('solana_utils_daily_balances') }} bal inner join (select address, symbol from stablecoin_tokens) sd on sd.address = bal.token_mint_address where day > cast('2024-10-26' as timestamp) group by 1,2,3,5 From 0fa32aa405955184d83486d51558d4f1050bdbdc Mon Sep 17 00:00:00 2001 From: synthquest Date: Thu, 21 Nov 2024 16:47:22 -0500 Subject: [PATCH 15/15] 0 --- .../_sector/stablecoins/stablecoins_solana_balances.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql index 948d7656c71..ebaf87c05a7 100644 --- a/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql +++ b/dbt_subprojects/solana/models/_sector/stablecoins/stablecoins_solana_balances.sql @@ -20,7 +20,7 @@ with {{ source('tokens_solana', 'stablecoins')}} ) -, updated_balances as ( +, balance_base as ( select day , bal.token_balance_owner @@ -43,7 +43,7 @@ with 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 + , 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.day)) AS token_balance , tt.token_mint_address from time_table tt