mirror of
https://github.com/FlipsideCrypto/fsc-evm.git
synced 2026-02-06 11:56:43 +00:00
Merge branch 'main' of github.com:FlipsideCrypto/fsc-evm into DAT2-192/upgrade-dbt-version-1.10
This commit is contained in:
commit
ed6bf5b32b
@ -58,7 +58,7 @@ jobs:
|
|||||||
git checkout -B docs origin/main
|
git checkout -B docs origin/main
|
||||||
|
|
||||||
- name: generate dbt docs
|
- name: generate dbt docs
|
||||||
run: dbt docs generate -t prod --exclude "fsc_evm,tag:streamline" "fsc_evm,tag:scores"
|
run: dbt docs generate -t prod --select "$PROJECT_NAME.*" "fsc_evm,tag:core" "fsc_evm,tag:prices" "fsc_evm,tag:labels" "fsc_evm,tag:balances" "fsc_evm,tag:decoded_logs" "fsc_evm,tag:abis" "fsc_evm,tag:defi" "fsc_evm,tag:stats"
|
||||||
|
|
||||||
- name: move files to docs directory
|
- name: move files to docs directory
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
19
data/curated/contract_reads/silver_reads__etherfi_seed.csv
Normal file
19
data/curated/contract_reads/silver_reads__etherfi_seed.csv
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
contract_address,address,token_address,function_name,function_sig,chain,attribution
|
||||||
|
0xab7590cee3ef1a863e9a5877fbb82d9be11504da,null,0x0000000000000000000000000000000000000000,categoryTVL,0x820a1175,optimism,ethereum
|
||||||
|
0x86b5780b606940eb59a062aa85a07959518c0161,null,0x7189fb5b6504bbff6a852b13b7b82a3c118fdc27,totalSupply,0x18160ddd,arbitrum,arbitrum
|
||||||
|
0x86b5780b606940eb59a062aa85a07959518c0161,null,0x6c240dda6b5c336df09a4d011139beaaa1ea2aa2,totalSupply,0x18160ddd,base,base
|
||||||
|
0x86b5780b606940eb59a062aa85a07959518c0161,null,0xfe0c30065b384f05761f15d0cc899d4f9f9cc0eb,totalSupply,0x18160ddd,ethereum,ethereum
|
||||||
|
0x939778d83b46b456224a33fb59630b11dec56663,null,null,totalSupply,0x18160ddd,ethereum,ethereum
|
||||||
|
0x6329004e903b7f420245e7af3f355186f2432466,null,0x0000000000000000000000000000000000000000,getTvl,0xd075dd42,optimism,ethereum
|
||||||
|
0x8236a87084f8b84306f72007f36f2618a5634494,0xd4e20eca1f996dab35883dc0ad5e3428af888d45,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,0x2260fac5e5542a773aa44fbcfedf7c193bc2c599,balanceOf,0x70a08231,arbitrum,ethereum
|
||||||
|
0x8236a87084f8b84306f72007f36f2618a5634494,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0xecac9c5f704e954931349da37f60e39f515c11c1,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,0x8236a87084f8b84306f72007f36f2618a5634494,balanceOf,0x70a08231,base,ethereum
|
||||||
|
0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,base,ethereum
|
||||||
|
0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,arbitrum,ethereum
|
||||||
|
0x468c34703f6c648ccf39dbab11305d17c70ba011,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0x9c0823d3a1172f9ddf672d438dec79c39a64f448,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0x126d4dbf752aaf61f3eaada24ab0db84fecf6891,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0x971e5b5d4baa5607863f3748febf287c7bf82618,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
0x2260fac5e5542a773aa44fbcfedf7c193bc2c599,0x657e8c867d8b37dcc18fa4caead9c45eb088c642,null,balanceOf,0x70a08231,ethereum,ethereum
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
chain,token_address,mixer_address
|
||||||
|
ethereum,0x0000000000000000000000000000000000000000,0x12d66f87a04a9e220743712ce6d9bb1b5616b8fc
|
||||||
|
ethereum,0x0000000000000000000000000000000000000000,0x47ce0c6ed5b0ce3d3a51fdb1c52dc66a7c3c2936
|
||||||
|
ethereum,0x0000000000000000000000000000000000000000,0x910cbd523d972eb0a6f4cae4618ad62622b39dbf
|
||||||
|
ethereum,0x0000000000000000000000000000000000000000,0xa160cdab225685da1d56aa342ad8841c3b53f291
|
||||||
|
ethereum,0x6b175474e89094c44da98b954eedeac495271d0f,0xd4b88df4d29f5cedd6857912842cff3b20c8cfa3
|
||||||
|
ethereum,0x6b175474e89094c44da98b954eedeac495271d0f,0xfd8610d20aa15b7b2e3be39b396a1bc3516c7144
|
||||||
|
ethereum,0x6b175474e89094c44da98b954eedeac495271d0f,0x07687e702b410fa43f4cb4af7fa097918ffd2730
|
||||||
|
ethereum,0x6b175474e89094c44da98b954eedeac495271d0f,0x23773e65ed146a459791799d01336db287f25334
|
||||||
|
ethereum,0xdac17f958d2ee523a2206206994597c13d831ec7,0x169ad27a470d064dede56a2d3ff727986b15d52b
|
||||||
|
ethereum,0xdac17f958d2ee523a2206206994597c13d831ec7,0x0836222f2b2b24a3f36f98668ed8f0b38d1a872f
|
||||||
|
ethereum,0xdac17f958d2ee523a2206206994597c13d831ec7,0xf67721a2d8f736e75a49fdd7fad2e31d8676542a
|
||||||
|
ethereum,0xdac17f958d2ee523a2206206994597c13d831ec7,0x9ad122c22b14202b4490edaf288fdb3c7cb3ff5e
|
||||||
|
ethereum,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xd96f2b1c14db8458374d9aca76e26c3d18364307
|
||||||
|
ethereum,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0x4736dcf1b7a3d580672cce6e7c65cd5cc9cfba9d
|
||||||
|
ethereum,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xd691f27f38b395864ea86cfc7253969b409c362d
|
||||||
|
ethereum,0x2260fac5e5542a773aa44fbcfedf7c193bc2c599,0x178169b423a011fff22b9e3f3abea13414ddd0f1
|
||||||
|
ethereum,0x2260fac5e5542a773aa44fbcfedf7c193bc2c599,0x610b717796ad172b316836ac95a2ffad065ceab4
|
||||||
|
ethereum,0x2260fac5e5542a773aa44fbcfedf7c193bc2c599,0xbb93e510bbcd0b7beb5a853875f9ec60275cf498
|
||||||
|
ethereum,0x5d3a536e4d6dbd6114cc1ead35777bab948e3643,0x22aaa7720ddd5388a3c0a3333430953c68f1849b
|
||||||
|
ethereum,0x5d3a536e4d6dbd6114cc1ead35777bab948e3643,0x03893a7c7463ae47d46bc7f091665f1893656003
|
||||||
|
ethereum,0x5d3a536e4d6dbd6114cc1ead35777bab948e3643,0x2717c5e28cf931547b621a5dddb772ab6a35b701
|
||||||
|
ethereum,0x5d3a536e4d6dbd6114cc1ead35777bab948e3643,0xd21be7248e0197ee08e0c20d4a96debdac3d20af
|
||||||
|
bsc,0x0000000000000000000000000000000000000000,0x84443cfd09a48af6ef360c6976c5392ac5023a1f
|
||||||
|
bsc,0x0000000000000000000000000000000000000000,0xd47438c816c9e7f2e2888e060936a499af9582b3
|
||||||
|
bsc,0x0000000000000000000000000000000000000000,0x330bdfade01ee9bf63c209ee33102dd334618e0a
|
||||||
|
bsc,0x0000000000000000000000000000000000000000,0x1e34a77868e19a6647b1f2f47b51ed72dede95dd
|
||||||
|
polygon,0x0000000000000000000000000000000000000000,0x1e34a77868e19a6647b1f2f47b51ed72dede95dd
|
||||||
|
polygon,0x0000000000000000000000000000000000000000,0xdf231d99ff8b6c6cbf4e9b9a945cbacef9339178
|
||||||
|
polygon,0x0000000000000000000000000000000000000000,0xaf4c0b70b2ea9fb7487c7cbb37ada259579fe040
|
||||||
|
polygon,0x0000000000000000000000000000000000000000,0xa5c2254e4253490c54cef0a4347fddb8f75a4998
|
||||||
|
optimism,0x0000000000000000000000000000000000000000,0x84443cfd09a48af6ef360c6976c5392ac5023a1f
|
||||||
|
optimism,0x0000000000000000000000000000000000000000,0xd47438c816c9e7f2e2888e060936a499af9582b3
|
||||||
|
optimism,0x0000000000000000000000000000000000000000,0x330bdfade01ee9bf63c209ee33102dd334618e0a
|
||||||
|
optimism,0x0000000000000000000000000000000000000000,0x1e34a77868e19a6647b1f2f47b51ed72dede95dd
|
||||||
|
arbitrum,0x0000000000000000000000000000000000000000,0x84443cfd09a48af6ef360c6976c5392ac5023a1f
|
||||||
|
arbitrum,0x0000000000000000000000000000000000000000,0xd47438c816c9e7f2e2888e060936a499af9582b3
|
||||||
|
arbitrum,0x0000000000000000000000000000000000000000,0x330bdfade01ee9bf63c209ee33102dd334618e0a
|
||||||
|
arbitrum,0x0000000000000000000000000000000000000000,0x1e34a77868e19a6647b1f2f47b51ed72dede95dd
|
||||||
|
gnosis,0x0000000000000000000000000000000000000000,0x1e34a77868e19a6647b1f2f47b51ed72dede95dd
|
||||||
|
gnosis,0x0000000000000000000000000000000000000000,0xdf231d99ff8b6c6cbf4e9b9a945cbacef9339178
|
||||||
|
gnosis,0x0000000000000000000000000000000000000000,0xaf4c0b70b2ea9fb7487c7cbb37ada259579fe040
|
||||||
|
gnosis,0x0000000000000000000000000000000000000000,0xa5c2254e4253490c54cef0a4347fddb8f75a4998
|
||||||
|
avax,0x0000000000000000000000000000000000000000,0x330bdfade01ee9bf63c209ee33102dd334618e0a
|
||||||
|
avax,0x0000000000000000000000000000000000000000,0x1e34a77868e19a6647b1f2f47b51ed72dede95dd
|
||||||
|
avax,0x0000000000000000000000000000000000000000,0xaf8d1839c3c67cf571aa74b5c12398d4901147b3
|
||||||
|
ethereumclassic,0x0000000000000000000000000000000000000000,0x2f56d5afc058b8734350b162efee75ee48f034e0
|
||||||
|
ethereumclassic,0x0000000000000000000000000000000000000000,0x59fcb629a23e8ed0a60a0188771e221042260118
|
||||||
|
ethereumclassic,0x0000000000000000000000000000000000000000,0x784b3a7a7981b959bd8d9d9e73c2013be819fbf2
|
||||||
|
28
macros/curated_package/unverify_contract_reads.sql
Normal file
28
macros/curated_package/unverify_contract_reads.sql
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{% macro unverify_contract_reads() %}
|
||||||
|
{% if var('HEAL_MODEL', false) and is_incremental() %}
|
||||||
|
DELETE FROM {{ this }} t
|
||||||
|
WHERE t.metadata:verified_check_enabled::STRING = 'true'
|
||||||
|
AND (
|
||||||
|
(
|
||||||
|
t.metadata:token0::STRING IS NOT NULL
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM {{ ref('price__ez_asset_metadata') }} v
|
||||||
|
WHERE v.is_verified
|
||||||
|
AND v.token_address IS NOT NULL
|
||||||
|
AND v.token_address = t.metadata:token0::STRING
|
||||||
|
)
|
||||||
|
)
|
||||||
|
OR (
|
||||||
|
t.metadata:token1::STRING IS NOT NULL
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM {{ ref('price__ez_asset_metadata') }} v
|
||||||
|
WHERE v.is_verified
|
||||||
|
AND v.token_address IS NOT NULL
|
||||||
|
AND v.token_address = t.metadata:token1::STRING
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
32
macros/curated_package/unverify_tvl.sql
Normal file
32
macros/curated_package/unverify_tvl.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{% macro unverify_tvl() %}
|
||||||
|
{% if var('HEAL_MODEL', false) and is_incremental() %}
|
||||||
|
-- Only target platforms that use verified_check_enabled
|
||||||
|
-- Delete rows that are invalid in BOTH v2 and v3/v4 styles
|
||||||
|
DELETE FROM {{ this }} t
|
||||||
|
WHERE EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM {{ ref('streamline__contract_reads_records') }}
|
||||||
|
WHERE metadata:verified_check_enabled::STRING = 'true'
|
||||||
|
AND platform = t.platform
|
||||||
|
) --necessary for the complete_tvl model
|
||||||
|
AND
|
||||||
|
-- Not valid in v2 style (address as pool)
|
||||||
|
NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM {{ ref('streamline__contract_reads_records') }} r
|
||||||
|
WHERE r.metadata:verified_check_enabled::STRING = 'true'
|
||||||
|
AND r.address IS NULL
|
||||||
|
AND r.contract_address = t.address
|
||||||
|
)
|
||||||
|
AND
|
||||||
|
-- Not valid in v3/v4 style (token-address combo)
|
||||||
|
NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM {{ ref('streamline__contract_reads_records') }} r
|
||||||
|
WHERE r.metadata:verified_check_enabled::STRING = 'true'
|
||||||
|
AND r.address IS NOT NULL
|
||||||
|
AND r.contract_address = t.contract_address
|
||||||
|
AND r.address = t.address
|
||||||
|
);
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
@ -23,7 +23,7 @@
|
|||||||
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['radiant-v2','radiant-v1'],
|
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['radiant-v2','radiant-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['hashflow-v1','gmx-v1','woofi-v3','woofi-v1'],
|
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['hashflow-v1','gmx-v1','woofi-v3','woofi-v1'],
|
||||||
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['trader_joe-v2','kyberswap-v1','kyberswap-v2','zyberswap-v2','fraxswap-v1'],
|
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['trader_joe-v2','kyberswap-v1','kyberswap-v2','zyberswap-v2','fraxswap-v1'],
|
||||||
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['hyperliquid-v1','across-v2','multichain-v7','symbiosis-v1','hop-v1'],
|
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['hyperliquid-v1','across-v2','multichain-v7','symbiosis-v1','hop-v1','everclear-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
||||||
'uniswap': {
|
'uniswap': {
|
||||||
'v2': {
|
'v2': {
|
||||||
|
|||||||
@ -22,8 +22,8 @@
|
|||||||
'CUSTOM_GHA_SCHEDULED_DEXALOT_MAIN_CRON': '5 * * * *',
|
'CUSTOM_GHA_SCHEDULED_DEXALOT_MAIN_CRON': '5 * * * *',
|
||||||
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['aave-v2'],
|
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['aave-v2'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['gmx-v1','hashflow-v1','woofi-v1'],
|
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['gmx-v1','hashflow-v1','woofi-v1'],
|
||||||
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['pharaoh-v1','kyberswap-v2','curve-v1','uniswap-v2','kyberswap-v1','fraxswap-v1'],
|
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['pharaoh-v1','kyberswap-v2','curve-v1','uniswap-v2','kyberswap-v1','fraxswap-v1','pharaoh-v2'],
|
||||||
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['symbiosis-v1','multichain-v7','allbridge-v1'],
|
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['symbiosis-v1','multichain-v7','allbridge-v1','everclear-v1','eywa-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
||||||
'arena_trade': {
|
'arena_trade': {
|
||||||
'v1': {
|
'v1': {
|
||||||
|
|||||||
@ -26,11 +26,14 @@
|
|||||||
'MAIN_OBSERV_EXCLUSION_LIST_ENABLED': true,
|
'MAIN_OBSERV_EXCLUSION_LIST_ENABLED': true,
|
||||||
'MAIN_SL_TOKEN_READS_BRONZE_TABLE_ENABLED': true,
|
'MAIN_SL_TOKEN_READS_BRONZE_TABLE_ENABLED': true,
|
||||||
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['silo-v1','aave-v1','flux-v1','aave-v2','aave-v2.1','sturdy-v1','silo-v2'],
|
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['silo-v1','aave-v1','flux-v1','aave-v2','aave-v2.1','sturdy-v1','silo-v2'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['hashflow-v1','pancakeswap-v2','synthetix-v1'],
|
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['hashflow-v1','pancakeswap-v2','synthetix-v1','uniswap-v1'],
|
||||||
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['kyberswap-v2'],
|
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['kyberswap-v2','uniswap-v1'],
|
||||||
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['ronin_axie_bridge-v1','multichain-v7','symbiosis-v1','axie_infinity-v2','across-v2','near_rainbow_bridge-v1','hop-v1'],
|
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['ronin_axie_bridge-v1','multichain-v7','symbiosis-v1','axie_infinity-v2','across-v1','near_rainbow_bridge-v1','hop-v1','everclear-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
||||||
'uniswap': {
|
'uniswap': {
|
||||||
|
'v1': {
|
||||||
|
'factory': '0xc0a47dfe034b400b47bdad5fecda2621de6c4d95'
|
||||||
|
},
|
||||||
'v2': {
|
'v2': {
|
||||||
'uni_v2_pair_created': '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f'
|
'uni_v2_pair_created': '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f'
|
||||||
},
|
},
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
'MAIN_GHA_SCHEDULED_SCORES_CRON': '50 5 * * *',
|
'MAIN_GHA_SCHEDULED_SCORES_CRON': '50 5 * * *',
|
||||||
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['morpho-v1'],
|
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['morpho-v1'],
|
||||||
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['squidswap-v1'],
|
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['squidswap-v1'],
|
||||||
|
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['everclear-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
||||||
'uniswap': {
|
'uniswap': {
|
||||||
'v2': {
|
'v2': {
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['granary-v1','sonne-v1'],
|
'CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST': ['granary-v1','sonne-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['woofi-v1','hashflow-v1'],
|
'CURATED_DEFI_DEX_SWAPS_RECENCY_EXCLUSION_LIST': ['woofi-v1','hashflow-v1'],
|
||||||
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['fraxswap-v1','kyberswap-v2','sushiswap-v1','uniswap-v2'],
|
'CURATED_DEFI_DEX_LP_ACTIONS_RECENCY_EXCLUSION_LIST': ['fraxswap-v1','kyberswap-v2','sushiswap-v1','uniswap-v2'],
|
||||||
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['eywa-v1','across-v2','meson-v1','symbiosis-v1','multichain-v7','hop-v1'],
|
'CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST': ['eywa-v1','across-v2','meson-v1','symbiosis-v1','multichain-v7','hop-v1','everclear-v1'],
|
||||||
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
'CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING': {
|
||||||
'uniswap': {
|
'uniswap': {
|
||||||
'v2': {
|
'v2': {
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
'GLOBAL_NODE_PROVIDER': 'flipside',
|
'GLOBAL_NODE_PROVIDER': 'flipside',
|
||||||
'GLOBAL_NODE_URL': "{URL}",
|
'GLOBAL_NODE_URL': "{URL}",
|
||||||
'GLOBAL_NODE_VAULT_PATH': 'vault/prod/evm/flipside/somnia/mainnet',
|
'GLOBAL_NODE_VAULT_PATH': 'vault/prod/evm/flipside/somnia/mainnet',
|
||||||
|
'GLOBAL_ALT_NODE_ENABLED': true,
|
||||||
|
'GLOBAL_ALT_NODE_VAULT_PATH': 'vault/prod/evm/ankr/somnia/mainnet',
|
||||||
'GLOBAL_WRAPPED_NATIVE_ASSET_ADDRESS': '0x046ede9564a72571df6f5e44d0405360c0f4dcab',
|
'GLOBAL_WRAPPED_NATIVE_ASSET_ADDRESS': '0x046ede9564a72571df6f5e44d0405360c0f4dcab',
|
||||||
'GLOBAL_WRAPPED_NATIVE_ASSET_SYMBOL': 'WSOMI',
|
'GLOBAL_WRAPPED_NATIVE_ASSET_SYMBOL': 'WSOMI',
|
||||||
'GLOBAL_NATIVE_ASSET_SYMBOL': 'SOMI',
|
'GLOBAL_NATIVE_ASSET_SYMBOL': 'SOMI',
|
||||||
|
|||||||
@ -19,6 +19,8 @@
|
|||||||
{% set ns.GLOBAL_NODE_VAULT_PATH = get_var('GLOBAL_NODE_VAULT_PATH', '') %}
|
{% set ns.GLOBAL_NODE_VAULT_PATH = get_var('GLOBAL_NODE_VAULT_PATH', '') %}
|
||||||
{% set ns.GLOBAL_NETWORK = get_var('GLOBAL_NETWORK', 'mainnet') %}
|
{% set ns.GLOBAL_NETWORK = get_var('GLOBAL_NETWORK', 'mainnet') %}
|
||||||
{% set ns.GLOBAL_START_BLOCK = get_var('GLOBAL_START_BLOCK', 0) %}
|
{% set ns.GLOBAL_START_BLOCK = get_var('GLOBAL_START_BLOCK', 0) %}
|
||||||
|
{% set ns.GLOBAL_ALT_NODE_ENABLED = get_var('GLOBAL_ALT_NODE_ENABLED', false) %}
|
||||||
|
{% set ns.GLOBAL_ALT_NODE_VAULT_PATH = get_var('GLOBAL_ALT_NODE_VAULT_PATH', '') %}
|
||||||
|
|
||||||
{% set ns.GLOBAL_BRONZE_FR_ENABLED = none if get_var('GLOBAL_BRONZE_FR_ENABLED', false) else false %} {# Sets to none if true, still requires --full-refresh, otherwise will use incremental #}
|
{% set ns.GLOBAL_BRONZE_FR_ENABLED = none if get_var('GLOBAL_BRONZE_FR_ENABLED', false) else false %} {# Sets to none if true, still requires --full-refresh, otherwise will use incremental #}
|
||||||
{% set ns.GLOBAL_SILVER_FR_ENABLED = none if get_var('GLOBAL_SILVER_FR_ENABLED', false) else false %}
|
{% set ns.GLOBAL_SILVER_FR_ENABLED = none if get_var('GLOBAL_SILVER_FR_ENABLED', false) else false %}
|
||||||
@ -281,16 +283,18 @@
|
|||||||
{% set ns.CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST = get_var('CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST', []) %}
|
{% set ns.CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST = get_var('CURATED_DEFI_BRIDGE_RECENCY_EXCLUSION_LIST', []) %}
|
||||||
{% set ns.CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST = get_var('CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST', []) %}
|
{% set ns.CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST = get_var('CURATED_DEFI_LENDING_RECENCY_EXCLUSION_LIST', []) %}
|
||||||
|
|
||||||
{# SL Stablecoin Reads Variables #}
|
{# SL Contract Reads Variables #}
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_REALTIME_SQL_LIMIT = get_var('CURATED_SL_STABLECOIN_READS_REALTIME_SQL_LIMIT', 3000) %}
|
{% set ns.CURATED_SL_CONTRACT_READS_START_DATE = get_var('CURATED_SL_CONTRACT_READS_START_DATE', '2025-06-10') %}
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_REALTIME_PRODUCER_BATCH_SIZE = get_var('CURATED_SL_STABLECOIN_READS_REALTIME_PRODUCER_BATCH_SIZE', 1500) %}
|
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_REALTIME_WORKER_BATCH_SIZE = get_var('CURATED_SL_STABLECOIN_READS_REALTIME_WORKER_BATCH_SIZE', 500) %}
|
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_REALTIME_ASYNC_CONCURRENT_REQUESTS = get_var('CURATED_SL_STABLECOIN_READS_REALTIME_ASYNC_CONCURRENT_REQUESTS', 5) %}
|
|
||||||
|
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_HISTORY_SQL_LIMIT = get_var('CURATED_SL_STABLECOIN_READS_HISTORY_SQL_LIMIT', 20000) %}
|
{% set ns.CURATED_SL_CONTRACT_READS_REALTIME_SQL_LIMIT = get_var('CURATED_SL_CONTRACT_READS_REALTIME_SQL_LIMIT', 12000000) %}
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_HISTORY_PRODUCER_BATCH_SIZE = get_var('CURATED_SL_STABLECOIN_READS_HISTORY_PRODUCER_BATCH_SIZE', 1500) %}
|
{% set ns.CURATED_SL_CONTRACT_READS_REALTIME_PRODUCER_BATCH_SIZE = get_var('CURATED_SL_CONTRACT_READS_REALTIME_PRODUCER_BATCH_SIZE', 240000) %}
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_HISTORY_WORKER_BATCH_SIZE = get_var('CURATED_SL_STABLECOIN_READS_HISTORY_WORKER_BATCH_SIZE', 500) %}
|
{% set ns.CURATED_SL_CONTRACT_READS_REALTIME_WORKER_BATCH_SIZE = get_var('CURATED_SL_CONTRACT_READS_REALTIME_WORKER_BATCH_SIZE', 60000) %}
|
||||||
{% set ns.CURATED_SL_STABLECOIN_READS_HISTORY_ASYNC_CONCURRENT_REQUESTS = get_var('CURATED_SL_STABLECOIN_READS_HISTORY_ASYNC_CONCURRENT_REQUESTS', 5) %}
|
{% set ns.CURATED_SL_CONTRACT_READS_REALTIME_ASYNC_CONCURRENT_REQUESTS = get_var('CURATED_SL_CONTRACT_READS_REALTIME_ASYNC_CONCURRENT_REQUESTS', 10) %}
|
||||||
|
|
||||||
|
{% set ns.CURATED_SL_CONTRACT_READS_HISTORY_SQL_LIMIT = get_var('CURATED_SL_CONTRACT_READS_HISTORY_SQL_LIMIT', 12000000) %}
|
||||||
|
{% set ns.CURATED_SL_CONTRACT_READS_HISTORY_PRODUCER_BATCH_SIZE = get_var('CURATED_SL_CONTRACT_READS_HISTORY_PRODUCER_BATCH_SIZE', 600000) %}
|
||||||
|
{% set ns.CURATED_SL_CONTRACT_READS_HISTORY_WORKER_BATCH_SIZE = get_var('CURATED_SL_CONTRACT_READS_HISTORY_WORKER_BATCH_SIZE', 60000) %}
|
||||||
|
{% set ns.CURATED_SL_CONTRACT_READS_HISTORY_ASYNC_CONCURRENT_REQUESTS = get_var('CURATED_SL_CONTRACT_READS_HISTORY_ASYNC_CONCURRENT_REQUESTS', 10) %}
|
||||||
|
|
||||||
{# Curated Bridge Variables #}
|
{# Curated Bridge Variables #}
|
||||||
{% set ns.CURATED_DEFI_BRIDGE_CONTRACT_MAPPING = get_var('CURATED_DEFI_BRIDGE_CONTRACT_MAPPING', {}) %}
|
{% set ns.CURATED_DEFI_BRIDGE_CONTRACT_MAPPING = get_var('CURATED_DEFI_BRIDGE_CONTRACT_MAPPING', {}) %}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
],
|
],
|
||||||
merge_exclude_columns = ["inserted_timestamp"],
|
merge_exclude_columns = ["inserted_timestamp"],
|
||||||
full_refresh = vars.GLOBAL_GOLD_FR_ENABLED,
|
full_refresh = vars.GLOBAL_GOLD_FR_ENABLED,
|
||||||
tags = ['gold','balances','erc20','heal','phase_4']
|
tags = ['gold','balances','erc20','heal','curated_daily','phase_4']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
WITH balances AS (
|
WITH balances AS (
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
merge_exclude_columns = ["inserted_timestamp"],
|
merge_exclude_columns = ["inserted_timestamp"],
|
||||||
post_hook = "{{ unverify_balances() }}",
|
post_hook = "{{ unverify_balances() }}",
|
||||||
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
||||||
tags = ['silver','balances','erc20','heal','phase_4']
|
tags = ['silver','balances','erc20','heal','curated_daily','phase_4']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
@ -87,7 +87,12 @@ SELECT
|
|||||||
'x-fsc-livequery', 'true'
|
'x-fsc-livequery', 'true'
|
||||||
),
|
),
|
||||||
'method', 'POST',
|
'method', 'POST',
|
||||||
'secret_name', '{{ vars.GLOBAL_NODE_VAULT_PATH }}',
|
'secret_name',
|
||||||
|
{% if vars.GLOBAL_ALT_NODE_ENABLED %}
|
||||||
|
'{{ vars.GLOBAL_ALT_NODE_VAULT_PATH }}'
|
||||||
|
{% else %}
|
||||||
|
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
||||||
|
{% endif %},
|
||||||
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
||||||
) AS request
|
) AS request
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -89,7 +89,12 @@ SELECT
|
|||||||
'x-fsc-livequery', 'true'
|
'x-fsc-livequery', 'true'
|
||||||
),
|
),
|
||||||
'method', 'POST',
|
'method', 'POST',
|
||||||
'secret_name', '{{ vars.GLOBAL_NODE_VAULT_PATH }}',
|
'secret_name',
|
||||||
|
{% if vars.GLOBAL_ALT_NODE_ENABLED %}
|
||||||
|
'{{ vars.GLOBAL_ALT_NODE_VAULT_PATH }}'
|
||||||
|
{% else %}
|
||||||
|
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
||||||
|
{% endif %},
|
||||||
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
||||||
) AS request
|
) AS request
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(address)",
|
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(address)",
|
||||||
merge_exclude_columns = ["inserted_timestamp"],
|
merge_exclude_columns = ["inserted_timestamp"],
|
||||||
full_refresh = vars.GLOBAL_GOLD_FR_ENABLED,
|
full_refresh = vars.GLOBAL_GOLD_FR_ENABLED,
|
||||||
tags = ['gold','balances','native','phase_4']
|
tags = ['gold','balances','native','curated_daily','phase_4']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
WITH balances AS (
|
WITH balances AS (
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
incremental_predicates = ["dynamic_range", "block_number"],
|
incremental_predicates = ["dynamic_range", "block_number"],
|
||||||
merge_exclude_columns = ["inserted_timestamp"],
|
merge_exclude_columns = ["inserted_timestamp"],
|
||||||
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
||||||
tags = ['silver','balances','native','phase_4']
|
tags = ['silver','balances','native','curated_daily','phase_4']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
@ -77,7 +77,12 @@ SELECT
|
|||||||
'x-fsc-livequery', 'true'
|
'x-fsc-livequery', 'true'
|
||||||
),
|
),
|
||||||
'method', 'POST',
|
'method', 'POST',
|
||||||
'secret_name', '{{ vars.GLOBAL_NODE_VAULT_PATH }}',
|
'secret_name',
|
||||||
|
{% if vars.GLOBAL_ALT_NODE_ENABLED %}
|
||||||
|
'{{ vars.GLOBAL_ALT_NODE_VAULT_PATH }}'
|
||||||
|
{% else %}
|
||||||
|
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
||||||
|
{% endif %},
|
||||||
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
||||||
) AS request
|
) AS request
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -79,7 +79,12 @@ SELECT
|
|||||||
'x-fsc-livequery', 'true'
|
'x-fsc-livequery', 'true'
|
||||||
),
|
),
|
||||||
'method', 'POST',
|
'method', 'POST',
|
||||||
'secret_name', '{{ vars.GLOBAL_NODE_VAULT_PATH }}',
|
'secret_name',
|
||||||
|
{% if vars.GLOBAL_ALT_NODE_ENABLED %}
|
||||||
|
'{{ vars.GLOBAL_ALT_NODE_VAULT_PATH }}'
|
||||||
|
{% else %}
|
||||||
|
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
||||||
|
{% endif %},
|
||||||
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
||||||
) AS request
|
) AS request
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -51,7 +51,7 @@ tx_fees AS (
|
|||||||
)
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
),
|
),
|
||||||
native_transfers_snapshot AS (
|
native_records_snapshot AS (
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT
|
DISTINCT
|
||||||
('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE AS block_date,
|
('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE AS block_date,
|
||||||
@ -80,8 +80,20 @@ native_transfers_snapshot AS (
|
|||||||
tx_fees
|
tx_fees
|
||||||
WHERE
|
WHERE
|
||||||
block_timestamp :: DATE <= ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
block_timestamp :: DATE <= ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
||||||
|
{% if not is_incremental() %}
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE AS block_date,
|
||||||
|
address
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__balances_validator_addresses_daily')}} b
|
||||||
|
GROUP BY
|
||||||
|
address
|
||||||
|
HAVING MIN(b.block_date) <= ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
||||||
|
{% endif %}
|
||||||
),
|
),
|
||||||
native_transfers_history AS (
|
native_records_history AS (
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT
|
DISTINCT
|
||||||
block_timestamp :: DATE AS block_date,
|
block_timestamp :: DATE AS block_date,
|
||||||
@ -110,11 +122,28 @@ native_transfers_history AS (
|
|||||||
tx_fees
|
tx_fees
|
||||||
WHERE
|
WHERE
|
||||||
block_date > ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
block_date > ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
||||||
),
|
|
||||||
all_transfers AS (
|
|
||||||
SELECT * FROM native_transfers_snapshot
|
|
||||||
UNION
|
UNION
|
||||||
SELECT * FROM native_transfers_history
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
block_date,
|
||||||
|
address
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__balances_validator_addresses_daily')}}
|
||||||
|
WHERE
|
||||||
|
block_date > ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
all_records AS (
|
||||||
|
SELECT * FROM native_records_snapshot
|
||||||
|
UNION
|
||||||
|
SELECT * FROM native_records_history
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
block_date,
|
block_date,
|
||||||
@ -124,6 +153,6 @@ SELECT
|
|||||||
SYSDATE() AS modified_timestamp,
|
SYSDATE() AS modified_timestamp,
|
||||||
'{{ invocation_id }}' AS _invocation_id
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
FROM
|
FROM
|
||||||
all_transfers qualify (ROW_NUMBER() over (PARTITION BY balances_native_daily_records_id
|
all_records qualify (ROW_NUMBER() over (PARTITION BY balances_native_daily_records_id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
modified_timestamp DESC)) = 1
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
{# Set up dbt configuration #}
|
||||||
|
{{ config (
|
||||||
|
materialized = "incremental",
|
||||||
|
unique_key = "balances_validator_addresses_daily_id",
|
||||||
|
cluster_by = "block_date",
|
||||||
|
tags = ['silver','streamline','balances','records','native','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH miner_addresses AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT block_timestamp :: DATE AS block_date,
|
||||||
|
miner AS address
|
||||||
|
FROM
|
||||||
|
{{ ref('core__fact_blocks') }}
|
||||||
|
WHERE miner <> '0x0000000000000000000000000000000000000000'
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND
|
||||||
|
modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_date,
|
||||||
|
address,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(['block_date', 'address']) }} AS balances_validator_addresses_daily_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
miner_addresses
|
||||||
|
QUALIFY(ROW_NUMBER() over (PARTITION BY balances_validator_addresses_daily_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -4,7 +4,7 @@
|
|||||||
{# Set up dbt configuration #}
|
{# Set up dbt configuration #}
|
||||||
{{ config (
|
{{ config (
|
||||||
materialized = 'view',
|
materialized = 'view',
|
||||||
tags = ['bronze','stablecoin_reads','phase_4']
|
tags = ['bronze','contract_reads','phase_4']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
{# Main query starts here #}
|
{# Main query starts here #}
|
||||||
@ -4,7 +4,7 @@
|
|||||||
{# Set up dbt configuration #}
|
{# Set up dbt configuration #}
|
||||||
{{ config (
|
{{ config (
|
||||||
materialized = 'view',
|
materialized = 'view',
|
||||||
tags = ['bronze','stablecoin_reads','phase_4']
|
tags = ['bronze','contract_reads','phase_4']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
{# Main query starts here #}
|
{# Main query starts here #}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
-- depends_on: {{ ref('bronze__contract_reads') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
unique_key = 'contract_reads_id',
|
||||||
|
cluster_by = ['block_date'],
|
||||||
|
incremental_predicates = ["dynamic_range", "block_number"],
|
||||||
|
merge_exclude_columns = ["inserted_timestamp"],
|
||||||
|
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
||||||
|
tags = ['silver','contract_reads','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
VALUE :"BLOCK_NUMBER" :: NUMBER AS block_number,
|
||||||
|
(
|
||||||
|
VALUE :"BLOCK_DATE_UNIX" :: TIMESTAMP
|
||||||
|
) :: DATE AS block_date,
|
||||||
|
VALUE :"CONTRACT_ADDRESS" :: STRING AS contract_address,
|
||||||
|
VALUE :"ADDRESS" :: STRING AS address,
|
||||||
|
VALUE :"PROTOCOL" :: STRING AS protocol,
|
||||||
|
VALUE :"VERSION" :: STRING AS version,
|
||||||
|
VALUE :"PLATFORM" :: STRING AS platform,
|
||||||
|
VALUE :"TYPE" :: STRING AS type,
|
||||||
|
PARSE_JSON(
|
||||||
|
VALUE :"METADATA_STR" :: STRING
|
||||||
|
) :: variant AS metadata,
|
||||||
|
VALUE :"FUNCTION_NAME" :: STRING AS function_name,
|
||||||
|
VALUE :"FUNCTION_SIG" :: STRING AS function_sig,
|
||||||
|
VALUE :"INPUT" :: STRING AS input,
|
||||||
|
DATA :result :: STRING AS result_hex,
|
||||||
|
_inserted_timestamp,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_number','contract_address', 'address', 'input', 'platform', 'type']
|
||||||
|
) }} AS contract_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
{{ ref('bronze__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
_inserted_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
COALESCE(MAX(_inserted_timestamp), '1970-01-01')
|
||||||
|
FROM
|
||||||
|
{{ this }})
|
||||||
|
AND DATA :result :: STRING <> '0x'
|
||||||
|
AND platform IS NOT NULL
|
||||||
|
{% else %}
|
||||||
|
{{ ref('bronze__contract_reads_fr') }}
|
||||||
|
WHERE
|
||||||
|
DATA :result :: STRING <> '0x'
|
||||||
|
AND platform IS NOT NULL
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
qualify(ROW_NUMBER() over (PARTITION BY contract_reads_id
|
||||||
|
ORDER BY
|
||||||
|
_inserted_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver__contract_reads
|
||||||
|
tests:
|
||||||
|
- dbt_utils.unique_combination_of_columns:
|
||||||
|
combination_of_columns:
|
||||||
|
- contract_reads_id
|
||||||
|
columns:
|
||||||
|
- name: BLOCK_DATE
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: CONTRACT_ADDRESS
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: PLATFORM
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: RESULT_HEX
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends on: {{ ref('bronze__contract_reads') }}
|
||||||
|
|
||||||
|
{# Set up dbt configuration #}
|
||||||
|
{{ config (
|
||||||
|
materialized = 'incremental',
|
||||||
|
unique_key = 'contract_reads_complete_id',
|
||||||
|
incremental_predicates = ['dynamic_range', 'partition_key'],
|
||||||
|
full_refresh = vars.GLOBAL_STREAMLINE_FR_ENABLED,
|
||||||
|
tags = ['streamline','contract_reads','complete','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
partition_key,
|
||||||
|
contract_address,
|
||||||
|
VALUE :"ADDRESS" :: STRING AS address,
|
||||||
|
VALUE :"BLOCK_NUMBER" :: NUMBER AS block_number,
|
||||||
|
(
|
||||||
|
VALUE :"BLOCK_DATE_UNIX" :: TIMESTAMP
|
||||||
|
) :: DATE AS block_date,
|
||||||
|
VALUE :"FUNCTION_NAME" :: STRING AS function_name,
|
||||||
|
VALUE :"FUNCTION_SIG" :: STRING AS function_sig,
|
||||||
|
VALUE :"INPUT" :: STRING AS input,
|
||||||
|
PARSE_JSON(
|
||||||
|
VALUE :"METADATA_STR" :: STRING
|
||||||
|
) :: variant AS metadata,
|
||||||
|
VALUE :"PROTOCOL" :: STRING AS protocol,
|
||||||
|
VALUE :"VERSION" :: STRING AS version,
|
||||||
|
VALUE :"PLATFORM" :: STRING AS platform,
|
||||||
|
VALUE :"TYPE" :: STRING AS type,
|
||||||
|
file_name,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address', 'address', 'block_number', 'function_name', 'function_sig', 'input', 'platform']
|
||||||
|
) }} AS contract_reads_complete_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
_inserted_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
{{ ref('bronze__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
_inserted_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
COALESCE (MAX(_inserted_timestamp), '1970-01-01' :: TIMESTAMP)
|
||||||
|
FROM
|
||||||
|
{{ this }})
|
||||||
|
AND platform IS NOT NULL
|
||||||
|
{% else %}
|
||||||
|
{{ ref('bronze__contract_reads_fr') }}
|
||||||
|
WHERE platform IS NOT NULL
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
qualify(ROW_NUMBER() over (PARTITION BY contract_reads_complete_id
|
||||||
|
ORDER BY
|
||||||
|
_inserted_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,115 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{# Set up dbt configuration #}
|
||||||
|
{{ config (
|
||||||
|
materialized = "table",
|
||||||
|
tags = ['streamline','contract_reads','history','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH last_x_days AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date
|
||||||
|
FROM
|
||||||
|
{{ ref("_max_block_by_date") }}
|
||||||
|
WHERE block_date >= ('{{ vars.CURATED_SL_CONTRACT_READS_START_DATE }}' :: TIMESTAMP) :: DATE
|
||||||
|
),
|
||||||
|
to_do AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
d.block_number,
|
||||||
|
d.block_date,
|
||||||
|
t.contract_address,
|
||||||
|
t.address,
|
||||||
|
t.function_name,
|
||||||
|
t.function_sig,
|
||||||
|
t.input,
|
||||||
|
t.metadata,
|
||||||
|
t.protocol,
|
||||||
|
t.version,
|
||||||
|
t.platform,
|
||||||
|
t.type
|
||||||
|
FROM
|
||||||
|
{{ ref("streamline__contract_reads_records") }} t
|
||||||
|
CROSS JOIN last_x_days d
|
||||||
|
WHERE type = 'daily'
|
||||||
|
EXCEPT
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
type
|
||||||
|
FROM
|
||||||
|
{{ ref("streamline__contract_reads_complete") }}
|
||||||
|
WHERE
|
||||||
|
block_date IS NOT NULL
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
DATE_PART('EPOCH_SECONDS', block_date) :: INT AS block_date_unix,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
metadata :: STRING AS metadata_str,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
type,
|
||||||
|
ROUND(
|
||||||
|
block_number,
|
||||||
|
-3
|
||||||
|
) AS partition_key,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'data', OBJECT_CONSTRUCT(
|
||||||
|
'id', CONCAT(
|
||||||
|
contract_address,
|
||||||
|
'-',
|
||||||
|
COALESCE(address,'null'),
|
||||||
|
'-',
|
||||||
|
input,
|
||||||
|
'-',
|
||||||
|
block_number
|
||||||
|
),
|
||||||
|
'jsonrpc', '2.0',
|
||||||
|
'method', 'eth_call',
|
||||||
|
'params', ARRAY_CONSTRUCT(
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'to', contract_address,
|
||||||
|
'data', input
|
||||||
|
),
|
||||||
|
utils.udf_int_to_hex(block_number)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'headers', OBJECT_CONSTRUCT(
|
||||||
|
'Content-Type', 'application/json',
|
||||||
|
'x-fsc-livequery', 'true'
|
||||||
|
),
|
||||||
|
'method', 'POST',
|
||||||
|
'secret_name',
|
||||||
|
{% if vars.GLOBAL_ALT_NODE_ENABLED %}
|
||||||
|
'{{ vars.GLOBAL_ALT_NODE_VAULT_PATH }}'
|
||||||
|
{% else %}
|
||||||
|
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
||||||
|
{% endif %},
|
||||||
|
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
||||||
|
) AS request
|
||||||
|
FROM
|
||||||
|
to_do
|
||||||
|
ORDER BY partition_key DESC, block_number DESC
|
||||||
|
|
||||||
|
LIMIT {{ vars.CURATED_SL_CONTRACT_READS_HISTORY_SQL_LIMIT }}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{# Set up dbt configuration #}
|
||||||
|
{{ config (
|
||||||
|
materialized = "view",
|
||||||
|
tags = ['streamline','contract_reads','history','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
{{ ref('streamline__contract_reads_daily_history_requests') }}
|
||||||
|
|
||||||
|
{# Streamline Function Call #}
|
||||||
|
{% if execute %}
|
||||||
|
{% set params = {
|
||||||
|
"external_table": 'contract_reads',
|
||||||
|
"sql_limit": vars.CURATED_SL_CONTRACT_READS_HISTORY_SQL_LIMIT,
|
||||||
|
"producer_batch_size": vars.CURATED_SL_CONTRACT_READS_HISTORY_PRODUCER_BATCH_SIZE,
|
||||||
|
"worker_batch_size": vars.CURATED_SL_CONTRACT_READS_HISTORY_WORKER_BATCH_SIZE,
|
||||||
|
"async_concurrent_requests": vars.CURATED_SL_CONTRACT_READS_HISTORY_ASYNC_CONCURRENT_REQUESTS,
|
||||||
|
"sql_source": 'contract_reads_history'
|
||||||
|
} %}
|
||||||
|
|
||||||
|
{% set function_call_sql %}
|
||||||
|
{{ fsc_utils.if_data_call_function_v2(
|
||||||
|
func = 'streamline.udf_bulk_rest_api_v2',
|
||||||
|
target = this.schema ~ "." ~ this.identifier,
|
||||||
|
params = params
|
||||||
|
) }}
|
||||||
|
{% endset %}
|
||||||
|
|
||||||
|
{% do run_query(function_call_sql) %}
|
||||||
|
{{ log("Streamline function call: " ~ function_call_sql, info=true) }}
|
||||||
|
{% endif %}
|
||||||
@ -0,0 +1,124 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{# Set up dbt configuration #}
|
||||||
|
{{ config (
|
||||||
|
materialized = "table",
|
||||||
|
tags = ['streamline','contract_reads','realtime','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH last_x_days AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date
|
||||||
|
FROM
|
||||||
|
{{ ref("_max_block_by_date") }}
|
||||||
|
WHERE block_date >= DATEADD('day',-4,SYSDATE()) --last 3 max block_number by date
|
||||||
|
),
|
||||||
|
to_do AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
d.block_number,
|
||||||
|
d.block_date,
|
||||||
|
t.contract_address,
|
||||||
|
t.address,
|
||||||
|
t.function_name,
|
||||||
|
t.function_sig,
|
||||||
|
t.input,
|
||||||
|
t.metadata,
|
||||||
|
t.protocol,
|
||||||
|
t.version,
|
||||||
|
t.platform,
|
||||||
|
t.type
|
||||||
|
FROM
|
||||||
|
{{ ref("streamline__contract_reads_records") }} t
|
||||||
|
CROSS JOIN last_x_days d
|
||||||
|
WHERE type = 'daily'
|
||||||
|
EXCEPT
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
type
|
||||||
|
FROM
|
||||||
|
{{ ref("streamline__contract_reads_complete") }}
|
||||||
|
WHERE
|
||||||
|
block_date >= (
|
||||||
|
SELECT MIN(block_date)
|
||||||
|
FROM last_x_days
|
||||||
|
)
|
||||||
|
AND block_date IS NOT NULL
|
||||||
|
AND _inserted_timestamp :: DATE >= DATEADD(
|
||||||
|
'day',
|
||||||
|
-7,
|
||||||
|
SYSDATE()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
DATE_PART('EPOCH_SECONDS', block_date) :: INT AS block_date_unix,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
metadata :: STRING AS metadata_str,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
type,
|
||||||
|
ROUND(
|
||||||
|
block_number,
|
||||||
|
-3
|
||||||
|
) AS partition_key,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'data', OBJECT_CONSTRUCT(
|
||||||
|
'id', CONCAT(
|
||||||
|
contract_address,
|
||||||
|
'-',
|
||||||
|
COALESCE(address,'null'),
|
||||||
|
'-',
|
||||||
|
input,
|
||||||
|
'-',
|
||||||
|
block_number
|
||||||
|
),
|
||||||
|
'jsonrpc', '2.0',
|
||||||
|
'method', 'eth_call',
|
||||||
|
'params', ARRAY_CONSTRUCT(
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'to', contract_address,
|
||||||
|
'data', input
|
||||||
|
),
|
||||||
|
utils.udf_int_to_hex(block_number)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'headers', OBJECT_CONSTRUCT(
|
||||||
|
'Content-Type', 'application/json',
|
||||||
|
'x-fsc-livequery', 'true'
|
||||||
|
),
|
||||||
|
'method', 'POST',
|
||||||
|
'secret_name',
|
||||||
|
{% if vars.GLOBAL_ALT_NODE_ENABLED %}
|
||||||
|
'{{ vars.GLOBAL_ALT_NODE_VAULT_PATH }}'
|
||||||
|
{% else %}
|
||||||
|
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
||||||
|
{% endif %},
|
||||||
|
'url', '{{ vars.GLOBAL_NODE_URL }}'
|
||||||
|
) AS request
|
||||||
|
FROM
|
||||||
|
to_do
|
||||||
|
ORDER BY partition_key DESC, block_number DESC
|
||||||
|
|
||||||
|
LIMIT {{ vars.CURATED_SL_CONTRACT_READS_REALTIME_SQL_LIMIT }}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{# Set up dbt configuration #}
|
||||||
|
{{ config (
|
||||||
|
materialized = "view",
|
||||||
|
tags = ['streamline','contract_reads','realtime','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
{{ ref('streamline__contract_reads_daily_realtime_requests') }}
|
||||||
|
|
||||||
|
{# Streamline Function Call #}
|
||||||
|
{% if execute %}
|
||||||
|
{% set params = {
|
||||||
|
"external_table": 'contract_reads',
|
||||||
|
"sql_limit": vars.CURATED_SL_CONTRACT_READS_REALTIME_SQL_LIMIT,
|
||||||
|
"producer_batch_size": vars.CURATED_SL_CONTRACT_READS_REALTIME_PRODUCER_BATCH_SIZE,
|
||||||
|
"worker_batch_size": vars.CURATED_SL_CONTRACT_READS_REALTIME_WORKER_BATCH_SIZE,
|
||||||
|
"async_concurrent_requests": vars.CURATED_SL_CONTRACT_READS_REALTIME_ASYNC_CONCURRENT_REQUESTS,
|
||||||
|
"sql_source": 'contract_reads_realtime'
|
||||||
|
} %}
|
||||||
|
|
||||||
|
{% set function_call_sql %}
|
||||||
|
{{ fsc_utils.if_data_call_function_v2(
|
||||||
|
func = 'streamline.udf_bulk_rest_api_v2',
|
||||||
|
target = this.schema ~ "." ~ this.identifier,
|
||||||
|
params = params
|
||||||
|
) }}
|
||||||
|
{% endset %}
|
||||||
|
|
||||||
|
{% do run_query(function_call_sql) %}
|
||||||
|
{{ log("Streamline function call: " ~ function_call_sql, info=true) }}
|
||||||
|
{% endif %}
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('silver_lending__aave_ethereum_tokens') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aave_v1_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH all_tokens AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
underlying_address AS contract_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_lending__aave_tokens') }}
|
||||||
|
WHERE
|
||||||
|
version = 'v1'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
underlying_address AS contract_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_lending__aave_ethereum_tokens') }}
|
||||||
|
--relevant for ethereum only
|
||||||
|
WHERE
|
||||||
|
version = 'v1'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
lending_pools AS (
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
CASE
|
||||||
|
WHEN '{{ vars.GLOBAL_PROJECT_NAME }}' = 'ethereum' THEN '0x3dfd23a6c5e8bbcfc9581d2e864a68feb6a076d3'
|
||||||
|
END AS address,
|
||||||
|
--Aave: LendingPoolCore
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
all_tokens
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
CASE
|
||||||
|
WHEN '{{ vars.GLOBAL_PROJECT_NAME }}' = 'ethereum' THEN '0x1012cff81a1582ddd0616517efb97d02c5c17e25'
|
||||||
|
END AS address,
|
||||||
|
--Uniswap: LendingPoolCore in Aave v1 holds Uniswap v1 LP tokens as collateral
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
all_tokens
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
NULL :: VARIANT AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS aave_v1_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
lending_pools
|
||||||
@ -0,0 +1,99 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('silver_lending__aave_ethereum_tokens') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aave_v2_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH all_tokens AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
underlying_address AS contract_address,
|
||||||
|
atoken_address AS address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_lending__aave_tokens') }}
|
||||||
|
WHERE
|
||||||
|
version = 'v2'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
underlying_address AS contract_address,
|
||||||
|
atoken_address AS address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_lending__aave_ethereum_tokens') }}
|
||||||
|
--relevant for ethereum only
|
||||||
|
WHERE
|
||||||
|
version IN ('v2','v2.1')
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
'0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9' AS contract_address, --AAVE
|
||||||
|
'0x4da27a545c0c5b758a6ba100e3a049001de870f5' AS address, --stkAAVE (Staking)
|
||||||
|
'aave' AS protocol,
|
||||||
|
'v2' AS version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
NULL :: variant AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS aave_v2_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
all_tokens
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aave_v3_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH all_tokens AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
atoken_address AS contract_address,
|
||||||
|
underlying_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_lending__aave_tokens') }}
|
||||||
|
WHERE
|
||||||
|
version = 'v3'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
NULL AS address,
|
||||||
|
'totalSupply' AS function_name,
|
||||||
|
'0x18160ddd' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'underlying_address',
|
||||||
|
underlying_address
|
||||||
|
) :: variant AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS aave_v3_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
all_tokens
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aerodrome_v1_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH liquidity_pools AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
pool_address AS contract_address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM {{ ref('silver_dex__aerodrome_pools') }}
|
||||||
|
{% if is_incremental() %}
|
||||||
|
WHERE modified_timestamp > (
|
||||||
|
SELECT MAX(modified_timestamp)
|
||||||
|
FROM {{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
NULL AS address,
|
||||||
|
'getReserves' AS function_name,
|
||||||
|
'0x0902f1ac' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'token0', token0,
|
||||||
|
'token1', token1
|
||||||
|
) :: VARIANT AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS aerodrome_v1_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM liquidity_pools
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'binance_v1_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH contracts AS (
|
||||||
|
SELECT
|
||||||
|
'0xa2e3356610840701bdf5611a53974510ae27e2e1' AS contract_address --Wrapped Binance Beacon ETH (wBETH)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
NULL AS address,
|
||||||
|
'totalSupply' AS function_name,
|
||||||
|
'0x18160ddd' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input,
|
||||||
|
NULL :: VARIANT AS metadata,
|
||||||
|
'binance' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(protocol, '-', version) AS platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS binance_v1_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
contracts
|
||||||
|
{% if is_incremental() %}
|
||||||
|
WHERE contract_address NOT IN (
|
||||||
|
SELECT
|
||||||
|
contract_address
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'curve_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH liquidity_pools AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
DISTINCT pool_address AS address,
|
||||||
|
token_address AS contract_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_dex__curve_pools') }}
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
WHERE
|
||||||
|
_inserted_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
NULL :: variant AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS curve_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
liquidity_pools
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'etherfi_v1_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH contracts AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
chain,
|
||||||
|
attribution
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_reads__etherfi_seed') }}
|
||||||
|
WHERE
|
||||||
|
chain = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND
|
||||||
|
CONCAT(contract_address, '-', COALESCE(address, 'null')) NOT IN (
|
||||||
|
SELECT
|
||||||
|
CONCAT(contract_address, '-', COALESCE(address, 'null'))
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
CASE
|
||||||
|
WHEN function_name = 'balanceOf' THEN CONCAT(
|
||||||
|
function_sig,
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
)
|
||||||
|
ELSE RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
)
|
||||||
|
END AS input,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'token_address', token_address,
|
||||||
|
'attribution', attribution,
|
||||||
|
'chain', chain
|
||||||
|
) :: variant AS metadata,
|
||||||
|
'etherfi' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS etherfi_v1_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
contracts
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'lido_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH pooled_assets AS (
|
||||||
|
SELECT
|
||||||
|
'0xae7ab96520de3a18e5e111b5eaab095312d7fe84' AS contract_address,
|
||||||
|
'getTotalPooledEther' AS function_name,
|
||||||
|
'0x37cfdaca' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
'0x9ee91f9f426fa633d227f7a9b000e28b9dfd8599' AS contract_address,
|
||||||
|
'getTotalPooledMatic' AS function_name,
|
||||||
|
'0xe00222a0' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
NULL AS address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
NULL :: VARIANT AS metadata,
|
||||||
|
'lido' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(protocol, '-', version) AS platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS lido_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM pooled_assets
|
||||||
|
{% if is_incremental() %}
|
||||||
|
WHERE contract_address NOT IN (
|
||||||
|
SELECT
|
||||||
|
contract_address
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'polymarket_v1_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH contracts AS (
|
||||||
|
SELECT
|
||||||
|
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174' AS contract_address, --USDC
|
||||||
|
'0x4d97dcd97ec945f40cf65f87097ace5ea0476045' AS address --Conditional Tokens
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174' AS contract_address, --USDC
|
||||||
|
'0x3a3bd7bb9528e159577f7c2e685cc81a765002e2' AS address --Collateral Tokens
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
NULL :: VARIANT AS metadata,
|
||||||
|
'polymarket' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(protocol, '-', version) AS platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS polymarket_v1_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
contracts
|
||||||
|
{% if is_incremental() %}
|
||||||
|
WHERE CONCAT(contract_address, '-', address) NOT IN (
|
||||||
|
SELECT
|
||||||
|
CONCAT(contract_address, '-', address)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('price__ez_asset_metadata') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'stablecoins_reads_id',
|
||||||
|
post_hook = '{{ unverify_stablecoins() }}',
|
||||||
|
tags = ['silver','contract_reads','heal']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH verified_stablecoins AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'symbol', symbol,
|
||||||
|
'name', name,
|
||||||
|
'label', label,
|
||||||
|
'decimals', decimals,
|
||||||
|
'is_verified', is_verified
|
||||||
|
) :: VARIANT AS metadata
|
||||||
|
FROM
|
||||||
|
{{ ref('defi__dim_stablecoins') }}
|
||||||
|
WHERE
|
||||||
|
is_verified
|
||||||
|
AND contract_address IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
NULL AS address,
|
||||||
|
'totalSupply' AS function_name,
|
||||||
|
'0x18160ddd' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input,
|
||||||
|
metadata,
|
||||||
|
'stablecoins' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(protocol,'-',version) AS platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS stablecoins_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
verified_stablecoins
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('price__ez_asset_metadata') }}
|
||||||
|
-- depends_on: {{ ref('silver_reads__lido_v1_reads') }}
|
||||||
|
-- depends_on: {{ ref('silver_reads__binance_v1_reads') }}
|
||||||
|
-- depends_on: {{ ref('silver_reads__polymarket_v1_reads') }}
|
||||||
|
{{ config (
|
||||||
|
materialized = "incremental",
|
||||||
|
unique_key = "contract_reads_records_id",
|
||||||
|
full_refresh = vars.GLOBAL_STREAMLINE_FR_ENABLED,
|
||||||
|
post_hook = '{{ unverify_contract_reads() }}',
|
||||||
|
tags = ['streamline','contract_reads','records','heal','phase_4']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
-- only specify chains/exclusions for _reads models with hardcoded or seed driven address data
|
||||||
|
-- for dynamic models, the underlying upstream data will already be filtered or made relevant for that chain
|
||||||
|
{% set models = [] %}
|
||||||
|
{% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__lido_v1_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__binance_v1_reads'), 'daily')) %}
|
||||||
|
{% endif %}
|
||||||
|
{% if vars.GLOBAL_PROJECT_NAME == 'polygon' %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__polymarket_v1_reads'), 'daily')) %}
|
||||||
|
{% endif %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__aerodrome_v1_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__superchain_slipstream_v1_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__stablecoins_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__uniswap_v2_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__uniswap_v3_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__uniswap_v4_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__aave_v1_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__aave_v2_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__aave_v3_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__curve_v1_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__tornado_cash_v1_reads'), 'daily')) %}
|
||||||
|
{% set _ = models.append((ref('silver_reads__etherfi_v1_reads'), 'daily')) %}
|
||||||
|
|
||||||
|
WITH all_records AS (
|
||||||
|
{% for model, type in models %}
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
'{{ type }}' AS type
|
||||||
|
FROM {{ model }}
|
||||||
|
{% if not loop.last %}
|
||||||
|
{% if is_incremental() %}
|
||||||
|
WHERE modified_timestamp > (
|
||||||
|
SELECT MAX(modified_timestamp)
|
||||||
|
FROM {{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
UNION ALL
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
function_name,
|
||||||
|
function_sig,
|
||||||
|
input,
|
||||||
|
metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
type,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS contract_reads_records_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
all_records qualify (ROW_NUMBER() over (PARTITION BY contract_reads_records_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'superchain_slipstream_v1_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH blacklisted_tokens AS (
|
||||||
|
SELECT LOWER('0xdbfefd2e8460a6ee4955a68582f85708baea60a3') AS token_address -- superOETHb: excluded to avoid double-counting with Origin Protocol TVL (Aerodrome AMO position)
|
||||||
|
),
|
||||||
|
liquidity_pools AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
pool_address,
|
||||||
|
token0_address AS token0,
|
||||||
|
token1_address AS token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM {{ ref('silver_dex__superchain_slipstream_pools') }}
|
||||||
|
WHERE token0 NOT IN (SELECT token_address FROM blacklisted_tokens)
|
||||||
|
AND token1 NOT IN (SELECT token_address FROM blacklisted_tokens)
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT MAX(modified_timestamp)
|
||||||
|
FROM {{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
lp_balances AS (
|
||||||
|
SELECT
|
||||||
|
token0 AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM liquidity_pools
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
token1 AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM liquidity_pools
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'token0', token0,
|
||||||
|
'token1', token1
|
||||||
|
) :: VARIANT AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS superchain_slipstream_v1_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM lp_balances
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'tornado_cash_reads_id',
|
||||||
|
tags = ['silver','contract_reads']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH mixers AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
token_address AS contract_address,
|
||||||
|
mixer_address AS address
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_reads__tornado_cash_mixer_seed') }}
|
||||||
|
WHERE
|
||||||
|
chain = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||||
|
AND contract_address IS NOT NULL --balanceOf calls only apply to erc20 token-mixer pairs. eth_getBalance calls to be handled downstream for null-mixer pairs.
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND CONCAT(COALESCE(contract_address, 'null'), '-', address) NOT IN (
|
||||||
|
SELECT
|
||||||
|
CONCAT(COALESCE(contract_address, 'null'), '-', address)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
NULL :: variant AS metadata,
|
||||||
|
'tornado_cash' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','address','input','platform']
|
||||||
|
) }} AS tornado_cash_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
mixers
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v2_reads_id',
|
||||||
|
post_hook = '{{ unverify_contract_reads() }}',
|
||||||
|
tags = ['silver','contract_reads','heal']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH verified_contracts AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT token_address
|
||||||
|
FROM
|
||||||
|
{{ ref('price__ez_asset_metadata') }}
|
||||||
|
WHERE
|
||||||
|
is_verified
|
||||||
|
AND token_address IS NOT NULL
|
||||||
|
),
|
||||||
|
liquidity_pools AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
pool_address AS contract_address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM {{ ref('silver_dex__paircreated_evt_v2_pools') }}
|
||||||
|
WHERE token0 IN (SELECT token_address FROM verified_contracts)
|
||||||
|
AND token1 IN (SELECT token_address FROM verified_contracts)
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND (
|
||||||
|
modified_timestamp > (SELECT MAX(modified_timestamp) FROM {{ this }})
|
||||||
|
OR pool_address NOT IN (SELECT contract_address FROM {{ this }})
|
||||||
|
-- pull in pools with newly verified tokens
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
NULL AS address,
|
||||||
|
'getReserves' AS function_name,
|
||||||
|
'0x0902f1ac' AS function_sig,
|
||||||
|
RPAD(
|
||||||
|
function_sig,
|
||||||
|
64,
|
||||||
|
'0'
|
||||||
|
) AS input,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'token0', token0,
|
||||||
|
'token1', token1,
|
||||||
|
'verified_check_enabled','true'
|
||||||
|
) :: VARIANT AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS uniswap_v2_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM liquidity_pools
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v3_reads_id',
|
||||||
|
post_hook = '{{ unverify_contract_reads() }}',
|
||||||
|
tags = ['silver','contract_reads','heal']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH verified_contracts AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT token_address
|
||||||
|
FROM
|
||||||
|
{{ ref('price__ez_asset_metadata') }}
|
||||||
|
WHERE
|
||||||
|
is_verified
|
||||||
|
AND token_address IS NOT NULL
|
||||||
|
),
|
||||||
|
liquidity_pools AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT
|
||||||
|
pool_address,
|
||||||
|
token0_address AS token0,
|
||||||
|
token1_address AS token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM {{ ref('silver_dex__poolcreated_evt_v3_pools') }}
|
||||||
|
WHERE token0 IN (SELECT token_address FROM verified_contracts)
|
||||||
|
AND token1 IN (SELECT token_address FROM verified_contracts)
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND (
|
||||||
|
modified_timestamp > (SELECT MAX(modified_timestamp) FROM {{ this }})
|
||||||
|
OR pool_address NOT IN (SELECT contract_address FROM {{ this }})
|
||||||
|
-- pull in pools with newly verified tokens
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
lp_balances AS (
|
||||||
|
SELECT
|
||||||
|
token0 AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM liquidity_pools
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
token1 AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM liquidity_pools
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
OBJECT_CONSTRUCT(
|
||||||
|
'token0', token0,
|
||||||
|
'token1', token1,
|
||||||
|
'verified_check_enabled','true'
|
||||||
|
) :: VARIANT AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS uniswap_v3_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM lp_balances
|
||||||
@ -0,0 +1,148 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v4_reads_id',
|
||||||
|
post_hook = '{{ unverify_contract_reads() }}',
|
||||||
|
tags = ['silver','contract_reads','heal']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH verified_contracts AS (
|
||||||
|
SELECT
|
||||||
|
DISTINCT token_address
|
||||||
|
FROM
|
||||||
|
{{ ref('price__ez_asset_metadata') }}
|
||||||
|
WHERE
|
||||||
|
is_verified
|
||||||
|
AND token_address IS NOT NULL
|
||||||
|
),
|
||||||
|
liquidity_pools AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
pool_address AS factory_address,
|
||||||
|
hook_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_dex__uniswap_v4_pools') }}
|
||||||
|
WHERE token0 IN (SELECT token_address FROM verified_contracts)
|
||||||
|
AND token1 IN (SELECT token_address FROM verified_contracts)
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND (
|
||||||
|
modified_timestamp > (SELECT MAX(modified_timestamp) FROM {{ this }})
|
||||||
|
OR CONCAT(token0,'-',token1) NOT IN (
|
||||||
|
SELECT CONCAT(metadata:token0::STRING,'-',metadata:token1::STRING)
|
||||||
|
FROM {{ this }}
|
||||||
|
)
|
||||||
|
-- pull in pools with newly verified tokens
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
all_balances AS (
|
||||||
|
SELECT
|
||||||
|
token0 AS contract_address,
|
||||||
|
factory_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
hook_address,
|
||||||
|
'factory' AS address_type,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
liquidity_pools
|
||||||
|
WHERE
|
||||||
|
token0 IS NOT NULL
|
||||||
|
AND token0 <> '0x0000000000000000000000000000000000000000' -- Represents native asset. balanceOf calls only apply to erc20 tokens. eth_getBalance calls to be handled downstream for null/native assets.
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
token1 AS contract_address,
|
||||||
|
factory_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
hook_address,
|
||||||
|
'factory' AS address_type,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
liquidity_pools
|
||||||
|
WHERE
|
||||||
|
token1 IS NOT NULL
|
||||||
|
AND token1 <> '0x0000000000000000000000000000000000000000'
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
token0 AS contract_address,
|
||||||
|
hook_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
hook_address,
|
||||||
|
'hook' AS address_type,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
liquidity_pools
|
||||||
|
WHERE
|
||||||
|
hook_address IS NOT NULL
|
||||||
|
AND hook_address <> '0x0000000000000000000000000000000000000000'
|
||||||
|
AND token0 IS NOT NULL
|
||||||
|
AND token0 <> '0x0000000000000000000000000000000000000000'
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
token1 AS contract_address,
|
||||||
|
hook_address AS address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
hook_address,
|
||||||
|
'hook' AS address_type,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
liquidity_pools
|
||||||
|
WHERE
|
||||||
|
hook_address IS NOT NULL
|
||||||
|
AND hook_address <> '0x0000000000000000000000000000000000000000'
|
||||||
|
AND token1 IS NOT NULL
|
||||||
|
AND token1 <> '0x0000000000000000000000000000000000000000'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
'balanceOf' AS function_name,
|
||||||
|
'0x70a08231' AS function_sig,
|
||||||
|
CONCAT(
|
||||||
|
'0x70a08231',
|
||||||
|
LPAD(SUBSTR(address, 3), 64, '0')
|
||||||
|
) AS input,
|
||||||
|
object_construct_keep_null(
|
||||||
|
'token0',
|
||||||
|
token0,
|
||||||
|
'token1',
|
||||||
|
token1,
|
||||||
|
'hook_address',
|
||||||
|
hook_address,
|
||||||
|
'address_type',
|
||||||
|
address_type,
|
||||||
|
'verified_check_enabled','true'
|
||||||
|
) :: variant AS metadata,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['contract_address','input','platform']
|
||||||
|
) }} AS uniswap_v4_reads_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
all_balances
|
||||||
@ -90,7 +90,7 @@ poolcreated_evt_v3 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__poolcreated_evt_v3_pool_actions') }}
|
{{ ref('silver_dex__poolcreated_evt_v3_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'poolcreated_evt_v3' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'poolcreated_evt_v3' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -136,7 +136,7 @@ paircreated_evt_v2 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__paircreated_evt_v2_pool_actions') }}
|
{{ ref('silver_dex__paircreated_evt_v2_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'paircreated_evt_v2' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'paircreated_evt_v2' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -182,7 +182,7 @@ aerodrome AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__aerodrome_pool_actions') }}
|
{{ ref('silver_dex__aerodrome_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'aerodrome' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'aerodrome' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -228,7 +228,7 @@ pharaoh_v1 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__pharaoh_v1_pool_actions') }}
|
{{ ref('silver_dex__pharaoh_v1_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'pharaoh_v1' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'pharaoh_v1' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -274,7 +274,7 @@ kyberswap_v1_dynamic AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__kyberswap_v1_dynamic_pool_actions') }}
|
{{ ref('silver_dex__kyberswap_v1_dynamic_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'kyberswap_v1_dynamic' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'kyberswap_v1_dynamic' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -320,7 +320,7 @@ kyberswap_v2_elastic AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__kyberswap_v2_elastic_pool_actions') }}
|
{{ ref('silver_dex__kyberswap_v2_elastic_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'kyberswap_v2_elastic' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'kyberswap_v2_elastic' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -366,7 +366,7 @@ dodo_v1 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__dodo_v1_pool_actions') }}
|
{{ ref('silver_dex__dodo_v1_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'dodo_v1' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'dodo_v1' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -412,7 +412,7 @@ pancakeswap_v3 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__pancakeswap_v3_pool_actions') }}
|
{{ ref('silver_dex__pancakeswap_v3_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'pancakeswap_v3' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'pancakeswap_v3' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -458,7 +458,7 @@ camelot_v2 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__camelot_v2_pool_actions') }}
|
{{ ref('silver_dex__camelot_v2_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'camelot_v2' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'camelot_v2' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -504,7 +504,7 @@ quickswap_v2 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__quickswap_v2_pool_actions') }}
|
{{ ref('silver_dex__quickswap_v2_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'quickswap_v2' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'quickswap_v2' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -551,7 +551,7 @@ quickswap_v4 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__quickswap_v4_pool_actions') }}
|
{{ ref('silver_dex__quickswap_v4_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'quickswap_v4' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'quickswap_v4' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -598,7 +598,7 @@ dackie AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__dackie_pool_actions') }}
|
{{ ref('silver_dex__dackie_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'dackie' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'dackie' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -644,7 +644,7 @@ superchain_slipstream AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__superchain_slipstream_pool_actions') }}
|
{{ ref('silver_dex__superchain_slipstream_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'superchain_slipstream' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'superchain_slipstream' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -690,7 +690,7 @@ sushiswap AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__sushiswap_pool_actions') }}
|
{{ ref('silver_dex__sushiswap_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'sushiswap' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'sushiswap' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -736,7 +736,7 @@ trader_joe_v2 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__trader_joe_v2_pool_actions') }}
|
{{ ref('silver_dex__trader_joe_v2_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'trader_joe_v2' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'trader_joe_v2' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -782,7 +782,53 @@ zyberswap_v2 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__zyberswap_v2_pool_actions') }}
|
{{ ref('silver_dex__zyberswap_v2_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'zyberswap_v2' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'zyberswap_v2' not in vars.CURATED_FR_MODELS %}
|
||||||
|
WHERE
|
||||||
|
_inserted_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
MAX(_inserted_timestamp) - INTERVAL '{{ vars.CURATED_COMPLETE_LOOKBACK_HOURS }}'
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
uniswap_v1 AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
event_index,
|
||||||
|
event_name,
|
||||||
|
liquidity_provider,
|
||||||
|
sender,
|
||||||
|
receiver,
|
||||||
|
pool_address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
NULL AS token2,
|
||||||
|
NULL AS token3,
|
||||||
|
NULL AS token4,
|
||||||
|
NULL AS token5,
|
||||||
|
NULL AS token6,
|
||||||
|
NULL AS token7,
|
||||||
|
amount0_unadj,
|
||||||
|
amount1_unadj,
|
||||||
|
NULL AS amount2_unadj,
|
||||||
|
NULL AS amount3_unadj,
|
||||||
|
NULL AS amount4_unadj,
|
||||||
|
NULL AS amount5_unadj,
|
||||||
|
NULL AS amount6_unadj,
|
||||||
|
NULL AS amount7_unadj,
|
||||||
|
platform,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
TYPE,
|
||||||
|
_log_id AS _id,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_dex__uniswap_v1_pool_actions') }}
|
||||||
|
|
||||||
|
{% if is_incremental() and 'uniswap_v1' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -828,7 +874,7 @@ velodrome_v1 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__velodrome_v1_pool_actions') }}
|
{{ ref('silver_dex__velodrome_v1_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'velodrome_v1' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'velodrome_v1' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -874,7 +920,7 @@ velodrome_v2 AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__velodrome_v2_pool_actions') }}
|
{{ ref('silver_dex__velodrome_v2_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'velodrome_v2' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'velodrome_v2' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -920,7 +966,7 @@ balancer AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__balancer_pool_actions') }}
|
{{ ref('silver_dex__balancer_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'balancer' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'balancer' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -966,7 +1012,7 @@ curve AS (
|
|||||||
FROM
|
FROM
|
||||||
{{ ref('silver_dex__curve_pool_actions') }}
|
{{ ref('silver_dex__curve_pool_actions') }}
|
||||||
|
|
||||||
{% if is_incremental() and 'curve' not in vars.curated_fr_models %}
|
{% if is_incremental() and 'curve' not in vars.CURATED_FR_MODELS %}
|
||||||
WHERE
|
WHERE
|
||||||
_inserted_timestamp >= (
|
_inserted_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
@ -1067,6 +1113,11 @@ all_pools AS (
|
|||||||
FROM
|
FROM
|
||||||
zyberswap_v2
|
zyberswap_v2
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
uniswap_v1
|
||||||
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -867,6 +867,44 @@ WHERE
|
|||||||
)
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
),
|
),
|
||||||
|
uniswap_v1 AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
contract_address,
|
||||||
|
pool_address,
|
||||||
|
'0x' AS pool_id,
|
||||||
|
NULL AS pool_name,
|
||||||
|
NULL AS fee,
|
||||||
|
NULL AS tick_spacing,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
NULL AS token2,
|
||||||
|
NULL AS token3,
|
||||||
|
NULL AS token4,
|
||||||
|
NULL AS token5,
|
||||||
|
NULL AS token6,
|
||||||
|
NULL AS token7,
|
||||||
|
platform,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
type,
|
||||||
|
_log_id AS _id,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_dex__uniswap_v1_pools') }}
|
||||||
|
|
||||||
|
{% if is_incremental() and 'uniswap_v1' not in vars.CURATED_FR_MODELS %}
|
||||||
|
WHERE
|
||||||
|
_inserted_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
MAX(_inserted_timestamp) - INTERVAL '{{ vars.CURATED_COMPLETE_LOOKBACK_HOURS }}'
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
uniswap_v4 AS (
|
uniswap_v4 AS (
|
||||||
SELECT
|
SELECT
|
||||||
block_number,
|
block_number,
|
||||||
@ -1234,6 +1272,11 @@ all_pools AS (
|
|||||||
FROM
|
FROM
|
||||||
pancakeswap_v3
|
pancakeswap_v3
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
uniswap_v1
|
||||||
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -1206,6 +1206,43 @@ WHERE
|
|||||||
)
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
),
|
),
|
||||||
|
uniswap_v1 AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
origin_function_signature,
|
||||||
|
origin_from_address,
|
||||||
|
origin_to_address,
|
||||||
|
contract_address,
|
||||||
|
'0x' AS pool_id,
|
||||||
|
event_name,
|
||||||
|
amount_in_unadj,
|
||||||
|
amount_out_unadj,
|
||||||
|
token_in,
|
||||||
|
token_out,
|
||||||
|
sender,
|
||||||
|
tx_to,
|
||||||
|
event_index,
|
||||||
|
platform,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
type,
|
||||||
|
_log_id,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_dex__uniswap_v1_swaps') }}
|
||||||
|
|
||||||
|
{% if is_incremental() and 'uniswap_v1' not in vars.CURATED_FR_MODELS %}
|
||||||
|
WHERE
|
||||||
|
_inserted_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
MAX(_inserted_timestamp) - INTERVAL '{{ vars.CURATED_COMPLETE_LOOKBACK_HOURS }}'
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
uniswap_v4 AS (
|
uniswap_v4 AS (
|
||||||
SELECT
|
SELECT
|
||||||
block_number,
|
block_number,
|
||||||
@ -1695,6 +1732,11 @@ all_dex AS (
|
|||||||
FROM
|
FROM
|
||||||
dackie
|
dackie
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
uniswap_v1
|
||||||
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@ -0,0 +1,110 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'block_number',
|
||||||
|
cluster_by = ['block_timestamp::DATE'],
|
||||||
|
tags = ['silver_dex','defi','dex','lp_actions','curated']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH evt AS (
|
||||||
|
SELECT
|
||||||
|
l.block_number,
|
||||||
|
l.block_timestamp,
|
||||||
|
l.tx_hash,
|
||||||
|
l.event_index,
|
||||||
|
origin_function_signature,
|
||||||
|
origin_from_address,
|
||||||
|
origin_to_address,
|
||||||
|
l.contract_address AS pool_address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
topic_0,
|
||||||
|
topic_1,
|
||||||
|
topic_2,
|
||||||
|
topic_3,
|
||||||
|
data,
|
||||||
|
CASE
|
||||||
|
WHEN topic_0 = '0x06239653922ac7bea6aa2b19dc486b9361821d37712eb796adfd38d81de278ca' THEN 'AddLiquidity'
|
||||||
|
ELSE 'RemoveLiquidity'
|
||||||
|
END AS event_name,
|
||||||
|
CONCAT('0x', SUBSTR(topic_1, 27, 40)) AS provider_address,
|
||||||
|
utils.udf_hex_to_int(
|
||||||
|
topic_2
|
||||||
|
) :: FLOAT AS eth_amount,
|
||||||
|
utils.udf_hex_to_int(
|
||||||
|
topic_3
|
||||||
|
) :: FLOAT AS token_amount,
|
||||||
|
provider_address AS liquidity_provider,
|
||||||
|
provider_address AS sender,
|
||||||
|
CASE
|
||||||
|
WHEN topic_0 = '0x06239653922ac7bea6aa2b19dc486b9361821d37712eb796adfd38d81de278ca' THEN pool_address
|
||||||
|
ELSE provider_address
|
||||||
|
END AS receiver,
|
||||||
|
p.protocol,
|
||||||
|
p.version,
|
||||||
|
p.type,
|
||||||
|
CONCAT(
|
||||||
|
p.protocol,
|
||||||
|
'-',
|
||||||
|
p.version
|
||||||
|
) AS platform,
|
||||||
|
CONCAT(
|
||||||
|
l.tx_hash :: STRING,
|
||||||
|
'-',
|
||||||
|
l.event_index :: STRING
|
||||||
|
) AS _log_id,
|
||||||
|
l.modified_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('core__fact_event_logs') }}
|
||||||
|
l
|
||||||
|
INNER JOIN {{ref('silver_dex__uniswap_v1_pools')}} p
|
||||||
|
ON l.contract_address = p.pool_address
|
||||||
|
WHERE
|
||||||
|
topic_0 IN ('0x06239653922ac7bea6aa2b19dc486b9361821d37712eb796adfd38d81de278ca', --AddLiquidity
|
||||||
|
'0x0fbf06c058b90cb038a618f8c2acbf6145f8b3570fd1fa56abb8f0f3f05b36e8' --RemoveLiquidity
|
||||||
|
)
|
||||||
|
AND tx_succeeded
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND l.modified_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp) - INTERVAL '{{ vars.CURATED_LOOKBACK_HOURS }}'
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
AND l.modified_timestamp >= SYSDATE() - INTERVAL '{{ vars.CURATED_LOOKBACK_DAYS }}'
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
event_index,
|
||||||
|
origin_function_signature,
|
||||||
|
origin_from_address,
|
||||||
|
origin_to_address,
|
||||||
|
event_name,
|
||||||
|
pool_address,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
liquidity_provider,
|
||||||
|
sender,
|
||||||
|
receiver,
|
||||||
|
token_amount AS amount0_unadj,
|
||||||
|
eth_amount AS amount1_unadj,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
type,
|
||||||
|
platform,
|
||||||
|
_log_id,
|
||||||
|
modified_timestamp
|
||||||
|
FROM
|
||||||
|
evt qualify(ROW_NUMBER() over (PARTITION BY _log_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'pool_address',
|
||||||
|
tags = ['silver_dex','defi','dex','curated']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH contract_mapping AS (
|
||||||
|
{{ curated_contract_mapping(
|
||||||
|
vars.CURATED_DEFI_DEX_SWAPS_CONTRACT_MAPPING
|
||||||
|
) }}
|
||||||
|
WHERE
|
||||||
|
version = 'v1'
|
||||||
|
),
|
||||||
|
pools AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
event_index,
|
||||||
|
l.contract_address,
|
||||||
|
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, --All pools are token-ETH only, no token-token pairs
|
||||||
|
'0x0000000000000000000000000000000000000000' AS token1, --native ETH, for pricing purposes
|
||||||
|
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS pool_address,
|
||||||
|
m.protocol,
|
||||||
|
m.version,
|
||||||
|
m.type,
|
||||||
|
CONCAT(
|
||||||
|
m.protocol,
|
||||||
|
'-',
|
||||||
|
m.version
|
||||||
|
) AS platform,
|
||||||
|
'NewExchange' AS event_name,
|
||||||
|
CONCAT(
|
||||||
|
tx_hash :: STRING,
|
||||||
|
'-',
|
||||||
|
event_index :: STRING
|
||||||
|
) AS _log_id,
|
||||||
|
modified_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('core__fact_event_logs') }}
|
||||||
|
l
|
||||||
|
INNER JOIN contract_mapping m
|
||||||
|
ON l.contract_address = m.contract_address
|
||||||
|
WHERE
|
||||||
|
topics [0] :: STRING = '0x9d42cb017eb05bd8944ab536a8b35bc68085931dd5f4356489801453923953f9' --NewExchange
|
||||||
|
AND tx_succeeded
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp) - INTERVAL '{{ vars.CURATED_LOOKBACK_HOURS }}'
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
AND modified_timestamp >= SYSDATE() - INTERVAL '{{ vars.CURATED_LOOKBACK_DAYS }}'
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
contract_address,
|
||||||
|
event_index,
|
||||||
|
event_name,
|
||||||
|
token0,
|
||||||
|
token1,
|
||||||
|
pool_address,
|
||||||
|
platform,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
type,
|
||||||
|
_log_id,
|
||||||
|
modified_timestamp
|
||||||
|
FROM
|
||||||
|
pools qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'block_number',
|
||||||
|
cluster_by = ['block_timestamp::DATE'],
|
||||||
|
tags = ['silver_dex','defi','dex','curated']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH swaps AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
l.block_number,
|
||||||
|
l.block_timestamp,
|
||||||
|
l.tx_hash,
|
||||||
|
l.event_index,
|
||||||
|
origin_function_signature,
|
||||||
|
origin_from_address,
|
||||||
|
origin_to_address,
|
||||||
|
l.contract_address,
|
||||||
|
CASE
|
||||||
|
WHEN topics [0] :: STRING = '0x7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b353984238705' THEN 'EthPurchase'
|
||||||
|
ELSE 'TokenPurchase'
|
||||||
|
END AS event_name,
|
||||||
|
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS buyer_address,
|
||||||
|
utils.udf_hex_to_int(
|
||||||
|
topics [2] :: STRING
|
||||||
|
) :: FLOAT AS sold_amount,
|
||||||
|
utils.udf_hex_to_int(
|
||||||
|
topics [3] :: STRING
|
||||||
|
) :: FLOAT AS bought_amount,
|
||||||
|
CASE
|
||||||
|
WHEN topics [0] :: STRING = '0x7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b353984238705' THEN p.token0
|
||||||
|
ELSE p.token1
|
||||||
|
END AS token_in,
|
||||||
|
CASE
|
||||||
|
WHEN topics [0] :: STRING = '0x7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b353984238705' THEN p.token1
|
||||||
|
ELSE p.token0
|
||||||
|
END AS token_out,
|
||||||
|
p.platform,
|
||||||
|
p.protocol,
|
||||||
|
p.version,
|
||||||
|
p.type,
|
||||||
|
CONCAT(
|
||||||
|
l.tx_hash :: STRING,
|
||||||
|
'-',
|
||||||
|
l.event_index :: STRING
|
||||||
|
) AS _log_id,
|
||||||
|
l.modified_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('core__fact_event_logs') }}
|
||||||
|
l
|
||||||
|
INNER JOIN {{ ref('silver_dex__uniswap_v1_pools') }}
|
||||||
|
p
|
||||||
|
ON p.pool_address = l.contract_address
|
||||||
|
WHERE
|
||||||
|
topics [0] :: STRING IN (
|
||||||
|
'0xcd60aa75dea3072fbc07ae6d7d856b5dc5f4eee88854f5b4abf7b680ef8bc50f',
|
||||||
|
--TokenPurchase
|
||||||
|
'0x7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b353984238705'
|
||||||
|
) --EthPurchase
|
||||||
|
AND tx_succeeded
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND l.modified_timestamp >= (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp) - INTERVAL '{{ vars.CURATED_LOOKBACK_HOURS }}'
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
AND l.modified_timestamp >= SYSDATE() - INTERVAL '{{ vars.CURATED_LOOKBACK_DAYS }}'
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_timestamp,
|
||||||
|
tx_hash,
|
||||||
|
event_index,
|
||||||
|
origin_function_signature,
|
||||||
|
origin_from_address,
|
||||||
|
origin_to_address,
|
||||||
|
contract_address,
|
||||||
|
buyer_address AS sender,
|
||||||
|
sender AS tx_to,
|
||||||
|
sold_amount AS amount_in_unadj,
|
||||||
|
bought_amount AS amount_out_unadj,
|
||||||
|
token_in,
|
||||||
|
token_out,
|
||||||
|
platform,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
TYPE,
|
||||||
|
event_name,
|
||||||
|
_log_id,
|
||||||
|
modified_timestamp
|
||||||
|
FROM
|
||||||
|
swaps
|
||||||
@ -8,7 +8,7 @@
|
|||||||
materialized = 'view',
|
materialized = 'view',
|
||||||
persist_docs ={ "relation": true,
|
persist_docs ={ "relation": true,
|
||||||
"columns": true },
|
"columns": true },
|
||||||
tags = ['gold','defi','stablecoins','heal','curated_daily']
|
tags = ['gold','defi','stablecoins','curated_daily']
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
@ -1,109 +0,0 @@
|
|||||||
{# Get variables #}
|
|
||||||
{% set vars = return_vars() %}
|
|
||||||
|
|
||||||
{# Log configuration details #}
|
|
||||||
{{ log_model_details() }}
|
|
||||||
|
|
||||||
-- depends_on: {{ ref('bronze__stablecoin_reads') }}
|
|
||||||
-- depends_on: {{ ref('price__ez_asset_metadata') }}
|
|
||||||
{{ config(
|
|
||||||
materialized = 'incremental',
|
|
||||||
unique_key = 'stablecoin_reads_id',
|
|
||||||
cluster_by = ['block_date'],
|
|
||||||
incremental_predicates = ["dynamic_range", "block_number"],
|
|
||||||
merge_exclude_columns = ["inserted_timestamp"],
|
|
||||||
post_hook = "{{ unverify_stablecoins() }}",
|
|
||||||
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
|
||||||
tags = ['silver','defi','stablecoins','curated_daily']
|
|
||||||
) }}
|
|
||||||
|
|
||||||
WITH stablecoin_reads AS (
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
VALUE :"BLOCK_NUMBER" :: NUMBER AS block_number,
|
|
||||||
(
|
|
||||||
VALUE :"BLOCK_DATE_UNIX" :: TIMESTAMP
|
|
||||||
) :: DATE AS block_date,
|
|
||||||
contract_address,
|
|
||||||
PARSE_JSON(
|
|
||||||
VALUE :"METADATA_STR" :: STRING
|
|
||||||
) :: variant AS metadata,
|
|
||||||
DATA :result :: STRING AS result_hex,
|
|
||||||
_inserted_timestamp
|
|
||||||
FROM
|
|
||||||
|
|
||||||
{% if is_incremental() %}
|
|
||||||
{{ ref('bronze__stablecoin_reads') }}
|
|
||||||
WHERE
|
|
||||||
_inserted_timestamp >= (
|
|
||||||
SELECT
|
|
||||||
COALESCE(MAX(_inserted_timestamp), '1970-01-01')
|
|
||||||
FROM
|
|
||||||
{{ this }})
|
|
||||||
AND DATA :result :: STRING <> '0x'
|
|
||||||
{% else %}
|
|
||||||
{{ ref('bronze__stablecoin_reads_fr') }}
|
|
||||||
WHERE
|
|
||||||
DATA :result :: STRING <> '0x'
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
qualify(ROW_NUMBER() over (PARTITION BY block_number, contract_address
|
|
||||||
ORDER BY
|
|
||||||
_inserted_timestamp DESC)) = 1
|
|
||||||
),
|
|
||||||
results AS (
|
|
||||||
SELECT
|
|
||||||
block_number,
|
|
||||||
block_date,
|
|
||||||
contract_address,
|
|
||||||
metadata,
|
|
||||||
IFF(
|
|
||||||
C.decimals IS NULL,
|
|
||||||
18,
|
|
||||||
C.decimals
|
|
||||||
) AS decimals_adj,
|
|
||||||
result_hex AS amount_hex,
|
|
||||||
IFNULL(
|
|
||||||
CASE
|
|
||||||
WHEN LENGTH(amount_hex) <= 4300
|
|
||||||
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
|
||||||
CASE
|
|
||||||
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
|
||||||
END
|
|
||||||
) AS amount_raw,
|
|
||||||
IFF(
|
|
||||||
decimals_adj IS NULL,
|
|
||||||
NULL,
|
|
||||||
utils.udf_decimal_adjust(
|
|
||||||
amount_raw,
|
|
||||||
decimals_adj
|
|
||||||
)
|
|
||||||
) AS amount_precise,
|
|
||||||
amount_precise :: FLOAT AS amount,
|
|
||||||
_inserted_timestamp
|
|
||||||
FROM
|
|
||||||
stablecoin_reads s
|
|
||||||
LEFT JOIN {{ ref('core__dim_contracts') }} C
|
|
||||||
ON s.contract_address = C.address
|
|
||||||
WHERE
|
|
||||||
amount_raw IS NOT NULL
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
block_number,
|
|
||||||
block_date,
|
|
||||||
contract_address,
|
|
||||||
metadata,
|
|
||||||
decimals_adj AS decimals,
|
|
||||||
amount_hex,
|
|
||||||
amount_raw,
|
|
||||||
amount_precise,
|
|
||||||
amount,
|
|
||||||
_inserted_timestamp,
|
|
||||||
{{ dbt_utils.generate_surrogate_key(
|
|
||||||
['block_date','contract_address']
|
|
||||||
) }} AS stablecoin_reads_id,
|
|
||||||
SYSDATE() AS inserted_timestamp,
|
|
||||||
SYSDATE() AS modified_timestamp,
|
|
||||||
'{{ invocation_id }}' AS _invocation_id
|
|
||||||
FROM
|
|
||||||
results
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
{# Get variables #}
|
|
||||||
{% set vars = return_vars() %}
|
|
||||||
|
|
||||||
{# Log configuration details #}
|
|
||||||
{{ log_model_details() }}
|
|
||||||
|
|
||||||
-- depends on: {{ ref('bronze__stablecoin_reads') }}
|
|
||||||
|
|
||||||
{# Set up dbt configuration #}
|
|
||||||
{{ config (
|
|
||||||
materialized = 'incremental',
|
|
||||||
unique_key = 'stablecoin_reads_complete_id',
|
|
||||||
incremental_predicates = ['dynamic_range', 'partition_key'],
|
|
||||||
full_refresh = vars.GLOBAL_STREAMLINE_FR_ENABLED,
|
|
||||||
tags = ['streamline','stablecoin_reads','complete','phase_4']
|
|
||||||
) }}
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
partition_key,
|
|
||||||
contract_address,
|
|
||||||
VALUE :"BLOCK_NUMBER" :: NUMBER AS block_number,
|
|
||||||
(
|
|
||||||
VALUE :"BLOCK_DATE_UNIX" :: TIMESTAMP
|
|
||||||
) :: DATE AS block_date,
|
|
||||||
file_name,
|
|
||||||
{{ dbt_utils.generate_surrogate_key(
|
|
||||||
['contract_address', 'block_number']
|
|
||||||
) }} AS stablecoin_reads_complete_id,
|
|
||||||
SYSDATE() AS inserted_timestamp,
|
|
||||||
SYSDATE() AS modified_timestamp,
|
|
||||||
_inserted_timestamp,
|
|
||||||
'{{ invocation_id }}' AS _invocation_id
|
|
||||||
FROM
|
|
||||||
|
|
||||||
{% if is_incremental() %}
|
|
||||||
{{ ref('bronze__stablecoin_reads') }}
|
|
||||||
WHERE
|
|
||||||
_inserted_timestamp >= (
|
|
||||||
SELECT
|
|
||||||
COALESCE (MAX(_inserted_timestamp), '1970-01-01' :: TIMESTAMP)
|
|
||||||
FROM
|
|
||||||
{{ this }})
|
|
||||||
{% else %}
|
|
||||||
{{ ref('bronze__stablecoin_reads_fr') }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
qualify(ROW_NUMBER() over (PARTITION BY stablecoin_reads_complete_id
|
|
||||||
ORDER BY
|
|
||||||
_inserted_timestamp DESC)) = 1
|
|
||||||
@ -1,141 +0,0 @@
|
|||||||
{# Get variables #}
|
|
||||||
{% set vars = return_vars() %}
|
|
||||||
|
|
||||||
{# Log configuration details #}
|
|
||||||
{{ log_model_details() }}
|
|
||||||
|
|
||||||
{# Set up dbt configuration #}
|
|
||||||
{{ config (
|
|
||||||
materialized = "view",
|
|
||||||
tags = ['streamline','stablecoin_reads','history','phase_4']
|
|
||||||
) }}
|
|
||||||
|
|
||||||
WITH verified_stablecoins AS (
|
|
||||||
SELECT
|
|
||||||
contract_address,
|
|
||||||
OBJECT_CONSTRUCT(
|
|
||||||
'symbol', symbol,
|
|
||||||
'name', name,
|
|
||||||
'label', label,
|
|
||||||
'decimals', decimals,
|
|
||||||
'is_verified', is_verified
|
|
||||||
) :: VARIANT AS metadata
|
|
||||||
FROM
|
|
||||||
{{ ref('defi__dim_stablecoins') }}
|
|
||||||
WHERE
|
|
||||||
is_verified
|
|
||||||
AND contract_address IS NOT NULL
|
|
||||||
),
|
|
||||||
max_blocks AS (
|
|
||||||
SELECT
|
|
||||||
block_number,
|
|
||||||
block_date
|
|
||||||
FROM
|
|
||||||
{{ ref("_max_block_by_date") }}
|
|
||||||
WHERE
|
|
||||||
block_date >= ('{{ vars.BALANCES_SL_START_DATE }}' :: TIMESTAMP) :: DATE
|
|
||||||
),
|
|
||||||
base AS (
|
|
||||||
SELECT
|
|
||||||
s.contract_address,
|
|
||||||
s.metadata,
|
|
||||||
m.block_number,
|
|
||||||
m.block_date
|
|
||||||
FROM
|
|
||||||
verified_stablecoins s
|
|
||||||
CROSS JOIN max_blocks m
|
|
||||||
LEFT JOIN {{ ref('streamline__stablecoin_reads_complete') }} c
|
|
||||||
ON s.contract_address = c.contract_address
|
|
||||||
AND m.block_number = c.block_number
|
|
||||||
WHERE
|
|
||||||
c.contract_address IS NULL
|
|
||||||
AND m.block_date < (
|
|
||||||
SELECT MAX(block_date)
|
|
||||||
FROM max_blocks
|
|
||||||
)
|
|
||||||
),
|
|
||||||
function_sigs AS (
|
|
||||||
SELECT
|
|
||||||
'0x18160ddd' AS function_sig,
|
|
||||||
'totalSupply' AS function_name
|
|
||||||
),
|
|
||||||
ready_reads AS (
|
|
||||||
SELECT
|
|
||||||
contract_address,
|
|
||||||
block_number,
|
|
||||||
block_date,
|
|
||||||
function_sig,
|
|
||||||
RPAD(
|
|
||||||
function_sig,
|
|
||||||
64,
|
|
||||||
'0'
|
|
||||||
) AS input,
|
|
||||||
metadata
|
|
||||||
FROM
|
|
||||||
base
|
|
||||||
JOIN function_sigs
|
|
||||||
ON 1 = 1
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
contract_address,
|
|
||||||
block_number,
|
|
||||||
DATE_PART('EPOCH_SECONDS', block_date) :: INT AS block_date_unix,
|
|
||||||
ROUND(block_number,-3) AS partition_key,
|
|
||||||
function_sig,
|
|
||||||
input,
|
|
||||||
metadata :: STRING AS metadata_str,
|
|
||||||
live.udf_api(
|
|
||||||
'POST',
|
|
||||||
'{{ vars.GLOBAL_NODE_URL }}',
|
|
||||||
OBJECT_CONSTRUCT(
|
|
||||||
'Content-Type', 'application/json',
|
|
||||||
'fsc-quantum-state', 'streamline'
|
|
||||||
),
|
|
||||||
OBJECT_CONSTRUCT(
|
|
||||||
'method', 'eth_call',
|
|
||||||
'jsonrpc', '2.0',
|
|
||||||
'params', [{'to': contract_address, 'from': null, 'data': input}, utils.udf_int_to_hex(block_number)],
|
|
||||||
'id', concat_ws(
|
|
||||||
'-',
|
|
||||||
contract_address,
|
|
||||||
input,
|
|
||||||
block_number
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
|
||||||
) AS request
|
|
||||||
FROM
|
|
||||||
ready_reads
|
|
||||||
WHERE
|
|
||||||
EXISTS (
|
|
||||||
SELECT
|
|
||||||
1
|
|
||||||
FROM
|
|
||||||
ready_reads
|
|
||||||
LIMIT
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
{# Streamline Function Call #}
|
|
||||||
{% if execute %}
|
|
||||||
{% set params = {
|
|
||||||
"external_table": 'contract_reads',
|
|
||||||
"sql_limit": vars.CURATED_SL_STABLECOIN_READS_HISTORY_SQL_LIMIT,
|
|
||||||
"producer_batch_size": vars.CURATED_SL_STABLECOIN_READS_HISTORY_PRODUCER_BATCH_SIZE,
|
|
||||||
"worker_batch_size": vars.CURATED_SL_STABLECOIN_READS_HISTORY_WORKER_BATCH_SIZE,
|
|
||||||
"async_concurrent_requests": vars.CURATED_SL_STABLECOIN_READS_HISTORY_ASYNC_CONCURRENT_REQUESTS,
|
|
||||||
"sql_source": 'contract_reads_daily_history'
|
|
||||||
} %}
|
|
||||||
|
|
||||||
{% set function_call_sql %}
|
|
||||||
{{ fsc_utils.if_data_call_function_v2(
|
|
||||||
func = 'streamline.udf_bulk_rest_api_v2',
|
|
||||||
target = this.schema ~ "." ~ this.identifier,
|
|
||||||
params = params
|
|
||||||
) }}
|
|
||||||
{% endset %}
|
|
||||||
|
|
||||||
{% do run_query(function_call_sql) %}
|
|
||||||
{{ log("Streamline function call: " ~ function_call_sql, info=true) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
@ -1,137 +0,0 @@
|
|||||||
{# Get variables #}
|
|
||||||
{% set vars = return_vars() %}
|
|
||||||
|
|
||||||
{# Log configuration details #}
|
|
||||||
{{ log_model_details() }}
|
|
||||||
|
|
||||||
{# Set up dbt configuration #}
|
|
||||||
{{ config (
|
|
||||||
materialized = "view",
|
|
||||||
tags = ['streamline','stablecoin_reads','realtime','phase_4']
|
|
||||||
) }}
|
|
||||||
|
|
||||||
WITH verified_stablecoins AS (
|
|
||||||
SELECT
|
|
||||||
contract_address,
|
|
||||||
OBJECT_CONSTRUCT(
|
|
||||||
'symbol', symbol,
|
|
||||||
'name', name,
|
|
||||||
'label', label,
|
|
||||||
'decimals', decimals,
|
|
||||||
'is_verified', is_verified
|
|
||||||
) :: VARIANT AS metadata
|
|
||||||
FROM
|
|
||||||
{{ ref('defi__dim_stablecoins') }}
|
|
||||||
WHERE
|
|
||||||
is_verified
|
|
||||||
AND contract_address IS NOT NULL
|
|
||||||
),
|
|
||||||
max_blocks AS (
|
|
||||||
SELECT
|
|
||||||
block_number,
|
|
||||||
block_date
|
|
||||||
FROM
|
|
||||||
{{ ref("_max_block_by_date") }}
|
|
||||||
WHERE
|
|
||||||
block_date >= DATEADD('day',-4,SYSDATE()) --last 3 max block_number by date
|
|
||||||
),
|
|
||||||
base AS (
|
|
||||||
SELECT
|
|
||||||
s.contract_address,
|
|
||||||
s.metadata,
|
|
||||||
m.block_number,
|
|
||||||
m.block_date
|
|
||||||
FROM
|
|
||||||
verified_stablecoins s
|
|
||||||
CROSS JOIN max_blocks m
|
|
||||||
LEFT JOIN {{ ref('streamline__stablecoin_reads_complete') }} c
|
|
||||||
ON s.contract_address = c.contract_address
|
|
||||||
AND m.block_number = c.block_number
|
|
||||||
WHERE
|
|
||||||
c.contract_address IS NULL
|
|
||||||
),
|
|
||||||
function_sigs AS (
|
|
||||||
SELECT
|
|
||||||
'0x18160ddd' AS function_sig,
|
|
||||||
'totalSupply' AS function_name
|
|
||||||
),
|
|
||||||
ready_reads AS (
|
|
||||||
SELECT
|
|
||||||
contract_address,
|
|
||||||
block_number,
|
|
||||||
block_date,
|
|
||||||
function_sig,
|
|
||||||
RPAD(
|
|
||||||
function_sig,
|
|
||||||
64,
|
|
||||||
'0'
|
|
||||||
) AS input,
|
|
||||||
metadata
|
|
||||||
FROM
|
|
||||||
base
|
|
||||||
JOIN function_sigs
|
|
||||||
ON 1 = 1
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
contract_address,
|
|
||||||
block_number,
|
|
||||||
DATE_PART('EPOCH_SECONDS', block_date) :: INT AS block_date_unix,
|
|
||||||
ROUND(block_number,-3) AS partition_key,
|
|
||||||
function_sig,
|
|
||||||
input,
|
|
||||||
metadata :: STRING AS metadata_str,
|
|
||||||
live.udf_api(
|
|
||||||
'POST',
|
|
||||||
'{{ vars.GLOBAL_NODE_URL }}',
|
|
||||||
OBJECT_CONSTRUCT(
|
|
||||||
'Content-Type', 'application/json',
|
|
||||||
'fsc-quantum-state', 'streamline'
|
|
||||||
),
|
|
||||||
OBJECT_CONSTRUCT(
|
|
||||||
'method', 'eth_call',
|
|
||||||
'jsonrpc', '2.0',
|
|
||||||
'params', [{'to': contract_address, 'from': null, 'data': input}, utils.udf_int_to_hex(block_number)],
|
|
||||||
'id', concat_ws(
|
|
||||||
'-',
|
|
||||||
contract_address,
|
|
||||||
input,
|
|
||||||
block_number
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'{{ vars.GLOBAL_NODE_VAULT_PATH }}'
|
|
||||||
) AS request
|
|
||||||
FROM
|
|
||||||
ready_reads
|
|
||||||
WHERE
|
|
||||||
EXISTS (
|
|
||||||
SELECT
|
|
||||||
1
|
|
||||||
FROM
|
|
||||||
ready_reads
|
|
||||||
LIMIT
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
{# Streamline Function Call #}
|
|
||||||
{% if execute %}
|
|
||||||
{% set params = {
|
|
||||||
"external_table" :"contract_reads",
|
|
||||||
"sql_limit" : vars.CURATED_SL_STABLECOIN_READS_REALTIME_SQL_LIMIT,
|
|
||||||
"producer_batch_size" : vars.CURATED_SL_STABLECOIN_READS_REALTIME_PRODUCER_BATCH_SIZE,
|
|
||||||
"worker_batch_size" : vars.CURATED_SL_STABLECOIN_READS_REALTIME_WORKER_BATCH_SIZE,
|
|
||||||
"async_concurrent_requests" : vars.CURATED_SL_STABLECOIN_READS_REALTIME_ASYNC_CONCURRENT_REQUESTS,
|
|
||||||
"sql_source" : 'contract_reads_daily_realtime'
|
|
||||||
} %}
|
|
||||||
|
|
||||||
{% set function_call_sql %}
|
|
||||||
{{ fsc_utils.if_data_call_function_v2(
|
|
||||||
func = 'streamline.udf_bulk_rest_api_v2',
|
|
||||||
target = this.schema ~ "." ~ this.identifier,
|
|
||||||
params = params
|
|
||||||
) }}
|
|
||||||
{% endset %}
|
|
||||||
|
|
||||||
{% do run_query(function_call_sql) %}
|
|
||||||
{{ log("Streamline function call: " ~ function_call_sql, info=true) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
@ -0,0 +1,155 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('price__ez_asset_metadata') }}
|
||||||
|
-- depends_on: {{ ref('defi__dim_stablecoins') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
unique_key = 'stablecoins_reads_totalsupply_id',
|
||||||
|
cluster_by = ['block_date'],
|
||||||
|
incremental_predicates = ["dynamic_range", "block_number"],
|
||||||
|
merge_exclude_columns = ["inserted_timestamp"],
|
||||||
|
post_hook = "{{ unverify_stablecoins() }}",
|
||||||
|
full_refresh = vars.GLOBAL_SILVER_FR_ENABLED,
|
||||||
|
tags = ['silver','defi','stablecoins','heal','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH stablecoin_reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
metadata,
|
||||||
|
result_hex,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
protocol = 'stablecoins'
|
||||||
|
AND function_name = 'totalSupply'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
results AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
metadata,
|
||||||
|
metadata :decimals AS decimals,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
IFF(
|
||||||
|
decimals IS NULL,
|
||||||
|
NULL,
|
||||||
|
utils.udf_decimal_adjust(
|
||||||
|
amount_raw,
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
) AS amount_precise,
|
||||||
|
amount_precise :: FLOAT AS amount,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
stablecoin_reads
|
||||||
|
WHERE
|
||||||
|
amount_raw IS NOT NULL
|
||||||
|
),
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
heal_model AS (
|
||||||
|
SELECT
|
||||||
|
t.block_number,
|
||||||
|
t.block_date,
|
||||||
|
t.contract_address,
|
||||||
|
t.metadata,
|
||||||
|
d.decimals AS decimals_heal,
|
||||||
|
t.amount_hex,
|
||||||
|
t.amount_raw,
|
||||||
|
IFF(
|
||||||
|
decimals_heal IS NULL,
|
||||||
|
NULL,
|
||||||
|
utils.udf_decimal_adjust(
|
||||||
|
t.amount_raw,
|
||||||
|
decimals_heal
|
||||||
|
)
|
||||||
|
) AS amount_precise_heal,
|
||||||
|
amount_precise_heal :: FLOAT AS amount_heal,
|
||||||
|
t._inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
t
|
||||||
|
INNER JOIN {{ ref('defi__dim_stablecoins') }}
|
||||||
|
d
|
||||||
|
ON t.contract_address = d.contract_address
|
||||||
|
WHERE
|
||||||
|
t.decimals IS NULL
|
||||||
|
AND d.decimals IS NOT NULL
|
||||||
|
),
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
FINAL AS (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
results
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
metadata,
|
||||||
|
decimals_heal AS decimals,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
amount_precise_heal AS amount_precise,
|
||||||
|
amount_heal AS amount,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
heal_model
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
metadata,
|
||||||
|
decimals,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
amount_precise,
|
||||||
|
amount,
|
||||||
|
_inserted_timestamp,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address']
|
||||||
|
) }} AS stablecoins_reads_totalsupply_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
FINAL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
qualify(ROW_NUMBER() over (PARTITION BY stablecoins_reads_totalsupply_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
|
{% endif %}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
version: 2
|
version: 2
|
||||||
models:
|
models:
|
||||||
- name: silver__stablecoin_reads
|
- name: silver_stablecoins__stablecoins_reads_totalsupply
|
||||||
tests:
|
tests:
|
||||||
- dbt_utils.unique_combination_of_columns:
|
- dbt_utils.unique_combination_of_columns:
|
||||||
arguments:
|
arguments:
|
||||||
combination_of_columns:
|
combination_of_columns:
|
||||||
- stablecoin_reads_id
|
- stablecoin_reads_id
|
||||||
@ -23,7 +23,7 @@ max_ts AS (
|
|||||||
incremental_dates AS (
|
incremental_dates AS (
|
||||||
-- Get all distinct dates that have been updated in any source table
|
-- Get all distinct dates that have been updated in any source table
|
||||||
SELECT DISTINCT block_date
|
SELECT DISTINCT block_date
|
||||||
FROM {{ ref('silver__stablecoin_reads') }}
|
FROM {{ ref('silver_stablecoins__stablecoins_reads_totalsupply') }}
|
||||||
WHERE modified_timestamp > (SELECT max_modified_timestamp FROM max_ts)
|
WHERE modified_timestamp > (SELECT max_modified_timestamp FROM max_ts)
|
||||||
UNION
|
UNION
|
||||||
SELECT DISTINCT block_date
|
SELECT DISTINCT block_date
|
||||||
@ -54,7 +54,7 @@ total_supply AS (
|
|||||||
metadata :label :: STRING AS label,
|
metadata :label :: STRING AS label,
|
||||||
metadata :decimals :: INTEGER AS decimals
|
metadata :decimals :: INTEGER AS decimals
|
||||||
FROM
|
FROM
|
||||||
{{ ref('silver__stablecoin_reads') }}
|
{{ ref('silver_stablecoins__stablecoins_reads_totalsupply') }}
|
||||||
|
|
||||||
{% if is_incremental() %}
|
{% if is_incremental() %}
|
||||||
WHERE
|
WHERE
|
||||||
@ -310,9 +310,7 @@ all_supply AS (
|
|||||||
AND s.contract_address = h.contract_address
|
AND s.contract_address = h.contract_address
|
||||||
),
|
),
|
||||||
|
|
||||||
{% if is_incremental() and var(
|
{% if is_incremental() %}
|
||||||
'HEAL_MODEL'
|
|
||||||
) %}
|
|
||||||
heal_model AS (
|
heal_model AS (
|
||||||
SELECT
|
SELECT
|
||||||
t.block_date,
|
t.block_date,
|
||||||
@ -367,9 +365,7 @@ FINAL AS (
|
|||||||
FROM
|
FROM
|
||||||
all_supply
|
all_supply
|
||||||
|
|
||||||
{% if is_incremental() and var(
|
{% if is_incremental() %}
|
||||||
'HEAL_MODEL'
|
|
||||||
) %}
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
block_date,
|
block_date,
|
||||||
@ -417,9 +413,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
FINAL
|
FINAL
|
||||||
|
|
||||||
{% if is_incremental() and var(
|
{% if is_incremental() %}
|
||||||
'HEAL_MODEL'
|
|
||||||
) %}
|
|
||||||
qualify(ROW_NUMBER() over (PARTITION BY stablecoins_supply_complete_id
|
qualify(ROW_NUMBER() over (PARTITION BY stablecoins_supply_complete_id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
modified_timestamp DESC)) = 1
|
modified_timestamp DESC)) = 1
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'view',
|
||||||
|
persist_docs ={ "relation": true,
|
||||||
|
"columns": true },
|
||||||
|
tags = ['gold','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH tvl_usd AS (
|
||||||
|
SELECT
|
||||||
|
block_date,
|
||||||
|
SUM(
|
||||||
|
CASE
|
||||||
|
WHEN COALESCE(amount_usd, 0) < POWER(10, max_usd_exponent) THEN COALESCE(amount_usd, 0)
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
) AS tvl_usd,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
MAX(modified_timestamp) AS modified_timestamp,
|
||||||
|
MAX(inserted_timestamp) AS inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_tvl__complete_tvl') }}
|
||||||
|
GROUP BY
|
||||||
|
block_date,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_date,
|
||||||
|
tvl_usd,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
modified_timestamp,
|
||||||
|
inserted_timestamp,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','platform']
|
||||||
|
) }} AS ez_protocol_tvl_id
|
||||||
|
FROM
|
||||||
|
tvl_usd
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: defi__ez_protocol_tvl
|
||||||
|
description: '{{ doc("ez_protocol_tvl_table_doc") }}'
|
||||||
|
|
||||||
|
columns:
|
||||||
|
- name: BLOCK_DATE
|
||||||
|
description: '{{ doc("ez_protocol_tvl_block_date") }}'
|
||||||
|
- name: TVL_USD
|
||||||
|
description: '{{ doc("ez_protocol_tvl_tvl_usd") }}'
|
||||||
|
- name: PROTOCOL
|
||||||
|
description: '{{ doc("ez_protocol_tvl_protocol") }}'
|
||||||
|
- name: VERSION
|
||||||
|
description: '{{ doc("ez_protocol_tvl_version") }}'
|
||||||
|
- name: PLATFORM
|
||||||
|
description: '{{ doc("ez_protocol_tvl_platform") }}'
|
||||||
|
- name: INSERTED_TIMESTAMP
|
||||||
|
description: '{{ doc("general_inserted_timestamp") }}'
|
||||||
|
- name: MODIFIED_TIMESTAMP
|
||||||
|
description: '{{ doc("general_modified_timestamp") }}'
|
||||||
|
- name: EZ_PROTOCOL_TVL_ID
|
||||||
|
description: '{{ doc("general_pk") }}'
|
||||||
@ -0,0 +1,114 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aave_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
amount_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT
|
||||||
|
DISTINCT platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_reads__aave_v1_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
balances AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
'0x0000000000000000000000000000000000000000' AS contract_address, -- Represents native asset, for pricing purposes
|
||||||
|
address,
|
||||||
|
balance_hex AS amount_hex,
|
||||||
|
balance_raw AS amount_raw,
|
||||||
|
'aave' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('balances__ez_balances_native_daily') }}
|
||||||
|
WHERE
|
||||||
|
address = '0x3dfd23a6c5e8bbcfc9581d2e864a68feb6a076d3'
|
||||||
|
AND balance_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
FINAL AS (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
reads
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
balances
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS aave_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
FINAL qualify(ROW_NUMBER() over(PARTITION BY aave_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__aave_v1_tvl
|
||||||
|
description: '{{ doc("aave_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aave_v2_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
amount_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT
|
||||||
|
DISTINCT platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_reads__aave_v2_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS aave_v2_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY aave_v2_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__aave_v2_tvl
|
||||||
|
description: '{{ doc("aave_v2_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aave_v3_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
metadata :underlying_address :: STRING AS underlying_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
amount_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT
|
||||||
|
DISTINCT platform
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_reads__aave_v3_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
underlying_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
12 AS usd_threshold,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS aave_v3_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY aave_v3_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__aave_v3_tvl
|
||||||
|
description: '{{ doc("aave_v3_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'aerodrome_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address AS pool_address,
|
||||||
|
address, --NULL
|
||||||
|
regexp_substr_all(SUBSTR(result_hex, 3, len(result_hex)), '.{64}') AS segmented_data,
|
||||||
|
segmented_data [0] :: STRING AS reserve_0_hex,
|
||||||
|
segmented_data [1] :: STRING AS reserve_1_hex,
|
||||||
|
segmented_data [2] :: STRING AS block_timestamp_last_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(reserve_0_hex) <= 4300
|
||||||
|
AND reserve_0_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(reserve_0_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN reserve_0_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(reserve_0_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS reserve_0_raw,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(reserve_1_hex) <= 4300
|
||||||
|
AND reserve_1_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(reserve_1_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN reserve_1_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(reserve_1_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS reserve_1_raw,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(block_timestamp_last_hex) <= 4300
|
||||||
|
AND block_timestamp_last_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(block_timestamp_last_hex) AS TIMESTAMP)END,
|
||||||
|
CASE
|
||||||
|
WHEN block_timestamp_last_hex IS NOT NULL THEN TRY_CAST(
|
||||||
|
utils.udf_hex_to_int(RTRIM(block_timestamp_last_hex, '0')) AS TIMESTAMP
|
||||||
|
)
|
||||||
|
END
|
||||||
|
) AS block_timestamp_last_raw,
|
||||||
|
metadata :token0 :: STRING AS token_0_address,
|
||||||
|
metadata :token1 :: STRING AS token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
reserve_0_raw IS NOT NULL
|
||||||
|
AND reserve_1_raw IS NOT NULL
|
||||||
|
AND block_timestamp_last_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT DISTINCT platform
|
||||||
|
FROM {{ ref('silver_reads__aerodrome_v1_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
all_reads AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
token_0_address AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
reserve_0_hex AS amount_hex,
|
||||||
|
reserve_0_raw AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM reads
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
token_1_address AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
reserve_1_hex AS amount_hex,
|
||||||
|
reserve_1_raw AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM reads
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS aerodrome_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
all_reads qualify(ROW_NUMBER() over(PARTITION BY aerodrome_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__aerodrome_v1_tvl
|
||||||
|
description: '{{ doc("aerodrome_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'binance_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'binance-v1'
|
||||||
|
AND amount_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','platform']
|
||||||
|
) }} AS binance_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY binance_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__binance_v1_tvl
|
||||||
|
description: '{{ doc("binance_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'curve_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'curve-v1'
|
||||||
|
AND amount_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS curve_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY curve_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__curve_v1_tvl
|
||||||
|
description: '{{ doc("curve_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'etherfi_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw_unadj,
|
||||||
|
metadata :token_address :: STRING AS token_address,
|
||||||
|
metadata :attribution :: STRING AS attribution,
|
||||||
|
metadata :chain :: STRING AS chain,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'etherfi-v1'
|
||||||
|
AND chain = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||||
|
AND amount_raw_unadj IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
CASE
|
||||||
|
WHEN r.token_address IS NOT NULL THEN r.token_address
|
||||||
|
ELSE contract_address
|
||||||
|
END AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
CASE
|
||||||
|
WHEN r.contract_address = '0xab7590cee3ef1a863e9a5877fbb82d9be11504da' THEN -1 * amount_raw_unadj
|
||||||
|
--categoryTVL() must be subtracted from getTVL(), negative value enables SUM
|
||||||
|
ELSE amount_raw_unadj
|
||||||
|
END AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
attribution,
|
||||||
|
chain,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS etherfi_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads r qualify(ROW_NUMBER() over(PARTITION BY etherfi_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__etherfi_v1_tvl
|
||||||
|
description: '{{ doc("etherfi_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,173 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'etherfi_v1_tvl_agg_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH chain_tvl AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
attribution,
|
||||||
|
chain
|
||||||
|
FROM
|
||||||
|
{{ ref('silver_tvl__etherfi_v1_tvl') }}
|
||||||
|
WHERE
|
||||||
|
chain = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||||
|
AND attribution = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
), {% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||||
|
eth_attributed_tvl AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
attribution,
|
||||||
|
chain
|
||||||
|
FROM
|
||||||
|
{{ source(
|
||||||
|
'silver_tvl_optimism',
|
||||||
|
'etherfi_v1_tvl'
|
||||||
|
) }}
|
||||||
|
WHERE
|
||||||
|
attribution = 'ethereum'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
attribution,
|
||||||
|
chain
|
||||||
|
FROM
|
||||||
|
{{ source(
|
||||||
|
'silver_tvl_arbitrum',
|
||||||
|
'etherfi_v1_tvl'
|
||||||
|
) }}
|
||||||
|
WHERE
|
||||||
|
attribution = 'ethereum'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
attribution,
|
||||||
|
chain
|
||||||
|
FROM
|
||||||
|
{{ source(
|
||||||
|
'silver_tvl_base',
|
||||||
|
'etherfi_v1_tvl'
|
||||||
|
) }}
|
||||||
|
WHERE
|
||||||
|
attribution = 'ethereum'
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
FINAL AS (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
chain_tvl
|
||||||
|
|
||||||
|
{% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
eth_attributed_tvl
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
attribution,
|
||||||
|
chain,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform','attribution','chain']
|
||||||
|
) }} AS etherfi_v1_tvl_agg_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
FINAL qualify(ROW_NUMBER() over(PARTITION BY etherfi_v1_tvl_agg_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__etherfi_v1_tvl_agg
|
||||||
|
description: '{{ doc("etherfi_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'lido_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'lido-v1'
|
||||||
|
AND amount_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','platform']
|
||||||
|
) }} AS lido_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY lido_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__lido_v1_tvl
|
||||||
|
description: '{{ doc("lido_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'polymarket_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'polymarket-v1'
|
||||||
|
AND amount_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS polymarket_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY polymarket_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__polymarket_v1_tvl
|
||||||
|
description: '{{ doc("polymarket_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,239 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('streamline__contract_reads_records') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'complete_tvl_id',
|
||||||
|
post_hook = '{{ unverify_tvl() }}',
|
||||||
|
tags = ['silver','defi','tvl','complete','heal','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
{% set models = [
|
||||||
|
(ref('silver_tvl__aave_v1_tvl'), 12, 'aave-v1'),
|
||||||
|
(ref('silver_tvl__aave_v2_tvl'), 12, 'aave-v2'),
|
||||||
|
(ref('silver_tvl__aave_v3_tvl'), 12, 'aave-v3'),
|
||||||
|
(ref('silver_tvl__aerodrome_v1_tvl'), 12, 'aerodrome-v1'),
|
||||||
|
(ref('silver_tvl__superchain_slipstream_v1_tvl'), 12, 'superchain-slipstream-v1'),
|
||||||
|
(ref('silver_tvl__binance_v1_tvl'), 12, 'binance-v1'),
|
||||||
|
(ref('silver_tvl__curve_v1_tvl'), 10, 'curve-v1'),
|
||||||
|
(ref('silver_tvl__etherfi_v1_tvl_agg'), 12, 'etherfi-v1'),
|
||||||
|
(ref('silver_tvl__lido_v1_tvl'), 12, 'lido-v1'),
|
||||||
|
(ref('silver_tvl__tornado_cash_v1_tvl'), 9, 'tornado_cash-v1'),
|
||||||
|
(ref('silver_tvl__uniswap_v1_tvl'), 9, 'uniswap-v1'),
|
||||||
|
(ref('silver_tvl__uniswap_v2_tvl'), 9, 'uniswap-v2'),
|
||||||
|
(ref('silver_tvl__uniswap_v3_tvl'), 9, 'uniswap-v3'),
|
||||||
|
(ref('silver_tvl__uniswap_v4_tvl'), 9, 'uniswap-v4')
|
||||||
|
] %}
|
||||||
|
|
||||||
|
WITH all_tvl AS (
|
||||||
|
{% for model, max_usd_exponent, platform in models %}
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ max_usd_exponent }} AS max_usd_exponent
|
||||||
|
FROM {{ model }}
|
||||||
|
{% if is_incremental() and platform not in vars.CURATED_FR_MODELS %}
|
||||||
|
WHERE modified_timestamp > (
|
||||||
|
SELECT MAX(modified_timestamp)
|
||||||
|
FROM {{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
{% if not loop.last %}
|
||||||
|
UNION ALL
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
),
|
||||||
|
contracts AS (
|
||||||
|
SELECT
|
||||||
|
address AS contract_address,
|
||||||
|
symbol AS token_symbol,
|
||||||
|
decimals AS token_decimals,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('core__dim_contracts') }}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
'0x0000000000000000000000000000000000000000' AS contract_address,
|
||||||
|
'{{ vars.GLOBAL_NATIVE_ASSET_SYMBOL }}' AS token_symbol,
|
||||||
|
decimals AS token_decimals,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('core__dim_contracts') }}
|
||||||
|
WHERE
|
||||||
|
address = '{{ vars.GLOBAL_WRAPPED_NATIVE_ASSET_ADDRESS }}'
|
||||||
|
),
|
||||||
|
prices AS (
|
||||||
|
SELECT
|
||||||
|
token_address,
|
||||||
|
price,
|
||||||
|
HOUR,
|
||||||
|
is_verified,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('price__ez_prices_hourly') }}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
'0x0000000000000000000000000000000000000000' AS token_address,
|
||||||
|
price,
|
||||||
|
HOUR,
|
||||||
|
is_verified,
|
||||||
|
modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('price__ez_prices_hourly') }}
|
||||||
|
WHERE
|
||||||
|
token_address = '{{ vars.GLOBAL_WRAPPED_NATIVE_ASSET_ADDRESS }}'
|
||||||
|
),
|
||||||
|
complete_tvl AS (
|
||||||
|
SELECT
|
||||||
|
A.block_number,
|
||||||
|
A.block_date,
|
||||||
|
A.contract_address,
|
||||||
|
A.address,
|
||||||
|
A.token_address,
|
||||||
|
c1.token_decimals AS decimals,
|
||||||
|
c1.token_symbol AS symbol,
|
||||||
|
p1.is_verified,
|
||||||
|
A.amount_hex,
|
||||||
|
A.amount_raw,
|
||||||
|
utils.udf_decimal_adjust(
|
||||||
|
A.amount_raw,
|
||||||
|
c1.token_decimals
|
||||||
|
) AS amount_precise,
|
||||||
|
amount_precise :: FLOAT AS amount,
|
||||||
|
ROUND(
|
||||||
|
amount * p1.price,
|
||||||
|
2
|
||||||
|
) AS amount_usd,
|
||||||
|
A.protocol,
|
||||||
|
A.version,
|
||||||
|
A.platform,
|
||||||
|
A.max_usd_exponent
|
||||||
|
FROM
|
||||||
|
all_tvl A
|
||||||
|
LEFT JOIN contracts c1
|
||||||
|
ON A.token_address = c1.contract_address
|
||||||
|
LEFT JOIN prices p1
|
||||||
|
ON A.token_address = p1.token_address
|
||||||
|
AND DATEADD(
|
||||||
|
'hour',
|
||||||
|
23,
|
||||||
|
A.block_date
|
||||||
|
) = p1.hour
|
||||||
|
),
|
||||||
|
|
||||||
|
{% if is_incremental() and var(
|
||||||
|
'HEAL_MODEL'
|
||||||
|
) %}
|
||||||
|
heal_model AS (
|
||||||
|
SELECT
|
||||||
|
t.block_number,
|
||||||
|
t.block_date,
|
||||||
|
t.contract_address,
|
||||||
|
t.address,
|
||||||
|
t.token_address,
|
||||||
|
c1.token_decimals AS decimals_heal,
|
||||||
|
c1.token_symbol AS symbol_heal,
|
||||||
|
p1.is_verified AS is_verified_heal,
|
||||||
|
t.amount_hex,
|
||||||
|
t.amount_raw,
|
||||||
|
utils.udf_decimal_adjust(
|
||||||
|
t.amount_raw,
|
||||||
|
c1.token_decimals
|
||||||
|
) AS amount_precise_heal,
|
||||||
|
amount_precise_heal :: FLOAT AS amount_heal,
|
||||||
|
ROUND(
|
||||||
|
amount_heal * p1.price,
|
||||||
|
2
|
||||||
|
) AS amount_usd_heal,
|
||||||
|
t.protocol,
|
||||||
|
t.version,
|
||||||
|
t.platform,
|
||||||
|
t.max_usd_exponent
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
t
|
||||||
|
LEFT JOIN contracts c1
|
||||||
|
ON t.token_address = c1.contract_address
|
||||||
|
LEFT JOIN prices p1
|
||||||
|
ON t.token_address = p1.token_address
|
||||||
|
AND DATEADD(
|
||||||
|
'hour',
|
||||||
|
23,
|
||||||
|
t.block_date
|
||||||
|
) = p1.hour
|
||||||
|
WHERE t.decimals IS NULL
|
||||||
|
AND c1.token_decimals IS NOT NULL -- only heal if contract data now exists
|
||||||
|
),
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
FINAL AS (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
complete_tvl
|
||||||
|
|
||||||
|
{% if is_incremental() and var(
|
||||||
|
'HEAL_MODEL'
|
||||||
|
) %}
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
decimals_heal AS decimals,
|
||||||
|
symbol_heal AS symbol,
|
||||||
|
is_verified_heal AS is_verified,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
amount_precise_heal AS amount_precise,
|
||||||
|
amount_heal AS amount,
|
||||||
|
amount_usd_heal AS amount_usd,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
max_usd_exponent
|
||||||
|
FROM
|
||||||
|
heal_model
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
decimals,
|
||||||
|
symbol,
|
||||||
|
is_verified,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
amount_precise,
|
||||||
|
amount,
|
||||||
|
amount_usd,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
max_usd_exponent,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_number','block_date','contract_address','address','platform']
|
||||||
|
) }} AS complete_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
FINAL
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__complete_tvl
|
||||||
|
tests:
|
||||||
|
- dbt_utils.unique_combination_of_columns:
|
||||||
|
combination_of_columns:
|
||||||
|
- COMPLETE_TVL_ID
|
||||||
|
|
||||||
|
columns:
|
||||||
|
- name: BLOCK_NUMBER
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: BLOCK_DATE
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: CONTRACT_ADDRESS
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- dbt_expectations.expect_column_values_to_match_regex:
|
||||||
|
regex: 0[xX][0-9a-fA-F]+
|
||||||
|
- name: AMOUNT_RAW
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: PLATFORM
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: PROTOCOL
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: VERSION
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- name: MODIFIED_TIMESTAMP
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||||
|
datepart: day
|
||||||
|
interval: 3
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'superchain_slipstream_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
metadata :token0 :: STRING AS token_0_address,
|
||||||
|
metadata :token1 :: STRING AS token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
amount_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT DISTINCT platform
|
||||||
|
FROM {{ ref('silver_reads__superchain_slipstream_v1_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS superchain_slipstream_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY superchain_slipstream_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__superchain_slipstream_v1_tvl
|
||||||
|
description: '{{ doc("superchain_slipstream_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,117 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'tornado_cash_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'tornado_cash-v1'
|
||||||
|
AND amount_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
balances AS (
|
||||||
|
SELECT
|
||||||
|
b.block_number,
|
||||||
|
b.block_date,
|
||||||
|
t.token_address AS contract_address,
|
||||||
|
b.address AS address,
|
||||||
|
balance_hex AS amount_hex,
|
||||||
|
balance_raw AS amount_raw,
|
||||||
|
'tornado_cash' AS protocol,
|
||||||
|
'v1' AS version,
|
||||||
|
CONCAT(
|
||||||
|
protocol,
|
||||||
|
'-',
|
||||||
|
version
|
||||||
|
) AS platform,
|
||||||
|
b.modified_timestamp AS _inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('balances__ez_balances_native_daily') }}
|
||||||
|
b
|
||||||
|
LEFT JOIN {{ ref('silver_reads__tornado_cash_mixer_seed') }}
|
||||||
|
t
|
||||||
|
ON b.address = t.mixer_address
|
||||||
|
WHERE
|
||||||
|
t.mixer_address IS NOT NULL
|
||||||
|
AND t.token_address = '0x0000000000000000000000000000000000000000'
|
||||||
|
AND t.chain = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||||
|
AND balance_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND b.modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
FINAL AS (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
reads
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
balances
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS tornado_cash_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
FINAL qualify(ROW_NUMBER() over(PARTITION BY tornado_cash_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__tornado_cash_v1_tvl
|
||||||
|
description: '{{ doc("tornado_cash_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v1_tvl_id',
|
||||||
|
tags = ['silver','defi','tvl','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH balances AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
b.block_number,
|
||||||
|
b.block_date,
|
||||||
|
p.token0,
|
||||||
|
p.token1,
|
||||||
|
b.address,
|
||||||
|
balance_hex,
|
||||||
|
balance_raw,
|
||||||
|
p.protocol,
|
||||||
|
p.version,
|
||||||
|
p.platform
|
||||||
|
FROM
|
||||||
|
{{ ref('balances__ez_balances_native_daily') }}
|
||||||
|
b
|
||||||
|
LEFT JOIN {{ ref('silver_dex__uniswap_v1_pools') }}
|
||||||
|
p
|
||||||
|
ON b.address = p.pool_address
|
||||||
|
WHERE
|
||||||
|
p.pool_address IS NOT NULL
|
||||||
|
AND balance_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND b.modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
|
||||||
|
expanded AS (
|
||||||
|
-- Row for token0 as contract_address
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
token0 AS contract_address,
|
||||||
|
token1 AS token_address,
|
||||||
|
address,
|
||||||
|
balance_hex,
|
||||||
|
balance_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
balances
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
-- Row for token1 as contract_address
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
token1 AS contract_address,
|
||||||
|
token1 AS token_address,
|
||||||
|
address,
|
||||||
|
balance_hex,
|
||||||
|
balance_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM
|
||||||
|
balances
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
token_address,
|
||||||
|
balance_hex AS amount_hex,
|
||||||
|
balance_raw AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','token_address','platform']
|
||||||
|
) }} AS uniswap_v1_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
expanded qualify(ROW_NUMBER() over(PARTITION BY uniswap_v1_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
block_number DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__uniswap_v1_tvl
|
||||||
|
description: '{{ doc("uniswap_v1_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,124 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('streamline__contract_reads_records') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v2_tvl_id',
|
||||||
|
post_hook = '{{ unverify_tvl() }}',
|
||||||
|
tags = ['silver','defi','tvl','heal','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address AS pool_address,
|
||||||
|
address, --NULL
|
||||||
|
regexp_substr_all(SUBSTR(result_hex, 3, len(result_hex)), '.{64}') AS segmented_data,
|
||||||
|
segmented_data [0] :: STRING AS reserve_0_hex,
|
||||||
|
segmented_data [1] :: STRING AS reserve_1_hex,
|
||||||
|
segmented_data [2] :: STRING AS block_timestamp_last_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(reserve_0_hex) <= 4300
|
||||||
|
AND reserve_0_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(reserve_0_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN reserve_0_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(reserve_0_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS reserve_0_raw,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(reserve_1_hex) <= 4300
|
||||||
|
AND reserve_1_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(reserve_1_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN reserve_1_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(reserve_1_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS reserve_1_raw,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(block_timestamp_last_hex) <= 4300
|
||||||
|
AND block_timestamp_last_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(block_timestamp_last_hex) AS TIMESTAMP)END,
|
||||||
|
CASE
|
||||||
|
WHEN block_timestamp_last_hex IS NOT NULL THEN TRY_CAST(
|
||||||
|
utils.udf_hex_to_int(RTRIM(block_timestamp_last_hex, '0')) AS TIMESTAMP
|
||||||
|
)
|
||||||
|
END
|
||||||
|
) AS block_timestamp_last_raw,
|
||||||
|
metadata :token0 :: STRING AS token_0_address,
|
||||||
|
metadata :token1 :: STRING AS token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
reserve_0_raw IS NOT NULL
|
||||||
|
AND reserve_1_raw IS NOT NULL
|
||||||
|
AND block_timestamp_last_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT DISTINCT platform
|
||||||
|
FROM {{ ref('silver_reads__uniswap_v2_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
),
|
||||||
|
all_reads AS (
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
token_0_address AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
reserve_0_hex AS amount_hex,
|
||||||
|
reserve_0_raw AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM reads
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
token_1_address AS contract_address,
|
||||||
|
pool_address AS address,
|
||||||
|
reserve_1_hex AS amount_hex,
|
||||||
|
reserve_1_raw AS amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform
|
||||||
|
FROM reads
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','platform']
|
||||||
|
) }} AS uniswap_v2_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
all_reads qualify(ROW_NUMBER() over(PARTITION BY uniswap_v2_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__uniswap_v2_tvl
|
||||||
|
description: '{{ doc("uniswap_v2_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('streamline__contract_reads_records') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v3_tvl_id',
|
||||||
|
post_hook = '{{ unverify_tvl() }}',
|
||||||
|
tags = ['silver','defi','tvl','heal','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
metadata :token0 :: STRING AS token_0_address,
|
||||||
|
metadata :token1 :: STRING AS token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
amount_raw IS NOT NULL
|
||||||
|
AND platform IN (
|
||||||
|
SELECT DISTINCT platform
|
||||||
|
FROM {{ ref('silver_reads__uniswap_v3_reads') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
token_0_address,
|
||||||
|
token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS uniswap_v3_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY uniswap_v3_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__uniswap_v3_tvl
|
||||||
|
description: '{{ doc("uniswap_v3_tvl_table_doc") }}'
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
{# Get variables #}
|
||||||
|
{% set vars = return_vars() %}
|
||||||
|
|
||||||
|
{# Log configuration details #}
|
||||||
|
{{ log_model_details() }}
|
||||||
|
|
||||||
|
-- depends_on: {{ ref('streamline__contract_reads_records') }}
|
||||||
|
{{ config(
|
||||||
|
materialized = 'incremental',
|
||||||
|
incremental_strategy = 'delete+insert',
|
||||||
|
unique_key = 'uniswap_v4_tvl_id',
|
||||||
|
post_hook = '{{ unverify_tvl() }}',
|
||||||
|
tags = ['silver','defi','tvl','heal','curated_daily']
|
||||||
|
) }}
|
||||||
|
|
||||||
|
WITH reads AS (
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
result_hex AS amount_hex,
|
||||||
|
IFNULL(
|
||||||
|
CASE
|
||||||
|
WHEN LENGTH(amount_hex) <= 4300
|
||||||
|
AND amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(amount_hex) AS bigint)END,
|
||||||
|
CASE
|
||||||
|
WHEN amount_hex IS NOT NULL THEN TRY_CAST(utils.udf_hex_to_int(RTRIM(amount_hex, '0')) AS bigint)
|
||||||
|
END
|
||||||
|
) AS amount_raw,
|
||||||
|
metadata :address_type :: STRING AS address_type,
|
||||||
|
metadata :hook_address :: STRING AS hook_address,
|
||||||
|
metadata :token0 :: STRING AS token_0_address,
|
||||||
|
metadata :token1 :: STRING AS token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
_inserted_timestamp
|
||||||
|
FROM
|
||||||
|
{{ ref('silver__contract_reads') }}
|
||||||
|
WHERE
|
||||||
|
platform = 'uniswap-v4'
|
||||||
|
AND amount_raw IS NOT NULL
|
||||||
|
|
||||||
|
{% if is_incremental() %}
|
||||||
|
AND modified_timestamp > (
|
||||||
|
SELECT
|
||||||
|
MAX(modified_timestamp)
|
||||||
|
FROM
|
||||||
|
{{ this }}
|
||||||
|
)
|
||||||
|
{% endif %}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
block_number,
|
||||||
|
block_date,
|
||||||
|
contract_address,
|
||||||
|
address,
|
||||||
|
contract_address AS token_address,
|
||||||
|
amount_hex,
|
||||||
|
amount_raw,
|
||||||
|
address_type,
|
||||||
|
hook_address,
|
||||||
|
token_0_address,
|
||||||
|
token_1_address,
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
{{ dbt_utils.generate_surrogate_key(
|
||||||
|
['block_date','contract_address','address','platform']
|
||||||
|
) }} AS uniswap_v4_tvl_id,
|
||||||
|
SYSDATE() AS inserted_timestamp,
|
||||||
|
SYSDATE() AS modified_timestamp,
|
||||||
|
'{{ invocation_id }}' AS _invocation_id
|
||||||
|
FROM
|
||||||
|
reads qualify(ROW_NUMBER() over(PARTITION BY uniswap_v4_tvl_id
|
||||||
|
ORDER BY
|
||||||
|
modified_timestamp DESC)) = 1
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
version: 2
|
||||||
|
models:
|
||||||
|
- name: silver_tvl__uniswap_v4_tvl
|
||||||
|
description: '{{ doc("uniswap_v4_tvl_table_doc") }}'
|
||||||
100
models/doc_descriptions/defi/ez_protocol_tvl.md
Normal file
100
models/doc_descriptions/defi/ez_protocol_tvl.md
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
{% docs ez_protocol_tvl_table_doc %}
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
This table provides daily Total Value Locked (TVL) metrics for DeFi protocols across EVM-compatible blockchains. It aggregates values by platform to track liquidity and value deposited in various DeFi applications. Methods may vary by protocol and blockchain.
|
||||||
|
|
||||||
|
## Methodology Note
|
||||||
|
|
||||||
|
For certain protocols (e.g., Uniswap v2/v3/v4 and forks), TVL is calculated only for pools where both tokens are verified. This filtering removes low-quality or spam pools, providing a more accurate representation of "real" TVL rather than values inflated by low-liquidity tokens.
|
||||||
|
|
||||||
|
## Key Use Cases
|
||||||
|
|
||||||
|
- Tracking protocol TVL growth and trends over time
|
||||||
|
- Comparing TVL across different protocols and platforms
|
||||||
|
- Analyzing protocol adoption and liquidity depth
|
||||||
|
- Building TVL-based dashboards and metrics
|
||||||
|
|
||||||
|
## Commonly-used Fields
|
||||||
|
|
||||||
|
- `block_date`: Date of the TVL snapshot
|
||||||
|
- `tvl_usd`: Total Value Locked in USD
|
||||||
|
- `protocol`: Name of the DeFi protocol (e.g., Uniswap, Aave)
|
||||||
|
- `version`: Protocol version (e.g., v2, v3)
|
||||||
|
- `platform`: Specific deployment or platform identifier
|
||||||
|
|
||||||
|
## Sample queries
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- Latest TVL by protocol
|
||||||
|
SELECT
|
||||||
|
protocol,
|
||||||
|
version,
|
||||||
|
tvl_usd
|
||||||
|
FROM <blockchain_name>.defi.ez_protocol_tvl
|
||||||
|
WHERE block_date = CURRENT_DATE - 1
|
||||||
|
ORDER BY tvl_usd DESC;
|
||||||
|
|
||||||
|
-- Daily TVL trend for a specific protocol in aggregate
|
||||||
|
SELECT
|
||||||
|
block_date,
|
||||||
|
SUM(tvl_usd) AS tvl_usd_total
|
||||||
|
FROM <blockchain_name>.defi.ez_protocol_tvl
|
||||||
|
WHERE protocol = 'uniswap'
|
||||||
|
AND block_date >= CURRENT_DATE - 30
|
||||||
|
GROUP BY block_date, protocol
|
||||||
|
ORDER BY block_date DESC;
|
||||||
|
|
||||||
|
-- TVL comparison across platforms
|
||||||
|
SELECT
|
||||||
|
block_date,
|
||||||
|
platform,
|
||||||
|
SUM(tvl_usd) AS total_tvl
|
||||||
|
FROM <blockchain_name>.defi.ez_protocol_tvl
|
||||||
|
WHERE block_date >= CURRENT_DATE - 7
|
||||||
|
GROUP BY block_date, platform
|
||||||
|
ORDER BY block_date DESC, total_tvl DESC;
|
||||||
|
```
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs ez_protocol_tvl_block_date %}
|
||||||
|
|
||||||
|
The date of the daily TVL snapshot.
|
||||||
|
|
||||||
|
Example: '2025-06-10'
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs ez_protocol_tvl_tvl_usd %}
|
||||||
|
|
||||||
|
The total value locked in USD for the protocol on the given date. Values exceeding $1 trillion (1e12) are excluded to filter out erroneous pricing data.
|
||||||
|
|
||||||
|
Example: 1500000000
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs ez_protocol_tvl_protocol %}
|
||||||
|
|
||||||
|
The name of the DeFi protocol.
|
||||||
|
|
||||||
|
Example: 'Uniswap'
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs ez_protocol_tvl_version %}
|
||||||
|
|
||||||
|
The version of the protocol deployment.
|
||||||
|
|
||||||
|
Example: 'v3'
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs ez_protocol_tvl_platform %}
|
||||||
|
|
||||||
|
The specific platform or deployment identifier for the protocol.
|
||||||
|
|
||||||
|
Example: 'uniswap-v3-ethereum'
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
104
models/doc_descriptions/defi/silver_tvl.md
Normal file
104
models/doc_descriptions/defi/silver_tvl.md
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
{% docs aave_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums all underlying token balances held by the LendingPoolCore contract + native ETH in the protocol
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs aave_v2_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums all underlying token balances held by each aToken contract (+ stkAAVE staking on Ethereum)
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs aave_v3_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums totalSupply of each aToken contract
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs binance_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Total supply of wBETH
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs curve_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums all token balances held across pool contracts
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs etherfi_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums values from protocol oracle (minus looped positions), eUSD supply, BTC product balances (WBTC, LBTC, cbBTC) and ETHFI staking where applicable.
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs lido_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Total pooled assets reported by the Lido staking contracts
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs tornado_cash_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums ERC20 token balances + native asset balances across all mixer contracts
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs uniswap_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums native ETH balance across all pool contracts, doubled to represent total pool value (all pools are 50/50 ETH-token pairs)
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs uniswap_v2_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums getReserves() values for token0 and token1 across all pools where both tokens are verified. This filtering removes spam/low-liquidity pools to provide a more accurate TVL value.
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs uniswap_v3_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums token0 and token1 balances held by each pool contract where both tokens are verified. This filtering removes spam/low-liquidity pools to provide a more accurate TVL value.
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs uniswap_v4_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums token0 and token1 balances held by the PoolManager singleton + any associated hook contracts where both tokens are verified. This filtering removes spam/low-liquidity pools to provide a more accurate TVL value.
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs polymarket_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums USDC balances held by the Conditional Tokens and Collateral Tokens contracts
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs aerodrome_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums getReserves() values for token0 and token1 across all AMM pools
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
|
|
||||||
|
{% docs superchain_slipstream_v1_tvl_table_doc %}
|
||||||
|
|
||||||
|
Methodology:
|
||||||
|
Sums token0 and token1 balances held by each Slipstream (CL) pool contract via balanceOf()
|
||||||
|
|
||||||
|
{% enddocs %}
|
||||||
@ -33,9 +33,9 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
modified_timestamp >= (
|
modified_timestamp >= (
|
||||||
SELECT
|
SELECT
|
||||||
MAX(
|
coalesce(MAX(
|
||||||
modified_timestamp
|
modified_timestamp
|
||||||
)
|
), '1970-01-01')
|
||||||
FROM
|
FROM
|
||||||
{{ this }}
|
{{ this }}
|
||||||
)
|
)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user