Skip to content

Add close_contributor instruction to token fundraiser - #146

Merged
mikemaccana merged 1 commit into
mainfrom
claude/fundraising-diagram-labels-ef5e0f
Sep 15, 2026
Merged

mikemaccana merged 1 commit into
mainfrom
claude/fundraising-diagram-labels-ef5e0f

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Summary

Adds a close_contributor instruction to both the Anchor v2 and Quasar implementations of the token fundraiser program. This allows contributors to close their contributor accounts after a successful fundraise and reclaim the rent stored in those accounts.

Problem

When a fundraiser successfully reaches its target, the check_contributions instruction closes the fundraiser account and vault, but cannot close the individual contributor accounts (one per contributor). The only other way to close a contributor account is through refund, which only runs on failed fundraises. This left contributors unable to reclaim the rent from their accounts after a successful raise.

Solution

Implemented a new close_contributor instruction that:

  • Allows a contributor to close their own contributor account once the fundraiser is gone
  • Returns the rent to the contributor
  • Validates that the fundraiser account no longer exists (not owned by the program) before allowing closure
  • Fails with a new FundraiserStillOpen error if attempted while the fundraiser is still active, ensuring live contributions can only be closed through refund

Changes

New Files:

  • anchor/programs/fundraiser/src/instructions/close_contributor.rs - Anchor v2 implementation
  • quasar/src/instructions/close_contributor.rs - Quasar implementation

Modified Files:

  • anchor/programs/fundraiser/src/lib.rs - Added close_contributor handler
  • anchor/programs/fundraiser/src/instructions/mod.rs - Exported new instruction
  • anchor/programs/fundraiser/src/error.rs - Added FundraiserStillOpen error
  • quasar/src/lib.rs - Added close_contributor handler with discriminator 4
  • quasar/src/instructions/mod.rs - Exported new instruction
  • quasar/src/error.rs - Added FundraiserStillOpen error
  • anchor/programs/fundraiser/tests/test_fundraiser.rs - Added two comprehensive tests
  • quasar/src/tests.rs - Added two comprehensive tests
  • Documentation and changelogs updated for both implementations

Testing

Added comprehensive test coverage:

  • test_close_contributor_after_successful_claim_returns_rent - Verifies rent is returned to contributor after successful claim
  • test_close_contributor_while_fundraiser_open_fails - Verifies the instruction fails while fundraiser is still active
  • Tests in both Anchor and Quasar implementations with identical coverage

https://claude.ai/code/session_01MFyue6rqsmrggYY6Zkcype

… a successful raise

A successful raise exits through check_contributions, which closes the
vault and the fundraiser account but cannot reach the contributor
accounts: there is one per contributor and the claim carries none of
them. Their only other closer, refund, runs only on a failed raise, so
every contributor to a successful raise held their rent in an account
nothing could close.

Add close_contributor to the Anchor v2 and Quasar ports. The contributor
signs and passes the fundraiser address their account was written for;
the account's seeds bind it to that address, and the one check is that
the account there is no longer owned by the program, else the new
FundraiserStillOpen error. A live fundraiser is program-owned and a
closed one belongs to the system program again whatever lamports it
holds, so a stray transfer to the closed address cannot block the close.
The close constraint returns the rent.

Two tests per port: the rent comes back after a claim, and the close is
refused while the fundraiser exists. READMEs and changelogs follow. The
Anchor v1 port is a frozen snapshot and does not change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MFyue6rqsmrggYY6Zkcype
@mikemaccana
mikemaccana merged commit e99196b into main Sep 15, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants