Merge pull request #473 from FlipsideCrypto/dat2-253-monad-staking-reads

Dat2-253-monad-staking-reads
This commit is contained in:
eric-laurello 2026-01-26 13:22:18 -05:00 committed by GitHub
commit aa7f49590b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,69 @@
{# Get variables #}
{% set vars = return_vars() %}
{# Log configuration details #}
{{ log_model_details() }}
{{ config(
materialized = 'table',
unique_key = 'monad_delegator_rewards_reads_id',
tags = ['streamline', 'contract_reads', 'records']
) }}
{# Generates contract read specifications for getDelegator calls.
Pulls unclaimed rewards for all active delegator/validator ID combos.
Function: getDelegator(uint64 validatorId, address delegator)
Selector: 0x573c1ce0
Contract: 0x0000000000000000000000000000000000001000 (Monad staking precompile)
Returns:
- stake (uint256): Current active stake
- accRewardPerToken (uint256): Last checked accumulator
- unclaimedRewards (uint256): Unclaimed delegator rewards
- deltaStake (uint256): Stake to be activated next epoch
- nextDeltaStake (uint256): Stake to be activated in 2 epochs
- deltaEpoch (uint64): Epoch when deltaStake becomes active
- nextDeltaEpoch (uint64): Epoch when nextDeltaStake becomes active #}
WITH active_delegators AS (
SELECT DISTINCT
validator_id,
delegator_address
FROM
{{ source('gold_gov_monad','ez_staking_balances_daily') }}
WHERE
active_balance > 0
AND balance_date >= (
SELECT MAX(balance_date) - 4
FROM {{ source('gold_gov_monad','ez_staking_balances_daily') }}
)
)
SELECT
'0x0000000000000000000000000000000000001000' AS contract_address,
NULL AS address,
'getDelegator' AS function_name,
'0x573c1ce0' AS function_sig,
CONCAT(
function_sig,
LPAD(LTRIM(utils.udf_int_to_hex(validator_id), '0x'), 64, '0'),
LPAD(LTRIM(delegator_address, '0x'), 64, '0')
) AS input,
OBJECT_CONSTRUCT(
'validator_id', validator_id,
'delegator_address', delegator_address
) :: VARIANT AS metadata,
'monad_staking' AS protocol,
'v1' AS version,
CONCAT(protocol, '-', version) AS platform,
{{ dbt_utils.generate_surrogate_key(
['contract_address', 'input', 'platform']
) }} AS monad_delegator_rewards_reads_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
active_delegators

View File

@ -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__monad_delegator_reads'), 'daily')) %}
WITH all_records AS (
{% for model, type in models %}

View File

@ -155,6 +155,11 @@ sources:
schema: silver_tvl
tables:
- name: etherfi_v1_tvl
- name: gold_gov_monad
database: monad
schema: gov
tables:
- name: ez_staking_balances_daily
- name: ethereum_beacon_chain
database: >-
{{ 'ETHEREUM_DEV' if '_DEV' in target.database.upper() else 'ETHEREUM' }}