/** * 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, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const SET_TEST_ORACLE_PRICE_DISCRIMINATOR = new Uint8Array([ 44, 111, 165, 185, 58, 14, 249, 249, ]); export function getSetTestOraclePriceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_TEST_ORACLE_PRICE_DISCRIMINATOR, ); } export type SetTestOraclePriceInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountPerpetuals extends string | AccountMeta = string, TAccountPool extends string | AccountMeta = string, TAccountCustody extends string | AccountMeta = string, TAccountOracleAccount extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdmin, TAccountPerpetuals extends string ? ReadonlyAccount : TAccountPerpetuals, TAccountPool extends string ? ReadonlyAccount : TAccountPool, TAccountCustody extends string ? ReadonlyAccount : TAccountCustody, TAccountOracleAccount extends string ? WritableAccount : TAccountOracleAccount, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type SetTestOraclePriceInstructionData = { discriminator: ReadonlyUint8Array; price: bigint; expo: number; conf: bigint; publishTime: bigint; }; export type SetTestOraclePriceInstructionDataArgs = { price: number | bigint; expo: number; conf: number | bigint; publishTime: number | bigint; }; export function getSetTestOraclePriceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["price", getU64Encoder()], ["expo", getI32Encoder()], ["conf", getU64Encoder()], ["publishTime", getI64Encoder()], ]), (value) => ({ ...value, discriminator: SET_TEST_ORACLE_PRICE_DISCRIMINATOR, }), ); } export function getSetTestOraclePriceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["price", getU64Decoder()], ["expo", getI32Decoder()], ["conf", getU64Decoder()], ["publishTime", getI64Decoder()], ]); } export function getSetTestOraclePriceInstructionDataCodec(): FixedSizeCodec< SetTestOraclePriceInstructionDataArgs, SetTestOraclePriceInstructionData > { return combineCodec( getSetTestOraclePriceInstructionDataEncoder(), getSetTestOraclePriceInstructionDataDecoder(), ); } export type SetTestOraclePriceInput< TAccountAdmin extends string = string, TAccountPerpetuals extends string = string, TAccountPool extends string = string, TAccountCustody extends string = string, TAccountOracleAccount extends string = string, TAccountSystemProgram extends string = string, > = { admin: TransactionSigner; perpetuals: Address; pool: Address; custody: Address; oracleAccount: Address; systemProgram?: Address; price: SetTestOraclePriceInstructionDataArgs["price"]; expo: SetTestOraclePriceInstructionDataArgs["expo"]; conf: SetTestOraclePriceInstructionDataArgs["conf"]; publishTime: SetTestOraclePriceInstructionDataArgs["publishTime"]; }; export function getSetTestOraclePriceInstruction< TAccountAdmin extends string, TAccountPerpetuals extends string, TAccountPool extends string, TAccountCustody extends string, TAccountOracleAccount extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: SetTestOraclePriceInput< TAccountAdmin, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountOracleAccount, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): SetTestOraclePriceInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountOracleAccount, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: true }, perpetuals: { value: input.perpetuals ?? null, isWritable: false }, pool: { value: input.pool ?? null, isWritable: false }, custody: { value: input.custody ?? null, isWritable: false }, oracleAccount: { value: input.oracleAccount ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.perpetuals), getAccountMeta(accounts.pool), getAccountMeta(accounts.custody), getAccountMeta(accounts.oracleAccount), getAccountMeta(accounts.systemProgram), ], data: getSetTestOraclePriceInstructionDataEncoder().encode( args as SetTestOraclePriceInstructionDataArgs, ), programAddress, } as SetTestOraclePriceInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals, TAccountPool, TAccountCustody, TAccountOracleAccount, TAccountSystemProgram >); } export type ParsedSetTestOraclePriceInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; perpetuals: TAccountMetas[1]; pool: TAccountMetas[2]; custody: TAccountMetas[3]; oracleAccount: TAccountMetas[4]; systemProgram: TAccountMetas[5]; }; data: SetTestOraclePriceInstructionData; }; export function parseSetTestOraclePriceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetTestOraclePriceInstruction { 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(), perpetuals: getNextAccount(), pool: getNextAccount(), custody: getNextAccount(), oracleAccount: getNextAccount(), systemProgram: getNextAccount(), }, data: getSetTestOraclePriceInstructionDataDecoder().decode( instruction.data, ), }; }