/** * 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 { isProgramError, type Address, type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, type SolanaError, } from "@solana/kit"; import { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; /** MathOverflow: Overflow in arithmetic operation */ export const PERPETUALS_ERROR__MATH_OVERFLOW = 0x1770; // 6000 /** UnsupportedOracle: Unsupported price oracle */ export const PERPETUALS_ERROR__UNSUPPORTED_ORACLE = 0x1771; // 6001 /** InvalidOracleAccount: Invalid oracle account */ export const PERPETUALS_ERROR__INVALID_ORACLE_ACCOUNT = 0x1772; // 6002 /** StaleOraclePrice: Stale oracle price */ export const PERPETUALS_ERROR__STALE_ORACLE_PRICE = 0x1773; // 6003 /** InvalidOraclePrice: Invalid oracle price */ export const PERPETUALS_ERROR__INVALID_ORACLE_PRICE = 0x1774; // 6004 /** InvalidEnvironment: Instruction is not allowed in production */ export const PERPETUALS_ERROR__INVALID_ENVIRONMENT = 0x1775; // 6005 /** InvalidCollateralAccount: Invalid collateral account */ export const PERPETUALS_ERROR__INVALID_COLLATERAL_ACCOUNT = 0x1776; // 6006 /** InvalidCollateralAmount: Invalid collateral amount */ export const PERPETUALS_ERROR__INVALID_COLLATERAL_AMOUNT = 0x1777; // 6007 /** CollateralSlippage: Collateral slippage */ export const PERPETUALS_ERROR__COLLATERAL_SLIPPAGE = 0x1778; // 6008 /** InvalidPositionState: Invalid position state */ export const PERPETUALS_ERROR__INVALID_POSITION_STATE = 0x1779; // 6009 /** InvalidPerpetualsConfig: Invalid perpetuals config */ export const PERPETUALS_ERROR__INVALID_PERPETUALS_CONFIG = 0x177a; // 6010 /** InvalidPoolConfig: Invalid pool config */ export const PERPETUALS_ERROR__INVALID_POOL_CONFIG = 0x177b; // 6011 /** InvalidInstruction: Invalid instruction */ export const PERPETUALS_ERROR__INVALID_INSTRUCTION = 0x177c; // 6012 /** InvalidCustodyConfig: Invalid custody config */ export const PERPETUALS_ERROR__INVALID_CUSTODY_CONFIG = 0x177d; // 6013 /** InvalidCustodyBalance: Invalid custody balance */ export const PERPETUALS_ERROR__INVALID_CUSTODY_BALANCE = 0x177e; // 6014 /** InvalidArgument: Invalid argument */ export const PERPETUALS_ERROR__INVALID_ARGUMENT = 0x177f; // 6015 /** InvalidPositionRequest: Invalid position request */ export const PERPETUALS_ERROR__INVALID_POSITION_REQUEST = 0x1780; // 6016 /** InvalidPositionRequestInputAta: Invalid position request input ata */ export const PERPETUALS_ERROR__INVALID_POSITION_REQUEST_INPUT_ATA = 0x1781; // 6017 /** InvalidMint: Invalid mint */ export const PERPETUALS_ERROR__INVALID_MINT = 0x1782; // 6018 /** InsufficientTokenAmount: Insufficient token amount */ export const PERPETUALS_ERROR__INSUFFICIENT_TOKEN_AMOUNT = 0x1783; // 6019 /** InsufficientAmountReturned: Insufficient token amount returned */ export const PERPETUALS_ERROR__INSUFFICIENT_AMOUNT_RETURNED = 0x1784; // 6020 /** MaxPriceSlippage: Price slippage limit exceeded */ export const PERPETUALS_ERROR__MAX_PRICE_SLIPPAGE = 0x1785; // 6021 /** MaxLeverage: Position leverage limit exceeded */ export const PERPETUALS_ERROR__MAX_LEVERAGE = 0x1786; // 6022 /** CustodyAmountLimit: Custody amount limit exceeded */ export const PERPETUALS_ERROR__CUSTODY_AMOUNT_LIMIT = 0x1787; // 6023 /** PoolAmountLimit: Pool amount limit exceeded */ export const PERPETUALS_ERROR__POOL_AMOUNT_LIMIT = 0x1788; // 6024 /** PersonalPoolAmountLimit: Personal pool amount limit exceeded */ export const PERPETUALS_ERROR__PERSONAL_POOL_AMOUNT_LIMIT = 0x1789; // 6025 /** UnsupportedToken: Token is not supported */ export const PERPETUALS_ERROR__UNSUPPORTED_TOKEN = 0x178a; // 6026 /** InstructionNotAllowed: Instruction is not allowed at this time */ export const PERPETUALS_ERROR__INSTRUCTION_NOT_ALLOWED = 0x178b; // 6027 /** JupiterProgramMismatch: Jupiter Program ID mismatch */ export const PERPETUALS_ERROR__JUPITER_PROGRAM_MISMATCH = 0x178c; // 6028 /** ProgramMismatch: Program ID mismatch */ export const PERPETUALS_ERROR__PROGRAM_MISMATCH = 0x178d; // 6029 /** AddressMismatch: Address mismatch */ export const PERPETUALS_ERROR__ADDRESS_MISMATCH = 0x178e; // 6030 /** KeeperATAMissing: Missing keeper ATA */ export const PERPETUALS_ERROR__KEEPER_A_T_A_MISSING = 0x178f; // 6031 /** SwapAmountMismatch: Swap amount mismatch */ export const PERPETUALS_ERROR__SWAP_AMOUNT_MISMATCH = 0x1790; // 6032 /** CPINotAllowed: CPI not allowed */ export const PERPETUALS_ERROR__C_P_I_NOT_ALLOWED = 0x1791; // 6033 /** InvalidKeeper: Invalid Keeper */ export const PERPETUALS_ERROR__INVALID_KEEPER = 0x1792; // 6034 /** ExceedExecutionPeriod: Exceed execution period */ export const PERPETUALS_ERROR__EXCEED_EXECUTION_PERIOD = 0x1793; // 6035 /** InvalidRequestType: Invalid Request Type */ export const PERPETUALS_ERROR__INVALID_REQUEST_TYPE = 0x1794; // 6036 /** InvalidTriggerPrice: Invalid Trigger Price */ export const PERPETUALS_ERROR__INVALID_TRIGGER_PRICE = 0x1795; // 6037 /** TriggerPriceSlippage: Trigger Price Slippage */ export const PERPETUALS_ERROR__TRIGGER_PRICE_SLIPPAGE = 0x1796; // 6038 /** MissingTriggerPrice: Missing Trigger Price */ export const PERPETUALS_ERROR__MISSING_TRIGGER_PRICE = 0x1797; // 6039 /** MissingPriceSlippage: Missing Price Slippage */ export const PERPETUALS_ERROR__MISSING_PRICE_SLIPPAGE = 0x1798; // 6040 /** InvalidPriceCalcMode: Invalid price calc mode */ export const PERPETUALS_ERROR__INVALID_PRICE_CALC_MODE = 0x1799; // 6041 export type PerpetualsError = | typeof PERPETUALS_ERROR__ADDRESS_MISMATCH | typeof PERPETUALS_ERROR__COLLATERAL_SLIPPAGE | typeof PERPETUALS_ERROR__C_P_I_NOT_ALLOWED | typeof PERPETUALS_ERROR__CUSTODY_AMOUNT_LIMIT | typeof PERPETUALS_ERROR__EXCEED_EXECUTION_PERIOD | typeof PERPETUALS_ERROR__INSTRUCTION_NOT_ALLOWED | typeof PERPETUALS_ERROR__INSUFFICIENT_AMOUNT_RETURNED | typeof PERPETUALS_ERROR__INSUFFICIENT_TOKEN_AMOUNT | typeof PERPETUALS_ERROR__INVALID_ARGUMENT | typeof PERPETUALS_ERROR__INVALID_COLLATERAL_ACCOUNT | typeof PERPETUALS_ERROR__INVALID_COLLATERAL_AMOUNT | typeof PERPETUALS_ERROR__INVALID_CUSTODY_BALANCE | typeof PERPETUALS_ERROR__INVALID_CUSTODY_CONFIG | typeof PERPETUALS_ERROR__INVALID_ENVIRONMENT | typeof PERPETUALS_ERROR__INVALID_INSTRUCTION | typeof PERPETUALS_ERROR__INVALID_KEEPER | typeof PERPETUALS_ERROR__INVALID_MINT | typeof PERPETUALS_ERROR__INVALID_ORACLE_ACCOUNT | typeof PERPETUALS_ERROR__INVALID_ORACLE_PRICE | typeof PERPETUALS_ERROR__INVALID_PERPETUALS_CONFIG | typeof PERPETUALS_ERROR__INVALID_POOL_CONFIG | typeof PERPETUALS_ERROR__INVALID_POSITION_REQUEST | typeof PERPETUALS_ERROR__INVALID_POSITION_REQUEST_INPUT_ATA | typeof PERPETUALS_ERROR__INVALID_POSITION_STATE | typeof PERPETUALS_ERROR__INVALID_PRICE_CALC_MODE | typeof PERPETUALS_ERROR__INVALID_REQUEST_TYPE | typeof PERPETUALS_ERROR__INVALID_TRIGGER_PRICE | typeof PERPETUALS_ERROR__JUPITER_PROGRAM_MISMATCH | typeof PERPETUALS_ERROR__KEEPER_A_T_A_MISSING | typeof PERPETUALS_ERROR__MATH_OVERFLOW | typeof PERPETUALS_ERROR__MAX_LEVERAGE | typeof PERPETUALS_ERROR__MAX_PRICE_SLIPPAGE | typeof PERPETUALS_ERROR__MISSING_PRICE_SLIPPAGE | typeof PERPETUALS_ERROR__MISSING_TRIGGER_PRICE | typeof PERPETUALS_ERROR__PERSONAL_POOL_AMOUNT_LIMIT | typeof PERPETUALS_ERROR__POOL_AMOUNT_LIMIT | typeof PERPETUALS_ERROR__PROGRAM_MISMATCH | typeof PERPETUALS_ERROR__STALE_ORACLE_PRICE | typeof PERPETUALS_ERROR__SWAP_AMOUNT_MISMATCH | typeof PERPETUALS_ERROR__TRIGGER_PRICE_SLIPPAGE | typeof PERPETUALS_ERROR__UNSUPPORTED_ORACLE | typeof PERPETUALS_ERROR__UNSUPPORTED_TOKEN; let perpetualsErrorMessages: Record | undefined; if (process.env.NODE_ENV !== "production") { perpetualsErrorMessages = { [PERPETUALS_ERROR__ADDRESS_MISMATCH]: `Address mismatch`, [PERPETUALS_ERROR__COLLATERAL_SLIPPAGE]: `Collateral slippage`, [PERPETUALS_ERROR__C_P_I_NOT_ALLOWED]: `CPI not allowed`, [PERPETUALS_ERROR__CUSTODY_AMOUNT_LIMIT]: `Custody amount limit exceeded`, [PERPETUALS_ERROR__EXCEED_EXECUTION_PERIOD]: `Exceed execution period`, [PERPETUALS_ERROR__INSTRUCTION_NOT_ALLOWED]: `Instruction is not allowed at this time`, [PERPETUALS_ERROR__INSUFFICIENT_AMOUNT_RETURNED]: `Insufficient token amount returned`, [PERPETUALS_ERROR__INSUFFICIENT_TOKEN_AMOUNT]: `Insufficient token amount`, [PERPETUALS_ERROR__INVALID_ARGUMENT]: `Invalid argument`, [PERPETUALS_ERROR__INVALID_COLLATERAL_ACCOUNT]: `Invalid collateral account`, [PERPETUALS_ERROR__INVALID_COLLATERAL_AMOUNT]: `Invalid collateral amount`, [PERPETUALS_ERROR__INVALID_CUSTODY_BALANCE]: `Invalid custody balance`, [PERPETUALS_ERROR__INVALID_CUSTODY_CONFIG]: `Invalid custody config`, [PERPETUALS_ERROR__INVALID_ENVIRONMENT]: `Instruction is not allowed in production`, [PERPETUALS_ERROR__INVALID_INSTRUCTION]: `Invalid instruction`, [PERPETUALS_ERROR__INVALID_KEEPER]: `Invalid Keeper`, [PERPETUALS_ERROR__INVALID_MINT]: `Invalid mint`, [PERPETUALS_ERROR__INVALID_ORACLE_ACCOUNT]: `Invalid oracle account`, [PERPETUALS_ERROR__INVALID_ORACLE_PRICE]: `Invalid oracle price`, [PERPETUALS_ERROR__INVALID_PERPETUALS_CONFIG]: `Invalid perpetuals config`, [PERPETUALS_ERROR__INVALID_POOL_CONFIG]: `Invalid pool config`, [PERPETUALS_ERROR__INVALID_POSITION_REQUEST]: `Invalid position request`, [PERPETUALS_ERROR__INVALID_POSITION_REQUEST_INPUT_ATA]: `Invalid position request input ata`, [PERPETUALS_ERROR__INVALID_POSITION_STATE]: `Invalid position state`, [PERPETUALS_ERROR__INVALID_PRICE_CALC_MODE]: `Invalid price calc mode`, [PERPETUALS_ERROR__INVALID_REQUEST_TYPE]: `Invalid Request Type`, [PERPETUALS_ERROR__INVALID_TRIGGER_PRICE]: `Invalid Trigger Price`, [PERPETUALS_ERROR__JUPITER_PROGRAM_MISMATCH]: `Jupiter Program ID mismatch`, [PERPETUALS_ERROR__KEEPER_A_T_A_MISSING]: `Missing keeper ATA`, [PERPETUALS_ERROR__MATH_OVERFLOW]: `Overflow in arithmetic operation`, [PERPETUALS_ERROR__MAX_LEVERAGE]: `Position leverage limit exceeded`, [PERPETUALS_ERROR__MAX_PRICE_SLIPPAGE]: `Price slippage limit exceeded`, [PERPETUALS_ERROR__MISSING_PRICE_SLIPPAGE]: `Missing Price Slippage`, [PERPETUALS_ERROR__MISSING_TRIGGER_PRICE]: `Missing Trigger Price`, [PERPETUALS_ERROR__PERSONAL_POOL_AMOUNT_LIMIT]: `Personal pool amount limit exceeded`, [PERPETUALS_ERROR__POOL_AMOUNT_LIMIT]: `Pool amount limit exceeded`, [PERPETUALS_ERROR__PROGRAM_MISMATCH]: `Program ID mismatch`, [PERPETUALS_ERROR__STALE_ORACLE_PRICE]: `Stale oracle price`, [PERPETUALS_ERROR__SWAP_AMOUNT_MISMATCH]: `Swap amount mismatch`, [PERPETUALS_ERROR__TRIGGER_PRICE_SLIPPAGE]: `Trigger Price Slippage`, [PERPETUALS_ERROR__UNSUPPORTED_ORACLE]: `Unsupported price oracle`, [PERPETUALS_ERROR__UNSUPPORTED_TOKEN]: `Token is not supported`, }; } export function getPerpetualsErrorMessage(code: PerpetualsError): string { if (process.env.NODE_ENV !== "production") { return (perpetualsErrorMessages as Record)[code]; } return "Error message not available in production bundles."; } export function isPerpetualsError( error: unknown, transactionMessage: { instructions: Record; }, code?: TProgramErrorCode, ): error is SolanaError & Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { return isProgramError( error, transactionMessage, PERPETUALS_PROGRAM_ADDRESS, code, ); }