Docs
Docs/Python SDK

Python SDK

Cross-chain route discovery, simulation, and analysis in Python.

Installation

Requires Python 3.10+.

bash
1pip install mnmx-sdk

Basic Usage

python
1from mnmx import MnmxRouter
2
3router = MnmxRouter(strategy="minimax")
4
5route = router.find_route(
6 from_chain="ethereum",
7 from_token="ETH",
8 amount="1.0",
9 to_chain="solana",
10 to_token="SOL",
11)
12
13print(f"Path: {' → '.join(route.path)}")
14print(f"Expected output: {route.expected_output} SOL")
15print(f"Guaranteed minimum: {route.guaranteed_minimum} SOL")
16print(f"Total fees: {route.total_fees}")
17print(f"Estimated time: {route.estimated_time}s")

Compare All Routes

python
1routes = router.find_all_routes(
2 from_chain="ethereum",
3 from_token="ETH",
4 amount="1.0",
5 to_chain="solana",
6 to_token="SOL",
7)
8
9for route in routes:
10 print(f"{' → '.join(route.path)}")
11 print(f" Expected: {route.expected_output} SOL")
12 print(f" Minimum: {route.guaranteed_minimum} SOL")
13 print(f" Score: {route.minimax_score:.4f}")
14 print()

Route Simulation

Simulate routes under various market conditions without executing:

python
1from mnmx import RouteSimulator
2
3sim = RouteSimulator()
4
5# Simulate with adversarial conditions
6result = sim.simulate(route, conditions={
7 "slippage_multiplier": 2.0, # 2x quoted slippage
8 "gas_multiplier": 1.5, # 1.5x current gas
9 "bridge_delay_multiplier": 3.0, # 3x median delay
10 "mev_extraction": 0.003, # 0.3% MEV
11})
12
13print(f"Simulated output: {result.output}")
14print(f"Fees paid: {result.total_fees}")
15print(f"Time: {result.total_time}s")

Monte Carlo Analysis

Run thousands of simulations with randomized conditions to understand the outcome distribution:

python
1mc = sim.monte_carlo(
2 route=route,
3 iterations=10_000,
4 seed=42,
5)
6
7print(f"Mean output: {mc.mean_output:.4f} SOL")
8print(f"5th percentile: {mc.percentile_5:.4f} SOL")
9print(f"95th percentile: {mc.percentile_95:.4f} SOL")
10print(f"Worst observed: {mc.min_output:.4f} SOL")
11print(f"Guaranteed minimum: {route.guaranteed_minimum} SOL")

Batch Route Analysis

Compare strategies across multiple token pairs:

python
1from mnmx import BatchAnalyzer
2
3analyzer = BatchAnalyzer(router)
4
5pairs = [
6 ("ethereum", "ETH", "solana", "SOL", "1.0"),
7 ("ethereum", "USDC", "arbitrum", "USDC", "5000"),
8 ("solana", "SOL", "base", "ETH", "10.0"),
9]
10
11report = analyzer.compare_strategies(
12 pairs=pairs,
13 strategies=["minimax", "cheapest", "fastest"],
14)
15
16print(report.summary())
17# Shows side-by-side comparison of strategies across all pairs

CLI

bash
1# Find optimal route
2mnmx route --from ethereum:ETH:1.0 --to solana:SOL
3
4# Compare all routes
5mnmx route --from ethereum:ETH:1.0 --to solana:SOL --all
6
7# Monte Carlo simulation
8mnmx simulate --from ethereum:ETH:1.0 --to solana:SOL --iterations 10000
9
10# Compare strategies
11mnmx compare --from ethereum:ETH:1.0 --to solana:SOL

Error Handling

ExceptionWhen
MnmxErrorBase class for all SDK errors
NoRouteFoundErrorNo viable path exists
InsufficientLiquidityErrorBridge liquidity below transfer amount
SimulationErrorInvalid simulation parameters
TimeoutErrorRoute discovery exceeded time limit
python
1from mnmx.exceptions import NoRouteFoundError
2
3try:
4 route = router.find_route(
5 from_chain="ethereum", from_token="ETH", amount="1.0",
6 to_chain="solana", to_token="SOL",
7 )
8except NoRouteFoundError as e:
9 print(f"No route available: {e.reason}")