Add close_contributor instruction to token fundraiser - #146
Merged
Merged
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
close_contributorinstruction 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_contributionsinstruction 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 throughrefund, 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_contributorinstruction that:FundraiserStillOpenerror if attempted while the fundraiser is still active, ensuring live contributions can only be closed throughrefundChanges
New Files:
anchor/programs/fundraiser/src/instructions/close_contributor.rs- Anchor v2 implementationquasar/src/instructions/close_contributor.rs- Quasar implementationModified Files:
anchor/programs/fundraiser/src/lib.rs- Added close_contributor handleranchor/programs/fundraiser/src/instructions/mod.rs- Exported new instructionanchor/programs/fundraiser/src/error.rs- Added FundraiserStillOpen errorquasar/src/lib.rs- Added close_contributor handler with discriminator 4quasar/src/instructions/mod.rs- Exported new instructionquasar/src/error.rs- Added FundraiserStillOpen erroranchor/programs/fundraiser/tests/test_fundraiser.rs- Added two comprehensive testsquasar/src/tests.rs- Added two comprehensive testsTesting
Added comprehensive test coverage:
test_close_contributor_after_successful_claim_returns_rent- Verifies rent is returned to contributor after successful claimtest_close_contributor_while_fundraiser_open_fails- Verifies the instruction fails while fundraiser is still activehttps://claude.ai/code/session_01MFyue6rqsmrggYY6Zkcype