Skip to content

Commit a8893d8

Browse files
committed
feat: add Offline Election Tool grant application (Predifi Labs)
1 parent 2c5f7f7 commit a8893d8

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# Offline Election Tool
2+
3+
- **Team Name:** Predifi Labs
4+
- **Payment Details:**
5+
- **DOT**: 14B4RC9uUzh73C5RmHMU5VgevNPccmMTnvgYPp2Y8xeUtwZY (50% vested over 2 years)
6+
- **Payment**: 14B4RC9uUzh73C5RmHMU5VgevNPccmMTnvgYPp2Y8xeUtwZY (USDC on Polkadot AssetHub)
7+
- **[Level](https://grants.web3.foundation/docs/Introduction/levels):** 1
8+
9+
> **This application is in response to the [Offline Election Tool RFP](https://github.com/w3f/Grants-Program/blob/master/docs/RFPs/Open/offline-election-tool.md) by @michalisFr.**
10+
11+
## Project Overview :page_facing_up:
12+
13+
### Overview
14+
15+
**Tagline:** A modern Rust-based tool for accurately simulating Polkadot's NPoS election mechanism offline.
16+
17+
The Offline Election Tool aims to accurately simulate Polkadot's Nominated Proof-of-Stake (NPoS) election mechanism that determines active validators and nomination distribution. It replaces the legacy election simulator with a modern, flexible, and accurate Rust-based implementation. The tool supports both on-chain and synthetic data, exposes a CLI and HTTP API, and allows custom parameters and "what-if" scenarios for staking providers and the Decentralized Nodes program.
18+
19+
**Integration with Polkadot:** This tool directly interfaces with Polkadot's staking pallets and uses the same election algorithms (via `sp-npos-elections`) that run on-chain. It enables validators, nominators, and staking providers to predict election outcomes without executing actual on-chain elections.
20+
21+
**Motivation:** Accurate election simulation helps staking providers and decentralized node operators plan nomination strategies, forecast validator inclusion probabilities, and test stake distributions without triggering on-chain elections. The old script is outdated and lacks API support, custom account simulation, and algorithm flexibility. This project addresses these gaps by providing a production-ready, well-documented, and actively maintained tool.
22+
23+
### Project Details
24+
25+
**Technology Stack:**
26+
- **Language:** Rust
27+
- **Core Libraries:** `sp-npos-elections`, `sp-runtime`, `frame-election-provider-support`, `parity-scale-codec`
28+
- **API Framework:** Axum (lightweight async HTTP server)
29+
- **RPC Client:** `subxt` or `jsonrpsee` for on-chain data fetching
30+
- **CLI Framework:** `clap` for command-line interface
31+
32+
**Architecture Overview:**
33+
34+
1. **Data Ingestion Layer:**
35+
- Fetch on-chain state from Polkadot/Kusama via RPC at specific block heights
36+
- Accept JSON input files for offline or synthetic scenarios
37+
- Support custom accounts (unbonded or non-existent voters/candidates)
38+
39+
2. **Election Simulation Engine:**
40+
- Use Substrate's `sp-npos-elections` crate for precise NPoS election logic
41+
- Support configurable parameters:
42+
- Maximum active validators
43+
- Maximum nominators per validator
44+
- Minimum nomination threshold
45+
- Commission rates
46+
- Execute phragmén or phragmms algorithms as configured
47+
48+
3. **Output & API Layer:**
49+
- **CLI Mode:** Run simulations via command-line with results output to stdout or files
50+
- **HTTP API:**
51+
- `POST /simulate`: Submit election data and parameters, receive predicted results
52+
- `GET /params`: Retrieve current configuration
53+
- `GET /health`: Health check endpoint
54+
- Output includes:
55+
- Active validator set
56+
- Nomination distribution per validator
57+
- Score/backing for each validator
58+
- Edge assignments (nominator → validator)
59+
60+
**What This Project Will NOT Include:**
61+
- Token economics modeling or financial projections
62+
- Deployment hosting or cloud infrastructure
63+
- Marketing, events, or business development activities
64+
- Auditing services (though code will be production-ready and tested)
65+
66+
**Validation Approach:**
67+
- Cross-check simulation results against 20+ historical eras from Polkadot mainnet
68+
- Target >95% parity in active validator set composition
69+
- Target >95% accuracy in nomination distribution patterns
70+
- Automated integration tests comparing tool output vs. actual on-chain results
71+
72+
### Ecosystem Fit
73+
74+
**Where does this project fit?**
75+
This tool serves the Polkadot staking ecosystem by providing essential infrastructure for:
76+
- Validator operators planning their nomination strategies
77+
- Staking-as-a-Service providers optimizing delegation
78+
- The Decentralized Nodes program for simulating nomination scenarios
79+
- Researchers studying NPoS fairness, decentralization, and game theory
80+
81+
**Target Audience:**
82+
- Staking providers (e.g., Stakefish, P2P Validator, Chorus One)
83+
- Individual validators and nominators
84+
- Decentralized Nodes program participants
85+
- Polkadot governance contributors analyzing staking dynamics
86+
- Academic researchers studying NPoS mechanisms
87+
88+
**Needs Met:**
89+
- **Predictability:** Simulate election outcomes before committing stake
90+
- **Strategy Testing:** Test "what-if" scenarios with custom parameters
91+
- **Transparency:** Understand why specific validators are elected or excluded
92+
- **Automation:** Integrate election prediction into automated staking workflows via API
93+
94+
**Evidence of Need:**
95+
- The RFP itself indicates demand from the Web3 Foundation and Decentralized Nodes program
96+
- Community discussions on [Polkadot Forum](https://forum.polkadot.network/) frequently mention the need for better staking tools
97+
- Existing legacy script is rarely updated and lacks modern features (API, custom scenarios)
98+
99+
**Similar Projects:**
100+
- **Legacy Election Simulator:** Outdated Python/JavaScript script; lacks API, extensibility, and maintenance
101+
- **Polkadot Staking Dashboard:** Focuses on UI/UX for nominators but doesn't provide programmatic election simulation
102+
- **This Project's Differentiation:**
103+
- Built in Rust using official Substrate crates (same logic as on-chain)
104+
- Provides both CLI and HTTP API for integration
105+
- Supports custom/synthetic accounts for forward-looking scenarios
106+
- Actively maintained with comprehensive documentation and tests
107+
108+
**Related Ecosystems:**
109+
- Ethereum staking tools focus on validator rotation and rewards, but NPoS is unique to Polkadot
110+
- Cosmos staking is simpler (top-N validators); NPoS election logic is more complex and novel
111+
112+
## Team :busts_in_silhouette:
113+
114+
### Team members
115+
116+
- **Team Leader:** Devendra Tanwar
117+
- **AI Engineering Support:** GPT-5 (technical assistant for algorithm design and Substrate integration)
118+
119+
### Contact
120+
121+
- **Contact Name:** Devendra Tanwar
122+
- **Contact Email:** dev@predifi.com
123+
- **Website:** https://predifi.com
124+
125+
### Legal Structure
126+
127+
- **Registered Address:** To be provided during KYC/KYB process
128+
- **Registered Legal Entity:** Predifi Labs (registration details to be confirmed in KYC)
129+
130+
### Team's experience
131+
132+
**Devendra Tanwar** is a full-stack engineer with extensive experience in:
133+
- Backend systems development (Rust, Go, Python)
134+
- DeFi protocol integration and smart contract interactions
135+
- Substrate/Polkadot ecosystem contributions
136+
- Building developer tooling and APIs for blockchain applications
137+
138+
Prior work includes contributions to DeFi protocols, staking infrastructure, and data analytics pipelines for on-chain activity.
139+
140+
**GPT-5 AI Support:** Used for algorithm design, Substrate crate integration, and technical documentation to accelerate development while maintaining high code quality.
141+
142+
### Team Code Repos
143+
144+
- https://github.com/Predifi-com/offline-election-tool (to be created)
145+
- https://github.com/Predifi-com
146+
147+
Team member GitHub:
148+
- https://github.com/devendra-tanwar (or actual handle)
149+
150+
### Team LinkedIn Profiles
151+
152+
- https://www.linkedin.com/in/devendra-tanwar (placeholder - replace with actual)
153+
154+
## Development Status :open_book:
155+
156+
This application is in direct response to the **[Offline Election Tool RFP](https://github.com/w3f/Grants-Program/blob/master/docs/RFPs/Open/offline-election-tool.md)** published by @michalisFr.
157+
158+
**Research and Preparation:**
159+
- Reviewed the legacy election simulator and identified its limitations
160+
- Analyzed Substrate's `sp-npos-elections` crate and election-provider pallets
161+
- Studied Polkadot's staking mechanics via runtime code and on-chain data
162+
- Reviewed community discussions on staking strategy and tooling needs
163+
- Defined API specifications and data models for the HTTP interface
164+
165+
**References:**
166+
- [Polkadot NPoS Research](https://research.web3.foundation/Polkadot/protocols/NPoS)
167+
- [sp-npos-elections documentation](https://paritytech.github.io/substrate/master/sp_npos_elections/)
168+
- [Decentralized Nodes Program](https://wiki.polkadot.network/docs/thousand-validators)
169+
170+
## Development Roadmap :nut_and_bolt:
171+
172+
### Overview
173+
174+
- **Total Estimated Duration:** 4 weeks
175+
- **Full-Time Equivalent (FTE):** 1
176+
- **Total Costs:** 5,000 USD
177+
- **DOT %:** 50% (vested over 2 years)
178+
179+
### Milestone 1 — Update Original Script & Accurate Prediction
180+
181+
- **Estimated duration:** 2 weeks
182+
- **FTE:** 1
183+
- **Costs:** 2,500 USD
184+
185+
| Number | Deliverable | Specification |
186+
| -----: | ----------- | ------------- |
187+
| **0a.** | License | Apache 2.0 |
188+
| **0b.** | Documentation | Inline documentation for all modules, plus a comprehensive README with setup instructions, usage examples, and architecture overview. |
189+
| **0c.** | Testing and Testing Guide | Unit tests for core election logic, integration tests comparing results against historical on-chain elections. Guide will explain how to run tests locally. |
190+
| **0d.** | Docker | Dockerfile for building and running the tool in a containerized environment. |
191+
| 1. | Core Election Engine | Implement Rust-based election simulation using `sp-npos-elections` with support for phragmén/phragmms algorithms. |
192+
| 2. | On-Chain Data Fetching | Integrate RPC client to fetch staking state (validators, nominators, stakes, commissions) at specific block heights. |
193+
| 3. | JSON Input Support | Accept offline JSON files with custom staking data for simulation. |
194+
| 4. | Result Output | Generate detailed output: active validator set, nomination distribution, scores, and edge assignments. |
195+
| 5. | Validation Suite | Automated tests comparing tool output against 20+ historical Polkadot eras to ensure >95% accuracy. |
196+
197+
### Milestone 2 — Support Non-Existent Voters and Candidates
198+
199+
- **Estimated Duration:** 1 week
200+
- **FTE:** 1
201+
- **Costs:** 1,250 USD
202+
203+
| Number | Deliverable | Specification |
204+
| -----: | ----------- | ------------- |
205+
| **0a.** | License | Apache 2.0 |
206+
| **0b.** | Documentation | Updated README and inline docs explaining how to add synthetic accounts (unbonded or non-existent voters/candidates). |
207+
| **0c.** | Testing and Testing Guide | Unit tests for synthetic account handling, integration tests for "what-if" scenarios. |
208+
| **0d.** | Docker | Updated Dockerfile including new features. |
209+
| 1. | Synthetic Account Injection | Allow users to specify custom voters and candidates (not present on-chain or unbonded) via JSON input. |
210+
| 2. | What-If Scenarios | Enable testing of hypothetical stake distributions and candidate additions without altering on-chain data. |
211+
| 3. | Validation | Ensure synthetic accounts integrate correctly with election logic and produce valid results. |
212+
213+
### Milestone 3 — API Development (CLI + HTTP)
214+
215+
- **Estimated Duration:** 1 week
216+
- **FTE:** 1
217+
- **Costs:** 1,250 USD
218+
219+
| Number | Deliverable | Specification |
220+
| -----: | ----------- | ------------- |
221+
| **0a.** | License | Apache 2.0 |
222+
| **0b.** | Documentation | API reference documentation (OpenAPI/Swagger spec), CLI usage guide, and integration examples. |
223+
| **0c.** | Testing and Testing Guide | API endpoint tests, CLI integration tests, and performance benchmarks. |
224+
| **0d.** | Docker | Production-ready Docker image for running HTTP API server. |
225+
| **0e.** | Article | Publish a Medium/blog post explaining the tool's features, use cases, and how it benefits the Polkadot staking ecosystem. |
226+
| 1. | CLI Interface | Command-line tool with subcommands for running simulations, fetching on-chain data, and managing configurations. Uses `clap` for argument parsing. |
227+
| 2. | HTTP API | Axum-based REST API with endpoints: `POST /simulate`, `GET /params`, `GET /health`. JSON request/response format. |
228+
| 3. | API Documentation | OpenAPI 3.0 spec and interactive Swagger UI for API testing. |
229+
| 4. | Integration Guide | Step-by-step tutorial for integrating the tool into staking workflows (e.g., via curl, Postman, or automated scripts). |
230+
| 5. | Performance Optimization | Ensure simulations complete within reasonable time (<10s for typical Polkadot election size). |
231+
232+
## Future Plans
233+
234+
**Short-Term (0-6 months):**
235+
- Promote the tool within the Polkadot community via forum posts, Twitter, and developer workshops
236+
- Gather feedback from staking providers and iterate on features
237+
- Add support for Kusama and other Substrate-based chains
238+
239+
**Long-Term Maintenance:**
240+
- Monitor Substrate/Polkadot runtime upgrades and update the tool accordingly
241+
- Accept community contributions via GitHub (issues, PRs, feature requests)
242+
- Potential future grant for advanced features (e.g., historical analysis dashboard, gas-optimized smart contract integration)
243+
244+
**Sustainability:**
245+
- Tool will remain open-source and community-maintained
246+
- Predifi Labs will provide ongoing support as part of our Polkadot ecosystem contributions
247+
- Consider offering premium hosted API service for enterprise staking providers (self-funded)
248+
249+
## Additional Information :heavy_plus_sign:
250+
251+
**How did you hear about the Grants Program?**
252+
Web3 Foundation Website and the RFP announcement in the Grants-Program repository.
253+
254+
**Additional Context:**
255+
- This tool directly supports the **Decentralized Nodes program** by enabling offline validator selection prediction and nomination planning.
256+
- Benefits extend to staking providers, community validators, and researchers studying NPoS fairness and decentralization.
257+
- We are committed to delivering a production-ready, well-documented, and actively maintained tool that becomes a standard resource in the Polkadot staking ecosystem.
258+
259+
**Previous Work:**
260+
- No previous Web3 Foundation grants applied for by Predifi Labs.
261+
- Team has prior experience contributing to DeFi protocols and blockchain developer tooling in the Polkadot ecosystem.

0 commit comments

Comments
 (0)