Commit 32183c9
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
- tokens/token-2022/transfer-fee/pinocchio
- program
- src
- instructions
- tests
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments