kidaMultichain TVL (Optimism)
    Updated 2023-01-05
    with
    vaults as (
    select distinct
    tx_json:to as vault_address
    from optimism.core.fact_transactions
    where
    from_address = lower('0xfa9da51631268a30ec3ddd1ccbf46c65fad99251')
    and left(tx_json:input, 10) = '0x2ebe3fbb' -- init vault
    ),
    weth_prices as (
    select
    date(block_timestamp) as date,
    replace(feed_name, ' / USD') as symbol,
    median(coalesce(latest_answer_adj, latest_answer_unadj / pow(10,8))) as price --using median cause there will be some nulls / zeroes
    from ethereum.chainlink.ez_oracle_feeds
    where feed_category = 'Cryptocurrency (USD pairs)'
    and feed_name in ('ETH / USD')
    group by 1,2
    order by 1
    ),
    net_ins as (
    select
    date(block_timestamp) as date,
    b.contract_address,
    sum(case when exists (select 1 from vaults where vault_address = from_address) then -raw_amount else raw_amount end) as net_in
    from optimism.core.fact_token_transfers b
    where exists (select 1 from vaults where vault_address = from_address)
    or exists (select 1 from vaults where vault_address = to_address)
    group by 1,2
    ),

    cumulative_min_date as (
    SELECT contract_address, MIN(date) as min_date
    FROM net_ins
    Run a query to Download Data