saeedmznUntitled Query
    Updated 2023-01-07
    with clipper AS (select
    BLOCK_NUMBER,
    BLOCK_TIMESTAMP,
    TX_HASH,
    ORIGIN_FROM_ADDRESS AS trader,
    concat('0x',substr(TOPICS[1],27,41)) AS TOKEN_IN,
    B.symbol AS SYMBOL_IN,
    tokenflow_eth.hextoint(substr(data,49,18))/power(10,B.DECIMALS) AS AMOUNT_IN,
    AMOUNT_IN*d.price AS AMOUNT_IN_USD,
    concat('0x',substr(TOPICS[2],27,41)) AS TOKEN_OUT,
    C.symbol AS SYMBOL_OUT,
    tokenflow_eth.hextoint(substr(data,113,18))/power(10,C.DECIMALS) AS AMOUNT_OUT,
    AMOUNT_OUT*e.price AS AMOUNT_OUT_USD
    from optimism.core.fact_event_logs A inner join optimism.core.dim_contracts B on concat('0x',substr(TOPICS[1],27,41))=B.ADDRESS
    inner join optimism.core.dim_contracts C on concat('0x',substr(TOPICS[2],27,41))=C.ADDRESS
    inner join optimism.core.fact_hourly_token_prices D on D.TOKEN_ADDRESS=concat('0x',substr(TOPICS[1],27,41)) and date_trunc('HOUR',BLOCK_TIMESTAMP)=D.HOUR
    inner join optimism.core.fact_hourly_token_prices e on e.TOKEN_ADDRESS=concat('0x',substr(TOPICS[2],27,41)) and date_trunc('HOUR',BLOCK_TIMESTAMP)=e.HOUR
    where ORIGIN_TO_ADDRESS=lower('0x5130f6cE257B8F9bF7fac0A0b519Bd588120ed40') and TOPICS[0]='0x4be05c8d54f5e056ab2cfa033e9f582057001268c3e28561bb999d35d2c8f2c8'),
    beethoven AS (
    select BLOCK_NUMBER,BLOCK_TIMESTAMP,TX_HASH,ORIGIN_FROM_ADDRESS AS trader,
    EVENT_INPUTS:tokenIn AS TOKEN_IN,
    B.symbol AS SYMBOL_IN,
    EVENT_INPUTS:amountIn/power(10,B.DECIMALS) AS AMOUNT_IN,
    AMOUNT_IN*d.price AS AMOUNT_IN_USD,
    EVENT_INPUTS:tokenOut AS TOKEN_OUT,
    c.symbol AS SYMBOL_OUT,
    EVENT_INPUTS:amountOut/power(10,C.DECIMALS) AS AMOUNT_OUT,
    AMOUNT_OUT*e.price AS AMOUNT_OUT_USD
    from optimism.core.fact_event_logs
    inner join optimism.core.dim_contracts B on EVENT_INPUTS:tokenIn=B.ADDRESS
    inner join optimism.core.dim_contracts C on EVENT_INPUTS:tokenOut=C.ADDRESS
    inner join optimism.core.fact_hourly_token_prices D on D.TOKEN_ADDRESS=EVENT_INPUTS:tokenIn and date_trunc('HOUR',BLOCK_TIMESTAMP)=D.HOUR
    inner join optimism.core.fact_hourly_token_prices e on e.TOKEN_ADDRESS=EVENT_INPUTS:tokenOut and date_trunc('HOUR',BLOCK_TIMESTAMP)=e.HOUR
    where ORIGIN_TO_ADDRESS='0xba12222222228d8ba445958a75a0704d566bf2c8'
    and EVENT_NAME='Swap'
    ),
    Run a query to Download Data