four-flap-meme-sdk 1.7.52 → 1.7.53
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.
|
@@ -365,15 +365,18 @@ export async function bundleSwap(params) {
|
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
367
|
// 3. 买家买入(使用买家自己的 OKB)
|
|
368
|
+
const buyAmount = estimatedOkbOut - profitAmount;
|
|
368
369
|
const buyCall = buildBuyCallInternal(buyerWallet, buyAmount, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
369
370
|
calls.push(buyCall);
|
|
370
371
|
}
|
|
371
372
|
else {
|
|
372
|
-
// ✅
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
373
|
+
// ✅ 资金利用率模式:卖出 -> 扣利润 -> 转账 -> 买入
|
|
374
|
+
const firstRecipient = hopWallets.length > 0 ? hopWallets[0].address : buyerWallet.address;
|
|
375
|
+
const buyAmount = estimatedOkbOut - profitAmount;
|
|
376
|
+
// 1. 卖家卖出 (独立卖出,不包含转账)
|
|
377
|
+
const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
378
|
+
calls.push(sellCall);
|
|
379
|
+
// 2. 利润刮取 (卖出后,转账前)
|
|
377
380
|
if (profitAmount > 0n) {
|
|
378
381
|
calls.push({
|
|
379
382
|
target: sellerWallet.address,
|
|
@@ -382,10 +385,26 @@ export async function bundleSwap(params) {
|
|
|
382
385
|
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
383
386
|
});
|
|
384
387
|
}
|
|
385
|
-
// 3.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
+
// 3. 卖家转账给第一个接收者 (分发剩余 OKB)
|
|
389
|
+
calls.push({
|
|
390
|
+
target: sellerWallet.address,
|
|
391
|
+
allowFailure: false,
|
|
392
|
+
value: 0n,
|
|
393
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
|
|
394
|
+
});
|
|
395
|
+
// 4. 中间钱包之间的转账
|
|
396
|
+
for (let i = 0; i < hopWallets.length; i++) {
|
|
397
|
+
const nextRecipient = i < hopWallets.length - 1 ? hopWallets[i + 1].address : buyerWallet.address;
|
|
398
|
+
calls.push({
|
|
399
|
+
target: hopWallets[i].address,
|
|
400
|
+
allowFailure: false,
|
|
401
|
+
value: 0n,
|
|
402
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [nextRecipient]),
|
|
403
|
+
});
|
|
388
404
|
}
|
|
405
|
+
// 5. 买家买入 (使用指定金额)
|
|
406
|
+
const buyCall = buildBuyCallInternal(buyerWallet, buyAmount, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
407
|
+
calls.push(buyCall);
|
|
389
408
|
}
|
|
390
409
|
// ========================================
|
|
391
410
|
// 同步构建交易
|
|
@@ -470,21 +489,38 @@ export async function bundleBatchSwap(params) {
|
|
|
470
489
|
// 普通模式:只卖币,不转账
|
|
471
490
|
const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
472
491
|
calls.push(sellCall);
|
|
492
|
+
// ✅ 利润刮取 (如果是 Independent 模式,直接从卖家余额扣)
|
|
493
|
+
if (profitAmount > 0n) {
|
|
494
|
+
calls.push({
|
|
495
|
+
target: sellerWallet.address,
|
|
496
|
+
allowFailure: false,
|
|
497
|
+
value: 0n,
|
|
498
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
499
|
+
});
|
|
500
|
+
}
|
|
473
501
|
}
|
|
474
502
|
else {
|
|
475
|
-
//
|
|
503
|
+
// 资金利用率模式:卖出 -> 扣利润 -> 转账 -> 买入
|
|
476
504
|
const firstRecipient = hopWallets.length > 0 ? hopWallets[0].address : buyerWallets[0].address;
|
|
477
|
-
|
|
505
|
+
// 1.1 卖出 (统一使用非转账 sell 函数,确保利润能成功扣除)
|
|
506
|
+
const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
478
507
|
calls.push(sellCall);
|
|
479
|
-
//
|
|
480
|
-
if (
|
|
508
|
+
// 1.2 扣除利润 (在卖家转账给下游之前)
|
|
509
|
+
if (profitAmount > 0n) {
|
|
481
510
|
calls.push({
|
|
482
511
|
target: sellerWallet.address,
|
|
483
512
|
allowFailure: false,
|
|
484
513
|
value: 0n,
|
|
485
|
-
callData: delegateInterface.encodeFunctionData('
|
|
514
|
+
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
486
515
|
});
|
|
487
516
|
}
|
|
517
|
+
// 1.3 卖家转账给第一个接收者
|
|
518
|
+
calls.push({
|
|
519
|
+
target: sellerWallet.address,
|
|
520
|
+
allowFailure: false,
|
|
521
|
+
value: 0n,
|
|
522
|
+
callData: delegateInterface.encodeFunctionData('transferTo', [firstRecipient]),
|
|
523
|
+
});
|
|
488
524
|
// 中间钱包转账
|
|
489
525
|
for (let i = 0; i < hopWallets.length - 1; i++) {
|
|
490
526
|
calls.push({
|
|
@@ -532,15 +568,6 @@ export async function bundleBatchSwap(params) {
|
|
|
532
568
|
const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
|
|
533
569
|
calls.push(buyCall);
|
|
534
570
|
}
|
|
535
|
-
// ✅ 5. 利润刮取(放在最后)
|
|
536
|
-
if (profitAmount > 0n) {
|
|
537
|
-
calls.push({
|
|
538
|
-
target: sellerWallet.address,
|
|
539
|
-
allowFailure: false,
|
|
540
|
-
value: 0n,
|
|
541
|
-
callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
571
|
// ========================================
|
|
545
572
|
// 同步签署授权(并行)
|
|
546
573
|
// ========================================
|