|
|
@@ -16,7 +16,7 @@ import {
|
|
|
import type { ParsedOperation } from '../monitor/types'
|
|
|
import { scaleAmount } from './ratio'
|
|
|
import { getTokenPrices, calculateCopyScale } from './price'
|
|
|
-import { ensureSufficientBalances, getUsdcBalance, swapTokensBackToUsdc, USDC_MINT } from './swap'
|
|
|
+import { ensureSufficientBalances, getUsdcBalance, getUsdtBalance, swapTokensBackToUsdc, USDC_MINT } from './swap'
|
|
|
import { sendDiscordNotification } from '../discord'
|
|
|
|
|
|
// We import from the built SDK dist using relative path
|
|
|
@@ -156,17 +156,26 @@ export class CopyEngine {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 检查 USDC 余额是否足够
|
|
|
+ * 检查 USDC+USDT 总余额是否足够,不够则跳过;
|
|
|
+ * 如果总余额够但 USDC 不足,自动从 USDT swap 到 USDC
|
|
|
*/
|
|
|
- private async checkUsdcBalance(requiredUsd: number): Promise<boolean> {
|
|
|
- const balance = await getUsdcBalance(this.connection)
|
|
|
- const balanceUsd = Number(balance) / 1e6
|
|
|
- if (balanceUsd < requiredUsd) {
|
|
|
+ private async checkStablecoinBalance(requiredUsd: number): Promise<boolean> {
|
|
|
+ const usdcBalance = await getUsdcBalance(this.connection)
|
|
|
+ const usdtBalance = await getUsdtBalance(this.connection)
|
|
|
+ const usdcUsd = Number(usdcBalance) / 1e6
|
|
|
+ const usdtUsd = Number(usdtBalance) / 1e6
|
|
|
+ const totalUsd = usdcUsd + usdtUsd
|
|
|
+
|
|
|
+ if (totalUsd < requiredUsd) {
|
|
|
console.log(
|
|
|
- `[CopyEngine] Insufficient USDC balance: $${balanceUsd.toFixed(2)} < $${requiredUsd.toFixed(2)}, skipping`,
|
|
|
+ `[CopyEngine] Insufficient stablecoin balance: USDC=$${usdcUsd.toFixed(2)} + USDT=$${usdtUsd.toFixed(2)} = $${totalUsd.toFixed(2)} < $${requiredUsd.toFixed(2)}, skipping`,
|
|
|
)
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+ console.log(
|
|
|
+ `[CopyEngine] Stablecoin balance: USDC=$${usdcUsd.toFixed(2)}, USDT=$${usdtUsd.toFixed(2)}, need=$${requiredUsd.toFixed(2)}`,
|
|
|
+ )
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
@@ -232,7 +241,7 @@ export class CopyEngine {
|
|
|
|
|
|
// Check USDC balance before proceeding
|
|
|
const neededUsd = mintA === USDC_MINT || mintB === USDC_MINT ? ourUsd * 0.6 : ourUsd
|
|
|
- if (!(await this.checkUsdcBalance(neededUsd))) {
|
|
|
+ if (!(await this.checkStablecoinBalance(neededUsd))) {
|
|
|
const skipMsg = `Insufficient USDC balance for $${ourUsd.toFixed(2)} position`
|
|
|
updateCopyHistory(historyId, { status: 'skipped', errorMessage: skipMsg })
|
|
|
sendDiscordNotification({
|
|
|
@@ -410,7 +419,7 @@ export class CopyEngine {
|
|
|
|
|
|
// Check USDC balance before proceeding
|
|
|
const neededUsd = mintA === USDC_MINT || mintB === USDC_MINT ? ourUsd * 0.6 : ourUsd
|
|
|
- if (!(await this.checkUsdcBalance(neededUsd))) {
|
|
|
+ if (!(await this.checkStablecoinBalance(neededUsd))) {
|
|
|
const skipMsg = `Insufficient USDC balance for $${ourUsd.toFixed(2)} add liquidity`
|
|
|
updateCopyHistory(historyId, { status: 'skipped', errorMessage: skipMsg })
|
|
|
sendDiscordNotification({
|