four-flap-meme-sdk 1.2.69 → 1.2.70

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.
@@ -5,6 +5,7 @@ import { FourClient, buildLoginMessage } from '../../clients/four.js';
5
5
  import { getErrorMessage, getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit, getProfitRecipient } from './config.js';
6
6
  import { batchCheckAllowances } from '../../utils/erc20.js';
7
7
  import { trySell } from '../tm.js';
8
+ import TM2Abi from '../../abis/TokenManager2.json' with { type: 'json' };
8
9
  const TM2_ABI = [
9
10
  'function createToken(bytes args, bytes signature) payable',
10
11
  'function buyTokenAMAP(uint256 origin, address token, address to, uint256 funds, uint256 minAmount) payable',
@@ -139,13 +140,78 @@ export async function createTokenWithBundleBuyMerkle(params) {
139
140
  }
140
141
  nonceManager.clearTemp();
141
142
  console.log(`✅ 总共生成了 ${signedTxs.length} 个交易签名 (1创建 + ${buyerKeys.length}买入 + 利润)`);
142
- // ✅ 返回签名交易,由服务器端提交到 48.club Bundle
143
- // 注意:浏览器无法直接调用 48.club Bundle API(CORS 限制)
144
- return {
145
- signedTransactions: signedTxs,
146
- tokenAddress: predictedTokenAddress, // 返回 0x0,服务器提交后需要从事件中解析真实地址
147
- metadata
148
- };
143
+ // ✅ 内部提交到 48.club Bundle
144
+ console.log('📡 开始提交到 48.club Bundle...');
145
+ // 检查是否有自定义提交函数
146
+ if (config.customSubmitFn) {
147
+ // 使用自定义提交函数(通过服务器代理)
148
+ const bundleUuid = await config.customSubmitFn(signedTxs);
149
+ console.log(`✅ Bundle 提交成功!UUID: ${bundleUuid}`);
150
+ // 等待交易上链并解析代币地址
151
+ const tokenAddress = await waitAndParseTokenAddress(provider, signedTxs[0], bundleUuid);
152
+ return {
153
+ signedTransactions: signedTxs,
154
+ tokenAddress,
155
+ metadata,
156
+ bundleUuid
157
+ };
158
+ }
159
+ else {
160
+ throw new Error('❌ 浏览器环境必须提供 customSubmitFn 来通过服务器代理提交 Bundle(避免 CORS 限制)');
161
+ }
162
+ }
163
+ /**
164
+ * 等待交易上链并解析代币地址
165
+ */
166
+ async function waitAndParseTokenAddress(provider, createTxSigned, bundleUuid) {
167
+ console.log('⏳ 等待交易上链,解析代币地址...');
168
+ let tokenAddress = ZERO_ADDRESS;
169
+ const maxAttempts = 30; // 最多等待 30 秒
170
+ for (let i = 0; i < maxAttempts; i++) {
171
+ await new Promise(resolve => setTimeout(resolve, 1000)); // 等待 1 秒
172
+ try {
173
+ // 获取创建交易的回执
174
+ const createTxHash = ethers.keccak256(createTxSigned);
175
+ const receipt = await provider.getTransactionReceipt(createTxHash);
176
+ if (receipt && receipt.status === 1) {
177
+ // 从事件日志中解析代币地址
178
+ const tm2Interface = new ethers.Interface(TM2Abi);
179
+ for (const log of receipt.logs) {
180
+ try {
181
+ const parsed = tm2Interface.parseLog({
182
+ topics: log.topics,
183
+ data: log.data
184
+ });
185
+ if (parsed && parsed.name === 'TokenCreate') {
186
+ tokenAddress = parsed.args.token;
187
+ console.log(`✅ 成功解析代币地址: ${tokenAddress}`);
188
+ return tokenAddress;
189
+ }
190
+ }
191
+ catch (e) {
192
+ // 忽略无法解析的日志
193
+ }
194
+ }
195
+ // 如果没有找到 TokenCreate 事件,尝试 TokenCreated
196
+ const tokenCreatedTopic = ethers.id('TokenCreated(address,address,uint256,uint256,uint256,uint256)');
197
+ for (const log of receipt.logs) {
198
+ if (log.topics[0] === tokenCreatedTopic) {
199
+ tokenAddress = ethers.getAddress('0x' + log.topics[1].slice(26));
200
+ console.log(`✅ 成功解析代币地址: ${tokenAddress}`);
201
+ return tokenAddress;
202
+ }
203
+ }
204
+ break;
205
+ }
206
+ }
207
+ catch (error) {
208
+ // 继续等待
209
+ }
210
+ }
211
+ if (tokenAddress === ZERO_ADDRESS) {
212
+ console.warn('⚠️ 未能从事件中解析代币地址,返回 0x0');
213
+ }
214
+ return tokenAddress;
149
215
  }
150
216
  export async function batchBuyWithBundleMerkle(params) {
151
217
  const { privateKeys, buyAmounts, tokenAddress, config } = params;
@@ -11,6 +11,7 @@ export type FourSignConfig = {
11
11
  chainId?: number;
12
12
  prefer21000ForNative?: boolean;
13
13
  checkBnbForErc20NoHop?: boolean;
14
+ customSubmitFn?: (signedTxs: string[]) => Promise<string>;
14
15
  };
15
16
  export type FourBundleMerkleConfig = {
16
17
  apiKey: string;
@@ -66,6 +67,8 @@ export type MerkleSignedResult = {
66
67
  metadata?: {
67
68
  [key: string]: any;
68
69
  };
70
+ /** Bundle UUID(内部提交时返回) */
71
+ bundleUuid?: string;
69
72
  };
70
73
  /** ✅ 创建代币 + 购买参数(Merkle 版本 - 完整) */
71
74
  export type FourCreateWithBundleBuyMerkleParams = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.69",
3
+ "version": "1.2.70",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",