import type { ChainId } from './client'; import { MAX_BPS } from './constants'; export class GauntletSDKError extends Error { constructor(message: string) { super(message); this.name = 'GauntletSDKError'; } } export class VaultNotFoundError extends GauntletSDKError { readonly vaultId: string; readonly chainId?: ChainId; constructor(vaultId: string, chainId?: ChainId) { const msg = chainId ? `Vault "${vaultId}" not found on chainId "${chainId}"` : `Vault "${vaultId}" not found`; super(msg); this.name = 'VaultNotFoundError'; this.vaultId = vaultId; this.chainId = chainId; } } export class UnsupportedAssetError extends GauntletSDKError { readonly asset: string; readonly vaultId: string; constructor(asset: string, vaultId: string) { super(`Asset "${asset}" is not supported by vault "${vaultId}"`); this.name = 'UnsupportedAssetError'; this.asset = asset; this.vaultId = vaultId; } } export class ChainMismatchError extends GauntletSDKError { readonly expected: string; readonly received: string; constructor(expected: string, received: string) { super(`Chain mismatch: expected "${expected}", received "${received}"`); this.name = 'ChainMismatchError'; this.expected = expected; this.received = received; } } export class UnsupportedDepositModeError extends GauntletSDKError { readonly vaultId: string; readonly requested: string; readonly available: string; constructor(vaultId: string, requested: string, available: string) { super(`Vault "${vaultId}" does not support ${requested} operations (available: ${available})`); this.name = 'UnsupportedDepositModeError'; this.vaultId = vaultId; this.requested = requested; this.available = available; } } export class RpcNotConfiguredError extends GauntletSDKError { readonly chainId: ChainId; constructor(chainId: ChainId) { super(`No client configured for chainId "${chainId}"`); this.name = 'RpcNotConfiguredError'; this.chainId = chainId; } } export class AccountRequiredError extends GauntletSDKError { constructor() { super( 'No account specified. Pass the required account, or configure a wallet when building transactions.' ); this.name = 'AccountRequiredError'; } } export class AccountMismatchError extends GauntletSDKError { readonly expected: string; readonly received: string; constructor(expected: string, received: string) { super(`Account mismatch: expected "${expected}", received "${received}"`); this.name = 'AccountMismatchError'; this.expected = expected; this.received = received; } } export class UnsupportedProtocolError extends GauntletSDKError { readonly protocol: string; constructor(protocol: string) { super(`Unsupported protocol: "${protocol}"`); this.name = 'UnsupportedProtocolError'; this.protocol = protocol; } } export class InvalidWithdrawParamsError extends GauntletSDKError { constructor() { super('Withdraw requires exactly one of: shares, amount, or all'); this.name = 'InvalidWithdrawParamsError'; } } export type SyncWithdrawBound = 'tokensOut' | 'minTokensOut' | 'unitsIn' | 'maxUnitsIn'; export class InvalidSyncWithdrawBoundError extends GauntletSDKError { readonly bound: SyncWithdrawBound; constructor(bound: SyncWithdrawBound) { super(`Sync withdraw cannot submit zero ${bound}; increase the amount or reduce slippage`); this.name = 'InvalidSyncWithdrawBoundError'; this.bound = bound; } } export function requireNonZeroSyncWithdrawBound(value: bigint, bound: SyncWithdrawBound) { if (value === 0n) throw new InvalidSyncWithdrawBoundError(bound); } export class UnimplementedFeatureError extends GauntletSDKError { readonly feature: string; constructor(feature: string) { super(`Feature not yet implemented: "${feature}"`); this.name = 'UnimplementedFeatureError'; this.feature = feature; } } export class UnsupportedFeatureError extends GauntletSDKError { readonly feature: string; constructor(feature: string) { super(`Feature not supported: "${feature}"`); this.name = 'UnsupportedFeatureError'; this.feature = feature; } } export class UnitConversionError extends GauntletSDKError { readonly vaultAddress: string; constructor(vaultAddress: string) { super(`Failed to convert token units for vault "${vaultAddress}": fee calculator unavailable`); this.name = 'UnitConversionError'; this.vaultAddress = vaultAddress; } } export class StalePriceError extends GauntletSDKError { readonly blockTimestamp: bigint; readonly maxPriceAge: bigint; readonly priceTimestamp: bigint; constructor({ blockTimestamp, maxPriceAge, priceTimestamp, }: { blockTimestamp: bigint; maxPriceAge: bigint; priceTimestamp: bigint; }) { super( `Price is stale: timestamp "${priceTimestamp}" with max age "${maxPriceAge}" is older than block timestamp "${blockTimestamp}"` ); this.name = 'StalePriceError'; this.blockTimestamp = blockTimestamp; this.maxPriceAge = maxPriceAge; this.priceTimestamp = priceTimestamp; } } export class InvalidSolverTipError extends GauntletSDKError { readonly solverTip: bigint; readonly availableAmount: bigint; constructor(solverTip: bigint, availableAmount: bigint) { super( `Solver tip "${solverTip}" must be less than available token amount "${availableAmount}"` ); this.name = 'InvalidSolverTipError'; this.solverTip = solverTip; this.availableAmount = availableAmount; } } export class InvalidSlippageBPSError extends GauntletSDKError { readonly slippage: number; constructor(slippage: number) { super(`Slippage not in range of 0-${Number(MAX_BPS)}; argument passed: ${slippage}`); this.name = 'IncorrectArgument'; this.slippage = slippage; } }