sakineh5021-nIQRzBtotal TVL (Ethereum)
    Updated 2022-03-26
    with inflow as (
    SELECT sum(AMOUNT_USD) as inpu , sum(AMOUNT) as inpu_num , SYMBOL
    from ethereum.udm_events
    where to_ADDRESS_NAME like '%sushiswap: bentoboxv1%'
    and to_address = '0xf5bce5077908a1b7370b9ae04adc565ebd643966'
    and from_address <> '0xf5bce5077908a1b7370b9ae04adc565ebd643966'

    and event_type like '%erc20_transfer%'
    group by 3
    ) ,
    outflow as (
    SELECT sum(AMOUNT_USD) as outpu , sum(AMOUNT) as outpu_num, SYMBOL
    from ethereum.udm_events
    where from_ADDRESS_NAME like '%sushiswap: bentoboxv1%'
    and from_address = '0xf5bce5077908a1b7370b9ae04adc565ebd643966'
    and to_address <> '0xf5bce5077908a1b7370b9ae04adc565ebd643966'
    and event_type like '%erc20_transfer%'

    group by 3
    ) ,

    Price_token as ( SELECT avg(price) as PRi, symbol , cast(hour as date )
    from ethereum.token_prices_hourly
    where cast(hour as date ) = '2022-03-21'
    group by 2 , 3
    )
    ,
    usd as (
    SELECT I.symbol as Locked_token , inpu_num -outpu_num as Number_of_Locked_tokens , Number_of_Locked_tokens*P.Pri as amount_usd
    from Inflow I ,outflow O , price_token P
    where I.SYMBOL = O.SYMBOL
    and I.SYMBOL = P.SYMBOL
    and Number_of_Locked_tokens >0
    )
    SELECT sum(amount_usd) as TVL
    from usd
    Run a query to Download Data