/** * 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, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, 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_CUSTODY_GLOBAL_LIMIT_DISCRIMINATOR = new Uint8Array([ 94, 82, 154, 177, 193, 205, 141, 76, ]); export function getSetCustodyGlobalLimitDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_CUSTODY_GLOBAL_LIMIT_DISCRIMINATOR, ); } export type SetCustodyGlobalLimitInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountKeeper extends string | AccountMeta = string, TAccountCustody extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountKeeper extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountKeeper, TAccountCustody extends string ? WritableAccount : TAccountCustody, ...TRemainingAccounts, ] >; export type SetCustodyGlobalLimitInstructionData = { discriminator: ReadonlyUint8Array; maxGlobalLongSizes: bigint; maxGlobalShortSizes: bigint; }; export type SetCustodyGlobalLimitInstructionDataArgs = { maxGlobalLongSizes: number | bigint; maxGlobalShortSizes: number | bigint; }; export function getSetCustodyGlobalLimitInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["maxGlobalLongSizes", getU64Encoder()], ["maxGlobalShortSizes", getU64Encoder()], ]), (value) => ({ ...value, discriminator: SET_CUSTODY_GLOBAL_LIMIT_DISCRIMINATOR, }), ); } export function getSetCustodyGlobalLimitInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["maxGlobalLongSizes", getU64Decoder()], ["maxGlobalShortSizes", getU64Decoder()], ]); } export function getSetCustodyGlobalLimitInstructionDataCodec(): FixedSizeCodec< SetCustodyGlobalLimitInstructionDataArgs, SetCustodyGlobalLimitInstructionData > { return combineCodec( getSetCustodyGlobalLimitInstructionDataEncoder(), getSetCustodyGlobalLimitInstructionDataDecoder(), ); } export type SetCustodyGlobalLimitInput< TAccountKeeper extends string = string, TAccountCustody extends string = string, > = { keeper: TransactionSigner; custody: Address; maxGlobalLongSizes: SetCustodyGlobalLimitInstructionDataArgs["maxGlobalLongSizes"]; maxGlobalShortSizes: SetCustodyGlobalLimitInstructionDataArgs["maxGlobalShortSizes"]; }; export function getSetCustodyGlobalLimitInstruction< TAccountKeeper extends string, TAccountCustody extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: SetCustodyGlobalLimitInput, config?: { programAddress?: TProgramAddress }, ): SetCustodyGlobalLimitInstruction< TProgramAddress, TAccountKeeper, TAccountCustody > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { keeper: { value: input.keeper ?? null, isWritable: false }, custody: { value: input.custody ?? 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.keeper), getAccountMeta(accounts.custody), ], data: getSetCustodyGlobalLimitInstructionDataEncoder().encode( args as SetCustodyGlobalLimitInstructionDataArgs, ), programAddress, } as SetCustodyGlobalLimitInstruction< TProgramAddress, TAccountKeeper, TAccountCustody >); } export type ParsedSetCustodyGlobalLimitInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { keeper: TAccountMetas[0]; custody: TAccountMetas[1]; }; data: SetCustodyGlobalLimitInstructionData; }; export function parseSetCustodyGlobalLimitInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetCustodyGlobalLimitInstruction { 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: { keeper: getNextAccount(), custody: getNextAccount() }, data: getSetCustodyGlobalLimitInstructionDataDecoder().decode( instruction.data, ), }; }