import { LimoClient } from '@kamino-finance/limo-sdk'; import { RouteOutput, RouteParams } from './types'; import { getRouterTypeID, ROUTER_PROGRAM_MAP, RouterType, TRITON_VOTE_ACCOUNT } from '../consts'; import BN from 'bn.js'; import { Address, createNoopSigner, Instruction } from '@solana/kit'; export async function getLimoLogsIxsForRoute(args: { params: RouteParams; route: RouteOutput; limoClient: LimoClient; inputTokenAccount: Address; outputTokenAccount: Address; nextBestAmountOutSimulated: BN; nextBestRouterTypeId: number; }): Promise<{ preIx: Instruction; postIx: Instruction }> { const { params, route, limoClient, inputTokenAccount, outputTokenAccount, nextBestAmountOutSimulated, nextBestRouterTypeId, } = args; const amountOutSimulated = params.swapType === 'exactIn' ? route.amountsExactIn.amountOutSimulated : route.amountsExactOut.amountOut; const simulatedTs = route.simulationResult?.simulationTimestamp ? new BN(route.simulationResult.simulationTimestamp) : new BN(0); const minimumAmountOut = params.swapType === 'exactIn' ? route.amountsExactIn.amountOutGuaranteed : route.amountsExactOut.amountOut; const amountIn = params.swapType === 'exactIn' ? route.amountsExactIn.amountIn : route.amountsExactOut.amountIn; const logSwapUserBalanceIx = await limoClient.logUserSwapBalancesIxs({ user: createNoopSigner(params.executor), inputMint: params.tokenIn, outputMint: params.tokenOut, inputTa: inputTokenAccount, outputTa: outputTokenAccount, swapProgarmId: ROUTER_PROGRAM_MAP[route.routerType], simulatedSwapAmountOut: amountOutSimulated ? amountOutSimulated : new BN(0), simulatedTs, minimumAmountOut: minimumAmountOut, swapAmountIn: amountIn, simulatedAmountOutNextBest: nextBestAmountOutSimulated, aggregatorId: getRouterTypeID(route.routerType), // only 4 chars supported for router name in SC nextBestAggregatorId: nextBestRouterTypeId, pdaReferrer: params.referrerPda ? params.referrerPda : limoClient.getProgramID(), voteAccount: TRITON_VOTE_ACCOUNT, }); return { preIx: logSwapUserBalanceIx.beforeSwapIx, postIx: logSwapUserBalanceIx.afterSwapIx, }; } export function includeLimoLogs(includeLimoLogs: boolean | undefined, routerType?: RouterType): boolean { if (includeLimoLogs !== undefined && !includeLimoLogs) { return false; } if (routerType === 'per' || routerType === 'jupiterZ') { return false; } return true; }