/** * 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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"; export const FREEZE_PRICE_DISCRIMINATOR = new Uint8Array([ 82, 182, 166, 239, 171, 188, 133, 14, ]); export function getFreezePriceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FREEZE_PRICE_DISCRIMINATOR, ); } export type FreezePriceInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta = string, TAccountConfiguration extends string | AccountMeta = string, TAccountOracleMappings extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAuthority, TAccountConfiguration extends string ? ReadonlyAccount : TAccountConfiguration, TAccountOracleMappings extends string ? WritableAccount : TAccountOracleMappings, ...TRemainingAccounts, ] >; export type FreezePriceInstructionData = { discriminator: ReadonlyUint8Array; token: number; feedName: string; freeze: boolean; }; export type FreezePriceInstructionDataArgs = { token: number; feedName: string; freeze: boolean; }; export function getFreezePriceInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["token", getU16Encoder()], ["feedName", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ["freeze", getBooleanEncoder()], ]), (value) => ({ ...value, discriminator: FREEZE_PRICE_DISCRIMINATOR }), ); } export function getFreezePriceInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["token", getU16Decoder()], ["feedName", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ["freeze", getBooleanDecoder()], ]); } export function getFreezePriceInstructionDataCodec(): Codec< FreezePriceInstructionDataArgs, FreezePriceInstructionData > { return combineCodec( getFreezePriceInstructionDataEncoder(), getFreezePriceInstructionDataDecoder(), ); } export type FreezePriceInput< TAccountAuthority extends string = string, TAccountConfiguration extends string = string, TAccountOracleMappings extends string = string, > = { authority: TransactionSigner; configuration: Address; oracleMappings: Address; token: FreezePriceInstructionDataArgs["token"]; feedName: FreezePriceInstructionDataArgs["feedName"]; freeze: FreezePriceInstructionDataArgs["freeze"]; }; export function getFreezePriceInstruction< TAccountAuthority extends string, TAccountConfiguration extends string, TAccountOracleMappings extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: FreezePriceInput< TAccountAuthority, TAccountConfiguration, TAccountOracleMappings >, config?: { programAddress?: TProgramAddress }, ): FreezePriceInstruction< TProgramAddress, TAccountAuthority, TAccountConfiguration, TAccountOracleMappings > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { authority: { value: input.authority ?? null, isWritable: false }, configuration: { value: input.configuration ?? null, isWritable: false }, oracleMappings: { value: input.oracleMappings ?? 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.authority), getAccountMeta(accounts.configuration), getAccountMeta(accounts.oracleMappings), ], data: getFreezePriceInstructionDataEncoder().encode( args as FreezePriceInstructionDataArgs, ), programAddress, } as FreezePriceInstruction< TProgramAddress, TAccountAuthority, TAccountConfiguration, TAccountOracleMappings >); } export type ParsedFreezePriceInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { authority: TAccountMetas[0]; configuration: TAccountMetas[1]; oracleMappings: TAccountMetas[2]; }; data: FreezePriceInstructionData; }; export function parseFreezePriceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedFreezePriceInstruction { if (instruction.accounts.length < 3) { // 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: { authority: getNextAccount(), configuration: getNextAccount(), oracleMappings: getNextAccount(), }, data: getFreezePriceInstructionDataDecoder().decode(instruction.data), }; }