/** * 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, fixDecoderSize, fixEncoderSize, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, transformEncoder, type AccountMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount, } from "@solana/kit"; import { SCOPE_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const REFRESH_PRICE_LIST_DISCRIMINATOR = new Uint8Array([ 83, 186, 207, 131, 203, 254, 198, 130, ]); export function getRefreshPriceListDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REFRESH_PRICE_LIST_DISCRIMINATOR, ); } export type RefreshPriceListInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountOraclePrices extends string | AccountMeta = string, TAccountOracleMappings extends string | AccountMeta = string, TAccountOracleTwaps extends string | AccountMeta = string, TAccountInstructionSysvarAccountInfo extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountOraclePrices extends string ? WritableAccount : TAccountOraclePrices, TAccountOracleMappings extends string ? ReadonlyAccount : TAccountOracleMappings, TAccountOracleTwaps extends string ? WritableAccount : TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo extends string ? ReadonlyAccount : TAccountInstructionSysvarAccountInfo, ...TRemainingAccounts, ] >; export type RefreshPriceListInstructionData = { discriminator: ReadonlyUint8Array; tokens: Array; }; export type RefreshPriceListInstructionDataArgs = { tokens: Array }; export function getRefreshPriceListInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["tokens", getArrayEncoder(getU16Encoder())], ]), (value) => ({ ...value, discriminator: REFRESH_PRICE_LIST_DISCRIMINATOR }), ); } export function getRefreshPriceListInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["tokens", getArrayDecoder(getU16Decoder())], ]); } export function getRefreshPriceListInstructionDataCodec(): Codec< RefreshPriceListInstructionDataArgs, RefreshPriceListInstructionData > { return combineCodec( getRefreshPriceListInstructionDataEncoder(), getRefreshPriceListInstructionDataDecoder(), ); } export type RefreshPriceListInput< TAccountOraclePrices extends string = string, TAccountOracleMappings extends string = string, TAccountOracleTwaps extends string = string, TAccountInstructionSysvarAccountInfo extends string = string, > = { oraclePrices: Address; oracleMappings: Address; oracleTwaps: Address; instructionSysvarAccountInfo: Address; tokens: RefreshPriceListInstructionDataArgs["tokens"]; }; export function getRefreshPriceListInstruction< TAccountOraclePrices extends string, TAccountOracleMappings extends string, TAccountOracleTwaps extends string, TAccountInstructionSysvarAccountInfo extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: RefreshPriceListInput< TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo >, config?: { programAddress?: TProgramAddress }, ): RefreshPriceListInstruction< TProgramAddress, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { oraclePrices: { value: input.oraclePrices ?? null, isWritable: true }, oracleMappings: { value: input.oracleMappings ?? null, isWritable: false }, oracleTwaps: { value: input.oracleTwaps ?? null, isWritable: true }, instructionSysvarAccountInfo: { value: input.instructionSysvarAccountInfo ?? null, isWritable: false, }, }; 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.oraclePrices), getAccountMeta(accounts.oracleMappings), getAccountMeta(accounts.oracleTwaps), getAccountMeta(accounts.instructionSysvarAccountInfo), ], data: getRefreshPriceListInstructionDataEncoder().encode( args as RefreshPriceListInstructionDataArgs, ), programAddress, } as RefreshPriceListInstruction< TProgramAddress, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo >); } export type ParsedRefreshPriceListInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { oraclePrices: TAccountMetas[0]; oracleMappings: TAccountMetas[1]; oracleTwaps: TAccountMetas[2]; instructionSysvarAccountInfo: TAccountMetas[3]; }; data: RefreshPriceListInstructionData; }; export function parseRefreshPriceListInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRefreshPriceListInstruction { if (instruction.accounts.length < 4) { // 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: { oraclePrices: getNextAccount(), oracleMappings: getNextAccount(), oracleTwaps: getNextAccount(), instructionSysvarAccountInfo: getNextAccount(), }, data: getRefreshPriceListInstructionDataDecoder().decode(instruction.data), }; }