This TypeScript SDK simplifies integration with decentralized exchanges (DEXs) on the Sui blockchain, allowing developers to execute token swaps in Move-based PTB applications or directly leverage the SDK for optimized token swaps across multiple sources for the best prices.
For full details, please see the Documentation.
- Cetus
- Turbos
- DeepBook v3
- Aftermath
- Kriya v2/v3
npm i navi-aggregator-sdk
- Get Quote
Pass in the fromCoin, toCoin, and amountIn. The output will be the quote for the swap.
import { getRoute } from 'navi-aggregator-sdk';
const quote = await getRoute(fromCoin: string, toCoin: string, amountIn: number | string | bigint);
console.log(`Amount In: ${quote.amount_in}, Amount Out: ${quote.amount_out}`);
console.log(`Routes: ${quote.routes}`);
- Coin-In-Coin-Out PTB function
Pass in a coinObject as the coin parameter. The output will be the final coin object after the swap.
import { swapPTB } from 'navi-aggregator-sdk';
const coinB = await swapPTB(
address: string,
txb: Transaction,
fromCoin: string,
toCoin: string,
coin: TransactionResult,
amountIn: number | string | bigint,
minAmountOut: number,
swapOptions: SwapOptions = { referer: 'https://www.navi.ag/', dexList: [], byAmountIn: true, depth: 3 }
)
- Swap function
The swap function is a wrapper for the getRoute and swapPTB functions. Set isDryRun
from swapOptions
to true to get a dry run result and balance changes. It will submit the transaction and return the result if a keypair
is provided.
import { swap } from 'navi-aggregator-sdk';
const result = await swap(
address: string,
client: SuiClient,
fromCoin: string,
toCoin: string,
amountIn: number | string | bigint,
minAmountOut: number,
swapOptions: SwapOptions = { referer: 'https://www.navi.ag/', dexList: [], byAmountIn: true, depth: 3, isDryRun: true, keypair: undefined }
);
See the demo for examples of how to use the SDK with NAVI-SDK.
This project is licensed under the MIT License - see the LICENSE file for details.