Docs
Docs/TypeScript SDK

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

MethodSignatureDescription
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

FieldTypeDefaultDescription
strategyStrategy'minimax'Routing strategy: minimax, cheapest, fastest, safest
slippageTolerancenumber0.5Max acceptable slippage (%)
timeoutnumber30000Max total execution time (ms)
bridgesstring[]allBridges to include in path discovery
maxHopsnumber3Maximum intermediate hops

Route

typescript
1interface Route {
2 path: RouteHop[]; // Ordered sequence of hops
3 expectedOutput: string; // Best-case output amount
4 guaranteedMinimum: string; // Minimax (worst-case) output
5 totalFees: string; // Total fees across all hops
6 estimatedTime: number; // Expected transfer time (seconds)
7 minimaxScore: number; // Combined minimax evaluation score
8 strategy: Strategy; // Strategy used for this route
9}
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 name
16 fee: string; // Fee for this hop
17 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 transfer
6 };
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 exclude
13 excludeChains?: string[]; // Intermediate chains to exclude
14 deadline?: number; // Max acceptable transfer time (seconds)
15 };
16}

Execution

typescript
1interface ExecOpts {
2 signer: Signer; // Wallet signer for transactions
3 onProgress?: (step: ExecStep) => void; // Progress callback
4 autoRetry?: boolean; // Retry failed steps (default: true)
5}
6
7interface ExecResult {
8 execId: string; // Unique execution ID
9 status: 'completed' | 'failed' | 'partial';
10 actualOutput: string; // Actual amount received
11 totalTime: number; // Actual total time (seconds)
12 steps: ExecStep[]; // Detailed step results
13 txHashes: string[]; // Transaction hashes per chain
14}
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; // seconds
17 liquidityDepth: string; // available liquidity
18}
19
20interface BridgeHealth {
21 online: boolean;
22 congestion: 'low' | 'medium' | 'high';
23 recentSuccessRate: number; // 0.0–1.0
24 medianConfirmTime: number; // seconds
25}

Error Types

ErrorWhen
NoRouteFoundErrorNo viable path exists between source and destination
InsufficientLiquidityErrorTransfer amount exceeds available bridge liquidity
SlippageExceededErrorActual slippage exceeded tolerance during execution
BridgeTimeoutErrorBridge transfer exceeded maximum wait time
ExecutionFailedErrorTransaction reverted on-chain