TypeScript SDK
Complete API reference for the MNMX TypeScript SDK.
MnmxRouter
Main entry point for cross-chain routing.
typescript
1import { MnmxRouter } from '@mnmx/core';2
3const router = new MnmxRouter({4 strategy: 'minimax',5 slippageTolerance: 0.5,6 timeout: 30_000,7 bridges: ['wormhole', 'debridge', 'layerzero', 'allbridge'],8 maxHops: 3,9});Methods
| Method | Signature | Description |
|---|---|---|
findRoute | (params: RouteParams) => Promise<Route> | Find the minimax-optimal route |
findAllRoutes | (params: RouteParams) => Promise<Route[]> | Return all viable routes, sorted by minimax score |
execute | (route: Route, opts: ExecOpts) => Promise<ExecResult> | Execute a route with transaction signing and monitoring |
getStatus | (execId: string) => Promise<ExecStatus> | Check execution status of a pending transfer |
RouterConfig
| Field | Type | Default | Description |
|---|---|---|---|
strategy | Strategy | 'minimax' | Routing strategy: minimax, cheapest, fastest, safest |
slippageTolerance | number | 0.5 | Max acceptable slippage (%) |
timeout | number | 30000 | Max total execution time (ms) |
bridges | string[] | all | Bridges to include in path discovery |
maxHops | number | 3 | Maximum intermediate hops |
Route
typescript
1interface Route {2 path: RouteHop[]; // Ordered sequence of hops3 expectedOutput: string; // Best-case output amount4 guaranteedMinimum: string; // Minimax (worst-case) output5 totalFees: string; // Total fees across all hops6 estimatedTime: number; // Expected transfer time (seconds)7 minimaxScore: number; // Combined minimax evaluation score8 strategy: Strategy; // Strategy used for this route9}10
11interface RouteHop {12 type: 'swap' | 'bridge';13 from: { chain: string; token: string };14 to: { chain: string; token: string };15 provider: string; // DEX or bridge name16 fee: string; // Fee for this hop17 estimatedTime: number; // Time for this hop (seconds)18}RouteParams
typescript
1interface RouteParams {2 from: {3 chain: string; // Source chain (e.g., 'ethereum')4 token: string; // Source token (e.g., 'ETH')5 amount: string; // Amount to transfer6 };7 to: {8 chain: string; // Destination chain (e.g., 'solana')9 token: string; // Destination token (e.g., 'SOL')10 };11 options?: {12 excludeBridges?: string[]; // Bridges to exclude13 excludeChains?: string[]; // Intermediate chains to exclude14 deadline?: number; // Max acceptable transfer time (seconds)15 };16}Execution
typescript
1interface ExecOpts {2 signer: Signer; // Wallet signer for transactions3 onProgress?: (step: ExecStep) => void; // Progress callback4 autoRetry?: boolean; // Retry failed steps (default: true)5}6
7interface ExecResult {8 execId: string; // Unique execution ID9 status: 'completed' | 'failed' | 'partial';10 actualOutput: string; // Actual amount received11 totalTime: number; // Actual total time (seconds)12 steps: ExecStep[]; // Detailed step results13 txHashes: string[]; // Transaction hashes per chain14}15
16interface ExecStep {17 hop: RouteHop;18 status: 'pending' | 'executing' | 'completed' | 'failed';19 txHash?: string;20 output?: string;21 error?: string;22}BridgeAdapter Interface
For adding custom bridge support:
typescript
1interface BridgeAdapter {2 name: string;3 supportedChains: Chain[];4
5 getQuote(params: QuoteParams): Promise<BridgeQuote>;6 execute(quote: BridgeQuote, signer: Signer): Promise<BridgeResult>;7 getStatus(txHash: string): Promise<BridgeStatus>;8 getHealth(): Promise<BridgeHealth>;9}10
11interface BridgeQuote {12 bridge: string;13 inputAmount: string;14 outputAmount: string;15 fee: string;16 estimatedTime: number; // seconds17 liquidityDepth: string; // available liquidity18}19
20interface BridgeHealth {21 online: boolean;22 congestion: 'low' | 'medium' | 'high';23 recentSuccessRate: number; // 0.0–1.024 medianConfirmTime: number; // seconds25}Error Types
| Error | When |
|---|---|
NoRouteFoundError | No viable path exists between source and destination |
InsufficientLiquidityError | Transfer amount exceeds available bridge liquidity |
SlippageExceededError | Actual slippage exceeded tolerance during execution |
BridgeTimeoutError | Bridge transfer exceeded maximum wait time |
ExecutionFailedError | Transaction reverted on-chain |