---
id: TASK-144
title: Power Indices for DAO Governance Analysis
status: Done
assignee: []
created_date: '2026-04-16 18:50'
labels:
  - rnetwork
  - governance
  - encryptid
  - trust-engine
dependencies: []
references:
  - src/encryptid/power-indices.ts
  - src/encryptid/trust-engine.ts
  - src/encryptid/schema.sql
  - modules/rnetwork/components/folk-graph-viewer.ts
  - modules/rnetwork/mod.ts
priority: medium
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Banzhaf & Shapley-Shubik power index computation for rSpace delegation system. Reveals who actually controls outcomes vs raw delegation weights.

## Implemented
- **Compute engine** (`src/encryptid/power-indices.ts`): Banzhaf DP O(n·Q), Shapley-Shubik DP O(n²·Q), Gini coefficient, HHI concentration
- **DB schema**: `power_indices` table (PK: did, space_slug, authority) with materialized results
- **Background job**: Hooks into trust engine 5-min recompute cycle
- **API**: GET `/api/power-indices?space=X&authority=Y`, GET `/api/power-indices/:did`, POST `/api/power-indices/simulate` (coalition what-if)
- **Visualization**: Power tab in rNetwork 3D graph viewer — animated Banzhaf bars, Gini/HHI gauges, node sizing by coalitional power
- **On-demand compute**: First API hit computes + caches if DB empty

## Future Integration Opportunities
- **Delegation Dashboard** (`folk-delegation-manager.ts`): Show each user their own Banzhaf power next to their delegation weights. "Your 10% weight gives you 23% voting power" insight.
- **rVote conviction voting**: Weight votes by Shapley-Shubik instead of raw tokens — prevents plutocratic capture
- **fin-ops blending**: Blend $MYCO token balances with delegation weights (configurable ratio) for fin-ops authority power indices
- **Trust Sankey** (`folk-trust-sankey.ts`): Color/thickness flows by marginal power contribution, not just raw weight
- **Space admin dashboard**: Alert when Gini > 0.6 or HHI > 0.25 (concentration warning)
- **rData analytics**: Time-series of power concentration metrics (Gini trend, effective voters trend)
- **Coalition builder UI**: Interactive "what if we form this coalition?" tool using the simulate endpoint
- **Quadratic power weighting**: Use sqrt(Banzhaf) as vote weight to reduce inequality
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [ ] #1 Banzhaf & Shapley-Shubik computed via DP (not brute force)
- [ ] #2 Results materialized in PG, recomputed every 5 min
- [ ] #3 3 API endpoints (list, per-user, simulate)
- [ ] #4 Power tab in rNetwork graph viewer with animated bars + gauges
- [ ] #5 Node sizes reflect Banzhaf power in power mode
- [ ] #6 On-demand computation when DB empty
<!-- AC:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Implemented Banzhaf and Shapley-Shubik power index computation integrated into the trust engine's 5-min background cycle. Power indices table in PG stores materialized results per (did, space, authority). Three API endpoints on EncryptID server with rNetwork proxy routes. Visualization integrated into 3D graph viewer as Power tab — animated bar chart showing weight/Banzhaf/Shapley-Shubik per player, Gini and HHI concentration gauges, and Banzhaf-scaled node sizing. Also fixed encryptid Dockerfile missing welcome-email.ts and swapped mouse controls to left-drag=rotate.

Commits: 97c1b02 (feature), 1bc2a0a (Dockerfile fix). Deployed to Netcup, live at demo.rspace.online/rnetwork/power.
<!-- SECTION:FINAL_SUMMARY:END -->
