Yousefi_1994MarketingDAO - Total Value Locked
    Updated 2023-02-13
    with deposit_found as (
    select
    block_timestamp,
    tx_hash,
    actions:predecessor_id as predecessor_id,
    case
    when actions:receipt:Action:actions[0]:FunctionCall:deposit is not null then actions:receipt:Action:actions[0]:FunctionCall:deposit
    when actions:receipt:Action:actions[2]:Transfer:deposit is not null then actions:receipt:Action:actions[2]:Transfer:deposit
    else actions:receipt:Action:actions[0]:Transfer:deposit
    end as deposit
    from near.core.fact_receipts
    where receiver_id = 'marketing.sputnik-dao.near'
    ),
    withdraw_fund as (
    select
    block_timestamp,
    tx_hash,
    receiver_id,
    actions:receipt:Action:actions[0]:Transfer:deposit as withdraw
    from near.core.fact_receipts
    where actions:predecessor_id = 'marketing.sputnik-dao.near'
    ),
    near_price_usd as (
    select
    timestamp::date as days,
    avg(price_usd) as price_usd
    from near.core.fact_prices
    where symbol = 'wNEAR'
    and timestamp::date = current_date - 1
    group by days
    limit 1
    ),
    deposit_final_result as (
    select
    sum(deposit)/1e24 as amount
    from deposit_found
    Run a query to Download Data