import { SovereignError } from "@sovereign-sdk/web3";
/**
 * Structured error details from rollup responses.
 *
 * Standard fields: domain, code, message
 * All other fields are dynamic and specific to each error type.
 */
export interface RollupErrorDetails {
    /** Error domain/category (e.g., 'risk_engine', 'account', 'order') */
    domain: string;
    /** Specific error code (e.g., 'stale_price', 'insufficient_margin') */
    code: string;
    /** Detailed error message from the rollup (thiserror Display) */
    message: string;
    /**
     * Additional dynamic fields specific to each error type.
     *
     * Examples:
     * - StalePrice: id, price_kind, last_update_timestamp, current_timestamp
     * - InsufficientMargin: address, available_margin, required_margin, margin_type
     * - OrderNotFound: order_id, market_id, market_type
     */
    [key: string]: unknown;
}
/**
 * Error class for Bullet SDK transaction execution errors.
 *
 * Wraps errors from `rollup.call()` and provides structured rollup module error details.
 * HTTP/API errors from data fetching are not wrapped and bubble up as Sovereign SDK errors.
 *
 * @example
 * ```typescript
 * try {
 *   await client.placeOrders("BTC-USD", [...]);
 * } catch (error) {
 *   if (isBulletError(error)) {
 *     console.log(error.code);     // 'stale_price'
 *     console.log(error.domain);   // 'risk_engine'
 *     console.log(error.message);  // 'Stale price - mark 1, last_update: 0, current: 1762425013275'
 *
 *     // Access error-specific fields via details
 *     console.log(error.details.id);
 *     console.log(error.details.price_kind);
 *     console.log(error.details.current_timestamp);
 *
 *     // Type-safe error handling
 *     if (error.domain === 'account' && error.code === 'insufficient_margin') {
 *       const { available_margin, required_margin } = error.details;
 *       showDepositModal(Number(required_margin) - Number(available_margin));
 *     }
 *   }
 * }
 * ```
 */
export declare class BulletError extends SovereignError {
    /** Specific error code (e.g., 'stale_price', 'insufficient_margin') */
    readonly code: string;
    /** Error domain/category (e.g., 'risk_engine', 'account', 'order') */
    readonly domain: string;
    /** HTTP status code */
    readonly status?: number;
    /**
     * Structured error details from the rollup.
     * Contains all error-specific fields.
     * For ModuleError format: has domain and code.
     * For non-ModuleError format: just contains the original error details.
     */
    readonly details: RollupErrorDetails | Record<string, unknown>;
    /** Original error that caused this */
    readonly cause?: Error;
    private constructor();
    /**
     * Creates a BulletError from a Sovereign SDK transaction error.
     *
     * Only use this for errors from `rollup.call()` which contain structured
     * rollup module error details. HTTP/API errors should bubble up naturally.
     *
     * @param error - Error from rollup.call() transaction execution
     * @returns A properly structured BulletError
     */
    static from(error: unknown): BulletError;
    /**
     * Serializes the error to JSON (safe for React state, Redux, etc.)
     */
    toJSON(): {
        name: string;
        code: string;
        domain: string;
        message: string;
        status: number | undefined;
        details: RollupErrorDetails | Record<string, unknown>;
        stack: string | undefined;
    };
    /**
     * Returns a developer-friendly string representation.
     *
     * @example
     * "[risk_engine:stale_price] Stale price - mark 1, last_update: 0, current: 1762425013275"
     */
    toString(): string;
}
/**
 * Type guard to check if an error is a BulletError.
 *
 * @example
 * ```typescript
 * catch (error) {
 *   if (isBulletError(error)) {
 *     console.log(error.code, error.domain, error.details);
 *   }
 * }
 * ```
 */
export declare function isBulletError(error: unknown): error is BulletError;
/**
 * Helper to create type-safe error handlers for specific error types.
 *
 * @example
 * ```typescript
 * const handleStalePrice = createErrorHandler(
 *   'risk_engine',
 *   'stale_price',
 *   (error) => {
 *     // Access fields via error.details
 *     console.log(`Stale price for ${error.details.id}`);
 *     console.log(`Price kind: ${error.details.price_kind}`);
 *     retryWithFreshData();
 *   }
 * );
 *
 * try {
 *   await client.placeOrder(...);
 * } catch (error) {
 *   if (isBulletError(error)) {
 *     handleStalePrice(error);
 *   }
 * }
 * ```
 */
export declare function createErrorHandler(domain: string, code: string, handler: (error: BulletError) => void): (error: BulletError) => boolean;
/**
 * Type guard with specific domain/code check.
 * Useful for narrowing error types in conditional logic.
 *
 * @example
 * ```typescript
 * if (isErrorType(error, 'risk_engine', 'stale_price')) {
 *   // error is BulletError with domain='risk_engine' and code='stale_price'
 *   const { id, price_kind } = error.details;
 * }
 * ```
 */
export declare function isErrorType(error: unknown, domain: string, code: string): error is BulletError;
/**
 * Custom AbortError class that works in both browser and Node.js environments.
 * Matches the behavior of DOMException with name "AbortError" for consistent error handling.
 *
 * This is the standard approach for isomorphic SDKs - using a custom error class
 * rather than runtime feature detection ensures predictable behavior across all environments.
 */
export declare class AbortError extends Error {
    constructor(message?: string);
}
/**
 * Type guard to check if an error is an AbortError.
 * Works with both custom AbortError and DOMException (browser).
 *
 * @example
 * ```typescript
 * try {
 *   await client.subscribeOrderbook(market, signal);
 * } catch (error) {
 *   if (isAbortError(error)) {
 *     // Expected cancellation, ignore
 *     return;
 *   }
 *   // Handle other errors
 * }
 * ```
 */
export declare function isAbortError(error: unknown): error is AbortError | Error;
//# sourceMappingURL=error.d.ts.map