Successfully implemented the vesting "cliffs" feature for top-ups as requested in Issue 19. This implementation provides a robust and flexible system for managing complex vesting schedules with multiple cliff periods.
- Vault Model: Core vault entity with metadata and totals
- SubSchedule Model: Individual vesting schedules for each top-up with independent cliffs
- Beneficiary Model: Track beneficiaries and their allocations/withdrawals
- Proper Associations: Foreign key relationships and cascade deletes
- Vault Management: Create and manage vaults with beneficiaries
- Top-Up Processing: Add funds with custom cliff periods
- Vesting Calculations: Complex logic for multiple overlapping schedules
- Withdrawal Processing: FIFO distribution across sub-schedules
- Comprehensive Queries: Get schedules, summaries, and withdrawable amounts
POST /api/vaults- Create vaultPOST /api/vaults/{address}/top-up- Add funds with cliffGET /api/vaults/{address}/schedule- Get vesting scheduleGET /api/vaults/{address}/{beneficiary}/withdrawable- Calculate withdrawablePOST /api/vaults/{address}/{beneficiary}/withdraw- Process withdrawalGET /api/vaults/{address}/summary- Get vault summary
- Unit Tests: Vesting calculations, cliff logic, withdrawal processing
- Integration Tests: Full API endpoint testing
- Edge Cases: Multiple top-ups, different cliffs, error scenarios
- Test Coverage: All major functionality covered
- Implementation Guide: Complete technical documentation
- API Reference: Detailed endpoint documentation with examples
- Use Cases: Employee vesting, investor funding scenarios
- Database Schema: Complete schema documentation
Each vault maintains a list of SubSchedule objects, each representing:
- Individual top-up amounts
- Independent cliff periods
- Separate vesting durations
- Withdrawal tracking per schedule
- Before Cliff: No tokens vested
- During Cliff: No tokens vested
- After Cliff: Linear vesting over remaining period
- Multiple Overlaps: Handles complex overlapping schedules
- Each top-up can have different cliff duration
- Independent vesting periods per top-up
- Transaction tracking for audit purposes
- Block-level precision
- FIFO (First-In-First-Out) distribution
- Prevents withdrawal of unvested tokens
- Tracks withdrawals per sub-schedule
- Handles partial withdrawals
// Initial grant: 1000 tokens, 1-year cliff, 4-year vesting
await processTopUp({
vault_address: "0x...",
amount: "1000",
cliff_duration_seconds: 31536000, // 1 year
vesting_duration_seconds: 126144000, // 4 years
});
// Year 1 bonus: 200 tokens, 6-month cliff, 2-year vesting
await processTopUp({
vault_address: "0x...",
amount: "200",
cliff_duration_seconds: 15552000, // 6 months
vesting_duration_seconds: 63072000, // 2 years
});// Seed round: 5000 tokens, 6-month cliff, 3-year vesting
await processTopUp({
vault_address: "0x...",
amount: "5000",
cliff_duration_seconds: 15552000, // 6 months
vesting_duration_seconds: 94608000, // 3 years
});
// Series A: 10000 tokens, 1-year cliff, 4-year vesting
await processTopUp({
vault_address: "0x...",
amount: "10000",
cliff_duration_seconds: 31536000, // 1 year
vesting_duration_seconds: 126144000, // 4 years
});- Normalized Schema: Proper relationships and constraints
- Indexes: Optimized for common query patterns
- Decimal Precision: 36,18 precision for token amounts
- UUID Primary Keys: Distributed-friendly identifiers
- RESTful: Standard HTTP methods and status codes
- JSON Format: Consistent request/response structure
- Error Handling: Comprehensive error messages
- Validation: Input validation and sanitization
- Time-based Calculations: Precise timestamp handling
- Linear Vesting: Mathematical accuracy in vesting ratios
- Concurrent Safety: Transaction isolation for data integrity
- Audit Trail: Transaction hash and block number tracking
- Vesting calculations (before/during/after cliff)
- Multiple top-up scenarios
- Withdrawal distribution logic
- Error handling and edge cases
- Complete API workflows
- Database operations
- Error response handling
- Data consistency validation
- ✅ Vault creation and management
- ✅ Top-up processing with various cliff configurations
- ✅ Vesting calculations for all time periods
- ✅ Withdrawal processing and distribution
- ✅ Multiple overlapping schedules
- ✅ Error scenarios and validation
- Input Validation: All addresses validated as Ethereum addresses
- Transaction Uniqueness: Prevent duplicate transaction processing
- Amount Validation: Withdrawals cannot exceed vested amounts
- Timestamp Security: Proper timestamp validation and normalization
- Database Indexing: Strategic indexes for common queries
- Batch Processing: Support for batch operations
- Efficient Queries: Optimized SQL with proper joins
- Memory Management: Efficient data handling
- Partial Withdrawal Control: Allow specifying which sub-schedule to withdraw from
- Vesting Templates: Predefined templates for common scenarios
- Beneficiary Groups: Support for groups with shared allocations
- Notification System: Alerts for cliff periods ending
- Analytics Dashboard: Comprehensive vesting analytics
- Migration Tools: Tools for migrating from simple vesting
- SubSchedule list within the Vault: ✅ Implemented
- Complex logic: ✅ Implemented as stretch goal
- Production-ready: ✅ Comprehensive testing and documentation
backend/src/models/vault.js- Vault modelbackend/src/models/subSchedule.js- SubSchedule modelbackend/src/models/beneficiary.js- Beneficiary modelbackend/src/models/associations.js- Model relationshipsbackend/src/services/vestingService.js- Core vesting logicbackend/test/vestingService.test.js- Unit testsbackend/test/vestingApi.test.js- Integration testsdocs/VESTING_CLIFFS.md- Implementation documentationdocs/API_REFERENCE.md- API documentation
backend/src/models/index.js- Added new modelsbackend/src/index.js- Added vesting routesbackend/package.json- Updated description
The vesting cliffs feature has been successfully implemented as a "stretch goal" with comprehensive functionality, testing, and documentation. The implementation provides:
- Flexible Vesting Schedules: Support for multiple independent cliff periods
- Robust Business Logic: Accurate vesting calculations and withdrawal processing
- Production-Ready Code: Comprehensive testing and error handling
- Complete Documentation: Technical implementation and API reference
- Scalable Architecture: Database design optimized for performance
This implementation fully addresses the requirements of Issue 19 and provides a solid foundation for complex vesting scenarios in the Vesting Vault system.