Skip to content

Commit 32183c9

Browse files
authored
Add Token-2022 transfer-fee Pinocchio example (#653)
* token-2022 transfer-fee: add pinocchio example Ports the transfer-fee Token-2022 example to Pinocchio, matching the mint-close-authority template (kit + litesvm, official @solana-program packages, real Rent::get()). The program hand-rolls three Token-2022 CPIs to create a mint with the TransferFeeConfig extension: it initializes the fee config to 1% before InitializeMint, then (mirroring the native example) updates it to 10% afterwards via SetTransferFee, which the transfer-fee config authority signs. Both the config and withdraw-withheld authorities are set to the payer. Mint size is 278 bytes (a 108-byte TransferFeeConfig TLV value). The litesvm test decodes the mint with the official Token-2022 codec and asserts the stored authorities and the newer transfer fee (10%, max 5 tokens). * token-2022 transfer-fee pinocchio: guard fee scaling against overflow decimals is unvalidated u8 instruction input and the workspace enables overflow-checks, so 5 * 10^decimals would panic and abort the transaction for large decimals (>= 19). Compute the max fee with checked_pow/checked_mul and return a controlled ProgramError::InvalidInstructionData instead. * token-2022 transfer-fee pinocchio: migrate to pinocchio 0.11 + prettier Rebased onto main (pinocchio 0.10 -> 0.11): handlers take &mut [AccountView] and CPI account-infos are passed as copies. Also apply prettier formatting to test.ts and tsconfig.json to satisfy the repo's Prettier check. * token-2022 transfer-fee pinocchio: switch test stack to mocha+tsx Per #656 / AGENTS.md 'do not deviate' rule: replace ts-mocha with 'mocha --import=tsx', bump @solana/kit to ^7 and the mocha/chai/tsx/types devDeps to match the token-2022/non-transferable reference, and align tsconfig (noEmit, bundler resolution). Regenerated pnpm-lock.yaml. Verified: tsc --noEmit clean and 'pnpm build-and-test' passes on the litesvm path. --------- Co-authored-by: MarkFeder <5670736+MarkFeder@users.noreply.github.com>
1 parent 6fe04fe commit 32183c9

12 files changed

Lines changed: 3356 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
@@ -65,6 +65,7 @@ members = [
6565
"tokens/token-2022/default-account-state/native/program",
6666
"tokens/token-2022/default-account-state/pinocchio/program",
6767
"tokens/token-2022/transfer-fee/native/program",
68+
"tokens/token-2022/transfer-fee/pinocchio/program",
6869
"tokens/token-2022/multiple-extensions/native/program",
6970
]
7071
resolver = "2"
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
"@solana/sysvars": "^6.10.0",
14+
"borsh": "^2.0.0",
15+
"litesvm": "^1.3.0"
16+
},
17+
"devDependencies": {
18+
"@types/chai": "^5.2.3",
19+
"@types/mocha": "^10.0.10",
20+
"@types/node": "^26.1.0",
21+
"chai": "^6.2.2",
22+
"mocha": "^11.7.5",
23+
"typescript": "^5.9.3",
24+
"tsx": "^4.19.2"
25+
}
26+
}

0 commit comments

Comments
 (0)