fusionCopy of Test query
    Updated 2021-11-11
    with
    Received as -- we extract the amount of tokens received from the terraswap pool from the msg_events table
    (SELECT
    block_id,
    block_timestamp,
    REGEXP_SUBSTR(EVENT_ATTRIBUTES:amount, '[0-9].[0-9]*[e][+][0-9]*')::NUMERIC/1000000 as amt_received,
    substring(REGEXP_SUBSTR(EVENT_ATTRIBUTES:amount, '([denom]*.[:]) *["]([a-z]*)'),9,100)::text as token_received,
    REGEXP_SUBSTR(EVENT_ATTRIBUTES:sender, '[terra]*.[^"]*') as terraswap_pool,
    REGEXP_SUBSTR(EVENT_ATTRIBUTES:recipient, '[terra]*.[^"]*') as sender,
    event_type,
    tx_id,
    msg_type,
    EVENT_ATTRIBUTES
    FROM terra.msg_events
    WHERE event_type = 'transfer' AND msg_type = 'wasm/MsgExecuteContract' AND terraswap_pool = 'terra1jxazgm67et0ce260kvrpfv50acuushpjsz2y0p' --Here we specify the bLUNA-LUNA terraswap pool, and the particular event (transfer) that we want to extract the data from; Other conditions are also meant to cut down on the potential results
    ),

    traded as -- we extract the tokens sent to the terraswap pool from the msgs table
    (SELECT
    block_id,
    block_timestamp,
    REGEXP_SUBSTR(MSG_VALUE:execute_msg,'[0-9].[0-9]*[e][+][0-9]*')::NUMERIC/1000000 as amt_sent,
    REGEXP_SUBSTR(MSG_VALUE:contract,'^.*') as address_token_sent,
    substring(REGEXP_SUBSTR(MSG_VALUE:execute_msg,'[a-z][a-z][a-z][a-z][a-z][a-z][a-z][a-z]["][:] *["][^"]*'),12,100) as terraswap_pool,
    REGEXP_SUBSTR(MSG_VALUE:sender,'^.*') as sender,
    substring(REGEXP_SUBSTR(MSG_VALUE:execute_msg,'[a-z][a-z][a-z][a-z][a-z][a-z][_][a-z][a-z][a-z][a-z][a-z]["][:] *[0-9][.][0-9]*'),15,100)::FLOAT as belief_price,
    msg_type,
    tx_id,
    msg_value:execute_msg
    FROM terra.msgs
    WHERE msg_type = 'wasm/MsgExecuteContract' AND terraswap_pool = 'terra1jxazgm67et0ce260kvrpfv50acuushpjsz2y0p' AND address_token_sent = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp' -- We define the terraswap pool in scope as the bLUNA-LUNA pool, and the asset swapped as bLUNA
    ),

    staging as -- we combine the tables in this table so that the last table can be a clean select statement where the user can focus on filters for
    (SELECT
    Run a query to Download Data