Skip to content

Commit 0e328ad

Browse files
committed
feat(oracles/pyth): add pinocchio example
Adds a Pinocchio implementation of the Pyth oracle example, the first pinocchio example under oracles/. The single read_price instruction reads a Pyth pull oracle PriceUpdateV2 account and logs its price fields. There is no Pyth SDK for Pinocchio, so the account is parsed by hand: the program checks the account's owner (the Pyth receiver program) and the anchor account discriminator before trusting the data, then reads the price, confidence, exponent, and publish time by byte offset. The account's VerificationLevel is a variable-size Borsh enum, so the price message offset is computed from it. The litesvm test injects a mock PriceUpdateV2 account with known values via setAccount and asserts the program logs the parsed fields, plus a second case that a non-Pyth-owned account is rejected.
1 parent 4823810 commit 0e328ad

12 files changed

Lines changed: 3221 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+
"oracles/pyth/pinocchio/program",
7677
]
7778
resolver = "2"
7879

oracles/pyth/pinocchio/cicd.sh

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/*.so
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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/*.so"
8+
},
9+
"dependencies": {
10+
"@solana/kit": "^7.0.0",
11+
"litesvm": "^1.3.0"
12+
},
13+
"devDependencies": {
14+
"@types/chai": "^5.2.3",
15+
"@types/mocha": "^10.0.10",
16+
"@types/node": "^26.1.0",
17+
"chai": "^6.2.2",
18+
"mocha": "^11.7.5",
19+
"typescript": "^5.9.3",
20+
"tsx": "^4.19.2"
21+
}
22+
}

0 commit comments

Comments
 (0)