From 5c9be838544483e2d2dcaf6bf8129f6b721a73bc Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Fri, 29 May 2026 08:58:15 +0100 Subject: [PATCH 1/2] Add CreateAccountAllowPrefund instruction (SIMD-0312) Adds the new System Program instruction CreateAccountAllowPrefund (discriminator 13) per [SIMD-0312](https://github.com/solana-foundation/solana-improvement-documents/blob/main/proposals/0312-create-account-allow-prefund.md), which allows account creation when the new account already holds lamports. The payer account is optional and only required when lamports > 0. --- .../instructions/createAccountAllowPrefund.ts | 208 +++++++++ .../js/src/generated/instructions/index.ts | 1 + clients/js/src/generated/programs/system.ts | 25 +- .../create_account_allow_prefund.rs | 397 ++++++++++++++++++ .../rust/src/generated/instructions/mod.rs | 2 + idl.json | 80 ++++ 6 files changed, 712 insertions(+), 1 deletion(-) create mode 100644 clients/js/src/generated/instructions/createAccountAllowPrefund.ts create mode 100644 clients/rust/src/generated/instructions/create_account_allow_prefund.rs diff --git a/clients/js/src/generated/instructions/createAccountAllowPrefund.ts b/clients/js/src/generated/instructions/createAccountAllowPrefund.ts new file mode 100644 index 00000000..46f9e663 --- /dev/null +++ b/clients/js/src/generated/instructions/createAccountAllowPrefund.ts @@ -0,0 +1,208 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + BASE_ACCOUNT_SIZE, + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableSignerAccount, +} from '@solana/kit'; +import { + getAccountMetaFactory, + type InstructionWithByteDelta, + type ResolvedInstructionAccount, +} from '@solana/kit/program-client-core'; +import { SYSTEM_PROGRAM_ADDRESS } from '../programs'; + +export const CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR = 13; + +export function getCreateAccountAllowPrefundDiscriminatorBytes(): ReadonlyUint8Array { + return getU32Encoder().encode(CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR); +} + +export type CreateAccountAllowPrefundInstruction< + TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS, + TAccountNewAccount extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta | undefined = undefined, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountNewAccount extends string + ? WritableSignerAccount & AccountSignerMeta + : TAccountNewAccount, + ...(TAccountPayer extends undefined + ? [] + : [ + TAccountPayer extends string + ? WritableSignerAccount & AccountSignerMeta + : TAccountPayer, + ]), + ...TRemainingAccounts, + ] + >; + +export type CreateAccountAllowPrefundInstructionData = { + discriminator: number; + lamports: bigint; + space: bigint; + programAddress: Address; +}; + +export type CreateAccountAllowPrefundInstructionDataArgs = { + lamports: number | bigint; + space: number | bigint; + programAddress: Address; +}; + +export function getCreateAccountAllowPrefundInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU32Encoder()], + ['lamports', getU64Encoder()], + ['space', getU64Encoder()], + ['programAddress', getAddressEncoder()], + ]), + value => ({ ...value, discriminator: CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR }), + ); +} + +export function getCreateAccountAllowPrefundInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU32Decoder()], + ['lamports', getU64Decoder()], + ['space', getU64Decoder()], + ['programAddress', getAddressDecoder()], + ]); +} + +export function getCreateAccountAllowPrefundInstructionDataCodec(): FixedSizeCodec< + CreateAccountAllowPrefundInstructionDataArgs, + CreateAccountAllowPrefundInstructionData +> { + return combineCodec( + getCreateAccountAllowPrefundInstructionDataEncoder(), + getCreateAccountAllowPrefundInstructionDataDecoder(), + ); +} + +export type CreateAccountAllowPrefundInput< + TAccountNewAccount extends string = string, + TAccountPayer extends string = string, +> = { + newAccount: TransactionSigner; + payer?: TransactionSigner; + lamports: CreateAccountAllowPrefundInstructionDataArgs['lamports']; + space: CreateAccountAllowPrefundInstructionDataArgs['space']; + programAddress: CreateAccountAllowPrefundInstructionDataArgs['programAddress']; +}; + +export function getCreateAccountAllowPrefundInstruction< + TAccountNewAccount extends string, + TAccountPayer extends string, + TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS, +>( + input: CreateAccountAllowPrefundInput, + config?: { programAddress?: TProgramAddress }, +): CreateAccountAllowPrefundInstruction & InstructionWithByteDelta { + // Program address. + const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + newAccount: { value: input.newAccount ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record; + + // Original args. + const args = { ...input }; + + // Bytes created or reallocated by the instruction. + const byteDelta: number = [Number(args.space) + BASE_ACCOUNT_SIZE].reduce((a, b) => a + b, 0); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted'); + return Object.freeze({ + accounts: [getAccountMeta('newAccount', accounts.newAccount), getAccountMeta('payer', accounts.payer)].filter( + (x: T | undefined): x is T => x !== undefined, + ), + byteDelta, + data: getCreateAccountAllowPrefundInstructionDataEncoder().encode( + args as CreateAccountAllowPrefundInstructionDataArgs, + ), + programAddress, + } as CreateAccountAllowPrefundInstruction & + InstructionWithByteDelta); +} + +export type ParsedCreateAccountAllowPrefundInstruction< + TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + newAccount: TAccountMetas[0]; + payer?: TAccountMetas[1] | undefined; + }; + data: CreateAccountAllowPrefundInstructionData; +}; + +export function parseCreateAccountAllowPrefundInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateAccountAllowPrefundInstruction { + if (instruction.accounts.length < 1) { + throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 1, + }); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + let optionalAccountsRemaining = instruction.accounts.length - 1; + const getNextOptionalAccount = () => { + if (optionalAccountsRemaining === 0) return undefined; + optionalAccountsRemaining -= 1; + return getNextAccount(); + }; + return { + programAddress: instruction.programAddress, + accounts: { newAccount: getNextAccount(), payer: getNextOptionalAccount() }, + data: getCreateAccountAllowPrefundInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index 56ae69fe..61d9591d 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -13,6 +13,7 @@ export * from './assign'; export * from './assignWithSeed'; export * from './authorizeNonceAccount'; export * from './createAccount'; +export * from './createAccountAllowPrefund'; export * from './createAccountWithSeed'; export * from './initializeNonceAccount'; export * from './transferSol'; diff --git a/clients/js/src/generated/programs/system.ts b/clients/js/src/generated/programs/system.ts index c0f20ba7..5c0c9464 100644 --- a/clients/js/src/generated/programs/system.ts +++ b/clients/js/src/generated/programs/system.ts @@ -39,6 +39,7 @@ import { getAssignInstruction, getAssignWithSeedInstruction, getAuthorizeNonceAccountInstruction, + getCreateAccountAllowPrefundInstruction, getCreateAccountInstruction, getCreateAccountWithSeedInstruction, getInitializeNonceAccountInstruction, @@ -52,6 +53,7 @@ import { parseAssignInstruction, parseAssignWithSeedInstruction, parseAuthorizeNonceAccountInstruction, + parseCreateAccountAllowPrefundInstruction, parseCreateAccountInstruction, parseCreateAccountWithSeedInstruction, parseInitializeNonceAccountInstruction, @@ -65,6 +67,7 @@ import { type AssignInput, type AssignWithSeedInput, type AuthorizeNonceAccountInput, + type CreateAccountAllowPrefundInput, type CreateAccountInput, type CreateAccountWithSeedInput, type InitializeNonceAccountInput, @@ -74,6 +77,7 @@ import { type ParsedAssignInstruction, type ParsedAssignWithSeedInstruction, type ParsedAuthorizeNonceAccountInstruction, + type ParsedCreateAccountAllowPrefundInstruction, type ParsedCreateAccountInstruction, type ParsedCreateAccountWithSeedInstruction, type ParsedInitializeNonceAccountInstruction, @@ -107,6 +111,7 @@ export enum SystemInstruction { AssignWithSeed, TransferSolWithSeed, UpgradeNonceAccount, + CreateAccountAllowPrefund, } export function identifySystemInstruction( @@ -152,6 +157,9 @@ export function identifySystemInstruction( if (containsBytes(data, getU32Encoder().encode(12), 0)) { return SystemInstruction.UpgradeNonceAccount; } + if (containsBytes(data, getU32Encoder().encode(13), 0)) { + return SystemInstruction.CreateAccountAllowPrefund; + } throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: 'system', @@ -173,7 +181,10 @@ export type ParsedSystemInstruction { + pub new_account: &'b solana_account_info::AccountInfo<'a>, + + pub payer: Option<&'b solana_account_info::AccountInfo<'a>>, +} + +/// `create_account_allow_prefund` CPI instruction. +pub struct CreateAccountAllowPrefundCpi<'a, 'b> { + /// The program to invoke. + pub __program: &'b solana_account_info::AccountInfo<'a>, + + pub new_account: &'b solana_account_info::AccountInfo<'a>, + + pub payer: Option<&'b solana_account_info::AccountInfo<'a>>, + /// The arguments for the instruction. + pub __args: CreateAccountAllowPrefundInstructionArgs, +} + +impl<'a, 'b> CreateAccountAllowPrefundCpi<'a, 'b> { + pub fn new( + program: &'b solana_account_info::AccountInfo<'a>, + accounts: CreateAccountAllowPrefundCpiAccounts<'a, 'b>, + args: CreateAccountAllowPrefundInstructionArgs, + ) -> Self { + Self { + __program: program, + new_account: accounts.new_account, + payer: accounts.payer, + __args: args, + } + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], &[]) + } + #[inline(always)] + pub fn invoke_with_remaining_accounts( + &self, + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) + } + #[inline(always)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) + } + #[allow(clippy::arithmetic_side_effects)] + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed_with_remaining_accounts( + &self, + signers_seeds: &[&[&[u8]]], + remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> solana_program_error::ProgramResult { + let mut accounts = Vec::with_capacity(2 + remaining_accounts.len()); + accounts.push(solana_instruction::AccountMeta::new( + *self.new_account.key, + true, + )); + if let Some(payer) = self.payer { + accounts.push(solana_instruction::AccountMeta::new(*payer.key, true)); + } + remaining_accounts.iter().for_each(|remaining_account| { + accounts.push(solana_instruction::AccountMeta { + pubkey: *remaining_account.0.key, + is_signer: remaining_account.1, + is_writable: remaining_account.2, + }) + }); + let mut data = CreateAccountAllowPrefundInstructionData::new() + .try_to_vec() + .unwrap(); + let mut args = self.__args.try_to_vec().unwrap(); + data.append(&mut args); + + let instruction = solana_instruction::Instruction { + program_id: crate::SYSTEM_ID, + accounts, + data, + }; + let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len()); + account_infos.push(self.__program.clone()); + account_infos.push(self.new_account.clone()); + if let Some(payer) = self.payer { + account_infos.push(payer.clone()); + } + remaining_accounts + .iter() + .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); + + if signers_seeds.is_empty() { + solana_cpi::invoke(&instruction, &account_infos) + } else { + solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds) + } + } +} + +/// Instruction builder for `CreateAccountAllowPrefund` via CPI. +/// +/// ### Accounts: +/// +/// 0. `[writable, signer]` new_account +/// 1. `[writable, signer, optional]` payer +#[derive(Clone, Debug)] +pub struct CreateAccountAllowPrefundCpiBuilder<'a, 'b> { + instruction: Box>, +} + +impl<'a, 'b> CreateAccountAllowPrefundCpiBuilder<'a, 'b> { + pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self { + let instruction = Box::new(CreateAccountAllowPrefundCpiBuilderInstruction { + __program: program, + new_account: None, + payer: None, + lamports: None, + space: None, + program_address: None, + __remaining_accounts: Vec::new(), + }); + Self { instruction } + } + #[inline(always)] + pub fn new_account( + &mut self, + new_account: &'b solana_account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.new_account = Some(new_account); + self + } + /// `[optional account]` + #[inline(always)] + pub fn payer(&mut self, payer: Option<&'b solana_account_info::AccountInfo<'a>>) -> &mut Self { + self.instruction.payer = payer; + self + } + #[inline(always)] + pub fn lamports(&mut self, lamports: u64) -> &mut Self { + self.instruction.lamports = Some(lamports); + self + } + #[inline(always)] + pub fn space(&mut self, space: u64) -> &mut Self { + self.instruction.space = Some(space); + self + } + #[inline(always)] + pub fn program_address(&mut self, program_address: Address) -> &mut Self { + self.instruction.program_address = Some(program_address); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account( + &mut self, + account: &'b solana_account_info::AccountInfo<'a>, + is_writable: bool, + is_signer: bool, + ) -> &mut Self { + self.instruction + .__remaining_accounts + .push((account, is_writable, is_signer)); + self + } + /// Add additional accounts to the instruction. + /// + /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, + /// and a `bool` indicating whether the account is a signer or not. + #[inline(always)] + pub fn add_remaining_accounts( + &mut self, + accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)], + ) -> &mut Self { + self.instruction + .__remaining_accounts + .extend_from_slice(accounts); + self + } + #[inline(always)] + pub fn invoke(&self) -> solana_program_error::ProgramResult { + self.invoke_signed(&[]) + } + #[allow(clippy::clone_on_copy)] + #[allow(clippy::vec_init_then_push)] + pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { + let args = CreateAccountAllowPrefundInstructionArgs { + lamports: self + .instruction + .lamports + .clone() + .expect("lamports is not set"), + space: self.instruction.space.clone().expect("space is not set"), + program_address: self + .instruction + .program_address + .clone() + .expect("program_address is not set"), + }; + let instruction = CreateAccountAllowPrefundCpi { + __program: self.instruction.__program, + + new_account: self + .instruction + .new_account + .expect("new_account is not set"), + + payer: self.instruction.payer, + __args: args, + }; + instruction.invoke_signed_with_remaining_accounts( + signers_seeds, + &self.instruction.__remaining_accounts, + ) + } +} + +#[derive(Clone, Debug)] +struct CreateAccountAllowPrefundCpiBuilderInstruction<'a, 'b> { + __program: &'b solana_account_info::AccountInfo<'a>, + new_account: Option<&'b solana_account_info::AccountInfo<'a>>, + payer: Option<&'b solana_account_info::AccountInfo<'a>>, + lamports: Option, + space: Option, + program_address: Option
, + /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. + __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>, +} diff --git a/clients/rust/src/generated/instructions/mod.rs b/clients/rust/src/generated/instructions/mod.rs index 85422fdd..b56f71f5 100644 --- a/clients/rust/src/generated/instructions/mod.rs +++ b/clients/rust/src/generated/instructions/mod.rs @@ -12,6 +12,7 @@ pub(crate) mod r#assign; pub(crate) mod r#assign_with_seed; pub(crate) mod r#authorize_nonce_account; pub(crate) mod r#create_account; +pub(crate) mod r#create_account_allow_prefund; pub(crate) mod r#create_account_with_seed; pub(crate) mod r#initialize_nonce_account; pub(crate) mod r#transfer_sol; @@ -26,6 +27,7 @@ pub use self::r#assign::*; pub use self::r#assign_with_seed::*; pub use self::r#authorize_nonce_account::*; pub use self::r#create_account::*; +pub use self::r#create_account_allow_prefund::*; pub use self::r#create_account_with_seed::*; pub use self::r#initialize_nonce_account::*; pub use self::r#transfer_sol::*; diff --git a/idl.json b/idl.json index 44b5c487..2da5a0b2 100644 --- a/idl.json +++ b/idl.json @@ -922,6 +922,86 @@ "idlName": "UpgradeNonceAccount", "docs": [], "optionalAccountStrategy": "omitted" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "newAccount", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "payer", + "isWritable": true, + "isSigner": true, + "isOptional": true, + "docs": [], + "defaultValue": { "kind": "payerValueNode" } + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 13 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "lamports", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "space", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "programAddress", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "byteDeltas": [ + { + "kind": "instructionByteDeltaNode", + "value": { "kind": "argumentValueNode", "name": "space" }, + "withHeader": true + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "createAccountAllowPrefund", + "idlName": "CreateAccountAllowPrefund", + "docs": [], + "optionalAccountStrategy": "omitted" } ], "definedTypes": [ From c1dcfcfe214bd6604a97c6c5b47b97d9d1782201 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Fri, 29 May 2026 12:00:33 +0100 Subject: [PATCH 2/2] Make lamports optional in CreateAccountAllowPrefund --- .../instructions/createAccountAllowPrefund.ts | 10 +++++++--- .../instructions/create_account_allow_prefund.rs | 10 ++++------ idl.json | 4 +++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/clients/js/src/generated/instructions/createAccountAllowPrefund.ts b/clients/js/src/generated/instructions/createAccountAllowPrefund.ts index 46f9e663..481d7b41 100644 --- a/clients/js/src/generated/instructions/createAccountAllowPrefund.ts +++ b/clients/js/src/generated/instructions/createAccountAllowPrefund.ts @@ -77,7 +77,7 @@ export type CreateAccountAllowPrefundInstructionData = { }; export type CreateAccountAllowPrefundInstructionDataArgs = { - lamports: number | bigint; + lamports?: number | bigint; space: number | bigint; programAddress: Address; }; @@ -90,7 +90,11 @@ export function getCreateAccountAllowPrefundInstructionDataEncoder(): FixedSizeE ['space', getU64Encoder()], ['programAddress', getAddressEncoder()], ]), - value => ({ ...value, discriminator: CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR }), + value => ({ + ...value, + discriminator: CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR, + lamports: value.lamports ?? 0, + }), ); } @@ -119,7 +123,7 @@ export type CreateAccountAllowPrefundInput< > = { newAccount: TransactionSigner; payer?: TransactionSigner; - lamports: CreateAccountAllowPrefundInstructionDataArgs['lamports']; + lamports?: CreateAccountAllowPrefundInstructionDataArgs['lamports']; space: CreateAccountAllowPrefundInstructionDataArgs['space']; programAddress: CreateAccountAllowPrefundInstructionDataArgs['programAddress']; }; diff --git a/clients/rust/src/generated/instructions/create_account_allow_prefund.rs b/clients/rust/src/generated/instructions/create_account_allow_prefund.rs index 29adfa73..c3b21111 100644 --- a/clients/rust/src/generated/instructions/create_account_allow_prefund.rs +++ b/clients/rust/src/generated/instructions/create_account_allow_prefund.rs @@ -118,6 +118,7 @@ impl CreateAccountAllowPrefundBuilder { self.payer = payer; self } + /// `[optional argument, defaults to '0']` #[inline(always)] pub fn lamports(&mut self, lamports: u64) -> &mut Self { self.lamports = Some(lamports); @@ -155,7 +156,7 @@ impl CreateAccountAllowPrefundBuilder { payer: self.payer, }; let args = CreateAccountAllowPrefundInstructionArgs { - lamports: self.lamports.clone().expect("lamports is not set"), + lamports: self.lamports.clone().unwrap_or(0), space: self.space.clone().expect("space is not set"), program_address: self .program_address @@ -304,6 +305,7 @@ impl<'a, 'b> CreateAccountAllowPrefundCpiBuilder<'a, 'b> { self.instruction.payer = payer; self } + /// `[optional argument, defaults to '0']` #[inline(always)] pub fn lamports(&mut self, lamports: u64) -> &mut Self { self.instruction.lamports = Some(lamports); @@ -354,11 +356,7 @@ impl<'a, 'b> CreateAccountAllowPrefundCpiBuilder<'a, 'b> { #[allow(clippy::vec_init_then_push)] pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult { let args = CreateAccountAllowPrefundInstructionArgs { - lamports: self - .instruction - .lamports - .clone() - .expect("lamports is not set"), + lamports: self.instruction.lamports.clone().unwrap_or(0), space: self.instruction.space.clone().expect("space is not set"), program_address: self .instruction diff --git a/idl.json b/idl.json index 2da5a0b2..2a5c3c6c 100644 --- a/idl.json +++ b/idl.json @@ -965,7 +965,9 @@ "format": "u64", "endian": "le" }, - "docs": [] + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 0 }, + "defaultValueStrategy": "optional" }, { "kind": "instructionArgumentNode",