pecio222TOTAL VOLUME moe aggregator using router events
    Updated 2025-06-12
    -- forked from TOTAL VOLUME lfj aggregator using router events @ https://flipsidecrypto.xyz/studio/queries/2c2bac39-3b0b-4ad7-9b77-a45b56999cf0

    with all_events as (
    select
    block_timestamp,
    date_trunc('hour', block_timestamp) as hour,
    tx_hash,
    case
    when DECODED_LOG ['tokenIn'] = '0x0000000000000000000000000000000000000000' then '0x78c1b0c915c4faa5fffa6cabf0219da63d7f4cb8'
    else DECODED_LOG ['tokenIn']
    end as token_in,
    case
    when DECODED_LOG ['tokenOut'] = '0x0000000000000000000000000000000000000000' then '0x78c1b0c915c4faa5fffa6cabf0219da63d7f4cb8'
    else DECODED_LOG ['tokenOut']
    end as token_out,
    DECODED_LOG ['amountIn'] as amount_in,
    DECODED_LOG ['amountOut'] as amount_out,
    DECODED_LOG ['sender'] as user
    from
    mantle.core.ez_decoded_event_logs
    where
    contract_address = lower('0x45a62b090df48243f12a21897e7ed91863e2c86b')
    and ORIGIN_TO_ADDRESS = lower('0x45a62b090df48243f12a21897e7ed91863e2c86b') --only directly with router, ignore LO etc
    and block_timestamp > TO_TIMESTAMP(1742947200) -- Wednesday, 26 March 2025 00:00:00
    ),
    all_txs as (
    select
    block_timestamp,
    tx_hash,
    case
    when concat('0x', substring(INPUT_DATA, 11 + 24, 40)) = '0xb35033d71cf5e13cab5eb8618260f94363dff9cf' then 'LFJ'
    when concat('0x', substring(INPUT_DATA, 11 + 24, 40)) = '0xc04f291347d21dc663f7646056db22bff8ce8430' then (
    CASE
    WHEN SUBSTRING(INPUT_DATA, 11 + 24 + 8 * 64 + 2 * 40, 40) = '88de50b233052e4fb783d4f6db78cc34fea3e9fc' THEN 'ODOS'
    WHEN SUBSTRING(INPUT_DATA, 11 + 24 + 8 * 64 + 2 * 40, 40) = '6131b5fae19ea4f9d964eac0408e4408b66337b5' THEN 'KYBER'
    WHEN SUBSTRING(INPUT_DATA, 11 + 24 + 8 * 64 + 2 * 40, 40) = '38575264810371c15f0e5744fa2ab29cdef7245d' THEN 'OKX'
    Last run: about 1 month ago
    DAYS
    AVG_SWAP_USD_VALUE
    TOTAL_SWAP_USD_VALUE
    HIGHEST_VALUE_SWAP
    SWAPS_NUMBER
    USER_NUMBER
    AVERAGE_GAS_LIMIT
    AVERAGE_GAS_USED
    1
    2025-03-26 00:00:00.00034.7997530939848.3301253315392.91311715719818111951997945519.119185773084932.638258
    2
    2025-03-27 00:00:00.0007.7141948791913.120329996438.5843942931504587541892607455.299036757733928.140179
    3
    2025-03-28 00:00:00.00028.6536459541805.179695115957.86070316341620961963585408.761417923346044.02459
    4
    2025-03-29 00:00:00.00076.8204115854071.48181402970.3907875129744652009063566.073922918553813.117043
    5
    2025-03-30 00:00:00.00089.2232838183301.2615012491566.6370868473672208629561.950413940125593.55608
    6
    2025-03-31 00:00:00.000105.4151579292951.624422008999.6991888267523502632028241.3444151003118510.521277
    7
    2025-04-01 00:00:00.000118.5724272992608.5934005711446.8697514755692912192708791.441125928270454.358524
    8
    2025-04-02 00:00:00.000557.73838833513943.45970836610374.2344408274332202410482799.6997691130142611.441109
    9
    2025-04-03 00:00:00.00085.6546345771713.092691549844.6578425974322382405277597.754631159671622.300926
    10
    2025-04-04 00:00:00.000108.4334684561843.3689637531491.6937475043151712450203372.5142861148219962.212698
    11
    2025-04-05 00:00:00.00044.914656815808.463822678469.3765404583211722415454662.9595021016704270.255452
    12
    2025-04-06 00:00:00.00053.9390296421510.292829987999.9341049715362193444414712.3768661360024985.656716
    13
    2025-04-07 00:00:00.000544.91651640510898.3303281071740.0888279814912413050674970.7270881516552889.372709
    14
    2025-04-08 00:00:00.000130.7008343683659.62336231953.3075832974321812666496941.6481481164971266.726852
    15
    2025-04-09 00:00:00.00075.95306036911.436724322287.2822404483551853075515919.3577461274902351.983099
    16
    2025-04-10 00:00:00.00039.574802624316.598420995308.689669623071582593368350.2605861178018989.80456
    17
    2025-04-11 00:00:00.00044.276171334708.418741342267.3801888422951572946117570.5661021101273081.742373
    18
    2025-04-12 00:00:00.000141.1330807641975.863130693995.8077183161372341323020.0443041117305294.927215
    19
    2025-04-13 00:00:00.000146.0227489371898.2957361851067.2004733393211512417526195.3271031173934457.071651
    20
    2025-04-14 00:00:00.000117.4796879451527.2359432811000.0701073201602264683892.9718751121309444.753125
    79
    9KB
    8s