npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pulsadev/defi-router

v0.1.0

Published

DEX swap router — optimal path finding, multi-hop routing, price quotes, calldata generation. Zero dependencies, pure RPC.

Downloads

42

Readme

@pulsadev/defi-router

DEX swap router — optimal path finding, multi-hop routing, price quotes, multi-DEX comparison, calldata generation. Zero dependencies, pure RPC.

Find the best swap route across multiple DEXes and paths. Build transaction calldata ready to submit. No SDK required.

Features

  • Optimal path finding — direct and multi-hop routes via intermediate tokens
  • Multi-DEX comparison — compare quotes across Uniswap, SushiSwap, PancakeSwap, etc.
  • Price quotes — getAmountsOut / getAmountsIn with accurate fee calculation
  • Swap calldata generation — build ready-to-submit transaction data
  • Price impact calculation — know your slippage before swapping
  • 7 chains / 10+ DEXes — Ethereum, BSC, Polygon, Arbitrum, Optimism, Base, Avalanche
  • Auto chain detection — pass an RPC URL, DEX config loads automatically
  • Built-in intermediate tokens — WETH, USDC, USDT, DAI per chain for multi-hop routing
  • Uniswap V2 math — pure JS constant product AMM calculations
  • Zero dependencies — ~12 KB bundled, ESM + CJS, pure TypeScript

Install

npm install @pulsadev/defi-router

Quick Start

Get a swap quote

import { DefiRouter } from '@pulsadev/defi-router'

const router = new DefiRouter({ rpcUrl: 'https://ethereum-rpc.publicnode.com' })

const quote = await router.getQuote(
  '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  1000000000000000000n, // 1 ETH
)

console.log(`Best output: ${quote.bestAmountOut} USDC`)
console.log(`Via: ${quote.bestRoute.dex.name}`)
console.log(`Path: ${quote.bestRoute.path.join(' → ')}`)
console.log(`Price impact: ${quote.bestRoute.priceImpact}%`)
console.log(`Routes found: ${quote.routes.length}`)

Compare across DEXes

const best = await router.findBestDex(WETH, USDC, 1000000000000000000n)
console.log(`Best DEX: ${best.dex.name} — ${best.amountOut} out`)

Build swap calldata

const calldata = router.buildSwapCalldata({
  tokenIn: WETH,
  tokenOut: USDC,
  amountIn: 1000000000000000000n,
  slippageBps: 50, // 0.5%
  recipient: '0xYourAddress...',
}, quote.bestRoute)

// Ready to submit
console.log(`To: ${calldata.to}`)
console.log(`Data: ${calldata.data}`)
console.log(`Value: ${calldata.value}`)

Use on any chain

// Auto-detects chain and loads DEX config
const bscRouter = new DefiRouter({ rpcUrl: 'https://bsc-dataseed.binance.org' })
const polygonRouter = new DefiRouter({ rpcUrl: 'https://polygon-bor-rpc.publicnode.com', chainId: 137 })

API

new DefiRouter(options)

| Option | Type | Description | |--------|------|-------------| | rpcUrl | string | RPC endpoint URL | | chainId | number | Chain ID (auto-detected if omitted) | | dexes | DexConfig[] | Custom DEX configs (auto-loaded if omitted) | | intermediateTokens | Address[] | Tokens for multi-hop (auto-loaded if omitted) |

Methods

| Method | Description | |--------|-------------| | getQuote(tokenIn, tokenOut, amountIn) | Find all routes and return best quote | | getAmountsOut(dex, path, amountIn) | Calculate output amounts along a path | | findBestDex(tokenIn, tokenOut, amountIn) | Compare single-hop across all DEXes | | buildSwapCalldata(params, route) | Build swapExactTokensForTokens calldata | | buildSwapExactETHCalldata(params, route) | Build swapExactETHForTokens calldata | | pairExists(dex, tokenA, tokenB) | Check if a pair exists | | getDexes() | Get configured DEX list | | getIntermediateTokens() | Get intermediate token list |

Standalone utilities

| Function | Description | |----------|-------------| | getAmountOut(amountIn, reserveIn, reserveOut, feeBps) | Uniswap V2 output calculation | | getAmountIn(amountOut, reserveIn, reserveOut, feeBps) | Uniswap V2 input calculation | | getPriceImpact(amountIn, reserveIn) | Calculate price impact % | | getPairAddress(rpcUrl, factory, tokenA, tokenB) | Query pair address from factory | | getPairReserves(rpcUrl, pairAddress) | Get pair reserves | | sortTokens(tokenA, tokenB) | Sort token pair |

Supported DEXes

| Chain | DEXes | |-------|-------| | Ethereum (1) | Uniswap V2, SushiSwap | | BSC (56) | PancakeSwap V2 | | Polygon (137) | QuickSwap, SushiSwap | | Arbitrum (42161) | SushiSwap | | Optimism (10) | Velodrome | | Base (8453) | Uniswap V2 | | Avalanche (43114) | TraderJoe |

License

MIT © Yuto Nakamura