Sandeshnekodex swaps chains date
    Updated 2025-02-01
    /*
    This SQL query analyzes cross-chain token swaps across multiple blockchain networks
    (Optimism, Ethereum, Base, and Arbitrum). It decodes event logs to extract swap details,
    combines data from different chains, and calculates trading volumes and user counts.
    */

    WITH decoded_swaps AS
    (
    -- Decode and combine swap data from multiple chains
    WITH optimism_swaps AS
    (
    -- Decode Optimism intra-chain swaps
    WITH intra_chain_swaps AS
    (
    SELECT
    tx_hash,
    block_timestamp,
    regexp_substr_all(SUBSTR(data, 3), '.{64}') AS decoded_data,
    concat('0x', substr(topics[1], -40)) AS swap_user,
    10 AS from_chain_id, -- Optimism chain ID
    10 AS to_chain_id, -- Optimism chain ID for intra-chain swaps
    concat('0x', substr(decoded_data[0], -40)) AS from_token,
    concat('0x', substr(decoded_data[2], -40)) AS from_token_value,
    utils.udf_hex_to_int(from_token_value) AS from_token_value_int,
    concat('0x', substr(decoded_data[1], -40)) AS to_token,
    concat('0x', substr(decoded_data[3], -40)) AS to_token_value,
    utils.udf_hex_to_int(to_token_value) AS to_token_value_int
    FROM optimism.core.fact_event_logs
    WHERE 1 = 1
    AND contract_address = '0x6cca65f0bc3140019a81a1619aa75a6925c2601e' -- Swap contract
    AND topics[0] = '0x900d96b4c36401fe685c5409d45d609db06c639ef658c6cfef098061d05aadc9' -- Swap event signature
    AND origin_from_address = '0xd19454648eedd9bee8d75142d503c5ee9179fc70' -- Specific swap initiator
    ),
    -- Decode Optimism inter-chain swaps
    inter_chain_swaps AS
    (
    Last run: 3 months agoAuto-refreshes every 24 hours
    DATE
    CHAIN
    NUMBER_OF_USERS
    VOLUME
    1
    2024-12-22 00:00:00.000base177442.140733344
    2
    2024-12-12 00:00:00.000optimism17231621.998519186
    3
    2024-12-27 00:00:00.000optimism10218242.635224588
    4
    2025-01-07 00:00:00.000base3236679.712654009
    5
    2024-11-13 00:00:00.000base191573.348246281
    6
    2025-01-04 00:00:00.000arbitrum1934763.399345887
    7
    2024-11-14 00:00:00.000optimism17525401.276631627
    8
    2024-11-20 00:00:00.000optimism19114943.732155995
    9
    2024-12-26 00:00:00.000arbitrum65144030.449170593
    10
    2024-10-08 00:00:00.000arbitrum5014812.947557615
    11
    2024-09-22 00:00:00.000arbitrum33263.004691935
    12
    2024-11-17 00:00:00.000base141428.149448839
    13
    2025-01-12 00:00:00.000optimism641655.808163074
    14
    2024-08-16 00:00:00.000ethereum41286.632017051
    15
    2024-11-11 00:00:00.000optimism78247685.335812078
    16
    2025-01-11 00:00:00.000base296376.578430249
    17
    2024-12-26 00:00:00.000base69149693.980836757
    18
    2025-01-10 00:00:00.000base3119530.809579942
    19
    2024-12-24 00:00:00.000arbitrum3213293.26801331
    20
    2024-10-14 00:00:00.000optimism668755.41010888
    ...
    672
    36KB
    226s