MLDZMNswap hours
    Updated 2024-03-17

    with tb1 as (select
    BLOCK_TIMESTAMP,
    BLOCK_NUMBER,
    CONTRACT_ADDRESS,
    TX_HASH,
    ORIGIN_FROM_ADDRESS as trader,
    topics[0]::string,
    lower('0x' || substr(topics[1]::string, 27, 40) :: string) as base,
    lower('0x' || substr(topics[2]::string, 27, 40) :: string) as quote,
    REGEXP_SUBSTR_ALL(SUBSTR(data, 3, len(data)), '.{64}') as particial_data,
    livequery.utils.udf_hex_to_int(particial_data[0]::string) :: int as poolIdx,
    livequery.utils.udf_hex_to_int(particial_data[1]::string) :: int as isBuy, --True if the user wants to pay base token and receive quote token. False if the user wants to receive base token and pay quote token
    livequery.utils.udf_hex_to_int(particial_data[2]::string) :: int as inBaseQty, --True if the quantity field is fixed in base token, false in quote token.
    livequery.utils.udf_hex_to_int(particial_data[3]::string) :: int as qty, -- The quantity of the fixed side of the swap
    livequery.utils.udf_hex_to_int(particial_data[4]::string) :: int as tip, --If zero the user accepts the standard swap fee rate in the pool. If non-zero the user agrees to pay up to this swap fee rate to the pool's LPs. In standard cases this should be 0.
    livequery.utils.udf_hex_to_int(particial_data[5]::string) :: int as limitPrice, -- Represents the worse possible price the user is willing to accept.
    livequery.utils.udf_hex_to_int(particial_data[6]::string) :: int as minOut, -- Minimum (maximum) expected output (input) of the token being bought (sold).
    livequery.utils.udf_hex_to_int(particial_data[7]::string) :: int as settleFlags -- Flag indicating how the user wants to settle the traded tokens for this swap.

    from blast.core.fact_event_logs
    where CONTRACT_ADDRESS = '0xaaaaaaaaffe404ee9433eef0094b6382d81fb958'
    --and tx_hash = '0x60c2b6c07ccc701dd22e4492456bf3f5588d99e0b82dedfaa4bc2a86737f8e45'
    and topics[0] ='0x5d7a6c346454f5c536b7f52655e780f6db27b15b489f80f2dbb288c9e4f366bd'
    ),

    tb2 as (select
    BLOCK_TIMESTAMP,
    BLOCK_NUMBER,
    TX_HASH,
    trader,
    case when base = '0x0000000000000000000000000000000000000000' then 'ETH' else base end as Base_token,
    case when quote = '0x0000000000000000000000000000000000000000' then 'ETH' else quote end as quote_token,
    poolIdx, -- 420 by default
    case when isBuy = 1 then Base_token else quote_token end as token_in,
    case when isBuy = 1 then quote_token else Base_token end as token_out,
    QueryRunArchived: QueryRun has been archived