From e5ee77584bd13d8f19de84a127cedfd02f824f0e Mon Sep 17 00:00:00 2001 From: Perelyn <64838956+Perelyn-sama@users.noreply.github.com> Date: Tue, 20 Jan 2026 05:28:38 +0100 Subject: [PATCH] use pinocchio v10 in basic examples --- Cargo.lock | 142 ++++++++++---- Cargo.toml | 6 +- basics/account-data/pinocchio/package.json | 5 +- basics/account-data/pinocchio/pnpm-lock.yaml | 182 +++++++++++------- .../account-data/pinocchio/program/src/lib.rs | 23 ++- .../pinocchio/tests/index.test.ts | 61 ++++-- .../pinocchio/program/src/lib.rs | 18 +- .../pinocchio/program/Cargo.toml | 1 + .../pinocchio/program/src/lib.rs | 40 ++-- .../pinocchio/program/tests/tests.rs | 9 + basics/counter/pinocchio/program/src/lib.rs | 13 +- .../pinocchio/program/src/lib.rs | 9 +- basics/favorites/pinocchio/program/Cargo.toml | 1 + .../program/src/instructions/create_pda.rs | 33 ++-- .../program/src/instructions/get_pda.rs | 23 +-- .../pinocchio/program/src/processor.rs | 10 +- .../favorites/pinocchio/program/tests/test.rs | 6 +- .../hello-solana/pinocchio/program/src/lib.rs | 11 +- .../pinocchio/tests/index.test.ts | 2 +- .../pinocchio/program/Cargo.toml | 1 + .../src/instructions/create_new_account.rs | 31 +-- .../src/instructions/init_rent_vault.rs | 31 +-- .../pinocchio/program/src/processor.rs | 10 +- .../pinocchio/program/tests/test.rs | 8 +- .../pinocchio/program/src/lib.rs | 9 +- .../program/src/instructions/create.rs | 16 +- .../program/src/instructions/increment.rs | 6 +- .../pinocchio/program/src/processor.rs | 8 +- .../program/src/instructions/create.rs | 14 +- .../program/src/instructions/reallocate.rs | 17 +- .../pinocchio/program/src/processor.rs | 8 +- basics/rent/pinocchio/program/src/lib.rs | 17 +- .../transfer-sol/pinocchio/program/src/lib.rs | 15 +- 33 files changed, 463 insertions(+), 323 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe1356c23..252fc5ca5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ name = "account-data-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "pinocchio-system", "solana-keypair", @@ -879,7 +879,7 @@ name = "checking-accounts-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "pinocchio-system", "solana-keypair", @@ -930,8 +930,9 @@ name = "close-account-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", + "pinocchio-pubkey", "pinocchio-system", "solana-instruction 3.0.0", "solana-keypair", @@ -1026,7 +1027,7 @@ name = "counter-solana-pinocchio" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "pinocchio-pubkey", "solana-instruction 3.0.0", @@ -1059,7 +1060,7 @@ name = "create-account-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "pinocchio-pubkey", "pinocchio-system", @@ -1417,8 +1418,9 @@ name = "favorites-pinocchio" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", + "pinocchio-pubkey", "pinocchio-system", "solana-instruction 3.0.0", "solana-keypair", @@ -1459,6 +1461,15 @@ dependencies = [ "five8_core", ] +[[package]] +name = "five8" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23f76610e969fa1784327ded240f1e28a3fd9520c9cec93b636fcf62dd37f772" +dependencies = [ + "five8_core", +] + [[package]] name = "five8_const" version = "0.1.4" @@ -1468,6 +1479,15 @@ dependencies = [ "five8_core", ] +[[package]] +name = "five8_const" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a0f1728185f277989ca573a402716ae0beaaea3f76a8ff87ef9dd8fb19436c5" +dependencies = [ + "five8_core", +] + [[package]] name = "five8_core" version = "0.1.2" @@ -1626,7 +1646,7 @@ dependencies = [ name = "hello-solana-program-pinocchio" version = "0.1.0" dependencies = [ - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", ] @@ -2175,8 +2195,9 @@ name = "pda-rent-payer-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", + "pinocchio-pubkey", "pinocchio-system", "solana-instruction 3.0.0", "solana-keypair", @@ -2223,20 +2244,33 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b971851087bc3699b001954ad02389d50c41405ece3548cbcafc88b3e20017a" +[[package]] +name = "pinocchio" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfad955b2fe8f736e1ea276ebb31820d778ee69c1161146054e9b31be2e73326" +dependencies = [ + "solana-account-view", + "solana-address 2.0.0", + "solana-define-syscall 4.0.1", + "solana-instruction-view", + "solana-program-error 3.0.0", +] + [[package]] name = "pinocchio-log" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89f8ffd986174cefe59448295a004aaf70c3605f30de066f42d27b06188f267" +checksum = "cd11022408f312e6179ece321c1f7dc0d1b2aa7765fddd39b2a7378d65a899e8" dependencies = [ "pinocchio-log-macro", ] [[package]] name = "pinocchio-log-macro" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6edac6ac2c9c456b850d3e908b7f224a54623f6c5b75906b9e48a4e248fb332b" +checksum = "69fb52edb3c5736b044cc462b0957b9767d0f574d138f4e2761438c498a4b467" dependencies = [ "quote", "regex", @@ -2249,19 +2283,19 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0225638cadcbebae8932cb7f49cb5da7c15c21beb19f048f05a5ca7d93f065" dependencies = [ - "five8_const", - "pinocchio", + "five8_const 0.1.4", + "pinocchio 0.9.2", "sha2-const-stable", ] [[package]] name = "pinocchio-system" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2a6dad40b5e75d1486f021619c4bd504c34c1362c9b94ed7fa525b1cc63cc" +checksum = "24044a0815753862b558e179e78f03f7344cb755de48617a09d7d23b50883b6c" dependencies = [ - "pinocchio", - "pinocchio-pubkey", + "pinocchio 0.10.1", + "solana-address 2.0.0", ] [[package]] @@ -2340,7 +2374,7 @@ name = "processing-instructions-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "solana-instruction 3.0.0", "solana-keypair", @@ -2403,7 +2437,7 @@ name = "program-derived-addresses-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-system", "solana-instruction 3.0.0", "solana-keypair", @@ -2532,7 +2566,7 @@ name = "realloc-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "pinocchio-system", "solana-instruction 3.0.0", @@ -2609,7 +2643,7 @@ name = "rent_pinocchio_program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-log", "pinocchio-system", "solana-instruction 3.0.0", @@ -2955,6 +2989,16 @@ dependencies = [ "solana-pubkey 3.0.0", ] +[[package]] +name = "solana-account-view" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f37ca34c37f92ee341b73d5ce7c8ef5bb38e9a87955b4bd343c63fa18b149215" +dependencies = [ + "solana-address 2.0.0", + "solana-program-error 3.0.0", +] + [[package]] name = "solana-address" version = "1.0.0" @@ -2965,8 +3009,8 @@ dependencies = [ "bytemuck", "bytemuck_derive", "curve25519-dalek 4.1.3", - "five8", - "five8_const", + "five8 0.2.1", + "five8_const 0.1.4", "rand 0.8.5", "serde", "serde_derive", @@ -2977,6 +3021,18 @@ dependencies = [ "solana-sha256-hasher 3.0.0", ] +[[package]] +name = "solana-address" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e37320fd2945c5d654b2c6210624a52d66c3f1f73b653ed211ab91a703b35bdd" +dependencies = [ + "five8 1.0.0", + "five8_const 1.0.0", + "solana-define-syscall 4.0.1", + "solana-program-error 3.0.0", +] + [[package]] name = "solana-address-lookup-table-interface" version = "2.2.2" @@ -3380,6 +3436,12 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9697086a4e102d28a156b8d6b521730335d6951bd39a5e766512bbe09007cee" +[[package]] +name = "solana-define-syscall" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e5b1c0bc1d4a4d10c88a4100499d954c09d3fecfae4912c1a074dff68b1738" + [[package]] name = "solana-derivation-path" version = "3.0.0" @@ -3634,7 +3696,7 @@ dependencies = [ "borsh 1.5.7", "bytemuck", "bytemuck_derive", - "five8", + "five8 0.2.1", "js-sys", "serde", "serde_derive", @@ -3652,7 +3714,7 @@ dependencies = [ "borsh 1.5.7", "bytemuck", "bytemuck_derive", - "five8", + "five8 0.2.1", "serde", "serde_derive", "solana-atomic-u64 3.0.0", @@ -3714,6 +3776,18 @@ dependencies = [ "solana-program-error 3.0.0", ] +[[package]] +name = "solana-instruction-view" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60147e4d0a4620013df40bf30a86dd299203ff12fcb8b593cd51014fce0875d8" +dependencies = [ + "solana-account-view", + "solana-address 2.0.0", + "solana-define-syscall 4.0.1", + "solana-program-error 3.0.0", +] + [[package]] name = "solana-instructions-sysvar" version = "2.2.2" @@ -3793,7 +3867,7 @@ checksum = "952ed9074c12edd2060cb09c2a8c664303f4ab7f7056a407ac37dd1da7bdaa3e" dependencies = [ "ed25519-dalek 2.2.0", "ed25519-dalek-bip32", - "five8", + "five8 0.2.1", "rand 0.8.5", "solana-derivation-path", "solana-pubkey 3.0.0", @@ -3976,7 +4050,7 @@ dependencies = [ "lazy_static", "serde", "serde_derive", - "solana-address", + "solana-address 1.0.0", "solana-hash 3.0.0", "solana-instruction 3.0.0", "solana-sanitize 3.0.1", @@ -4397,8 +4471,8 @@ dependencies = [ "bytemuck", "bytemuck_derive", "curve25519-dalek 4.1.3", - "five8", - "five8_const", + "five8 0.2.1", + "five8_const 0.1.4", "getrandom 0.2.16", "js-sys", "num-traits", @@ -4419,7 +4493,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8909d399deb0851aa524420beeb5646b115fd253ef446e35fe4504c904da3941" dependencies = [ "rand 0.8.5", - "solana-address", + "solana-address 1.0.0", ] [[package]] @@ -4732,7 +4806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bb8057cc0e9f7b5e89883d49de6f407df655bb6f3a71d0b7baf9986a2218fd9" dependencies = [ "ed25519-dalek 2.2.0", - "five8", + "five8 0.2.1", "rand 0.8.5", "serde", "serde-big-array", @@ -5123,7 +5197,7 @@ dependencies = [ "bincode", "serde", "serde_derive", - "solana-address", + "solana-address 1.0.0", "solana-hash 3.0.0", "solana-instruction 3.0.0", "solana-instruction-error", @@ -5782,7 +5856,7 @@ name = "transfer-sol-pinocchio-program" version = "0.1.0" dependencies = [ "litesvm", - "pinocchio", + "pinocchio 0.10.1", "pinocchio-system", "solana-instruction 3.0.0", "solana-keypair", diff --git a/Cargo.toml b/Cargo.toml index 9e3984b75..413032468 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,9 +77,9 @@ spl-associated-token-account-interface = "2.0.0" spl-token-2022-interface = "2.0.0" # pinocchio -pinocchio = "0.9.2" -pinocchio-log = "0.4.0" -pinocchio-system = "0.4.0" +pinocchio = { version = "0.10.1", features = ["cpi"] } +pinocchio-log = "0.5.1" +pinocchio-system = "0.5.0" pinocchio-pubkey = "0.3.0" # testing diff --git a/basics/account-data/pinocchio/package.json b/basics/account-data/pinocchio/package.json index 0423bc543..9fa753258 100644 --- a/basics/account-data/pinocchio/package.json +++ b/basics/account-data/pinocchio/package.json @@ -4,7 +4,7 @@ "test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/index.test.ts", "build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test", "build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so", - "deploy": "solana program deploy ./program/target/so/hello_solana_program_pinocchio.so" + "deploy": "solana program deploy ./program/target/so/account_data_pinocchio_program.so" }, "dependencies": { "@solana/web3.js": "^1.47.3" @@ -13,10 +13,9 @@ "@types/bn.js": "^5.1.0", "@types/chai": "^4.3.1", "@types/mocha": "^9.1.1", - "@types/node": "^22.15.2", "chai": "^4.3.4", + "litesvm": "^0.3.3", "mocha": "^9.0.3", - "solana-bankrun": "^0.3.0", "ts-mocha": "^10.0.0", "typescript": "^4.3.5" } diff --git a/basics/account-data/pinocchio/pnpm-lock.yaml b/basics/account-data/pinocchio/pnpm-lock.yaml index 187e1e651..031d4ece3 100644 --- a/basics/account-data/pinocchio/pnpm-lock.yaml +++ b/basics/account-data/pinocchio/pnpm-lock.yaml @@ -21,18 +21,15 @@ importers: '@types/mocha': specifier: ^9.1.1 version: 9.1.1 - '@types/node': - specifier: ^22.15.2 - version: 22.15.2 chai: specifier: ^4.3.4 version: 4.5.0 + litesvm: + specifier: ^0.3.3 + version: 0.3.3(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10) mocha: specifier: ^9.0.3 version: 9.2.2 - solana-bankrun: - specifier: ^0.3.0 - version: 0.3.1(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10) ts-mocha: specifier: ^10.0.0 version: 10.1.0(mocha@9.2.2) @@ -80,6 +77,9 @@ packages: '@solana/web3.js@1.98.2': resolution: {integrity: sha512-BqVwEG+TaG2yCkBMbD3C4hdpustR4FpuUFRPUmqRZYYlPI9Hg4XMWxHWOWRzHE9Lkc9NDjzXFX7lDXSgzC7R1A==} + '@solana/web3.js@1.98.4': + resolution: {integrity: sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw==} + '@swc/helpers@0.5.17': resolution: {integrity: sha512-5IKx/Y13RsYd+sauPb2x+U/xZikHjolzfuDgTAl/Tdf3Q8rslRvC19NKDLgAJQ6wsqADk10ntlv08nPFw/gO/A==} @@ -152,6 +152,9 @@ packages: base-x@3.0.11: resolution: {integrity: sha512-xz7wQ8xDhdyP7tQxwdteLYeFfS68tSMNCZ/Y37WJ4bhGfKPpqEIlmIyueQHqOyoPhE6xNUqjzRr8ra0eF9VRvA==} + base-x@5.0.1: + resolution: {integrity: sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg==} + base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} @@ -178,6 +181,9 @@ packages: bs58@4.0.1: resolution: {integrity: sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==} + bs58@6.0.0: + resolution: {integrity: sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw==} + buffer-from@1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} @@ -287,6 +293,9 @@ packages: fast-stable-stringify@1.0.0: resolution: {integrity: sha512-wpYMUmFu5f00Sm0cj2pfivpmawLZ0NKdviQ4w9zJeR8JVtOpOxHmLaJuj0vxvGqMJQWyP/COUkF75/57OKyRag==} + fastestsmallesttextencoderdecoder@1.0.22: + resolution: {integrity: sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==} + fill-range@7.1.1: resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} engines: {node: '>=8'} @@ -399,6 +408,40 @@ packages: resolution: {integrity: sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==} hasBin: true + litesvm-darwin-arm64@0.3.3: + resolution: {integrity: sha512-81YimsV3ezWjWLgoKixsXfVznaaecbURE3RtECgNb6Din6Za03pKGKGEN4gkyecHkv8uoPaEZv5cl6ARsgeN1Q==} + engines: {node: '>= 20'} + cpu: [arm64] + os: [darwin] + + litesvm-darwin-x64@0.3.3: + resolution: {integrity: sha512-pYietuU165Bl+2eDnVp2Eidiedfjt+pljyyBAfJPbYriaFyG577mU364NiNcsfQ8ZZWbe+ygIEAVq4Ol247+1g==} + engines: {node: '>= 20'} + cpu: [x64] + os: [darwin] + + litesvm-linux-arm64-musl@0.3.3: + resolution: {integrity: sha512-mkI15rWtNbaJxVFUfh+qnolqnDCZEqhwSZo/XZ48TZNsQ69vAqY00KhyFhTVJ+jeaYCAZTSNamuFIiRBxqVmNg==} + engines: {node: '>= 20'} + cpu: [arm64] + os: [linux] + + litesvm-linux-x64-gnu@0.3.3: + resolution: {integrity: sha512-Qai2/E8Eq03w8VKnJDREyiWxwavjykW/H6onE179ayMnBjVVmkj5fN7XF50VV4z73kasx5bpDzBNK8fcaxMdzA==} + engines: {node: '>= 20'} + cpu: [x64] + os: [linux] + + litesvm-linux-x64-musl@0.3.3: + resolution: {integrity: sha512-bpWZ2f506hbfu1y6bkmuZf+qqtnLDxggpOMTQbibjd+q6faEO3sETWwKGlIgHB99P8wyU+aXKwLSGQX2sJEw6Q==} + engines: {node: '>= 20'} + cpu: [x64] + os: [linux] + + litesvm@0.3.3: + resolution: {integrity: sha512-QHXjAIXzvG0uAMOza6aJcYl19yTKz3guwq/z0Zml4KnQxyQvPhjaBpUFc5sf2ey/NxMVdqFhoXmL02CXOOomjw==} + engines: {node: '>= 20'} + locate-path@6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -509,39 +552,6 @@ packages: serialize-javascript@6.0.0: resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} - solana-bankrun-darwin-arm64@0.3.1: - resolution: {integrity: sha512-9LWtH/3/WR9fs8Ve/srdo41mpSqVHmRqDoo69Dv1Cupi+o1zMU6HiEPUHEvH2Tn/6TDbPEDf18MYNfReLUqE6A==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] - - solana-bankrun-darwin-universal@0.3.1: - resolution: {integrity: sha512-muGHpVYWT7xCd8ZxEjs/bmsbMp8XBqroYGbE4lQPMDUuLvsJEIrjGqs3MbxEFr71sa58VpyvgywWd5ifI7sGIg==} - engines: {node: '>= 10'} - os: [darwin] - - solana-bankrun-darwin-x64@0.3.1: - resolution: {integrity: sha512-oCaxfHyt7RC3ZMldrh5AbKfy4EH3YRMl8h6fSlMZpxvjQx7nK7PxlRwMeflMnVdkKKp7U8WIDak1lilIPd3/lg==} - engines: {node: '>= 10'} - cpu: [x64] - os: [darwin] - - solana-bankrun-linux-x64-gnu@0.3.1: - resolution: {integrity: sha512-PfRFhr7igGFNt2Ecfdzh3li9eFPB3Xhmk0Eib17EFIB62YgNUg3ItRnQQFaf0spazFjjJLnglY1TRKTuYlgSVA==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - - solana-bankrun-linux-x64-musl@0.3.1: - resolution: {integrity: sha512-6r8i0NuXg3CGURql8ISMIUqhE7Hx/O7MlIworK4oN08jYrP0CXdLeB/hywNn7Z8d1NXrox/NpYUgvRm2yIzAsQ==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - - solana-bankrun@0.3.1: - resolution: {integrity: sha512-inRwON7fBU5lPC36HdEqPeDg15FXJYcf77+o0iz9amvkUMJepcwnRwEfTNyMVpVYdgjTOBW5vg+596/3fi1kGA==} - engines: {node: '>= 10'} - source-map-support@0.5.21: resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} @@ -756,6 +766,29 @@ snapshots: - typescript - utf-8-validate + '@solana/web3.js@1.98.4(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10)': + dependencies: + '@babel/runtime': 7.27.0 + '@noble/curves': 1.9.0 + '@noble/hashes': 1.8.0 + '@solana/buffer-layout': 4.0.1 + '@solana/codecs-numbers': 2.1.0(typescript@4.9.5) + agentkeepalive: 4.6.0 + bn.js: 5.2.1 + borsh: 0.7.0 + bs58: 4.0.1 + buffer: 6.0.3 + fast-stable-stringify: 1.0.0 + jayson: 4.2.0(bufferutil@4.0.9)(utf-8-validate@5.0.10) + node-fetch: 2.7.0 + rpc-websockets: 9.1.1 + superstruct: 2.0.2 + transitivePeerDependencies: + - bufferutil + - encoding + - typescript + - utf-8-validate + '@swc/helpers@0.5.17': dependencies: tslib: 2.8.1 @@ -822,6 +855,8 @@ snapshots: dependencies: safe-buffer: 5.2.1 + base-x@5.0.1: {} + base64-js@1.5.1: {} binary-extensions@2.3.0: {} @@ -849,6 +884,10 @@ snapshots: dependencies: base-x: 3.0.11 + bs58@6.0.0: + dependencies: + base-x: 5.0.1 + buffer-from@1.1.2: {} buffer@6.0.3: @@ -950,6 +989,8 @@ snapshots: fast-stable-stringify@1.0.0: {} + fastestsmallesttextencoderdecoder@1.0.22: {} + fill-range@7.1.1: dependencies: to-regex-range: 5.0.1 @@ -1055,6 +1096,38 @@ snapshots: minimist: 1.2.8 optional: true + litesvm-darwin-arm64@0.3.3: + optional: true + + litesvm-darwin-x64@0.3.3: + optional: true + + litesvm-linux-arm64-musl@0.3.3: + optional: true + + litesvm-linux-x64-gnu@0.3.3: + optional: true + + litesvm-linux-x64-musl@0.3.3: + optional: true + + litesvm@0.3.3(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10): + dependencies: + '@solana/web3.js': 1.98.4(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10) + bs58: 6.0.0 + fastestsmallesttextencoderdecoder: 1.0.22 + optionalDependencies: + litesvm-darwin-arm64: 0.3.3 + litesvm-darwin-x64: 0.3.3 + litesvm-linux-arm64-musl: 0.3.3 + litesvm-linux-x64-gnu: 0.3.3 + litesvm-linux-x64-musl: 0.3.3 + transitivePeerDependencies: + - bufferutil + - encoding + - typescript + - utf-8-validate + locate-path@6.0.0: dependencies: p-locate: 5.0.0 @@ -1177,37 +1250,6 @@ snapshots: dependencies: randombytes: 2.1.0 - solana-bankrun-darwin-arm64@0.3.1: - optional: true - - solana-bankrun-darwin-universal@0.3.1: - optional: true - - solana-bankrun-darwin-x64@0.3.1: - optional: true - - solana-bankrun-linux-x64-gnu@0.3.1: - optional: true - - solana-bankrun-linux-x64-musl@0.3.1: - optional: true - - solana-bankrun@0.3.1(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10): - dependencies: - '@solana/web3.js': 1.98.2(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10) - bs58: 4.0.1 - optionalDependencies: - solana-bankrun-darwin-arm64: 0.3.1 - solana-bankrun-darwin-universal: 0.3.1 - solana-bankrun-darwin-x64: 0.3.1 - solana-bankrun-linux-x64-gnu: 0.3.1 - solana-bankrun-linux-x64-musl: 0.3.1 - transitivePeerDependencies: - - bufferutil - - encoding - - typescript - - utf-8-validate - source-map-support@0.5.21: dependencies: buffer-from: 1.1.2 diff --git a/basics/account-data/pinocchio/program/src/lib.rs b/basics/account-data/pinocchio/program/src/lib.rs index 0cdb75010..937cf3d7c 100644 --- a/basics/account-data/pinocchio/program/src/lib.rs +++ b/basics/account-data/pinocchio/program/src/lib.rs @@ -1,12 +1,11 @@ #![no_std] use pinocchio::{ - account_info::AccountInfo, - entrypoint, nostd_panic_handler, - program_error::ProgramError, - pubkey::Pubkey, + entrypoint, + error::ProgramError, + nostd_panic_handler, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; use pinocchio_system::instructions::CreateAccount; @@ -14,8 +13,8 @@ entrypoint!(process_instruction); nostd_panic_handler!(); fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { match instruction_data.split_first() { @@ -36,8 +35,8 @@ impl<'a> AddressInfo<'a> { } fn process_create( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [address_info, payer, system_program] = accounts else { @@ -52,7 +51,7 @@ fn process_create( return Err(ProgramError::InvalidAccountData); }; - if !pinocchio_system::check_id(system_program.key()) { + if !pinocchio_system::check_id(system_program.address()) { return Err(ProgramError::InvalidAccountData); } @@ -63,7 +62,7 @@ fn process_create( let rent = Rent::get()?; let account_span = AddressInfo::LEN; - let lamports_required = rent.minimum_balance(account_span); + let lamports_required = rent.try_minimum_balance(account_span)?; CreateAccount { from: payer, @@ -74,7 +73,7 @@ fn process_create( } .invoke()?; - let mut address_info_data = address_info.try_borrow_mut_data()?; + let mut address_info_data = address_info.try_borrow_mut()?; address_info_data.copy_from_slice(instruction_data); Ok(()) diff --git a/basics/account-data/pinocchio/tests/index.test.ts b/basics/account-data/pinocchio/tests/index.test.ts index 07be2d7d5..1fac4271e 100644 --- a/basics/account-data/pinocchio/tests/index.test.ts +++ b/basics/account-data/pinocchio/tests/index.test.ts @@ -1,13 +1,13 @@ -import { Buffer } from "node:buffer"; +import { readFileSync } from "node:fs"; import { describe, test } from "node:test"; import { Keypair, - PublicKey, + LAMPORTS_PER_SOL, SystemProgram, Transaction, TransactionInstruction, } from "@solana/web3.js"; -import { start } from "solana-bankrun"; +import { LiteSVM } from "litesvm"; interface AddressInfo { name: string; @@ -71,19 +71,34 @@ function fromBytes(buffer: Buffer): AddressInfo { return { name, house_number, street, city }; } -describe("Account Data!", async () => { - const addressInfoAccount = Keypair.generate(); - const PROGRAM_ID = PublicKey.unique(); - const context = await start( - [{ name: "account_data_pinocchio_program", programId: PROGRAM_ID }], - [], - ); - const client = context.banksClient; +describe("Account Data!", () => { + // Load the program keypair + const programKeypairPath = new URL( + "./fixtures/account_data_pinocchio_program-keypair.json", + // @ts-ignore + import.meta.url, + ).pathname; + const programKeypairData = JSON.parse(readFileSync(programKeypairPath, "utf-8")); + const programKeypair = Keypair.fromSecretKey(new Uint8Array(programKeypairData)); + const PROGRAM_ID = programKeypair.publicKey; + + // Load the program + const programPath = new URL( + "./fixtures/account_data_pinocchio_program.so", + // @ts-ignore + import.meta.url, + ).pathname; + + const litesvm = new LiteSVM(); + litesvm.addProgramFromFile(PROGRAM_ID, programPath); + + const payer = Keypair.generate(); + litesvm.airdrop(payer.publicKey, BigInt(100 * LAMPORTS_PER_SOL)); - test("Create the address info account", async () => { - const payer = context.payer; + const addressInfoAccount = Keypair.generate(); - console.log(`Program Address : ${PROGRAM_ID}`); + test("Create the address info account", () => { + console.log(`Program Address : ${PROGRAM_ID}`); console.log(`Payer Address : ${payer.publicKey}`); console.log(`Address Info Acct : ${addressInfoAccount.publicKey}`); @@ -108,16 +123,20 @@ describe("Account Data!", async () => { data: toBytes(addressInfo), }); - const blockhash = context.lastBlockhash; + const tx = new Transaction().add(ix); + tx.feePayer = payer.publicKey; + tx.recentBlockhash = litesvm.latestBlockhash(); + tx.sign(payer, addressInfoAccount); - const tx = new Transaction(); - tx.recentBlockhash = blockhash; - tx.add(ix).sign(payer, addressInfoAccount); - await client.processTransaction(tx); + litesvm.sendTransaction(tx); }); - test("Read the new account's data", async () => { - const accountInfo = await client.getAccount(addressInfoAccount.publicKey); + test("Read the new account's data", () => { + const accountInfo = litesvm.getAccount(addressInfoAccount.publicKey); + + if (!accountInfo) { + throw new Error("Account not found"); + } const readAddressInfo = fromBytes(Buffer.from(accountInfo.data)); diff --git a/basics/checking-accounts/pinocchio/program/src/lib.rs b/basics/checking-accounts/pinocchio/program/src/lib.rs index 0aa10d413..9640f3b35 100644 --- a/basics/checking-accounts/pinocchio/program/src/lib.rs +++ b/basics/checking-accounts/pinocchio/program/src/lib.rs @@ -1,8 +1,7 @@ #![no_std] use pinocchio::{ - account_info::AccountInfo, entrypoint, nostd_panic_handler, program_error::ProgramError, - pubkey::Pubkey, ProgramResult, + entrypoint, error::ProgramError, nostd_panic_handler, AccountView, Address, ProgramResult, }; use pinocchio_log::log; @@ -10,8 +9,8 @@ entrypoint!(process_instruction); nostd_panic_handler!(); fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], _instruction_data: &[u8], ) -> ProgramResult { // You can verify the list has the correct number of accounts. @@ -32,7 +31,7 @@ fn process_instruction( // You can make sure an account has NOT been initialized. - log!("New account: {}", account_to_create.key()); + log!("New account: {}", account_to_create.address().as_array()); if account_to_create.lamports() != 0 { log!("The program expected the account to create to not yet be initialized."); return Err(ProgramError::AccountAlreadyInitialized); @@ -40,20 +39,23 @@ fn process_instruction( // (Create account...) // You can also make sure an account has been initialized. - log!("Account to change: {}", account_to_change.key()); + log!( + "Account to change: {}", + account_to_change.address().as_array() + ); if account_to_change.lamports() == 0 { log!("The program expected the account to change to be initialized."); return Err(ProgramError::UninitializedAccount); }; // If we want to modify an account's data, it must be owned by our program. - if account_to_change.owner() != program_id { + if !account_to_change.owned_by(program_id) { log!("Account to change does not have the correct program id."); return Err(ProgramError::IncorrectProgramId); }; // You can also check pubkeys against constants. - if system_program.key() != &pinocchio_system::ID { + if system_program.address() != &pinocchio_system::ID { return Err(ProgramError::IncorrectProgramId); }; diff --git a/basics/close-account/pinocchio/program/Cargo.toml b/basics/close-account/pinocchio/program/Cargo.toml index a792f896c..e1c7f3307 100644 --- a/basics/close-account/pinocchio/program/Cargo.toml +++ b/basics/close-account/pinocchio/program/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] pinocchio.workspace = true pinocchio-log.workspace = true +pinocchio-pubkey.workspace = true pinocchio-system.workspace = true [dev-dependencies] diff --git a/basics/close-account/pinocchio/program/src/lib.rs b/basics/close-account/pinocchio/program/src/lib.rs index a8f3dc361..d63f67b04 100644 --- a/basics/close-account/pinocchio/program/src/lib.rs +++ b/basics/close-account/pinocchio/program/src/lib.rs @@ -1,14 +1,12 @@ #![no_std] use pinocchio::{ - account_info::AccountInfo, + cpi::{Seed, Signer}, entrypoint, - instruction::{Seed, Signer}, + error::ProgramError, nostd_panic_handler, - program_error::ProgramError, - pubkey::Pubkey, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; use pinocchio_system::instructions::CreateAccount; @@ -16,8 +14,8 @@ entrypoint!(process_instruction); nostd_panic_handler!(); fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { match instruction_data.split_first() { @@ -40,8 +38,8 @@ impl<'a> User<'a> { } fn process_user( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [target_account, payer, _system_program] = accounts else { @@ -51,17 +49,13 @@ fn process_user( let rent = Rent::get()?; let account_span = User::LEN; - let lamports_required = rent.minimum_balance(account_span); + let lamports_required = rent.try_minimum_balance(account_span)?; - let (_, bump) = pinocchio::pubkey::find_program_address( - &[User::SEED_PREFIX.as_bytes(), payer.key()], - program_id, - ); - let bump_bytes = bump.to_le_bytes(); + let bump_bytes = instruction_data[0].to_le_bytes(); let seeds = [ Seed::from(User::SEED_PREFIX.as_bytes()), - Seed::from(payer.key().as_ref()), + Seed::from(payer.address().as_ref()), Seed::from(&bump_bytes), ]; let signers = [Signer::from(&seeds)]; @@ -75,13 +69,13 @@ fn process_user( } .invoke_signed(&signers)?; - let mut address_info_data = target_account.try_borrow_mut_data()?; - address_info_data.copy_from_slice(instruction_data); + let mut address_info_data = target_account.try_borrow_mut()?; + address_info_data.copy_from_slice(&instruction_data[1..]); Ok(()) } -fn process_close(accounts: &[AccountInfo]) -> ProgramResult { +fn process_close(accounts: &[AccountView]) -> ProgramResult { let [target_account, payer, system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; @@ -89,17 +83,17 @@ fn process_close(accounts: &[AccountInfo]) -> ProgramResult { let rent = Rent::get()?; let account_span = 0usize; - let lamports_required = rent.minimum_balance(account_span); + let lamports_required = rent.try_minimum_balance(account_span)?; let diff = target_account.lamports() - lamports_required; - *target_account.try_borrow_mut_lamports()? -= diff; - *payer.try_borrow_mut_lamports()? += diff; + target_account.set_lamports(target_account.lamports() - diff); + payer.set_lamports(payer.lamports() + diff); target_account.resize(account_span)?; unsafe { - target_account.assign(system_program.key()); + target_account.assign(system_program.address()); } Ok(()) diff --git a/basics/close-account/pinocchio/program/tests/tests.rs b/basics/close-account/pinocchio/program/tests/tests.rs index 41e51bf93..9814b4d4d 100644 --- a/basics/close-account/pinocchio/program/tests/tests.rs +++ b/basics/close-account/pinocchio/program/tests/tests.rs @@ -22,8 +22,16 @@ fn test_close_account() { let test_account_pubkey = Pubkey::find_program_address(&[b"USER".as_ref(), &payer.pubkey().as_ref()], &program_id).0; + let bump = Pubkey::find_program_address( + &[User::SEED_PREFIX.as_bytes(), payer.pubkey().as_ref()], + &program_id, + ) + .1; + + // process_user let mut data = Vec::new(); data.push(CREATE_DISCRIMINATOR); + data.push(bump); let mut name = [0u8; User::LEN]; let name_len = b"Jacob".len().min(User::LEN); name[..name_len].copy_from_slice(&b"Jacob"[..name_len]); @@ -54,6 +62,7 @@ fn test_close_account() { assert_eq!(account.owner, program_id); assert_eq!(&account.data[..5], b"Jacob"); + // process_close let mut data = Vec::new(); data.push(CLOSE_DISCRIMINATOR); diff --git a/basics/counter/pinocchio/program/src/lib.rs b/basics/counter/pinocchio/program/src/lib.rs index 53bb40c9c..ed0a0de8d 100644 --- a/basics/counter/pinocchio/program/src/lib.rs +++ b/basics/counter/pinocchio/program/src/lib.rs @@ -1,9 +1,6 @@ #![no_std] -use pinocchio::{ - account_info::AccountInfo, nostd_panic_handler, program_error::ProgramError, pubkey::Pubkey, - ProgramResult, -}; +use pinocchio::{error::ProgramError, nostd_panic_handler, AccountView, Address, ProgramResult}; use pinocchio_log::log; mod state; @@ -20,8 +17,8 @@ entrypoint!(process_instruction); nostd_panic_handler!(); pub fn process_instruction( - _program_id: &Pubkey, - accounts: &[AccountInfo], + _program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let (instruction_discriminant, instruction_data_inner) = instruction_data.split_at(1); @@ -38,7 +35,7 @@ pub fn process_instruction( } pub fn process_increment_counter( - accounts: &[AccountInfo], + accounts: &[AccountView], _instruction_data: &[u8], ) -> Result<(), ProgramError> { let [counter_account] = accounts else { @@ -50,7 +47,7 @@ pub fn process_increment_counter( "Counter account must be writable" ); - let mut counter_account_data = counter_account.try_borrow_mut_data()?; + let mut counter_account_data = counter_account.try_borrow_mut()?; // Read the current counter value (first 8 bytes) let counter_bytes: [u8; 8] = counter_account_data[0..8] diff --git a/basics/create-account/pinocchio/program/src/lib.rs b/basics/create-account/pinocchio/program/src/lib.rs index 7f2bc0b9e..ea66cfd75 100644 --- a/basics/create-account/pinocchio/program/src/lib.rs +++ b/basics/create-account/pinocchio/program/src/lib.rs @@ -1,8 +1,7 @@ #![no_std] use pinocchio::{ - account_info::AccountInfo, entrypoint, nostd_panic_handler, program_error::ProgramError, - pubkey::Pubkey, ProgramResult, + entrypoint, error::ProgramError, nostd_panic_handler, AccountView, Address, ProgramResult, }; use pinocchio_log::log; @@ -14,8 +13,8 @@ nostd_panic_handler!(); const LAMPORTS_PER_SOL: u64 = 1_000_000_000; fn process_instruction( - _program_id: &Pubkey, - accounts: &[AccountInfo], + _program_id: &Address, + accounts: &[AccountView], _instruction_data: &[u8], ) -> ProgramResult { let [payer, new_account, _system_program] = accounts else { @@ -24,7 +23,7 @@ fn process_instruction( log!("Program invoked. Creating a system account..."); log!(" New public key will be:"); - pinocchio::pubkey::log(new_account.key()); + log!("{}", new_account.address().as_array()); CreateAccount { from: payer, diff --git a/basics/favorites/pinocchio/program/Cargo.toml b/basics/favorites/pinocchio/program/Cargo.toml index ffdefcf1c..576a8c916 100644 --- a/basics/favorites/pinocchio/program/Cargo.toml +++ b/basics/favorites/pinocchio/program/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] pinocchio.workspace = true pinocchio-log.workspace = true +pinocchio-pubkey.workspace = true pinocchio-system.workspace = true diff --git a/basics/favorites/pinocchio/program/src/instructions/create_pda.rs b/basics/favorites/pinocchio/program/src/instructions/create_pda.rs index 89192a9ae..8140b2aea 100644 --- a/basics/favorites/pinocchio/program/src/instructions/create_pda.rs +++ b/basics/favorites/pinocchio/program/src/instructions/create_pda.rs @@ -1,43 +1,46 @@ use crate::state::Favorites; use pinocchio::{ - account_info::AccountInfo, - instruction::{Seed, Signer}, - program_error::ProgramError, - pubkey::{find_program_address, Pubkey}, + cpi::{Seed, Signer}, + error::ProgramError, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; +use pinocchio_pubkey::derive_address; use pinocchio_system::instructions::CreateAccount; -pub fn create_pda(program_id: &Pubkey, accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { +pub fn create_pda(program_id: &Address, accounts: &[AccountView], data: &[u8]) -> ProgramResult { let [user, favorite_account, _] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; // deriving the favorite pda - let (favorite_pda, favorite_bump) = - find_program_address(&[b"favorite", user.key().as_ref()], program_id); + let bump = data[0]; + let favorite_pda = derive_address( + &[b"favorite", user.address().as_ref()], + Some(bump), + program_id.as_array(), + ); // Checking if the favorite account is same as the derived favorite pda - if favorite_account.key() != &favorite_pda { + if favorite_account.address().as_array() != &favorite_pda { return Err(ProgramError::IncorrectProgramId); } // Checking if the pda is already initialized - if favorite_account.try_borrow_data()?.is_empty() { + if favorite_account.try_borrow()?.is_empty() { let rent = Rent::get()?; // Initialize the favorite account if it's not initialized let space = size_of::(); - let lamports = rent.minimum_balance(space); + let lamports = rent.try_minimum_balance(space)?; - let bump_bytes = favorite_bump.to_le_bytes(); + let bump_bytes = bump.to_le_bytes(); let seeds = [ Seed::from(b"favorite"), - Seed::from(user.key()), + Seed::from(user.address().as_ref()), Seed::from(&bump_bytes), ]; @@ -53,8 +56,8 @@ pub fn create_pda(program_id: &Pubkey, accounts: &[AccountInfo], data: &[u8]) -> .invoke_signed(&signers)?; // Serialize and store the data - let mut favrite_account_data = favorite_account.try_borrow_mut_data()?; - favrite_account_data.copy_from_slice(data); + let mut favrite_account_data = favorite_account.try_borrow_mut()?; + favrite_account_data.copy_from_slice(&data[1..]); } else { return Err(ProgramError::AccountAlreadyInitialized); } diff --git a/basics/favorites/pinocchio/program/src/instructions/get_pda.rs b/basics/favorites/pinocchio/program/src/instructions/get_pda.rs index 033c4f37c..88ea00cb3 100644 --- a/basics/favorites/pinocchio/program/src/instructions/get_pda.rs +++ b/basics/favorites/pinocchio/program/src/instructions/get_pda.rs @@ -1,25 +1,26 @@ -use pinocchio::{ - account_info::AccountInfo, - program_error::ProgramError, - pubkey::{find_program_address, Pubkey}, - ProgramResult, -}; +use pinocchio::{error::ProgramError, AccountView, Address, ProgramResult}; use pinocchio_log::log; +use pinocchio_pubkey::derive_address; -pub fn get_pda(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { +pub fn get_pda(program_id: &Address, accounts: &[AccountView], data: &[u8]) -> ProgramResult { let [user, favorite_account] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; // deriving the favorite pda - let (favorite_pda, _) = find_program_address(&[b"favorite", user.key().as_ref()], program_id); + let bump = data[0]; + let favorite_pda = derive_address( + &[b"favorite", user.address().as_ref()], + Some(bump), + program_id.as_array(), + ); // Checking if the favorite account is same as the derived favorite pda - if favorite_account.key() != &favorite_pda { + if favorite_account.address().as_array() != &favorite_pda { return Err(ProgramError::IncorrectProgramId); }; - let favorites = favorite_account.try_borrow_data()?; + let favorites = favorite_account.try_borrow()?; let number = u64::from_le_bytes( favorites[0..8] @@ -44,7 +45,7 @@ pub fn get_pda(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { log!( 300, "User {}'s favorite number is {}, favorite color is: {}, and their hobbies are {} {} {} {}", - user.key(), + user.address().as_array(), number, color, hobby1, diff --git a/basics/favorites/pinocchio/program/src/processor.rs b/basics/favorites/pinocchio/program/src/processor.rs index 808e68202..57cf6e702 100644 --- a/basics/favorites/pinocchio/program/src/processor.rs +++ b/basics/favorites/pinocchio/program/src/processor.rs @@ -1,20 +1,18 @@ -use pinocchio::{ - account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey, ProgramResult, -}; +use pinocchio::{error::ProgramError, AccountView, Address, ProgramResult}; use crate::instructions::{create_pda::*, get_pda::*}; pub use crate::state::Favorites; pub fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let (discriminator, ix_data) = instruction_data.split_first().unwrap(); match discriminator { 1 => create_pda(program_id, accounts, ix_data), - 2 => get_pda(program_id, accounts), + 2 => get_pda(program_id, accounts, ix_data), _ => Err(ProgramError::InvalidInstructionData), }?; diff --git a/basics/favorites/pinocchio/program/tests/test.rs b/basics/favorites/pinocchio/program/tests/test.rs index b6c29c87f..8b3eddeac 100644 --- a/basics/favorites/pinocchio/program/tests/test.rs +++ b/basics/favorites/pinocchio/program/tests/test.rs @@ -17,12 +17,13 @@ fn test_favorites() { svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap(); - let favorites_pda = - Pubkey::find_program_address(&[b"favorite", payer.pubkey().as_ref()], &program_id).0; + let (favorites_pda, favorites_bump) = + Pubkey::find_program_address(&[b"favorite", payer.pubkey().as_ref()], &program_id); let mut data = Vec::new(); data.push(1); + data.push(favorites_bump); data.extend_from_slice(&u64::to_le_bytes(42)); @@ -73,6 +74,7 @@ fn test_favorites() { let mut data = Vec::new(); data.push(2); + data.push(favorites_bump); let ix = Instruction { program_id, diff --git a/basics/hello-solana/pinocchio/program/src/lib.rs b/basics/hello-solana/pinocchio/program/src/lib.rs index a313b1965..2044eded4 100644 --- a/basics/hello-solana/pinocchio/program/src/lib.rs +++ b/basics/hello-solana/pinocchio/program/src/lib.rs @@ -1,8 +1,5 @@ use pinocchio::{ - account_info::AccountInfo, - default_panic_handler, no_allocator, program_entrypoint, - pubkey::{self, Pubkey}, - ProgramResult, + default_panic_handler, no_allocator, program_entrypoint, AccountView, Address, ProgramResult, }; use pinocchio_log::log; @@ -15,13 +12,13 @@ default_panic_handler!(); #[inline(always)] fn process_instruction( - program_id: &Pubkey, - _accounts: &[AccountInfo], + program_id: &Address, + _accounts: &[AccountView], _instruction_data: &[u8], ) -> ProgramResult { log!("Hello, Solana!"); - pubkey::log(program_id); + log!("{}", program_id.as_array()); Ok(()) } diff --git a/basics/hello-solana/pinocchio/tests/index.test.ts b/basics/hello-solana/pinocchio/tests/index.test.ts index 8bddf0509..734bad24f 100644 --- a/basics/hello-solana/pinocchio/tests/index.test.ts +++ b/basics/hello-solana/pinocchio/tests/index.test.ts @@ -31,7 +31,7 @@ describe('hello-solana', () => { assert(transaction.logMessages[0].startsWith(`Program ${PROGRAM_ID}`)); assert(transaction.logMessages[1] === 'Program log: Hello, Solana!'); - assert(transaction.logMessages[2] === `Program log: ${PROGRAM_ID}`); + assert(transaction.logMessages[2] === `Program log: [${Array.from(PROGRAM_ID.toBytes()).join(', ')}]`); assert(transaction.logMessages[3].startsWith(`Program ${PROGRAM_ID} consumed`)); assert(transaction.logMessages[4] === `Program ${PROGRAM_ID} success`); assert(transaction.logMessages.length === 5); diff --git a/basics/pda-rent-payer/pinocchio/program/Cargo.toml b/basics/pda-rent-payer/pinocchio/program/Cargo.toml index afca652bc..acb1dee0b 100644 --- a/basics/pda-rent-payer/pinocchio/program/Cargo.toml +++ b/basics/pda-rent-payer/pinocchio/program/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] pinocchio.workspace = true pinocchio-log.workspace = true +pinocchio-pubkey.workspace = true pinocchio-system.workspace = true diff --git a/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs b/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs index 2991fdf39..0b746188d 100644 --- a/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs +++ b/basics/pda-rent-payer/pinocchio/program/src/instructions/create_new_account.rs @@ -1,28 +1,37 @@ use pinocchio::{ - account_info::AccountInfo, - program_error::ProgramError, - pubkey::{find_program_address, Pubkey}, + error::ProgramError, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; +use pinocchio_pubkey::derive_address; use crate::state::RentVault; -pub fn create_new_account(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { +pub fn create_new_account( + program_id: &Address, + accounts: &[AccountView], + instruction_data: &[u8], +) -> ProgramResult { let [new_account, rent_vault, _] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - let (rent_vault_pda, _rent_vault_bump) = - find_program_address(&[RentVault::SEED_PREFIX.as_bytes()], program_id); - assert!(rent_vault.key().eq(&rent_vault_pda)); + let bump = instruction_data[0]; + + let rent_vault_pda = derive_address( + &[RentVault::SEED_PREFIX.as_bytes()], + Some(bump), + program_id.as_array(), + ); + + assert!(rent_vault.address().as_array().eq(&rent_vault_pda)); // Assuming this account has no inner data (size 0) // - let lamports_required_for_rent = (Rent::get()?).minimum_balance(0); + let lamports_required_for_rent = (Rent::get()?).try_minimum_balance(0)?; - *rent_vault.try_borrow_mut_lamports()? -= lamports_required_for_rent; - *new_account.try_borrow_mut_lamports()? += lamports_required_for_rent; + rent_vault.set_lamports(rent_vault.lamports() - lamports_required_for_rent); + new_account.set_lamports(new_account.lamports() + lamports_required_for_rent); Ok(()) } diff --git a/basics/pda-rent-payer/pinocchio/program/src/instructions/init_rent_vault.rs b/basics/pda-rent-payer/pinocchio/program/src/instructions/init_rent_vault.rs index 3622075c2..28d28e6df 100644 --- a/basics/pda-rent-payer/pinocchio/program/src/instructions/init_rent_vault.rs +++ b/basics/pda-rent-payer/pinocchio/program/src/instructions/init_rent_vault.rs @@ -1,11 +1,10 @@ use pinocchio::{ - account_info::AccountInfo, - instruction::{Seed, Signer}, - program_error::ProgramError, - pubkey::{find_program_address, Pubkey}, + cpi::{Seed, Signer}, + error::ProgramError, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; +use pinocchio_pubkey::derive_address; use pinocchio_system::instructions::CreateAccount; use crate::state::RentVault; @@ -15,28 +14,34 @@ pub struct InitRentVaultArgs { } pub fn init_rent_vault( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [rent_vault, payer, _] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - let (rent_vault_pda, rent_vault_bump) = - find_program_address(&[RentVault::SEED_PREFIX.as_bytes()], program_id); - assert!(rent_vault.key().eq(&rent_vault_pda)); + let bump = instruction_data[0]; + + let rent_vault_pda = derive_address( + &[RentVault::SEED_PREFIX.as_bytes()], + Some(bump), + program_id.as_array(), + ); + + assert!(rent_vault.address().as_array().eq(&rent_vault_pda)); // Lamports for rent on the vault, plus the desired additional funding // let fund_lamports = u64::from_le_bytes( - instruction_data[0..8] + instruction_data[1..9] .try_into() .map_err(|_| ProgramError::InvalidInstructionData)?, ); - let lamports_required = (Rent::get()?).minimum_balance(0) + fund_lamports; + let lamports_required = (Rent::get()?).try_minimum_balance(0)? + fund_lamports; - let bump_bytes = rent_vault_bump.to_le_bytes(); + let bump_bytes = bump.to_le_bytes(); let seeds = [ Seed::from(RentVault::SEED_PREFIX.as_bytes()), diff --git a/basics/pda-rent-payer/pinocchio/program/src/processor.rs b/basics/pda-rent-payer/pinocchio/program/src/processor.rs index a65d599e4..b1ee364c1 100644 --- a/basics/pda-rent-payer/pinocchio/program/src/processor.rs +++ b/basics/pda-rent-payer/pinocchio/program/src/processor.rs @@ -1,6 +1,4 @@ -use pinocchio::{ - account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey, ProgramResult, -}; +use pinocchio::{error::ProgramError, AccountView, Address, ProgramResult}; use crate::instructions::{ create_new_account::create_new_account, @@ -13,13 +11,13 @@ pub enum MyInstruction { } pub fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { match instruction_data.split_first() { Some((0, data)) => init_rent_vault(program_id, accounts, data), - Some((1, _)) => create_new_account(program_id, accounts), + Some((1, data)) => create_new_account(program_id, accounts, data), _ => Err(ProgramError::InvalidInstructionData), } } diff --git a/basics/pda-rent-payer/pinocchio/program/tests/test.rs b/basics/pda-rent-payer/pinocchio/program/tests/test.rs index 741927c41..ce542922f 100644 --- a/basics/pda-rent-payer/pinocchio/program/tests/test.rs +++ b/basics/pda-rent-payer/pinocchio/program/tests/test.rs @@ -16,10 +16,12 @@ fn test_pda_rent_payer() { let payer = Keypair::new(); svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap(); - let rent_value_pda = Pubkey::find_program_address(&[b"rent_vault"], &program_id).0; + let (rent_value_pda, bump) = Pubkey::find_program_address(&[b"rent_vault"], &program_id); + // init_rent_vault let mut data = Vec::new(); data.push(0); + data.push(bump); data.extend_from_slice(&u64::to_le_bytes(1000000000)); let ix = Instruction { @@ -42,9 +44,11 @@ fn test_pda_rent_payer() { let res = svm.send_transaction(tx); assert!(res.is_ok()); + // create_new_account let new_account = Keypair::new(); - let data = vec![1]; + let mut data = vec![1]; + data.push(bump); let ix = Instruction { program_id, diff --git a/basics/processing-instructions/pinocchio/program/src/lib.rs b/basics/processing-instructions/pinocchio/program/src/lib.rs index 49e61decb..64296ff80 100644 --- a/basics/processing-instructions/pinocchio/program/src/lib.rs +++ b/basics/processing-instructions/pinocchio/program/src/lib.rs @@ -1,14 +1,11 @@ -use pinocchio::{ - account_info::AccountInfo, entrypoint, program_error::ProgramError, pubkey::Pubkey, - ProgramResult, -}; +use pinocchio::{entrypoint, error::ProgramError, AccountView, Address, ProgramResult}; use pinocchio_log::log; entrypoint!(process_instruction); fn process_instruction( - _program_id: &Pubkey, - _accounts: &[AccountInfo], + _program_id: &Address, + _accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let name = core::str::from_utf8(&instruction_data[0..8]) diff --git a/basics/program-derived-addresses/pinocchio/program/src/instructions/create.rs b/basics/program-derived-addresses/pinocchio/program/src/instructions/create.rs index 23c129e90..b0a8ed288 100644 --- a/basics/program-derived-addresses/pinocchio/program/src/instructions/create.rs +++ b/basics/program-derived-addresses/pinocchio/program/src/instructions/create.rs @@ -1,10 +1,8 @@ use pinocchio::{ - account_info::AccountInfo, - instruction::{Seed, Signer}, - program_error::ProgramError, - pubkey::Pubkey, + cpi::{Seed, Signer}, + error::ProgramError, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; use pinocchio_system::instructions::CreateAccount; @@ -12,8 +10,8 @@ use pinocchio_system::instructions::CreateAccount; use crate::state::PageVisits; pub fn create_page_visits( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [page_visits_account, user, payer, _] = accounts else { @@ -21,13 +19,13 @@ pub fn create_page_visits( }; let account_span = PageVisits::ACCOUNT_SPACE; - let lamports_required = (Rent::get()?).minimum_balance(account_span); + let lamports_required = (Rent::get()?).try_minimum_balance(account_span)?; let bump_bytes = &instruction_data[4..5]; let seeds = [ Seed::from(PageVisits::SEED_PREFIX.as_bytes()), - Seed::from(user.key().as_ref()), + Seed::from(user.address().as_ref()), Seed::from(bump_bytes), ]; diff --git a/basics/program-derived-addresses/pinocchio/program/src/instructions/increment.rs b/basics/program-derived-addresses/pinocchio/program/src/instructions/increment.rs index 9ac4a67e8..45da69ef9 100644 --- a/basics/program-derived-addresses/pinocchio/program/src/instructions/increment.rs +++ b/basics/program-derived-addresses/pinocchio/program/src/instructions/increment.rs @@ -1,11 +1,11 @@ -use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult}; +use pinocchio::{error::ProgramError, AccountView, ProgramResult}; -pub fn increment_page_visits(accounts: &[AccountInfo]) -> ProgramResult { +pub fn increment_page_visits(accounts: &[AccountView]) -> ProgramResult { let [page_visits_account] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - let mut page_visits_bytes = page_visits_account.try_borrow_mut_data()?; + let mut page_visits_bytes = page_visits_account.try_borrow_mut()?; let mut page_visits = u32::from_le_bytes( page_visits_bytes[0..4] diff --git a/basics/program-derived-addresses/pinocchio/program/src/processor.rs b/basics/program-derived-addresses/pinocchio/program/src/processor.rs index eb5f75718..1fc614d5a 100644 --- a/basics/program-derived-addresses/pinocchio/program/src/processor.rs +++ b/basics/program-derived-addresses/pinocchio/program/src/processor.rs @@ -1,12 +1,10 @@ -use pinocchio::{ - account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey, ProgramResult, -}; +use pinocchio::{error::ProgramError, AccountView, Address, ProgramResult}; use crate::instructions; pub fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { match instruction_data.split_first() { diff --git a/basics/realloc/pinocchio/program/src/instructions/create.rs b/basics/realloc/pinocchio/program/src/instructions/create.rs index 5a69113bf..9de50e129 100644 --- a/basics/realloc/pinocchio/program/src/instructions/create.rs +++ b/basics/realloc/pinocchio/program/src/instructions/create.rs @@ -1,17 +1,15 @@ use pinocchio::{ - account_info::AccountInfo, - program_error::ProgramError, - pubkey::Pubkey, + error::ProgramError, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; use pinocchio_system::instructions::CreateAccount; use crate::state::AddressInfo; pub fn create_address_info( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [target_account, payer, _] = accounts else { @@ -19,7 +17,7 @@ pub fn create_address_info( }; let account_span = AddressInfo::LEN; - let lamports_required = (Rent::get()?).minimum_balance(account_span); + let lamports_required = (Rent::get()?).try_minimum_balance(account_span)?; CreateAccount { from: payer, @@ -30,7 +28,7 @@ pub fn create_address_info( } .invoke()?; - let mut data = target_account.try_borrow_mut_data()?; + let mut data = target_account.try_borrow_mut()?; data.copy_from_slice(instruction_data); Ok(()) diff --git a/basics/realloc/pinocchio/program/src/instructions/reallocate.rs b/basics/realloc/pinocchio/program/src/instructions/reallocate.rs index 3eb13c73a..5001e36c1 100644 --- a/basics/realloc/pinocchio/program/src/instructions/reallocate.rs +++ b/basics/realloc/pinocchio/program/src/instructions/reallocate.rs @@ -1,15 +1,14 @@ use pinocchio::{ - account_info::AccountInfo, - program_error::ProgramError, + error::ProgramError, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, ProgramResult, }; use pinocchio_system::instructions::Transfer; use crate::state::{EnhancedAddressInfo, WorkInfo}; pub fn reallocate_without_zero_init( - accounts: &[AccountInfo], + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [target_account, payer, _] = accounts else { @@ -17,9 +16,9 @@ pub fn reallocate_without_zero_init( }; let account_span = EnhancedAddressInfo::LEN; - let lamports_required = (Rent::get()?).minimum_balance(account_span); + let lamports_required = (Rent::get()?).try_minimum_balance(account_span)?; - let diff = lamports_required - *target_account.try_borrow_lamports()?; + let diff = lamports_required - target_account.lamports(); Transfer { from: payer, @@ -30,13 +29,13 @@ pub fn reallocate_without_zero_init( target_account.resize(account_span)?; - let mut target_account_data = target_account.try_borrow_mut_data()?; + let mut target_account_data = target_account.try_borrow_mut()?; target_account_data[25..37].copy_from_slice(instruction_data); Ok(()) } -pub fn reallocate_zero_init(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { +pub fn reallocate_zero_init(accounts: &[AccountView], data: &[u8]) -> ProgramResult { let [target_account] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; @@ -45,7 +44,7 @@ pub fn reallocate_zero_init(accounts: &[AccountInfo], data: &[u8]) -> ProgramRes target_account.resize(account_span)?; - let mut target_account_data = target_account.try_borrow_mut_data()?; + let mut target_account_data = target_account.try_borrow_mut()?; target_account_data.copy_from_slice(data); Ok(()) diff --git a/basics/realloc/pinocchio/program/src/processor.rs b/basics/realloc/pinocchio/program/src/processor.rs index 9b33aaac2..544c0d117 100644 --- a/basics/realloc/pinocchio/program/src/processor.rs +++ b/basics/realloc/pinocchio/program/src/processor.rs @@ -1,11 +1,9 @@ use crate::instructions::*; -use pinocchio::{ - account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey, ProgramResult, -}; +use pinocchio::{error::ProgramError, AccountView, Address, ProgramResult}; pub fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { match instruction_data.split_first() { diff --git a/basics/rent/pinocchio/program/src/lib.rs b/basics/rent/pinocchio/program/src/lib.rs index b3883db55..e57f6923a 100644 --- a/basics/rent/pinocchio/program/src/lib.rs +++ b/basics/rent/pinocchio/program/src/lib.rs @@ -1,12 +1,11 @@ #![no_std] use pinocchio::{ - account_info::AccountInfo, - entrypoint, nostd_panic_handler, - program_error::ProgramError, - pubkey::Pubkey, + entrypoint, + error::ProgramError, + nostd_panic_handler, sysvars::{rent::Rent, Sysvar}, - ProgramResult, + AccountView, Address, ProgramResult, }; use pinocchio_log::log; use pinocchio_system::instructions::CreateAccount; @@ -15,8 +14,8 @@ entrypoint!(process_instruction); nostd_panic_handler!(); fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], + program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { let [payer, new_account, _system_program] = accounts else { @@ -25,14 +24,14 @@ fn process_instruction( log!("Program invoked. Creating a system account..."); log!(" New public key will be: "); - pinocchio::pubkey::log(new_account.key()); + log!("{}", new_account.address().as_array()); let rent = Rent::get()?; // Determine the necessary minimum rent by calculating the account's size // let account_span = instruction_data.len(); - let lamports_required = rent.minimum_balance(account_span); + let lamports_required = rent.try_minimum_balance(account_span)?; log!(50, "Account span: {}", account_span); log!(50, "Lamports required: {}", lamports_required); diff --git a/basics/transfer-sol/pinocchio/program/src/lib.rs b/basics/transfer-sol/pinocchio/program/src/lib.rs index 5b27c4f42..c3ed5d7f1 100644 --- a/basics/transfer-sol/pinocchio/program/src/lib.rs +++ b/basics/transfer-sol/pinocchio/program/src/lib.rs @@ -1,8 +1,7 @@ #![no_std] use pinocchio::{ - account_info::AccountInfo, entrypoint, nostd_panic_handler, program_error::ProgramError, - pubkey::Pubkey, ProgramResult, + entrypoint, error::ProgramError, nostd_panic_handler, AccountView, Address, ProgramResult, }; use pinocchio_system::instructions::Transfer; @@ -10,8 +9,8 @@ entrypoint!(process_instruction); nostd_panic_handler!(); fn process_instruction( - _program_id: &Pubkey, - accounts: &[AccountInfo], + _program_id: &Address, + accounts: &[AccountView], instruction_data: &[u8], ) -> ProgramResult { match instruction_data.split_first() { @@ -24,7 +23,7 @@ fn process_instruction( pub const CPI_TRANSFER_DISCRIMINATOR: u8 = 0; pub const PROGRAM_TRANSFER_DISCRIMINATOR: u8 = 1; -fn transfer_sol_with_cpi(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult { +fn transfer_sol_with_cpi(accounts: &[AccountView], instruction_data: &[u8]) -> ProgramResult { let [payer, recipient, _system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; @@ -44,7 +43,7 @@ fn transfer_sol_with_cpi(accounts: &[AccountInfo], instruction_data: &[u8]) -> P Ok(()) } -fn transfer_sol_with_program(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult { +fn transfer_sol_with_program(accounts: &[AccountView], instruction_data: &[u8]) -> ProgramResult { let [payer, recipient] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; @@ -54,8 +53,8 @@ fn transfer_sol_with_program(accounts: &[AccountInfo], instruction_data: &[u8]) .map_err(|_| ProgramError::InvalidInstructionData)?; let amount = u64::from_le_bytes(amount_bytes); - *payer.try_borrow_mut_lamports()? -= amount; - *recipient.try_borrow_mut_lamports()? += amount; + payer.set_lamports(payer.lamports() - amount); + recipient.set_lamports(recipient.lamports() + amount); Ok(()) }