four-flap-meme-sdk 1.5.41 → 1.5.43
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.d.ts +0 -3
- package/dist/xlayer/bundle.js +55 -62
- package/package.json +1 -1
package/dist/xlayer/bundle.d.ts
CHANGED
|
@@ -91,9 +91,6 @@ export declare class BundleExecutor {
|
|
|
91
91
|
* 捆绑发射代币 + 购买(签名版本)
|
|
92
92
|
*/
|
|
93
93
|
bundleCreateBuySign(params: BundleCreateBuySignParams): Promise<BundleCreateBuySignResult>;
|
|
94
|
-
/**
|
|
95
|
-
* 捆绑发射代币 + 购买(执行版本)
|
|
96
|
-
*/
|
|
97
94
|
bundleCreateBuy(params: BundleCreateBuyParams): Promise<BundleCreateBuyResult>;
|
|
98
95
|
/**
|
|
99
96
|
* 检查多个 AA 账户的授权状态
|
package/dist/xlayer/bundle.js
CHANGED
|
@@ -1131,12 +1131,10 @@ export class BundleExecutor {
|
|
|
1131
1131
|
console.log('token:', tokenInfo.symbol);
|
|
1132
1132
|
console.log('dev:', devWallet.address);
|
|
1133
1133
|
console.log('buyers:', buyerWallets.length);
|
|
1134
|
-
// 1. 准备代币地址
|
|
1135
1134
|
const tokenAddress = params.tokenAddress || ZERO_ADDRESS;
|
|
1136
|
-
// 2. 构造 UserOperations
|
|
1135
|
+
// 2. 构造 UserOperations (主要涵盖发币和购买)
|
|
1137
1136
|
const ops = [];
|
|
1138
1137
|
const nonceMap = new AANonceMap();
|
|
1139
|
-
// 2a. Dev 发射代币
|
|
1140
1138
|
const devAccount = await this.aaManager.getAccountInfo(devWallet.address);
|
|
1141
1139
|
nonceMap.init(devAccount.sender, devAccount.nonce);
|
|
1142
1140
|
const useV4 = params.dexId !== undefined || params.lpFeeProfile !== undefined;
|
|
@@ -1206,16 +1204,13 @@ export class BundleExecutor {
|
|
|
1206
1204
|
});
|
|
1207
1205
|
const signedDevOp = await this.aaManager.signUserOp(devCreateOp.userOp, devWallet);
|
|
1208
1206
|
ops.push(signedDevOp.userOp);
|
|
1209
|
-
// 2b. Buyers 买入
|
|
1210
1207
|
const profitSettings = resolveProfitSettings(effConfig);
|
|
1211
1208
|
const inputToken = params.quoteToken && params.quoteToken !== ZERO_ADDRESS ? params.quoteToken : ZERO_ADDRESS;
|
|
1212
1209
|
const useNativeToken = inputToken === ZERO_ADDRESS;
|
|
1213
|
-
// BundleCreateBuyParams 目前没有 quoteTokenDecimals,默认用 18
|
|
1214
1210
|
const quoteDecimals = 18;
|
|
1215
1211
|
let totalBuyWei = 0n;
|
|
1216
|
-
let totalBuyProfitWei = 0n;
|
|
1212
|
+
let totalBuyProfitWei = 0n;
|
|
1217
1213
|
const buyerSenders = [];
|
|
1218
|
-
const profitWeis = [];
|
|
1219
1214
|
const portalIface = new Interface(PORTAL_ABI);
|
|
1220
1215
|
for (let i = 0; i < buyerWallets.length; i++) {
|
|
1221
1216
|
const buyer = buyerWallets[i];
|
|
@@ -1230,11 +1225,9 @@ export class BundleExecutor {
|
|
|
1230
1225
|
}
|
|
1231
1226
|
totalBuyWei += buyWei;
|
|
1232
1227
|
totalBuyProfitWei += profitWei;
|
|
1233
|
-
profitWeis.push(profitWei);
|
|
1234
1228
|
const buyerAccount = await this.aaManager.getAccountInfo(buyer.address);
|
|
1235
1229
|
buyerSenders.push(buyerAccount.sender);
|
|
1236
1230
|
nonceMap.init(buyerAccount.sender, buyerAccount.nonce);
|
|
1237
|
-
// 买入:使用扣除利润后的金额
|
|
1238
1231
|
const swapData = portalIface.encodeFunctionData('swapExactInput', [
|
|
1239
1232
|
{
|
|
1240
1233
|
inputToken,
|
|
@@ -1255,10 +1248,9 @@ export class BundleExecutor {
|
|
|
1255
1248
|
const signedBuyOp = await this.aaManager.signUserOp(buyOp.userOp, buyer);
|
|
1256
1249
|
ops.push(signedBuyOp.userOp);
|
|
1257
1250
|
}
|
|
1258
|
-
|
|
1251
|
+
let nativeProfitAmount = 0n;
|
|
1259
1252
|
if (profitSettings.extractProfit && totalBuyProfitWei > 0n) {
|
|
1260
|
-
|
|
1261
|
-
let nativeProfitAmount = totalBuyProfitWei;
|
|
1253
|
+
nativeProfitAmount = totalBuyProfitWei;
|
|
1262
1254
|
if (!useNativeToken) {
|
|
1263
1255
|
try {
|
|
1264
1256
|
const dq = new DexQuery(effConfig);
|
|
@@ -1274,38 +1266,34 @@ export class BundleExecutor {
|
|
|
1274
1266
|
}
|
|
1275
1267
|
}
|
|
1276
1268
|
}
|
|
1277
|
-
if (nativeProfitAmount > 0n) {
|
|
1278
|
-
console.log(`[利润提取-签名] 总利润: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
|
|
1279
|
-
// 找到利润贡献最大的买家作为利润转账的 sender
|
|
1280
|
-
const maxProfitIndex = profitWeis.reduce((maxIdx, p, idx) => p > (profitWeis[maxIdx] ?? 0n) ? idx : maxIdx, 0);
|
|
1281
|
-
const pOwner = buyerWallets[maxProfitIndex];
|
|
1282
|
-
const pSender = buyerSenders[maxProfitIndex];
|
|
1283
|
-
// 利润转账:直接转 OKB(对齐 bundleBuy 语义)
|
|
1284
|
-
const profitCallData = encodeExecute(profitSettings.profitRecipient, nativeProfitAmount, '0x');
|
|
1285
|
-
const profitOp = await this.aaManager.buildUserOpWithFixedGas({
|
|
1286
|
-
ownerWallet: pOwner,
|
|
1287
|
-
sender: pSender,
|
|
1288
|
-
callData: profitCallData,
|
|
1289
|
-
nonce: nonceMap.next(pSender),
|
|
1290
|
-
initCode: '0x', // 之前买入阶段已处理 initCode
|
|
1291
|
-
deployed: true,
|
|
1292
|
-
fixedGas: {
|
|
1293
|
-
...(effConfig.fixedGas ?? {}),
|
|
1294
|
-
callGasLimit: effConfig.fixedGas?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT_WITHDRAW,
|
|
1295
|
-
}
|
|
1296
|
-
});
|
|
1297
|
-
const signedProfitOp = await this.aaManager.signUserOp(profitOp.userOp, pOwner);
|
|
1298
|
-
ops.push(signedProfitOp.userOp);
|
|
1299
|
-
}
|
|
1300
1269
|
}
|
|
1301
|
-
|
|
1302
|
-
const
|
|
1270
|
+
const provider = this.aaManager.getProvider();
|
|
1271
|
+
const startNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
|
|
1272
|
+
const signedTransactions = [];
|
|
1273
|
+
const signedMainTx = await this.signHandleOpsTx({
|
|
1303
1274
|
ops,
|
|
1304
1275
|
payerWallet: payer,
|
|
1305
|
-
beneficiary: useBeneficiary
|
|
1276
|
+
beneficiary: useBeneficiary,
|
|
1277
|
+
nonce: startNonce
|
|
1306
1278
|
});
|
|
1279
|
+
signedTransactions.push(signedMainTx);
|
|
1280
|
+
if (nativeProfitAmount > 0n) {
|
|
1281
|
+
console.log(`[利润提取-签名] 非 AA 转账: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
|
|
1282
|
+
const feeData = await provider.getFeeData();
|
|
1283
|
+
const gasPrice = feeData.gasPrice ?? 100000000n;
|
|
1284
|
+
const profitTxRequest = {
|
|
1285
|
+
to: profitSettings.profitRecipient,
|
|
1286
|
+
value: nativeProfitAmount,
|
|
1287
|
+
nonce: startNonce + 1,
|
|
1288
|
+
gasLimit: 21000n,
|
|
1289
|
+
gasPrice: gasPrice,
|
|
1290
|
+
chainId: (await provider.getNetwork()).chainId
|
|
1291
|
+
};
|
|
1292
|
+
const signedProfitTx = await payer.signTransaction(profitTxRequest);
|
|
1293
|
+
signedTransactions.push(signedProfitTx);
|
|
1294
|
+
}
|
|
1307
1295
|
return {
|
|
1308
|
-
signedTransactions
|
|
1296
|
+
signedTransactions,
|
|
1309
1297
|
tokenAddress,
|
|
1310
1298
|
metadata: {
|
|
1311
1299
|
tokenAddress,
|
|
@@ -1317,42 +1305,47 @@ export class BundleExecutor {
|
|
|
1317
1305
|
}
|
|
1318
1306
|
};
|
|
1319
1307
|
}
|
|
1320
|
-
/**
|
|
1321
|
-
* 捆绑发射代币 + 购买(执行版本)
|
|
1322
|
-
*/
|
|
1323
1308
|
async bundleCreateBuy(params) {
|
|
1324
1309
|
const signResult = await this.bundleCreateBuySign({
|
|
1325
1310
|
...params,
|
|
1326
1311
|
payerPrivateKey: params.privateKeys[0]
|
|
1327
1312
|
});
|
|
1328
1313
|
const sharedProvider = this.aaManager.getProvider();
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
const epIface = new Interface(ENTRYPOINT_ABI);
|
|
1314
|
+
let mainTxHash = '';
|
|
1315
|
+
let lastReceipt;
|
|
1332
1316
|
const userOpEvents = [];
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1317
|
+
const epIface = new Interface(ENTRYPOINT_ABI);
|
|
1318
|
+
for (let i = 0; i < signResult.signedTransactions.length; i++) {
|
|
1319
|
+
const signedTx = signResult.signedTransactions[i];
|
|
1320
|
+
const tx = await sharedProvider.broadcastTransaction(signedTx);
|
|
1321
|
+
if (i === 0)
|
|
1322
|
+
mainTxHash = tx.hash;
|
|
1323
|
+
const receipt = await tx.wait();
|
|
1324
|
+
lastReceipt = receipt;
|
|
1325
|
+
if (receipt) {
|
|
1326
|
+
for (const log of receipt.logs) {
|
|
1327
|
+
try {
|
|
1328
|
+
const parsed = epIface.parseLog(log);
|
|
1329
|
+
if (parsed?.name === 'UserOperationEvent') {
|
|
1330
|
+
userOpEvents.push({
|
|
1331
|
+
userOpHash: parsed.args.userOpHash,
|
|
1332
|
+
sender: parsed.args.sender,
|
|
1333
|
+
paymaster: parsed.args.paymaster,
|
|
1334
|
+
success: parsed.args.success,
|
|
1335
|
+
actualGasCost: parsed.args.actualGasCost,
|
|
1336
|
+
actualGasUsed: parsed.args.actualGasUsed
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1346
1339
|
}
|
|
1340
|
+
catch { }
|
|
1347
1341
|
}
|
|
1348
|
-
catch { }
|
|
1349
1342
|
}
|
|
1350
1343
|
}
|
|
1351
1344
|
return {
|
|
1352
1345
|
createBuyResult: {
|
|
1353
|
-
txHash:
|
|
1354
|
-
blockNumber:
|
|
1355
|
-
status:
|
|
1346
|
+
txHash: mainTxHash,
|
|
1347
|
+
blockNumber: lastReceipt?.blockNumber ?? 0,
|
|
1348
|
+
status: lastReceipt?.status ?? 0,
|
|
1356
1349
|
userOpEvents
|
|
1357
1350
|
},
|
|
1358
1351
|
tokenAddress: signResult.tokenAddress
|