Sandeshroyalties earned
    Updated 2023-03-03



    SELECT signed_at::date as "date",
    sum((token_amount)/10e6) as royalties -- num_decimals for usdt is 6
    , sum(royalties) OVER (ORDER BY "date") as cummulative_royalties_in_USD
    FROM
    ((
    --Deposits (+)
    SELECT block_timestamp as signed_at,
    raw_amount as token_amount,
    contract_address as token_address
    FROM polygon.core.fact_token_transfers
    where 1=1
    -- and tx_hash=lower('0x32842066a5c3aa993fc850b52a1ac461edf287bf727d02a876ff8ce4bbc1d1ad')
    and contract_address='0xc2132d05d31c914a87c6611c10748aeb04b58e8f'
    and to_address='0x66e4e493bab59250d46bfcf8ea73c02952655206'

    )
    UNION ALL -- UNION Withdrawals and Deposits

    --Withdrawals (-)
    (
    SELECT block_timestamp::date as "date",
    -1.0 * raw_amount as token_amount -- Negative
    ,contract_address as token_address
    FROM polygon.core.fact_token_transfers e
    where 1=1
    -- and tx_hash=lower('0x32842066a5c3aa993fc850b52a1ac461edf287bf727d02a876ff8ce4bbc1d1ad')
    and contract_address='0xc2132d05d31c914a87c6611c10748aeb04b58e8f'
    and to_address='0x66e4e493bab59250d46bfcf8ea73c02952655206'

    ))
    GROUP BY "date"
    ORDER BY "date" desc

    Run a query to Download Data