kidaMultichain Volume by Token (BSC)
    Updated 2023-01-03
    with
    vaults as (
    select distinct
    tx_json:to as vault_address
    from bsc.core.fact_transactions
    where
    from_address = lower('0xfa9da51631268a30ec3ddd1ccbf46c65fad99251')
    and left(tx_json:input, 10) = '0x2ebe3fbb' -- init vault
    ),

    decimals as (
    select
    token_in as contract_address,
    median(case when event_inputs:amount1In::decimal < event_inputs:amount0In::decimal then event_inputs:amount0In else event_inputs:amount1In end / amount_in) as decimals
    from bsc.sushi.ez_swaps s
    join bsc.core.fact_event_logs t
    on t.event_index = s.event_index and s.tx_hash = t.tx_hash
    group by 1
    ),

    prices as (
    select
    date(block_timestamp) as date,
    token_in as token_address,
    symbol_in as symbol,
    avg(amount_in_usd / amount_in) as price
    from bsc.sushi.ez_swaps
    group by 1, 2, 3
    ),

    sourceTxHashes as (
    select distinct
    tx_hash
    from bsc.core.fact_event_logs
    where event_name = 'LogAnySwapOut' -- source chain only to prevent double logging
    ),
    Run a query to Download Data