> For the complete documentation index, see [llms.txt](https://docs.aftermath.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aftermath.finance/for-developers/typescript-sdk/products/router.md).

# Router

The Router class provides a smart order routing system to find optimal trade routes across multiple pools and protocols on the Sui network. It handles routing trades through various liquidity pools to achieve the best possible execution price.

{% hint style="warning" %}
The current production API exposes router `trade-route`, `transactions/add-trade`, and `supported-coins`. Legacy SDK helpers such as `getVolume24hrs`, `searchSupportedCoins`, and `getInteractionEvents` may require a different backend and should not be assumed to work against the current public service. `getSupportedCoins` is not among them: it calls `GET /api/router/supported-coins`, which is live.
{% endhint %}

### Initialization

Create a Router instance:

```typescript
const afSdk = await Aftermath.create({ network: "MAINNET" });

const router = afSdk.Router();
```

### Methods

#### getVolume24hrs() (Legacy)

Retrieves the total trading volume in the last 24 hours.

```typescript
const volume = await router.getVolume24hrs();
console.log(volume); // Returns a number representing total 24h volume
```

#### getSupportedCoins()

Returns an array of Sui coin types that can be traded through the router. It calls `GET /api/router/supported-coins`.

```typescript
const supportedCoins = await router.getSupportedCoins();
```

The response is large: 92,803 coin types, about 7.8 MB, on 2026-08-22. Cache it rather than calling it on a hot path such as per-transaction fee selection.

This is the router's trading universe. It is not the list of coins eligible to pay gas through [Dynamic Gas](/for-developers/typescript-sdk/products/dynamic-gas.md).

#### getCompleteTradeRouteGivenAmountIn()

Creates an optimal route for a trade with a specified input amount.

```typescript
const route = await router.getCompleteTradeRouteGivenAmountIn({
  coinInType: "0x2::sui::SUI",
  coinOutType: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
  coinInAmount: BigInt(10_000_000_000), // Amount of input token
  referrer?: "0x...", // Optional referrer address
  externalFee?: {     // Optional external fee configuration
    recipient: "0x...",
    feePercentage: 0.01 // 1%
  },
  protocolBlacklist?: ["Cetus", "BlueMove"], // Optional protocols to exclude
  // OR
  protocolWhitelist?: ["Aftermath", "Cetus"], // Optional protocols to include
  
  poolBlacklist?: ["0x...", "0x..."], // Optional pool ids to exclude
  // OR
  poolWhitelist?: ["0x...", "0x..."] // Optional pool ids to include
}, abortSignal?);
```

#### getCompleteTradeRouteGivenAmountOut()

Creates an optimal route for a trade with a specified output amount.

```typescript
const route = await router.getCompleteTradeRouteGivenAmountOut({
  coinInType: "0x2::sui::SUI",
  coinOutType: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
  coinOutAmount: BigInt(20_000_000), // Desired output amount
  slippage: 0.01, // 1% slippage tolerance
  referrer?: "0x...", // Optional referrer address
  externalFee?: {     // Optional external fee configuration
    recipient: "0x...",
    feePercentage: 0.01 // 1%
  },
  protocolBlacklist?: ["Cetus", "BlueMove"], // Optional protocols to exclude
  // OR
  protocolWhitelist?: ["Aftermath", "Cetus"], // Optional protocols to include
  
  poolBlacklist?: ["0x...", "0x..."], // Optional pool ids to exclude
  // OR
  poolWhitelist?: ["0x...", "0x..."] // Optional pool ids to include
}, abortSignal?);
```

#### getTransactionForCompleteTradeRoute()

Generates a transaction for executing a complete trade route.

```typescript
const transaction = await router.getTransactionForCompleteTradeRoute({
	walletAddress: "0x...", // Trader's address
	completeRoute: routeObject, // Route from getCompleteTradeRoute
	slippage: 0.01, // 1% max slippage
	isSponsoredTx: boolean, // Optional sponsored transaction flag
});
```

#### addTransactionForCompleteTradeRoute()

Adds a trade to an existing transaction (swap can be performed before or after any logic within the existing transaction).

```typescript
const result = await router.addTransactionForCompleteTradeRoute({
	tx: Transaction, // Existing transaction
	completeRoute: route, // Route from getCompleteTradeRoute
	slippage: number, // Slippage tolerance (e.g. 0.01 for 1%)
	walletAddress: string, // Trader's address
	coinInId: TransactionObjectArgument, // Optional coin input ID
});

// Returns: { tx: Transaction, coinOutId: TransactionObjectArgument }
```

**Address-balance inputs**

`coinInId` may reference any `Coin<T>` already materialized by the transaction prefix; it does not have to be an owned coin object selected by the Router. A wallet can withdraw a SIP-58 address balance, redeem the withdrawal with `0x2::coin::redeem_funds`, merge that coin with owned `Coin<T>` objects when both storage forms are needed, and pass the resulting `Coin<T>` argument as `coinInId`. The Router preserves the wallet-authored prefix and appends the quoted swap.

Router composition is separate from gas sponsorship. Acceptance of a materialized address-balance coin by `transactions/add-trade` does not imply that the legacy [Dynamic Gas](/for-developers/typescript-sdk/products/dynamic-gas.md) endpoint can discover that same balance as a reimbursement source from only `walletAddress` and `gasCoinType`; handle that sponsorship boundary independently.

### Types

#### RouterProtocolName

Supported DEX protocols for routing:

```typescript
type RouterProtocolName =
	| "Aftermath"
	| "BlueMove"
	| "Cetus"
	| "DeepBook"
	| "DeepBookV3"
	| "DoubleUpPump"
	| "FlowX"
	| "FlowXClmm"
	| "HopFun"
	| "Kriya"
	| "KriyaClmm"
	| "Metastable"
	| "MovePump"
	| "Obric"
	| "SuiSwap"
	| "Turbos"
	| "SpringSui"
	| "Bluefin"
	| "TurbosFun";
```

#### RouterCompleteTradeRoute

Structure containing the complete trade route information:

```typescript
interface RouterCompleteTradeRoute {
	routes: RouterTradeRoute[];
	netTradeFeePercentage: number;
	referrer?: string;
	externalFee?: {
		recipient: string;
		feePercentage: number;
	};
	slippage?: number;
	coinIn: {
		type: string;
		amount: bigint;
		tradeFee: bigint;
	};
	coinOut: {
		type: string;
		amount: bigint;
		tradeFee: bigint;
	};
	spotPrice: number;
}
```

### Constants

```typescript
Router.constants = {
	maxExternalFeePercentage: 0.5, // Maximum allowed external fee (50%)
};
```

### Example Usage

#### Basic Trading

```typescript
// Initialize router
const afSdk = await Aftermath.create({ network: "MAINNET" });
const router = afSdk.Router();

// Get a trade route
const route = await router.getCompleteTradeRouteGivenAmountIn({
	coinInType: "0x2::sui::SUI",
	coinOutType:
		"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
	coinInAmount: BigInt(10_000_000_000),
	referrer: "0x...",
});

// Generate transaction for the route
const tx = await router.getTransactionForCompleteTradeRoute({
	walletAddress: "0x...",
	completeRoute: route,
	slippage: 0.01,
});
```

#### Advanced Transaction Building

```typescript
const WALLET_ADDRESS = "0x123";

// Initialize SDK and router
const af = await Aftermath.create({ network: "MAINNET" });
const router = af.Router();

// Find first route (SUIP -> SUI)
const completeRoute = await router.getCompleteTradeRouteGivenAmountIn({
	coinInAmount: BigInt("2000000000"),
	coinInType:
		"0xe4239cd951f6c53d9c41e25270d80d31f925ad1655e5ba5b543843d4a66975ee::SUIP::SUIP",
	coinOutType: "0x2::sui::SUI",
});

// Create transaction and add first trade
const tx = new Transaction();
const { tx: newTx, coinOutId } =
	await router.addTransactionForCompleteTradeRoute({
		tx,
		completeRoute,
		slippage: 0.1,
		walletAddress: WALLET_ADDRESS,
	});

// Transfer first trade output
newTx.transferObjects([coinOutId!], WALLET_ADDRESS);

// Find second route (SUI -> SUIP)
const completeRoute2 = await router.getCompleteTradeRouteGivenAmountIn({
	coinInAmount: BigInt("2000000000"),
	coinInType: "0x2::sui::SUI",
	coinOutType:
		"0xe4239cd951f6c53d9c41e25270d80d31f925ad1655e5ba5b543843d4a66975ee::SUIP::SUIP",
});

// Add second trade to same transaction
const { tx: newTx2, coinOutId: coinOutId2 } =
	await router.addTransactionForCompleteTradeRoute({
		tx: newTx,
		completeRoute: completeRoute2,
		slippage: 0.1,
		walletAddress: WALLET_ADDRESS,
	});

// Transfer second trade output
newTx2.transferObjects([coinOutId2!], WALLET_ADDRESS);

// Execute transaction `newTx2`...
```

Rest API documention can be found [here](https://www.postman.com/aftermath-finance/aftermath-router-api/collection/ske4grf/aftermath-router-api?action=share\&creator=39946215).
