Skip to content

Commit 62c8661

Browse files
committed
add pinocchio transfer-tokens example
Add a Pinocchio implementation of tokens/transfer-tokens covering the core SPL flow: create a mint, mint tokens to an associated token account, and transfer tokens between wallets. The program dispatches three instructions by a leading discriminator byte (0=CreateToken, 1=MintTokens, 2=TransferTokens) using pinocchio-token, pinocchio-associated-token-account, and pinocchio-system. A bankrun test exercises the full create -> mint 150 -> transfer 50 flow and asserts the resulting 100/50 balances.
1 parent 203b246 commit 62c8661

15 files changed

Lines changed: 1815 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 35 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ members = [
5151
"basics/transfer-sol/asm",
5252

5353
# tokens
54+
"tokens/transfer-tokens/pinocchio/program",
5455
"tokens/token-2022/mint-close-authority/native/program",
5556
"tokens/token-2022/non-transferable/native/program",
5657
"tokens/token-2022/default-account-state/native/program",
@@ -87,6 +88,8 @@ pinocchio = { version = "0.10.2", features = ["cpi"] }
8788
pinocchio-log = "0.5.1"
8889
pinocchio-system = "0.5.0"
8990
pinocchio-pubkey = "0.3.0"
91+
pinocchio-token = "0.5.0"
92+
pinocchio-associated-token-account = "0.3.0"
9093

9194
# testing
9295
litesvm = "0.11.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Create an NFT collection, mint NFTs, and verify NFTs as part of a collection usi
149149

150150
[Transfer tokens between accounts](./tokens/transfer-tokens/README.md)
151151

152-
[anchor](./tokens/transfer-tokens/anchor) [native](./tokens/transfer-tokens/native)
152+
[anchor](./tokens/transfer-tokens/anchor) [pinocchio](./tokens/transfer-tokens/pinocchio) [native](./tokens/transfer-tokens/native)
153153

154154
### Allowing users to swap digital assets - Escrow
155155

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "pnpm ts-mocha -p ./tsconfig.json -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/web3.js": "^1.98.4",
11+
"borsh": "^2.0.0"
12+
},
13+
"devDependencies": {
14+
"@types/bn.js": "^5.1.0",
15+
"@types/chai": "^4.3.1",
16+
"@types/mocha": "^9.1.1",
17+
"chai": "^4.3.4",
18+
"mocha": "^9.0.3",
19+
"solana-bankrun": "^0.3.0",
20+
"ts-mocha": "^10.0.0",
21+
"typescript": "^4.3.5"
22+
}
23+
}

0 commit comments

Comments
 (0)