Browse Source

feat: skip swap for stablecoins

- Add STABLECOIN_MINTS list (USDC, USDT, USD1)
- Skip swap when output token is a stablecoin
- Avoid unnecessary USDC -> USDC/USDT swaps
lushdog@outlook.com 1 tháng trước cách đây
mục cha
commit
2708e02bd5
1 tập tin đã thay đổi với 14 bổ sung0 xóa
  1. 14 0
      src/services/jupiter.js

+ 14 - 0
src/services/jupiter.js

@@ -187,6 +187,13 @@ export class JupiterSwapper {
     }
   }
 
+  /** 稳定币 mint:用 USDC 换这些币时无需 swap,直接视为已有 */
+  static STABLECOIN_MINTS = [
+    'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
+    'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', // USDT
+    'USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB',  // USD1
+  ];
+
   /**
    * Swap a fixed USD amount of USDC into the output token (ExactIn).
    * Uses valueUsd from calculation API - no ExactOut, no token amount.
@@ -201,6 +208,13 @@ export class JupiterSwapper {
       return true;
     }
 
+    const mint = String(outputMint || '').trim();
+    const isStablecoin = JupiterSwapper.STABLECOIN_MINTS.includes(mint) || mint === USDC_MINT;
+    if (isStablecoin) {
+      logger.info(`Skip swap: output is stablecoin (USDC/USDT), no need to swap USDC -> same`);
+      return true;
+    }
+
     if (!this.apiKey) {
       logger.error('═══════════════════════════════════════════════════');
       logger.error('Jupiter API Key is required!');