Repository navigation
Conversation
[Medium impact] The PR appears safe to merge, with no new actionable issues found. SummaryAdds a Pinocchio example that demonstrates Token-2022
Reviews (2) · Last reviewed commit: "token-2022 cpi-guard: add pinocchio exam..." · Reviewed by Greptile |
|
@amilz could you take a look at this one when you get a chance? No open review threads left on it, so it is ready for maintainer review. It is one of 23 open Pinocchio ports I have up — they are independent and self-contained, so they can be reviewed and merged in any order: https://github.com/solana-developers/program-examples/pulls/MarkFeder |
|
@dev-jodee friendly ping, could you review this when you get a chance? CI is green and it's mergeable. Thanks! |
|
@dev-jodee gentle ping: this has been open since Aug 26 with no review. It's still green and mergeable, and I'm happy to rebase or change anything. These 3 are also what's blocking me from reopening the closed ports under the 3-PR limit. Thanks! |
Ports the cpi-guard Token-2022 example to Pinocchio (the anchor example has no native sibling). Unlike the other extension examples, CpiGuard cannot be enabled or disabled through a CPI, so the program cannot initialize it; instead the program exposes a cpi_transfer instruction (a Token-2022 TransferChecked CPI, reading the mint's decimals from account data) and the example demonstrates the guard's effect. The litesvm test creates a source account with CpiGuard enabled (client-side) and funded, then shows the program's CPI transfer is rejected while the guard is on and succeeds once it is disabled, asserting the destination balance. Matches the kit + litesvm template of the other token-2022 pinocchio examples.
dc05d82 to
f11b186
Compare
|
Hi @MarkFeder, Thanks for the pull request. We ask that every change references an issue a maintainer has accepted, and there isn't one linked here. These examples are a teaching resource and each one has to stay small enough to read in one sitting, so whether a new example or framework flavor belongs here is worth settling before anyone writes it. Agreeing on the approach in an issue first means nobody writes code that can't be merged. See CONTRIBUTING.md for the full workflow. Please open an issue describing the change, or comment on the existing one. Once a maintainer has labelled it |
|
Superseded by #793 (the bot closed this one and GitHub won't let me reopen it). |
Linked issue
Fixes #786
What and why
Adds a Pinocchio version of
tokens/token-2022/cpi-guard, which only had an Anchor one, following the same kit + LiteSVM template as the other Token-2022 Pinocchio examples.CpiGuardstops privileged token operations (transfer, burn, approve, close) authorized by the account owner from running through a CPI. Token-2022 doesn't allow enabling or disabling the guard through a CPI either, so unlike the other extension examples the program can't initialize it. Instead:cpi_transferinstruction: a Token-2022TransferCheckedCPI (variant 12) from source to destination, signed by the source's owner. It readsdecimalsfrom the mint account (offset 44) so the checked transfer matches the mint.The JS dependencies match the versions #765 set for the other non-anchor examples.
Testing
pnpm install --frozen-lockfile,tsc --noEmit,pnpm build,pnpm build-and-testandpnpm auditin a Linux container, pluscargo fmt --check,cargo clippy -D warningsandprettier --check:The test creates a mint and a funded source account with CpiGuard enabled, asserts
cpi_transferfails (FailedTransactionMetadata), disables the guard, and asserts the same call succeeds and the destination balance is1. The success after disabling shows the guard caused the rejection.AI disclosure
Check exactly one. See CONTRIBUTING.md.