freemartianTotal TVL
    Updated 2024-09-09
    -- forked from Total TVL per Token @ https://flipsidecrypto.xyz/studio/queries/c466c355-fc9e-4818-b2ea-3421b2f35b2f

    WITH
    prices AS (
    SELECT
    -- hour::date AS price_day,
    symbol AS price_symbol,
    AVG(price) AS price
    FROM ethereum.price.ez_prices_hourly
    WHERE hour::date = current_date
    AND symbol IN ('WBTC','WEETH','SDAI','USDE','RSETH')
    GROUP BY 1
    ORDER BY 1 ASC
    ),

    deposits AS (
    SELECT
    -- block_timestamp::date AS deposit_day,
    symbol AS token_deposit,
    count(tx_hash) AS deposit_tx,
    count(DISTINCT origin_from_address) AS depositors,
    SUM(amount) AS deposit_amount,
    SUM(amount_usd) AS deposit_amount_usd,

    FROM ethereum.core.ez_token_transfers
    WHERE to_address = '0x8bc93498b861fd98277c3b51d240e7e56e48f23c'
    AND from_address <> '0x0000000000000000000000000000000000000000'
    AND block_timestamp::date >= '2024-08-22'
    AND amount_usd IS NOT NULL
    GROUP BY 1
    ),

    withdraws AS (
    SELECT
    -- block_timestamp::date AS withdraw_day,
    symbol AS token_withdraw,
    QueryRunArchived: QueryRun has been archived