/** * 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 { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getUtf8Decoder, getUtf8Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from "@solana/kit"; import { SCOPE_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const APPROVE_ADMIN_CACHED_DISCRIMINATOR = new Uint8Array([ 101, 149, 97, 58, 48, 79, 16, 105, ]); export function getApproveAdminCachedDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( APPROVE_ADMIN_CACHED_DISCRIMINATOR, ); } export type ApproveAdminCachedInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountAdminCached extends string | AccountMeta = string, TAccountConfiguration extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdminCached extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdminCached, TAccountConfiguration extends string ? WritableAccount : TAccountConfiguration, ...TRemainingAccounts, ] >; export type ApproveAdminCachedInstructionData = { discriminator: ReadonlyUint8Array; feedName: string; }; export type ApproveAdminCachedInstructionDataArgs = { feedName: string }; export function getApproveAdminCachedInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["feedName", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ]), (value) => ({ ...value, discriminator: APPROVE_ADMIN_CACHED_DISCRIMINATOR, }), ); } export function getApproveAdminCachedInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["feedName", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ]); } export function getApproveAdminCachedInstructionDataCodec(): Codec< ApproveAdminCachedInstructionDataArgs, ApproveAdminCachedInstructionData > { return combineCodec( getApproveAdminCachedInstructionDataEncoder(), getApproveAdminCachedInstructionDataDecoder(), ); } export type ApproveAdminCachedInput< TAccountAdminCached extends string = string, TAccountConfiguration extends string = string, > = { adminCached: TransactionSigner; configuration: Address; feedName: ApproveAdminCachedInstructionDataArgs["feedName"]; }; export function getApproveAdminCachedInstruction< TAccountAdminCached extends string, TAccountConfiguration extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: ApproveAdminCachedInput, config?: { programAddress?: TProgramAddress }, ): ApproveAdminCachedInstruction< TProgramAddress, TAccountAdminCached, TAccountConfiguration > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { adminCached: { value: input.adminCached ?? null, isWritable: false }, configuration: { value: input.configuration ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.adminCached), getAccountMeta(accounts.configuration), ], data: getApproveAdminCachedInstructionDataEncoder().encode( args as ApproveAdminCachedInstructionDataArgs, ), programAddress, } as ApproveAdminCachedInstruction< TProgramAddress, TAccountAdminCached, TAccountConfiguration >); } export type ParsedApproveAdminCachedInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { adminCached: TAccountMetas[0]; configuration: TAccountMetas[1]; }; data: ApproveAdminCachedInstructionData; }; export function parseApproveAdminCachedInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedApproveAdminCachedInstruction { if (instruction.accounts.length < 2) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { adminCached: getNextAccount(), configuration: getNextAccount(), }, data: getApproveAdminCachedInstructionDataDecoder().decode( instruction.data, ), }; }