Afonso_DiazGrouping txns
    Updated 2025-02-13
    with

    pricet as (
    select
    hour::date as date,
    token_address,
    avg(price) as token_price_usd
    from
    ronin.price.ez_prices_hourly
    group by 1, 2
    ),

    main as (
    select
    tx_hash,
    block_timestamp,
    utils.udf_hex_to_int(topics[3])::bigint as amount_unadj,
    amount_unadj / pow(10, a.decimals) as amount,
    amount * token_price_usd as amount_usd,
    '0x' || right(topics[2], 40) as token_address,
    a.symbol,
    origin_from_address as user,
    iff(topics[0] = '0x5dac0c1b1112564a045ba943c9d50270893e8e826c49be8e7073adc713ab7bd7', 'Stake', 'Unstake') as event_name
    from
    ronin.core.fact_event_logs
    left join
    ronin.core.dim_contracts a on address = '0x' || right(topics[2], 40)
    left join
    pricet b on block_timestamp::date = date and b.token_address = a.address
    where
    tx_succeeded
    and origin_to_address = '0x05b0bb3c1c320b280501b86706c3551995bc8571'
    and topics[0] in ('0x5dac0c1b1112564a045ba943c9d50270893e8e826c49be8e7073adc713ab7bd7', '0xd8654fcc8cf5b36d30b3f5e4688fc78118e6d68de60b9994e09902268b57c3e3')
    )

    select
    QueryRunArchived: QueryRun has been archived