four-flap-meme-sdk 1.7.65 → 1.7.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.
@@ -36,10 +36,13 @@ export declare function estimateErc20TransferGas(provider: JsonRpcProvider, toke
36
36
  export declare function estimateMaxErc20TransferGas(provider: JsonRpcProvider, tokenAddress: string, from: string, recipients: string[], amounts: bigint[], bufferPercent?: number): Promise<bigint>;
37
37
  /**
38
38
  * 计算 Gas Limit
39
- * - 原生代币转账:21000 gas(固定)
39
+ * - 原生代币转账:
40
+ * - BSC: 21000 gas(固定)
41
+ * - XLayer: 50000 gas(EIP-7702 授权地址需要更多 gas)
40
42
  * - ERC20 标准 transfer:约 45000-55000 gas,使用 55000 作为安全值
41
43
  *
42
44
  * ✅ 优化:降低 ERC20 gas limit,减少中转钱包 BNB 残留
45
+ * ✅ XLayer 特殊处理:EIP-7702 授权的地址接收 OKB 时会触发 delegate 代码,需要更多 gas
43
46
  */
44
47
  export declare function calculateGasLimit(config: any, isNative: boolean, hasHops: boolean, hopCount?: number): bigint;
45
48
  export declare function isNativeTokenAddress(tokenAddress?: string): boolean;
@@ -195,17 +195,25 @@ export async function estimateMaxErc20TransferGas(provider, tokenAddress, from,
195
195
  }
196
196
  /**
197
197
  * 计算 Gas Limit
198
- * - 原生代币转账:21000 gas(固定)
198
+ * - 原生代币转账:
199
+ * - BSC: 21000 gas(固定)
200
+ * - XLayer: 50000 gas(EIP-7702 授权地址需要更多 gas)
199
201
  * - ERC20 标准 transfer:约 45000-55000 gas,使用 55000 作为安全值
200
202
  *
201
203
  * ✅ 优化:降低 ERC20 gas limit,减少中转钱包 BNB 残留
204
+ * ✅ XLayer 特殊处理:EIP-7702 授权的地址接收 OKB 时会触发 delegate 代码,需要更多 gas
202
205
  */
203
206
  export function calculateGasLimit(config, isNative, hasHops, hopCount = 0) {
204
207
  if (config.gasLimit !== undefined) {
205
208
  return BigInt(config.gasLimit);
206
209
  }
207
- // ✅ 原生代币: 21000, ERC20 标准 transfer: 48000USDT 最低约 46815)
208
- const baseGas = isNative ? 21000 : 46815;
210
+ // ✅ XLayer 链(chainId=196)原生代币需要更多 gasEIP-7702 delegate 执行)
211
+ const isXLayer = config.chainId === 196;
212
+ // ✅ 原生代币: BSC 21000, XLayer 50000(EIP-7702 安全)
213
+ // ✅ ERC20 标准 transfer: 48000(USDT 最低约 46815)
214
+ const baseGas = isNative
215
+ ? (isXLayer ? 50000 : 21000)
216
+ : 46815;
209
217
  // ✅ 多跳时只需要累加单次转账的 gas,不需要额外乘数
210
218
  // 每个中转钱包只执行一笔 transfer
211
219
  if (hasHops && hopCount > 0) {
@@ -391,14 +391,15 @@ export async function bundleSwap(params) {
391
391
  const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
392
392
  // 多跳转账(如果有)
393
393
  if (hopWallets.length > 0) {
394
- // 卖家 hop1
394
+ // 修复:卖家只转移"卖出所得 - 利润",不是全部余额
395
+ // 避免把卖家原有的 OKB 也转走
395
396
  calls.push({
396
397
  target: sellerWallet.address,
397
398
  allowFailure: false,
398
399
  value: 0n,
399
- callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[0].address]),
400
+ callData: delegateInterface.encodeFunctionData('transferAmount', [hopWallets[0].address, buyAmountAfterProfit]),
400
401
  });
401
- // hop1 → hop2 → ... → 最后一个 hop(分发者)
402
+ // hop1 → hop2 → ... → 最后一个 hop(分发者):使用 transferTo(全部余额)
402
403
  for (let i = 0; i < hopWallets.length - 1; i++) {
403
404
  calls.push({
404
405
  target: hopWallets[i].address,
@@ -408,12 +409,12 @@ export async function bundleSwap(params) {
408
409
  });
409
410
  }
410
411
  }
411
- // 4. 分发者按比例转账给买家
412
+ // 4. 分发者转账给买家:使用 transferTo(全部余额,确保资金不滞留)
412
413
  calls.push({
413
414
  target: distributor.address,
414
415
  allowFailure: false,
415
416
  value: 0n,
416
- callData: delegateInterface.encodeFunctionData('transferAmount', [buyerWallet.address, buyAmountAfterProfit]),
417
+ callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallet.address]),
417
418
  });
418
419
  // 5. 买家买入(使用收到的 OKB)
419
420
  const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
@@ -603,14 +604,15 @@ export async function bundleBatchSwap(params) {
603
604
  // 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
604
605
  const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
605
606
  if (hopWallets.length > 0) {
606
- // 有多跳:卖家 hop1 → hop2 → ... → 最后一个 hop(分发者)
607
+ // 修复:卖家只转移"卖出所得 - 利润",不是全部余额
608
+ // 避免把卖家原有的 OKB 也转走
607
609
  calls.push({
608
610
  target: sellerWallet.address,
609
611
  allowFailure: false,
610
612
  value: 0n,
611
- callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[0].address]),
613
+ callData: delegateInterface.encodeFunctionData('transferAmount', [hopWallets[0].address, totalBuyAmountAfterProfit]),
612
614
  });
613
- // 中间钱包之间转账(到最后一个 hop
615
+ // 中间钱包之间转账(到最后一个 hop):使用 transferTo(全部余额)
614
616
  for (let i = 0; i < hopWallets.length - 1; i++) {
615
617
  calls.push({
616
618
  target: hopWallets[i].address,
@@ -625,11 +627,15 @@ export async function bundleBatchSwap(params) {
625
627
  const amountToTransfer = buyAmountsPerBuyer[i];
626
628
  if (amountToTransfer <= 0n)
627
629
  continue;
630
+ // ✅ 最后一个买家使用 transferTo(全部余额),确保资金不滞留
631
+ const isLastBuyer = i === buyerWallets.length - 1;
628
632
  calls.push({
629
633
  target: distributor.address,
630
634
  allowFailure: false,
631
635
  value: 0n,
632
- callData: delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, amountToTransfer]),
636
+ callData: isLastBuyer
637
+ ? delegateInterface.encodeFunctionData('transferTo', [buyerWallets[i].address])
638
+ : delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, amountToTransfer]),
633
639
  });
634
640
  }
635
641
  // 4. 所有买家买入
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.65",
3
+ "version": "1.7.67",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",