Skip to content

jeremylongshore/tons-of-skills-marketplace / plugins/crypto/dex-aggregator-router/skills/routing-dex-trades

routing-dex-trades

Verified

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".

FileKindSize
ARD.mdmarkdown21.4 KB
PRD.mdmarkdown8.0 KB
SKILL.mdskill md4.4 KB
config/settings.yamlconfig2.8 KB
references/errors.mdmarkdown4.7 KB
references/examples.mdmarkdown8.5 KB
references/implementation.mdmarkdown3.2 KB
scripts/dex_router.pyscript9.7 KB
scripts/formatters.pyscript18.9 KB
scripts/mev_assessor.pyscript13.7 KB
scripts/quote_fetcher.pyscript16.3 KB
scripts/route_optimizer.pyscript10.5 KB
scripts/split_calculator.pyscript11.4 KB

references/implementation.md

View on GitHub
# Implementation Details

## Trade Size Recommendations

| Trade Size | Strategy | Notes |
|------------|----------|-------|
| < $1K | Direct quote | Gas may exceed savings from optimization |
| $1K - $10K | Compare + routes | Multi-hop can save 0.1-0.5% |
| $10K - $100K | Split analysis | 2-3 way splits reduce price impact |
| > $100K | Full + MEV + private TX | Consider OTC or algorithmic execution |

## Split Order Optimization

For large trades ($10K+), the router calculates optimal allocation across venues:

```
Split Recommendation:
  60% via Uniswap V3  (60 ETH -> 152,589 USDC)
  40% via Curve       (40 ETH -> 101,843 USDC)
  ─────────────────────────────────────────────
  Total: 254,432 USDC (vs. 251,200 single-venue)
  Improvement: +1.28% ($3,232 saved)
```

The optimization algorithm:

1. Queries each venue for the full trade amount to measure price impact curves
2. Uses gradient descent to find the allocation that minimizes total slippage
3. Accounts for gas costs of multiple transactions (splitting adds ~$5-15 per venue)
4. Only recommends splitting when savings exceed additional gas overhead

## Output Mode Details

**Quick Quote Mode:**

- Best price across aggregators, output amount, effective rate, gas estimate, recommended venue

**Comparison Mode (`--compare`):**

- All venues ranked by effective rate (price minus gas)
- Price impact percentage per venue
- Gas costs compared in USD
- Liquidity depth indicators (shallow/moderate/deep)

**Route Analysis (`--routes`):**

- Direct vs. multi-hop comparison
- Hop-by-hop breakdown with intermediate tokens
- Cumulative price impact at each hop
- Gas cost per route type

**Split Mode (`--split`):**

- Optimal allocation percentages across venues
- Per-venue output amounts
- Total vs. single-venue comparison
- Dollar savings estimate

**MEV Assessment (`--mev-check`):**

- Risk score: LOW/MEDIUM/HIGH
- Estimated sandwich attack exposure in USD
- Protection recommendations (Flashbots Protect, CoW Swap, private mempool)
- Alternative MEV-resistant venues

## MEV Risk Scoring

The MEV check analyzes:

- **Token pair popularity**: High-volume pairs attract more MEV bots
- **Trade size relative to pool**: Larger trades = more profitable to sandwich
- **Current mempool activity**: Active searcher presence
- **Slippage tolerance**: Higher tolerance = more extractable value

Risk levels:

- **LOW** (score 0-30): Safe to execute via public mempool
- **MEDIUM** (score 31-70): Consider private transaction relay
- **HIGH** (score 71-100): Use Flashbots Protect or CoW Swap batch auctions

## API Configuration

Edit `${CLAUDE_SKILL_DIR}/config/settings.yaml`:

```yaml
api_keys:
  oneinch: "your-1inch-api-key"    # Optional, increases rate limits
  zerox: "your-0x-api-key"         # Optional

chain: ethereum                     # Default: ethereum, arbitrum, polygon, optimism

aggregators:
  - name: 1inch
    enabled: true
    timeout: 10
  - name: paraswap
    enabled: true
    timeout: 10
  - name: zerox
    enabled: true
    timeout: 10
```

---
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall