UNPKG

@stabilis/c9-shape-liquidity-getter

Version:

A library for calculating redemption values of concentrated liquidity positions for C9 shape liquidity.

120 lines (119 loc) 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NFTError = exports.ComponentError = exports.DataError = exports.NetworkError = exports.ValidationError = exports.BaseError = void 0; /** * Base error class for the library */ class BaseError extends Error { constructor(message, code, statusCode, details) { super(message); this.code = code; this.statusCode = statusCode; this.details = details; this.name = this.constructor.name; Error.captureStackTrace(this, this.constructor); } } exports.BaseError = BaseError; /** * Input validation errors */ class ValidationError extends BaseError { constructor(message, details) { super(message, "VALIDATION_ERROR", 400, details); } static invalidComponentAddress(address) { return new ValidationError(`Invalid component address: ${address}`); } static invalidNftId(id) { return new ValidationError(`Invalid NFT ID: ${id}`); } static invalidNftIds() { return new ValidationError("Invalid NFT IDs array"); } static invalidStateVersion(version) { return new ValidationError(`Invalid state version: ${version}`); } static invalidPriceBounds() { return new ValidationError("Invalid price bounds. Must be [lowerMultiplier, upperMultiplier] where lowerMultiplier > 0 and lowerMultiplier < upperMultiplier"); } static invalidMiddlePrice() { return new ValidationError("Invalid middle price. Must be a positive number"); } } exports.ValidationError = ValidationError; /** * Network-related errors */ class NetworkError extends BaseError { constructor(message, statusCode, details) { super(message, "NETWORK_ERROR", statusCode, details); } static requestFailed(message, statusCode) { return new NetworkError(message, statusCode); } static timeout(operation) { return new NetworkError(`Operation timed out: ${operation}`, 408); } } exports.NetworkError = NetworkError; /** * Data-related errors */ class DataError extends BaseError { constructor(message, details) { super(message, "DATA_ERROR", 422, details); } static notFound(type, id) { return new DataError(`${type} not found: ${id}`, { type, id }); } static invalidFormat(type, details) { return new DataError(`Invalid ${type} format`, details); } static stateVersionTooHigh(version) { return new DataError("State version is beyond the end of the known ledger", { version }); } static missingData(type, field) { return new DataError(`Missing ${type} data: ${field}`, { type, field }); } } exports.DataError = DataError; /** * Component-specific errors */ class ComponentError extends BaseError { constructor(message, details) { super(message, "COMPONENT_ERROR", 422, details); } static notC9Component(address) { return new ComponentError("Not a C9 component", { address }); } static invalidState(address, details) { return new ComponentError("Invalid component state", { address, ...details, }); } static missingField(address, field) { return new ComponentError(`Missing component field: ${field}`, { address, field, }); } } exports.ComponentError = ComponentError; /** * NFT-related errors */ class NFTError extends BaseError { constructor(message, details) { super(message, "NFT_ERROR", 422, details); } static invalidClaims(nftId) { return new NFTError("Invalid or missing liquidity claims", { nftId }); } static notFound(nftId) { return new NFTError("NFT not found", { nftId }); } } exports.NFTError = NFTError;