four-flap-meme-sdk 1.2.76 → 1.2.77
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.
|
@@ -225,17 +225,12 @@ export async function batchBuyWithBundleMerkle(params) {
|
|
|
225
225
|
throw new Error(getErrorMessage('KEY_AMOUNT_MISMATCH'));
|
|
226
226
|
}
|
|
227
227
|
const { provider, chainId } = createChainContext(config.rpcUrl);
|
|
228
|
-
const buyers = createWallets(privateKeys, provider);
|
|
229
228
|
const txType = getTxType(config);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
(
|
|
234
|
-
|
|
235
|
-
// 预加载所有钱包的 nonce(批量查询)
|
|
236
|
-
await Promise.all(buyers.map(w => nm.getNextNonce(w)));
|
|
237
|
-
return nm;
|
|
238
|
-
})()
|
|
229
|
+
const buyers = createWallets(privateKeys, provider);
|
|
230
|
+
// ✅ 优化:并行初始化 nonceManager 和获取 gasPrice
|
|
231
|
+
const [nonceManager, gasPrice] = await Promise.all([
|
|
232
|
+
Promise.resolve(new NonceManager(provider)),
|
|
233
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config))
|
|
239
234
|
]);
|
|
240
235
|
const buyFlow = await executeBuyFlow({
|
|
241
236
|
wallets: buyers,
|
|
@@ -261,18 +256,10 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
261
256
|
throw new Error(getErrorMessage('SELL_KEY_AMOUNT_MISMATCH'));
|
|
262
257
|
}
|
|
263
258
|
const { provider, chainId } = createChainContext(config.rpcUrl);
|
|
259
|
+
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
260
|
+
const nonceManager = new NonceManager(provider);
|
|
264
261
|
const sellers = createWallets(privateKeys, provider);
|
|
265
262
|
const txType = getTxType(config);
|
|
266
|
-
// ✅ 优化:并行执行 gasPrice 获取和 nonce 预加载
|
|
267
|
-
const [gasPrice, nonceManager] = await Promise.all([
|
|
268
|
-
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
269
|
-
(async () => {
|
|
270
|
-
const nm = new NonceManager(provider);
|
|
271
|
-
// 预加载所有钱包的 nonce(批量查询)
|
|
272
|
-
await Promise.all(sellers.map(w => nm.getNextNonce(w)));
|
|
273
|
-
return nm;
|
|
274
|
-
})()
|
|
275
|
-
]);
|
|
276
263
|
const sellFlow = await executeSellFlow({
|
|
277
264
|
wallets: sellers,
|
|
278
265
|
sellAmounts,
|
|
@@ -128,21 +128,16 @@ export async function batchBuyWithBundleMerkle(params) {
|
|
|
128
128
|
throw new Error(getErrorMessage('KEY_AMOUNT_MISMATCH'));
|
|
129
129
|
}
|
|
130
130
|
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
131
|
+
const nonceManager = new NonceManager(provider);
|
|
132
|
+
const signedTxs = [];
|
|
131
133
|
const buyers = createWallets(privateKeys, provider);
|
|
132
134
|
const extractProfit = shouldExtractProfit(config);
|
|
133
135
|
const { fundsList, originalAmounts, totalBuyAmount, totalProfit } = analyzeBuyFunds(buyAmounts, config, extractProfit);
|
|
134
136
|
const maxFundsIndex = findMaxIndex(originalAmounts);
|
|
135
137
|
const gasLimits = buildGasLimitList(buyers.length, config);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const [gasPrice, nonceManager, unsignedBuys] = await Promise.all([
|
|
138
|
+
// ✅ 优化:并行执行 gasPrice 和 populateBuyTransactions(最耗时的两个操作)
|
|
139
|
+
const [gasPrice, unsignedBuys] = await Promise.all([
|
|
139
140
|
resolveGasPrice(provider, config),
|
|
140
|
-
(async () => {
|
|
141
|
-
const nm = new NonceManager(provider);
|
|
142
|
-
// 预加载所有钱包的 nonce(批量查询)
|
|
143
|
-
await Promise.all(buyers.map(w => nm.getNextNonce(w)));
|
|
144
|
-
return nm;
|
|
145
|
-
})(),
|
|
146
141
|
populateBuyTransactions(buyers, FLAP_PORTAL_ADDRESSES[chain], tokenAddress, fundsList)
|
|
147
142
|
]);
|
|
148
143
|
const buyerNonces = await allocateBuyerNonces(buyers, extractProfit, maxFundsIndex, totalProfit, nonceManager);
|
|
@@ -184,35 +179,25 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
184
179
|
throw new Error(getErrorMessage('SELL_KEY_AMOUNT_MISMATCH'));
|
|
185
180
|
}
|
|
186
181
|
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
182
|
+
const gasPrice = await resolveGasPrice(provider, config);
|
|
183
|
+
const nonceManager = new NonceManager(provider);
|
|
184
|
+
const signedTxs = [];
|
|
187
185
|
const wallets = createWallets(privateKeys, provider);
|
|
188
186
|
const amountsWei = sellAmounts.map(a => ethers.parseUnits(a, 18));
|
|
189
187
|
const portalAddr = FLAP_PORTAL_ADDRESSES[chain];
|
|
190
188
|
const readOnlyPortal = new ethers.Contract(portalAddr, PORTAL_ABI, provider);
|
|
191
|
-
const
|
|
192
|
-
const signedTxs = [];
|
|
193
|
-
// ✅ 优化:并行执行所有 RPC 调用(gasPrice + nonces + quotes)
|
|
194
|
-
const [gasPrice, nonceManager, quotedOutputs] = await Promise.all([
|
|
195
|
-
resolveGasPrice(provider, config),
|
|
196
|
-
(async () => {
|
|
197
|
-
const nm = new NonceManager(provider);
|
|
198
|
-
// 预加载所有钱包的 nonce(批量查询)
|
|
199
|
-
await Promise.all(wallets.map(w => nm.getNextNonce(w)));
|
|
200
|
-
return nm;
|
|
201
|
-
})(),
|
|
202
|
-
quoteSellOutputs(readOnlyPortal, tokenAddress, amountsWei)
|
|
203
|
-
]);
|
|
189
|
+
const quotedOutputs = await quoteSellOutputs(readOnlyPortal, tokenAddress, amountsWei);
|
|
204
190
|
const minOuts = resolveMinOutputs(minOutputAmounts, wallets.length, quotedOutputs);
|
|
205
|
-
|
|
206
|
-
const unsignedList = await Promise.all(
|
|
191
|
+
const portals = wallets.map(w => new ethers.Contract(portalAddr, PORTAL_ABI, w));
|
|
192
|
+
const unsignedList = await Promise.all(portals.map((portal, i) => portal.swapExactInput.populateTransaction({
|
|
207
193
|
inputToken: tokenAddress,
|
|
208
194
|
outputToken: ZERO_ADDRESS,
|
|
209
195
|
inputAmount: amountsWei[i],
|
|
210
196
|
minOutputAmount: minOuts[i],
|
|
211
197
|
permitData: '0x'
|
|
212
198
|
})));
|
|
213
|
-
|
|
199
|
+
const gasLimits = buildGasLimitList(wallets.length, config);
|
|
214
200
|
const nonces = await Promise.all(wallets.map(w => nonceManager.getNextNonce(w)));
|
|
215
|
-
// ✅ 优化:批量签名交易
|
|
216
201
|
const signedList = await Promise.all(unsignedList.map((unsigned, i) => wallets[i].signTransaction({
|
|
217
202
|
...unsigned,
|
|
218
203
|
from: wallets[i].address,
|
|
@@ -288,15 +273,14 @@ function findMaxIndex(values) {
|
|
|
288
273
|
return maxIndex;
|
|
289
274
|
}
|
|
290
275
|
async function populateBuyTransactions(buyers, portalAddr, tokenAddress, fundsList) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return await Promise.all(fundsList.map((funds) => portal.swapExactInput.populateTransaction({
|
|
276
|
+
const portals = buyers.map(wallet => new ethers.Contract(portalAddr, PORTAL_ABI, wallet));
|
|
277
|
+
return await Promise.all(portals.map((portal, i) => portal.swapExactInput.populateTransaction({
|
|
294
278
|
inputToken: ZERO_ADDRESS,
|
|
295
279
|
outputToken: tokenAddress,
|
|
296
|
-
inputAmount:
|
|
280
|
+
inputAmount: fundsList[i],
|
|
297
281
|
minOutputAmount: 0n,
|
|
298
282
|
permitData: '0x'
|
|
299
|
-
}, { value:
|
|
283
|
+
}, { value: fundsList[i] })));
|
|
300
284
|
}
|
|
301
285
|
function buildGasLimitList(length, config) {
|
|
302
286
|
const gasLimit = getGasLimit(config);
|