mirror of
https://github.com/FlipsideCrypto/fsc-evm.git
synced 2026-02-06 13:26:49 +00:00
Merge 039cb47273 into aa7f49590b
This commit is contained in:
commit
0676a1908f
@ -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 = 'stakewise_v2_reads_id',
|
||||
tags = ['streamline','contract_reads','records']
|
||||
) }}
|
||||
|
||||
-- Static staking tokens (Ethereum: rETH2, sETH2; Gnosis: sGNO)
|
||||
WITH staking_tokens AS (
|
||||
SELECT
|
||||
'0x20bc832ca081b91433ff6c17f85701b6e92486c5' AS contract_address,
|
||||
contract_address AS token_address, -- rETH2 has price feed
|
||||
'reth2' AS component,
|
||||
'ethereum' AS chain
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0xfe2e637202056d30016725477c5da089ab0a043a' AS contract_address,
|
||||
contract_address AS token_address, -- sETH2 has price feed
|
||||
'seth2' AS component,
|
||||
'ethereum' AS chain
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0xa4ef9da5ba71cc0d2e5e877a910a37ec43420445' AS contract_address,
|
||||
'0x9c58bacc331c9aa871afd802db6379a98e80cedb' AS token_address, -- sGNO -> GNO for pricing
|
||||
'sgno' AS component,
|
||||
'gnosis' AS chain
|
||||
),
|
||||
|
||||
-- v3 Vaults from VaultAdded events (Ethereum only)
|
||||
vault_events AS (
|
||||
SELECT
|
||||
DISTINCT LOWER('0x' || SUBSTRING(topics[2]::STRING, 27, 40)) AS contract_address,
|
||||
'{{ vars.GLOBAL_WRAPPED_NATIVE_ASSET_ADDRESS }}' AS token_address, -- Vaults hold ETH, use WETH for pricing
|
||||
'vault' AS component
|
||||
FROM {{ ref('core__fact_event_logs') }}
|
||||
WHERE contract_address = LOWER('0x3a0008a588772446f6e656133c2d5029cc4fc20e') -- Vault Factory
|
||||
AND topics[0]::STRING = '0x2f0697414292d16e25e419060ebbb3a3318648280380829ca42af307b155393b' -- VaultAdded(address,address)
|
||||
AND block_number >= 18470078 -- Factory deployment block
|
||||
-- Exclude blacklisted vault
|
||||
AND LOWER('0x' || SUBSTRING(topics[2]::STRING, 27, 40)) != '0x09e84205df7c68907e619d07afd90143c5763605'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT MAX(modified_timestamp) FROM {{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
-- Combine: totalSupply for staking tokens, totalAssets for vaults
|
||||
all_reads AS (
|
||||
-- Staking tokens: totalSupply()
|
||||
SELECT
|
||||
contract_address,
|
||||
token_address,
|
||||
component,
|
||||
'totalSupply' AS function_name,
|
||||
'0x18160ddd' AS function_sig
|
||||
FROM staking_tokens
|
||||
WHERE chain = '{{ vars.GLOBAL_PROJECT_NAME }}'
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- v3 Vaults: totalAssets() (Ethereum only - no rows on other chains since factory contract doesn't exist)
|
||||
SELECT
|
||||
contract_address,
|
||||
token_address,
|
||||
component,
|
||||
'totalAssets' AS function_name,
|
||||
'0x01e1d114' AS function_sig
|
||||
FROM vault_events
|
||||
)
|
||||
|
||||
SELECT
|
||||
contract_address,
|
||||
NULL AS address,
|
||||
function_name,
|
||||
function_sig,
|
||||
RPAD(function_sig, 64, '0') AS input,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token_address', token_address,
|
||||
'component', component
|
||||
)::VARIANT AS metadata,
|
||||
'stakewise' AS protocol,
|
||||
'v2' AS version,
|
||||
CONCAT(protocol, '-', version) AS platform,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['contract_address', 'input', 'platform']
|
||||
) }} AS stakewise_v2_reads_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM all_reads
|
||||
{% if is_incremental() %}
|
||||
WHERE contract_address NOT IN (
|
||||
SELECT contract_address FROM {{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
@ -49,6 +49,7 @@
|
||||
{% set _ = models.append((ref('silver_reads__compound_v1_reads'), 'daily')) %}
|
||||
{% set _ = models.append((ref('silver_reads__compound_v2_reads'), 'daily')) %}
|
||||
{% set _ = models.append((ref('silver_reads__compound_v3_reads'), 'daily')) %}
|
||||
{% set _ = models.append((ref('silver_reads__stakewise_v2_reads'), 'daily')) %}
|
||||
{% set _ = models.append((ref('silver_reads__monad_delegator_reads'), 'daily')) %}
|
||||
|
||||
WITH all_records AS (
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
(ref('silver_tvl__lido_v1_tvl'), 12, 'lido-v1'),
|
||||
(ref('silver_tvl__rocketpool_v1_tvl'), 12, 'rocketpool-v1'),
|
||||
(ref('silver_tvl__sky_v1_tvl'), 12, 'sky-v1'),
|
||||
(ref('silver_tvl__stakewise_v2_tvl'), 12, 'stakewise-v2'),
|
||||
(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'),
|
||||
|
||||
@ -0,0 +1,130 @@
|
||||
{# Get variables #}
|
||||
{% set vars = return_vars() %}
|
||||
|
||||
{# Log configuration details #}
|
||||
{{ log_model_details() }}
|
||||
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'stakewise_v2_tvl_id',
|
||||
tags = ['silver','defi','tvl','curated_daily']
|
||||
) }}
|
||||
|
||||
-- Contract reads: rETH2, sETH2, sGNO totalSupply + vault totalAssets
|
||||
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:token_address::STRING AS token_address,
|
||||
metadata:component::STRING AS component,
|
||||
protocol,
|
||||
version,
|
||||
platform,
|
||||
_inserted_timestamp
|
||||
FROM {{ ref('silver__contract_reads') }}
|
||||
WHERE platform = 'stakewise-v2'
|
||||
AND amount_raw IS NOT NULL
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT MAX(modified_timestamp)
|
||||
FROM {{ this }}
|
||||
WHERE component != 'validators'
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
reads_tvl AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_date,
|
||||
contract_address,
|
||||
address,
|
||||
token_address,
|
||||
amount_hex,
|
||||
amount_raw,
|
||||
component,
|
||||
_inserted_timestamp
|
||||
FROM reads
|
||||
)
|
||||
|
||||
{% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||
-- Ethereum only: count ValidatorRegistered events for solo validators
|
||||
, validator_events AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp::DATE AS block_date,
|
||||
COUNT(*) AS validator_count,
|
||||
MAX(_inserted_timestamp) AS _inserted_timestamp
|
||||
FROM {{ ref('core__fact_event_logs') }}
|
||||
WHERE contract_address = LOWER('0xEadCBA8BF9ACA93F627F31fB05470F5A0686CEca') -- Validator Registry
|
||||
AND topics[0]::STRING = '0x8a2676b782a7cf403677a95c1d8a31760667d6eee71f2e2b1647980576490aae' -- ValidatorRegistered(bytes32,bytes,uint256,address)
|
||||
AND block_number >= 11726299 -- Registry deployment block
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT MAX(modified_timestamp)
|
||||
FROM {{ this }}
|
||||
WHERE component = 'validators'
|
||||
)
|
||||
{% endif %}
|
||||
GROUP BY 1, 2
|
||||
),
|
||||
|
||||
validators_tvl AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_date,
|
||||
LOWER('0xEadCBA8BF9ACA93F627F31fB05470F5A0686CEca') AS contract_address,
|
||||
NULL AS address,
|
||||
'0x0000000000000000000000000000000000000000' AS token_address, -- Native ETH
|
||||
NULL AS amount_hex,
|
||||
validator_count * 32 * POW(10, 18) AS amount_raw, -- 32 ETH per validator
|
||||
'validators' AS component,
|
||||
_inserted_timestamp
|
||||
FROM validator_events
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
combined_tvl AS (
|
||||
SELECT block_number, block_date, contract_address, address, token_address, amount_hex, amount_raw, component, _inserted_timestamp
|
||||
FROM reads_tvl
|
||||
{% if vars.GLOBAL_PROJECT_NAME == 'ethereum' %}
|
||||
UNION ALL
|
||||
SELECT block_number, block_date, contract_address, address, token_address, amount_hex, amount_raw, component, _inserted_timestamp
|
||||
FROM validators_tvl
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_date,
|
||||
contract_address,
|
||||
address,
|
||||
token_address,
|
||||
amount_hex,
|
||||
amount_raw,
|
||||
'stakewise' AS protocol,
|
||||
'v2' AS version,
|
||||
'stakewise-v2' AS platform,
|
||||
component,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['block_date','contract_address','token_address','component']
|
||||
) }} AS stakewise_v2_tvl_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM combined_tvl
|
||||
WHERE amount_raw IS NOT NULL AND amount_raw > 0
|
||||
QUALIFY ROW_NUMBER() OVER (PARTITION BY stakewise_v2_tvl_id ORDER BY _inserted_timestamp DESC) = 1
|
||||
@ -0,0 +1,4 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_tvl__stakewise_v2_tvl
|
||||
description: '{{ doc("stakewise_v2_tvl_table_doc") }}'
|
||||
@ -166,4 +166,13 @@ Sums balanceOf() for collateral tokens held by each collateral join contract (di
|
||||
Methodology:
|
||||
Sums ERC20 token balances across clearinghouse and endpoint contracts
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs stakewise_v2_tvl_table_doc %}
|
||||
|
||||
Methodology:
|
||||
**Ethereum:** Sums (1) rETH2 totalSupply, (2) sETH2 totalSupply, (3) ValidatorRegistered event count × 32 ETH for solo validators, and (4) totalAssets() for non-blacklisted v3 vaults discovered via VaultAdded events.
|
||||
|
||||
**Gnosis:** sGNO totalSupply reported as GNO.
|
||||
|
||||
{% enddocs %}
|
||||
Loading…
Reference in New Issue
Block a user