austinbBalancer Swaps
    Updated 2022-07-05
    -- I start by digging through the event logs and looking for 'TokensResgistered' events
    -- These correspond to pool creation events and tell us the address of the tokens and their positions
    -- Please note there may be more than 5 tokens in a pool, could add to this step and the final join to add more using the same logic, if necessary
    WITH vault_creation AS (
    SELECT
    tx_hash,
    event_inputs :poolId :: STRING AS poolId,
    LOWER(
    event_inputs :tokens [0] :: STRING
    ) AS token0,
    LOWER(
    event_inputs :tokens [1] :: STRING
    ) AS token1,
    LOWER(
    event_inputs :tokens [2] :: STRING
    ) AS token2,
    LOWER(
    event_inputs :tokens [3] :: STRING
    ) AS token3,
    LOWER(
    event_inputs :tokens [4] :: STRING
    ) AS token4,
    event_inputs :tokens AS token_array
    FROM
    ethereum.core.fact_event_logs
    WHERE
    event_name = 'TokensRegistered'
    ),
    -- I next look for 'Swap' events emiited from the balancer vault
    -- The inputs here are decoded, so I can easily find the amount in and amount out
    -- Here we can also find details about the swap such as the token address in, token address out, and the poolId / pool address
    -- This is filtered for just the last week of data
    -- If there is a pool you care about, I would filter for it here
    swaps AS (
    SELECT
    tx_hash,
    Run a query to Download Data