/** * 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, getArrayDecoder, getArrayEncoder, 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 ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from "@solana/kit"; import { SCOPE_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; import { getUpdateOracleMappingAndMetadataEntriesWithIdDecoder, getUpdateOracleMappingAndMetadataEntriesWithIdEncoder, type UpdateOracleMappingAndMetadataEntriesWithId, type UpdateOracleMappingAndMetadataEntriesWithIdArgs, } from "../types"; export const UPDATE_MAPPING_AND_METADATA_DISCRIMINATOR = new Uint8Array([ 158, 81, 149, 146, 206, 154, 91, 56, ]); export function getUpdateMappingAndMetadataDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( UPDATE_MAPPING_AND_METADATA_DISCRIMINATOR, ); } export type UpdateMappingAndMetadataInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountConfiguration extends string | AccountMeta = string, TAccountOracleMappings extends string | AccountMeta = string, TAccountTokensMetadata extends string | AccountMeta = string, TAccountOraclePrices extends string | AccountMeta = string, TAccountOracleTwaps extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountConfiguration extends string ? ReadonlyAccount : TAccountConfiguration, TAccountOracleMappings extends string ? WritableAccount : TAccountOracleMappings, TAccountTokensMetadata extends string ? WritableAccount : TAccountTokensMetadata, TAccountOraclePrices extends string ? WritableAccount : TAccountOraclePrices, TAccountOracleTwaps extends string ? WritableAccount : TAccountOracleTwaps, ...TRemainingAccounts, ] >; export type UpdateMappingAndMetadataInstructionData = { discriminator: ReadonlyUint8Array; feedName: string; updates: Array; }; export type UpdateMappingAndMetadataInstructionDataArgs = { feedName: string; updates: Array; }; export function getUpdateMappingAndMetadataInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["feedName", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], [ "updates", getArrayEncoder( getUpdateOracleMappingAndMetadataEntriesWithIdEncoder(), ), ], ]), (value) => ({ ...value, discriminator: UPDATE_MAPPING_AND_METADATA_DISCRIMINATOR, }), ); } export function getUpdateMappingAndMetadataInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["feedName", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], [ "updates", getArrayDecoder(getUpdateOracleMappingAndMetadataEntriesWithIdDecoder()), ], ]); } export function getUpdateMappingAndMetadataInstructionDataCodec(): Codec< UpdateMappingAndMetadataInstructionDataArgs, UpdateMappingAndMetadataInstructionData > { return combineCodec( getUpdateMappingAndMetadataInstructionDataEncoder(), getUpdateMappingAndMetadataInstructionDataDecoder(), ); } export type UpdateMappingAndMetadataInput< TAccountAdmin extends string = string, TAccountConfiguration extends string = string, TAccountOracleMappings extends string = string, TAccountTokensMetadata extends string = string, TAccountOraclePrices extends string = string, TAccountOracleTwaps extends string = string, > = { admin: TransactionSigner; configuration: Address; oracleMappings: Address; tokensMetadata: Address; /** Price entry will be reset if the corresponding mapping changes */ oraclePrices: Address; /** Twap entry will be reset if the corresponding mapping changes */ oracleTwaps: Address; feedName: UpdateMappingAndMetadataInstructionDataArgs["feedName"]; updates: UpdateMappingAndMetadataInstructionDataArgs["updates"]; }; export function getUpdateMappingAndMetadataInstruction< TAccountAdmin extends string, TAccountConfiguration extends string, TAccountOracleMappings extends string, TAccountTokensMetadata extends string, TAccountOraclePrices extends string, TAccountOracleTwaps extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: UpdateMappingAndMetadataInput< TAccountAdmin, TAccountConfiguration, TAccountOracleMappings, TAccountTokensMetadata, TAccountOraclePrices, TAccountOracleTwaps >, config?: { programAddress?: TProgramAddress }, ): UpdateMappingAndMetadataInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration, TAccountOracleMappings, TAccountTokensMetadata, TAccountOraclePrices, TAccountOracleTwaps > { // 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: false }, oracleMappings: { value: input.oracleMappings ?? null, isWritable: true }, tokensMetadata: { value: input.tokensMetadata ?? null, isWritable: true }, oraclePrices: { value: input.oraclePrices ?? null, isWritable: true }, oracleTwaps: { value: input.oracleTwaps ?? 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), getAccountMeta(accounts.oracleMappings), getAccountMeta(accounts.tokensMetadata), getAccountMeta(accounts.oraclePrices), getAccountMeta(accounts.oracleTwaps), ], data: getUpdateMappingAndMetadataInstructionDataEncoder().encode( args as UpdateMappingAndMetadataInstructionDataArgs, ), programAddress, } as UpdateMappingAndMetadataInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration, TAccountOracleMappings, TAccountTokensMetadata, TAccountOraclePrices, TAccountOracleTwaps >); } export type ParsedUpdateMappingAndMetadataInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; configuration: TAccountMetas[1]; oracleMappings: TAccountMetas[2]; tokensMetadata: TAccountMetas[3]; /** Price entry will be reset if the corresponding mapping changes */ oraclePrices: TAccountMetas[4]; /** Twap entry will be reset if the corresponding mapping changes */ oracleTwaps: TAccountMetas[5]; }; data: UpdateMappingAndMetadataInstructionData; }; export function parseUpdateMappingAndMetadataInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpdateMappingAndMetadataInstruction { if (instruction.accounts.length < 6) { // 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(), oracleMappings: getNextAccount(), tokensMetadata: getNextAccount(), oraclePrices: getNextAccount(), oracleTwaps: getNextAccount(), }, data: getUpdateMappingAndMetadataInstructionDataDecoder().decode( instruction.data, ), }; }