Updated 2023-09-15
    WITH amount_values AS (
    SELECT
    ethereum_tx_amounts.amount / pow(10, ifnull(token_contracts.decimals, 18)) * latest_prices.price AS amount_usd_value
    FROM
    (
    SELECT
    iff(
    input_table.value [0] = '0x0000000000000000000000000000000000000000',
    '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    input_table.value [0]
    ) as token,
    SUM(input_table.value [1]) as amount
    FROM
    ethereum.core.fact_decoded_event_logs,
    lateral flatten(input => decoded_log ['order'] [0]) as input_table
    WHERE
    CONTRACT_ADDRESS IN (
    '0x50084c51f6d7e9801b6a7bdba85822db985465fe',
    '0x2f6427d6437d69a2a2ae5cc7cd6496fd4c170365',
    '0x87259d957709ff337a5969d7778e459262d1575c'
    )
    GROUP BY
    1
    ) as ethereum_tx_amounts
    LEFT JOIN ethereum.core.dim_contracts as token_contracts ON ethereum_tx_amounts.token = token_contracts.address
    LEFT JOIN (
    SELECT
    TOKEN_ADDRESS,
    PRICE
    FROM
    (
    SELECT
    TOKEN_ADDRESS,
    price,
    ROW_NUMBER() OVER (
    PARTITION BY TOKEN_ADDRESS
    Run a query to Download Data