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..f9f16f34 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", @@ -490,7 +494,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 +733,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 +765,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 +929,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) {", @@ -1400,7 +1410,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..865b9c73 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) {", @@ -1209,8 +1221,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 +1270,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", @@ -1431,8 +1449,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 +1543,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) {", 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/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-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/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..32b0e0d9 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 @@ -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) {", @@ -2703,7 +2707,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 +2823,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",", @@ -4703,7 +4709,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 +4741,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 +4905,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) {", @@ -5376,7 +5386,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 +5502,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 +6874,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 +6893,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..6964bf82 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 @@ -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) {", @@ -1753,7 +1757,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 +1877,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",", @@ -2802,7 +2808,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 +2840,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 +3004,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) {", @@ -3475,7 +3485,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 +3605,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 +4977,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 +4996,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..06c1fc15 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 @@ -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", @@ -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),", @@ -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) {", @@ -4900,12 +4931,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 +5068,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 +6275,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 +6294,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 +6579,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 +6598,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 }],