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.
Initialization
Create a Router instance:
const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider
const router = afSdk.Router();Methods
getVolume24hrs()
Retrieves the total trading volume in the last 24 hours.
const volume = await router.getVolume24hrs();
console.log(volume); // Returns a number representing total 24h volumegetSupportedCoins()
Returns an array of supported coins that can be traded through the router.
const supportedCoins = await router.getSupportedCoins();getCompleteTradeRouteGivenAmountIn()
Creates an optimal route for a trade with a specified input amount.
getCompleteTradeRouteGivenAmountOut()
Creates an optimal route for a trade with a specified output amount.
getTransactionForCompleteTradeRoute()
Generates a transaction for executing a complete trade route.
addTransactionForCompleteTradeRoute()
Adds a trade to an existing transaction (swap can be performed before or after any logic within the existing transaction).
Types
RouterProtocolName
Supported DEX protocols for routing:
RouterCompleteTradeRoute
Structure containing the complete trade route information:
Constants
Example Usage
Basic Trading
Advanced Transaction Building
Rest API documention can be found here.
Last updated