MoDeFinear aidols - traders history
    Updated 2025-03-05
    with tokens_list as (
    select * from $query('f6dfb764-1ad5-4744-b69a-40d8ce173cf0')),

    actual_sender as (
    select a.BLOCK_TIMESTAMP, a.tx_hash, ifnull(tx:actions[0]:Delegate:delegate_action:sender_id::string, TX_SIGNER) as user
    from near.core.fact_transactions a
    join near.defi.ez_dex_swaps b
    on a.tx_hash=b.tx_hash),

    ref_swaps as (
    select a.BLOCK_TIMESTAMP, user as trader,
    token_in_contract,
    case when token_out_contract='wrap.near' then b.symbol
    else 'wNEAR' end as symbol_in,
    case when token_out_contract='wrap.near' then amount_in_raw/pow(10,b.decimals)
    else amount_in end as amount_in, amount_in_usd,
    token_out_contract,
    case when token_in_contract='wrap.near' then b.symbol
    else 'wNEAR' end as symbol_out,
    case when token_in_contract='wrap.near' then amount_out_raw/pow(10,b.decimals)
    else amount_out end as amount_out, amount_out_usd,
    a.tx_hash
    from near.defi.ez_dex_swaps a
    join tokens_list b
    on (case when token_out_contract='wrap.near' then token_in_contract else token_out_contract end)=token_address
    join actual_sender c
    on a.tx_hash=c.tx_hash and c.BLOCK_TIMESTAMP::date>='2025-01-14'
    where a.BLOCK_TIMESTAMP::date>='2025-01-14'),

    other_swaps as (
    select a.BLOCK_TIMESTAMP, user_id as trader,
    input_token as token_in_contract,
    case when output_token='wrap.near' then b.symbol
    else 'wNEAR' end as symbol_in,
    case when output_token='wrap.near' then input_amount/pow(10,b.decimals)
    else input_amount/1e24 end as amount_in,
    QueryRunArchived: QueryRun has been archived