Flipside TeamMoM - 1 year
    Updated 2024-09-22
    -- forked from MoM @ https://flipsidecrypto.xyz/studio/queries/a1150646-ad8e-4d02-a5e8-6909c6088972

    with MaticPrice as (select date_trunc('month', HOUR) AS date , median (PRICE) as MPrice
    from ethereum.price.ez_prices_hourly
    where SYMBOL = 'MATIC'
    group by 1) ,
    contracts as (with txs2 as (select TX_HASH
    from ethereum.core.ez_decoded_event_logs
    where CONTRACT_ADDRESS = '0x47cbe25bbdb40a774cc37e1da92d10c2c7ec897f'
    and CONTRACT_NAME = 'Matic Validator'
    and ORIGIN_FUNCTION_SIGNATURE = '0x6a761202'
    and ORIGIN_TO_ADDRESS = '0xfa7d2a996ac6350f4b56c043112da0366a59b74c') ,
    txs1 as (select TX_HASH
    from ethereum.core.ez_decoded_event_logs
    where CONTRACT_ADDRESS = '0x47cbe25bbdb40a774cc37e1da92d10c2c7ec897f'
    and CONTRACT_NAME = 'Matic Validator'
    and ORIGIN_FUNCTION_SIGNATURE = '0x4fdd20f1'
    and ORIGIN_TO_ADDRESS = '0x5e3ef299fddf15eaa0432e6e66473ace8c13d908')
    select date_trunc('month', BLOCK_TIMESTAMP) AS month,CONTRACT_ADDRESS
    from txs2 t left join ethereum.core.ez_decoded_event_logs e on t.TX_HASH=e.TX_HASH
    where EVENT_NAME = 'OwnershipTransferred'
    union
    select date_trunc('month', BLOCK_TIMESTAMP) AS month,CONTRACT_ADDRESS
    from txs1 t left join ethereum.core.ez_decoded_event_logs e on t.TX_HASH=e.TX_HASH
    where EVENT_NAME = 'OwnershipTransferred')
    , tot1 as (
    select
    date_trunc('month', BLOCK_TIMESTAMP) AS month,
    TO_ADDRESS as wallet,
    (RAW_AMOUNT / 1e18) as amount,
    CONTRACT_ADDRESS,
    'stake' as action
    from
    ethereum.core.ez_token_transfers
    where
    CONTRACT_ADDRESS in (
    QueryRunArchived: QueryRun has been archived