reclaim buffer account - #60
Open
kaze-cow wants to merge 6 commits into
Open
Conversation
fedgiac
reviewed
Jul 16, 2026
fedgiac
left a comment
Contributor
There was a problem hiding this comment.
The PR is fairly large so I'd suggest to split it in 2: first, introducing the new state PDA data and the initialization; then, introducing the new reclaim buffer instruction. If that's large as well you can consider splitting parsing/ix building to the processing but maybe it isn't needed (the burn logic is nontrivial though).
kaze-cow
force-pushed
the
kaze/sc-151-close-buffer-account
branch
from
July 30, 2026 09:02
1221424 to
fc9e0ca
Compare
Closes buffer PDAs and returns their rent to the `receiver` recorded in the state PDA, which must sign. Each buffer is paired with its `mint` so the canonical buffer PDA can be re-derived and verified. Any token balance still sitting in a buffer is burned before the close: a bad actor could otherwise send dust to a buffer to keep it from closing, and recovering the dust would cost more than it's worth. This is destructive, so it's flagged at every level of the call chain. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
kaze-cow
force-pushed
the
kaze/sc-151-close-buffer-account
branch
from
July 30, 2026 09:19
e785bfa to
c413b9a
Compare
fedgiac
reviewed
Jul 31, 2026
required refactoring/moving the function into processor
out of scope for this PR (determined)
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.
Description
Adds the
ReclaimBuffersinstruction. Also add some more capabilities to the test helpers.Stacked on #84, which adds the
receiverfield to the state PDA that this instruction reads. Review that one first; the diff here is against it.Changes
The instruction takes in 3 accounts,
state_account, receiver_account, token_account, plus two additional accountsbuffer_pda, mintfor each buffer to clear. Themintis required to help verify the canonical status ofbuffer_pda, as well as to callBurnif the account happens to hold excess funds.The instruction can only be called by the
receiveraccount which is registered in thestate_pda(see #84).Since a bad actor could send 1 wei/lamport of a token to the buffers just before we close them, the buffer may become unable to be closed and the instruction would fail. This could be used as a griefing tactic, so this instruction will additionally
Burnany remaining tokens found in the buffer before closing.Burnis used instead ofTransferbecause a transfer would likely require conditional allocation and sending--all for what is almost certainly a tiny . So its much easier to simply burn this amount entirely and move on. As this is a potentially destructive operation, multiple warnings have been added around the codebase to prevent this from being overlooked. Additionally, while most tokens support anyone being able to Burn their own tokens, there may exist certain 2022 tokens which disallow it, and so the buffer could not be closed unless we were to empty the account completely.How to test