# soroswap-router-sdk

> [![npm version](https://badge.fury.io/js/soroswap-router-sdk.svg)](https://badge.fury.io/js/soroswap-router-sdk)

Latest version **1.4.6** (published 2024-10-08) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install soroswap-router-sdk
pnpm add soroswap-router-sdk
yarn add soroswap-router-sdk
bun add soroswap-router-sdk
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.6 |
| Published | 2024-10-08 |
| First published | 2024-02-02 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 13 |
| Unpacked size | 860.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | abstract829 |
| Maintainers | esteblock, coderipper, devmonsterblock |

## Links

- npm: https://www.npmjs.com/package/soroswap-router-sdk
- Repository: https://github.com/soroswap/soroswap-router-sdk
- npm.io page: https://npm.io/package/soroswap-router-sdk

## Dependencies (13)

- [jsbi](https://npm.io/package/jsbi.md) ^4.3.0
- [axios](https://npm.io/package/axios.md) ^1.6.5
- [sinon](https://npm.io/package/sinon.md) ^17.0.1
- [big.js](https://npm.io/package/big.js.md) ^6.2.1
- [bunyan](https://npm.io/package/bunyan.md) ^1.8.15
- [dotenv](https://npm.io/package/dotenv.md) ^16.4.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [toformat](https://npm.io/package/toformat.md) ^2.0.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.1.2
- [tiny-invariant](https://npm.io/package/tiny-invariant.md) ^1.3.1
- [decimal.js-light](https://npm.io/package/decimal.js-light.md) ^2.5.1
- [bigint-conversion](https://npm.io/package/bigint-conversion.md) ^2.4.3
- [@stellar/stellar-sdk](https://npm.io/package/@stellar/stellar-sdk.md) ^11.3.0

## Recent versions

- 1.4.6 (latest) — 2024-10-08
- 1.2.12-beta (beta) — 2024-08-28
- 1.4.0 — 2024-09-30
- 1.3.0 — 2024-09-29
- 1.2.13 — 2024-08-28
- 1.2.12 — 2024-08-28
- 1.2.11-beta — 2024-08-28
- 1.2.10-beta — 2024-08-28
- 1.2.10 — 2024-07-26
- 1.2.9 — 2024-06-26
- 1.2.8 — 2024-06-19
- 1.2.7 — 2024-06-19
- 1.2.6 — 2024-06-06
- 1.2.5 — 2024-06-06
- 1.2.4 — 2024-04-15
- … 34 more at https://npm.io/package/soroswap-router-sdk/versions

## README

# Soroswap Router SDK

[![npm version](https://badge.fury.io/js/soroswap-router-sdk.svg)](https://badge.fury.io/js/soroswap-router-sdk)

This repository contains routing logic for the Soroswap.Finance protocol.

It searches for the most efficient way to swap token A for token B, considering the reserves available in the protocol's liquidity pools.

**Useful links:**

- Documentation: https://soroswap-router-sdk.soroswap.finance/
- NPM Package: https://www.npmjs.com/package/soroswap-router-sdk
- Github Repo: https://github.com/soroswap/soroswap-router-sdk
- [Soroswap.Finance Discord Server](https://discord.gg/QaezKEWXqX)

## Install

```ts
npm i soroswap-router-sdk
```

or

```ts
yarn add soroswap-router-sdk
```

## How to use

```ts
import {
  Router,
  Token,
  CurrencyAmount,
  TradeType,
  Networks,
} from "soroswap-router-sdk";

const XLM_ADDRESS = "CDMLFMKMMD7MWZP3FKUBZPVHTUEDLSX4BYGYKH4GCESXYHS3IHQ4EIG4";
const USDC_ADDRESS = "CAMZFR4BHDUMT6J7INBBBGJG22WMS26RXEYORKC2ERZL2YGDIEEKTOJB";

const XLM_TOKEN = new Token(
  Networks.TESTNET,
  XLM_ADDRESS,
  7,
  "XLM",
  "Stellar Lumens"
);

const USDC_TOKEN = new Token(
  Networks.TESTNET,
  USDC_ADDRESS,
  7,
  "USDC",
  "USD Coin"
);

const amount = 10000000;

const router = new Router({
  pairsCacheInSeconds: 20, // pairs cache duration
  protocols: [Protocols.SOROSWAP], // protocols to be used
  network: Networks.TESTNET, // network to be used
});

const currencyAmount = CurrencyAmount.fromRawAmount(USDC_TOKEN, amount);
const quoteCurrency = XLM_TOKEN;

const route = await router.route(
  currencyAmount,
  quoteCurrency,
  TradeType.EXACT_INPUT
);

console.log(route.trade.path);

//Output: ['0x...', '0x...', '0x...']
```

# Development

## Test

```
bash docker/run.sh
yarn
yarn test
```

## Document

1.- Generate Documentation

```
bash docker/run.sh
yarn
yarn docs
```

## Publish
```
bash docker/run.sh
git config --global --add safe.directory /workspace
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
npm login

yarn
yarn build
yarn publish
```

For beta versions you can use `yarn publish --tag beta`

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