/** * 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, getU64Decoder, getU64Encoder, 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 RESET_TWAP_DISCRIMINATOR = new Uint8Array([ 101, 216, 28, 92, 154, 79, 49, 187, ]); export function getResetTwapDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(RESET_TWAP_DISCRIMINATOR); } export type ResetTwapInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountConfiguration extends string | AccountMeta = string, TAccountOracleTwaps extends string | AccountMeta = string, TAccountInstructionSysvarAccountInfo extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountConfiguration extends string ? ReadonlyAccount : TAccountConfiguration, TAccountOracleTwaps extends string ? WritableAccount : TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo extends string ? ReadonlyAccount : TAccountInstructionSysvarAccountInfo, ...TRemainingAccounts, ] >; export type ResetTwapInstructionData = { discriminator: ReadonlyUint8Array; token: bigint; feedName: string; }; export type ResetTwapInstructionDataArgs = { token: number | bigint; feedName: string; }; export function getResetTwapInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["token", getU64Encoder()], ["feedName", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ]), (value) => ({ ...value, discriminator: RESET_TWAP_DISCRIMINATOR }), ); } export function getResetTwapInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["token", getU64Decoder()], ["feedName", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ]); } export function getResetTwapInstructionDataCodec(): Codec< ResetTwapInstructionDataArgs, ResetTwapInstructionData > { return combineCodec( getResetTwapInstructionDataEncoder(), getResetTwapInstructionDataDecoder(), ); } export type ResetTwapInput< TAccountAdmin extends string = string, TAccountConfiguration extends string = string, TAccountOracleTwaps extends string = string, TAccountInstructionSysvarAccountInfo extends string = string, > = { admin: TransactionSigner; configuration: Address; oracleTwaps: Address; instructionSysvarAccountInfo: Address; token: ResetTwapInstructionDataArgs["token"]; feedName: ResetTwapInstructionDataArgs["feedName"]; }; export function getResetTwapInstruction< TAccountAdmin extends string, TAccountConfiguration extends string, TAccountOracleTwaps extends string, TAccountInstructionSysvarAccountInfo extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: ResetTwapInput< TAccountAdmin, TAccountConfiguration, TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo >, config?: { programAddress?: TProgramAddress }, ): ResetTwapInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration, TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo > { // 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 }, 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.admin), getAccountMeta(accounts.configuration), getAccountMeta(accounts.oracleTwaps), getAccountMeta(accounts.instructionSysvarAccountInfo), ], data: getResetTwapInstructionDataEncoder().encode( args as ResetTwapInstructionDataArgs, ), programAddress, } as ResetTwapInstruction< TProgramAddress, TAccountAdmin, TAccountConfiguration, TAccountOracleTwaps, TAccountInstructionSysvarAccountInfo >); } export type ParsedResetTwapInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; configuration: TAccountMetas[1]; oracleTwaps: TAccountMetas[2]; instructionSysvarAccountInfo: TAccountMetas[3]; }; data: ResetTwapInstructionData; }; export function parseResetTwapInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedResetTwapInstruction { 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: { admin: getNextAccount(), configuration: getNextAccount(), oracleTwaps: getNextAccount(), instructionSysvarAccountInfo: getNextAccount(), }, data: getResetTwapInstructionDataDecoder().decode(instruction.data), }; }