|
|
@@ -81,16 +81,18 @@ export class SniperEngine {
|
|
|
logger.info(` Token B: ${tokenB.amount} ${tokenB.symbol || ''} (${formatUsd(tokenB.valueUsd)})`);
|
|
|
logger.info(` Estimated Total Value: ${formatUsd(calculation.estimatedValue)}`);
|
|
|
|
|
|
- // Step 2: Check and swap Token A
|
|
|
+ // Step 2: Check and swap Token A (add 10% buffer for slippage)
|
|
|
const tokenABalance = await this.swapper.getTokenBalance(tokenA.address);
|
|
|
const requiredAmountA = parseFloat(tokenA.amount);
|
|
|
+ const swapAmountA = requiredAmountA * 1.1; // Add 10% buffer
|
|
|
|
|
|
if (tokenABalance < requiredAmountA * 0.95) {
|
|
|
logger.info(`Token A balance insufficient: ${tokenABalance.toFixed(4)} < ${requiredAmountA.toFixed(4)}`);
|
|
|
+ logger.info(`Swapping with 10% buffer: ${swapAmountA.toFixed(4)} (required: ${requiredAmountA.toFixed(4)})`);
|
|
|
const success = await this.swapper.swapIfNeeded(
|
|
|
'So11111111111111111111111111111111111111112', // Use SOL as source
|
|
|
tokenA.address,
|
|
|
- requiredAmountA,
|
|
|
+ swapAmountA,
|
|
|
tokenA.decimals
|
|
|
);
|
|
|
if (!success) {
|
|
|
@@ -101,16 +103,18 @@ export class SniperEngine {
|
|
|
logger.success(`Token A balance sufficient: ${tokenABalance.toFixed(4)} >= ${requiredAmountA.toFixed(4)}`);
|
|
|
}
|
|
|
|
|
|
- // Step 3: Check and swap Token B
|
|
|
+ // Step 3: Check and swap Token B (add 10% buffer for slippage)
|
|
|
const tokenBBalance = await this.swapper.getTokenBalance(tokenB.address);
|
|
|
const requiredAmountB = parseFloat(tokenB.amount);
|
|
|
+ const swapAmountB = requiredAmountB * 1.1; // Add 10% buffer
|
|
|
|
|
|
if (tokenBBalance < requiredAmountB * 0.95) {
|
|
|
logger.info(`Token B balance insufficient: ${tokenBBalance.toFixed(4)} < ${requiredAmountB.toFixed(4)}`);
|
|
|
+ logger.info(`Swapping with 10% buffer: ${swapAmountB.toFixed(4)} (required: ${requiredAmountB.toFixed(4)})`);
|
|
|
const success = await this.swapper.swapIfNeeded(
|
|
|
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // Use USDC as source
|
|
|
tokenB.address,
|
|
|
- requiredAmountB,
|
|
|
+ swapAmountB,
|
|
|
tokenB.decimals
|
|
|
);
|
|
|
if (!success) {
|