From 9b6b55753d793e11cbce5a5dcc2c5084dd32ee1e Mon Sep 17 00:00:00 2001 From: acheron Date: Tue, 14 Jan 2025 18:09:13 +0100 Subject: [PATCH 1/3] idl: Support PDA resolution of call expressions that don't have any arguments --- lang/syn/src/idl/accounts.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lang/syn/src/idl/accounts.rs b/lang/syn/src/idl/accounts.rs index 3d0051ffbf..56d85618bc 100644 --- a/lang/syn/src/idl/accounts.rs +++ b/lang/syn/src/idl/accounts.rs @@ -342,6 +342,14 @@ fn parse_seed(seed: &syn::Expr, accounts: &AccountsStruct) -> Result Ok(quote! { + #idl::IdlSeed::Const( + #idl::IdlSeedConst { + value: AsRef::<[u8]>::as_ref(&#seed).into(), + } + ) + }), syn::Expr::Path(path) => { let seed = path .path From 2797df6134349dbbee5cfc5f70d6e11554eb4568 Mon Sep 17 00:00:00 2001 From: acheron Date: Tue, 14 Jan 2025 20:27:10 +0100 Subject: [PATCH 2/3] tests: Add a test case --- .../programs/pda-derivation/src/lib.rs | 14 ++++++++++++++ tests/pda-derivation/tests/typescript.spec.ts | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/tests/pda-derivation/programs/pda-derivation/src/lib.rs b/tests/pda-derivation/programs/pda-derivation/src/lib.rs index 5b2a4bd6f5..f2a5352c63 100644 --- a/tests/pda-derivation/programs/pda-derivation/src/lib.rs +++ b/tests/pda-derivation/programs/pda-derivation/src/lib.rs @@ -59,6 +59,10 @@ pub mod pda_derivation { pub fn unsupported_program_seed(_ctx: Context) -> Result<()> { Ok(()) } + + pub fn call_expr_with_no_args(_ctx: Context) -> Result<()> { + Ok(()) + } } #[derive(Accounts)] @@ -210,6 +214,16 @@ fn external_function_with_an_argument(pk: &Pubkey) -> Pubkey { *pk } +#[derive(Accounts)] +pub struct CallExprWithNoArgs<'info> { + #[account( + seeds = [System::id().as_ref()], + seeds::program = System::id(), + bump + )] + pub pda: UncheckedAccount<'info>, +} + #[account] pub struct MyAccount { data: u64, diff --git a/tests/pda-derivation/tests/typescript.spec.ts b/tests/pda-derivation/tests/typescript.spec.ts index 8c4059d3e7..203b270b23 100644 --- a/tests/pda-derivation/tests/typescript.spec.ts +++ b/tests/pda-derivation/tests/typescript.spec.ts @@ -142,4 +142,8 @@ describe("typescript", () => { // @ts-expect-error expect(acc.pda).to.be.undefined; }); + + it("Can resolve call expressions with no arguments", async () => { + await program.methods.callExprWithNoArgs().rpc(); + }); }); From 536486cfe9646cbd3ceb740448bf52a5f4136212 Mon Sep 17 00:00:00 2001 From: acheron Date: Thu, 16 Jan 2025 19:59:26 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b32cb5e5..6e02b09c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ The minor version will be incremented upon a breaking change and the patch versi - idl: Disallow account discriminators that can conflict with the `zero` constraint ([#3365](https://github.com/coral-xyz/anchor/pull/3365)). - cli: Include recommended solana args by default and add new `--max-retries` option to the `deploy` command ([#3354](https://github.com/coral-xyz/anchor/pull/3354)). - avm: Make installation download binaries by default ([#3445](https://github.com/coral-xyz/anchor/pull/3445)). +- idl: Support PDA resolution of call expressions that don't have any arguments ([#3485](https://github.com/coral-xyz/anchor/pull/3485)). ### Fixes