feyikemiRelocked veOLAS
    Updated 2024-11-04
    WITH unlocks AS (
    SELECT
    ACCOUNT_ADDRESS,
    MIN(UNLOCK_TIMESTAMP) AS first_unlock_date,
    SUM(OLAS_AMOUNT) AS initially_unlocked_amount
    FROM crosschain.olas.ez_olas_locking
    GROUP BY ACCOUNT_ADDRESS
    ),

    relocks AS (
    SELECT
    t.ACCOUNT_ADDRESS,
    SUM(u.initially_unlocked_amount) AS initially_unlocked_amount,
    SUM(t.OLAS_AMOUNT) AS total_relocked_veolas
    FROM crosschain.olas.ez_olas_locking t
    JOIN unlocks u
    ON t.ACCOUNT_ADDRESS = u.ACCOUNT_ADDRESS
    WHERE t.UNLOCK_TIMESTAMP > u.first_unlock_date
    GROUP BY t.ACCOUNT_ADDRESS
    )

    SELECT
    COALESCE(SUM(total_relocked_veolas), 0) AS total_relocked_veolas,
    COALESCE(SUM(initially_unlocked_amount), 0) AS Total_initially_unlocked_veOLAS,
    COUNT(DISTINCT ACCOUNT_ADDRESS) AS total_addresses_relocked,
    CASE
    WHEN SUM(initially_unlocked_amount) > 0
    THEN (SUM(total_relocked_veolas) / SUM(initially_unlocked_amount)) * 100
    ELSE 0
    END AS relocked_percentage
    FROM relocks
    QueryRunArchived: QueryRun has been archived