Query editor
WITH decoded_logs AS (SELECTvarbinary_ltrim(topic1) AS user,block_time,--data,varbinary_to_uint256(varbinary_substring(data, 1+32*0, 32))/1e18 AS amtNative,varbinary_to_uint256(varbinary_substring(data, 1+32*1, 32))/1e18 AS amtEqual,varbinary_to_uint256(varbinary_substring(data, 1+32*2, 32)) AS lockId,varbinary_to_uint256(varbinary_substring(data, 1+32*3, 32))/1e18 AS usrTotBuy,varbinary_to_uint256(varbinary_substring(data, 1+32*4, 32))/1e18 AS usrTotLock,varbinary_to_uint256(varbinary_substring(data, 1+32*5, 32))/1e18 AS totBuy,varbinary_to_uint256(varbinary_substring(data, 1+32*6, 32))/1e18 AS totLock,varbinary_to_uint256(varbinary_substring(data, 1+32*7, 32))/1e18 AS p2r0,varbinary_to_uint256(varbinary_substring(data, 1+32*8, 32))/1e18 AS p2r1,varbinary_to_uint256(varbinary_substring(data, 1+32*9, 32))/1e18 AS coinusd,varbinary_to_uint256(varbinary_substring(data, 1+32*10, 32))/1e18 AS wen,varbinary_to_uint256(varbinary_substring(data, 1+32*11, 32))/1e18 AS users,varbinary_to_uint256(varbinary_substring(data, 1+32*12, 32)) AS interactionsFROM base.logsWHERE contract_address = 0x4Bcb116341B0dE791a0105e6CaEbb93b9b12AAF9AND topic0 = 0x5346f18f32b745e2cc45d1a743c225e39d7389e780746be567342186dae3a248ORDER BY block_time),allocks as (SELECT *, amtNative/amtEqual AS buyLockPrice, usrTotBuy/usrTotLock as usrAvgBuyLockPrice, totBuy/totLock as avgBuyLockPrice,sum(amtNative) over() nativeGrandTotal, sum(amtEqual) over() as EqualGrandTotalFROM decoded_logs),res as(SELECT user, SUM(amtNative) as usrTotalNative, SUM(amtNative/nativeGrandTotal*1000000) as airdrop, SUM(amtNative/nativeGrandTotal) as airdropPercent,SUM(amtEqual) as usrTotalEqual, SUM(amtEqual/EqualGrandTotal*1000000) as airdropE, SUM(amtEqual/EqualGrandTotal) as airdropPercentEFROM allocksGROUP BY USERORDER BY 2 DESC)select * , airdropPercent - airdropPercentE as airdropDiff,CASEWHEN airdropPercent > airdropPercentE THEN (airdropPercent - airdropPercentE)/airdropPercentEWHEN airdropPercentE > airdropPercent THEN -(airdropPercentE - airdropPercent)/airdropPercentEEND as AirdropChange,AirdropPercent as AirdropByETH, airdropPercentE as AirdropByScalefrom resORDER BY airdropChange DESC