four-flap-meme-sdk 1.2.70 → 1.2.71
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.
- package/dist/contracts/tm-bundle.js +57 -6
- package/package.json +1 -1
|
@@ -38,6 +38,34 @@ function getErrorMessage(key, ...args) {
|
|
|
38
38
|
return typeof message === 'function' ? message(...args) : message;
|
|
39
39
|
}
|
|
40
40
|
// ========================================
|
|
41
|
+
// 辅助函数
|
|
42
|
+
// ========================================
|
|
43
|
+
/**
|
|
44
|
+
* 等待交易上链(不使用 club48 客户端)
|
|
45
|
+
*/
|
|
46
|
+
async function waitForBundleWithProvider(provider, firstTxSigned, bundleUuid) {
|
|
47
|
+
const maxAttempts = 60; // 最多等待 60 秒
|
|
48
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
49
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
50
|
+
try {
|
|
51
|
+
const txHash = ethers.keccak256(firstTxSigned);
|
|
52
|
+
const receipt = await provider.getTransactionReceipt(txHash);
|
|
53
|
+
if (receipt) {
|
|
54
|
+
if (receipt.status === 1) {
|
|
55
|
+
return { status: 'INCLUDED', includedBlock: receipt.blockNumber };
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return { status: 'FAILED' };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// 继续等待
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { status: 'PENDING' };
|
|
67
|
+
}
|
|
68
|
+
// ========================================
|
|
41
69
|
// 辅助函数:估算 gas 并应用配置
|
|
42
70
|
// ========================================
|
|
43
71
|
/**
|
|
@@ -87,10 +115,14 @@ export async function createTokenWithBundleBuy(params) {
|
|
|
87
115
|
}
|
|
88
116
|
const provider = new JsonRpcProvider(config.rpcUrl);
|
|
89
117
|
const devWallet = new Wallet(privateKeys[0], provider);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
// ✅ 只在没有 customSubmitFn 时创建 club48 客户端
|
|
119
|
+
let club48 = null;
|
|
120
|
+
if (!config.customSubmitFn) {
|
|
121
|
+
club48 = new Club48Client({
|
|
122
|
+
endpoint: 'https://puissant-bsc.48.club',
|
|
123
|
+
explorerEndpoint: config.club48ExplorerEndpoint
|
|
124
|
+
});
|
|
125
|
+
}
|
|
94
126
|
const fourClient = new FourClient({ baseUrl: config.fourApiUrl });
|
|
95
127
|
// 1. 登录 four.meme
|
|
96
128
|
const nonce = await fourClient.generateNonce({
|
|
@@ -144,7 +176,16 @@ export async function createTokenWithBundleBuy(params) {
|
|
|
144
176
|
});
|
|
145
177
|
// 4. 构建交易
|
|
146
178
|
const tmAddr = ADDRESSES.BSC.TokenManagerV2Proxy;
|
|
147
|
-
|
|
179
|
+
// ✅ 获取 gas price
|
|
180
|
+
let gasPrice;
|
|
181
|
+
if (club48) {
|
|
182
|
+
gasPrice = await club48.getMinGasPrice();
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// 使用 provider 获取 gas price 并增加 20%
|
|
186
|
+
const currentGasPrice = (await provider.getFeeData()).gasPrice || 3000000000n;
|
|
187
|
+
gasPrice = (currentGasPrice * 120n) / 100n;
|
|
188
|
+
}
|
|
148
189
|
const signedTxs = [];
|
|
149
190
|
const nextNonceMap = new Map();
|
|
150
191
|
const getNextNonce = async (w) => {
|
|
@@ -265,6 +306,9 @@ export async function createTokenWithBundleBuy(params) {
|
|
|
265
306
|
}
|
|
266
307
|
else {
|
|
267
308
|
// ✅ 直接提交到 48.club(仅服务器端可用)
|
|
309
|
+
if (!club48) {
|
|
310
|
+
throw new Error('❌ club48 客户端未初始化');
|
|
311
|
+
}
|
|
268
312
|
bundleUuid = await club48.sendBundle({
|
|
269
313
|
txs: signedTxs,
|
|
270
314
|
maxBlockNumber: (await provider.getBlockNumber()) + (config.bundleBlockOffset ?? 100),
|
|
@@ -276,7 +320,14 @@ export async function createTokenWithBundleBuy(params) {
|
|
|
276
320
|
});
|
|
277
321
|
}
|
|
278
322
|
// 6. 等待完成
|
|
279
|
-
|
|
323
|
+
let status;
|
|
324
|
+
if (club48) {
|
|
325
|
+
status = await club48.waitForBundle(bundleUuid);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
// 使用 provider 等待交易上链
|
|
329
|
+
status = await waitForBundleWithProvider(provider, signedTxs[0], bundleUuid);
|
|
330
|
+
}
|
|
280
331
|
// 7. 解析 TokenCreate 事件获取创建的代币地址
|
|
281
332
|
let createdTokenAddress;
|
|
282
333
|
if (status.status === 'INCLUDED' || status.status === 'PENDING') {
|