/** * 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, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from "@solana/kit"; import { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const SET_TEST_TIME_DISCRIMINATOR = new Uint8Array([ 242, 231, 177, 251, 126, 145, 159, 104, ]); export function getSetTestTimeDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_TEST_TIME_DISCRIMINATOR, ); } export type SetTestTimeInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountPerpetuals extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountPerpetuals extends string ? WritableAccount : TAccountPerpetuals, ...TRemainingAccounts, ] >; export type SetTestTimeInstructionData = { discriminator: ReadonlyUint8Array; time: bigint; }; export type SetTestTimeInstructionDataArgs = { time: number | bigint }; export function getSetTestTimeInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["time", getI64Encoder()], ]), (value) => ({ ...value, discriminator: SET_TEST_TIME_DISCRIMINATOR }), ); } export function getSetTestTimeInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["time", getI64Decoder()], ]); } export function getSetTestTimeInstructionDataCodec(): FixedSizeCodec< SetTestTimeInstructionDataArgs, SetTestTimeInstructionData > { return combineCodec( getSetTestTimeInstructionDataEncoder(), getSetTestTimeInstructionDataDecoder(), ); } export type SetTestTimeInput< TAccountAdmin extends string = string, TAccountPerpetuals extends string = string, > = { admin: TransactionSigner; perpetuals: Address; time: SetTestTimeInstructionDataArgs["time"]; }; export function getSetTestTimeInstruction< TAccountAdmin extends string, TAccountPerpetuals extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: SetTestTimeInput, config?: { programAddress?: TProgramAddress }, ): SetTestTimeInstruction { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: false }, perpetuals: { value: input.perpetuals ?? 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.perpetuals), ], data: getSetTestTimeInstructionDataEncoder().encode( args as SetTestTimeInstructionDataArgs, ), programAddress, } as SetTestTimeInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals >); } export type ParsedSetTestTimeInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; perpetuals: TAccountMetas[1]; }; data: SetTestTimeInstructionData; }; export function parseSetTestTimeInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetTestTimeInstruction { if (instruction.accounts.length < 2) { // 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() }, data: getSetTestTimeInstructionDataDecoder().decode(instruction.data), }; }