lidoETH Staked through Lido middleware
    Updated 3 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: 3 days ago
    C.DAY::DATE
    LIDO_DEPOSITED_DAILY
    LIDO_DEPOSITED_CUMU
    LIDO_BUFFER
    LIDO_WITHDRAWALS_DAILY
    LIDO_WITHDRAWALS_CUMU
    LIDO_AMOUNT
    1
    2025-05-27 00:00:00.0000124718721680.3914405960-3478979.158130078994573.23331053
    2
    2025-05-26 00:00:00.0000124718721246.986696743-32-3478979.158130078994139.82856668
    3
    2025-05-25 00:00:00.0000124718722957.393533474-736-3478947.158130078995882.23540341
    4
    2025-05-24 00:00:00.0000124718723797.865015927-7840-3478211.158130078997458.70688586
    5
    2025-05-23 00:00:00.0000124718721098.742396770-3470371.158130079002599.5842667
    6
    2025-05-22 00:00:00.00001247187217567.567571154-21056-3470371.158130079019068.40944109
    7
    2025-05-21 00:00:00.0000124718721311.1029059170-3449315.158130079023867.94477585
    8
    2025-05-20 00:00:00.0000124718721313.71194656-31584-3449315.158130079023870.55381649
    9
    2025-05-19 00:00:00.00001247187225280.661271043-63424-3417731.158130079079421.50314098
    10
    2025-05-18 00:00:00.0000124718721505.5962878910-3354307.158130079119070.43815782
    11
    2025-05-17 00:00:00.000012471872872.252249175-320-3354307.158130079118437.09411911
    12
    2025-05-16 00:00:00.0000124718725343.534083353-383.992126911-3353987.158130079123228.37595329
    13
    2025-05-15 00:00:00.0000124718723267.734172835-1440-3353603.166003169121536.56816968
    14
    2025-05-14 00:00:00.0000124718727870.171284824-1728-3352163.166003169127579.00528167
    15
    2025-05-13 00:00:00.0000124718722060.564717918-1984-3350435.166003169123497.39871476
    16
    2025-05-12 00:00:00.00001247187214702.383041764-1024-3348451.166003169138123.21703861
    17
    2025-05-11 00:00:00.0000124718724626.919416739-1568-3347427.166003169129071.75341358
    18
    2025-05-10 00:00:00.00001247187216541.742255314-28576-3345859.166003169142554.57625216
    19
    2025-05-09 00:00:00.00001247187214058.261291141-12288-3317283.166003169168647.09528799
    20
    2025-05-08 00:00:00.0000124718725795.936621118-224-3304995.166003169172672.77061796
    ...
    1669
    116KB
    9s