diff --git a/Cargo.toml b/Cargo.toml index aae171e04..1f8decb6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,5 +98,7 @@ solana-instruction = "3.0.0" solana-keypair = "3.0.1" solana-pubkey = "3.0.0" solana-transaction = "3.0.1" +solana-transaction-error = "3.2.0" solana-native-token = "3.0.0" +solana-rent = "4.1.0" solana-address = "2.6.0" diff --git a/basics/account-data/native/program/Cargo.toml b/basics/account-data/native/program/Cargo.toml index bb79994c1..873cb6c0f 100644 --- a/basics/account-data/native/program/Cargo.toml +++ b/basics/account-data/native/program/Cargo.toml @@ -20,10 +20,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-keypair = "3.0.1" +litesvm.workspace = true +solana-keypair.workspace = true solana-message = "4.0.0" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" +solana-native-token.workspace = true +solana-pubkey.workspace = true solana-signer = "3.0.0" -solana-transaction = "3.0.1" +solana-transaction.workspace = true diff --git a/basics/account-data/pinocchio/program/Cargo.toml b/basics/account-data/pinocchio/program/Cargo.toml index 756dbbc01..e4842acc7 100644 --- a/basics/account-data/pinocchio/program/Cargo.toml +++ b/basics/account-data/pinocchio/program/Cargo.toml @@ -9,13 +9,13 @@ pinocchio-log.workspace = true pinocchio-system.workspace = true [dev-dependencies] -litesvm = "0.11.0" -solana-keypair = "3.0.1" +litesvm.workspace = true +solana-keypair.workspace = true solana-message = "4.0.0" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" +solana-native-token.workspace = true +solana-pubkey.workspace = true solana-signer = "3.0.0" -solana-transaction = "3.0.1" +solana-transaction.workspace = true solana-system-interface.workspace = true [lib] diff --git a/basics/checking-accounts/asm/Cargo.toml b/basics/checking-accounts/asm/Cargo.toml index 86c433065..fd767509e 100644 --- a/basics/checking-accounts/asm/Cargo.toml +++ b/basics/checking-accounts/asm/Cargo.toml @@ -6,14 +6,14 @@ edition = "2021" [dependencies] [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true solana-system-interface.workspace = true -solana-transaction-error = "3.2.0" +solana-transaction-error.workspace = true [features] test-sbf = [] diff --git a/basics/checking-accounts/native/program/Cargo.toml b/basics/checking-accounts/native/program/Cargo.toml index 665516c54..393e0286a 100644 --- a/basics/checking-accounts/native/program/Cargo.toml +++ b/basics/checking-accounts/native/program/Cargo.toml @@ -19,9 +19,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" +litesvm.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true solana-sdk = "4.0.1" -solana-transaction = "3.0.1" +solana-transaction.workspace = true diff --git a/basics/checking-accounts/pinocchio/program/Cargo.toml b/basics/checking-accounts/pinocchio/program/Cargo.toml index ea2451116..9d5785a5c 100644 --- a/basics/checking-accounts/pinocchio/program/Cargo.toml +++ b/basics/checking-accounts/pinocchio/program/Cargo.toml @@ -9,12 +9,12 @@ pinocchio-system.workspace = true pinocchio-log.workspace = true [dev-dependencies] -litesvm = "0.11.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" +litesvm.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true solana-sdk = "4.0.1" -solana-transaction = "3.0.1" +solana-transaction.workspace = true solana-system-interface.workspace = true [lib] diff --git a/basics/close-account/native/program/Cargo.toml b/basics/close-account/native/program/Cargo.toml index ca3d566e6..03fc5de78 100644 --- a/basics/close-account/native/program/Cargo.toml +++ b/basics/close-account/native/program/Cargo.toml @@ -20,9 +20,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/close-account/pinocchio/program/Cargo.toml b/basics/close-account/pinocchio/program/Cargo.toml index af5308d90..2f06d5c96 100644 --- a/basics/close-account/pinocchio/program/Cargo.toml +++ b/basics/close-account/pinocchio/program/Cargo.toml @@ -10,13 +10,13 @@ pinocchio-pubkey.workspace = true pinocchio-system.workspace = true [dev-dependencies] -litesvm = "0.11.0" -solana-keypair = "3.0.1" +litesvm.workspace = true +solana-keypair.workspace = true solana-message = "4.0.0" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" +solana-native-token.workspace = true +solana-pubkey.workspace = true solana-signer = "3.0.0" -solana-transaction = "3.0.1" +solana-transaction.workspace = true solana-system-interface.workspace = true solana-instruction.workspace = true diff --git a/basics/counter/native/program/Cargo.toml b/basics/counter/native/program/Cargo.toml index c928d7806..3ae950a31 100644 --- a/basics/counter/native/program/Cargo.toml +++ b/basics/counter/native/program/Cargo.toml @@ -22,11 +22,11 @@ solana-program.workspace = true unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-rent = "4.1.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-rent.workspace = true solana-system-interface.workspace = true diff --git a/basics/counter/pinocchio/program/Cargo.toml b/basics/counter/pinocchio/program/Cargo.toml index 2df97c688..2b01c6422 100644 --- a/basics/counter/pinocchio/program/Cargo.toml +++ b/basics/counter/pinocchio/program/Cargo.toml @@ -22,11 +22,11 @@ pinocchio-pubkey.workspace = true unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-rent = "4.1.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-rent.workspace = true solana-system-interface.workspace = true diff --git a/basics/create-account/asm/Cargo.toml b/basics/create-account/asm/Cargo.toml index 07b92124c..3f39d80c6 100644 --- a/basics/create-account/asm/Cargo.toml +++ b/basics/create-account/asm/Cargo.toml @@ -6,12 +6,12 @@ edition = "2021" [dependencies] [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true solana-system-interface.workspace = true [features] diff --git a/basics/create-account/native/program/Cargo.toml b/basics/create-account/native/program/Cargo.toml index bde26597a..066129e15 100644 --- a/basics/create-account/native/program/Cargo.toml +++ b/basics/create-account/native/program/Cargo.toml @@ -18,9 +18,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/create-account/pinocchio/program/Cargo.toml b/basics/create-account/pinocchio/program/Cargo.toml index 609d465c2..c0960bd40 100644 --- a/basics/create-account/pinocchio/program/Cargo.toml +++ b/basics/create-account/pinocchio/program/Cargo.toml @@ -20,10 +20,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true solana-system-interface.workspace = true diff --git a/basics/cross-program-invocation/native/programs/hand/Cargo.toml b/basics/cross-program-invocation/native/programs/hand/Cargo.toml index c74aab0f4..e3df0a5b1 100644 --- a/basics/cross-program-invocation/native/programs/hand/Cargo.toml +++ b/basics/cross-program-invocation/native/programs/hand/Cargo.toml @@ -10,9 +10,9 @@ custom-heap = [] custom-panic = [] [dependencies] -borsh = "1.5.7" -borsh-derive = "1.5.7" -solana-program = "3.0" +borsh = "1.6.1" +borsh-derive = "1.6.1" +solana-program = "4.0" cross-program-invocatio-native-lever = { path = "../lever", features = ["cpi"] } [lib] diff --git a/basics/cross-program-invocation/native/programs/lever/Cargo.toml b/basics/cross-program-invocation/native/programs/lever/Cargo.toml index 84b93055a..388363be5 100644 --- a/basics/cross-program-invocation/native/programs/lever/Cargo.toml +++ b/basics/cross-program-invocation/native/programs/lever/Cargo.toml @@ -10,9 +10,9 @@ custom-heap = [] custom-panic = [] [dependencies] -borsh = "1.5.7" -borsh-derive = "1.5.7" -solana-program = "3.0" +borsh = "1.6.1" +borsh-derive = "1.6.1" +solana-program = "4.0" solana-system-interface = {version = "2.0.0", features = ["bincode"]} [lib] diff --git a/basics/favorites/native/program/Cargo.toml b/basics/favorites/native/program/Cargo.toml index 416af7197..f8182fecb 100644 --- a/basics/favorites/native/program/Cargo.toml +++ b/basics/favorites/native/program/Cargo.toml @@ -20,9 +20,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/favorites/native/tests/test.ts b/basics/favorites/native/tests/test.ts index 13e5e5b34..c6cafe304 100644 --- a/basics/favorites/native/tests/test.ts +++ b/basics/favorites/native/tests/test.ts @@ -6,7 +6,6 @@ import { Transaction, TransactionInstruction, } from "@solana/web3.js"; -import { BN } from "bn.js"; import * as borsh from "borsh"; import { assert, expect } from "chai"; import { describe, test } from "mocha"; @@ -103,15 +102,15 @@ describe("Favorites Solana Native", () => { console.log("Deserialized data:", favoritesData); - expect(new BN(favoritesData.number as Buffer, "le").toNumber()).to.equal(favData.number); + expect(Number(favoritesData.number)).to.equal(favData.number); expect(favoritesData.color).to.equal(favData.color); expect(favoritesData.hobbies).to.deep.equal(favData.hobbies); }); test("Check if the test fails if the pda seeds aren't same", async () => { - // We put the wrong seeds knowingly to see if the test fails because of checks - const favoritesPda = PublicKey.findProgramAddressSync( - [Buffer.from("favorite"), payer.publicKey.toBuffer()], + // Derive a PDA using WRONG seeds so the program's on-chain seed check rejects it + const wrongPda = PublicKey.findProgramAddressSync( + [Buffer.from("wrong_seed"), payer.publicKey.toBuffer()], programId, )[0]; const favData = { @@ -124,7 +123,7 @@ describe("Favorites Solana Native", () => { const ix = new TransactionInstruction({ keys: [ { pubkey: payer.publicKey, isSigner: true, isWritable: true }, - { pubkey: favoritesPda, isSigner: false, isWritable: true }, + { pubkey: wrongPda, isSigner: false, isWritable: true }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, ], programId, @@ -136,12 +135,13 @@ describe("Favorites Solana Native", () => { tx.recentBlockhash = blockhash; tx.sign(payer); tx.recentBlockhash = blockhash; + let threw = false; try { await client.processTransaction(tx); - console.error("Expected the test to fail"); } catch (_err) { - assert(true); + threw = true; } + assert(threw, "Expected transaction to fail with wrong PDA seeds"); }); test("Get the favorite pda and cross-check the data", async () => { diff --git a/basics/favorites/pinocchio/program/Cargo.toml b/basics/favorites/pinocchio/program/Cargo.toml index 2842e5f8c..4fac4a63e 100644 --- a/basics/favorites/pinocchio/program/Cargo.toml +++ b/basics/favorites/pinocchio/program/Cargo.toml @@ -21,10 +21,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true solana-system-interface.workspace = true diff --git a/basics/hello-solana/native/program/Cargo.toml b/basics/hello-solana/native/program/Cargo.toml index a51e82ffa..f41076334 100644 --- a/basics/hello-solana/native/program/Cargo.toml +++ b/basics/hello-solana/native/program/Cargo.toml @@ -17,9 +17,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/processing-instructions/native/program/Cargo.toml b/basics/processing-instructions/native/program/Cargo.toml index d3af395c4..e348596c4 100644 --- a/basics/processing-instructions/native/program/Cargo.toml +++ b/basics/processing-instructions/native/program/Cargo.toml @@ -19,9 +19,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-native-token = "3.0.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-native-token.workspace = true diff --git a/basics/processing-instructions/pinocchio/program/Cargo.toml b/basics/processing-instructions/pinocchio/program/Cargo.toml index 5e202b590..6f1536a0f 100644 --- a/basics/processing-instructions/pinocchio/program/Cargo.toml +++ b/basics/processing-instructions/pinocchio/program/Cargo.toml @@ -18,9 +18,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-native-token = "3.0.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-native-token.workspace = true diff --git a/basics/program-derived-addresses/native/program/Cargo.toml b/basics/program-derived-addresses/native/program/Cargo.toml index 1251e8d8a..544875820 100644 --- a/basics/program-derived-addresses/native/program/Cargo.toml +++ b/basics/program-derived-addresses/native/program/Cargo.toml @@ -20,10 +20,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-native-token = "3.0.0" -solana-rent = "4.1.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-native-token.workspace = true +solana-rent.workspace = true diff --git a/basics/program-derived-addresses/pinocchio/program/Cargo.toml b/basics/program-derived-addresses/pinocchio/program/Cargo.toml index e803884e6..0b4e75df2 100644 --- a/basics/program-derived-addresses/pinocchio/program/Cargo.toml +++ b/basics/program-derived-addresses/pinocchio/program/Cargo.toml @@ -19,11 +19,11 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-native-token = "3.0.0" -solana-rent = "4.1.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-native-token.workspace = true +solana-rent.workspace = true solana-system-interface.workspace = true diff --git a/basics/realloc/native/package.json b/basics/realloc/native/package.json index c01413a56..1bbd3c6e5 100644 --- a/basics/realloc/native/package.json +++ b/basics/realloc/native/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "@solana/web3.js": "^1.98.4", + "borsh": "^2.0.0", "fs": "^0.0.1-security" }, "devDependencies": { diff --git a/basics/realloc/native/pnpm-lock.yaml b/basics/realloc/native/pnpm-lock.yaml index a79f68d42..512871087 100644 --- a/basics/realloc/native/pnpm-lock.yaml +++ b/basics/realloc/native/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@solana/web3.js': specifier: ^1.98.4 version: 1.98.4(bufferutil@4.0.9)(typescript@4.9.5)(utf-8-validate@5.0.10) + borsh: + specifier: ^2.0.0 + version: 2.0.0 fs: specifier: ^0.0.1-security version: 0.0.1-security @@ -165,6 +168,9 @@ packages: borsh@0.7.0: resolution: {integrity: sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==} + borsh@2.0.0: + resolution: {integrity: sha512-kc9+BgR3zz9+cjbwM8ODoUB4fs3X3I5A/HtX7LZKxCLaMrEeDFoBpnhZY//DTS1VZBSs6S5v46RZRbZjRFspEg==} + brace-expansion@1.1.11: resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} @@ -531,14 +537,12 @@ packages: engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] solana-bankrun-linux-x64-musl@0.3.1: resolution: {integrity: sha512-6r8i0NuXg3CGURql8ISMIUqhE7Hx/O7MlIworK4oN08jYrP0CXdLeB/hywNn7Z8d1NXrox/NpYUgvRm2yIzAsQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] solana-bankrun@0.3.1: resolution: {integrity: sha512-inRwON7fBU5lPC36HdEqPeDg15FXJYcf77+o0iz9amvkUMJepcwnRwEfTNyMVpVYdgjTOBW5vg+596/3fi1kGA==} @@ -834,6 +838,8 @@ snapshots: bs58: 4.0.1 text-encoding-utf-8: 1.0.2 + borsh@2.0.0: {} + brace-expansion@1.1.11: dependencies: balanced-match: 1.0.2 diff --git a/basics/realloc/native/program/Cargo.toml b/basics/realloc/native/program/Cargo.toml index 8a763a8e1..857fc3c17 100644 --- a/basics/realloc/native/program/Cargo.toml +++ b/basics/realloc/native/program/Cargo.toml @@ -20,9 +20,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/realloc/native/ts/instructions/create.ts b/basics/realloc/native/ts/instructions/create.ts index 3fbc6a84e..63439a491 100644 --- a/basics/realloc/native/ts/instructions/create.ts +++ b/basics/realloc/native/ts/instructions/create.ts @@ -3,51 +3,15 @@ import { type PublicKey, SystemProgram, TransactionInstruction } from "@solana/w import * as borsh from "borsh"; import { ReallocInstruction } from "./instruction"; -export class Create { - instruction: ReallocInstruction; - name: string; - house_number: number; - street: string; - city: string; - - constructor(props: { - instruction: ReallocInstruction; - name: string; - house_number: number; - street: string; - city: string; - }) { - this.instruction = props.instruction; - this.name = props.name; - this.house_number = props.house_number; - this.street = props.street; - this.city = props.city; - } - - toBuffer() { - return Buffer.from(borsh.serialize(CreateSchema, this)); - } - - static fromBuffer(buffer: Buffer) { - return borsh.deserialize(CreateSchema, Create, buffer); - } -} - -export const CreateSchema = new Map([ - [ - Create, - { - kind: "struct", - fields: [ - ["instruction", "u8"], - ["name", "string"], - ["house_number", "u8"], - ["street", "string"], - ["city", "string"], - ], - }, - ], -]); +const CreateSchema = { + struct: { + instruction: "u8", + name: "string", + house_number: "u8", + street: "string", + city: "string", + }, +} as const; export function createCreateInstruction( target: PublicKey, @@ -58,23 +22,23 @@ export function createCreateInstruction( street: string, city: string, ): TransactionInstruction { - const instructionObject = new Create({ - instruction: ReallocInstruction.Create, - name, - house_number, - street, - city, - }); - - const ix = new TransactionInstruction({ + const data = Buffer.from( + borsh.serialize(CreateSchema, { + instruction: ReallocInstruction.Create, + name, + house_number, + street, + city, + }), + ); + + return new TransactionInstruction({ keys: [ - { pubkey: target, isSigner: false, isWritable: true }, + { pubkey: target, isSigner: true, isWritable: true }, { pubkey: payer, isSigner: true, isWritable: true }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, ], - programId: programId, - data: instructionObject.toBuffer(), + programId, + data, }); - - return ix; } diff --git a/basics/realloc/native/ts/instructions/reallocate.ts b/basics/realloc/native/ts/instructions/reallocate.ts index 197e711d6..637d463e2 100644 --- a/basics/realloc/native/ts/instructions/reallocate.ts +++ b/basics/realloc/native/ts/instructions/reallocate.ts @@ -3,43 +3,13 @@ import { type PublicKey, SystemProgram, TransactionInstruction } from "@solana/w import * as borsh from "borsh"; import { ReallocInstruction } from "./instruction"; -export class ReallocateWithoutZeroInit { - instruction: ReallocInstruction; - state: string; - zip: number; - - constructor(props: { - instruction: ReallocInstruction; - state: string; - zip: number; - }) { - this.instruction = props.instruction; - this.state = props.state; - this.zip = props.zip; - } - - toBuffer() { - return Buffer.from(borsh.serialize(ReallocateWithoutZeroInitSchema, this)); - } - - static fromBuffer(buffer: Buffer) { - return borsh.deserialize(ReallocateWithoutZeroInitSchema, ReallocateWithoutZeroInit, buffer); - } -} - -export const ReallocateWithoutZeroInitSchema = new Map([ - [ - ReallocateWithoutZeroInit, - { - kind: "struct", - fields: [ - ["instruction", "u8"], - ["state", "string"], - ["zip", "u32"], - ], - }, - ], -]); +const ReallocateWithoutZeroInitSchema = { + struct: { + instruction: "u8", + state: "string", + zip: "u32", + }, +} as const; export function createReallocateWithoutZeroInitInstruction( target: PublicKey, @@ -48,70 +18,34 @@ export function createReallocateWithoutZeroInitInstruction( state: string, zip: number, ): TransactionInstruction { - const instructionObject = new ReallocateWithoutZeroInit({ - instruction: ReallocInstruction.ReallocateWithoutZeroInit, - state, - zip, - }); - - const ix = new TransactionInstruction({ + const data = Buffer.from( + borsh.serialize(ReallocateWithoutZeroInitSchema, { + instruction: ReallocInstruction.ReallocateWithoutZeroInit, + state, + zip, + }), + ); + + return new TransactionInstruction({ keys: [ { pubkey: target, isSigner: false, isWritable: true }, { pubkey: payer, isSigner: true, isWritable: true }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, ], - programId: programId, - data: instructionObject.toBuffer(), + programId, + data, }); - - return ix; } -export class ReallocateZeroInit { - instruction: ReallocInstruction; - name: string; - position: string; - company: string; - years_employed: number; - - constructor(props: { - instruction: ReallocInstruction; - name: string; - position: string; - company: string; - years_employed: number; - }) { - this.instruction = props.instruction; - this.name = props.name; - this.position = props.position; - this.company = props.company; - this.years_employed = props.years_employed; - } - - toBuffer() { - return Buffer.from(borsh.serialize(ReallocateZeroInitSchema, this)); - } - - static fromBuffer(buffer: Buffer) { - return borsh.deserialize(ReallocateZeroInitSchema, ReallocateZeroInit, buffer); - } -} - -export const ReallocateZeroInitSchema = new Map([ - [ - ReallocateZeroInit, - { - kind: "struct", - fields: [ - ["instruction", "u8"], - ["name", "string"], - ["position", "string"], - ["company", "string"], - ["years_employed", "u8"], - ], - }, - ], -]); +const ReallocateZeroInitSchema = { + struct: { + instruction: "u8", + name: "string", + position: "string", + company: "string", + years_employed: "u8", + }, +} as const; export function createReallocateZeroInitInstruction( target: PublicKey, @@ -122,19 +56,19 @@ export function createReallocateZeroInitInstruction( company: string, years_employed: number, ): TransactionInstruction { - const instructionObject = new ReallocateZeroInit({ - instruction: ReallocInstruction.ReallocateZeroInit, - name, - position, - company, - years_employed, - }); - - const ix = new TransactionInstruction({ + const data = Buffer.from( + borsh.serialize(ReallocateZeroInitSchema, { + instruction: ReallocInstruction.ReallocateZeroInit, + name, + position, + company, + years_employed, + }), + ); + + return new TransactionInstruction({ keys: [{ pubkey: target, isSigner: false, isWritable: true }], - programId: programId, - data: instructionObject.toBuffer(), + programId, + data, }); - - return ix; } diff --git a/basics/realloc/native/ts/state/address-info.ts b/basics/realloc/native/ts/state/address-info.ts index 6acf96c8a..5f521a028 100644 --- a/basics/realloc/native/ts/state/address-info.ts +++ b/basics/realloc/native/ts/state/address-info.ts @@ -1,6 +1,15 @@ import { Buffer } from "node:buffer"; import * as borsh from "borsh"; +export const AddressInfoSchema = { + struct: { + name: "string", + house_number: "u8", + street: "string", + city: "string", + }, +} as const; + export class AddressInfo { name: string; house_number: number; @@ -19,30 +28,11 @@ export class AddressInfo { this.city = props.city; } - toBase58() { - return borsh.serialize(AddressInfoSchema, this).toString(); - } - toBuffer() { return Buffer.from(borsh.serialize(AddressInfoSchema, this)); } - static fromBuffer(buffer: Buffer) { - return borsh.deserialize(AddressInfoSchema, AddressInfo, buffer); + static fromBuffer(buffer: Buffer): AddressInfo { + return borsh.deserialize(AddressInfoSchema, buffer) as AddressInfo; } } - -export const AddressInfoSchema = new Map([ - [ - AddressInfo, - { - kind: "struct", - fields: [ - ["name", "string"], - ["house_number", "u8"], - ["street", "string"], - ["city", "string"], - ], - }, - ], -]); diff --git a/basics/realloc/native/ts/state/enhanced-address-info.ts b/basics/realloc/native/ts/state/enhanced-address-info.ts index edbda7781..e24131b3f 100644 --- a/basics/realloc/native/ts/state/enhanced-address-info.ts +++ b/basics/realloc/native/ts/state/enhanced-address-info.ts @@ -1,6 +1,17 @@ import { Buffer } from "node:buffer"; import * as borsh from "borsh"; +export const EnhancedAddressInfoSchema = { + struct: { + name: "string", + house_number: "u8", + street: "string", + city: "string", + state: "string", + zip: "u32", + }, +} as const; + export class EnhancedAddressInfo { name: string; house_number: number; @@ -25,32 +36,11 @@ export class EnhancedAddressInfo { this.zip = props.zip; } - toBase58() { - return borsh.serialize(EnhancedAddressInfoSchema, this).toString(); - } - toBuffer() { return Buffer.from(borsh.serialize(EnhancedAddressInfoSchema, this)); } - static fromBuffer(buffer: Buffer) { - return borsh.deserialize(EnhancedAddressInfoSchema, EnhancedAddressInfo, buffer); + static fromBuffer(buffer: Buffer): EnhancedAddressInfo { + return borsh.deserialize(EnhancedAddressInfoSchema, buffer) as EnhancedAddressInfo; } } - -export const EnhancedAddressInfoSchema = new Map([ - [ - EnhancedAddressInfo, - { - kind: "struct", - fields: [ - ["name", "string"], - ["house_number", "u8"], - ["street", "string"], - ["city", "string"], - ["state", "string"], - ["zip", "u32"], - ], - }, - ], -]); diff --git a/basics/realloc/native/ts/state/work-info.ts b/basics/realloc/native/ts/state/work-info.ts index 26a89ebec..73f11b9c7 100644 --- a/basics/realloc/native/ts/state/work-info.ts +++ b/basics/realloc/native/ts/state/work-info.ts @@ -1,6 +1,15 @@ import { Buffer } from "node:buffer"; import * as borsh from "borsh"; +export const WorkInfoSchema = { + struct: { + name: "string", + position: "string", + company: "string", + years_employed: "u8", + }, +} as const; + export class WorkInfo { name: string; position: string; @@ -19,30 +28,11 @@ export class WorkInfo { this.years_employed = props.years_employed; } - toBase58() { - return borsh.serialize(WorkInfoSchema, this).toString(); - } - toBuffer() { return Buffer.from(borsh.serialize(WorkInfoSchema, this)); } - static fromBuffer(buffer: Buffer) { - return borsh.deserialize(WorkInfoSchema, WorkInfo, buffer); + static fromBuffer(buffer: Buffer): WorkInfo { + return borsh.deserialize(WorkInfoSchema, buffer) as WorkInfo; } } - -export const WorkInfoSchema = new Map([ - [ - WorkInfo, - { - kind: "struct", - fields: [ - ["name", "string"], - ["position", "string"], - ["company", "string"], - ["years_employed", "u8"], - ], - }, - ], -]); diff --git a/basics/realloc/native/ts/util/util.ts b/basics/realloc/native/ts/util/util.ts index 7e72414f8..69da9c32b 100644 --- a/basics/realloc/native/ts/util/util.ts +++ b/basics/realloc/native/ts/util/util.ts @@ -1,5 +1,6 @@ +import { readFileSync } from "node:fs"; import { Keypair } from "@solana/web3.js"; export function createKeypairFromFile(path: string): Keypair { - return Keypair.fromSecretKey(Buffer.from(JSON.parse(require("node:fs").readFileSync(path, "utf-8")))); + return Keypair.fromSecretKey(Buffer.from(JSON.parse(readFileSync(path, "utf-8")))); } diff --git a/basics/realloc/pinocchio/program/Cargo.toml b/basics/realloc/pinocchio/program/Cargo.toml index 35d0043d1..6450882dd 100644 --- a/basics/realloc/pinocchio/program/Cargo.toml +++ b/basics/realloc/pinocchio/program/Cargo.toml @@ -20,10 +20,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true solana-system-interface.workspace = true diff --git a/basics/rent/native/program/Cargo.toml b/basics/rent/native/program/Cargo.toml index dcbff7dc9..ce79dc241 100644 --- a/basics/rent/native/program/Cargo.toml +++ b/basics/rent/native/program/Cargo.toml @@ -20,10 +20,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-rent = "4.1.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-rent.workspace = true +solana-transaction.workspace = true diff --git a/basics/rent/pinocchio/program/Cargo.toml b/basics/rent/pinocchio/program/Cargo.toml index 486190ede..39ccc025e 100644 --- a/basics/rent/pinocchio/program/Cargo.toml +++ b/basics/rent/pinocchio/program/Cargo.toml @@ -19,11 +19,11 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-rent = "4.1.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-rent.workspace = true +solana-transaction.workspace = true solana-system-interface .workspace = true diff --git a/basics/repository-layout/native/program/Cargo.toml b/basics/repository-layout/native/program/Cargo.toml index 44f37d83c..a75a1e2e6 100644 --- a/basics/repository-layout/native/program/Cargo.toml +++ b/basics/repository-layout/native/program/Cargo.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2021" [dependencies] -borsh = "1.6.1" -borsh-derive = "1.6.1" -solana-program = "4.0" +borsh.workspace = true +borsh-derive.workspace = true +solana-program.workspace = true [lib] crate-type = ["cdylib", "lib"] @@ -19,9 +19,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/repository-layout/pinocchio/program/Cargo.toml b/basics/repository-layout/pinocchio/program/Cargo.toml index 2f6424aa4..1e1221259 100644 --- a/basics/repository-layout/pinocchio/program/Cargo.toml +++ b/basics/repository-layout/pinocchio/program/Cargo.toml @@ -18,9 +18,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" -solana-native-token = "3.0.0" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true +solana-native-token.workspace = true diff --git a/basics/transfer-sol/native/program/Cargo.toml b/basics/transfer-sol/native/program/Cargo.toml index 9202a2596..134db6bce 100644 --- a/basics/transfer-sol/native/program/Cargo.toml +++ b/basics/transfer-sol/native/program/Cargo.toml @@ -20,9 +20,9 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true diff --git a/basics/transfer-sol/pinocchio/program/Cargo.toml b/basics/transfer-sol/pinocchio/program/Cargo.toml index 570467285..d0119b658 100644 --- a/basics/transfer-sol/pinocchio/program/Cargo.toml +++ b/basics/transfer-sol/pinocchio/program/Cargo.toml @@ -18,10 +18,10 @@ custom-panic = [] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] } [dev-dependencies] -litesvm = "0.11.0" -solana-instruction = "3.0.0" -solana-keypair = "3.0.1" -solana-native-token = "3.0.0" -solana-pubkey = "3.0.0" -solana-transaction = "3.0.1" +litesvm.workspace = true +solana-instruction.workspace = true +solana-keypair.workspace = true +solana-native-token.workspace = true +solana-pubkey.workspace = true +solana-transaction.workspace = true solana-system-interface.workspace = true