cheeyoung-kekvelo daily tvl
    Updated 2022-08-16
    with all_in as(
    select
    day,
    case when in_usd is null then -1*out_usd when out_usd is null then in_usd else in_usd-out_usd end as total_volume,
    sum(case when in_usd is null then 1*out_usd when out_usd is null then in_usd else in_usd-out_usd end) over (order by day) as tvl

    from (
    select
    b.day::date day,
    in_usd as in_usd,
    out_usd as out_usd


    from (
    select
    date_trunc('day',block_timestamp) as day ,
    sum(case
    when token0_amount_usd is null then 2*token1_amount_usd
    when token1_amount_usd is null then 2*token0_amount_usd
    else coalesce(token0_amount_usd, 0) + coalesce(token1_amount_usd,0) end) as in_usd
    from optimism.velodrome.ez_lp_actions
    where lp_action = 'deposit'
    group by 1
    ) b
    full join (
    select
    date_trunc('day',block_timestamp) as day ,
    sum( case
    when token0_amount_usd is null then 2*token1_amount_usd
    when token1_amount_usd is null then 2*token0_amount_usd
    else coalesce(token0_amount_usd, 0) + coalesce(token1_amount_usd,0) end )as out_usd
    from optimism.velodrome.ez_lp_actions
    where lp_action = 'withdraw'
    group by 1
    ) a
    Run a query to Download Data