four-flap-meme-sdk 1.2.47 → 1.2.49

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.
@@ -7,7 +7,7 @@ export declare function approveFourPancakeProxy(params: FourPancakeProxyApproval
7
7
  approved: boolean;
8
8
  }>;
9
9
  /**
10
- * 批量授权代币给 PancakeSwapProxy(Merkle Bundle 版本)
10
+ * 批量授权代币给 PancakeSwapProxy(内部直接广播提交)
11
11
  */
12
12
  export declare function approveFourPancakeProxyBatch(params: FourPancakeProxyApprovalBatchParams): Promise<FourPancakeProxyApprovalBatchResult>;
13
13
  /**
@@ -1,5 +1,4 @@
1
1
  import { ethers, Wallet, JsonRpcProvider, Contract } from 'ethers';
2
- import { MerkleClient } from '../../clients/merkle.js';
3
2
  import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
4
3
  import { ADDRESSES } from '../../utils/constants.js';
5
4
  import { getTxType, getBundleOptions, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit, getProfitRecipient } from './config.js';
@@ -201,7 +200,7 @@ export async function approveFourPancakeProxy(params) {
201
200
  };
202
201
  }
203
202
  /**
204
- * 批量授权代币给 PancakeSwapProxy(Merkle Bundle 版本)
203
+ * 批量授权代币给 PancakeSwapProxy(内部直接广播提交)
205
204
  */
206
205
  export async function approveFourPancakeProxyBatch(params) {
207
206
  const { privateKeys, tokenAddress, amounts, config } = params;
@@ -209,13 +208,10 @@ export async function approveFourPancakeProxyBatch(params) {
209
208
  throw new Error('Private key count and amount count must match');
210
209
  }
211
210
  const pancakeProxyAddress = ADDRESSES.BSC.PancakeProxy;
212
- const merkle = new MerkleClient({
213
- apiKey: config.apiKey,
214
- chainId: 56, // Four.meme 固定 BSC
215
- customRpcUrl: config.customRpcUrl
211
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
212
+ chainId: 56,
213
+ name: 'BSC'
216
214
  });
217
- const provider = merkle.getProvider();
218
- const blockOffset = config.bundleBlockOffset ?? 2;
219
215
  const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
220
216
  // 查询 decimals
221
217
  const decimals = await getTokenDecimals(tokenAddress, provider);
@@ -231,6 +227,7 @@ export async function approveFourPancakeProxyBatch(params) {
231
227
  return {
232
228
  success: true,
233
229
  approvedCount: 0,
230
+ signedTransactions: [],
234
231
  message: '所有钱包已授权'
235
232
  };
236
233
  }
@@ -253,30 +250,35 @@ export async function approveFourPancakeProxyBatch(params) {
253
250
  type: txType
254
251
  })));
255
252
  nonceManager.clearTemp();
256
- // ✅ 内部提交到 Merkle
257
- const currentBlock = await provider.getBlockNumber();
258
- const targetBlock = currentBlock + blockOffset;
259
- const bundleResult = await merkle.sendBundle({
260
- transactions: signedTxs,
261
- targetBlock: targetBlock
262
- });
263
- // ✅ 等待授权确认
264
- const confirmResults = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, 60000);
265
- const successCount = confirmResults.filter(r => r.success).length;
253
+ // ✅ 内部直接广播提交(逐个发送)
254
+ const txHashes = [];
255
+ const errors = [];
256
+ for (let i = 0; i < signedTxs.length; i++) {
257
+ try {
258
+ const tx = await provider.broadcastTransaction(signedTxs[i]);
259
+ txHashes.push(tx.hash);
260
+ }
261
+ catch (error) {
262
+ errors.push(`钱包 ${i} 授权失败: ${error.message}`);
263
+ }
264
+ }
265
+ const successCount = txHashes.length;
266
266
  if (successCount > 0) {
267
267
  return {
268
268
  success: true,
269
269
  approvedCount: successCount,
270
- bundleHash: bundleResult.bundleHash,
271
- message: `授权成功,共 ${successCount} 个钱包`
270
+ signedTransactions: signedTxs,
271
+ txHashes,
272
+ message: `授权成功,共 ${successCount} 个钱包${errors.length > 0 ? `,${errors.length} 个失败` : ''}`
272
273
  };
273
274
  }
