four-flap-meme-sdk 1.7.64 → 1.7.66
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.
|
@@ -367,10 +367,12 @@ export async function bundleSwap(params) {
|
|
|
367
367
|
if (useFundUtilization) {
|
|
368
368
|
// ========================================
|
|
369
369
|
// ✅ 资金利用率模式
|
|
370
|
+
// 核心逻辑:卖出获得的 OKB 按比例转给买家
|
|
370
371
|
// 1. 卖家卖出代币 → 获得 OKB
|
|
371
|
-
// 2. OKB
|
|
372
|
-
// 3.
|
|
373
|
-
// 4.
|
|
372
|
+
// 2. 利润从卖家 OKB 中扣除
|
|
373
|
+
// 3. (可选多跳)卖家 → hop1 → hop2 → ... → 分发者
|
|
374
|
+
// 4. 分发者按比例转账给买家
|
|
375
|
+
// 5. 买家买入
|
|
374
376
|
// ========================================
|
|
375
377
|
console.log(`[Bundle Swap] 资金利用率模式,hopCount=${actualHopCount}`);
|
|
376
378
|
// 1. 卖家卖出
|
|
@@ -385,29 +387,37 @@ export async function bundleSwap(params) {
|
|
|
385
387
|
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
386
388
|
});
|
|
387
389
|
}
|
|
388
|
-
// 3.
|
|
389
|
-
const
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
value: 0n,
|
|
395
|
-
callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
|
|
396
|
-
});
|
|
397
|
-
// 中间钱包之间转账
|
|
398
|
-
for (let i = 0; i < hopWallets.length; i++) {
|
|
399
|
-
const nextRecipient = i < hopWallets.length - 1 ? hopWallets[i + 1].address : buyerWallet.address;
|
|
390
|
+
// 3. 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
|
|
391
|
+
const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
|
|
392
|
+
// 多跳转账(如果有)
|
|
393
|
+
if (hopWallets.length > 0) {
|
|
394
|
+
// ✅ 修复:卖家只转移"卖出所得 - 利润",不是全部余额
|
|
395
|
+
// 避免把卖家原有的 OKB 也转走
|
|
400
396
|
calls.push({
|
|
401
|
-
target:
|
|
397
|
+
target: sellerWallet.address,
|
|
402
398
|
allowFailure: false,
|
|
403
399
|
value: 0n,
|
|
404
|
-
callData: delegateInterface.encodeFunctionData('
|
|
400
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [hopWallets[0].address, buyAmountAfterProfit]),
|
|
405
401
|
});
|
|
402
|
+
// hop1 → hop2 → ... → 最后一个 hop(分发者):使用 transferTo(全部余额)
|
|
403
|
+
for (let i = 0; i < hopWallets.length - 1; i++) {
|
|
404
|
+
calls.push({
|
|
405
|
+
target: hopWallets[i].address,
|
|
406
|
+
allowFailure: false,
|
|
407
|
+
value: 0n,
|
|
408
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
|
|
409
|
+
});
|
|
410
|
+
}
|
|
406
411
|
}
|
|
407
|
-
// 4.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
412
|
+
// 4. 分发者转账给买家:使用 transferTo(全部余额,确保资金不滞留)
|
|
413
|
+
calls.push({
|
|
414
|
+
target: distributor.address,
|
|
415
|
+
allowFailure: false,
|
|
416
|
+
value: 0n,
|
|
417
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallet.address]),
|
|
418
|
+
});
|
|
419
|
+
// 5. 买家买入(使用收到的 OKB)
|
|
420
|
+
const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
411
421
|
calls.push(buyCall);
|
|
412
422
|
}
|
|
413
423
|
else {
|
|
@@ -574,7 +584,7 @@ export async function bundleBatchSwap(params) {
|
|
|
574
584
|
// ✅ 资金利用率模式(一卖多买)
|
|
575
585
|
// 1. 卖家卖出代币 → 获得 OKB
|
|
576
586
|
// 2. 利润从卖家 OKB 中扣除
|
|
577
|
-
// 3.
|
|
587
|
+
// 3. 卖家(或最后一个 hop)按比例转账给各买家
|
|
578
588
|
// 4. 各买家用收到的 OKB 买入
|
|
579
589
|
// ========================================
|
|
580
590
|
console.log(`[Bundle Batch Swap] 资金利用率模式,hopCount=${actualHopCount}`);
|
|
@@ -590,32 +600,42 @@ export async function bundleBatchSwap(params) {
|
|
|
590
600
|
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
591
601
|
});
|
|
592
602
|
}
|
|
593
|
-
// 3. OKB
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
value: 0n,
|
|
600
|
-
callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
|
|
601
|
-
});
|
|
602
|
-
// 中间钱包之间转账
|
|
603
|
-
for (let i = 0; i < hopWallets.length; i++) {
|
|
604
|
-
const nextRecipient = i < hopWallets.length - 1 ? hopWallets[i + 1].address : buyerWallets[0].address;
|
|
603
|
+
// 3. OKB 转账逻辑
|
|
604
|
+
// 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
|
|
605
|
+
const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
|
|
606
|
+
if (hopWallets.length > 0) {
|
|
607
|
+
// ✅ 修复:卖家只转移"卖出所得 - 利润",不是全部余额
|
|
608
|
+
// 避免把卖家原有的 OKB 也转走
|
|
605
609
|
calls.push({
|
|
606
|
-
target:
|
|
610
|
+
target: sellerWallet.address,
|
|
607
611
|
allowFailure: false,
|
|
608
612
|
value: 0n,
|
|
609
|
-
callData: delegateInterface.encodeFunctionData('
|
|
613
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [hopWallets[0].address, totalBuyAmountAfterProfit]),
|
|
610
614
|
});
|
|
615
|
+
// 中间钱包之间转账(到最后一个 hop):使用 transferTo(全部余额)
|
|
616
|
+
for (let i = 0; i < hopWallets.length - 1; i++) {
|
|
617
|
+
calls.push({
|
|
618
|
+
target: hopWallets[i].address,
|
|
619
|
+
allowFailure: false,
|
|
620
|
+
value: 0n,
|
|
621
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
|
|
622
|
+
});
|
|
623
|
+
}
|
|
611
624
|
}
|
|
612
|
-
//
|
|
613
|
-
for (let i =
|
|
625
|
+
// 分发者按比例转给各买家
|
|
626
|
+
for (let i = 0; i < buyerWallets.length; i++) {
|
|
627
|
+
const amountToTransfer = buyAmountsPerBuyer[i];
|
|
628
|
+
if (amountToTransfer <= 0n)
|
|
629
|
+
continue;
|
|
630
|
+
// ✅ 最后一个买家使用 transferTo(全部余额),确保资金不滞留
|
|
631
|
+
const isLastBuyer = i === buyerWallets.length - 1;
|
|
614
632
|
calls.push({
|
|
615
|
-
target:
|
|
633
|
+
target: distributor.address,
|
|
616
634
|
allowFailure: false,
|
|
617
635
|
value: 0n,
|
|
618
|
-
callData:
|
|
636
|
+
callData: isLastBuyer
|
|
637
|
+
? delegateInterface.encodeFunctionData('transferTo', [buyerWallets[i].address])
|
|
638
|
+
: delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, amountToTransfer]),
|
|
619
639
|
});
|
|
620
640
|
}
|
|
621
641
|
// 4. 所有买家买入
|