Query editor
WITH staking_calls AS (SELECTblock_date AS day,value AS value_wei,data AS calldata,lower(substr(to_hex(data), 1, 8)) AS function_selectorFROM sei.transactionsWHERE"to" = 0x0000000000000000000000000000000000001005AND success = TRUEAND data IS NOT NULLAND length(data) >= 4),flows AS (SELECTday,-- delegate(string): increases stake by msg.value (18 decimals)CASEWHEN function_selector = '9ddb511a'THEN CAST(value_wei AS DOUBLE) / 1e18ELSE 0.0END AS delegated_sei,-- undelegate(string,uint256): decreases stake by amount (uSEI, 6 decimals)CASEWHEN function_selector = '8dfc8897'THEN CAST(bytearray_to_uint256(bytearray_substring(calldata, 37, 32)) AS DOUBLE) / 1e6ELSE 0.0END AS undelegated_sei-- redelegate is net 0 for total staked, so ignored hereFROM staking_calls),daily AS (SELECTday,SUM(delegated_sei) AS delegated_sei,SUM(undelegated_sei) AS undelegated_sei,SUM(delegated_sei) - SUM(undelegated_sei) AS net_staked_change_seiFROM flowsGROUP BY 1),bounds AS (SELECTMIN(day) AS min_day,MAX(day) AS max_dayFROM daily),calendar AS (SELECT t.day AS dayFROM bounds bCROSS JOIN UNNEST(sequence(b.min_day, b.max_day, interval '1' day)) AS t(day)),daily_filled AS (