Description
Governance treasury payouts (a passed proposal disbursing tokens) currently rely on the governance contract calling into token-factory as a separate step with no atomicity guarantee — if the token-factory call fails after governance has already marked the proposal executed, the disbursement is silently lost with no compensating mechanism.
Requirements and Context
- Design and implement a two-phase settlement protocol between governance and token-factory: a prepare phase that reserves the disbursement amount, and a commit/abort phase that finalizes or releases the reservation
- The governance contract's "proposal executed" state must only be set after the token-factory commit is confirmed successful, never before
- A failed commit must automatically transition to abort, releasing the reservation back to the treasury with no funds stuck in limbo
- Add a stuck-reservation cleanup path for a reservation neither committed nor aborted within a timeout window
- Proof of work (required): this is a hard/complex issue — the PR description must include (1) a screenshot of the full relevant test suite run showing all tests passing, and (2) a screenshot of a successful project/module build or compile (
cargo build --release) with no errors. PRs missing either screenshot will not be reviewed.
Suggested Execution
Branch: feat/contract-cross-contract-atomic-settlement
Implement Changes
- Add a
Reservation storage type in token-factory with prepare/commit/abort entry points callable only by the governance contract
- Update governance's proposal-execution path to call prepare → commit, and to call abort on any failure, before setting proposal state to executed
- Add the stuck-reservation cleanup path
- Add tests covering: full success, commit failure with automatic abort, and stuck-reservation timeout cleanup
Test and Commit
Run cargo test settlement --package governance --package token-factory — prepare/commit, commit-failure/abort, and timeout-cleanup scenarios all pass with zero stuck reservations. Then run cargo build --release and confirm it completes with no errors. Attach a screenshot of both the passing test run and the successful build to the PR description as proof of work.
Example Commit Message
feat(contracts): two-phase atomic settlement protocol between governance and token-factory
Closes #<issue>
Guidelines
- Branch from
main, open a PR back to main
- All new code must have corresponding tests
- Run
npm run lint and npm run test before pushing
- Follow existing naming conventions and file structure
- PR description must reference this issue number (e.g.,
Closes #<issue>)
- Keep commits atomic and use conventional commit format
- This is a hard/complex issue: PR must include a screenshot of the test suite passing and a screenshot of a successful build/compile — PRs without both screenshots will be marked incomplete and not merged
Description
Governance treasury payouts (a passed proposal disbursing tokens) currently rely on the governance contract calling into token-factory as a separate step with no atomicity guarantee — if the token-factory call fails after governance has already marked the proposal executed, the disbursement is silently lost with no compensating mechanism.
Requirements and Context
cargo build --release) with no errors. PRs missing either screenshot will not be reviewed.Suggested Execution
Branch:
feat/contract-cross-contract-atomic-settlementImplement Changes
Reservationstorage type in token-factory with prepare/commit/abort entry points callable only by the governance contractTest and Commit
Run
cargo test settlement --package governance --package token-factory— prepare/commit, commit-failure/abort, and timeout-cleanup scenarios all pass with zero stuck reservations. Then runcargo build --releaseand confirm it completes with no errors. Attach a screenshot of both the passing test run and the successful build to the PR description as proof of work.Example Commit Message
Guidelines
main, open a PR back tomainnpm run lintandnpm run testbefore pushingCloses #<issue>)