four-flap-meme-sdk 1.9.22 → 1.9.24

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.
@@ -272,10 +272,14 @@ export async function directBatchBuyForSubmit(params) {
272
272
  const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
273
273
  const transactions = [];
274
274
  const totalFlow = amounts.reduce((sum, amount) => sum + amount, 0n);
275
+ const isBatch = privateKeys.length > 1;
275
276
  for (let i = 0; i < privateKeys.length; i++) {
276
277
  const wallet = new Wallet(privateKeys[i], provider);
277
278
  const preview = await query.previewBuy(token, amounts[i]);
278
- const minOut = applySlippage(preview, slippageBps);
279
+ const effectiveSlippage = isBatch
280
+ ? Math.min(9500, slippageBps + i * 2000)
281
+ : slippageBps;
282
+ const minOut = applySlippage(preview, effectiveSlippage);
279
283
  const calldata = encodeBuyCall(token, minOut);
280
284
  const nonce = await wallet.getNonce();
281
285
  const signedTx = await wallet.signTransaction({
@@ -323,11 +327,15 @@ export async function directBatchSellForSubmit(params) {
323
327
  const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
324
328
  const transactions = [];
325
329
  const estimatedOuts = [];
330
+ const isBatch = privateKeys.length > 1;
326
331
  for (let i = 0; i < privateKeys.length; i++) {
327
332
  const wallet = new Wallet(privateKeys[i], provider);
328
333
  const preview = await query.previewSell(token, tokenAmounts[i]);
329
334
  estimatedOuts.push(preview);
330
- const minOut = applySlippage(preview, slippageBps);
335
+ const effectiveSlippage = isBatch
336
+ ? Math.min(9500, slippageBps + i * 2000)
337
+ : slippageBps;
338
+ const minOut = applySlippage(preview, effectiveSlippage);
331
339
  const calldata = encodeSellCall(token, tokenAmounts[i], minOut);
332
340
  const nonce = await wallet.getNonce();
333
341
  const signedTx = await wallet.signTransaction({
@@ -62,8 +62,16 @@ export declare class FairPoolQuery {
62
62
  }
63
63
  /**
64
64
  * 构建 Pool claim 交易
65
+ * @param sharedProvider 可选的共享 provider,避免重复创建连接
66
+ * @param sharedFeeData 可选的共享 feeData,避免重复 RPC 调用
65
67
  */
66
- export declare function claimFromPool(params: PoolClaimParams): Promise<PoolClaimResult>;
68
+ export declare function claimFromPool(params: PoolClaimParams & {
69
+ sharedProvider?: JsonRpcProvider;
70
+ sharedFeeData?: {
71
+ maxFeePerGas: bigint;
72
+ maxPriorityFeePerGas: bigint;
73
+ };
74
+ }): Promise<PoolClaimResult>;
67
75
  /**
68
76
  * 构建 Pool claim 交易 — ForSubmit 版本
69
77
  * 自动追加利润转账,兼容 emitservice submit_blockrazor 接口
@@ -84,14 +84,30 @@ export class FairPoolQuery {
84
84
  // ============================================================================
85
85
  /**
86
86
  * 构建 Pool claim 交易
87
+ * @param sharedProvider 可选的共享 provider,避免重复创建连接
88
+ * @param sharedFeeData 可选的共享 feeData,避免重复 RPC 调用
87
89
  */
88
90
  export async function claimFromPool(params) {
89
- const { rpcUrl = ENI_RPC_URL, privateKey, poolAddress, amountToken, inviteCode = '', value = 0n, gasPrice, } = params;
90
- const provider = new JsonRpcProvider(rpcUrl, ENI_CHAIN_ID, { staticNetwork: true });
91
+ const { rpcUrl = ENI_RPC_URL, privateKey, poolAddress, amountToken, inviteCode = '', value = 0n, gasPrice, sharedProvider, sharedFeeData, } = params;
92
+ const provider = sharedProvider ?? new JsonRpcProvider(rpcUrl, ENI_CHAIN_ID, { staticNetwork: true });
91
93
  const wallet = new Wallet(privateKey, provider);
92
94
  const calldata = poolIface.encodeFunctionData('claim', [amountToken, inviteCode]);
93
95
  const nonce = await wallet.getNonce();
94
- const feeData = await provider.getFeeData();
96
+ let maxFeePerGas;
97
+ let maxPriorityFeePerGas;
98
+ if (gasPrice) {
99
+ maxFeePerGas = gasPrice;
100
+ maxPriorityFeePerGas = sharedFeeData?.maxPriorityFeePerGas ?? 0n;
101
+ }
102
+ else if (sharedFeeData) {
103
+ maxFeePerGas = sharedFeeData.maxFeePerGas;
104
+ maxPriorityFeePerGas = sharedFeeData.maxPriorityFeePerGas;
105
+ }
106
+ else {
107
+ const feeData = await provider.getFeeData();
108
+ maxFeePerGas = feeData.maxFeePerGas ?? feeData.gasPrice ?? 1000000000n;
109
+ maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
110
+ }
95
111
  const signedTx = await wallet.signTransaction({
96
112
  to: poolAddress,
97
113
  data: calldata,
@@ -99,8 +115,8 @@ export async function claimFromPool(params) {
99
115
  nonce,
100
116
  chainId: ENI_CHAIN_ID,
101
117
  type: 2,
102
- maxFeePerGas: gasPrice ?? feeData.maxFeePerGas ?? feeData.gasPrice ?? 1000000000n,
103
- maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 0n,
118
+ maxFeePerGas,
119
+ maxPriorityFeePerGas,
104
120
  gasLimit: 500000n,
105
121
  });
106
122
  return { signedTx, from: wallet.address, nonce };
@@ -148,10 +164,12 @@ export async function batchClaimForSubmit(params) {
148
164
  if (claims.length === 0) {
149
165
  return { signedTransactions: [], totalValue: 0n };
150
166
  }
167
+ // 复用单个 provider 和 feeData,减少 RPC 调用
151
168
  const provider = new JsonRpcProvider(rpcUrl, ENI_CHAIN_ID, { staticNetwork: true });
152
169
  const feeData = await provider.getFeeData();
153
170
  const maxFeePerGas = gasPrice ?? feeData.maxFeePerGas ?? feeData.gasPrice ?? 1000000000n;
154
171
  const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
172
+ const sharedFeeData = { maxFeePerGas, maxPriorityFeePerGas };
155
173
  const signedTransactions = [];
156
174
  let totalValue = 0n;
157
175
  let totalQuoteAmount = 0n;
@@ -165,6 +183,8 @@ export async function batchClaimForSubmit(params) {
165
183
  inviteCode: claim.inviteCode ?? '',
166
184
  value: claim.value,
167
185
  gasPrice: maxFeePerGas,
186
+ sharedProvider: provider,
187
+ sharedFeeData,
168
188
  });
169
189
  signedTransactions.push(result.signedTx);
170
190
  totalValue += claim.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.9.22",
3
+ "version": "1.9.24",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",