cristinatintoechelon swaps 2
    Updated 2025-05-29
    with
    swaps as (
    select
    x.tx_hash, x.block_timestamp, x.event_data:amount_in as amount_in, x.event_data:amount_out as amount_out, y.sender,
    case when x.payload_function='0x60955b957956d79bc80b096d3e41bad525dd400d8ce957cdeb05719ed1e4fc26::router::swap_exact_in_2' then y.payload:type_arguments[1] else y.payload:type_arguments[0] end as token_in,
    case when x.payload_function='0x60955b957956d79bc80b096d3e41bad525dd400d8ce957cdeb05719ed1e4fc26::router::swap_exact_in_2' then y.payload:type_arguments[18] else y.payload:type_arguments[1] end as token_out
    from aptos.core.fact_events x
    join aptos.core.fact_transactions y on x.tx_hash=y.tx_hash
    where x.payload_function in ('0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::stable_pool_scripts::swap_exact_in','0x60955b957956d79bc80b096d3e41bad525dd400d8ce957cdeb05719ed1e4fc26::router::swap_exact_in_2','0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool_scripts::swap_exact_in')
    and x.event_address='0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af' and x.event_resource='SwapEvent<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa'
    and x.account_address='0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af'
    and y.vm_status='Executed successfully'
    ),
    prices as (
    SELECT
    date_trunc('week',hour) as date,
    token_address,
    symbol,
    decimals,
    avg(price) as price_usd
    from aptos.price.ez_prices_hourly
    group by 1,2,3,4
    )
    select
    date_trunc('week',block_timestamp) as week,
    symbol,
    count(distinct tx_hash) as swaps,
    sum(swaps) over (partition by symbol order by week) as total_swaps,
    count(distinct sender) as swappers,
    sum( case when symbol in ('WBTC','WETH') then ((amount_out/pow(10,decimals))*price_usd)/pow(10,3) else (amount_out/pow(10,decimals))*price_usd end) as volume_swapped,
    avg( case when symbol in ('WBTC','WETH') then ((amount_out/pow(10,decimals))*price_usd)/pow(10,3) else (amount_out/pow(10,decimals))*price_usd end) as avg_volume_swapped,
    sum(volume_swapped) over (partition by symbol order by week) as total_volume_swapped
    from swaps s join prices p on date_trunc('week',s.block_timestamp)=p.date and lower(s.token_out)=lower(p.token_address)
    group by 1,2 order by 1 desc ,2


    Last run: 19 days ago
    WEEK
    SYMBOL
    SWAPS
    TOTAL_SWAPS
    SWAPPERS
    VOLUME_SWAPPED
    AVG_VOLUME_SWAPPED
    TOTAL_VOLUME_SWAPPED
    1
    2025-05-26 00:00:00.000WBTC11297341387615.61789330817618.891722423366740213.041747
    2
    2025-05-12 00:00:00.000APT270981723.4525411011.15084703463486654.8284985
    3
    2025-05-12 00:00:00.000USDC1498611.1103173931.1103173931613656.17332528
    4
    2025-05-05 00:00:00.000APT2709815229.73484715114.86742357563486651.3759574
    5
    2025-05-05 00:00:00.000WBTC452972311260009.4144082214000.104604536366352597.423854
    6
    2025-04-28 00:00:00.000APT470981321.0412496520.260312413163486621.6411102
    7
    2025-04-28 00:00:00.000Cake126710.00063208846430.0006320884643117.792979615
    8
    2025-04-28 00:00:00.000WBTC1162967813131436.1970668813497.569814943365092588.009446
    9
    2025-04-21 00:00:00.000APT37098092214.33962609371.44654203163486620.5998606
    10
    2025-04-21 00:00:00.000USDT153038134.79744946234.79744946219573757.4696936
    11
    2025-04-21 00:00:00.000WBTC32295621796098.10597581812439.032905872361961151.812379
    12
    2025-04-14 00:00:00.000APT570980655.4665133931.09330267963486406.2602345
    13
    2025-04-14 00:00:00.000WBTC1732953013734274.4323921310792.700671654361165053.706403
    14
    2025-04-07 00:00:00.000APT27098011223.185098624111.59254931263486400.7937211
    15
    2025-04-07 00:00:00.000USDC14985124.73094623624.7309462361613655.06300789
    16
    2025-04-07 00:00:00.000USDT2530372554.079223248277.03961162419573722.6722442
    17
    2025-04-07 00:00:00.000WBTC3012935725812176.464375219654.778180025357430779.274011
    18
    2025-03-31 00:00:00.000APT370979930.55364813390.18454937863486177.6086224
    19
    2025-03-31 00:00:00.000USDC1498416.033614056.033614051613630.33206165
    20
    2025-03-31 00:00:00.000USDT15303510.09681897120.096818971219573168.5930209
    ...
    668
    58KB
    357s