winnie-fsLB Overall Swap Volume copy
    Updated 2023-04-19
    -- forked from cloudr3n / LB Overall Swap Volume @ https://flipsidecrypto.xyz/cloudr3n/q/untitled-query-GKh_4S

    with
    ab_tb as (
    select
    *,
    case
    when topics[0] = '0x2c8d104b27c6b7f4492017a6f5cf3803043688934ebcaa6a03540beeaf976aff' then 'LBPairCreated'
    when topics[0] = '0x63a7af39b7b68b9c3f2dfe93e5f32d9faecb4c6c98733bb608f757e62f816c0d' then 'FeeParametersSet'
    else event_name
    end as event_name1
    from
    arbitrum.core.fact_event_logs
    where
    contract_address = '0x1886d09c9ade0c5db822d85d21678db67b6c2982'
    -- tx_hash = '0x81fc8e10010040ed205312f5c4d453914771c553a595d53e87319ab8b0975c4d' --contract_address=lower('0xafeBf9bBa7984954e42d7551AB0cE47130BfDC0A') -- and event_name='LBPairCreated'
    order by
    block_timestamp,
    event_index asc
    ),
    ab_lbpair1 as (
    SELECT
    *,
    concat('0x', right(substr(topics[1], 3 + 24, 64), 40)) as tokenX,
    concat('0x', right(substr(topics[2], 3 + 24, 64), 40)) as tokenY,
    concat('0x', right(substr(data, 1 + 2 + 64 * 0, 64), 40)) as LBPair01,
    ethereum.public.udf_hex_to_int (substr(data, 1 + 2 + 64 * 1, 64)) as pid
    FROM
    ab_tb
    WHERE
    event_name1 = 'LBPairCreated'
    ),
    ab_lbpair2 as (
    SELECT
    *,
    concat('0x', right(substr(topics[2], 3 + 24, 64), 40)) as LBPair02,
    Run a query to Download Data