ZSaed5.1 swaps total daily
    Updated 2023-03-15
    -- forked from 647e9c59-096c-4cdf-9237-0121e6ca1950

    with clean as (select
    a.* from near.social.fact_addkey_events a
    INNER JOIN near.core.fact_transactions b on a.tx_hash = b.tx_hash and b.tx_status = 'Success'
    where a.BLOCK_TIMESTAMP is not null
    )
    , singin as (
    select min(BLOCK_TIMESTAMP) as day , SIGNER_ID as user from clean
    group by user
    )
    , period as (
    select day , user from singin
    where day::date between '{{Start_from}}' and '{{End_At}}'
    )
    , price as (
    select avg(price_usd) as usd , symbol , token_contract
    from near.core.fact_prices
    group by symbol , token_contract
    )

    select
    BLOCK_TIMESTAMP::date as day ,
    count(DISTINCT TX_HASH ) as num_tx,
    count(DISTINCT TRADER) as num_user,
    count(DISTINCT TOKEN_IN) as num_token_in,
    count(DISTINCT TOKEN_OUT) as num_token_out,
    count(distinct PLATFORM) as num_platform
    from near.core.ez_dex_swaps
    where TRADER in (select DISTINCT user from period )
    group by day


    Run a query to Download Data