four-flap-meme-sdk 1.5.44 → 1.5.46
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/bundle.js +13 -57
- package/package.json +1 -1
package/dist/xlayer/bundle.js
CHANGED
|
@@ -1135,8 +1135,8 @@ export class BundleExecutor {
|
|
|
1135
1135
|
// 2. 构造 UserOperations (主要涵盖发币和购买)
|
|
1136
1136
|
const ops = [];
|
|
1137
1137
|
const nonceMap = new AANonceMap();
|
|
1138
|
-
const
|
|
1139
|
-
nonceMap.init(
|
|
1138
|
+
const payerAccount = await this.aaManager.getAccountInfo(payer.address);
|
|
1139
|
+
nonceMap.init(payerAccount.sender, payerAccount.nonce);
|
|
1140
1140
|
const useV4 = params.dexId !== undefined || params.lpFeeProfile !== undefined;
|
|
1141
1141
|
const useV3 = !useV4 && !!params.extensionID;
|
|
1142
1142
|
let createCallData;
|
|
@@ -1195,14 +1195,14 @@ export class BundleExecutor {
|
|
|
1195
1195
|
});
|
|
1196
1196
|
}
|
|
1197
1197
|
const devCreateOp = await this.aaManager.buildUserOpWithFixedGas({
|
|
1198
|
-
ownerWallet:
|
|
1199
|
-
sender:
|
|
1198
|
+
ownerWallet: payer, // ✅ 改用 payer 作为发币者
|
|
1199
|
+
sender: payerAccount.sender,
|
|
1200
1200
|
callData: encodeExecute(this.portalAddress, params.quoteAmt || 0n, createCallData),
|
|
1201
|
-
nonce: nonceMap.next(
|
|
1202
|
-
initCode:
|
|
1203
|
-
deployed:
|
|
1201
|
+
nonce: nonceMap.next(payerAccount.sender),
|
|
1202
|
+
initCode: payerAccount.deployed ? '0x' : this.aaManager.generateInitCode(payer.address),
|
|
1203
|
+
deployed: payerAccount.deployed
|
|
1204
1204
|
});
|
|
1205
|
-
const signedDevOp = await this.aaManager.signUserOp(devCreateOp.userOp,
|
|
1205
|
+
const signedDevOp = await this.aaManager.signUserOp(devCreateOp.userOp, payer);
|
|
1206
1206
|
ops.push(signedDevOp.userOp);
|
|
1207
1207
|
const profitSettings = resolveProfitSettings(effConfig);
|
|
1208
1208
|
const inputToken = params.quoteToken && params.quoteToken !== ZERO_ADDRESS ? params.quoteToken : ZERO_ADDRESS;
|
|
@@ -1273,65 +1273,21 @@ export class BundleExecutor {
|
|
|
1273
1273
|
const feeData = await provider.getFeeData();
|
|
1274
1274
|
const gasPrice = feeData.gasPrice ?? 100000000n;
|
|
1275
1275
|
const chainId = (await provider.getNetwork()).chainId;
|
|
1276
|
-
|
|
1277
|
-
// === 1. 预存资金交易:payer -> 各个 AA sender ===
|
|
1278
|
-
// 计算每个 buyer sender 需要的 OKB(买入金额 + gas 余量)
|
|
1279
|
-
const GAS_BUFFER = parseOkb('0.001'); // 0.001 OKB 作为 gas 缓冲
|
|
1280
|
-
const prefundTargets = [];
|
|
1281
|
-
// Dev sender 需要 quoteAmt(发币时的首次购买金额)
|
|
1282
|
-
const devQuoteAmt = params.quoteAmt || 0n;
|
|
1283
|
-
if (useNativeToken && devQuoteAmt > 0n) {
|
|
1284
|
-
prefundTargets.push({ sender: devAccount.sender, amount: devQuoteAmt + GAS_BUFFER });
|
|
1285
|
-
}
|
|
1286
|
-
// Buyer senders 需要各自的买入金额
|
|
1287
|
-
for (let i = 0; i < buyerWallets.length; i++) {
|
|
1288
|
-
const amountStr = buyAmounts[i] || '0';
|
|
1289
|
-
const originalWei = useNativeToken ? parseOkb(amountStr) : ethers.parseUnits(amountStr, quoteDecimals);
|
|
1290
|
-
let buyWei = originalWei;
|
|
1291
|
-
if (profitSettings.extractProfit) {
|
|
1292
|
-
const res = calculateProfit(originalWei, profitSettings.profitBps);
|
|
1293
|
-
buyWei = res.remaining;
|
|
1294
|
-
}
|
|
1295
|
-
if (buyWei > 0n) {
|
|
1296
|
-
prefundTargets.push({ sender: buyerSenders[i], amount: buyWei + GAS_BUFFER });
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
// 如果有需要预存资金的地址,生成批量转账交易
|
|
1300
|
-
if (prefundTargets.length > 0) {
|
|
1301
|
-
const totalPrefund = prefundTargets.reduce((sum, t) => sum + t.amount, 0n);
|
|
1302
|
-
console.log(`[预存资金] 共 ${prefundTargets.length} 个 AA sender,总计: ${formatOkb(totalPrefund)} OKB`);
|
|
1303
|
-
// 批量转账:使用多个单独交易(因为普通 EOA 无法一次转账到多个地址)
|
|
1304
|
-
for (const target of prefundTargets) {
|
|
1305
|
-
const prefundTx = {
|
|
1306
|
-
to: target.sender,
|
|
1307
|
-
value: target.amount,
|
|
1308
|
-
nonce: currentNonce,
|
|
1309
|
-
gasLimit: 21000n,
|
|
1310
|
-
gasPrice,
|
|
1311
|
-
chainId
|
|
1312
|
-
};
|
|
1313
|
-
const signedPrefundTx = await payer.signTransaction(prefundTx);
|
|
1314
|
-
signedTransactions.push(signedPrefundTx);
|
|
1315
|
-
currentNonce++;
|
|
1316
|
-
console.log(` - prefund ${target.sender.slice(0, 10)}... = ${formatOkb(target.amount)} OKB (nonce: ${currentNonce - 1})`);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
// === 2. AA handleOps 交易 ===
|
|
1276
|
+
// === 1. AA handleOps 交易(包含所有 UserOps:创建 + 买入)===
|
|
1320
1277
|
const signedMainTx = await this.signHandleOpsTx({
|
|
1321
1278
|
ops,
|
|
1322
1279
|
payerWallet: payer,
|
|
1323
1280
|
beneficiary: useBeneficiary,
|
|
1324
|
-
nonce:
|
|
1281
|
+
nonce: startNonce
|
|
1325
1282
|
});
|
|
1326
1283
|
signedTransactions.push(signedMainTx);
|
|
1327
|
-
|
|
1328
|
-
// === 3. 利润提取交易 ===
|
|
1284
|
+
// === 2. 利润提取交易(独立的 EOA 转账)===
|
|
1329
1285
|
if (nativeProfitAmount > 0n) {
|
|
1330
1286
|
console.log(`[利润提取-签名] 非 AA 转账: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
|
|
1331
1287
|
const profitTxRequest = {
|
|
1332
1288
|
to: profitSettings.profitRecipient,
|
|
1333
1289
|
value: nativeProfitAmount,
|
|
1334
|
-
nonce:
|
|
1290
|
+
nonce: startNonce + 1,
|
|
1335
1291
|
gasLimit: 21000n,
|
|
1336
1292
|
gasPrice,
|
|
1337
1293
|
chainId
|
|
@@ -1345,7 +1301,7 @@ export class BundleExecutor {
|
|
|
1345
1301
|
metadata: {
|
|
1346
1302
|
tokenAddress,
|
|
1347
1303
|
devOwner: devWallet.address,
|
|
1348
|
-
devSender:
|
|
1304
|
+
devSender: payerAccount.sender,
|
|
1349
1305
|
buyerOwners: buyerWallets.map(w => w.address),
|
|
1350
1306
|
buyerSenders,
|
|
1351
1307
|
totalBuyWei: totalBuyWei.toString()
|