four-flap-meme-sdk 1.2.57 → 1.2.58
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.
|
@@ -63,6 +63,8 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
63
63
|
funGroup: false,
|
|
64
64
|
clickFun: false,
|
|
65
65
|
});
|
|
66
|
+
// 🔍 调试:打印 createResp 的内容
|
|
67
|
+
console.log('🔍 Four.meme createToken 响应:', JSON.stringify(createResp, null, 2));
|
|
66
68
|
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
67
69
|
const nonceManager = new NonceManager(provider);
|
|
68
70
|
const txType = getTxType(config);
|
|
@@ -85,14 +87,34 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
85
87
|
value: valueWei
|
|
86
88
|
};
|
|
87
89
|
signedTxs.push(await devWallet.signTransaction(createTxRequest));
|
|
88
|
-
|
|
90
|
+
// ✅ 尝试从 createArg 中解析代币地址
|
|
91
|
+
// createArg 是一个 ABI 编码的参数,包含了代币的所有创建信息
|
|
92
|
+
let predictedTokenAddress = resolveTokenAddress(createResp);
|
|
93
|
+
// 如果 API 没有直接返回地址,尝试从 createArg 中解析
|
|
94
|
+
if (predictedTokenAddress === ZERO_ADDRESS && createResp.createArg) {
|
|
95
|
+
try {
|
|
96
|
+
// createArg 是 bytes 类型,通常是 ABI 编码的结构体
|
|
97
|
+
// 格式:abi.encode(TokenCreateArg) 其中包含 token 地址
|
|
98
|
+
const createArgBytes = createResp.createArg.startsWith('0x')
|
|
99
|
+
? createResp.createArg
|
|
100
|
+
: '0x' + createResp.createArg;
|
|
101
|
+
// 尝试解码 createArg(假设 token 地址在前 32 字节之后)
|
|
102
|
+
// 通常 ABI 编码的第一个 address 类型会在偏移 32 字节处
|
|
103
|
+
if (createArgBytes.length >= 66) {
|
|
104
|
+
// 跳过前 32 字节(通常是长度或其他元数据),取接下来的 20 字节(地址)
|
|
105
|
+
const addressHex = '0x' + createArgBytes.slice(-40); // 取最后 40 个字符(20 字节)
|
|
106
|
+
if (ethers.isAddress(addressHex)) {
|
|
107
|
+
predictedTokenAddress = ethers.getAddress(addressHex);
|
|
108
|
+
console.log('✅ 从 createArg 中解析到代币地址:', predictedTokenAddress);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.warn('⚠️ 无法从 createArg 解析代币地址:', error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
89
116
|
let metadata;
|
|
90
|
-
|
|
91
|
-
// 因为代币还未创建。如果需要在创建后立即买入,请:
|
|
92
|
-
// 1. 等待创建交易上链
|
|
93
|
-
// 2. 从交易回执中解析代币地址
|
|
94
|
-
// 3. 再调用 batchBuyWithBundleMerkle 进行买入
|
|
95
|
-
if (predictedTokenAddress !== ZERO_ADDRESS) {
|
|
117
|
+
if (predictedTokenAddress !== ZERO_ADDRESS && buyerKeys.length > 0) {
|
|
96
118
|
const buyers = createWallets(buyerKeys, provider);
|
|
97
119
|
const buyFlow = await executeBuyFlow({
|
|
98
120
|
wallets: buyers,
|
|
@@ -109,9 +131,9 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
109
131
|
signedTxs.push(...buyFlow.signedTxs);
|
|
110
132
|
metadata = buyFlow.metadata;
|
|
111
133
|
}
|
|
112
|
-
else {
|
|
113
|
-
// ⚠️
|
|
114
|
-
|
|
134
|
+
else if (buyerKeys.length > 0) {
|
|
135
|
+
// ⚠️ 无法预测代币地址,但用户传入了买家私钥
|
|
136
|
+
throw new Error('❌ 无法预测代币地址,无法生成买入交易。请检查 Four.meme API 返回的 createResp 是否包含代币地址信息。');
|
|
115
137
|
}
|
|
116
138
|
nonceManager.clearTemp();
|
|
117
139
|
return {
|