# sushi-router

> Sushi Router

Latest version **0.0.19** (published 2024-04-14) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install sushi-router
pnpm add sushi-router
yarn add sushi-router
bun add sushi-router
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.19 |
| Published | 2024-04-14 |
| First published | 2024-04-14 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 3.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rouzwelt |
| Maintainers | rouzwelt |
| Keywords | sushi, routers |

## Links

- npm: https://www.npmjs.com/package/sushi-router
- Repository: https://github.com/rouzwelt/sushi-router
- Homepage: https://github.com/rouzwelt/sushi-router#readme
- Issues: https://github.com/rouzwelt/sushi-router/issues
- npm.io page: https://npm.io/package/sushi-router

## Dependencies (3)

- [viem](https://npm.io/package/viem.md) 1.16.2
- [sushi](https://npm.io/package/sushi.md) =3.0.0
- [memoize-fs](https://npm.io/package/memoize-fs.md) github:rouzwelt/memoize-fs#e5fcc9f6effc4ad087514372a53a49d380520ad5

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.0.19 (latest) — 2024-04-14
- 0.0.18 — 2024-04-14
- 0.0.17 — 2024-04-14

## README

# SushiSwap Router Standalone

This is standalone fork of sushiswap router lib v0.0.16 with option of block number and memoize for data fetching

- All of the source code and dependencies (except `viem`, `memoize-fs` and `sushi`) of this library has been bundled into a single file, but only source code typings are available.
- Requires `sushi` lib v3.0.0.
- Requires `viem` lib v1.6.0 as the JSON-RPC handler which is bundled.
- Requires `memoize-fs` lib from `github:rouzwelt/memoize-fs#e5fcc9f6effc4ad087514372a53a49d380520ad5`.

insall:
```sh
npm install 'rouzwelt/sushi-router',
```

# Tutorial
```typescript
import { Token } from "sushi/currency";
import { fallback, http, createPublicClient } from "viem";
import { DataFetcher, Router, LiquidityProviders, config } from "sushi-router";

const transport = fallback(
  [
    http(rpcUrl),
    http(otherUrl),
    http(anotherUrl)
  ],
  { rank: true }
);

const dataFetcher = new DataFetcher(
  chainId,
  createPublicClient({
    chain: config[chainId]?.chain,
    transport
  })
);

// start the data fetcher with desired liquidity providers
const liquidityProviders = [
  LiquidityProviders.SushiSwapV2,
  LiquidityProviders.SushiSwapV3
]
dataFetcher.startDataFetching(liquidityProviders);

// get pools and data for a token pair
const fromToken = new Token({
  chainId,
  decimals,
  address,
});
const toToken = new Token({
  chainId,
  decimals,
  address,
});

// use memozie or block number as optional args for getting pool 
// data at specific block height and memoize the result, if omitted
// the data will be at last block number and not memoized
await dataFetcher.fetchPoolsForToken(fromToken, toToken, excludePools, { blockNumber: 123n, memoize: true });

// find the best route
const pcMap = dataFetcher.getCurrentPoolCodeMap(fromToken, toToken);
const route = Router.findBestRoute(
  pcMap,
  chainId,
  fromToken,
  amountIn,
  toToken,
  gasPrice.toNumber()
);
if (route.status == "NoWay") throw "found no route for this token pair";

// build price, be aware of each token decimals, should factor them yourself
const price = route.amountOutBI / amountIn;
console.log(price);

// get params for calling RouteProcessor3 contract
const params = Router.routeProcessor2Params(
  pcMap,
  route,
  fromToken,
  toToken,
  receiverAddress,
  routeProcessor3Address,
);
```

---
_Source: https://npm.io/package/sushi-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
