AN-5901/add-usdc-and-usdt-historical-xchain-supply (#100)

This commit is contained in:
Matt Romano 2025-04-15 08:35:23 -07:00 committed by GitHub
parent a0a120efae
commit 58169a7d75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 372 additions and 0 deletions

View File

@ -0,0 +1,145 @@
CHAIN,STABLECOIN_ID,SYMBOL
algorand,1,USDT
algorand,2,USDC
aptos,2,USDC
aptos,1,USDT
arbitrum,2,USDC
arbitrum,1,USDT
astar,2,USDC
astar,1,USDT
aurora,1,USDT
aurora,2,USDC
avalanche,1,USDT
avalanche,2,USDC
berachain,2,USDC
berachain,1,USDT
binance,1,USDT
binance,2,USDC
bittorrent,1,USDT
boba,2,USDC
boba,1,USDT
canto,2,USDC
canto,1,USDT
celo,1,USDT
celo,2,USDC
crab,1,USDT
crab,2,USDC
defichain,2,USDC
defichain,1,USDT
dogechain,1,USDT
dogechain,2,USDC
elrond,2,USDC
elrond,1,USDT
eos,1,USDT
ethereum,1,USDT
ethereum,2,USDC
ethereumclassic,2,USDC
ethereumclassic,1,USDT
everscale,1,USDT
everscale,2,USDC
evmos,1,USDT
evmos,2,USDC
fantom,1,USDT
fantom,2,USDC
fuse,1,USDT
fuse,2,USDC
harmony,1,USDT
heco,1,USDT
icp,1,USDT
icp,2,USDC
injective,1,USDT
injective,2,USDC
ink,2,USDC
ink,1,USDT
iotex,1,USDT
iotex,2,USDC
kardia,2,USDC
kardia,1,USDT
kava,1,USDT
kava,2,USDC
klaytn,1,USDT
klaytn,2,USDC
kucoin,2,USDC
kucoin,1,USDT
kusama,1,USDT
linea,1,USDT
linea,2,USDC
manta,2,USDC
manta,1,USDT
mantle,2,USDC
mantle,1,USDT
meter,2,USDC
meter,1,USDT
metis,1,USDT
metis,2,USDC
mixin,1,USDT
mixin,2,USDC
mode,1,USDT
mode,2,USDC
moonbeam,2,USDC
moonbeam,1,USDT
moonriver,1,USDT
moonriver,2,USDC
morph,1,USDT
morph,2,USDC
near,1,USDT
near,2,USDC
neo,1,USDT
oasis,2,USDC
oasis,1,USDT
okexchain,1,USDT
okexchain,2,USDC
ontology,1,USDT
optimism,2,USDC
optimism,1,USDT
osmosis,2,USDC
osmosis,1,USDT
polkadot,2,USDC
polkadot,1,USDT
pulse,1,USDT
pulse,2,USDC
pulsechain,1,USDT
pulsechain,2,USDC
rsk,1,USDT
rsk,2,USDC
scroll,1,USDT
scroll,2,USDC
sei,1,USDT
sei,2,USDC
shiden,1,USDT
solana,2,USDC
solana,1,USDT
stacks,1,USDT
starknet,2,USDC
starknet,1,USDT
sui,2,USDC
sui,1,USDT
sxnetwork,2,USDC
sxnetwork,1,USDT
syscoin,2,USDC
syscoin,1,USDT
taiko,2,USDC
taiko,1,USDT
telos,2,USDC
telos,1,USDT
terra,1,USDT
terra,2,USDC
tezos,1,USDT
theta,1,USDT
theta,2,USDC
thundercore,2,USDC
thundercore,1,USDT
tomochain,2,USDC
tomochain,1,USDT
ton,1,USDT
tron,2,USDC
tron,1,USDT
wanchain,2,USDC
wanchain,1,USDT
waves,1,USDT
waves,2,USDC
xdai,1,USDT
xdai,2,USDC
zilliqa,1,USDT
zircuit,2,USDC
zircuit,1,USDT
1 CHAIN STABLECOIN_ID SYMBOL
2 algorand 1 USDT
3 algorand 2 USDC
4 aptos 2 USDC
5 aptos 1 USDT
6 arbitrum 2 USDC
7 arbitrum 1 USDT
8 astar 2 USDC
9 astar 1 USDT
10 aurora 1 USDT
11 aurora 2 USDC
12 avalanche 1 USDT
13 avalanche 2 USDC
14 berachain 2 USDC
15 berachain 1 USDT
16 binance 1 USDT
17 binance 2 USDC
18 bittorrent 1 USDT
19 boba 2 USDC
20 boba 1 USDT
21 canto 2 USDC
22 canto 1 USDT
23 celo 1 USDT
24 celo 2 USDC
25 crab 1 USDT
26 crab 2 USDC
27 defichain 2 USDC
28 defichain 1 USDT
29 dogechain 1 USDT
30 dogechain 2 USDC
31 elrond 2 USDC
32 elrond 1 USDT
33 eos 1 USDT
34 ethereum 1 USDT
35 ethereum 2 USDC
36 ethereumclassic 2 USDC
37 ethereumclassic 1 USDT
38 everscale 1 USDT
39 everscale 2 USDC
40 evmos 1 USDT
41 evmos 2 USDC
42 fantom 1 USDT
43 fantom 2 USDC
44 fuse 1 USDT
45 fuse 2 USDC
46 harmony 1 USDT
47 heco 1 USDT
48 icp 1 USDT
49 icp 2 USDC
50 injective 1 USDT
51 injective 2 USDC
52 ink 2 USDC
53 ink 1 USDT
54 iotex 1 USDT
55 iotex 2 USDC
56 kardia 2 USDC
57 kardia 1 USDT
58 kava 1 USDT
59 kava 2 USDC
60 klaytn 1 USDT
61 klaytn 2 USDC
62 kucoin 2 USDC
63 kucoin 1 USDT
64 kusama 1 USDT
65 linea 1 USDT
66 linea 2 USDC
67 manta 2 USDC
68 manta 1 USDT
69 mantle 2 USDC
70 mantle 1 USDT
71 meter 2 USDC
72 meter 1 USDT
73 metis 1 USDT
74 metis 2 USDC
75 mixin 1 USDT
76 mixin 2 USDC
77 mode 1 USDT
78 mode 2 USDC
79 moonbeam 2 USDC
80 moonbeam 1 USDT
81 moonriver 1 USDT
82 moonriver 2 USDC
83 morph 1 USDT
84 morph 2 USDC
85 near 1 USDT
86 near 2 USDC
87 neo 1 USDT
88 oasis 2 USDC
89 oasis 1 USDT
90 okexchain 1 USDT
91 okexchain 2 USDC
92 ontology 1 USDT
93 optimism 2 USDC
94 optimism 1 USDT
95 osmosis 2 USDC
96 osmosis 1 USDT
97 polkadot 2 USDC
98 polkadot 1 USDT
99 pulse 1 USDT
100 pulse 2 USDC
101 pulsechain 1 USDT
102 pulsechain 2 USDC
103 rsk 1 USDT
104 rsk 2 USDC
105 scroll 1 USDT
106 scroll 2 USDC
107 sei 1 USDT
108 sei 2 USDC
109 shiden 1 USDT
110 solana 2 USDC
111 solana 1 USDT
112 stacks 1 USDT
113 starknet 2 USDC
114 starknet 1 USDT
115 sui 2 USDC
116 sui 1 USDT
117 sxnetwork 2 USDC
118 sxnetwork 1 USDT
119 syscoin 2 USDC
120 syscoin 1 USDT
121 taiko 2 USDC
122 taiko 1 USDT
123 telos 2 USDC
124 telos 1 USDT
125 terra 1 USDT
126 terra 2 USDC
127 tezos 1 USDT
128 theta 1 USDT
129 theta 2 USDC
130 thundercore 2 USDC
131 thundercore 1 USDT
132 tomochain 2 USDC
133 tomochain 1 USDT
134 ton 1 USDT
135 tron 2 USDC
136 tron 1 USDT
137 wanchain 2 USDC
138 wanchain 1 USDT
139 waves 1 USDT
140 waves 2 USDC
141 xdai 1 USDT
142 xdai 2 USDC
143 zilliqa 1 USDT
144 zircuit 2 USDC
145 zircuit 1 USDT

View File

@ -0,0 +1,56 @@
{{ config(
materialized = 'incremental',
unique_key = ['chain', 'stablecoin_id','_inserted_timestamp'],
tags = ['defillama']
) }}
WITH usdt_supply AS (
SELECT
C.chain,
1 AS stablecoin_id,
live.udf_api(
'GET',
'https://pro-api.llama.fi/{api_key}/stablecoins/stablecoincharts/' || C.chain || '?stablecoin=1',{},{},
--usdt
'Vault/prod/external/defillama'
) AS READ,
SYSDATE() AS _inserted_timestamp
FROM
{{ ref('bronze__defillama_usdt_usdc_chain_seed') }} C
WHERE
stablecoin_id = 1
),
usdc_supply AS (
SELECT
C.chain,
2 AS stablecoin_id,
live.udf_api(
'GET',
'https://pro-api.llama.fi/{api_key}/stablecoins/stablecoincharts/' || C.chain || '?stablecoin=2',{},{},
--usdc
'Vault/prod/external/defillama'
) AS READ,
SYSDATE() AS _inserted_timestamp
FROM
{{ ref('bronze__defillama_usdt_usdc_chain_seed') }} C
WHERE
stablecoin_id = 2
)
SELECT
chain,
stablecoin_id,
READ,
bytes,
_inserted_timestamp
FROM
usdt_supply
UNION ALL
SELECT
chain,
stablecoin_id,
READ,
bytes,
_inserted_timestamp
FROM
usdc_supply

View File

@ -0,0 +1,10 @@
version: 2
models:
- name: bronze__defillama_usdc_usdt_supply
columns:
- name: _INSERTED_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_NTZ

View File

@ -0,0 +1,28 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
tags = ['defillama'],
meta={
'database_tags':{
'table': {
'PROTOCOL': 'DEFILLAMA'
}
}
}
) }}
SELECT
date,
stablecoin_id,
stablecoin,
symbol,
chain,
total_bridged_usd,
total_circulating,
total_circulating_usd,
defillama_usdc_usdt_supply_id as defillama_fact_usdt_usdc_supply_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__defillama_usdt_usdc_supply') }} f

