Mikey_Bebop
    Updated 2022-11-10
    with bebop_supported_tokens as
    (
    select
    distinct contract_address
    from polygon.core.fact_event_logs
    where origin_to_address = '0xaf0b0000f0210d0f421f0009c72406703b50506b' and
    origin_function_signature in ('0x4263b9ab', '0x8c4bd1cb') and
    event_name = 'Transfer' and
    event_inputs:"from"::string = '0xaf0b0000f0210d0f421f0009c72406703b50506b'
    ),
    polygon_decimals as
    (
    select distinct token, decimals
    from
    (
    select token0_address as token, token0_decimals as decimals
    from polygon.sushi.dim_dex_pools
    where token0_decimals is not null and
    token0_address in (select * from bebop_supported_tokens)

    union all

    select token1_address as token, token1_decimals as decimals
    from polygon.sushi.dim_dex_pools
    where token1_decimals is not null and
    token1_address in (select * from bebop_supported_tokens)
    )
    ),
    polygon_prices as
    (
    select
    avg(price) as price,
    symbol,
    token,
    "Date"
    from
    Run a query to Download Data