274
275
  else {
275
276
  return {
276
277
  success: false,
277
278
  approvedCount: 0,
278
- bundleHash: bundleResult.bundleHash,
279
- message: '授权交易未确认'
279
+ signedTransactions: signedTxs,
280
+ txHashes: [],
281
+ message: `授权失败: ${errors.join('; ')}`
280
282
  };
281
283
  }
282
284
  }
@@ -368,12 +368,14 @@ export type FourPancakeProxyApprovalBatchParams = {
368
368
  privateKeys: string[];
369
369
  tokenAddress: string;
370
370
  amounts: (string | 'max')[];
371
- config: FourBundleMerkleConfig;
371
+ config: FourSignConfig;
372
372
  };
373
373
  /** ✅ PancakeProxy 批量授权结果 */
374
374
  export type FourPancakeProxyApprovalBatchResult = {
375
375
  success: boolean;
376
376
  approvedCount: number;
377
+ signedTransactions: string[];
378
+ txHashes?: string[];
377
379
  bundleHash?: string;
378
380
  message: string;
379
381
  };
@@ -7,7 +7,7 @@ export declare function approvePancakeProxy(params: PancakeProxyApprovalParams):
7
7
  approved: boolean;
8
8
  }>;
9
9
  /**
10
- * 批量授权代币给 PancakeSwapProxy(Merkle Bundle 版本)
10
+ * 批量授权代币给 PancakeSwapProxy(内部直接广播提交)
11
11
  */
12
12
  export declare function approvePancakeProxyBatch(params: PancakeProxyApprovalBatchParams): Promise<PancakeProxyApprovalBatchResult>;
13
13
  /**
@@ -1,5 +1,4 @@
1
1
  import { ethers, Wallet, JsonRpcProvider, Contract } from 'ethers';
2
- import { MerkleClient } from '../../clients/merkle.js';
3
2
  import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
4
3
  import { ADDRESSES } from '../../utils/constants.js';
5
4
  import { CHAIN_ID_MAP, getTxType, getBundleOptions, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit, getProfitRecipient } from './config.js';
@@ -200,7 +199,7 @@ export async function approvePancakeProxy(params) {
200
199
  };
201
200
  }
202
201
  /**
203
- * 批量授权代币给 PancakeSwapProxy(Merkle Bundle 版本)
202
+ * 批量授权代币给 PancakeSwapProxy(内部直接广播提交)
204
203
  */
205
204
  export async function approvePancakeProxyBatch(params) {
206
205
  const { chain, privateKeys, tokenAddress, amounts, config } = params;
@@ -209,13 +208,10 @@ export async function approvePancakeProxyBatch(params) {
209
208
  }
210
209
  const pancakeProxyAddress = ADDRESSES.BSC.PancakeProxy;
211
210
  const chainId = CHAIN_ID_MAP[chain];
212
- const merkle = new MerkleClient({
213
- apiKey: config.apiKey,
214
- chainId: chainId,
215
- customRpcUrl: config.customRpcUrl
211
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
212
+ chainId,
213
+ name: chain.toUpperCase()
216
214
  });
217
- const provider = merkle.getProvider();
218
- const blockOffset = config.bundleBlockOffset ?? 2;
219
215
  const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
220
216
  // 查询 decimals
221
217
  const decimals = await getTokenDecimals(tokenAddress, provider);
@@ -231,6 +227,7 @@ export async function approvePancakeProxyBatch(params) {
231
227
  return {
232
228
  success: true,
233
229
  approvedCount: 0,
230
+ signedTransactions: [],
234
231
  message: '所有钱包已授权'
235
232
  };
236
233
  }
@@ -252,30 +249,35 @@ export async function approvePancakeProxyBatch(params) {
252
249
  type: getTxType(config)
253
250
  })));
