four-flap-meme-sdk 1.2.73 → 1.2.75
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.
|
@@ -2,7 +2,6 @@ import { ethers, Wallet } from 'ethers';
|
|
|
2
2
|
import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
|
|
3
3
|
import { ADDRESSES } from '../../utils/constants.js';
|
|
4
4
|
import { FourClient, buildLoginMessage } from '../../clients/four.js';
|
|
5
|
-
import axios from 'axios';
|
|
6
5
|
import { getErrorMessage, getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit, getProfitRecipient } from './config.js';
|
|
7
6
|
import { batchCheckAllowances } from '../../utils/erc20.js';
|
|
8
7
|
import { trySell } from '../tm.js';
|
|
@@ -141,42 +140,77 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
141
140
|
}
|
|
142
141
|
nonceManager.clearTemp();
|
|
143
142
|
console.log(`✅ 总共生成了 ${signedTxs.length} 个交易签名 (1创建 + ${buyerKeys.length}买入 + 利润)`);
|
|
144
|
-
// ✅
|
|
145
|
-
console.log('📡
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
// ✅ 使用公共 BSC RPC 提交交易(无 CORS 问题)
|
|
144
|
+
console.log('📡 开始通过公共 RPC 提交交易...');
|
|
145
|
+
const txHashes = [];
|
|
146
|
+
// ✅ 使用 provider.broadcastTransaction 逐个提交
|
|
147
|
+
for (let i = 0; i < signedTxs.length; i++) {
|
|
148
|
+
try {
|
|
149
|
+
const tx = signedTxs[i];
|
|
150
|
+
console.log(`📤 提交第 ${i + 1}/${signedTxs.length} 个交易...`);
|
|
151
|
+
const txResponse = await provider.broadcastTransaction(tx);
|
|
152
|
+
txHashes.push(txResponse.hash);
|
|
153
|
+
console.log(`✅ 交易 ${i + 1} 提交成功: ${txResponse.hash}`);
|
|
154
|
+
// 短暂延迟,避免 nonce 冲突
|
|
155
|
+
if (i < signedTxs.length - 1) {
|
|
156
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error(`❌ 交易 ${i + 1} 提交失败:`, error.message);
|
|
161
|
+
throw new Error(`交易 ${i + 1} 提交失败: ${error.message}`);
|
|
162
|
+
}
|
|
151
163
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
throw new Error(`48.club bundle 提交失败: ${response.data.error.message}`);
|
|
164
|
+
console.log(`✅ 所有交易提交成功!共 ${txHashes.length} 笔`);
|
|
165
|
+
// 等待创建交易确认并解析代币地址
|
|
166
|
+
console.log('⏳ 等待创建交易确认并解析代币地址...');
|
|
167
|
+
const createTxHash = txHashes[0];
|
|
168
|
+
// 使用公共 RPC 查询交易收据(避免 CORS)
|
|
169
|
+
let receipt = null;
|
|
170
|
+
let retries = 0;
|
|
171
|
+
const maxRetries = 60; // 最多等待 60 秒
|
|
172
|
+
while (!receipt && retries < maxRetries) {
|
|
173
|
+
try {
|
|
174
|
+
receipt = await provider.getTransactionReceipt(createTxHash);
|
|
175
|
+
if (receipt)
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
// 忽略查询错误
|
|
169
180
|
}
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
182
|
+
retries++;
|
|
183
|
+
if (retries % 5 === 0) {
|
|
184
|
+
console.log(`⏳ 等待交易确认... (${retries}/${maxRetries})`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!receipt) {
|
|
188
|
+
throw new Error('等待交易确认超时');
|
|
189
|
+
}
|
|
190
|
+
console.log(`✅ 创建交易已确认,区块: ${receipt.blockNumber}`);
|
|
191
|
+
// 解析 TokenCreated 事件
|
|
192
|
+
let tokenAddress;
|
|
193
|
+
for (const log of receipt.logs) {
|
|
194
|
+
try {
|
|
195
|
+
// TokenCreated(address indexed token, ...)
|
|
196
|
+
if (log.topics[0] === ethers.id('TokenCreated(address,address,string,string,uint256,uint256,uint256)')) {
|
|
197
|
+
tokenAddress = ethers.getAddress('0x' + log.topics[1].slice(26));
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
// 忽略解析错误
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!tokenAddress) {
|
|
206
|
+
throw new Error('无法从交易收据中解析代币地址');
|
|
172
207
|
}
|
|
173
|
-
|
|
174
|
-
const tokenAddress = await waitAndParseTokenAddress(provider, signedTxs[0], bundleUuid);
|
|
208
|
+
console.log(`✅ 代币地址: ${tokenAddress}`);
|
|
175
209
|
return {
|
|
176
210
|
signedTransactions: signedTxs,
|
|
177
211
|
tokenAddress,
|
|
178
212
|
metadata,
|
|
179
|
-
|
|
213
|
+
txHashes
|
|
180
214
|
};
|
|
181
215
|
}
|
|
182
216
|
/**
|
|
@@ -70,8 +70,8 @@ export type MerkleSignedResult = {
|
|
|
70
70
|
metadata?: {
|
|
71
71
|
[key: string]: any;
|
|
72
72
|
};
|
|
73
|
-
/**
|
|
74
|
-
|
|
73
|
+
/** 交易哈希数组(内部提交时返回) */
|
|
74
|
+
txHashes?: string[];
|
|
75
75
|
};
|
|
76
76
|
/** ✅ 创建代币 + 购买参数(Merkle 版本 - 完整) */
|
|
77
77
|
export type FourCreateWithBundleBuyMerkleParams = {
|