Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/with ranged_txns as(select *, ROW_NUMBER () over (partition by validatorId order by evt_block_time asc) as numfrom polygon_validator_contract_2_ethereum.StakingInfo_evt_StakeUpdateorder by validatorId asc, num desc), differences as(selectevt_block_time as time,DATE_TRUNC('day', evt_block_time) as day,validatorId,CAST(newAmount as double) /1e18 as newAmount,CAST(newAmount as double) /1e18 -(select--COALESCE(newAmount,0)COALESCE(max (CAST(newAmount as double))/1e18,0)from ranged_txns l2where l1.validatorId = l2.validatorIdand l2.num = l1.num -1)as differencefrom ranged_txns l1), total_MATIC_amounts as(SELECTday as time,SUM(difference) as daily_amount,SUM(SUM(difference)) over (order by day) AS TOTAL_stakedfrom differencesgroup by 1order by 1 desc),prices as --MATIC/stMATIC(selecttime,sum (price*amount) / sum(amount) as weight_avg_pricefrom(selectdate_trunc('day',evt_block_time) as time,CAST(_amount as double)/1e18 /(select max( CAST(value as DOUBLE))/1e18from lido_ethereum.StMATIC_evt_Transfer l2where l2.evt_tx_hash = l1.evt_tx_hash-- and "contract_address" = '\x9ee91F9f426fA633d227f7a9b000E28b9dfd8599'and l2.to = l1._from)as price,CAST(_amount as DOUBLE) /1e18 as amountfrom lido_ethereum.StMATIC_evt_SubmitEvent l1) ttgroup by 1)