/** * 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, 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, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core'; import { LOADER_V3_PROGRAM_ADDRESS } from '../programs'; export const UPGRADE_DISCRIMINATOR = 3; export function getUpgradeDiscriminatorBytes(): ReadonlyUint8Array { return getU32Encoder().encode(UPGRADE_DISCRIMINATOR); } export type UpgradeInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountProgramDataAccount extends string | AccountMeta = string, TAccountProgramAccount extends string | AccountMeta = string, TAccountBufferAccount extends string | AccountMeta = string, TAccountSpillAccount extends string | AccountMeta = string, TAccountRentSysvar extends string | AccountMeta = 'SysvarRent111111111111111111111111111111111', TAccountClockSysvar extends string | AccountMeta = 'SysvarC1ock11111111111111111111111111111111', TAccountAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountProgramDataAccount extends string ? WritableAccount : TAccountProgramDataAccount, TAccountProgramAccount extends string ? WritableAccount : TAccountProgramAccount, TAccountBufferAccount extends string ? WritableAccount : TAccountBufferAccount, TAccountSpillAccount extends string ? WritableAccount : TAccountSpillAccount, TAccountRentSysvar extends string ? ReadonlyAccount : TAccountRentSysvar, TAccountClockSysvar extends string ? ReadonlyAccount : TAccountClockSysvar, TAccountAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAuthority, ...TRemainingAccounts, ] >; export type UpgradeInstructionData = { discriminator: number }; export type UpgradeInstructionDataArgs = {}; export function getUpgradeInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU32Encoder()]]), value => ({ ...value, discriminator: UPGRADE_DISCRIMINATOR, })); } export function getUpgradeInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU32Decoder()]]); } export function getUpgradeInstructionDataCodec(): FixedSizeCodec { return combineCodec(getUpgradeInstructionDataEncoder(), getUpgradeInstructionDataDecoder()); } export type UpgradeInput< TAccountProgramDataAccount extends string = string, TAccountProgramAccount extends string = string, TAccountBufferAccount extends string = string, TAccountSpillAccount extends string = string, TAccountRentSysvar extends string = string, TAccountClockSysvar extends string = string, TAccountAuthority extends string = string, > = { /** ProgramData account. */ programDataAccount: Address; /** Program account. */ programAccount: Address; /** Buffer account where the new program data has been written. */ bufferAccount: Address; /** Spill account. */ spillAccount: Address; /** Rent sysvar. */ rentSysvar?: Address; /** Clock sysvar. */ clockSysvar?: Address; /** Authority. */ authority: TransactionSigner; }; export function getUpgradeInstruction< TAccountProgramDataAccount extends string, TAccountProgramAccount extends string, TAccountBufferAccount extends string, TAccountSpillAccount extends string, TAccountRentSysvar extends string, TAccountClockSysvar extends string, TAccountAuthority extends string, TProgramAddress extends Address = typeof LOADER_V3_PROGRAM_ADDRESS, >( input: UpgradeInput< TAccountProgramDataAccount, TAccountProgramAccount, TAccountBufferAccount, TAccountSpillAccount, TAccountRentSysvar, TAccountClockSysvar, TAccountAuthority >, config?: { programAddress?: TProgramAddress }, ): UpgradeInstruction< TProgramAddress, TAccountProgramDataAccount, TAccountProgramAccount, TAccountBufferAccount, TAccountSpillAccount, TAccountRentSysvar, TAccountClockSysvar, TAccountAuthority > { // Program address. const programAddress = config?.programAddress ?? LOADER_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { programDataAccount: { value: input.programDataAccount ?? null, isWritable: true }, programAccount: { value: input.programAccount ?? null, isWritable: true }, bufferAccount: { value: input.bufferAccount ?? null, isWritable: true }, spillAccount: { value: input.spillAccount ?? null, isWritable: true }, rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }, clockSysvar: { value: input.clockSysvar ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; // 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'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('programDataAccount', accounts.programDataAccount), getAccountMeta('programAccount', accounts.programAccount), getAccountMeta('bufferAccount', accounts.bufferAccount), getAccountMeta('spillAccount', accounts.spillAccount), getAccountMeta('rentSysvar', accounts.rentSysvar), getAccountMeta('clockSysvar', accounts.clockSysvar), getAccountMeta('authority', accounts.authority), ], data: getUpgradeInstructionDataEncoder().encode({}), programAddress, } as UpgradeInstruction< TProgramAddress, TAccountProgramDataAccount, TAccountProgramAccount, TAccountBufferAccount, TAccountSpillAccount, TAccountRentSysvar, TAccountClockSysvar, TAccountAuthority >); } export type ParsedUpgradeInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** ProgramData account. */ programDataAccount: TAccountMetas[0]; /** Program account. */ programAccount: TAccountMetas[1]; /** Buffer account where the new program data has been written. */ bufferAccount: TAccountMetas[2]; /** Spill account. */ spillAccount: TAccountMetas[3]; /** Rent sysvar. */ rentSysvar: TAccountMetas[4]; /** Clock sysvar. */ clockSysvar: TAccountMetas[5]; /** Authority. */ authority: TAccountMetas[6]; }; data: UpgradeInstructionData; }; export function parseUpgradeInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpgradeInstruction { if (instruction.accounts.length < 7) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 7, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { programDataAccount: getNextAccount(), programAccount: getNextAccount(), bufferAccount: getNextAccount(), spillAccount: getNextAccount(), rentSysvar: getNextAccount(), clockSysvar: getNextAccount(), authority: getNextAccount(), }, data: getUpgradeInstructionDataDecoder().decode(instruction.data), }; }