|
| 1 | +<!-- |
| 2 | +Sync Impact Report: |
| 3 | +- Version change: INITIAL → 1.0.0 |
| 4 | +- New principles added: |
| 5 | + 1. Type Safety & Code Quality |
| 6 | + 2. Provider Agnostic Architecture |
| 7 | + 3. Comprehensive Testing |
| 8 | + 4. Performance & Reliability |
| 9 | + 5. Developer Experience & Documentation |
| 10 | + 6. Blockchain Best Practices |
| 11 | +- New sections added: |
| 12 | + - Core Principles (6 principles) |
| 13 | + - Quality Standards |
| 14 | + - Development Workflow |
| 15 | + - Governance |
| 16 | +- Templates updated: |
| 17 | + ✅ plan-template.md - Added Constitution Check section with all 6 principles |
| 18 | + ✅ spec-template.md - Added Non-Functional Requirements section referencing constitution |
| 19 | + ✅ tasks-template.md - Updated to require tests per constitution, aligned file paths with TypeScript, added constitution compliance to Polish phase |
| 20 | +- No command files to update (none exist) |
| 21 | +- Follow-up TODOs: None |
| 22 | +--> |
| 23 | + |
| 24 | +# Mento SDK Constitution |
| 25 | + |
| 26 | +## Core Principles |
| 27 | + |
| 28 | +### I. Type Safety & Code Quality |
| 29 | + |
| 30 | +The Mento SDK MUST maintain the highest standards of type safety and code quality to ensure reliability in blockchain interactions. |
| 31 | + |
| 32 | +**Non-negotiable rules:** |
| 33 | +- TypeScript strict mode MUST be enabled for all source code |
| 34 | +- All exported functions, classes, and methods MUST have explicit type annotations |
| 35 | +- No `any` types permitted in public APIs (internal use requires documented justification) |
| 36 | +- ESLint and Prettier MUST pass with zero warnings on all code |
| 37 | +- All code MUST follow the established architectural patterns (adapters, services, types) |
| 38 | +- Path aliases MUST be used consistently (`@adapters/*`, `@services/*`, `@types/*`, etc.) |
| 39 | + |
| 40 | +**Rationale**: Blockchain SDKs handle financial transactions and asset management. Type errors can lead to loss of funds. Strict typing catches errors at compile time, provides superior IDE support, and creates self-documenting code that users can trust. |
| 41 | + |
| 42 | +### II. Provider Agnostic Architecture |
| 43 | + |
| 44 | +The SDK MUST remain completely agnostic to the underlying provider implementation, supporting multiple provider ecosystems equally. |
| 45 | + |
| 46 | +**Non-negotiable rules:** |
| 47 | +- All blockchain interactions MUST go through the `ProviderAdapter` interface |
| 48 | +- Direct provider-specific calls MUST NOT appear in services or business logic |
| 49 | +- New provider support MUST be addable by implementing `ProviderAdapter` only |
| 50 | +- Adapters MUST handle provider-specific conversions (ABI formats, address formats, etc.) |
| 51 | +- Each supported provider (Ethers v5, Ethers v6, Viem) MUST have equal feature parity |
| 52 | +- Provider detection and initialization MUST be automatic and type-safe |
| 53 | + |
| 54 | +**Rationale**: The Ethereum/blockchain ecosystem has multiple competing provider libraries. Users should be able to integrate Mento SDK into existing projects without forcing a provider change. This adapter pattern ensures maintainability and allows the SDK to evolve independently of provider library changes. |
| 55 | + |
| 56 | +### III. Comprehensive Testing |
| 57 | + |
| 58 | +Testing MUST be comprehensive, covering all critical paths, provider integrations, and blockchain interactions. |
| 59 | + |
| 60 | +**Non-negotiable rules:** |
| 61 | +- All services MUST have unit tests covering core business logic |
| 62 | +- Each provider adapter MUST have integration tests verifying blockchain interactions |
| 63 | +- Shared test suites MUST be used to ensure consistent behavior across providers |
| 64 | +- Code coverage MUST be tracked and maintained above 80% for services |
| 65 | +- Tests MUST NOT be skipped without documented justification in PR description |
| 66 | +- Integration tests MUST use real blockchain data (mainnet fork or testnet) |
| 67 | +- Breaking changes MUST include test updates demonstrating the change |
| 68 | + |
| 69 | +**Test organization:** |
| 70 | +- `tests/unit/` - Fast, isolated tests for pure functions and business logic |
| 71 | +- `tests/integration/` - Provider-specific tests against real blockchain state |
| 72 | +- `tests/integration/shared/` - Reusable test suites ensuring provider parity |
| 73 | + |
| 74 | +**Rationale**: Blockchain SDKs interact with immutable smart contracts and handle real assets. Comprehensive testing is the only way to ensure reliability. Shared test suites prevent provider-specific bugs and ensure users get consistent behavior regardless of their provider choice. |
| 75 | + |
| 76 | +### IV. Performance & Reliability |
| 77 | + |
| 78 | +The SDK MUST be performant and reliable, minimizing unnecessary blockchain calls and handling errors gracefully. |
| 79 | + |
| 80 | +**Non-negotiable rules:** |
| 81 | +- Blockchain calls MUST be batched when possible to reduce RPC load |
| 82 | +- Retry logic with exponential backoff MUST be implemented for transient failures |
| 83 | +- All async operations MUST have proper error handling with meaningful error messages |
| 84 | +- No synchronous blocking operations permitted in async code paths |
| 85 | +- Network timeouts MUST be configurable or have sensible defaults |
| 86 | +- Contract addresses and ABIs MUST be cached and statically defined |
| 87 | +- Large data operations MUST be performed iteratively to avoid memory issues |
| 88 | + |
| 89 | +**Performance targets:** |
| 90 | +- SDK initialization: < 100ms (excluding network calls) |
| 91 | +- Single contract read: < 500ms on mainnet |
| 92 | +- Batch operations: Proportional to item count, no O(n²) operations |
| 93 | + |
| 94 | +**Rationale**: Users often integrate SDKs into time-sensitive applications (trading bots, dashboards, DeFi protocols). Slow or unreliable SDKs lead to poor user experience or lost opportunities. Blockchain RPC nodes have rate limits, so efficient call patterns are essential. |
| 95 | + |
| 96 | +### V. Developer Experience & Documentation |
| 97 | + |
| 98 | +The SDK MUST provide an exceptional developer experience through clear APIs, comprehensive documentation, and helpful error messages. |
| 99 | + |
| 100 | +**Non-negotiable rules:** |
| 101 | +- All public APIs MUST have JSDoc comments with usage examples |
| 102 | +- README MUST include quick start guides for each supported provider |
| 103 | +- Breaking changes MUST be clearly documented with migration guides |
| 104 | +- Error messages MUST be actionable (tell users what went wrong AND how to fix it) |
| 105 | +- TypeScript types MUST be exported and available to SDK consumers |
| 106 | +- Examples MUST be tested and kept up-to-date with API changes |
| 107 | + |
| 108 | +**Documentation requirements:** |
| 109 | +- Each service MUST document its purpose and primary use cases |
| 110 | +- Complex functions MUST include `@dev` comments with implementation notes |
| 111 | +- Public types MUST have property-level documentation |
| 112 | +- README MUST be updated when adding/removing features |
| 113 | + |
| 114 | +**Rationale**: SDK adoption depends on how quickly developers can get started and how easily they can debug issues. Good documentation and developer experience reduces support burden and increases user satisfaction. |
| 115 | + |
| 116 | +### VI. Blockchain Best Practices |
| 117 | + |
| 118 | +The SDK MUST follow blockchain and Web3 best practices to ensure security and compatibility. |
| 119 | + |
| 120 | +**Non-negotiable rules:** |
| 121 | +- All contract addresses MUST be checksummed and validated |
| 122 | +- Chain IDs MUST be verified to prevent cross-chain replay attacks |
| 123 | +- ABIs MUST match deployed contracts (verified against on-chain bytecode when possible) |
| 124 | +- Gas estimation MUST be available for state-changing operations |
| 125 | +- Event subscriptions MUST handle reorganizations gracefully |
| 126 | +- Numeric values MUST use BigNumber/BigInt to prevent precision loss |
| 127 | +- Contract calls MUST specify exact function signatures to prevent ambiguity |
| 128 | + |
| 129 | +**Security considerations:** |
| 130 | +- Never trust user input - validate all addresses, amounts, and parameters |
| 131 | +- Never expose private keys or sensitive data in logs or errors |
| 132 | +- Follow principle of least privilege for contract interactions |
| 133 | + |
| 134 | +**Rationale**: Blockchain development has unique security considerations. Incorrect address formats, chain ID mismatches, or floating-point arithmetic can lead to loss of funds. Following established best practices prevents common vulnerabilities. |
| 135 | + |
| 136 | +## Quality Standards |
| 137 | + |
| 138 | +### Code Organization |
| 139 | +- One class per file, filename matches class name |
| 140 | +- Related functionality grouped in services |
| 141 | +- Shared types centralized in `@types/*` |
| 142 | +- ABIs separated by contract in `@abis/*` |
| 143 | +- Constants organized by concern (addresses, chain IDs, etc.) |
| 144 | + |
| 145 | +### Dependency Management |
| 146 | +- Peer dependencies for provider libraries (optional to allow user choice) |
| 147 | +- Minimal production dependencies (current: only BigNumber.js) |
| 148 | +- Dev dependencies pinned to prevent build inconsistencies |
| 149 | +- Node.js >= 18 and pnpm >= 9 required |
| 150 | + |
| 151 | +### Version Management |
| 152 | +- Semantic versioning (MAJOR.MINOR.PATCH) |
| 153 | +- MAJOR: Breaking API changes, provider support changes |
| 154 | +- MINOR: New features, new chains, backward-compatible additions |
| 155 | +- PATCH: Bug fixes, documentation, dependency updates |
| 156 | + |
| 157 | +## Development Workflow |
| 158 | + |
| 159 | +### Pull Request Requirements |
| 160 | +- All tests MUST pass (unit + integration) |
| 161 | +- ESLint and Prettier checks MUST pass |
| 162 | +- Code coverage MUST not decrease (exceptions require justification) |
| 163 | +- At least one approval from core maintainer |
| 164 | +- Meaningful commit messages following conventional commits |
| 165 | + |
| 166 | +### Testing Workflow |
| 167 | +1. Write tests first for new features (test-driven development encouraged) |
| 168 | +2. Ensure tests fail before implementation |
| 169 | +3. Implement feature |
| 170 | +4. Verify all tests pass |
| 171 | +5. Check coverage report |
| 172 | + |
| 173 | +### Review Checklist |
| 174 | +- [ ] TypeScript strict mode compliance |
| 175 | +- [ ] All provider adapters maintain feature parity |
| 176 | +- [ ] JSDoc comments on public APIs |
| 177 | +- [ ] Error messages are actionable |
| 178 | +- [ ] Tests cover new functionality |
| 179 | +- [ ] README updated if adding/changing public API |
| 180 | +- [ ] No hardcoded values (use constants) |
| 181 | +- [ ] Async operations have error handling |
| 182 | + |
| 183 | +## Governance |
| 184 | + |
| 185 | +### Constitution Authority |
| 186 | +This constitution supersedes all other development practices, guidelines, or preferences. When conflicts arise between this constitution and other documentation, the constitution takes precedence. |
| 187 | + |
| 188 | +### Amendment Process |
| 189 | +1. Proposed changes MUST be documented with rationale |
| 190 | +2. Changes MUST have approval from at least 2 core maintainers |
| 191 | +3. Version MUST be bumped according to change significance: |
| 192 | + - MAJOR: Removing/changing core principles |
| 193 | + - MINOR: Adding new principles or sections |
| 194 | + - PATCH: Clarifications, typos, non-semantic changes |
| 195 | +4. All dependent templates MUST be updated for consistency |
| 196 | +5. A sync impact report MUST be included with the amendment |
| 197 | + |
| 198 | +### Compliance Review |
| 199 | +- All PRs MUST verify alignment with these principles |
| 200 | +- New complexity or architectural patterns MUST be justified against simplicity |
| 201 | +- Violations require documented rationale and core maintainer approval |
| 202 | +- Constitution review recommended quarterly or after major features |
| 203 | + |
| 204 | +### Conflict Resolution |
| 205 | +When principles conflict in practice: |
| 206 | +1. Security and correctness take precedence over performance |
| 207 | +2. User experience takes precedence over implementation simplicity |
| 208 | +3. Type safety takes precedence over brevity |
| 209 | +4. Consult core maintainers for guidance on edge cases |
| 210 | + |
| 211 | +**Version**: 1.0.0 | **Ratified**: 2025-11-03 | **Last Amended**: 2025-11-03 |
0 commit comments