# Router

```typescript
const router = new Aftermath("TESTNET").Router();
```

## **Route a Trade**

### 1. Create trade route

```typescript
const route = await router.getCompleteTradeRouteGivenAmountIn({
	coinInType: "0x...",
	coinOutType: "0x...",
	coinInAmount: 1_000_000_000n,
	
	// optional
	referrer: "0x...",
	externalFee: {
		recipient: "0x...",
		feePercentage: 0.01, // 1% fee from amount out
	},
});

console.log(route);
/*
{
	coinIn: {
		type: "0x1...",
		amount: 1_000_000n,
		tradeFee: 1_00_000_000_000_000_000n, // 0.1% (18 decimals)
	},
	coinOut: {
		type: "0x2...",
		amount: 1_100_000n,
		tradeFee: 0n, // 0% (18 decimals)
	},
	spotPrice: 0.90909090909, // in/out (ignoring fees)
	routes: [...],
	
	// optional
	referrer: "0x...",
	externalFee: {
		recipient: "0x...",
		feePercentage: 0.01, // 1% fee from amount out
	},
}
*/
```

### 2. Get transaction for route

```typescript
const tx = await router.getTransactionForCompleteTradeRoute({
	walletAddress: "0x...",
	completeRoute: route,
	slippage: 0.01,	// 1% max slippage
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aftermath-finance-1.gitbook.io/aftermath-finance/aftermath-typescript-sdk/router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