View File

@ -0,0 +1,32 @@
version: 2
models:
- name: defillama__fact_usdt_usdc_supply
description: Daily USDT and USDC supply metrics across different blockchains
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- DEFILLAMA_FACT_USDT_USDC_SUPPLY_ID
columns:
- name: DATE
description: Date of the supply data point
- name: STABLECOIN_ID
description: Unique identifier for the stablecoin from Defillama
- name: STABLECOIN
description: Name of the stablecoin
- name: SYMBOL
description: Token symbol (USDC or USDT)
- name: CHAIN
description: Blockchain network where the stablecoin is deployed
- name: TOTAL_BRIDGED_USD
description: Total value of bridged stablecoins in USD
- name: TOTAL_CIRCULATING
description: Total circulating supply of the stablecoin
- name: TOTAL_CIRCULATING_USD
description: Total circulating supply in USD value
- name: DEFILLAMA_FACT_USDT_USDC_SUPPLY_ID
description: Unique identifier for this record
- name: INSERTED_TIMESTAMP
description: Timestamp when the record was inserted
- name: MODIFIED_TIMESTAMP
description: Timestamp when the record was last modified

View File

@ -0,0 +1,83 @@
{{ config(
materialized = 'incremental',
cluster_by = 'chain',
unique_key = 'defillama_usdc_usdt_supply_id',
tags = ['defillama']
) }}
WITH base AS (
SELECT
chain,
stablecoin_id,
READ,
bytes,
_inserted_timestamp
FROM
{{ ref('bronze__defillama_usdc_usdt_supply') }}
{% if is_incremental() %}
WHERE
_inserted_timestamp > (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% endif %}
),
flattened_supply AS (
SELECT
chain,
stablecoin_id,
TO_TIMESTAMP_NTZ(
VALUE :date :: INT
) AS DATE,
VALUE :totalBridgedToUSD :peggedUSD :: FLOAT AS total_bridged_usd,
VALUE :totalCirculating :peggedUSD :: FLOAT AS total_circulating,
VALUE :totalCirculatingUSD :peggedUSD :: FLOAT AS total_circulating_usd,
_inserted_timestamp
FROM
base,
LATERAL FLATTEN(
input => READ :data
)
)
SELECT
A.date,
A.stablecoin_id,
b.stablecoin,
b.symbol,
A.chain,
A.total_bridged_usd,
A.total_circulating,
A.total_circulating_usd,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['chain','date','a.stablecoin_id']
) }} AS defillama_usdc_usdt_supply_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
flattened_supply A
LEFT JOIN {{ ref('bronze__defillama_stablecoins') }}
b
ON A.stablecoin_id = b.stablecoin_id
{% if is_incremental() %}
WHERE
DATE > (
SELECT
MAX(DATE) :: DATE
FROM
{{ this }}
)
{% endif %}
qualify ROW_NUMBER() over (
PARTITION BY A.chain,
A.date,
A.stablecoin_id
ORDER BY
A._inserted_timestamp DESC
) = 1

View File

@ -0,0 +1,18 @@
version: 2
models:
- name: silver__defillama_usdt_usdc_supply
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- DEFILLAMA_USDC_USDT_SUPPLY_ID
columns:
- name: _INSERTED_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_NTZ
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 2