/** * 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, getAddressDecoder, getAddressEncoder, 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 SET_ADMIN_CACHED_DISCRIMINATOR = new Uint8Array([ 114, 14, 105, 205, 216, 148, 30, 75, ]); export function getSetAdminCachedDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_ADMIN_CACHED_DISCRIMINATOR, ); } export type SetAdminCachedInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountConfiguration extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountConfiguration extends string ? WritableAccount : TAccountConfiguration, ...TRemainingAccounts, ] >; export type SetAdminCachedInstructionData = { discriminator: ReadonlyUint8Array; newAdmin: Address; feedName: string; }; export type SetAdminCachedInstructionDataArgs = { newAdmin: Address; feedName: string; }; export function getSetAdminCachedInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["newAdmin", getAddressEncoder()], ["feedName", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ]), (value) => ({ ...value, discriminator: SET_ADMIN_CACHED_DISCRIMINATOR }), ); } export function getSetAdminCachedInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["newAdmin", getAddressDecoder()], ["feedName", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ]); } export function getSetAdminCachedInstructionDataCodec(): Codec< SetAdminCachedInstructionDataArgs, SetAdminCachedInstructionData > { return combineCodec( getSetAdminCachedInstructionDataEncoder(), getSetAdminCachedInstructionDataDecoder(), ); } export type SetAdminCachedInput< TAccountAdmin extends string = string, TAccountConfiguration extends string = string, > = { admin: TransactionSigner; configuration: Address; newAdmin: SetAdminCachedInstructionDataArgs["newAdmin"]; feedName: SetAdminCachedInstructionDataArgs["feedName"]; }; export function getSetAdminCachedInstruction< TAccountAdmin extends string, TAccountConfiguration extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: SetAdminCachedInput, config?: { programAddress?: TProgramAddress }, ): SetAdminCachedInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? 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.admin), getAccountMeta(accounts.configuration), ], data: getSetAdminCachedInstructionDataEncoder().encode( args as SetAdminCachedInstructionDataArgs, ), programAddress, } as SetAdminCachedInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration >); } export type ParsedSetAdminCachedInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; configuration: TAccountMetas[1]; }; data: SetAdminCachedInstructionData; }; export function parseSetAdminCachedInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetAdminCachedInstruction { 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: { admin: getNextAccount(), configuration: getNextAccount() }, data: getSetAdminCachedInstructionDataDecoder().decode(instruction.data), }; }