/** * 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 { assertIsInstructionWithAccounts, containsBytes, fixEncoderSize, getBytesEncoder, type Address, type Instruction, type InstructionWithData, type ReadonlyUint8Array, } from "@solana/kit"; import { parseAddCustodyInstruction, parseAddLiquidityInstruction, parseAddPoolInstruction, parseClosePositionRequestInstruction, parseCreateDecreasePositionRequestInstruction, parseCreateIncreasePositionRequestInstruction, parseDecreasePositionInstruction, parseDecreasePositionPostSwapInstruction, parseGetAddLiquidityAmountAndFeeInstruction, parseGetDecreasePositionInstruction, parseGetExactOutSwapAmountAndFeesInstruction, parseGetIncreasePositionInstruction, parseGetLiquidationStateInstruction, parseGetOraclePriceInstruction, parseGetPnlInstruction, parseGetRemoveLiquidityAmountAndFeeInstruction, parseGetSwapAmountAndFeesInstruction, parseIncreasePositionInstruction, parseIncreasePositionPreSwapInstruction, parseInitInstruction, parseLiquidatePositionInstruction, parseRemoveLiquidityInstruction, parseSetCustodyConfigInstruction, parseSetCustodyGlobalLimitInstruction, parseSetPerpetualsConfigInstruction, parseSetPoolConfigInstruction, parseSetTestOraclePriceInstruction, parseSetTestTimeInstruction, parseSwapExactOutInstruction, parseSwapInstruction, parseTestInitInstruction, parseTransferAdminInstruction, parseUpdateDecreasePositionRequestInstruction, parseUpdateIncreasePositionRequestInstruction, parseWithdrawFeesInstruction, type ParsedAddCustodyInstruction, type ParsedAddLiquidityInstruction, type ParsedAddPoolInstruction, type ParsedClosePositionRequestInstruction, type ParsedCreateDecreasePositionRequestInstruction, type ParsedCreateIncreasePositionRequestInstruction, type ParsedDecreasePositionInstruction, type ParsedDecreasePositionPostSwapInstruction, type ParsedGetAddLiquidityAmountAndFeeInstruction, type ParsedGetDecreasePositionInstruction, type ParsedGetExactOutSwapAmountAndFeesInstruction, type ParsedGetIncreasePositionInstruction, type ParsedGetLiquidationStateInstruction, type ParsedGetOraclePriceInstruction, type ParsedGetPnlInstruction, type ParsedGetRemoveLiquidityAmountAndFeeInstruction, type ParsedGetSwapAmountAndFeesInstruction, type ParsedIncreasePositionInstruction, type ParsedIncreasePositionPreSwapInstruction, type ParsedInitInstruction, type ParsedLiquidatePositionInstruction, type ParsedRemoveLiquidityInstruction, type ParsedSetCustodyConfigInstruction, type ParsedSetCustodyGlobalLimitInstruction, type ParsedSetPerpetualsConfigInstruction, type ParsedSetPoolConfigInstruction, type ParsedSetTestOraclePriceInstruction, type ParsedSetTestTimeInstruction, type ParsedSwapExactOutInstruction, type ParsedSwapInstruction, type ParsedTestInitInstruction, type ParsedTransferAdminInstruction, type ParsedUpdateDecreasePositionRequestInstruction, type ParsedUpdateIncreasePositionRequestInstruction, type ParsedWithdrawFeesInstruction, } from "../instructions"; export const PERPETUALS_PROGRAM_ADDRESS = "PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu" as Address<"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu">; export enum PerpetualsAccount { Custody, TestOracle, Perpetuals, Pool, PositionRequest, Position, } export function identifyPerpetualsAccount( account: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): PerpetualsAccount { const data = "data" in account ? account.data : account; if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([1, 184, 48, 81, 93, 131, 63, 145]), ), 0, ) ) { return PerpetualsAccount.Custody; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([198, 49, 63, 134, 232, 251, 168, 28]), ), 0, ) ) { return PerpetualsAccount.TestOracle; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([28, 167, 98, 191, 104, 82, 108, 196]), ), 0, ) ) { return PerpetualsAccount.Perpetuals; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([241, 154, 109, 4, 17, 177, 109, 188]), ), 0, ) ) { return PerpetualsAccount.Pool; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([12, 38, 250, 199, 46, 154, 32, 216]), ), 0, ) ) { return PerpetualsAccount.PositionRequest; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([170, 188, 143, 228, 122, 64, 247, 208]), ), 0, ) ) { return PerpetualsAccount.Position; } throw new Error( "The provided account could not be identified as a perpetuals account.", ); } export enum PerpetualsInstruction { Init, AddPool, AddCustody, SetCustodyConfig, SetCustodyGlobalLimit, SetPoolConfig, SetPerpetualsConfig, TransferAdmin, WithdrawFees, TestInit, SetTestOraclePrice, SetTestTime, Swap, SwapExactOut, AddLiquidity, RemoveLiquidity, CreateIncreasePositionRequest, UpdateIncreasePositionRequest, CreateDecreasePositionRequest, UpdateDecreasePositionRequest, ClosePositionRequest, IncreasePosition, IncreasePositionPreSwap, DecreasePosition, DecreasePositionPostSwap, LiquidatePosition, GetAddLiquidityAmountAndFee, GetRemoveLiquidityAmountAndFee, GetIncreasePosition, GetDecreasePosition, GetPnl, GetLiquidationState, GetOraclePrice, GetSwapAmountAndFees, GetExactOutSwapAmountAndFees, } export function identifyPerpetualsInstruction( instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): PerpetualsInstruction { const data = "data" in instruction ? instruction.data : instruction; if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([220, 59, 207, 236, 108, 250, 47, 100]), ), 0, ) ) { return PerpetualsInstruction.Init; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([115, 230, 212, 211, 175, 49, 39, 169]), ), 0, ) ) { return PerpetualsInstruction.AddPool; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([247, 254, 126, 17, 26, 6, 215, 117]), ), 0, ) ) { return PerpetualsInstruction.AddCustody; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([133, 97, 130, 143, 215, 229, 36, 176]), ), 0, ) ) { return PerpetualsInstruction.SetCustodyConfig; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([94, 82, 154, 177, 193, 205, 141, 76]), ), 0, ) ) { return PerpetualsInstruction.SetCustodyGlobalLimit; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([216, 87, 65, 125, 113, 110, 185, 120]), ), 0, ) ) { return PerpetualsInstruction.SetPoolConfig; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([80, 72, 21, 191, 29, 121, 45, 111]), ), 0, ) ) { return PerpetualsInstruction.SetPerpetualsConfig; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([42, 242, 66, 106, 228, 10, 111, 156]), ), 0, ) ) { return PerpetualsInstruction.TransferAdmin; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([198, 212, 171, 109, 144, 215, 174, 89]), ), 0, ) ) { return PerpetualsInstruction.WithdrawFees; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([48, 51, 92, 122, 81, 19, 112, 41]), ), 0, ) ) { return PerpetualsInstruction.TestInit; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([44, 111, 165, 185, 58, 14, 249, 249]), ), 0, ) ) { return PerpetualsInstruction.SetTestOraclePrice; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([242, 231, 177, 251, 126, 145, 159, 104]), ), 0, ) ) { return PerpetualsInstruction.SetTestTime; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([248, 198, 158, 145, 225, 117, 135, 200]), ), 0, ) ) { return PerpetualsInstruction.Swap; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([250, 73, 101, 33, 38, 207, 75, 184]), ), 0, ) ) { return PerpetualsInstruction.SwapExactOut; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([181, 157, 89, 67, 143, 182, 52, 72]), ), 0, ) ) { return PerpetualsInstruction.AddLiquidity; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([80, 85, 209, 72, 24, 206, 177, 108]), ), 0, ) ) { return PerpetualsInstruction.RemoveLiquidity; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([8, 160, 201, 226, 217, 74, 228, 137]), ), 0, ) ) { return PerpetualsInstruction.CreateIncreasePositionRequest; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([100, 110, 83, 102, 86, 7, 105, 157]), ), 0, ) ) { return PerpetualsInstruction.UpdateIncreasePositionRequest; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([146, 21, 51, 121, 187, 208, 7, 69]), ), 0, ) ) { return PerpetualsInstruction.CreateDecreasePositionRequest; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([69, 44, 72, 173, 62, 20, 177, 146]), ), 0, ) ) { return PerpetualsInstruction.UpdateDecreasePositionRequest; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([40, 105, 217, 188, 220, 45, 109, 110]), ), 0, ) ) { return PerpetualsInstruction.ClosePositionRequest; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([253, 234, 128, 104, 192, 188, 45, 91]), ), 0, ) ) { return PerpetualsInstruction.IncreasePosition; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([26, 136, 225, 217, 22, 21, 83, 20]), ), 0, ) ) { return PerpetualsInstruction.IncreasePositionPreSwap; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([57, 125, 21, 59, 200, 137, 179, 108]), ), 0, ) ) { return PerpetualsInstruction.DecreasePosition; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([75, 246, 208, 7, 203, 66, 106, 91]), ), 0, ) ) { return PerpetualsInstruction.DecreasePositionPostSwap; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([187, 74, 229, 149, 102, 81, 221, 68]), ), 0, ) ) { return PerpetualsInstruction.LiquidatePosition; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([172, 150, 249, 181, 233, 241, 78, 139]), ), 0, ) ) { return PerpetualsInstruction.GetAddLiquidityAmountAndFee; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([194, 226, 233, 102, 14, 21, 196, 7]), ), 0, ) ) { return PerpetualsInstruction.GetRemoveLiquidityAmountAndFee; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([101, 131, 0, 32, 246, 54, 251, 101]), ), 0, ) ) { return PerpetualsInstruction.GetIncreasePosition; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([106, 31, 146, 195, 103, 108, 48, 250]), ), 0, ) ) { return PerpetualsInstruction.GetDecreasePosition; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([106, 212, 3, 250, 195, 224, 64, 160]), ), 0, ) ) { return PerpetualsInstruction.GetPnl; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([127, 126, 199, 117, 90, 89, 29, 50]), ), 0, ) ) { return PerpetualsInstruction.GetLiquidationState; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([200, 20, 0, 106, 56, 210, 230, 140]), ), 0, ) ) { return PerpetualsInstruction.GetOraclePrice; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([247, 121, 40, 99, 35, 82, 100, 32]), ), 0, ) ) { return PerpetualsInstruction.GetSwapAmountAndFees; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( new Uint8Array([196, 32, 218, 118, 151, 233, 43, 56]), ), 0, ) ) { return PerpetualsInstruction.GetExactOutSwapAmountAndFees; } throw new Error( "The provided instruction could not be identified as a perpetuals instruction.", ); } export type ParsedPerpetualsInstruction = | ({ instructionType: PerpetualsInstruction.Init; } & ParsedInitInstruction) | ({ instructionType: PerpetualsInstruction.AddPool; } & ParsedAddPoolInstruction) | ({ instructionType: PerpetualsInstruction.AddCustody; } & ParsedAddCustodyInstruction) | ({ instructionType: PerpetualsInstruction.SetCustodyConfig; } & ParsedSetCustodyConfigInstruction) | ({ instructionType: PerpetualsInstruction.SetCustodyGlobalLimit; } & ParsedSetCustodyGlobalLimitInstruction) | ({ instructionType: PerpetualsInstruction.SetPoolConfig; } & ParsedSetPoolConfigInstruction) | ({ instructionType: PerpetualsInstruction.SetPerpetualsConfig; } & ParsedSetPerpetualsConfigInstruction) | ({ instructionType: PerpetualsInstruction.TransferAdmin; } & ParsedTransferAdminInstruction) | ({ instructionType: PerpetualsInstruction.WithdrawFees; } & ParsedWithdrawFeesInstruction) | ({ instructionType: PerpetualsInstruction.TestInit; } & ParsedTestInitInstruction) | ({ instructionType: PerpetualsInstruction.SetTestOraclePrice; } & ParsedSetTestOraclePriceInstruction) | ({ instructionType: PerpetualsInstruction.SetTestTime; } & ParsedSetTestTimeInstruction) | ({ instructionType: PerpetualsInstruction.Swap; } & ParsedSwapInstruction) | ({ instructionType: PerpetualsInstruction.SwapExactOut; } & ParsedSwapExactOutInstruction) | ({ instructionType: PerpetualsInstruction.AddLiquidity; } & ParsedAddLiquidityInstruction) | ({ instructionType: PerpetualsInstruction.RemoveLiquidity; } & ParsedRemoveLiquidityInstruction) | ({ instructionType: PerpetualsInstruction.CreateIncreasePositionRequest; } & ParsedCreateIncreasePositionRequestInstruction) | ({ instructionType: PerpetualsInstruction.UpdateIncreasePositionRequest; } & ParsedUpdateIncreasePositionRequestInstruction) | ({ instructionType: PerpetualsInstruction.CreateDecreasePositionRequest; } & ParsedCreateDecreasePositionRequestInstruction) | ({ instructionType: PerpetualsInstruction.UpdateDecreasePositionRequest; } & ParsedUpdateDecreasePositionRequestInstruction) | ({ instructionType: PerpetualsInstruction.ClosePositionRequest; } & ParsedClosePositionRequestInstruction) | ({ instructionType: PerpetualsInstruction.IncreasePosition; } & ParsedIncreasePositionInstruction) | ({ instructionType: PerpetualsInstruction.IncreasePositionPreSwap; } & ParsedIncreasePositionPreSwapInstruction) | ({ instructionType: PerpetualsInstruction.DecreasePosition; } & ParsedDecreasePositionInstruction) | ({ instructionType: PerpetualsInstruction.DecreasePositionPostSwap; } & ParsedDecreasePositionPostSwapInstruction) | ({ instructionType: PerpetualsInstruction.LiquidatePosition; } & ParsedLiquidatePositionInstruction) | ({ instructionType: PerpetualsInstruction.GetAddLiquidityAmountAndFee; } & ParsedGetAddLiquidityAmountAndFeeInstruction) | ({ instructionType: PerpetualsInstruction.GetRemoveLiquidityAmountAndFee; } & ParsedGetRemoveLiquidityAmountAndFeeInstruction) | ({ instructionType: PerpetualsInstruction.GetIncreasePosition; } & ParsedGetIncreasePositionInstruction) | ({ instructionType: PerpetualsInstruction.GetDecreasePosition; } & ParsedGetDecreasePositionInstruction) | ({ instructionType: PerpetualsInstruction.GetPnl; } & ParsedGetPnlInstruction) | ({ instructionType: PerpetualsInstruction.GetLiquidationState; } & ParsedGetLiquidationStateInstruction) | ({ instructionType: PerpetualsInstruction.GetOraclePrice; } & ParsedGetOraclePriceInstruction) | ({ instructionType: PerpetualsInstruction.GetSwapAmountAndFees; } & ParsedGetSwapAmountAndFeesInstruction) | ({ instructionType: PerpetualsInstruction.GetExactOutSwapAmountAndFees; } & ParsedGetExactOutSwapAmountAndFeesInstruction); export function parsePerpetualsInstruction( instruction: Instruction & InstructionWithData, ): ParsedPerpetualsInstruction { const instructionType = identifyPerpetualsInstruction(instruction); switch (instructionType) { case PerpetualsInstruction.Init: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.Init, ...parseInitInstruction(instruction), }; } case PerpetualsInstruction.AddPool: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.AddPool, ...parseAddPoolInstruction(instruction), }; } case PerpetualsInstruction.AddCustody: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.AddCustody, ...parseAddCustodyInstruction(instruction), }; } case PerpetualsInstruction.SetCustodyConfig: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SetCustodyConfig, ...parseSetCustodyConfigInstruction(instruction), }; } case PerpetualsInstruction.SetCustodyGlobalLimit: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SetCustodyGlobalLimit, ...parseSetCustodyGlobalLimitInstruction(instruction), }; } case PerpetualsInstruction.SetPoolConfig: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SetPoolConfig, ...parseSetPoolConfigInstruction(instruction), }; } case PerpetualsInstruction.SetPerpetualsConfig: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SetPerpetualsConfig, ...parseSetPerpetualsConfigInstruction(instruction), }; } case PerpetualsInstruction.TransferAdmin: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.TransferAdmin, ...parseTransferAdminInstruction(instruction), }; } case PerpetualsInstruction.WithdrawFees: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.WithdrawFees, ...parseWithdrawFeesInstruction(instruction), }; } case PerpetualsInstruction.TestInit: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.TestInit, ...parseTestInitInstruction(instruction), }; } case PerpetualsInstruction.SetTestOraclePrice: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SetTestOraclePrice, ...parseSetTestOraclePriceInstruction(instruction), }; } case PerpetualsInstruction.SetTestTime: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SetTestTime, ...parseSetTestTimeInstruction(instruction), }; } case PerpetualsInstruction.Swap: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.Swap, ...parseSwapInstruction(instruction), }; } case PerpetualsInstruction.SwapExactOut: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.SwapExactOut, ...parseSwapExactOutInstruction(instruction), }; } case PerpetualsInstruction.AddLiquidity: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.AddLiquidity, ...parseAddLiquidityInstruction(instruction), }; } case PerpetualsInstruction.RemoveLiquidity: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.RemoveLiquidity, ...parseRemoveLiquidityInstruction(instruction), }; } case PerpetualsInstruction.CreateIncreasePositionRequest: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.CreateIncreasePositionRequest, ...parseCreateIncreasePositionRequestInstruction(instruction), }; } case PerpetualsInstruction.UpdateIncreasePositionRequest: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.UpdateIncreasePositionRequest, ...parseUpdateIncreasePositionRequestInstruction(instruction), }; } case PerpetualsInstruction.CreateDecreasePositionRequest: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.CreateDecreasePositionRequest, ...parseCreateDecreasePositionRequestInstruction(instruction), }; } case PerpetualsInstruction.UpdateDecreasePositionRequest: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.UpdateDecreasePositionRequest, ...parseUpdateDecreasePositionRequestInstruction(instruction), }; } case PerpetualsInstruction.ClosePositionRequest: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.ClosePositionRequest, ...parseClosePositionRequestInstruction(instruction), }; } case PerpetualsInstruction.IncreasePosition: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.IncreasePosition, ...parseIncreasePositionInstruction(instruction), }; } case PerpetualsInstruction.IncreasePositionPreSwap: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.IncreasePositionPreSwap, ...parseIncreasePositionPreSwapInstruction(instruction), }; } case PerpetualsInstruction.DecreasePosition: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.DecreasePosition, ...parseDecreasePositionInstruction(instruction), }; } case PerpetualsInstruction.DecreasePositionPostSwap: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.DecreasePositionPostSwap, ...parseDecreasePositionPostSwapInstruction(instruction), }; } case PerpetualsInstruction.LiquidatePosition: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.LiquidatePosition, ...parseLiquidatePositionInstruction(instruction), }; } case PerpetualsInstruction.GetAddLiquidityAmountAndFee: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetAddLiquidityAmountAndFee, ...parseGetAddLiquidityAmountAndFeeInstruction(instruction), }; } case PerpetualsInstruction.GetRemoveLiquidityAmountAndFee: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetRemoveLiquidityAmountAndFee, ...parseGetRemoveLiquidityAmountAndFeeInstruction(instruction), }; } case PerpetualsInstruction.GetIncreasePosition: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetIncreasePosition, ...parseGetIncreasePositionInstruction(instruction), }; } case PerpetualsInstruction.GetDecreasePosition: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetDecreasePosition, ...parseGetDecreasePositionInstruction(instruction), }; } case PerpetualsInstruction.GetPnl: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetPnl, ...parseGetPnlInstruction(instruction), }; } case PerpetualsInstruction.GetLiquidationState: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetLiquidationState, ...parseGetLiquidationStateInstruction(instruction), }; } case PerpetualsInstruction.GetOraclePrice: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetOraclePrice, ...parseGetOraclePriceInstruction(instruction), }; } case PerpetualsInstruction.GetSwapAmountAndFees: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetSwapAmountAndFees, ...parseGetSwapAmountAndFeesInstruction(instruction), }; } case PerpetualsInstruction.GetExactOutSwapAmountAndFees: { assertIsInstructionWithAccounts(instruction); return { instructionType: PerpetualsInstruction.GetExactOutSwapAmountAndFees, ...parseGetExactOutSwapAmountAndFeesInstruction(instruction), }; } default: throw new Error( `Unrecognized instruction type: ${instructionType as string}`, ); } }