From 327decbc1677165c74bfb32c2bb7aa8a7162b439 Mon Sep 17 00:00:00 2001 From: beeman Date: Mon, 22 Apr 2024 17:57:38 +0200 Subject: [PATCH] feat: update Anchor to v0.30.0 (#59) --- .../anchor-application-generator.spec.ts.snap | 283 ++-- .../anchor-application-generator.ts | 9 + .../anchor-template-generator.spec.ts.snap | 1134 ++++++++-------- .../files/basic/Cargo.lock.template | 180 ++- .../programs/__fileName__/Cargo.toml.template | 3 +- .../src/__fileName__-exports.ts.template | 10 +- .../idl/__fileNameUnderscore__.json.template | 21 +- .../types/__fileNameUnderscore__.ts.template | 42 +- .../files/counter/Cargo.lock.template | 180 ++- .../programs/__fileName__/Cargo.toml.template | 3 +- .../src/__fileName__-exports.ts.template | 12 +- .../idl/__fileNameUnderscore__.json.template | 118 +- .../types/__fileNameUnderscore__.ts.template | 231 ++-- packages/preset-common/package.json | 2 +- .../common-template-generator.spec.ts.snap | 36 +- .../files/readme/README.md.template | 6 +- .../src/utils/package-versions.ts | 2 +- .../next-application-generator.spec.ts.snap | 480 +++---- .../react-application-generator.spec.ts.snap | 480 +++---- .../react-feature-generator.spec.ts.snap | 1186 +++++++++-------- .../__fileName__-data-access.tsx.template | 4 +- .../__fileName__-data-access.tsx.template | 4 +- 22 files changed, 2171 insertions(+), 2255 deletions(-) diff --git a/packages/preset-anchor/src/generators/anchor-application/__snapshots__/anchor-application-generator.spec.ts.snap b/packages/preset-anchor/src/generators/anchor-application/__snapshots__/anchor-application-generator.spec.ts.snap index bc843f64..20d9f420 100644 --- a/packages/preset-anchor/src/generators/anchor-application/__snapshots__/anchor-application-generator.spec.ts.snap +++ b/packages/preset-anchor/src/generators/anchor-application/__snapshots__/anchor-application-generator.spec.ts.snap @@ -194,7 +194,7 @@ exports[`anchor-application generator should generate app with "basic" template ""name": "@proj/anchor-app",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -226,8 +226,9 @@ exports[`anchor-application generator should generate app with "basic" template "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "anchor-app/programs/my-program/Cargo.toml", @@ -344,15 +345,18 @@ exports[`anchor-application generator should generate app with "basic" template "my-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { PublicKey } from '@solana/web3.js';", "import type { MyProgram } from '../target/types/my_program';", "import { IDL as MyProgramIDL } from '../target/types/my_program';", "// Re-export the generated IDL and type", "export { MyProgram, MyProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const programId = new PublicKey(", - "'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA'", - ");", + "// The programId is imported from the program IDL.", + "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(MyProgramIDL.address);", + "// This is a helper function to get the MyProgram Anchor program.", + "export function getMyProgramProgram(provider: AnchorProvider) {", + "return new Program(MyProgramIDL as MyProgram, provider);", + "}", ], "isBinary": false, "path": "anchor-app/src/my-program-exports.ts", @@ -384,11 +388,17 @@ exports[`anchor-application generator should generate app with "basic" template "my_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "greet",", + ""discriminator": [203, 194, 3, 150, 228, 58, 181, 62],", ""accounts": [],", ""args": []", "}", @@ -405,28 +415,29 @@ exports[`anchor-application generator should generate app with "basic" template "children": { "my_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_program.json\`.", + "*/", "export type MyProgram = {", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myProgram';", "version: '0.1.0';", - "name: 'my_program';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", "instructions: [", "{", "name: 'greet';", + "discriminator: [203, 194, 3, 150, 228, 58, 181, 62];", "accounts: [];", "args: [];", "}", "];", "};", - "export const IDL: MyProgram = {", - "version: '0.1.0',", - "name: 'my_program',", - "instructions: [", - "{", - "name: 'greet',", - "accounts: [],", - "args: [],", - "},", - "],", - "};", ], "isBinary": false, "path": "anchor-app/target/types/my_program.ts", @@ -490,7 +501,9 @@ exports[`anchor-application generator should generate app with "basic" template ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": ["node"],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", ""include": ["src/**/*.ts"],", ""exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]", @@ -727,7 +740,7 @@ exports[`anchor-application generator should generate app with "counter" templat ""name": "@proj/anchor-app",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -759,8 +772,9 @@ exports[`anchor-application generator should generate app with "counter" templat "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "anchor-app/programs/my-program/Cargo.toml", @@ -922,15 +936,18 @@ exports[`anchor-application generator should generate app with "counter" templat "my-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import MyProgramIDL from '../target/idl/my_program.json';", "import type { MyProgram } from '../target/types/my_program';", - "import { IDL as MyProgramIDL } from '../target/types/my_program';", "// Re-export the generated IDL and type", "export { MyProgram, MyProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(", - "'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA'", - ");", + "// The programId is imported from the program IDL.", + "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(MyProgramIDL.address);", + "// This is a helper function to get the MyProgram Anchor program.", + "export function getMyProgramProgram(provider: AnchorProvider) {", + "return new Program(MyProgramIDL as MyProgram, provider);", + "}", "// This is a helper function to get the program ID for the MyProgram program depending on the cluster.", "export function getMyProgramProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -972,75 +989,80 @@ exports[`anchor-application generator should generate app with "counter" templat "my_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [98, 165, 201, 177, 108, 65, 206, 96],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [106, 227, 168, 59, 248, 27, 150, 101],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [11, 18, 104, 9, 104, 174, 59, 33],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [175, 175, 109, 31, 13, 152, 155, 237],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": true", + ""name": "my_program",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [198, 51, 53, 241, 116, 29, 126, 194],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": [", @@ -1054,6 +1076,12 @@ exports[`anchor-application generator should generate app with "counter" templat ""accounts": [", "{", ""name": "MyProgram",", + ""discriminator": [135, 64, 223, 168, 233, 143, 162, 215]", + "}", + "],", + ""types": [", + "{", + ""name": "MyProgram",", ""type": {", ""kind": "struct",", ""fields": [", @@ -1064,10 +1092,7 @@ exports[`anchor-application generator should generate app with "counter" templat "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -1080,76 +1105,87 @@ exports[`anchor-application generator should generate app with "counter" templat "children": { "my_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_program.json\`.", + "*/", "export type MyProgram = {", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myProgram';", "version: '0.1.0';", - "name: 'my_program';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", "instructions: [", "{", "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'systemProgram';", - "isMut: false;", - "isSigner: false;", + "address: '11111111111111111111111111111111';", "}", "];", "args: [];", "},", "{", "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [", @@ -1163,6 +1199,12 @@ exports[`anchor-application generator should generate app with "counter" templat "accounts: [", "{", "name: 'myProgram';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", + "}", + "];", + "types: [", + "{", + "name: 'myProgram';", "type: {", "kind: 'struct';", "fields: [", @@ -1175,101 +1217,6 @@ exports[`anchor-application generator should generate app with "counter" templat "}", "];", "};", - "export const IDL: MyProgram = {", - "version: '0.1.0',", - "name: 'my_program',", - "instructions: [", - "{", - "name: 'close',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'decrement',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'increment',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'initialize',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'systemProgram',", - "isMut: false,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'set',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [", - "{", - "name: 'value',", - "type: 'u8',", - "},", - "],", - "},", - "],", - "accounts: [", - "{", - "name: 'myProgram',", - "type: {", - "kind: 'struct',", - "fields: [", - "{", - "name: 'count',", - "type: 'u8',", - "},", - "],", - "},", - "},", - "],", - "};", ], "isBinary": false, "path": "anchor-app/target/types/my_program.ts", @@ -1400,7 +1347,9 @@ exports[`anchor-application generator should generate app with "counter" templat ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": ["node"],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", ""include": ["src/**/*.ts"],", ""exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]", diff --git a/packages/preset-anchor/src/generators/anchor-application/anchor-application-generator.ts b/packages/preset-anchor/src/generators/anchor-application/anchor-application-generator.ts index c6641e3d..5d1d2e96 100644 --- a/packages/preset-anchor/src/generators/anchor-application/anchor-application-generator.ts +++ b/packages/preset-anchor/src/generators/anchor-application/anchor-application-generator.ts @@ -37,6 +37,15 @@ export async function anchorApplicationGenerator(tree: Tree, rawOptions: AnchorA return json }) + updateJson(tree, join(project.root, 'tsconfig.lib.json'), (json) => { + json.compilerOptions = { + ...json.compilerOptions, + resolveJsonModule: true, + allowSyntheticDefaultImports: true, + } + return json + }) + await anchorTemplateGenerator(tree, { projectName: options.name, name: 'base', diff --git a/packages/preset-anchor/src/generators/anchor-template/__snapshots__/anchor-template-generator.spec.ts.snap b/packages/preset-anchor/src/generators/anchor-template/__snapshots__/anchor-template-generator.spec.ts.snap index 787d728b..bc1b08bc 100644 --- a/packages/preset-anchor/src/generators/anchor-template/__snapshots__/anchor-template-generator.spec.ts.snap +++ b/packages/preset-anchor/src/generators/anchor-template/__snapshots__/anchor-template-generator.spec.ts.snap @@ -54,8 +54,9 @@ exports[`anchor-template generator should be able to generate two templates side "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "target/programs/counter-one/Cargo.toml", @@ -157,8 +158,9 @@ exports[`anchor-template generator should be able to generate two templates side "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "target/programs/counter-two/Cargo.toml", @@ -250,13 +252,18 @@ exports[`anchor-template generator should be able to generate two templates side "counter-one-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import CounterOneIDL from '../target/idl/counter_one.json';", "import type { CounterOne } from '../target/types/counter_one';", - "import { IDL as CounterOneIDL } from '../target/types/counter_one';", "// Re-export the generated IDL and type", "export { CounterOne, CounterOneIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const COUNTER_ONE_PROGRAM_ID = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const COUNTER_ONE_PROGRAM_ID = new PublicKey(CounterOneIDL.address)", + "// This is a helper function to get the CounterOne Anchor program.", + "export function getCounterOneProgram(provider: AnchorProvider) {", + "return new Program(CounterOneIDL as CounterOne, provider);", + "}", "// This is a helper function to get the program ID for the CounterOne program depending on the cluster.", "export function getCounterOneProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -274,13 +281,18 @@ exports[`anchor-template generator should be able to generate two templates side "counter-two-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import CounterTwoIDL from '../target/idl/counter_two.json';", "import type { CounterTwo } from '../target/types/counter_two';", - "import { IDL as CounterTwoIDL } from '../target/types/counter_two';", "// Re-export the generated IDL and type", "export { CounterTwo, CounterTwoIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const COUNTER_TWO_PROGRAM_ID = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const COUNTER_TWO_PROGRAM_ID = new PublicKey(CounterTwoIDL.address)", + "// This is a helper function to get the CounterTwo Anchor program.", + "export function getCounterTwoProgram(provider: AnchorProvider) {", + "return new Program(CounterTwoIDL as CounterTwo, provider);", + "}", "// This is a helper function to get the program ID for the CounterTwo program depending on the cluster.", "export function getCounterTwoProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -332,75 +344,125 @@ exports[`anchor-template generator should be able to generate two templates side "counter_one.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "counter_one",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [", + "98,", + "165,", + "201,", + "177,", + "108,", + "65,", + "206,", + "96", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_one",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [", + "106,", + "227,", + "168,", + "59,", + "248,", + "27,", + "150,", + "101", + "],", ""accounts": [", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_one",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [", + "11,", + "18,", + "104,", + "9,", + "104,", + "174,", + "59,", + "33", + "],", ""accounts": [", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_one",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [", + "175,", + "175,", + "109,", + "31,", + "13,", + "152,", + "155,", + "237", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": true", + ""name": "counter_one",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [", + "198,", + "51,", + "53,", + "241,", + "116,", + "29,", + "126,", + "194", + "],", ""accounts": [", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_one",", + ""writable": true", "}", "],", ""args": [", @@ -414,6 +476,21 @@ exports[`anchor-template generator should be able to generate two templates side ""accounts": [", "{", ""name": "CounterOne",", + ""discriminator": [", + "135,", + "64,", + "223,", + "168,", + "233,", + "143,", + "162,", + "215", + "]", + "}", + "],", + ""types": [", + "{", + ""name": "CounterOne",", ""type": {", ""kind": "struct",", ""fields": [", @@ -424,10 +501,7 @@ exports[`anchor-template generator should be able to generate two templates side "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -436,75 +510,125 @@ exports[`anchor-template generator should be able to generate two templates side "counter_two.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "counter_two",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [", + "98,", + "165,", + "201,", + "177,", + "108,", + "65,", + "206,", + "96", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_two",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [", + "106,", + "227,", + "168,", + "59,", + "248,", + "27,", + "150,", + "101", + "],", ""accounts": [", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_two",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [", + "11,", + "18,", + "104,", + "9,", + "104,", + "174,", + "59,", + "33", + "],", ""accounts": [", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_two",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [", + "175,", + "175,", + "109,", + "31,", + "13,", + "152,", + "155,", + "237", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": true", + ""name": "counter_two",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [", + "198,", + "51,", + "53,", + "241,", + "116,", + "29,", + "126,", + "194", + "],", ""accounts": [", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + ""name": "counter_two",", + ""writable": true", "}", "],", ""args": [", @@ -518,6 +642,21 @@ exports[`anchor-template generator should be able to generate two templates side ""accounts": [", "{", ""name": "CounterTwo",", + ""discriminator": [", + "135,", + "64,", + "223,", + "168,", + "233,", + "143,", + "162,", + "215", + "]", + "}", + "],", + ""types": [", + "{", + ""name": "CounterTwo",", ""type": {", ""kind": "struct",", ""fields": [", @@ -528,10 +667,7 @@ exports[`anchor-template generator should be able to generate two templates side "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -544,195 +680,117 @@ exports[`anchor-template generator should be able to generate two templates side "children": { "counter_one.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/counter_one.json\`.", + "*/", "export type CounterOne = {", - ""version": "0.1.0",", - ""name": "counter_one",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'counterOne';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", + "instructions: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", + "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", + "accounts: [", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "decrement",", - ""accounts": [", - "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + "name: 'counterOne';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", + "accounts: [", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + "name: 'counterOne';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "initialize",", - ""accounts": [", + "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'counterOne';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", - "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", - "}", - "],", - ""accounts": [", - "{", - ""name": "counterOne",", - ""type": {", - ""kind": "struct",", - ""fields": [", - "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", - "}", - "}", - "]", - "};", - "export const IDL: CounterOne = {", - ""version": "0.1.0",", - ""name": "counter_one",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", + "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", + "name: 'counterOne';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "decrement",", - ""accounts": [", - "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + "name: 'systemProgram';", + "address: '11111111111111111111111111111111';", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", + "accounts: [", "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + "name: 'counterOne';", + "writable: true;", "}", - "],", - ""args": []", - "},", - "{", - ""name": "initialize",", - ""accounts": [", + "];", + "args: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'value';", + "type: 'u8';", "}", - "],", - ""args": []", - "},", - "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counterOne",", - ""isMut": true,", - ""isSigner": false", + "];", "}", - "],", - ""args": [", + "];", + "accounts: [", "{", - ""name": "value",", - ""type": "u8"", + "name: 'counterOne';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", "}", - "]", - "}", - "],", - ""accounts": [", + "];", + "types: [", "{", - ""name": "counterOne",", - ""type": {", - ""kind": "struct",", - ""fields": [", + "name: 'counterOne';", + "type: {", + "kind: 'struct';", + "fields: [", "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'count';", + "type: 'u8';", "}", + "];", + "};", "}", - "]", + "];", "};", ], "isBinary": false, @@ -740,195 +798,117 @@ exports[`anchor-template generator should be able to generate two templates side }, "counter_two.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/counter_two.json\`.", + "*/", "export type CounterTwo = {", - ""version": "0.1.0",", - ""name": "counter_two",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'counterTwo';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", + "instructions: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", + "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", + "accounts: [", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "decrement",", - ""accounts": [", - "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + "name: 'counterTwo';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", + "accounts: [", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + "name: 'counterTwo';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "initialize",", - ""accounts": [", + "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'counterTwo';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", - "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", - "}", - "],", - ""accounts": [", - "{", - ""name": "counterTwo",", - ""type": {", - ""kind": "struct",", - ""fields": [", - "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", - "}", - "}", - "]", - "};", - "export const IDL: CounterTwo = {", - ""version": "0.1.0",", - ""name": "counter_two",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", + "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", + "name: 'counterTwo';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "decrement",", - ""accounts": [", - "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + "name: 'systemProgram';", + "address: '11111111111111111111111111111111';", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", + "accounts: [", "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + "name: 'counterTwo';", + "writable: true;", "}", - "],", - ""args": []", - "},", - "{", - ""name": "initialize",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": true", - "},", + "];", + "args: [", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'value';", + "type: 'u8';", "}", - "],", - ""args": []", - "},", - "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counterTwo",", - ""isMut": true,", - ""isSigner": false", + "];", "}", - "],", - ""args": [", + "];", + "accounts: [", "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", + "name: 'counterTwo';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", "}", - "],", - ""accounts": [", + "];", + "types: [", "{", - ""name": "counterTwo",", - ""type": {", - ""kind": "struct",", - ""fields": [", + "name: 'counterTwo';", + "type: {", + "kind: 'struct';", + "fields: [", "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'count';", + "type: 'u8';", "}", + "];", + "};", "}", - "]", + "];", "};", ], "isBinary": false, @@ -1209,8 +1189,9 @@ exports[`anchor-template generator should generate files for basic template 1`] "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "target/programs/basic/Cargo.toml", @@ -1257,13 +1238,18 @@ exports[`anchor-template generator should generate files for basic template 1`] "basic-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { PublicKey } from '@solana/web3.js';", "import type { Basic } from '../target/types/basic';", "import { IDL as BasicIDL } from '../target/types/basic';", "// Re-export the generated IDL and type", "export { Basic, BasicIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const programId = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const BASIC_PROGRAM_ID = new PublicKey(BasicIDL.address)", + "// This is a helper function to get the Basic Anchor program.", + "export function getBasicProgram(provider: AnchorProvider) {", + "return new Program(BasicIDL as Basic, provider);", + "}", ], "isBinary": false, "path": "target/src/basic-exports.ts", @@ -1297,11 +1283,26 @@ exports[`anchor-template generator should generate files for basic template 1`] "basic.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "basic",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "greet",", + ""discriminator": [", + "203,", + "194,", + "3,", + "150,", + "228,", + "58,", + "181,", + "62", + "],", ""accounts": [],", ""args": []", "}", @@ -1318,27 +1319,28 @@ exports[`anchor-template generator should generate files for basic template 1`] "children": { "basic.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/basic.json\`.", + "*/", "export type Basic = {", - ""version": "0.1.0",", - ""name": "basic",", - ""instructions": [", - "{", - ""name": "greet",", - ""accounts": [],", - ""args": []", - "}", - "]", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'basic';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", "};", - "export const IDL: Basic = {", - ""version": "0.1.0",", - ""name": "basic",", - ""instructions": [", + "instructions: [", "{", - ""name": "greet",", - ""accounts": [],", - ""args": []", + "name: 'greet';", + "discriminator: [203, 194, 3, 150, 228, 58, 181, 62];", + "accounts: [];", + "args: [];", "}", - "]", + "];", "};", ], "isBinary": false, @@ -1431,8 +1433,9 @@ exports[`anchor-template generator should generate files for counter template 1` "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "target/programs/counter/Cargo.toml", @@ -1524,13 +1527,18 @@ exports[`anchor-template generator should generate files for counter template 1` "counter-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import CounterIDL from '../target/idl/counter.json';", "import type { Counter } from '../target/types/counter';", - "import { IDL as CounterIDL } from '../target/types/counter';", "// Re-export the generated IDL and type", "export { Counter, CounterIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const COUNTER_PROGRAM_ID = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const COUNTER_PROGRAM_ID = new PublicKey(CounterIDL.address)", + "// This is a helper function to get the Counter Anchor program.", + "export function getCounterProgram(provider: AnchorProvider) {", + "return new Program(CounterIDL as Counter, provider);", + "}", "// This is a helper function to get the program ID for the Counter program depending on the cluster.", "export function getCounterProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -1576,75 +1584,125 @@ exports[`anchor-template generator should generate files for counter template 1` "counter.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "counter",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [", + "98,", + "165,", + "201,", + "177,", + "108,", + "65,", + "206,", + "96", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [", + "106,", + "227,", + "168,", + "59,", + "248,", + "27,", + "150,", + "101", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [", + "11,", + "18,", + "104,", + "9,", + "104,", + "174,", + "59,", + "33", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [", + "175,", + "175,", + "109,", + "31,", + "13,", + "152,", + "155,", + "237", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [", + "198,", + "51,", + "53,", + "241,", + "116,", + "29,", + "126,", + "194", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": [", @@ -1658,6 +1716,21 @@ exports[`anchor-template generator should generate files for counter template 1` ""accounts": [", "{", ""name": "Counter",", + ""discriminator": [", + "135,", + "64,", + "223,", + "168,", + "233,", + "143,", + "162,", + "215", + "]", + "}", + "],", + ""types": [", + "{", + ""name": "Counter",", ""type": {", ""kind": "struct",", ""fields": [", @@ -1668,10 +1741,7 @@ exports[`anchor-template generator should generate files for counter template 1` "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -1684,195 +1754,117 @@ exports[`anchor-template generator should generate files for counter template 1` "children": { "counter.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/counter.json\`.", + "*/", "export type Counter = {", - ""version": "0.1.0",", - ""name": "counter",", - ""instructions": [", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'counter';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", + "instructions: [", "{", - ""name": "close",", - ""accounts": [", + "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "decrement",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "initialize",", - ""accounts": [", + "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", - "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", - "}", - "],", - ""accounts": [", - "{", - ""name": "counter",", - ""type": {", - ""kind": "struct",", - ""fields": [", + "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", + "accounts: [", "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", - "}", - "}", - "]", - "};", - "export const IDL: Counter = {", - ""version": "0.1.0",", - ""name": "counter",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", + "name: 'counter';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "decrement",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'systemProgram';", + "address: '11111111111111111111111111111111';", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", - "},", - "{", - ""name": "initialize",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": true", - "},", + "];", + "args: [", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'value';", + "type: 'u8';", "}", - "],", - ""args": []", - "},", - "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "];", "}", - "],", - ""args": [", + "];", + "accounts: [", "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", + "name: 'counter';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", "}", - "],", - ""accounts": [", + "];", + "types: [", "{", - ""name": "counter",", - ""type": {", - ""kind": "struct",", - ""fields": [", + "name: 'counter';", + "type: {", + "kind: 'struct';", + "fields: [", "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'count';", + "type: 'u8';", "}", + "];", + "};", "}", - "]", + "];", "};", ], "isBinary": false, diff --git a/packages/preset-anchor/src/generators/anchor-template/files/basic/Cargo.lock.template b/packages/preset-anchor/src/generators/anchor-template/files/basic/Cargo.lock.template index 85f99ba3..fc5825b7 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/basic/Cargo.lock.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/basic/Cargo.lock.template @@ -25,11 +25,20 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anchor-attribute-access-control" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f619f1d04f53621925ba8a2e633ba5a6081f2ae14758cbb67f38fd823e0a3e" +checksum = "dd7368e171b3a317885dc08ec0f74eed9d0ad6c726cc819593aed81440dca926" dependencies = [ "anchor-syn", "proc-macro2", @@ -39,9 +48,9 @@ dependencies = [ [[package]] name = "anchor-attribute-account" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f2a3e1df4685f18d12a943a9f2a7456305401af21a07c9fe076ef9ecd6e400" +checksum = "f527df85a8cba3f2bea04e46ed71b66e525ea378c7fec538aa205f4520b73e31" dependencies = [ "anchor-syn", "bs58 0.5.0", @@ -52,9 +61,9 @@ dependencies = [ [[package]] name = "anchor-attribute-constant" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9423945cb55627f0b30903288e78baf6f62c6c8ab28fb344b6b25f1ffee3dca7" +checksum = "3eb1dc1845cf8636c2e046a274ca074dabd3884ac8ed11cc4ed64b7e8ef5a318" dependencies = [ "anchor-syn", "quote", @@ -63,9 +72,9 @@ dependencies = [ [[package]] name = "anchor-attribute-error" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ed12720033cc3c3bf3cfa293349c2275cd5ab99936e33dd4bf283aaad3e241" +checksum = "7f382e41514c59a77ffa7bb1a47df9a0359564a749b6934485c742c11962e540" dependencies = [ "anchor-syn", "quote", @@ -74,9 +83,9 @@ dependencies = [ [[package]] name = "anchor-attribute-event" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef4dc0371eba2d8c8b54794b0b0eb786a234a559b77593d6f80825b6d2c77a2" +checksum = "473a122aeed3f6b666438236338d2ef7833ee5fdc5688e1baa80185d61088a53" dependencies = [ "anchor-syn", "proc-macro2", @@ -86,20 +95,26 @@ dependencies = [ [[package]] name = "anchor-attribute-program" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18c4f191331e078d4a6a080954d1576241c29c56638783322a18d308ab27e4f" +checksum = "7f88c7ffe2eb40aeac43ffd0d74a6671581158aedfaa0552330a2ef92fa5c889" dependencies = [ + "anchor-lang-idl", "anchor-syn", + "anyhow", + "bs58 0.5.0", + "heck", + "proc-macro2", "quote", + "serde_json", "syn 1.0.109", ] [[package]] name = "anchor-derive-accounts" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de10d6e9620d3bcea56c56151cad83c5992f50d5960b3a9bebc4a50390ddc3c" +checksum = "ed9b97c99dcec135aae0ff908c14bcfcd3e78cfc16a0c6f245135038f0e6d390" dependencies = [ "anchor-syn", "quote", @@ -108,9 +123,9 @@ dependencies = [ [[package]] name = "anchor-derive-serde" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4e2e5be518ec6053d90a2a7f26843dbee607583c779e6c8395951b9739bdfbe" +checksum = "bbece98f6ad9c37070edc0841326c9623a249346cd74f433e7cef69b14f7f31d" dependencies = [ "anchor-syn", "borsh-derive-internal 0.10.3", @@ -121,9 +136,9 @@ dependencies = [ [[package]] name = "anchor-derive-space" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecc31d19fa54840e74b7a979d44bcea49d70459de846088a1d71e87ba53c419" +checksum = "8badbe2648bc99a85ee05a7a5f9512e5e2af8ffac71476a69350cb278057ac53" dependencies = [ "proc-macro2", "quote", @@ -132,9 +147,9 @@ dependencies = [ [[package]] name = "anchor-lang" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35da4785497388af0553586d55ebdc08054a8b1724720ef2749d313494f2b8ad" +checksum = "e41feb9c1cd9f4b0fad1c004fc8f289183f3ce27e9db38fa6e434470c716fb1e" dependencies = [ "anchor-attribute-access-control", "anchor-attribute-account", @@ -145,8 +160,9 @@ dependencies = [ "anchor-derive-accounts", "anchor-derive-serde", "anchor-derive-space", + "anchor-lang-idl", "arrayref", - "base64 0.13.1", + "base64 0.21.7", "bincode", "borsh 0.10.3", "bytemuck", @@ -155,14 +171,28 @@ dependencies = [ "thiserror", ] +[[package]] +name = "anchor-lang-idl" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29da81eae478b1bb846749b06b8a2cb9c6f9ed26ca793b0c916793fdf36adab" +dependencies = [ + "anchor-syn", + "anyhow", + "regex", + "serde", + "serde_json", +] + [[package]] name = "anchor-syn" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9101b84702fed2ea57bd22992f75065da5648017135b844283a2f6d74f27825" +checksum = "ac53f2378bc08e89e20c2b893c01986ffd34cfbc69a17e35bd6f754753e9fdad" dependencies = [ "anyhow", "bs58 0.5.0", + "cargo_toml", "heck", "proc-macro2", "quote", @@ -320,12 +350,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -568,6 +592,16 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cargo_toml" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a98356df42a2eb1bd8f1793ae4ee4de48e384dd974ce5eac8eee802edb7492be" +dependencies = [ + "serde", + "toml 0.8.12", +] + [[package]] name = "cc" version = "1.0.83" @@ -809,13 +843,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "<%= fileName %>" -version = "0.1.0" -dependencies = [ - "anchor-lang", -] - [[package]] name = "hmac" version = "0.8.1" @@ -1119,7 +1146,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] @@ -1128,7 +1155,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -1281,6 +1308,35 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1360,6 +1416,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "sha2" version = "0.9.9" @@ -1618,11 +1683,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.12", +] + [[package]] name = "toml_datetime" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -1632,7 +1712,20 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.6", ] [[package]] @@ -1810,6 +1903,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +dependencies = [ + "memchr", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/packages/preset-anchor/src/generators/anchor-template/files/basic/programs/__fileName__/Cargo.toml.template b/packages/preset-anchor/src/generators/anchor-template/files/basic/programs/__fileName__/Cargo.toml.template index 311ed416..f8b902cc 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/basic/programs/__fileName__/Cargo.toml.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/basic/programs/__fileName__/Cargo.toml.template @@ -14,6 +14,7 @@ no-idl = [] no-log-ix-name = [] cpi = ["no-entrypoint"] default = [] +idl-build = ["anchor-lang/idl-build"] [dependencies] -anchor-lang = "0.29.0" +anchor-lang = "0.30.0" diff --git a/packages/preset-anchor/src/generators/anchor-template/files/basic/src/__fileName__-exports.ts.template b/packages/preset-anchor/src/generators/anchor-template/files/basic/src/__fileName__-exports.ts.template index a59afa22..1af740b1 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/basic/src/__fileName__-exports.ts.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/basic/src/__fileName__-exports.ts.template @@ -1,4 +1,5 @@ // Here we export some useful types and functions for interacting with the Anchor program. +import { AnchorProvider, Program } from '@coral-xyz/anchor'; import { PublicKey } from '@solana/web3.js'; import type { <%= className %> } from '../target/types/<%= fileNameUnderscore %>'; import { IDL as <%= className %>IDL } from '../target/types/<%= fileNameUnderscore %>'; @@ -6,5 +7,10 @@ import { IDL as <%= className %>IDL } from '../target/types/<%= fileNameUndersco // Re-export the generated IDL and type export { <%= className %>, <%= className %>IDL }; -// After updating your program ID (e.g. after running `anchor keys sync`) update the value below. -export const programId = new PublicKey('<%= publicKey %>') +// The programId is imported from the program IDL. +export const <%= upperCaseName %>_PROGRAM_ID = new PublicKey(<%= className %>IDL.address) + +// This is a helper function to get the <%= className %> Anchor program. +export function get<%= className %>Program(provider: AnchorProvider) { + return new Program(<%= className %>IDL as <%= className %>, provider); +} diff --git a/packages/preset-anchor/src/generators/anchor-template/files/basic/target/idl/__fileNameUnderscore__.json.template b/packages/preset-anchor/src/generators/anchor-template/files/basic/target/idl/__fileNameUnderscore__.json.template index 562663af..a77e78af 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/basic/target/idl/__fileNameUnderscore__.json.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/basic/target/idl/__fileNameUnderscore__.json.template @@ -1,9 +1,24 @@ { - "version": "0.1.0", - "name": "<%= fileNameUnderscore %>", - "instructions": [ + "address": "<%= publicKey %>", + "metadata": { + "name": "<%= fileNameUnderscore %>", + "version": "0.1.0", + "spec": "0.1.0", + "description": "Created with Anchor" + }, + "instructions": [ { "name": "greet", + "discriminator": [ + 203, + 194, + 3, + 150, + 228, + 58, + 181, + 62 + ], "accounts": [], "args": [] } diff --git a/packages/preset-anchor/src/generators/anchor-template/files/basic/target/types/__fileNameUnderscore__.ts.template b/packages/preset-anchor/src/generators/anchor-template/files/basic/target/types/__fileNameUnderscore__.ts.template index 9468b908..0ff59950 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/basic/target/types/__fileNameUnderscore__.ts.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/basic/target/types/__fileNameUnderscore__.ts.template @@ -1,23 +1,23 @@ +/** + * Program IDL in camelCase format in order to be used in JS/TS. + * + * Note that this is only a type helper and is not the actual IDL. The original + * IDL can be found at `target/idl/<%= fileNameUnderscore %>.json`. + */ export type <%= className %> = { - "version": "0.1.0", - "name": "<%= fileNameUnderscore %>", - "instructions": [ - { - "name": "greet", - "accounts": [], - "args": [] - } - ] -}; - -export const IDL: <%= className %> = { - "version": "0.1.0", - "name": "<%= fileNameUnderscore %>", - "instructions": [ - { - "name": "greet", - "accounts": [], - "args": [] - } - ] + address: '<%= publicKey %>'; + metadata: { + name: '<%= propertyName %>'; + version: '0.1.0'; + spec: '0.1.0'; + description: 'Created with Anchor'; + }; + instructions: [ + { + name: 'greet'; + discriminator: [203, 194, 3, 150, 228, 58, 181, 62]; + accounts: []; + args: []; + } + ]; }; diff --git a/packages/preset-anchor/src/generators/anchor-template/files/counter/Cargo.lock.template b/packages/preset-anchor/src/generators/anchor-template/files/counter/Cargo.lock.template index 18d6cfc3..fc5825b7 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/counter/Cargo.lock.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/counter/Cargo.lock.template @@ -25,11 +25,20 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anchor-attribute-access-control" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f619f1d04f53621925ba8a2e633ba5a6081f2ae14758cbb67f38fd823e0a3e" +checksum = "dd7368e171b3a317885dc08ec0f74eed9d0ad6c726cc819593aed81440dca926" dependencies = [ "anchor-syn", "proc-macro2", @@ -39,9 +48,9 @@ dependencies = [ [[package]] name = "anchor-attribute-account" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f2a3e1df4685f18d12a943a9f2a7456305401af21a07c9fe076ef9ecd6e400" +checksum = "f527df85a8cba3f2bea04e46ed71b66e525ea378c7fec538aa205f4520b73e31" dependencies = [ "anchor-syn", "bs58 0.5.0", @@ -52,9 +61,9 @@ dependencies = [ [[package]] name = "anchor-attribute-constant" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9423945cb55627f0b30903288e78baf6f62c6c8ab28fb344b6b25f1ffee3dca7" +checksum = "3eb1dc1845cf8636c2e046a274ca074dabd3884ac8ed11cc4ed64b7e8ef5a318" dependencies = [ "anchor-syn", "quote", @@ -63,9 +72,9 @@ dependencies = [ [[package]] name = "anchor-attribute-error" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ed12720033cc3c3bf3cfa293349c2275cd5ab99936e33dd4bf283aaad3e241" +checksum = "7f382e41514c59a77ffa7bb1a47df9a0359564a749b6934485c742c11962e540" dependencies = [ "anchor-syn", "quote", @@ -74,9 +83,9 @@ dependencies = [ [[package]] name = "anchor-attribute-event" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef4dc0371eba2d8c8b54794b0b0eb786a234a559b77593d6f80825b6d2c77a2" +checksum = "473a122aeed3f6b666438236338d2ef7833ee5fdc5688e1baa80185d61088a53" dependencies = [ "anchor-syn", "proc-macro2", @@ -86,20 +95,26 @@ dependencies = [ [[package]] name = "anchor-attribute-program" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18c4f191331e078d4a6a080954d1576241c29c56638783322a18d308ab27e4f" +checksum = "7f88c7ffe2eb40aeac43ffd0d74a6671581158aedfaa0552330a2ef92fa5c889" dependencies = [ + "anchor-lang-idl", "anchor-syn", + "anyhow", + "bs58 0.5.0", + "heck", + "proc-macro2", "quote", + "serde_json", "syn 1.0.109", ] [[package]] name = "anchor-derive-accounts" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de10d6e9620d3bcea56c56151cad83c5992f50d5960b3a9bebc4a50390ddc3c" +checksum = "ed9b97c99dcec135aae0ff908c14bcfcd3e78cfc16a0c6f245135038f0e6d390" dependencies = [ "anchor-syn", "quote", @@ -108,9 +123,9 @@ dependencies = [ [[package]] name = "anchor-derive-serde" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4e2e5be518ec6053d90a2a7f26843dbee607583c779e6c8395951b9739bdfbe" +checksum = "bbece98f6ad9c37070edc0841326c9623a249346cd74f433e7cef69b14f7f31d" dependencies = [ "anchor-syn", "borsh-derive-internal 0.10.3", @@ -121,9 +136,9 @@ dependencies = [ [[package]] name = "anchor-derive-space" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecc31d19fa54840e74b7a979d44bcea49d70459de846088a1d71e87ba53c419" +checksum = "8badbe2648bc99a85ee05a7a5f9512e5e2af8ffac71476a69350cb278057ac53" dependencies = [ "proc-macro2", "quote", @@ -132,9 +147,9 @@ dependencies = [ [[package]] name = "anchor-lang" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35da4785497388af0553586d55ebdc08054a8b1724720ef2749d313494f2b8ad" +checksum = "e41feb9c1cd9f4b0fad1c004fc8f289183f3ce27e9db38fa6e434470c716fb1e" dependencies = [ "anchor-attribute-access-control", "anchor-attribute-account", @@ -145,8 +160,9 @@ dependencies = [ "anchor-derive-accounts", "anchor-derive-serde", "anchor-derive-space", + "anchor-lang-idl", "arrayref", - "base64 0.13.1", + "base64 0.21.7", "bincode", "borsh 0.10.3", "bytemuck", @@ -155,14 +171,28 @@ dependencies = [ "thiserror", ] +[[package]] +name = "anchor-lang-idl" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b29da81eae478b1bb846749b06b8a2cb9c6f9ed26ca793b0c916793fdf36adab" +dependencies = [ + "anchor-syn", + "anyhow", + "regex", + "serde", + "serde_json", +] + [[package]] name = "anchor-syn" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9101b84702fed2ea57bd22992f75065da5648017135b844283a2f6d74f27825" +checksum = "ac53f2378bc08e89e20c2b893c01986ffd34cfbc69a17e35bd6f754753e9fdad" dependencies = [ "anyhow", "bs58 0.5.0", + "cargo_toml", "heck", "proc-macro2", "quote", @@ -320,12 +350,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -568,6 +592,16 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cargo_toml" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a98356df42a2eb1bd8f1793ae4ee4de48e384dd974ce5eac8eee802edb7492be" +dependencies = [ + "serde", + "toml 0.8.12", +] + [[package]] name = "cc" version = "1.0.83" @@ -616,13 +650,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" -[[package]] -name = "<%= fileName %>" -version = "0.1.0" -dependencies = [ - "anchor-lang", -] - [[package]] name = "cpufeatures" version = "0.2.12" @@ -1119,7 +1146,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] @@ -1128,7 +1155,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -1281,6 +1308,35 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1360,6 +1416,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "sha2" version = "0.9.9" @@ -1618,11 +1683,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.12", +] + [[package]] name = "toml_datetime" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -1632,7 +1712,20 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.6", ] [[package]] @@ -1810,6 +1903,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +dependencies = [ + "memchr", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/packages/preset-anchor/src/generators/anchor-template/files/counter/programs/__fileName__/Cargo.toml.template b/packages/preset-anchor/src/generators/anchor-template/files/counter/programs/__fileName__/Cargo.toml.template index 311ed416..f8b902cc 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/counter/programs/__fileName__/Cargo.toml.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/counter/programs/__fileName__/Cargo.toml.template @@ -14,6 +14,7 @@ no-idl = [] no-log-ix-name = [] cpi = ["no-entrypoint"] default = [] +idl-build = ["anchor-lang/idl-build"] [dependencies] -anchor-lang = "0.29.0" +anchor-lang = "0.30.0" diff --git a/packages/preset-anchor/src/generators/anchor-template/files/counter/src/__fileName__-exports.ts.template b/packages/preset-anchor/src/generators/anchor-template/files/counter/src/__fileName__-exports.ts.template index b3dae24c..afd7a8b9 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/counter/src/__fileName__-exports.ts.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/counter/src/__fileName__-exports.ts.template @@ -1,13 +1,19 @@ // Here we export some useful types and functions for interacting with the Anchor program. +import { AnchorProvider, Program } from '@coral-xyz/anchor'; import { Cluster, PublicKey } from '@solana/web3.js'; +import <%= className %>IDL from '../target/idl/<%= fileNameUnderscore %>.json'; import type { <%= className %> } from '../target/types/<%= fileNameUnderscore %>'; -import { IDL as <%= className %>IDL } from '../target/types/<%= fileNameUnderscore %>'; // Re-export the generated IDL and type export { <%= className %>, <%= className %>IDL }; -// After updating your program ID (e.g. after running `anchor keys sync`) update the value below. -export const <%= upperCaseName %>_PROGRAM_ID = new PublicKey('<%= publicKey %>') +// The programId is imported from the program IDL. +export const <%= upperCaseName %>_PROGRAM_ID = new PublicKey(<%= className %>IDL.address) + +// This is a helper function to get the <%= className %> Anchor program. +export function get<%= className %>Program(provider: AnchorProvider) { + return new Program(<%= className %>IDL as <%= className %>, provider); +} // This is a helper function to get the program ID for the <%= className %> program depending on the cluster. export function get<%= className %>ProgramId(cluster: Cluster) { diff --git a/packages/preset-anchor/src/generators/anchor-template/files/counter/target/idl/__fileNameUnderscore__.json.template b/packages/preset-anchor/src/generators/anchor-template/files/counter/target/idl/__fileNameUnderscore__.json.template index a07f54a1..54d793b8 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/counter/target/idl/__fileNameUnderscore__.json.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/counter/target/idl/__fileNameUnderscore__.json.template @@ -1,73 +1,123 @@ { - "version": "0.1.0", - "name": "<%= fileNameUnderscore %>", + "address": "<%= publicKey %>", + "metadata": { + "name": "<%= fileNameUnderscore %>", + "version": "0.1.0", + "spec": "0.1.0", + "description": "Created with Anchor" + }, "instructions": [ { "name": "close", + "discriminator": [ + 98, + 165, + 201, + 177, + 108, + 65, + 206, + 96 + ], "accounts": [ { "name": "payer", - "isMut": true, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + "name": "<%= fileNameUnderscore %>", + "writable": true } ], "args": [] }, { "name": "decrement", + "discriminator": [ + 106, + 227, + 168, + 59, + 248, + 27, + 150, + 101 + ], "accounts": [ { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + "name": "<%= fileNameUnderscore %>", + "writable": true } ], "args": [] }, { "name": "increment", + "discriminator": [ + 11, + 18, + 104, + 9, + 104, + 174, + 59, + 33 + ], "accounts": [ { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + "name": "<%= fileNameUnderscore %>", + "writable": true } ], "args": [] }, { "name": "initialize", + "discriminator": [ + 175, + 175, + 109, + 31, + 13, + 152, + 155, + 237 + ], "accounts": [ { "name": "payer", - "isMut": true, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": true + "name": "<%= fileNameUnderscore %>", + "writable": true, + "signer": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [] }, { "name": "set", + "discriminator": [ + 198, + 51, + 53, + 241, + 116, + 29, + 126, + 194 + ], "accounts": [ { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + "name": "<%= fileNameUnderscore %>", + "writable": true } ], "args": [ @@ -79,6 +129,21 @@ } ], "accounts": [ + { + "name": "<%= className %>", + "discriminator": [ + 135, + 64, + 223, + 168, + 233, + 143, + 162, + 215 + ] + } + ], + "types": [ { "name": "<%= className %>", "type": { @@ -91,8 +156,5 @@ ] } } - ], - "metadata": { - "address": "<%= publicKey %>" - } + ] } diff --git a/packages/preset-anchor/src/generators/anchor-template/files/counter/target/types/__fileNameUnderscore__.ts.template b/packages/preset-anchor/src/generators/anchor-template/files/counter/target/types/__fileNameUnderscore__.ts.template index 72b40e2e..a6d224be 100644 --- a/packages/preset-anchor/src/generators/anchor-template/files/counter/target/types/__fileNameUnderscore__.ts.template +++ b/packages/preset-anchor/src/generators/anchor-template/files/counter/target/types/__fileNameUnderscore__.ts.template @@ -1,191 +1,112 @@ +/** + * Program IDL in camelCase format in order to be used in JS/TS. + * + * Note that this is only a type helper and is not the actual IDL. The original + * IDL can be found at `target/idl/<%= fileNameUnderscore %>.json`. + */ export type <%= className %> = { - "version": "0.1.0", - "name": "<%= fileNameUnderscore %>", - "instructions": [ + address: '<%= publicKey %>'; + metadata: { + name: '<%= propertyName %>'; + version: '0.1.0'; + spec: '0.1.0'; + description: 'Created with Anchor'; + }; + instructions: [ { - "name": "close", - "accounts": [ + name: 'close'; + discriminator: [98, 165, 201, 177, 108, 65, 206, 96]; + accounts: [ { - "name": "payer", - "isMut": true, - "isSigner": true + name: 'payer'; + writable: true; + signer: true; }, { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + name: '<%= propertyName %>'; + writable: true; } - ], - "args": [] + ]; + args: []; }, { - "name": "decrement", - "accounts": [ + name: 'decrement'; + discriminator: [106, 227, 168, 59, 248, 27, 150, 101]; + accounts: [ { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + name: '<%= propertyName %>'; + writable: true; } - ], - "args": [] + ]; + args: []; }, { - "name": "increment", - "accounts": [ + name: 'increment'; + discriminator: [11, 18, 104, 9, 104, 174, 59, 33]; + accounts: [ { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + name: '<%= propertyName %>'; + writable: true; } - ], - "args": [] + ]; + args: []; }, { - "name": "initialize", - "accounts": [ + name: 'initialize'; + discriminator: [175, 175, 109, 31, 13, 152, 155, 237]; + accounts: [ { - "name": "payer", - "isMut": true, - "isSigner": true + name: 'payer'; + writable: true; + signer: true; }, { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": true + name: '<%= propertyName %>'; + writable: true; + signer: true; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: 'systemProgram'; + address: '11111111111111111111111111111111'; } - ], - "args": [] + ]; + args: []; }, { - "name": "set", - "accounts": [ + name: 'set'; + discriminator: [198, 51, 53, 241, 116, 29, 126, 194]; + accounts: [ { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false + name: '<%= propertyName %>'; + writable: true; } - ], - "args": [ + ]; + args: [ { - "name": "value", - "type": "u8" + name: 'value'; + type: 'u8'; } - ] + ]; } - ], - "accounts": [ + ]; + accounts: [ { - "name": "<%= propertyName %>", - "type": { - "kind": "struct", - "fields": [ - { - "name": "count", - "type": "u8" - } - ] - } - } - ] -}; - -export const IDL: <%= className %> = { - "version": "0.1.0", - "name": "<%= fileNameUnderscore %>", - "instructions": [ - { - "name": "close", - "accounts": [ - { - "name": "payer", - "isMut": true, - "isSigner": true - }, - { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "decrement", - "accounts": [ - { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "increment", - "accounts": [ - { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "initialize", - "accounts": [ - { - "name": "payer", - "isMut": true, - "isSigner": true - }, - { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": true - }, - { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "set", - "accounts": [ - { - "name": "<%= propertyName %>", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "value", - "type": "u8" - } - ] + name: '<%= propertyName %>'; + discriminator: [135, 64, 223, 168, 233, 143, 162, 215]; } - ], - "accounts": [ + ]; + types: [ { - "name": "<%= propertyName %>", - "type": { - "kind": "struct", - "fields": [ + name: '<%= propertyName %>'; + type: { + kind: 'struct'; + fields: [ { - "name": "count", - "type": "u8" + name: 'count'; + type: 'u8'; } - ] - } + ]; + }; } - ] + ]; }; diff --git a/packages/preset-common/package.json b/packages/preset-common/package.json index 0e593705..6980824a 100644 --- a/packages/preset-common/package.json +++ b/packages/preset-common/package.json @@ -4,7 +4,7 @@ "description": "This library is a preset for create-solana-dapp with shared code for the other presets.", "dependencies": { "@nx/devkit": "18.1.3", - "ts-morph": "^21.0.1", + "ts-morph": "^22.0.0", "tslib": "^2.3.0" }, "type": "commonjs", diff --git a/packages/preset-common/src/generators/common-template/__snapshots__/common-template-generator.spec.ts.snap b/packages/preset-common/src/generators/common-template/__snapshots__/common-template-generator.spec.ts.snap index 4c1197aa..e97634f9 100644 --- a/packages/preset-common/src/generators/common-template/__snapshots__/common-template-generator.spec.ts.snap +++ b/packages/preset-common/src/generators/common-template/__snapshots__/common-template-generator.spec.ts.snap @@ -261,9 +261,9 @@ exports[`common-template generator should generate files: { template: 'readme', "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -332,9 +332,9 @@ exports[`common-template generator should generate files: { template: 'readme', "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -403,9 +403,9 @@ exports[`common-template generator should generate files: { template: 'readme', "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -474,9 +474,9 @@ exports[`common-template generator should generate files: { template: 'readme', "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -545,9 +545,9 @@ exports[`common-template generator should generate files: { template: 'readme', "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -616,9 +616,9 @@ exports[`common-template generator should generate files: { template: 'readme', "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", diff --git a/packages/preset-common/src/generators/common-template/files/readme/README.md.template b/packages/preset-common/src/generators/common-template/files/readme/README.md.template index 8fe58d75..ee06641a 100644 --- a/packages/preset-common/src/generators/common-template/files/readme/README.md.template +++ b/packages/preset-common/src/generators/common-template/files/readme/README.md.template @@ -8,9 +8,9 @@ This project is generated with the [create-solana-dapp](https://github.com/solan - Node v18.18.0 or higher <% if (anchor.fileName !== 'none') { %> -- Rust v1.70.0 or higher -- Anchor CLI 0.29.0 or higher -- Solana CLI 1.17.0 or higher +- Rust v1.77.2 or higher +- Anchor CLI 0.30.0 or higher +- Solana CLI 1.18.9 or higher <% } %> ### Installation diff --git a/packages/preset-common/src/utils/package-versions.ts b/packages/preset-common/src/utils/package-versions.ts index bf45e6b0..6b144fe3 100644 --- a/packages/preset-common/src/utils/package-versions.ts +++ b/packages/preset-common/src/utils/package-versions.ts @@ -1,6 +1,6 @@ export const packageVersion = { '@coral-xyz': { - anchor: '^0.29.0', + anchor: '^0.30.0', }, '@tailwindcss': { typography: '0.5.10', diff --git a/packages/preset-next/src/generators/next-application/__snapshots__/next-application-generator.spec.ts.snap b/packages/preset-next/src/generators/next-application/__snapshots__/next-application-generator.spec.ts.snap index 51ab5617..21e9bb2a 100644 --- a/packages/preset-next/src/generators/next-application/__snapshots__/next-application-generator.spec.ts.snap +++ b/packages/preset-next/src/generators/next-application/__snapshots__/next-application-generator.spec.ts.snap @@ -1777,9 +1777,9 @@ exports[`application generator default apps should generate default app with "no "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -2030,7 +2030,7 @@ exports[`application generator default apps should generate default app with "no ""name": "@proj/anchor",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -2062,8 +2062,9 @@ exports[`application generator default apps should generate default app with "no "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor/programs/my-program/Cargo.toml", @@ -2225,15 +2226,18 @@ exports[`application generator default apps should generate default app with "no "my-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import MyProgramIDL from '../target/idl/my_program.json';", "import type { MyProgram } from '../target/types/my_program';", - "import { IDL as MyProgramIDL } from '../target/types/my_program';", "// Re-export the generated IDL and type", "export { MyProgram, MyProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(", - "'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA'", - ");", + "// The programId is imported from the program IDL.", + "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(MyProgramIDL.address);", + "// This is a helper function to get the MyProgram Anchor program.", + "export function getMyProgramProgram(provider: AnchorProvider) {", + "return new Program(MyProgramIDL as MyProgram, provider);", + "}", "// This is a helper function to get the program ID for the MyProgram program depending on the cluster.", "export function getMyProgramProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -2275,75 +2279,80 @@ exports[`application generator default apps should generate default app with "no "my_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [98, 165, 201, 177, 108, 65, 206, 96],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [106, 227, 168, 59, 248, 27, 150, 101],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [11, 18, 104, 9, 104, 174, 59, 33],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [175, 175, 109, 31, 13, 152, 155, 237],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": true", + ""name": "my_program",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [198, 51, 53, 241, 116, 29, 126, 194],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": [", @@ -2357,6 +2366,12 @@ exports[`application generator default apps should generate default app with "no ""accounts": [", "{", ""name": "MyProgram",", + ""discriminator": [135, 64, 223, 168, 233, 143, 162, 215]", + "}", + "],", + ""types": [", + "{", + ""name": "MyProgram",", ""type": {", ""kind": "struct",", ""fields": [", @@ -2367,10 +2382,7 @@ exports[`application generator default apps should generate default app with "no "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -2383,76 +2395,87 @@ exports[`application generator default apps should generate default app with "no "children": { "my_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_program.json\`.", + "*/", "export type MyProgram = {", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myProgram';", "version: '0.1.0';", - "name: 'my_program';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", "instructions: [", "{", "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'systemProgram';", - "isMut: false;", - "isSigner: false;", + "address: '11111111111111111111111111111111';", "}", "];", "args: [];", "},", "{", "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [", @@ -2466,6 +2489,12 @@ exports[`application generator default apps should generate default app with "no "accounts: [", "{", "name: 'myProgram';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", + "}", + "];", + "types: [", + "{", + "name: 'myProgram';", "type: {", "kind: 'struct';", "fields: [", @@ -2478,101 +2507,6 @@ exports[`application generator default apps should generate default app with "no "}", "];", "};", - "export const IDL: MyProgram = {", - "version: '0.1.0',", - "name: 'my_program',", - "instructions: [", - "{", - "name: 'close',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'decrement',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'increment',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'initialize',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'systemProgram',", - "isMut: false,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'set',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [", - "{", - "name: 'value',", - "type: 'u8',", - "},", - "],", - "},", - "],", - "accounts: [", - "{", - "name: 'myProgram',", - "type: {", - "kind: 'struct',", - "fields: [", - "{", - "name: 'count',", - "type: 'u8',", - "},", - "],", - "},", - "},", - "],", - "};", ], "isBinary": false, "path": "./anchor/target/types/my_program.ts", @@ -2703,7 +2637,9 @@ exports[`application generator default apps should generate default app with "no ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": ["node"],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", ""include": ["src/**/*.ts"],", ""exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]", @@ -2817,7 +2753,7 @@ exports[`application generator default apps should generate default app with "no "{", ""name": "@proj/source",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/spl-token": "0.4.1",", ""@solana/wallet-adapter-base": "^0.9.23",", ""@solana/wallet-adapter-react": "^0.15.35",", @@ -4450,9 +4386,9 @@ exports[`application generator default apps should generate default app with "ta "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -4703,7 +4639,7 @@ exports[`application generator default apps should generate default app with "ta ""name": "@proj/anchor",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -4735,8 +4671,9 @@ exports[`application generator default apps should generate default app with "ta "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor/programs/my-program/Cargo.toml", @@ -4898,15 +4835,18 @@ exports[`application generator default apps should generate default app with "ta "my-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import MyProgramIDL from '../target/idl/my_program.json';", "import type { MyProgram } from '../target/types/my_program';", - "import { IDL as MyProgramIDL } from '../target/types/my_program';", "// Re-export the generated IDL and type", "export { MyProgram, MyProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(", - "'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA'", - ");", + "// The programId is imported from the program IDL.", + "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(MyProgramIDL.address);", + "// This is a helper function to get the MyProgram Anchor program.", + "export function getMyProgramProgram(provider: AnchorProvider) {", + "return new Program(MyProgramIDL as MyProgram, provider);", + "}", "// This is a helper function to get the program ID for the MyProgram program depending on the cluster.", "export function getMyProgramProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -4948,75 +4888,80 @@ exports[`application generator default apps should generate default app with "ta "my_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [98, 165, 201, 177, 108, 65, 206, 96],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [106, 227, 168, 59, 248, 27, 150, 101],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [11, 18, 104, 9, 104, 174, 59, 33],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [175, 175, 109, 31, 13, 152, 155, 237],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": true", + ""name": "my_program",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [198, 51, 53, 241, 116, 29, 126, 194],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": [", @@ -5030,6 +4975,12 @@ exports[`application generator default apps should generate default app with "ta ""accounts": [", "{", ""name": "MyProgram",", + ""discriminator": [135, 64, 223, 168, 233, 143, 162, 215]", + "}", + "],", + ""types": [", + "{", + ""name": "MyProgram",", ""type": {", ""kind": "struct",", ""fields": [", @@ -5040,10 +4991,7 @@ exports[`application generator default apps should generate default app with "ta "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -5056,76 +5004,87 @@ exports[`application generator default apps should generate default app with "ta "children": { "my_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_program.json\`.", + "*/", "export type MyProgram = {", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myProgram';", "version: '0.1.0';", - "name: 'my_program';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", "instructions: [", "{", "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'systemProgram';", - "isMut: false;", - "isSigner: false;", + "address: '11111111111111111111111111111111';", "}", "];", "args: [];", "},", "{", "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [", @@ -5139,6 +5098,12 @@ exports[`application generator default apps should generate default app with "ta "accounts: [", "{", "name: 'myProgram';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", + "}", + "];", + "types: [", + "{", + "name: 'myProgram';", "type: {", "kind: 'struct';", "fields: [", @@ -5151,101 +5116,6 @@ exports[`application generator default apps should generate default app with "ta "}", "];", "};", - "export const IDL: MyProgram = {", - "version: '0.1.0',", - "name: 'my_program',", - "instructions: [", - "{", - "name: 'close',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'decrement',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'increment',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'initialize',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'systemProgram',", - "isMut: false,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'set',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [", - "{", - "name: 'value',", - "type: 'u8',", - "},", - "],", - "},", - "],", - "accounts: [", - "{", - "name: 'myProgram',", - "type: {", - "kind: 'struct',", - "fields: [", - "{", - "name: 'count',", - "type: 'u8',", - "},", - "],", - "},", - "},", - "],", - "};", ], "isBinary": false, "path": "./anchor/target/types/my_program.ts", @@ -5376,7 +5246,9 @@ exports[`application generator default apps should generate default app with "ta ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": ["node"],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", ""include": ["src/**/*.ts"],", ""exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]", @@ -5490,7 +5362,7 @@ exports[`application generator default apps should generate default app with "ta "{", ""name": "@proj/source",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/spl-token": "0.4.1",", ""@solana/wallet-adapter-base": "^0.9.23",", ""@solana/wallet-adapter-react": "^0.15.35",", @@ -6862,7 +6734,7 @@ exports[`application generator default apps should generate default app with "ta "my-program-data-access.tsx": { "content": [ "'use client';", - "import { MyProgramIDL, getMyProgramProgramId } from '@proj/anchor';", + "import { getMyProgramProgram, getMyProgramProgramId } from '@proj/anchor';", "import { Program } from '@coral-xyz/anchor';", "import { useConnection } from '@solana/wallet-adapter-react';", "import { Cluster, Keypair, PublicKey } from '@solana/web3.js';", @@ -6881,7 +6753,7 @@ exports[`application generator default apps should generate default app with "ta "() => getMyProgramProgramId(cluster.network as Cluster),", "[cluster]", ");", - "const program = new Program(MyProgramIDL, programId, provider);", + "const program = getMyProgramProgram(provider);", "const accounts = useQuery({", "queryKey: ['my-program', 'all', { cluster }],", "queryFn: () => program.account.myProgram.all(),", diff --git a/packages/preset-react/src/generators/react-application/__snapshots__/react-application-generator.spec.ts.snap b/packages/preset-react/src/generators/react-application/__snapshots__/react-application-generator.spec.ts.snap index 7913aa3f..cab6b288 100644 --- a/packages/preset-react/src/generators/react-application/__snapshots__/react-application-generator.spec.ts.snap +++ b/packages/preset-react/src/generators/react-application/__snapshots__/react-application-generator.spec.ts.snap @@ -827,9 +827,9 @@ exports[`react-application generator default apps should generate default app wi "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -1080,7 +1080,7 @@ exports[`react-application generator default apps should generate default app wi ""name": "@proj/anchor",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -1112,8 +1112,9 @@ exports[`react-application generator default apps should generate default app wi "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor/programs/my-program/Cargo.toml", @@ -1275,15 +1276,18 @@ exports[`react-application generator default apps should generate default app wi "my-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import MyProgramIDL from '../target/idl/my_program.json';", "import type { MyProgram } from '../target/types/my_program';", - "import { IDL as MyProgramIDL } from '../target/types/my_program';", "// Re-export the generated IDL and type", "export { MyProgram, MyProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(", - "'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA'", - ");", + "// The programId is imported from the program IDL.", + "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(MyProgramIDL.address);", + "// This is a helper function to get the MyProgram Anchor program.", + "export function getMyProgramProgram(provider: AnchorProvider) {", + "return new Program(MyProgramIDL as MyProgram, provider);", + "}", "// This is a helper function to get the program ID for the MyProgram program depending on the cluster.", "export function getMyProgramProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -1325,75 +1329,80 @@ exports[`react-application generator default apps should generate default app wi "my_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [98, 165, 201, 177, 108, 65, 206, 96],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [106, 227, 168, 59, 248, 27, 150, 101],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [11, 18, 104, 9, 104, 174, 59, 33],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [175, 175, 109, 31, 13, 152, 155, 237],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": true", + ""name": "my_program",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [198, 51, 53, 241, 116, 29, 126, 194],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": [", @@ -1407,6 +1416,12 @@ exports[`react-application generator default apps should generate default app wi ""accounts": [", "{", ""name": "MyProgram",", + ""discriminator": [135, 64, 223, 168, 233, 143, 162, 215]", + "}", + "],", + ""types": [", + "{", + ""name": "MyProgram",", ""type": {", ""kind": "struct",", ""fields": [", @@ -1417,10 +1432,7 @@ exports[`react-application generator default apps should generate default app wi "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -1433,76 +1445,87 @@ exports[`react-application generator default apps should generate default app wi "children": { "my_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_program.json\`.", + "*/", "export type MyProgram = {", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myProgram';", "version: '0.1.0';", - "name: 'my_program';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", "instructions: [", "{", "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'systemProgram';", - "isMut: false;", - "isSigner: false;", + "address: '11111111111111111111111111111111';", "}", "];", "args: [];", "},", "{", "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [", @@ -1516,6 +1539,12 @@ exports[`react-application generator default apps should generate default app wi "accounts: [", "{", "name: 'myProgram';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", + "}", + "];", + "types: [", + "{", + "name: 'myProgram';", "type: {", "kind: 'struct';", "fields: [", @@ -1528,101 +1557,6 @@ exports[`react-application generator default apps should generate default app wi "}", "];", "};", - "export const IDL: MyProgram = {", - "version: '0.1.0',", - "name: 'my_program',", - "instructions: [", - "{", - "name: 'close',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'decrement',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'increment',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'initialize',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'systemProgram',", - "isMut: false,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'set',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [", - "{", - "name: 'value',", - "type: 'u8',", - "},", - "],", - "},", - "],", - "accounts: [", - "{", - "name: 'myProgram',", - "type: {", - "kind: 'struct',", - "fields: [", - "{", - "name: 'count',", - "type: 'u8',", - "},", - "],", - "},", - "},", - "],", - "};", ], "isBinary": false, "path": "./anchor/target/types/my_program.ts", @@ -1753,7 +1687,9 @@ exports[`react-application generator default apps should generate default app wi ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": ["node"],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", ""include": ["src/**/*.ts"],", ""exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]", @@ -1871,7 +1807,7 @@ exports[`react-application generator default apps should generate default app wi "{", ""name": "@proj/source",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/spl-token": "0.4.1",", ""@solana/wallet-adapter-base": "^0.9.23",", ""@solana/wallet-adapter-react": "^0.15.35",", @@ -2549,9 +2485,9 @@ exports[`react-application generator default apps should generate default app wi "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -2802,7 +2738,7 @@ exports[`react-application generator default apps should generate default app wi ""name": "@proj/anchor",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -2834,8 +2770,9 @@ exports[`react-application generator default apps should generate default app wi "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor/programs/my-program/Cargo.toml", @@ -2997,15 +2934,18 @@ exports[`react-application generator default apps should generate default app wi "my-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import MyProgramIDL from '../target/idl/my_program.json';", "import type { MyProgram } from '../target/types/my_program';", - "import { IDL as MyProgramIDL } from '../target/types/my_program';", "// Re-export the generated IDL and type", "export { MyProgram, MyProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(", - "'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA'", - ");", + "// The programId is imported from the program IDL.", + "export const MY_PROGRAM_PROGRAM_ID = new PublicKey(MyProgramIDL.address);", + "// This is a helper function to get the MyProgram Anchor program.", + "export function getMyProgramProgram(provider: AnchorProvider) {", + "return new Program(MyProgramIDL as MyProgram, provider);", + "}", "// This is a helper function to get the program ID for the MyProgram program depending on the cluster.", "export function getMyProgramProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -3047,75 +2987,80 @@ exports[`react-application generator default apps should generate default app wi "my_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [98, 165, 201, 177, 108, 65, 206, 96],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [106, 227, 168, 59, 248, 27, 150, 101],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [11, 18, 104, 9, 104, 174, 59, 33],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [175, 175, 109, 31, 13, 152, 155, 237],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": true", + ""name": "my_program",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [198, 51, 53, 241, 116, 29, 126, 194],", ""accounts": [", "{", - ""name": "myProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_program",", + ""writable": true", "}", "],", ""args": [", @@ -3129,6 +3074,12 @@ exports[`react-application generator default apps should generate default app wi ""accounts": [", "{", ""name": "MyProgram",", + ""discriminator": [135, 64, 223, 168, 233, 143, 162, 215]", + "}", + "],", + ""types": [", + "{", + ""name": "MyProgram",", ""type": {", ""kind": "struct",", ""fields": [", @@ -3139,10 +3090,7 @@ exports[`react-application generator default apps should generate default app wi "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -3155,76 +3103,87 @@ exports[`react-application generator default apps should generate default app wi "children": { "my_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_program.json\`.", + "*/", "export type MyProgram = {", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myProgram';", "version: '0.1.0';", - "name: 'my_program';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", "instructions: [", "{", "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [];", "},", "{", "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", "accounts: [", "{", "name: 'payer';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: true;", + "writable: true;", + "signer: true;", "},", "{", "name: 'systemProgram';", - "isMut: false;", - "isSigner: false;", + "address: '11111111111111111111111111111111';", "}", "];", "args: [];", "},", "{", "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", "accounts: [", "{", "name: 'myProgram';", - "isMut: true;", - "isSigner: false;", + "writable: true;", "}", "];", "args: [", @@ -3238,6 +3197,12 @@ exports[`react-application generator default apps should generate default app wi "accounts: [", "{", "name: 'myProgram';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", + "}", + "];", + "types: [", + "{", + "name: 'myProgram';", "type: {", "kind: 'struct';", "fields: [", @@ -3250,101 +3215,6 @@ exports[`react-application generator default apps should generate default app wi "}", "];", "};", - "export const IDL: MyProgram = {", - "version: '0.1.0',", - "name: 'my_program',", - "instructions: [", - "{", - "name: 'close',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'decrement',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'increment',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'initialize',", - "accounts: [", - "{", - "name: 'payer',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: true,", - "},", - "{", - "name: 'systemProgram',", - "isMut: false,", - "isSigner: false,", - "},", - "],", - "args: [],", - "},", - "{", - "name: 'set',", - "accounts: [", - "{", - "name: 'myProgram',", - "isMut: true,", - "isSigner: false,", - "},", - "],", - "args: [", - "{", - "name: 'value',", - "type: 'u8',", - "},", - "],", - "},", - "],", - "accounts: [", - "{", - "name: 'myProgram',", - "type: {", - "kind: 'struct',", - "fields: [", - "{", - "name: 'count',", - "type: 'u8',", - "},", - "],", - "},", - "},", - "],", - "};", ], "isBinary": false, "path": "./anchor/target/types/my_program.ts", @@ -3475,7 +3345,9 @@ exports[`react-application generator default apps should generate default app wi ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": ["node"],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", ""include": ["src/**/*.ts"],", ""exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]", @@ -3593,7 +3465,7 @@ exports[`react-application generator default apps should generate default app wi "{", ""name": "@proj/source",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/spl-token": "0.4.1",", ""@solana/wallet-adapter-base": "^0.9.23",", ""@solana/wallet-adapter-react": "^0.15.35",", @@ -4965,7 +4837,7 @@ exports[`react-application generator default apps should generate default app wi "children": { "my-program-data-access.tsx": { "content": [ - "import { MyProgramIDL, getMyProgramProgramId } from '@proj/anchor';", + "import { getMyProgramProgram, getMyProgramProgramId } from '@proj/anchor';", "import { Program } from '@coral-xyz/anchor';", "import { useConnection } from '@solana/wallet-adapter-react';", "import { Cluster, Keypair, PublicKey } from '@solana/web3.js';", @@ -4984,7 +4856,7 @@ exports[`react-application generator default apps should generate default app wi "() => getMyProgramProgramId(cluster.network as Cluster),", "[cluster]", ");", - "const program = new Program(MyProgramIDL, programId, provider);", + "const program = getMyProgramProgram(provider);", "const accounts = useQuery({", "queryKey: ['my-program', 'all', { cluster }],", "queryFn: () => program.account.myProgram.all(),", diff --git a/packages/preset-react/src/generators/react-feature/__snapshots__/react-feature-generator.spec.ts.snap b/packages/preset-react/src/generators/react-feature/__snapshots__/react-feature-generator.spec.ts.snap index 3cc1f5cd..30bfb416 100644 --- a/packages/preset-react/src/generators/react-feature/__snapshots__/react-feature-generator.spec.ts.snap +++ b/packages/preset-react/src/generators/react-feature/__snapshots__/react-feature-generator.spec.ts.snap @@ -131,9 +131,9 @@ exports[`react-feature generator should generate files for anchor-basic feature "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -396,7 +396,7 @@ exports[`react-feature generator should generate files for anchor-basic feature ""name": "@proj/anchor-app",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -428,8 +428,9 @@ exports[`react-feature generator should generate files for anchor-basic feature "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor-app/programs/counter/Cargo.toml", @@ -531,8 +532,9 @@ exports[`react-feature generator should generate files for anchor-basic feature "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor-app/programs/my-anchor-basic-program/Cargo.toml", @@ -654,13 +656,18 @@ exports[`react-feature generator should generate files for anchor-basic feature "counter-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import CounterIDL from '../target/idl/counter.json';", "import type { Counter } from '../target/types/counter';", - "import { IDL as CounterIDL } from '../target/types/counter';", "// Re-export the generated IDL and type", "export { Counter, CounterIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const COUNTER_PROGRAM_ID = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const COUNTER_PROGRAM_ID = new PublicKey(CounterIDL.address)", + "// This is a helper function to get the Counter Anchor program.", + "export function getCounterProgram(provider: AnchorProvider) {", + "return new Program(CounterIDL as Counter, provider);", + "}", "// This is a helper function to get the program ID for the Counter program depending on the cluster.", "export function getCounterProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -689,13 +696,18 @@ exports[`react-feature generator should generate files for anchor-basic feature "my-anchor-basic-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { PublicKey } from '@solana/web3.js';", "import type { MyAnchorBasicProgram } from '../target/types/my_anchor_basic_program';", "import { IDL as MyAnchorBasicProgramIDL } from '../target/types/my_anchor_basic_program';", "// Re-export the generated IDL and type", "export { MyAnchorBasicProgram, MyAnchorBasicProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const programId = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const MY_ANCHOR_BASIC_PROGRAM_PROGRAM_ID = new PublicKey(MyAnchorBasicProgramIDL.address)", + "// This is a helper function to get the MyAnchorBasicProgram Anchor program.", + "export function getMyAnchorBasicProgramProgram(provider: AnchorProvider) {", + "return new Program(MyAnchorBasicProgramIDL as MyAnchorBasicProgram, provider);", + "}", ], "isBinary": false, "path": "./anchor-app/src/my-anchor-basic-program-exports.ts", @@ -729,75 +741,125 @@ exports[`react-feature generator should generate files for anchor-basic feature "counter.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "counter",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [", + "98,", + "165,", + "201,", + "177,", + "108,", + "65,", + "206,", + "96", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [", + "106,", + "227,", + "168,", + "59,", + "248,", + "27,", + "150,", + "101", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [", + "11,", + "18,", + "104,", + "9,", + "104,", + "174,", + "59,", + "33", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [", + "175,", + "175,", + "109,", + "31,", + "13,", + "152,", + "155,", + "237", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [", + "198,", + "51,", + "53,", + "241,", + "116,", + "29,", + "126,", + "194", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": [", @@ -811,6 +873,21 @@ exports[`react-feature generator should generate files for anchor-basic feature ""accounts": [", "{", ""name": "Counter",", + ""discriminator": [", + "135,", + "64,", + "223,", + "168,", + "233,", + "143,", + "162,", + "215", + "]", + "}", + "],", + ""types": [", + "{", + ""name": "Counter",", ""type": {", ""kind": "struct",", ""fields": [", @@ -821,10 +898,7 @@ exports[`react-feature generator should generate files for anchor-basic feature "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -833,11 +907,26 @@ exports[`react-feature generator should generate files for anchor-basic feature "my_anchor_basic_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_anchor_basic_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "greet",", + ""discriminator": [", + "203,", + "194,", + "3,", + "150,", + "228,", + "58,", + "181,", + "62", + "],", ""accounts": [],", ""args": []", "}", @@ -854,195 +943,117 @@ exports[`react-feature generator should generate files for anchor-basic feature "children": { "counter.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/counter.json\`.", + "*/", "export type Counter = {", - ""version": "0.1.0",", - ""name": "counter",", - ""instructions": [", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'counter';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", + "instructions: [", "{", - ""name": "close",", - ""accounts": [", + "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "decrement",", - ""accounts": [", + "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "initialize",", - ""accounts": [", + "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": true", + "name: 'counter';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'systemProgram';", + "address: '11111111111111111111111111111111';", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", + "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", + "accounts: [", "{", - ""name": "value",", - ""type": "u8"", + "name: 'counter';", + "writable: true;", "}", - "]", - "}", - "],", - ""accounts": [", + "];", + "args: [", "{", - ""name": "counter",", - ""type": {", - ""kind": "struct",", - ""fields": [", - "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", - "}", + "name: 'value';", + "type: 'u8';", "}", - "]", - "};", - "export const IDL: Counter = {", - ""version": "0.1.0",", - ""name": "counter",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "];", "}", - "],", - ""args": []", - "},", - "{", - ""name": "decrement",", - ""accounts": [", + "];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", "}", - "],", - ""args": []", - "},", + "];", + "types: [", "{", - ""name": "increment",", - ""accounts": [", + "name: 'counter';", + "type: {", + "kind: 'struct';", + "fields: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "initialize",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", - "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", - "}", - "],", - ""accounts": [", - "{", - ""name": "counter",", - ""type": {", - ""kind": "struct",", - ""fields": [", - "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'count';", + "type: 'u8';", "}", + "];", + "};", "}", - "]", + "];", "};", ], "isBinary": false, @@ -1050,27 +1061,28 @@ exports[`react-feature generator should generate files for anchor-basic feature }, "my_anchor_basic_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_anchor_basic_program.json\`.", + "*/", "export type MyAnchorBasicProgram = {", - ""version": "0.1.0",", - ""name": "my_anchor_basic_program",", - ""instructions": [", - "{", - ""name": "greet",", - ""accounts": [],", - ""args": []", - "}", - "]", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myAnchorBasicProgram';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", "};", - "export const IDL: MyAnchorBasicProgram = {", - ""version": "0.1.0",", - ""name": "my_anchor_basic_program",", - ""instructions": [", + "instructions: [", "{", - ""name": "greet",", - ""accounts": [],", - ""args": []", + "name: 'greet';", + "discriminator: [203, 194, 3, 150, 228, 58, 181, 62];", + "accounts: [];", + "args: [];", "}", - "]", + "];", "};", ], "isBinary": false, @@ -1197,12 +1209,19 @@ exports[`react-feature generator should generate files for anchor-basic feature ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": [", + ""node"", + "],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", - ""include": ["src/**/*.ts"],", + ""include": [", + ""src/**/*.ts"", + "],", ""exclude": [", ""jest.config.ts",", - ""src/**/*.spec.ts", "src/**/*.test.ts"", + ""src/**/*.spec.ts",", + ""src/**/*.test.ts"", "]", "}", ], @@ -1327,7 +1346,7 @@ exports[`react-feature generator should generate files for anchor-basic feature "{", ""name": "@proj/source",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/spl-token": "0.4.1",", ""@solana/wallet-adapter-base": "^0.9.23",", ""@solana/wallet-adapter-react": "^0.15.35",", @@ -2534,7 +2553,7 @@ exports[`react-feature generator should generate files for anchor-basic feature "children": { "counter-data-access.tsx": { "content": [ - "import { CounterIDL, getCounterProgramId } from '@proj/anchor'", + "import { getCounterProgram, getCounterProgramId } from '@proj/anchor'", "import { Program } from '@coral-xyz/anchor';", "import { useConnection } from '@solana/wallet-adapter-react';", "import { Cluster, Keypair, PublicKey } from '@solana/web3.js';", @@ -2553,7 +2572,7 @@ exports[`react-feature generator should generate files for anchor-basic feature "() => getCounterProgramId(cluster.network as Cluster),", "[cluster]", ");", - "const program = new Program(CounterIDL, programId, provider)", + "const program = getCounterProgram(provider)", "const accounts = useQuery({", "queryKey: ['counter', 'all', { cluster }],", "queryFn: () => program.account.counter.all(),", @@ -2838,7 +2857,7 @@ exports[`react-feature generator should generate files for anchor-basic feature "children": { "my-anchor-basic-program-data-access.tsx": { "content": [ - "import { programId, MyAnchorBasicProgramIDL } from '@proj/anchor';", + "import { programId, getMyAnchorBasicProgramProgram } from '@proj/anchor';", "import { Program } from '@coral-xyz/anchor';", "import { useConnection } from '@solana/wallet-adapter-react';", "import { Keypair } from '@solana/web3.js';", @@ -2852,7 +2871,7 @@ exports[`react-feature generator should generate files for anchor-basic feature "const { cluster } = useCluster();", "const transactionToast = useTransactionToast();", "const provider = useAnchorProvider();", - "const program = new Program(MyAnchorBasicProgramIDL, programId, provider);", + "const program = getMyAnchorBasicProgramProgram(provider);", "const getProgramAccount = useQuery({", "queryKey: ['get-program-account', { cluster }],", "queryFn: () => connection.getParsedAccountInfo(programId),", @@ -3481,9 +3500,9 @@ exports[`react-feature generator should generate files for anchor-counter featur "## Getting Started", "### Prerequisites", "- Node v18.18.0 or higher", - "- Rust v1.70.0 or higher", - "- Anchor CLI 0.29.0 or higher", - "- Solana CLI 1.17.0 or higher", + "- Rust v1.77.2 or higher", + "- Anchor CLI 0.30.0 or higher", + "- Solana CLI 1.18.9 or higher", "### Installation", "#### Clone the repo", "\`\`\`shell", @@ -3746,7 +3765,7 @@ exports[`react-feature generator should generate files for anchor-counter featur ""name": "@proj/anchor-app",", ""version": "0.0.1",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/web3.js": "1.90.0"", "},", ""type": "commonjs",", @@ -3778,8 +3797,9 @@ exports[`react-feature generator should generate files for anchor-counter featur "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor-app/programs/counter/Cargo.toml", @@ -3881,8 +3901,9 @@ exports[`react-feature generator should generate files for anchor-counter featur "no-log-ix-name = []", "cpi = ["no-entrypoint"]", "default = []", + "idl-build = ["anchor-lang/idl-build"]", "[dependencies]", - "anchor-lang = "0.29.0"", + "anchor-lang = "0.30.0"", ], "isBinary": false, "path": "./anchor-app/programs/my-anchor-counter-program/Cargo.toml", @@ -4049,13 +4070,18 @@ exports[`react-feature generator should generate files for anchor-counter featur "counter-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import CounterIDL from '../target/idl/counter.json';", "import type { Counter } from '../target/types/counter';", - "import { IDL as CounterIDL } from '../target/types/counter';", "// Re-export the generated IDL and type", "export { Counter, CounterIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const COUNTER_PROGRAM_ID = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const COUNTER_PROGRAM_ID = new PublicKey(CounterIDL.address)", + "// This is a helper function to get the Counter Anchor program.", + "export function getCounterProgram(provider: AnchorProvider) {", + "return new Program(CounterIDL as Counter, provider);", + "}", "// This is a helper function to get the program ID for the Counter program depending on the cluster.", "export function getCounterProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -4084,13 +4110,18 @@ exports[`react-feature generator should generate files for anchor-counter featur "my-anchor-counter-program-exports.ts": { "content": [ "// Here we export some useful types and functions for interacting with the Anchor program.", + "import { AnchorProvider, Program } from '@coral-xyz/anchor';", "import { Cluster, PublicKey } from '@solana/web3.js';", + "import MyAnchorCounterProgramIDL from '../target/idl/my_anchor_counter_program.json';", "import type { MyAnchorCounterProgram } from '../target/types/my_anchor_counter_program';", - "import { IDL as MyAnchorCounterProgramIDL } from '../target/types/my_anchor_counter_program';", "// Re-export the generated IDL and type", "export { MyAnchorCounterProgram, MyAnchorCounterProgramIDL };", - "// After updating your program ID (e.g. after running \`anchor keys sync\`) update the value below.", - "export const MY_ANCHOR_COUNTER_PROGRAM_PROGRAM_ID = new PublicKey('GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA')", + "// The programId is imported from the program IDL.", + "export const MY_ANCHOR_COUNTER_PROGRAM_PROGRAM_ID = new PublicKey(MyAnchorCounterProgramIDL.address)", + "// This is a helper function to get the MyAnchorCounterProgram Anchor program.", + "export function getMyAnchorCounterProgramProgram(provider: AnchorProvider) {", + "return new Program(MyAnchorCounterProgramIDL as MyAnchorCounterProgram, provider);", + "}", "// This is a helper function to get the program ID for the MyAnchorCounterProgram program depending on the cluster.", "export function getMyAnchorCounterProgramProgramId(cluster: Cluster) {", "switch (cluster) {", @@ -4134,75 +4165,125 @@ exports[`react-feature generator should generate files for anchor-counter featur "counter.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "counter",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [", + "98,", + "165,", + "201,", + "177,", + "108,", + "65,", + "206,", + "96", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [", + "106,", + "227,", + "168,", + "59,", + "248,", + "27,", + "150,", + "101", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [", + "11,", + "18,", + "104,", + "9,", + "104,", + "174,", + "59,", + "33", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [", + "175,", + "175,", + "109,", + "31,", + "13,", + "152,", + "155,", + "237", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [", + "198,", + "51,", + "53,", + "241,", + "116,", + "29,", + "126,", + "194", + "],", ""accounts": [", "{", ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + ""writable": true", "}", "],", ""args": [", @@ -4216,6 +4297,21 @@ exports[`react-feature generator should generate files for anchor-counter featur ""accounts": [", "{", ""name": "Counter",", + ""discriminator": [", + "135,", + "64,", + "223,", + "168,", + "233,", + "143,", + "162,", + "215", + "]", + "}", + "],", + ""types": [", + "{", + ""name": "Counter",", ""type": {", ""kind": "struct",", ""fields": [", @@ -4226,10 +4322,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -4238,75 +4331,125 @@ exports[`react-feature generator should generate files for anchor-counter featur "my_anchor_counter_program.json": { "content": [ "{", - ""version": "0.1.0",", + ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA",", + ""metadata": {", ""name": "my_anchor_counter_program",", + ""version": "0.1.0",", + ""spec": "0.1.0",", + ""description": "Created with Anchor"", + "},", ""instructions": [", "{", ""name": "close",", + ""discriminator": [", + "98,", + "165,", + "201,", + "177,", + "108,", + "65,", + "206,", + "96", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_anchor_counter_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "decrement",", + ""discriminator": [", + "106,", + "227,", + "168,", + "59,", + "248,", + "27,", + "150,", + "101", + "],", ""accounts": [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_anchor_counter_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "increment",", + ""discriminator": [", + "11,", + "18,", + "104,", + "9,", + "104,", + "174,", + "59,", + "33", + "],", ""accounts": [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_anchor_counter_program",", + ""writable": true", "}", "],", ""args": []", "},", "{", ""name": "initialize",", + ""discriminator": [", + "175,", + "175,", + "109,", + "31,", + "13,", + "152,", + "155,", + "237", + "],", ""accounts": [", "{", ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": true", + ""name": "my_anchor_counter_program",", + ""writable": true,", + ""signer": true", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + ""name": "system_program",", + ""address": "11111111111111111111111111111111"", "}", "],", ""args": []", "},", "{", ""name": "set",", + ""discriminator": [", + "198,", + "51,", + "53,", + "241,", + "116,", + "29,", + "126,", + "194", + "],", ""accounts": [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + ""name": "my_anchor_counter_program",", + ""writable": true", "}", "],", ""args": [", @@ -4320,6 +4463,21 @@ exports[`react-feature generator should generate files for anchor-counter featur ""accounts": [", "{", ""name": "MyAnchorCounterProgram",", + ""discriminator": [", + "135,", + "64,", + "223,", + "168,", + "233,", + "143,", + "162,", + "215", + "]", + "}", + "],", + ""types": [", + "{", + ""name": "MyAnchorCounterProgram",", ""type": {", ""kind": "struct",", ""fields": [", @@ -4330,10 +4488,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "]", "}", "}", - "],", - ""metadata": {", - ""address": "GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA"", - "}", + "]", "}", ], "isBinary": false, @@ -4346,195 +4501,117 @@ exports[`react-feature generator should generate files for anchor-counter featur "children": { "counter.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/counter.json\`.", + "*/", "export type Counter = {", - ""version": "0.1.0",", - ""name": "counter",", - ""instructions": [", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'counter';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", + "instructions: [", "{", - ""name": "close",", - ""accounts": [", + "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "decrement",", - ""accounts": [", + "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "initialize",", - ""accounts": [", + "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": true", + "name: 'counter';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'systemProgram';", + "address: '11111111111111111111111111111111';", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", + "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", + "accounts: [", "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", + "name: 'counter';", + "writable: true;", "}", - "],", - ""accounts": [", - "{", - ""name": "counter",", - ""type": {", - ""kind": "struct",", - ""fields": [", + "];", + "args: [", "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'value';", + "type: 'u8';", "}", + "];", "}", - "]", - "};", - "export const IDL: Counter = {", - ""version": "0.1.0",", - ""name": "counter",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", + "];", + "accounts: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", + "name: 'counter';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", "}", - "],", - ""args": []", - "},", + "];", + "types: [", "{", - ""name": "decrement",", - ""accounts": [", + "name: 'counter';", + "type: {", + "kind: 'struct';", + "fields: [", "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "increment",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "initialize",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "counter",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", - "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", - "}", - "],", - ""accounts": [", - "{", - ""name": "counter",", - ""type": {", - ""kind": "struct",", - ""fields": [", - "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'count';", + "type: 'u8';", "}", + "];", + "};", "}", - "]", + "];", "};", ], "isBinary": false, @@ -4542,195 +4619,117 @@ exports[`react-feature generator should generate files for anchor-counter featur }, "my_anchor_counter_program.ts": { "content": [ + "/**", + "* Program IDL in camelCase format in order to be used in JS/TS.", + "*", + "* Note that this is only a type helper and is not the actual IDL. The original", + "* IDL can be found at \`target/idl/my_anchor_counter_program.json\`.", + "*/", "export type MyAnchorCounterProgram = {", - ""version": "0.1.0",", - ""name": "my_anchor_counter_program",", - ""instructions": [", + "address: 'GMSER7ttdzFvei8hUjFrCxv3PNKje2NrPwuNYS7m15dA';", + "metadata: {", + "name: 'myAnchorCounterProgram';", + "version: '0.1.0';", + "spec: '0.1.0';", + "description: 'Created with Anchor';", + "};", + "instructions: [", "{", - ""name": "close",", - ""accounts": [", + "name: 'close';", + "discriminator: [98, 165, 201, 177, 108, 65, 206, 96];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + "name: 'myAnchorCounterProgram';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "decrement",", - ""accounts": [", + "name: 'decrement';", + "discriminator: [106, 227, 168, 59, 248, 27, 150, 101];", + "accounts: [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + "name: 'myAnchorCounterProgram';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "increment",", - ""accounts": [", + "name: 'increment';", + "discriminator: [11, 18, 104, 9, 104, 174, 59, 33];", + "accounts: [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + "name: 'myAnchorCounterProgram';", + "writable: true;", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "initialize",", - ""accounts": [", + "name: 'initialize';", + "discriminator: [175, 175, 109, 31, 13, 152, 155, 237];", + "accounts: [", "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", + "name: 'payer';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": true", + "name: 'myAnchorCounterProgram';", + "writable: true;", + "signer: true;", "},", "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", + "name: 'systemProgram';", + "address: '11111111111111111111111111111111';", "}", - "],", - ""args": []", + "];", + "args: [];", "},", "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", + "name: 'set';", + "discriminator: [198, 51, 53, 241, 116, 29, 126, 194];", + "accounts: [", "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", + "name: 'myAnchorCounterProgram';", + "writable: true;", "}", - "],", - ""accounts": [", - "{", - ""name": "myAnchorCounterProgram",", - ""type": {", - ""kind": "struct",", - ""fields": [", + "];", + "args: [", "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'value';", + "type: 'u8';", "}", + "];", "}", - "]", - "};", - "export const IDL: MyAnchorCounterProgram = {", - ""version": "0.1.0",", - ""name": "my_anchor_counter_program",", - ""instructions": [", - "{", - ""name": "close",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", + "];", + "accounts: [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", + "name: 'myAnchorCounterProgram';", + "discriminator: [135, 64, 223, 168, 233, 143, 162, 215];", "}", - "],", - ""args": []", - "},", + "];", + "types: [", "{", - ""name": "decrement",", - ""accounts": [", + "name: 'myAnchorCounterProgram';", + "type: {", + "kind: 'struct';", + "fields: [", "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "increment",", - ""accounts": [", - "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "initialize",", - ""accounts": [", - "{", - ""name": "payer",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": true", - "},", - "{", - ""name": "systemProgram",", - ""isMut": false,", - ""isSigner": false", - "}", - "],", - ""args": []", - "},", - "{", - ""name": "set",", - ""accounts": [", - "{", - ""name": "myAnchorCounterProgram",", - ""isMut": true,", - ""isSigner": false", - "}", - "],", - ""args": [", - "{", - ""name": "value",", - ""type": "u8"", - "}", - "]", - "}", - "],", - ""accounts": [", - "{", - ""name": "myAnchorCounterProgram",", - ""type": {", - ""kind": "struct",", - ""fields": [", - "{", - ""name": "count",", - ""type": "u8"", - "}", - "]", + "name: 'count';", + "type: 'u8';", "}", + "];", + "};", "}", - "]", + "];", "};", ], "isBinary": false, @@ -4900,12 +4899,19 @@ exports[`react-feature generator should generate files for anchor-counter featur ""compilerOptions": {", ""outDir": "../dist/out-tsc",", ""declaration": true,", - ""types": ["node"]", + ""types": [", + ""node"", + "],", + ""resolveJsonModule": true,", + ""allowSyntheticDefaultImports": true", "},", - ""include": ["src/**/*.ts"],", + ""include": [", + ""src/**/*.ts"", + "],", ""exclude": [", ""jest.config.ts",", - ""src/**/*.spec.ts", "src/**/*.test.ts"", + ""src/**/*.spec.ts",", + ""src/**/*.test.ts"", "]", "}", ], @@ -5030,7 +5036,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "{", ""name": "@proj/source",", ""dependencies": {", - ""@coral-xyz/anchor": "^0.29.0",", + ""@coral-xyz/anchor": "^0.30.0",", ""@solana/spl-token": "0.4.1",", ""@solana/wallet-adapter-base": "^0.9.23",", ""@solana/wallet-adapter-react": "^0.15.35",", @@ -6237,7 +6243,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "children": { "counter-data-access.tsx": { "content": [ - "import { CounterIDL, getCounterProgramId } from '@proj/anchor'", + "import { getCounterProgram, getCounterProgramId } from '@proj/anchor'", "import { Program } from '@coral-xyz/anchor';", "import { useConnection } from '@solana/wallet-adapter-react';", "import { Cluster, Keypair, PublicKey } from '@solana/web3.js';", @@ -6256,7 +6262,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "() => getCounterProgramId(cluster.network as Cluster),", "[cluster]", ");", - "const program = new Program(CounterIDL, programId, provider)", + "const program = getCounterProgram(provider)", "const accounts = useQuery({", "queryKey: ['counter', 'all', { cluster }],", "queryFn: () => program.account.counter.all(),", @@ -6541,7 +6547,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "children": { "my-anchor-counter-program-data-access.tsx": { "content": [ - "import { MyAnchorCounterProgramIDL, getMyAnchorCounterProgramProgramId } from '@proj/anchor'", + "import { getMyAnchorCounterProgramProgram, getMyAnchorCounterProgramProgramId } from '@proj/anchor'", "import { Program } from '@coral-xyz/anchor';", "import { useConnection } from '@solana/wallet-adapter-react';", "import { Cluster, Keypair, PublicKey } from '@solana/web3.js';", @@ -6560,7 +6566,7 @@ exports[`react-feature generator should generate files for anchor-counter featur "() => getMyAnchorCounterProgramProgramId(cluster.network as Cluster),", "[cluster]", ");", - "const program = new Program(MyAnchorCounterProgramIDL, programId, provider)", + "const program = getMyAnchorCounterProgramProgram(provider)", "const accounts = useQuery({", "queryKey: ['my-anchor-counter-program', 'all', { cluster }],", "queryFn: () => program.account.myAnchorCounterProgram.all(),", diff --git a/packages/preset-react/src/generators/react-feature/files/anchor-basic/__fileName__-data-access.tsx.template b/packages/preset-react/src/generators/react-feature/files/anchor-basic/__fileName__-data-access.tsx.template index bb97ace0..77a7d8bd 100644 --- a/packages/preset-react/src/generators/react-feature/files/anchor-basic/__fileName__-data-access.tsx.template +++ b/packages/preset-react/src/generators/react-feature/files/anchor-basic/__fileName__-data-access.tsx.template @@ -2,7 +2,7 @@ 'use client'; <% } %> -import { programId, <%= className %>IDL } from '@<%= npmScope %>/anchor'; +import { programId, get<%= className %>Program } from '@<%= npmScope %>/anchor'; import { Program } from '@coral-xyz/anchor'; import { useConnection } from '@solana/wallet-adapter-react'; import { Keypair } from '@solana/web3.js'; @@ -17,7 +17,7 @@ export function use<%= className %>Program() { const { cluster } = useCluster(); const transactionToast = useTransactionToast(); const provider = useAnchorProvider(); - const program = new Program(<%= className %>IDL, programId, provider); + const program = get<%= className %>Program(provider); const getProgramAccount = useQuery({ queryKey: ['get-program-account', { cluster }], diff --git a/packages/preset-react/src/generators/react-feature/files/anchor-counter/__fileName__-data-access.tsx.template b/packages/preset-react/src/generators/react-feature/files/anchor-counter/__fileName__-data-access.tsx.template index 6e3e03dd..6f5e729d 100644 --- a/packages/preset-react/src/generators/react-feature/files/anchor-counter/__fileName__-data-access.tsx.template +++ b/packages/preset-react/src/generators/react-feature/files/anchor-counter/__fileName__-data-access.tsx.template @@ -2,7 +2,7 @@ 'use client'; <% } %> -import { <%= className %>IDL, get<%= className %>ProgramId } from '@<%= npmScope %>/anchor' +import { get<%= className %>Program, get<%= className %>ProgramId } from '@<%= npmScope %>/anchor' import { Program } from '@coral-xyz/anchor'; import { useConnection } from '@solana/wallet-adapter-react'; import { Cluster, Keypair, PublicKey } from '@solana/web3.js'; @@ -22,7 +22,7 @@ export function use<%= className %>Program() { () => get<%= className %>ProgramId(cluster.network as Cluster), [cluster] ); - const program = new Program(<%= className %>IDL, programId, provider) + const program = get<%= className %>Program(provider) const accounts = useQuery({ queryKey: ['<%= fileName %>', 'all', { cluster }],