254
251
  nonceManager.clearTemp();
255
- // ✅ 内部提交到 Merkle
256
- const currentBlock = await provider.getBlockNumber();
257
- const targetBlock = currentBlock + blockOffset;
258
- const bundleResult = await merkle.sendBundle({
259
- transactions: signedTxs,
260
- targetBlock: targetBlock
261
- });
262
- // ✅ 等待授权确认
263
- const confirmResults = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, 60000);
264
- const successCount = confirmResults.filter(r => r.success).length;
252
+ // ✅ 内部直接广播提交(逐个发送)
253
+ const txHashes = [];
254
+ const errors = [];
255
+ for (let i = 0; i < signedTxs.length; i++) {
256
+ try {
257
+ const tx = await provider.broadcastTransaction(signedTxs[i]);
258
+ txHashes.push(tx.hash);
259
+ }
260
+ catch (error) {
261
+ errors.push(`钱包 ${i} 授权失败: ${error.message}`);
262
+ }
263
+ }
264
+ const successCount = txHashes.length;
265
265
  if (successCount > 0) {
266
266
  return {
267
267
  success: true,
268
268
  approvedCount: successCount,
269
- bundleHash: bundleResult.bundleHash,
270
- message: `授权成功,共 ${successCount} 个钱包`
269
+ signedTransactions: signedTxs,
270
+ txHashes,
271
+ message: `授权成功,共 ${successCount} 个钱包${errors.length > 0 ? `,${errors.length} 个失败` : ''}`
271
272
  };
272
273
  }
273
274
  else {
274
275
  return {
275
276
  success: false,
276
277
  approvedCount: 0,
277
- bundleHash: bundleResult.bundleHash,
278
- message: '授权交易未确认'
278
+ signedTransactions: signedTxs,
279
+ txHashes: [],
280
+ message: `授权失败: ${errors.join('; ')}`
279
281
  };
280
282
  }
281
283
  }
@@ -265,12 +265,14 @@ export type PancakeProxyApprovalBatchParams = {
265
265
  privateKeys: string[];
266
266
  tokenAddress: string;
267
267
  amounts: (string | 'max')[];
268
- config: FlapBundleMerkleConfig;
268
+ config: FlapSignConfig;
269
269
  };
270
270
  /** ✅ PancakeProxy 批量授权结果 */
271
271
  export type PancakeProxyApprovalBatchResult = {
272
272
  success: boolean;
273
273
  approvedCount: number;
274
+ signedTransactions: string[];
275
+ txHashes?: string[];
274
276
  bundleHash?: string;
275
277
  message: string;
276
278
  };
@@ -2,6 +2,7 @@ import { type FlapChain } from '../flap/portal.js';
2
2
  export type LPPlatform = 'FOUR' | 'FLAP' | 'PANCAKE_V2' | 'PANCAKE_V3' | 'PANCAKE_MIXED' | 'UNKNOWN';
3
3
  export type LPInfo = {
4
4
  platform: LPPlatform;
5
+ decimals?: number;
5
6
  four?: {
6
7
  helper: string;
7
8
  reserveNative?: string;
@@ -41,6 +41,14 @@ export async function inspectTokenLP(token, opts) {
41
41
  multicall3 = '0xca11bde05977b3631167028862be2a173976ca11';
42
42
  }
43
43
  }
44
+ // 查询代币精度
45
+ try {
46
+ const tokenContract = new Contract(token, I_ERC20_ABI, provider);
47
+ out.decimals = await tokenContract.decimals();
48
+ }
49
+ catch {
50
+ // 如果查询失败,不设置 decimals(保持 undefined)
51
+ }
44
52
  async function resolveFactories() {
45
53
  // 1) 直接给出工厂
46
54
  if (opts.factoryV2 && opts.factoryV3)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.47",
3
+ "version": "1.2.49",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",