/** * 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 { combineCodec, 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 ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core'; import { LOADER_V3_PROGRAM_ADDRESS } from '../programs'; export const DEPLOY_WITH_MAX_DATA_LEN_DISCRIMINATOR = 2; export function getDeployWithMaxDataLenDiscriminatorBytes(): ReadonlyUint8Array { return getU32Encoder().encode(DEPLOY_WITH_MAX_DATA_LEN_DISCRIMINATOR); } export type DeployWithMaxDataLenInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountPayerAccount extends string | AccountMeta = string, TAccountProgramDataAccount extends string | AccountMeta = string, TAccountProgramAccount extends string | AccountMeta = string, TAccountBufferAccount extends string | AccountMeta = string, TAccountRentSysvar extends string | AccountMeta = 'SysvarRent111111111111111111111111111111111', TAccountClockSysvar extends string | AccountMeta = 'SysvarC1ock11111111111111111111111111111111', TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TAccountAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPayerAccount extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayerAccount, TAccountProgramDataAccount extends string ? WritableAccount : TAccountProgramDataAccount, TAccountProgramAccount extends string ? WritableAccount : TAccountProgramAccount, TAccountBufferAccount extends string ? WritableAccount : TAccountBufferAccount, TAccountRentSysvar extends string ? ReadonlyAccount : TAccountRentSysvar, TAccountClockSysvar extends string ? ReadonlyAccount : TAccountClockSysvar, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAuthority, ...TRemainingAccounts, ] >; export type DeployWithMaxDataLenInstructionData = { discriminator: number; maxDataLen: bigint }; export type DeployWithMaxDataLenInstructionDataArgs = { maxDataLen: number | bigint }; export function getDeployWithMaxDataLenInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', getU32Encoder()], ['maxDataLen', getU64Encoder()], ]), value => ({ ...value, discriminator: DEPLOY_WITH_MAX_DATA_LEN_DISCRIMINATOR }), ); } export function getDeployWithMaxDataLenInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', getU32Decoder()], ['maxDataLen', getU64Decoder()], ]); } export function getDeployWithMaxDataLenInstructionDataCodec(): FixedSizeCodec< DeployWithMaxDataLenInstructionDataArgs, DeployWithMaxDataLenInstructionData > { return combineCodec( getDeployWithMaxDataLenInstructionDataEncoder(), getDeployWithMaxDataLenInstructionDataDecoder(), ); } export type DeployWithMaxDataLenInput< TAccountPayerAccount extends string = string, TAccountProgramDataAccount extends string = string, TAccountProgramAccount extends string = string, TAccountBufferAccount extends string = string, TAccountRentSysvar extends string = string, TAccountClockSysvar extends string = string, TAccountSystemProgram extends string = string, TAccountAuthority extends string = string, > = { /** Payer account that will pay to create the ProgramData account. */ payerAccount: TransactionSigner; /** ProgramData account (uninitialized). */ programDataAccount: Address; /** Program account (uninitialized). */ programAccount: Address; /** Buffer account where the program data has been written. */ bufferAccount: Address; /** Rent sysvar. */ rentSysvar?: Address; /** Clock sysvar. */ clockSysvar?: Address; /** System program. */ systemProgram?: Address; /** Authority. */ authority: TransactionSigner; maxDataLen: DeployWithMaxDataLenInstructionDataArgs['maxDataLen']; }; export function getDeployWithMaxDataLenInstruction< TAccountPayerAccount extends string, TAccountProgramDataAccount extends string, TAccountProgramAccount extends string, TAccountBufferAccount extends string, TAccountRentSysvar extends string, TAccountClockSysvar extends string, TAccountSystemProgram extends string, TAccountAuthority extends string, TProgramAddress extends Address = typeof LOADER_V3_PROGRAM_ADDRESS, >( input: DeployWithMaxDataLenInput< TAccountPayerAccount, TAccountProgramDataAccount, TAccountProgramAccount, TAccountBufferAccount, TAccountRentSysvar, TAccountClockSysvar, TAccountSystemProgram, TAccountAuthority >, config?: { programAddress?: TProgramAddress }, ): DeployWithMaxDataLenInstruction< TProgramAddress, TAccountPayerAccount, TAccountProgramDataAccount, TAccountProgramAccount, TAccountBufferAccount, TAccountRentSysvar, TAccountClockSysvar, TAccountSystemProgram, TAccountAuthority > { // Program address. const programAddress = config?.programAddress ?? LOADER_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payerAccount: { value: input.payerAccount ?? null, isWritable: true }, programDataAccount: { value: input.programDataAccount ?? null, isWritable: true }, programAccount: { value: input.programAccount ?? null, isWritable: true }, bufferAccount: { value: input.bufferAccount ?? null, isWritable: true }, rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.rentSysvar.value) { accounts.rentSysvar.value = 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } if (!accounts.clockSysvar.value) { accounts.clockSysvar.value = 'SysvarC1ock11111111111111111111111111111111' as Address<'SysvarC1ock11111111111111111111111111111111'>; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('payerAccount', accounts.payerAccount), getAccountMeta('programDataAccount', accounts.programDataAccount), getAccountMeta('programAccount', accounts.programAccount), getAccountMeta('bufferAccount', accounts.bufferAccount), getAccountMeta('rentSysvar', accounts.rentSysvar), getAccountMeta('clockSysvar', accounts.clockSysvar), getAccountMeta('systemProgram', accounts.systemProgram), getAccountMeta('authority', accounts.authority), ], data: getDeployWithMaxDataLenInstructionDataEncoder().encode(args as DeployWithMaxDataLenInstructionDataArgs), programAddress, } as DeployWithMaxDataLenInstruction< TProgramAddress, TAccountPayerAccount, TAccountProgramDataAccount, TAccountProgramAccount, TAccountBufferAccount, TAccountRentSysvar, TAccountClockSysvar, TAccountSystemProgram, TAccountAuthority >); } export type ParsedDeployWithMaxDataLenInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Payer account that will pay to create the ProgramData account. */ payerAccount: TAccountMetas[0]; /** ProgramData account (uninitialized). */ programDataAccount: TAccountMetas[1]; /** Program account (uninitialized). */ programAccount: TAccountMetas[2]; /** Buffer account where the program data has been written. */ bufferAccount: TAccountMetas[3]; /** Rent sysvar. */ rentSysvar: TAccountMetas[4]; /** Clock sysvar. */ clockSysvar: TAccountMetas[5]; /** System program. */ systemProgram: TAccountMetas[6]; /** Authority. */ authority: TAccountMetas[7]; }; data: DeployWithMaxDataLenInstructionData; }; export function parseDeployWithMaxDataLenInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedDeployWithMaxDataLenInstruction { if (instruction.accounts.length < 8) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { payerAccount: getNextAccount(), programDataAccount: getNextAccount(), programAccount: getNextAccount(), bufferAccount: getNextAccount(), rentSysvar: getNextAccount(), clockSysvar: getNextAccount(), systemProgram: getNextAccount(), authority: getNextAccount(), }, data: getDeployWithMaxDataLenInstructionDataDecoder().decode(instruction.data), }; }