four-flap-meme-sdk 1.6.75 → 1.6.76
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.
|
@@ -345,6 +345,9 @@ export class HopWalletManager {
|
|
|
345
345
|
deployed: hopDeployedOnChain[i],
|
|
346
346
|
balance: ethers.formatEther(hopBalances[i]),
|
|
347
347
|
})));
|
|
348
|
+
// ✅ 记录 Payer nonce,避免冲突
|
|
349
|
+
let payerNonceCounter = await this.provider.getTransactionCount(payerWallet.address, 'pending');
|
|
350
|
+
const connectedPayer = payerWallet.connect(this.provider);
|
|
348
351
|
for (let i = 0; i < hopWallets.length; i++) {
|
|
349
352
|
const hop = hopWallets[i];
|
|
350
353
|
try {
|
|
@@ -363,23 +366,24 @@ export class HopWalletManager {
|
|
|
363
366
|
// 增加 20% buffer 确保足够
|
|
364
367
|
const estimatedPrefund = (totalGasNeeded * gasPrice * 120n) / 100n;
|
|
365
368
|
console.log(`[HopWalletManager] Hop ${i} prefund 估算: callGas=${callGasLimit}, verifyGas=${verificationGasLimit}, preVerify=${preVerificationGas}, total=${totalGasNeeded}, prefund=${ethers.formatEther(estimatedPrefund)} OKB, balance=${ethers.formatEther(balance)} OKB, deployed=${isDeployed}`);
|
|
366
|
-
// ✅
|
|
369
|
+
// ✅ 最小可退金额(至少要有这么多才值得退款)
|
|
370
|
+
const minRefundAmount = gasPrice * 50000n; // ~0.00005 OKB
|
|
371
|
+
// ✅ 关键改进:如果余额不足 prefund + minRefund,先让 Payer 给 Hop 充值差额
|
|
367
372
|
let effectiveBalance = balance;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
373
|
+
const minNeededForRefund = estimatedPrefund + minRefundAmount;
|
|
374
|
+
if (balance < minNeededForRefund) {
|
|
375
|
+
// 计算需要充值的金额(差额 + 少量 buffer,确保能退回一些)
|
|
376
|
+
const shortfall = minNeededForRefund - balance + (gasPrice * 20000n);
|
|
371
377
|
console.log(`[HopWalletManager] Hop ${i} 余额不足,需要补充: ${ethers.formatEther(shortfall)} OKB`);
|
|
372
378
|
try {
|
|
373
|
-
// 使用 Payer 给 Hop 充值
|
|
374
|
-
const connectedPayer = payerWallet.connect(this.provider);
|
|
375
|
-
const payerNonce = await this.provider.getTransactionCount(payerWallet.address, 'pending');
|
|
376
379
|
const topUpTx = await connectedPayer.sendTransaction({
|
|
377
380
|
to: hop.senderAddress,
|
|
378
381
|
value: shortfall,
|
|
379
|
-
nonce:
|
|
382
|
+
nonce: payerNonceCounter,
|
|
380
383
|
gasPrice,
|
|
381
384
|
gasLimit: 21055n,
|
|
382
385
|
});
|
|
386
|
+
payerNonceCounter++; // ✅ 递增 nonce
|
|
383
387
|
console.log(`[HopWalletManager] Hop ${i} 补充转账已发送: ${topUpTx.hash}`);
|
|
384
388
|
// 等待确认
|
|
385
389
|
const receipt = await topUpTx.wait();
|
|
@@ -401,6 +405,16 @@ export class HopWalletManager {
|
|
|
401
405
|
}
|
|
402
406
|
}
|
|
403
407
|
const refundAmount = effectiveBalance - estimatedPrefund;
|
|
408
|
+
// ✅ 安全检查:确保退款金额为正数
|
|
409
|
+
if (refundAmount <= 0n) {
|
|
410
|
+
console.warn(`[HopWalletManager] Hop ${i} 退款金额为 ${refundAmount},跳过`);
|
|
411
|
+
hopRefunds.push({
|
|
412
|
+
hopIndex: hop.index,
|
|
413
|
+
refundWei: 0n,
|
|
414
|
+
error: `退款金额不足: ${ethers.formatEther(refundAmount)} OKB`,
|
|
415
|
+
});
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
404
418
|
const initCode = isDeployed ? '0x' : hop.initCode;
|
|
405
419
|
// 构建 UserOp
|
|
406
420
|
const hopWallet = new Wallet(hop.privateKey, this.provider);
|
|
@@ -455,7 +469,6 @@ export class HopWalletManager {
|
|
|
455
469
|
});
|
|
456
470
|
// 发送 handleOps
|
|
457
471
|
try {
|
|
458
|
-
const connectedPayer = payerWallet.connect(this.provider);
|
|
459
472
|
const entryPointAddress = this.aaManager.getEntryPointAddress();
|
|
460
473
|
// ✅ 直接创建新 Contract 实例(跟其他地方一样)
|
|
461
474
|
const entryPointWithSigner = new ethers.Contract(entryPointAddress, ['function handleOps((address sender,uint256 nonce,bytes initCode,bytes callData,uint256 callGasLimit,uint256 verificationGasLimit,uint256 preVerificationGas,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,bytes paymasterAndData,bytes signature)[] ops, address payable beneficiary) external'], connectedPayer);
|