Skip to content

Commit dc05d82

Browse files
committed
token-2022 cpi-guard: add pinocchio example
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.
1 parent 73219fe commit dc05d82

12 files changed

Lines changed: 3311 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ members = [
7373
"tokens/token-2022/permanent-delegate/pinocchio/program",
7474
"tokens/token-2022/multiple-extensions/pinocchio/program",
7575
"tokens/token-2022/immutable-owner/pinocchio/program",
76+
"tokens/token-2022/cpi-guard/pinocchio/program",
7677
]
7778
resolver = "2"
7879

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This script is for quick building & deploying of the program.
4+
# It also serves as a reference for the commands used for building & deploying Solana programs.
5+
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"
6+
7+
cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so
8+
solana program deploy ./program/target/so/program.so
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "mocha --import=tsx -t 1000000 ./tests/test.ts",
5+
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
6+
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
7+
"deploy": "solana program deploy ./program/target/so/program.so"
8+
},
9+
"dependencies": {
10+
"@solana-program/system": "^0.12.2",
11+
"@solana-program/token-2022": "^0.12.0",
12+
"@solana/kit": "^7.0.0",
13+
"litesvm": "^1.3.0"
14+
},
15+
"devDependencies": {
16+
"@types/chai": "^5.2.3",
17+
"@types/mocha": "^10.0.10",
18+
"@types/node": "^26.1.0",
19+
"chai": "^6.2.2",
20+
"mocha": "^11.7.5",
21+
"typescript": "^5.9.3",
22+
"tsx": "^4.19.2"
23+
}
24+
}

0 commit comments

Comments
 (0)