diff --git a/clients/js/src/generated/instructions/createAccountAllowPrefund.ts b/clients/js/src/generated/instructions/createAccountAllowPrefund.ts new file mode 100644 index 0000000..481d7b4 --- /dev/null +++ b/clients/js/src/generated/instructions/createAccountAllowPrefund.ts @@ -0,0 +1,212 @@ +/** + * 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, + lamports: value.lamports ?? 0, + }), + ); +} + +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 56ae69f..61d9591 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 c0f20ba..5c0c946 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 &mut Self { + self.lamports = Some(lamports); + self + } + #[inline(always)] + pub fn space(&mut self, space: u64) -> &mut Self { + self.space = Some(space); + self + } + #[inline(always)] + pub fn program_address(&mut self, program_address: Address) -> &mut Self { + self.program_address = Some(program_address); + self + } + /// Add an additional account to the instruction. + #[inline(always)] + pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self { + self.__remaining_accounts.push(account); + self + } + /// Add additional accounts to the instruction. + #[inline(always)] + pub fn add_remaining_accounts( + &mut self, + accounts: &[solana_instruction::AccountMeta], + ) -> &mut Self { + self.__remaining_accounts.extend_from_slice(accounts); + self + } + #[allow(clippy::clone_on_copy)] + pub fn instruction(&self) -> solana_instruction::Instruction { + let accounts = CreateAccountAllowPrefund { + new_account: self.new_account.expect("new_account is not set"), + payer: self.payer, + }; + let args = CreateAccountAllowPrefundInstructionArgs { + lamports: self.lamports.clone().unwrap_or(0), + space: self.space.clone().expect("space is not set"), + program_address: self + .program_address + .clone() + .expect("program_address is not set"), + }; + + accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + } +} + +/// `create_account_allow_prefund` CPI accounts. +pub struct CreateAccountAllowPrefundCpiAccounts<'a, 'b> { + 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 + } + /// `[optional argument, defaults to '0']` + #[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().unwrap_or(0), + 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 85422fd..b56f71f 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 44b5c48..2a5c3c6 100644 --- a/idl.json +++ b/idl.json @@ -922,6 +922,88 @@ "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": [], + "defaultValue": { "kind": "numberValueNode", "number": 0 }, + "defaultValueStrategy": "optional" + }, + { + "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": [