---
name: routing-dex-trades
description: 'Route trades across multiple DEXs to find optimal prices with minimal slippage and gas costs.

  Use when comparing DEX prices, finding optimal swap routes, analyzing price impact, splitting large orders, or assessing MEV risk.

  Trigger with phrases like "find best swap", "compare DEX prices", "route trade", "optimal swap route", "split order", "DEX aggregator", "check slippage", or "MEV protection".'
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(crypto:dex-*)
version: 1.26.0
author: Jeremy Longshore <jeremy@intentsolutions.io>
license: MIT
tags:
  - crypto
  - cost-optimization
  - routing-dex
compatibility: Designed for Claude Code
title: routing-dex-trades
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades
last_updated: 2026-10-23T05:08:30.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [ARD.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/ARD.md), [config/settings.yaml](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/config/settings.yaml), [PRD.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/PRD.md), [references/errors.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/errors.md), [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/implementation.md), [scripts/dex_router.py](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/scripts/dex_router.py), [scripts/formatters.py](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/scripts/formatters.py), [scripts/mev_assessor.py](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/scripts/mev_assessor.py), [scripts/quote_fetcher.py](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/scripts/quote_fetcher.py), [scripts/route_optimizer.py](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/scripts/route_optimizer.py), [scripts/split_calculator.py](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/scripts/split_calculator.py).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/routing-dex-trades`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/routing-dex-trades`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/routing-dex-trades`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/routing-dex-trades --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/routing-dex-trades --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Routing DEX Trades

## Contents

[Overview](#overview) | [Prerequisites](#prerequisites) | [Instructions](#instructions) | [Output](#output) | [Error Handling](#error-handling) | [Examples](#examples) | [Resources](#resources)

## Overview

Optimal trade routing across decentralized exchanges by aggregating quotes from 1inch, Paraswap, and 0x. Discovers multi-hop routes, calculates split orders for large trades, and assesses MEV risk to minimize slippage and gas costs.

## Prerequisites

1. Install Python 3.9+ with `httpx`, `pydantic`, and `rich` packages
2. Verify network access to aggregator APIs (1inch, Paraswap, 0x)
3. Optionally add API keys for 1inch and 0x (higher rate limits)
4. Copy settings: `cp ${CLAUDE_SKILL_DIR}/config/settings.yaml.example ${CLAUDE_SKILL_DIR}/config/settings.yaml`

## Instructions

1. Get a quick quote for the single best price with gas cost and effective rate:

   ```bash
   python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 1.0
   ```

2. Compare all DEXs to see quotes ranked by effective rate (after gas):

   ```bash
   python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 5.0 --compare
   ```

3. Analyze multi-hop routes to compare direct vs. multi-hop (2-3 pools) with hop-by-hop breakdown:

   ```bash
   python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 10.0 --routes
   ```

4. Split large orders ($10K+) across multiple DEXs to minimize total price impact:

   ```bash
   python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 100.0 --split
   ```

5. Assess MEV risk (sandwich attack risk score: LOW/MEDIUM/HIGH) before executing:

   ```bash
   python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 50.0 --mev-check
   ```

6. Run full analysis combining all features for comprehensive output:

   ```bash
   python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 25.0 --full --output json
   ```

## Output

- **Quick Quote**: Best price, output amount, gas cost, recommended venue
- **Comparison**: All venues ranked by effective rate with price impact and gas
- **Route Analysis**: Direct vs. multi-hop with hop-by-hop breakdown
- **Split Mode**: Optimal allocation percentages with dollar savings vs. single-venue
- **MEV Assessment**: Risk score, exposure estimate, protection recommendations

See [`references/implementation.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/implementation.md) for detailed output examples.

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| API Rate Limited | Too many requests | Wait 60s or add API key for higher limits |
| Quote Expired | Stale price data | Refresh before execution; quotes valid ~30s |
| No Route Found | Low liquidity token | Try larger DEXs or reduce trade size |
| Network Timeout | Aggregator down | Retry or check aggregator status page |

See [`references/errors.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/errors.md) for comprehensive error handling.

## Examples

**Compare prices for a 5 ETH swap:**

```bash
python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 5.0 --compare
```

**Find optimal split for a large order:**

```bash
python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 100.0 --split
```

**Check MEV risk before executing:**

```bash
python ${CLAUDE_SKILL_DIR}/scripts/dex_router.py ETH USDC 50.0 --mev-check
```

See [`references/examples.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/examples.md) for multi-hop discovery and MEV-protected execution examples.

## Resources

- [`references/implementation.md`](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/routing-dex-trades/references/implementation.md) - Trade size guide, split optimization, MEV scoring, API config
- [1inch API](https://docs.1inch.io/) - Primary aggregator
- [Paraswap API](https://developers.paraswap.network/) - Secondary aggregator
- [0x API](https://0x.org/docs/api) - Third aggregator
- [Flashbots Protect](https://docs.flashbots.net/flashbots-protect/overview) - MEV protection
