Query editor
-- =============================================================================-- NET CUMULATIVE STAKE OVER TIME-- =============================================================================---- METHODOLOGY:---- 1. TRACKING DEPOSITS:-- - Pier Two uses a batch deposit contract (0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756)-- to stake ETH on behalf of their clients-- - This contract sends ETH to the Beacon Deposit Contract-- (0x00000000219ab540356cbb839cbe05303d7705fa)-- - We track deposits by filtering ethereum.traces for transactions where:-- * FROM = Pier Two batch contract-- * TO = Beacon Deposit Contract-- * Value > 0 (actual ETH transferred)---- 2. LINKING DEPOSITS TO VALIDATORS:-- - Each deposit emits a DepositEvent log (topic0 = 0x649bbc62d0e31342...)-- - The validator's public key (48 bytes) is encoded in the log data at position 193-- - We extract these pubkeys to identify which validators are managed by Pier Two---- 3. MAPPING PUBKEYS TO VALIDATOR INDICES:-- - The beacon.validators table maps public_key -> index (validator_index)-- - We need the validator_index to track withdrawals/exits---- 4. TRACKING EXITS:-- - When validators exit, ETH is withdrawn to the withdrawal address (not the batch contract)-- - The ethereum.withdrawals table records which validator_index withdrew and how much-- - Full exits are identified by withdrawals >= 32 ETH-- - We filter withdrawals to only include validator_indices that belong to Pier Two---- 5. WHY THIS APPROACH WORKS:-- - Even though exits go to different withdrawal addresses (controlled by stakers),-- we can still attribute them to Pier Two because we tracked the original deposit-- and know which validator pubkeys/indices were created through their batch contract---- =============================================================================-- STEP 1: Get all validator pubkeys deposited through Pier Two's batch contractWITH piertwo_pubkeys AS (SELECT DISTINCTBYTEARRAY_SUBSTRING(l.data, 193, 48) AS validator_pubkeyFROM ethereum.logs AS lWHERE l.contract_address = 0x00000000219ab540356cbb839cbe05303d7705fa -- Beacon Deposit ContractAND l.topic0 = 0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5 -- DepositEvent signatureAND l.tx_hash IN (-- Filter for transactions originating from Pier Two's batch contractSELECT t.tx_hashFROM ethereum.traces AS tWHERE t."from" = 0xcD7a6C118Ac8F6544BC5076F2D8Fb86D2C546756 -- Pier Two batch contractAND t.to = 0x00000000219ab540356cbb839cbe05303d7705fa -- Beacon Deposit ContractAND t.value > 0AND t.success = TRUE)),-- STEP 2: Map pubkeys to validator indices using beacon.validatorspiertwo_validator_indices AS (SELECT v.index AS validator_indexFROM beacon.validators AS v