Skip to content

Commit

Permalink
[branch repeat] [swell] adding daily balances table of core swell ass…
Browse files Browse the repository at this point in the history
…ets (#7246)

* fuck it we ball ?

* dont think the previous incremental balled

* trying to fix seed testing

* lets try this

* adding core asset balances

* fix unique key

* testing single seed

* adding more seeds

* [to be reverted] try testing only missing tokens

* revert

* adding missing swell assets to tokens_ethereum_erc20

* fix earnBTC decimals

* add dependancy warning

* add seed for earnAssets and rSWELL

---------

Co-authored-by: 0xRob <[email protected]>
  • Loading branch information
darvinrio and 0xRobin authored Dec 16, 2024
1 parent 0805218 commit aa33d8d
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dbt_macros/shared/balances_incremental_subset_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

@NOTICE this macro constructs the address level token balances table for given input table
@NOTICE aka, you give lists of tokens and/or address, it generates table with daily balances of the address-token pair

@WARN this macro has a dependancy on erc20.tokens.
@WARN if your token is not in the default list, manually add it via spellbook/dbt_subprojects/tokens/models/tokens/<chain>/tokens_<chain>_erc20.sql

@PARAM blockchain -- blockchain name
@PARAM address_list -- must have an address column, can be none if only filtering on tokens
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{
config(
schema = 'swell_balances_ethereum',
alias = 'core_assets',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['day', 'wallet_address', 'token_address'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')],
post_hook='{{ expose_spells(\'["ethereum"]\',
"project",
"swell",
\'["maybeYonas"]\') }}'
)
}}

with
tokens as (
select * from (values
(0xf951E335afb289353dc249e82926178EaC7DEd78, 'swETH', 'Swell LRT'),
(0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0, 'rswETH', 'Swell LRT'),
(0x0a6E7Ba5042B38349e437ec6Db6214AEC7B35676, 'SWELL', 'Swell LRT'),
(0x358d94b5b2F147D741088803d932Acb566acB7B6, 'rSWELL', 'Swell LRT'),
(0x9Ed15383940CC380fAEF0a75edacE507cC775f22, 'earnETH', 'Swell LRT'),
(0x66E47E6957B85Cf62564610B76dD206BB04d831a, 'earnBTC', 'Swell LRT'),
(0x8DB2350D78aBc13f5673A411D4700BCF87864dDE, 'swBTC', 'Swell LRT')
) as t(
token_address,
symbol,
name
)
),
balances as (
{{
balances_incremental_subset_daily(
blockchain = 'ethereum',
token_list = 'tokens',
start_date = '2023-04-12'
)
}}
)

select
-- t.name,
b.blockchain,
b.day,
b.address as wallet_address,
b.token_symbol,
b.token_address,
b.token_standard,
b.token_id,
b.balance,
b.balance_usd,
b.last_updated,
b.next_update
from balances b
-- left join tokens t
-- on b.token_address = t.token_address
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: 2

models:
- name: swell_balances_ethereum_core_assets

meta:
blockchain: ethereum
project: swell
contributors: maybeYonas

config:
tags: ['swell', 'restaking', 'lrt', 'lst', 'vaults', 'balances']
description: "balances of swell asset holders"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- wallet_address
- token_address
- check_seed:
seed_file: ref('swell_balances_ethereum_core_assets_seed')
match_columns:
- blockchain
- day
- wallet_address
- token_address
check_columns:
- balance
- last_updated
columns:
- &blockchain
name: blockchain
description: "blockchain"
- &day
name: day
description: "date on which the token balance is logged"
- &wallet_address
name: wallet_address
description: "wallet address of the holder"
- &token_symbol
name: token_symbol
description: "token symbol"
- &token_address
name: token_address
description: "token address"
- &token_standard
name: token_standard
description: "standard of the token (erc20)"
- &token_id
name: token_id
description: "ID of the token"
- &balance
name: balance
description: "asset balance of the wallet"
- &balance_usd
name: balance_usd
description: "usd value of token balance of the wallet"
- &last_updated
name: last_updated
description: "UTC timestamp when balance was last updated"
- &next_update
name: next_update
description: "UTC timestamp when balance is next updated"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

seeds:
- name: swell_balances_ethereum_core_assets_seed
config:
column_types:
blockchain: varchar
day: timestamp
wallet_address: varbinary
token_address: varbinary
balance: double
last_updated: timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blockchain,day,wallet_address,token_address,balance,last_updated
ethereum,2024-08-13 00:00:00.000 UTC,0x4589Ef5d52a152C25Daa513cF43b1389Bd1f3C00,0xf951E335afb289353dc249e82926178EaC7DEd78,0.004752378895635013,2024-02-29 00:00:00.000 UTC
ethereum,2024-12-04 00:00:00.000 UTC,0xaf1ec97ea59e9052ee563e4265c39291c020e3dd,0x0a6e7ba5042b38349e437ec6db6214aec7b35676,1074.616281,2024-11-08 00:00:00.000 UTC
ethereum,2024-12-05 00:00:00.000 UTC,0x841ea52b74c94420a61d41ba790e710e1af8ee0a,0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0,0.050121577326075153,2024-11-24 00:00:00.000 UTC
ethereum,2024-08-13 00:00:00.000 UTC,0xfee2d4498085581dde097b9924e4e3544682d767,0x8db2350d78abc13f5673a411d4700bcf87864dde,0.04096165,2024-08-13 00:00:00.000 UTC
ethereum,2024-12-04 00:00:00.000 UTC,0xbdD5d655ad781FB9929BFe515EB4A50090444C21,0x9Ed15383940CC380fAEF0a75edacE507cC775f22,89.828941195874851394,2024-11-08 00:00:00.000 UTC
ethereum,2024-12-01 00:00:00.000 UTC,0x84a6a7c0674A3AA03e09c026600cb46181821f07,0x66E47E6957B85Cf62564610B76dD206BB04d831a,1,2024-11-25 00:00:00.000 UTC
ethereum,2024-12-04 00:00:00.000 UTC,0x22aA3f5D1daFfe1a9DF298e79a0CF2f98C1b92FF,0x358d94b5b2F147D741088803d932Acb566acB7B6,278707.960865665406065408,2024-12-02 00:00:00.000 UTC

0 comments on commit aa33d8d

Please sign in to comment.