A complete DAO governance system has been implemented for the StellarSplit platform, enabling decentralized decision-making through proposals, voting, and time-locked execution.
- Proposal - Main proposal entity with voting results and lifecycle tracking
- Vote - Individual votes with voting power and reasoning
- ProposalAction - Executable actions within proposals
- GovernanceConfig - System-wide governance parameters
CreateProposalDto- Create new proposals with actionsCastVoteDto- Simple FOR/AGAINST votingCastVoteWithTypeDto- Advanced voting with FOR/AGAINST/ABSTAINExecuteProposalDto- Execute approved proposalsVetoProposalDto- Veto proposals with reasoning
GovernanceService implements all core functionality:
- ✅
createProposal()- Create proposals with threshold validation - ✅
vote()- Cast votes with double-vote prevention - ✅
executeProposal()- Execute proposals after timelock - ✅
vetoProposal()- Veto mechanism for authorized addresses - ✅
finalizeProposal()- Calculate results and queue for execution - ✅
getProposal()/getProposals()- Query proposals - ✅
getVotes()- Get votes for a proposal
GovernanceController exposes REST API endpoints:
POST /governance/proposals- Create proposalPOST /governance/vote- Cast votePOST /governance/execute- Execute proposalPOST /governance/veto- Veto proposalGET /governance/proposals- List proposalsGET /governance/proposals/:id- Get proposal detailsGET /governance/proposals/:id/votes- Get proposal votes
- Multi-action proposals
- Proposal threshold validation
- Configurable quorum per proposal
- Automatic voting period scheduling
- FOR/AGAINST/ABSTAIN vote types
- Voting power weighting
- Double-vote prevention
- Optional vote reasoning
- Real-time vote counting
- Configurable quorum percentage
- Participation tracking
- Automatic quorum validation on finalization
- Configurable timelock delay (default: 2 days)
- Queued status for approved proposals
- Execution time validation
- Sequential action execution
- Authorized veto addresses
- Veto with reasoning
- Cannot veto executed proposals
- Veto event emission
PENDING → ACTIVE → SUCCEEDED → QUEUED → EXECUTED
↓
DEFEATED
↓
VETOED
- TRANSFER_FUNDS - Transfer tokens to addresses
- UPDATE_PARAMETER - Update system parameters
- ADD_MEMBER - Add DAO members
- REMOVE_MEMBER - Remove DAO members
- UPGRADE_CONTRACT - Upgrade smart contracts
- CUSTOM - Custom actions with arbitrary parameters
Default governance parameters:
- Quorum: 51%
- Voting Period: 3 days
- Timelock Delay: 2 days
- Proposal Lifetime: 7 days
- Proposal Threshold: 1,000,000,000,000
Migration file created: 1769800000000-CreateGovernanceTables.ts
Creates tables:
governance_configproposalsvotesproposal_actions
Test files created:
governance.service.spec.ts- Service unit testsgovernance.controller.spec.ts- Controller unit tests
Test coverage includes:
- Proposal creation with threshold validation
- Voting with double-vote prevention
- Veto mechanism with authorization
- Error handling for invalid states
Added to AppModule:
import { GovernanceModule } from './governance/governance.module';
@Module({
imports: [
// ... other modules
GovernanceModule,
],
})The service emits events for external integrations:
proposal.created- New proposal createdvote.cast- Vote cast on proposalproposal.finalized- Voting ended, result calculatedproposal.executed- Proposal actions executedproposal.vetoed- Proposal vetoedaction.executed- Individual action executed
// Create proposal
const proposal = await governanceService.createProposal({
proposer: "stellar-address",
description: "Allocate funds for development",
actions: [
{
actionType: ActionType.TRANSFER_FUNDS,
target: "recipient-address",
parameters: { amount: "10000", token: "USDC" },
},
],
});
// Vote
await governanceService.vote({
proposalId: proposal.id,
voter: "voter-address",
support: true,
reason: "Good proposal",
});
// Execute after timelock
await governanceService.executeProposal(proposal.id);backend/src/governance/
├── entities/
│ ├── proposal.entity.ts
│ ├── vote.entity.ts
│ ├── proposal-action.entity.ts
│ └── governance-config.entity.ts
├── dto/
│ ├── create-proposal.dto.ts
│ ├── vote.dto.ts
│ ├── execute-proposal.dto.ts
│ └── proposal-response.dto.ts
├── examples/
│ └── governance-usage.example.ts
├── governance.service.ts
├── governance.service.spec.ts
├── governance.controller.ts
├── governance.controller.spec.ts
├── governance.module.ts
├── README.md
└── IMPLEMENTATION_SUMMARY.md
To use the governance system:
-
Install dependencies (if not already):
npm install
-
Run migration:
npm run migration:run
-
Start the server:
npm run start:dev
-
Test the API:
curl -X POST http://localhost:3000/governance/proposals \ -H "Content-Type: application/json" \ -d '{ "proposer": "address", "description": "Test proposal", "actions": [] }'
To fully integrate with your platform:
- Voting Power: Implement
getVotingPower()to integrate with your token system - Action Execution: Implement
executeAction()to perform actual on-chain operations - Authentication: Add authentication middleware to controller endpoints
- Authorization: Validate proposer/voter addresses
- Notifications: Subscribe to events for user notifications
- ✅ Proposal threshold prevents spam
- ✅ Double-vote prevention
- ✅ Timelock prevents immediate execution
- ✅ Veto mechanism for emergency situations
- ✅ Status validation prevents invalid state transitions
⚠️ Add authentication/authorization middleware⚠️ Implement rate limiting on endpoints⚠️ Validate action parameters before execution