/** * 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 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 SET_AUTHORITY_CHECKED_DISCRIMINATOR = 7; export function getSetAuthorityCheckedDiscriminatorBytes(): ReadonlyUint8Array { return getU32Encoder().encode(SET_AUTHORITY_CHECKED_DISCRIMINATOR); } export type SetAuthorityCheckedInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountBufferOrProgramDataAccount extends string | AccountMeta = string, TAccountCurrentAuthority extends string | AccountMeta = string, TAccountNewAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountBufferOrProgramDataAccount extends string ? WritableAccount : TAccountBufferOrProgramDataAccount, TAccountCurrentAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountCurrentAuthority, TAccountNewAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountNewAuthority, ...TRemainingAccounts, ] >; export type SetAuthorityCheckedInstructionData = { discriminator: number }; export type SetAuthorityCheckedInstructionDataArgs = {}; export function getSetAuthorityCheckedInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU32Encoder()]]), value => ({ ...value, discriminator: SET_AUTHORITY_CHECKED_DISCRIMINATOR, })); } export function getSetAuthorityCheckedInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU32Decoder()]]); } export function getSetAuthorityCheckedInstructionDataCodec(): FixedSizeCodec< SetAuthorityCheckedInstructionDataArgs, SetAuthorityCheckedInstructionData > { return combineCodec(getSetAuthorityCheckedInstructionDataEncoder(), getSetAuthorityCheckedInstructionDataDecoder()); } export type SetAuthorityCheckedInput< TAccountBufferOrProgramDataAccount extends string = string, TAccountCurrentAuthority extends string = string, TAccountNewAuthority extends string = string, > = { /** Buffer or ProgramData account to change the authority of. */ bufferOrProgramDataAccount: Address; /** Current authority. */ currentAuthority: TransactionSigner; /** New authority. */ newAuthority: TransactionSigner; }; export function getSetAuthorityCheckedInstruction< TAccountBufferOrProgramDataAccount extends string, TAccountCurrentAuthority extends string, TAccountNewAuthority extends string, TProgramAddress extends Address = typeof LOADER_V3_PROGRAM_ADDRESS, >( input: SetAuthorityCheckedInput, config?: { programAddress?: TProgramAddress }, ): SetAuthorityCheckedInstruction< TProgramAddress, TAccountBufferOrProgramDataAccount, TAccountCurrentAuthority, TAccountNewAuthority > { // Program address. const programAddress = config?.programAddress ?? LOADER_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { bufferOrProgramDataAccount: { value: input.bufferOrProgramDataAccount ?? null, isWritable: true }, currentAuthority: { value: input.currentAuthority ?? null, isWritable: false }, newAuthority: { value: input.newAuthority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('bufferOrProgramDataAccount', accounts.bufferOrProgramDataAccount), getAccountMeta('currentAuthority', accounts.currentAuthority), getAccountMeta('newAuthority', accounts.newAuthority), ], data: getSetAuthorityCheckedInstructionDataEncoder().encode({}), programAddress, } as SetAuthorityCheckedInstruction< TProgramAddress, TAccountBufferOrProgramDataAccount, TAccountCurrentAuthority, TAccountNewAuthority >); } export type ParsedSetAuthorityCheckedInstruction< TProgram extends string = typeof LOADER_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Buffer or ProgramData account to change the authority of. */ bufferOrProgramDataAccount: TAccountMetas[0]; /** Current authority. */ currentAuthority: TAccountMetas[1]; /** New authority. */ newAuthority: TAccountMetas[2]; }; data: SetAuthorityCheckedInstructionData; }; export function parseSetAuthorityCheckedInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetAuthorityCheckedInstruction { if (instruction.accounts.length < 3) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { bufferOrProgramDataAccount: getNextAccount(), currentAuthority: getNextAccount(), newAuthority: getNextAccount(), }, data: getSetAuthorityCheckedInstructionDataDecoder().decode(instruction.data), }; }