four-flap-meme-sdk 1.6.66 → 1.6.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xlayer/dex-bundle-swap.js +14 -29
- package/package.json +1 -1
|
@@ -203,10 +203,9 @@ export class AADexSwapExecutor {
|
|
|
203
203
|
initIfNeeded(buyerSender, !!buyerAi?.deployed, buyerOwner.address);
|
|
204
204
|
const decimals = await this.bundleExecutor['getErc20Decimals'](tokenAddress);
|
|
205
205
|
const sellerTokenBal = await this.aaManager.getErc20Balance(tokenAddress, sellerSender);
|
|
206
|
-
// ✅ 当 sellPercent = 100 时直接使用完整余额,避免精度损失
|
|
207
206
|
const sellAmountWei = sellAmount
|
|
208
207
|
? ethers.parseUnits(String(sellAmount), decimals)
|
|
209
|
-
: (
|
|
208
|
+
: (sellerTokenBal * BigInt(sellPercent)) / 100n;
|
|
210
209
|
if (sellAmountWei <= 0n)
|
|
211
210
|
throw new Error('卖出数量无效');
|
|
212
211
|
// 授权检查
|
|
@@ -472,10 +471,9 @@ export class AADexSwapExecutor {
|
|
|
472
471
|
}
|
|
473
472
|
const decimals = await this.bundleExecutor['getErc20Decimals'](tokenAddress);
|
|
474
473
|
const sellerTokenBal = await this.aaManager.getErc20Balance(tokenAddress, sellerAi.sender);
|
|
475
|
-
// ✅ 当 sellPercent = 100 时直接使用完整余额,避免精度损失
|
|
476
474
|
const sellAmountWei = sellAmount
|
|
477
475
|
? ethers.parseUnits(String(sellAmount), decimals)
|
|
478
|
-
: (
|
|
476
|
+
: (sellerTokenBal * BigInt(sellPercent)) / 100n;
|
|
479
477
|
let needApprove = false;
|
|
480
478
|
if (!skipApprovalCheck) {
|
|
481
479
|
const allowance = await this.aaManager.getErc20Allowance(tokenAddress, sellerAi.sender, effectiveRouter);
|
|
@@ -586,32 +584,19 @@ export class AADexSwapExecutor {
|
|
|
586
584
|
const totalBuyerPrefundWithBuffer = (useNativeToken && capitalMode)
|
|
587
585
|
? buyerAis.reduce((sum, ai) => sum + estimateBuyerPrefundWithBuffer(ai.deployed), 0n)
|
|
588
586
|
: 0n;
|
|
589
|
-
// ✅
|
|
590
|
-
|
|
591
|
-
//
|
|
592
|
-
// 这样可以避免 seller 需要用自己的 OKB 补贴分发
|
|
587
|
+
// ✅ 计算利润(不再压缩到“卖出-买入-prefund”上限,按配置直接刮取)
|
|
588
|
+
const profitWei = extractProfit ? calculateProfitWei(quotedSellOutWei, profitBps) : 0n;
|
|
589
|
+
// 资金充足性提示:不再阻断,记录警告后继续分发
|
|
593
590
|
const totalDistributeNeeded = totalBuyWei + totalBuyerPrefundWithBuffer + profitWei;
|
|
594
|
-
let adjustedBuyAmountsWei = buyAmountsWei;
|
|
595
|
-
let adjustedProfitWei = profitWei;
|
|
596
591
|
if (quotedSellOutWei > 0n && totalDistributeNeeded > quotedSellOutWei) {
|
|
597
|
-
|
|
598
|
-
const safeQuoted = (quotedSellOutWei * 95n) / 100n; // 留 5% 给 seller prefund
|
|
599
|
-
const scaleRatio = safeQuoted > 0n ? (safeQuoted * 10000n) / totalDistributeNeeded : 0n;
|
|
600
|
-
// 按比例缩减 buyAmounts
|
|
601
|
-
adjustedBuyAmountsWei = buyAmountsWei.map(w => (w * scaleRatio) / 10000n);
|
|
602
|
-
const adjustedTotalBuyWei = adjustedBuyAmountsWei.reduce((a, b) => a + b, 0n);
|
|
603
|
-
// 按比例缩减 profit
|
|
604
|
-
adjustedProfitWei = (profitWei * scaleRatio) / 10000n;
|
|
605
|
-
console.warn('[AA DEX 批量换手] ⚠️ 分发金额超过预估卖出,已按比例缩减:', {
|
|
592
|
+
console.warn('[AA DEX 批量换手] ⚠️ 预估卖出金额不足,仍继续分发:', {
|
|
606
593
|
quotedSellOutWei: ethers.formatEther(quotedSellOutWei),
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
594
|
+
totalBuyWei: ethers.formatEther(totalBuyWei),
|
|
595
|
+
totalBuyerPrefund: ethers.formatEther(totalBuyerPrefundWithBuffer),
|
|
596
|
+
profitWei: ethers.formatEther(profitWei),
|
|
597
|
+
totalNeeded: ethers.formatEther(totalDistributeNeeded),
|
|
598
|
+
shortfall: ethers.formatEther(totalDistributeNeeded - quotedSellOutWei),
|
|
612
599
|
});
|
|
613
|
-
// 更新变量
|
|
614
|
-
profitWei = adjustedProfitWei;
|
|
615
600
|
}
|
|
616
601
|
// ✅ 利润在分发阶段通过 AA 内部刮取
|
|
617
602
|
// ✅ 资金分发逻辑(仅 capitalMode=true 时执行,对应 BSC flapQuickBatchSwapMerkle)
|
|
@@ -698,7 +683,7 @@ export class AADexSwapExecutor {
|
|
|
698
683
|
// - 原生代币模式:分发金额 = 买入金额 + 买方 prefund
|
|
699
684
|
// - ERC20 模式:只分发 ERC20 代币,prefund 需要 buyer 自己有 OKB
|
|
700
685
|
const items = buyerSenders.map((to, i) => {
|
|
701
|
-
const buyAmount =
|
|
686
|
+
const buyAmount = buyAmountsWei[i] ?? 0n;
|
|
702
687
|
const prefund = buyerPrefunds[i] ?? 0n;
|
|
703
688
|
return {
|
|
704
689
|
to,
|
|
@@ -870,7 +855,7 @@ export class AADexSwapExecutor {
|
|
|
870
855
|
const chainHops = allGeneratedHopWallets[buyerIdx];
|
|
871
856
|
const buyerSender = buyerSenders[buyerIdx];
|
|
872
857
|
const buyerAi = buyerAis[buyerIdx];
|
|
873
|
-
const buyAmount =
|
|
858
|
+
const buyAmount = buyAmountsWei[buyerIdx] ?? 0n;
|
|
874
859
|
if (buyAmount <= 0n)
|
|
875
860
|
continue;
|
|
876
861
|
// ✅ 计算 buyer 的 prefund(用于买入,使用常量)
|
|
@@ -1016,7 +1001,7 @@ export class AADexSwapExecutor {
|
|
|
1016
1001
|
// 不使用 exactOutput,因为卖出后价格下跌,可能导致 OKB 不够买回目标数量
|
|
1017
1002
|
for (let i = 0; i < buyerOwners.length; i++) {
|
|
1018
1003
|
const ai = buyerAis[i];
|
|
1019
|
-
const buyWei =
|
|
1004
|
+
const buyWei = buyAmountsWei[i]; // 分发给买家的 OKB 金额
|
|
1020
1005
|
let buyCallData;
|
|
1021
1006
|
if (useNativeToken) {
|
|
1022
1007
|
// ✅ 原生代币模式:OKB → Token
|