Mrftitremendous-fuchsia
    Updated 12 hours ago
    -- Step 1: Define the new transfers CTE
    with new_transfers as (
    select
    '0x' || RIGHT(TOPIC_1, 40) AS from_address,
    '0x' || RIGHT(TOPIC_2, 40) AS to_address,
    CAST(ethereum.public.udf_hex_to_int(SUBSTR(DATA, 3)) AS DECIMAL) / pow(10,18) AS amount
    from swell.core.fact_event_logs
    where ORIGIN_FUNCTION_SIGNATURE = '0xa9059cbb' -- transfer
    and contract_address = '0x2826d136f5630ada89c1678b64a61620aab77aea'
    ),
    -- Step 2: Check raw transfer data (for debugging)
    raw_check as (
    select
    from_address,
    to_address,
    amount
    from new_transfers
    ),
    -- Step 3: Calculate inputs and outputs
    tbl as (
    select
    to_address as "Address",
    sum(amount) as "Input"
    from new_transfers
    group by 1
    ),
    tbl2 as (
    select
    from_address as "Address",
    sum(amount) as "Output"
    from new_transfers
    group by 1
    ),
    -- Step 4: Combine and calculate balances
    tbl3 as (
    select
    Last run: about 12 hours agoAuto-refreshes every 12 hours
    Total supply
    1
    170283042.591944
    1
    20B
    4s