refactor(finance/escrow): extract PDA-aware token transfer/close helpers#65
Merged
Merged
Conversation
Add an owning_pda_seeds option to transfer_tokens and a new close_token_account helper in shared.rs, then use them across make_offer, take_offer, and cancel_offer. This removes the duplicated CpiContext::new_with_signer + transfer_checked/close_account boilerplate that was hand-rolled in each handler. No behavior change: per-maker PDA seeds and has_one checks are unchanged. Verified with cargo test (5 tests pass).
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.
What
Refactors the Anchor escrow example to remove duplicated token-CPI boilerplate.
transfer_tokensgains anowning_pda_seeds: Option<&[&[u8]]>parameter so the same helper handles both signer-authority and PDA-authority transfers.close_token_accounthelper covering the PDA-signed vault close.make_offer,take_offer, andcancel_offernow call these helpers instead of hand-rollingCpiContext::new_with_signer+transfer_checked/close_accountin each handler.These helpers were adapted from the prototype
escrow-2026project (now removed), but updated to use Anchor 1.0's CPI calling convention (token_program.key()) rather than theto_account_info()style from that 0.32.1 prototype.Behavior
No on-chain behavior change. The per-maker PDA seeds (
[b"offer", maker, id]) and thehas_oneconstraints are unchanged.Testing
cargo test— 5 tests pass:test_make_offertest_take_offertest_cancel_offertest_cancel_offer_rejects_non_makertest_id