lidoETH Staked through Lido middleware
    Updated 8 days ago
    /*
    Calculations details:
    1) Period: November 1, 2020 - current date
    2) ETH staked = Total ETH deposited - Total ETH principal withdrawn +- Lido Buffer
    2.1) Total ETH deposited - Sum of all ETH sent from stETH contract, Lido Withdrawal Vault and
    Lido Staking Router to Beacon Deposit Contract
    - ETH sent from stETH contract to Beacon Deposit Contract - until Lido V2 (last tx 2023-05-12)
    - ETH sent from Lido Withdrawal Vault and Lido Staking Router to Beacon Deposit Contract - since V2 (first tx 2023-05-18)
    2.2) Total ETH principal withdrawn
    We need to take into account principal withdrawals and not rewards withdrawals.
    - If the amount > 32ETH we take 32 as a principal
    - If amount in (20, 32) we consider this all to be a principal (e.g. after slashing) - this is an empirical constant
    - Otherwise, we consider the principal to be 0 (the whole amount is rewards)
    2.3) Lido Buffer data

    */
    -- generates a calendar from '2020-11-01' to the current date
    WITH recursive calendar AS (
    SELECT CAST('2020-11-01' AS DATE) AS day
    UNION ALL
    SELECT DATEADD(day, 1, day)
    FROM calendar
    WHERE day < CURRENT_DATE
    )
    -- calculates daily ETH deposits to Beacon Chain by Lido
    , lido_deposits_daily AS (
    SELECT
    BLOCK_TIMESTAMP::date AS time
    , SUM(DEPOSIT_AMOUNT) AS lido_deposited
    FROM ethereum.beacon_chain.ez_deposits
    WHERE PLATFORM = 'lido'
    GROUP BY 1
    )
    -- calculates daily ETH withdrawals + assigns principal withdrawals
    , lido_withdrawals_daily AS (
    SELECT
    Last run: 8 days ago
    C.DAY::DATE
    LIDO_DEPOSITED_DAILY
    LIDO_DEPOSITED_CUMU
    LIDO_BUFFER
    LIDO_WITHDRAWALS_DAILY
    LIDO_WITHDRAWALS_CUMU
    LIDO_AMOUNT
    1
    2025-06-05 00:00:00.000012471872-88.8241805160-3514019.158130078957764.01768942
    2
    2025-06-04 00:00:00.0000124718724037.8628550680-3514019.158130078961890.704725
    3
    2025-06-03 00:00:00.00001247187210735.9487886570-3514019.158130078968588.79065859
    4
    2025-06-02 00:00:00.00001247187215888.512036751-4576-3514019.158130078973741.35390668
    5
    2025-06-01 00:00:00.0000124718722123.7779432370-3509443.158130078964552.61981317
    6
    2025-05-31 00:00:00.00001247187210429.659525533-8576-3509443.158130078972858.50139547
    7
    2025-05-30 00:00:00.0000124718727350.8873490120-3500867.158130078978355.72921894
    8
    2025-05-29 00:00:00.0000124718726944.182617085-9888-3500867.158130078977949.02448702
    9
    2025-05-28 00:00:00.00001247187211792.700741186-12000-3490979.158130078992685.54261112
    10
    2025-05-27 00:00:00.000012471872416.706624770-3478979.158130078993309.5484947
    11
    2025-05-26 00:00:00.0000124718721246.986696742-32-3478979.158130078994139.82856668
    12
    2025-05-25 00:00:00.0000124718722957.393533474-736-3478947.158130078995882.23540341
    13
    2025-05-24 00:00:00.0000124718723797.865015926-7840-3478211.158130078997458.70688586
    14
    2025-05-23 00:00:00.0000124718721098.7423967690-3470371.158130079002599.5842667
    15
    2025-05-22 00:00:00.00001247187217567.567571154-21056-3470371.158130079019068.40944109
    16
    2025-05-21 00:00:00.0000124718721311.1029059170-3449315.158130079023867.94477585
    17
    2025-05-20 00:00:00.0000124718721313.71194656-31584-3449315.158130079023870.55381649
    18
    2025-05-19 00:00:00.00001247187225280.661271042-63424-3417731.158130079079421.50314097
    19
    2025-05-18 00:00:00.0000124718721505.5962878910-3354307.158130079119070.43815782
    20
    2025-05-17 00:00:00.000012471872872.252249175-320-3354307.158130079118437.09411911
    ...
    1678
    117KB
    7s