JhanlycnAVAX TVL
    Updated 2023-05-25
    WITH transactions AS (
    SELECT
    CASE
    WHEN origin_function_signature = '0x3bc1f1ed' THEN 'deposit'
    WHEN origin_function_signature = '0x4b2084e3' THEN 'withdraw'
    END AS event,
    origin_from_address as user,
    tx_hash
    FROM
    avalanche.core.fact_event_logs
    WHERE
    contract_address = '0x0cd070285380cabfc3be55176928dc8a55e6d2a7'
    ),
    transfers AS (
    SELECT
    tx_hash,
    symbol,
    amount_usd
    FROM
    avalanche.core.ez_token_transfers
    WHERE tx_hash in (select tx_hash from transactions)
    ),
    combined AS (
    SELECT
    t.event,
    tr.amount_usd,
    tr.symbol
    FROM
    transactions t
    JOIN
    transfers tr
    ON t.tx_hash = tr.tx_hash
    )
    SELECT
    symbol,
    GREATEST(0, sum(case when event = 'deposit' then amount_usd else -amount_usd end)) as tvl_per_token,
    Run a query to Download Data