Hello this is my function to write swapping:
async function swapTokens(amount: number, fromToken: string, targetToken: string) {
const amountIn = new BN(amount);
const routerRes = await aggregatorClient.findRouters({ from: fromToken, target: targetToken, amount: amountIn, byAmountIn: true });
if (routerRes) {
const routerTx = new Transaction();
await aggregatorClient.fastRouterSwap({
routers: routerRes.routes,
byAmountIn: true,
txb: routerTx,
slippage: 0.01,
// isMergeTragetCoin: true,
refreshAllCoins: true,
});
const result = await client.signAndExecuteTransaction(routerTx);
console.log("Swap result:", result);
} else {
console.error("No routers found for the swap.");
}
}```
i am unable to execute this function. i am stuck with poor documentation for last 2 days. I need help on it. have anyone implemented it before using the poor documentation . The cetus aggregator have nothing with it.