Query editor
-- 1inch DAO: Cost of attack/denial-- = average UP participation over the last 10 closed 1inch.eth proposals, converted to USDWITH last_n_resp AS (SELECT http_post('https://hub.snapshot.org/graphql','{"query":"{ proposals(first: 10, where: {space: \"1inch.eth\", state: \"closed\"}, orderBy: \"end\", orderDirection: desc) { scores_total } }"}',ARRAY['Content-Type: application/json']) AS body),last_n AS (SELECT COUNT(*) AS n,AVG(CAST(json_extract_scalar(x, '$.scores_total') AS DOUBLE)) AS avg_upFROM last_n_respCROSS JOIN UNNEST(CAST(json_extract(body, '$.data.proposals') AS ARRAY(JSON))) AS t(x)),prop_resp AS (SELECT http_post('https://hub.snapshot.org/graphql','{"query":"{ proposals(first: 1, where: {space: \"1inch.eth\", state: \"closed\"}, orderBy: \"end\", orderDirection: desc) { id scores_total } }"}',ARRAY['Content-Type: application/json']) AS body),prop AS (SELECT json_extract_scalar(body, '$.data.proposals[0].id') AS id,CAST(json_extract_scalar(body, '$.data.proposals[0].scores_total') AS DOUBLE) AS total_upFROM prop_resp),votes_resp AS (SELECT http_post('https://hub.snapshot.org/graphql','{"query":"{ votes(first: 1000, where: {proposal: \"' || id || '\"}) { voter vp } }"}',ARRAY['Content-Type: application/json']) AS bodyFROM prop),votes AS (SELECT from_hex(substr(lower(json_extract_scalar(v, '$.voter')), 3)) AS voterFROM votes_respCROSS JOIN UNNEST(CAST(json_extract(body, '$.data.votes') AS ARRAY(JSON))) AS t(v)),params AS (SELECT rpad(to_utf8('1inch.eth'), 32, 0x00) AS space_id,rpad(0x00, 32, 0x00) AS global_id),evts AS (SELECT delegator, id, delegate, evt_block_number, evt_index, 'set' AS kindFROM snapshot_ethereum.DelegateRegistry_evt_SetDelegate, paramsWHERE id IN (space_id, global_id)UNION ALLSELECT delegator, id, delegate, evt_block_number, evt_index, 'clear' AS kindFROM snapshot_ethereum.DelegateRegistry_evt_ClearDelegate, paramsWHERE id IN (space_id, global_id)),ranked AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY delegator, id ORDER BY evt_block_number DESC, evt_index DESC) AS rnFROM evts),active AS (SELECT delegator, id, delegate FROM ranked WHERE rn = 1 AND kind = 'set'),