four-flap-meme-sdk 1.2.57 → 1.2.59
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,42 @@ 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
|
+
const createArgBytes = createResp.createArg.startsWith('0x')
|
|
97
|
+
? createResp.createArg
|
|
98
|
+
: '0x' + createResp.createArg;
|
|
99
|
+
// Four.meme 的 createArg 结构(根据合约分析):
|
|
100
|
+
// struct TokenCreateArg {
|
|
101
|
+
// address token; // 偏移 0: 代币地址(20 字节,填充到 32 字节)
|
|
102
|
+
// uint256 totalAmount; // 偏移 32: 总供应量
|
|
103
|
+
// uint256 saleAmount; // 偏移 64: 销售数量
|
|
104
|
+
// ... 其他字段
|
|
105
|
+
// }
|
|
106
|
+
// 提取第一个字段(token 地址):前 32 字节,取后 20 字节
|
|
107
|
+
if (createArgBytes.length >= 66) { // 至少 0x + 64 个字符(32 字节)
|
|
108
|
+
// 地址在前 32 字节中,但只占后 20 字节
|
|
109
|
+
const tokenAddressHex = '0x' + createArgBytes.slice(26, 66); // 跳过 '0x' + 前 12 个字节(24 字符)
|
|
110
|
+
console.log('🔍 尝试解析地址:', tokenAddressHex);
|
|
111
|
+
if (ethers.isAddress(tokenAddressHex)) {
|
|
112
|
+
predictedTokenAddress = ethers.getAddress(tokenAddressHex);
|
|
113
|
+
console.log('✅ 从 createArg 中解析到代币地址:', predictedTokenAddress);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.warn('⚠️ 解析的地址格式不正确:', tokenAddressHex);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.warn('⚠️ 无法从 createArg 解析代币地址:', error.message);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
89
124
|
let metadata;
|
|
90
|
-
|
|
91
|
-
// 因为代币还未创建。如果需要在创建后立即买入,请:
|
|
92
|
-
// 1. 等待创建交易上链
|
|
93
|
-
// 2. 从交易回执中解析代币地址
|
|
94
|
-
// 3. 再调用 batchBuyWithBundleMerkle 进行买入
|
|
95
|
-
if (predictedTokenAddress !== ZERO_ADDRESS) {
|
|
125
|
+
if (predictedTokenAddress !== ZERO_ADDRESS && buyerKeys.length > 0) {
|
|
96
126
|
const buyers = createWallets(buyerKeys, provider);
|
|
97
127
|
const buyFlow = await executeBuyFlow({
|
|
98
128
|
wallets: buyers,
|
|
@@ -109,9 +139,9 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
109
139
|
signedTxs.push(...buyFlow.signedTxs);
|
|
110
140
|
metadata = buyFlow.metadata;
|
|
111
141
|
}
|
|
112
|
-
else {
|
|
113
|
-
// ⚠️
|
|
114
|
-
|
|
142
|
+
else if (buyerKeys.length > 0) {
|
|
143
|
+
// ⚠️ 无法预测代币地址,但用户传入了买家私钥
|
|
144
|
+
throw new Error('❌ 无法预测代币地址,无法生成买入交易。请检查 Four.meme API 返回的 createResp 是否包含代币地址信息。');
|
|
115
145
|
}
|
|
116
146
|
nonceManager.clearTemp();
|
|
117
147
|
return {
|