Query editor
-- https://dune.com/queries/3655065with dedup_votes as (--governance_optimism.proposal_votes has duplicated rowsselecttx_hash, date_timestamp, voter, proposal_id-- max,因为是重复的,取任意值都可以-- ln是为了压缩数据范围,使分布尽可能正太, ln(max(votingweightage + 1e-6)) as votepowerfrom governance_optimism.proposal_votesgroup by 1,2,3,4), votepower_range as (selectmin_vpower*if(min_vpower>0, 0.99, 1.01) as min_vpower, (max_vpower*if(max_vpower>0, 1.01, 0.99) - min_vpower*if(min_vpower>0, 0.99, 1.01))/{{bins}} as bin_widthfrom (selectmin(votepower) as min_vpower, max(votepower) as max_vpowerfrom dedup_votes)), votepower_bins as (selectbin_idx, lb, ub, '[' || cast(cast(exp(lb) as int) as varchar) || ',' || cast(cast(exp(ub) as int) as varchar) || ')' as bin_rangefrom (selectbin_idx, r.min_vpower + (bin_idx-1)*r.bin_width as lb, r.min_vpower + bin_idx * r.bin_width as ubfrom unnest(sequence(1,{{bins}})) as tbl(bin_idx)cross join votepower_range r)), votepower_binned as (selectvoter, proposal_id, votepower, b.bin_idx as vpower_bin_idx, b.bin_range as vpower_binfrom dedup_votes vleft join votepower_bins bon v.votepower >= b.lband v.votepower < b.ub), proposals_onlyone_topic as (-- 因为Dune不允许太复杂、太深的subquery调用-- 这里不得不让每个proposal只有一个topic,方便group by-- 好在现时拥有多个topic的并不多select