MLDZMNsne10
    Updated 2023-02-26
    with tb1 as (
    SELECT
    *
    from ethereum.core.fact_event_logs
    where ORIGIN_TO_ADDRESS='0x881d40237659c251811cec9c364ef91dc08d300c'
    and EVENT_NAME='Swap'
    ),
    t2 as (select
    TIMESTAMP::date as day,
    avg(PRICE_USD) as price
    from near.core.fact_prices
    where SYMBOL ilike '%near%'
    group by 1 ),

    tb2 as (select
    'Metamask' as platfroms,
    count(distinct tx_hash) as swap,
    count(distinct ORIGIN_FROM_ADDRESS) as swappers,
    sum(AMOUNT*price) as volume_usd,
    avg(AMOUNT*price) as avg_volume,
    median(AMOUNT*price) as median_volume_usd,
    swappers/count(distinct date_trunc(day, block_timestamp)) as average_swapper_day,
    volume_usd/count(distinct date_trunc(day, block_timestamp)) as average_volume_day
    from ethereum.core.ez_token_transfers s left join t2 a on s.BLOCK_TIMESTAMP::date=a.day
    where BLOCK_TIMESTAMP>=CURRENT_DATE-90
    and CONTRACT_ADDRESS ilike '0x85F17Cf997934a597031b2E18a9aB6ebD4B9f6a4'
    and tx_hash in (select tx_hash from tb1)
    group by 1
    ),

    tb4 as (select
    PLATFORM as platfroms,
    count(distinct tx_hash) as swap,
    count(distinct ORIGIN_FROM_ADDRESS) as swappers,
    sum(CASE WHEN SYMBOL_IN='NEAR' THEN AMOUNT_IN*price WHEN SYMBOL_OUT='NEAR' THEN AMOUNT_OUT*price ELSE null END) as volume_usd,
    Run a query to Download Data