SocioAnalyticafact swap [Thala]
    Updated 2025-03-09
    with
    fact_swaps as (
    SELECT
    a.block_number,
    a.block_timestamp,
    a.tx_hash,
    a.success,
    a.tx_type,
    a.payload_function,
    a.event_index,
    event_module,
    EVENT_RESOURCE,
    sender as swapper,
    event_data:idx_in as id_index_in,
    event_data:idx_out as id_index_out,
    event_data:amount_in as amounts_in,
    event_data:amount_out as amounts_out,
    CASE when id_index_in = '1' then SPLIT(event_type, ',')[1]
    when id_index_in = '0' then SPLIT_PART(SPLIT(event_type, ',')[0], '<', 2)
    end as token_in,
    CASE when id_index_out = '0' then SPLIT_PART(SPLIT(event_type, ',')[0], '<', 2)
    when id_index_out = '1' then SPLIT(event_type, ',')[1]
    end as token_out,
    SPLIT_PART(token_in, '::', 3) as symbol_in,
    SPLIT_PART(token_out, '::', 3) as symbol_out
    FROM aptos.core.fact_events a
    JOIN aptos.core.fact_transactions b ON a.tx_hash = b.tx_hash
    WHERE event_resource ilike 'Swap%'
    AND event_address = '0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af'
    )
    ,
    token_price as ( -- last price of each token
    SELECT *
    FROM (
    SELECT
    hour,
    Auto-refreshes every 24 hours
    QueryRunArchived: QueryRun has been archived