four-flap-meme-sdk 1.2.59 → 1.2.60
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.
|
@@ -87,43 +87,25 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
87
87
|
value: valueWei
|
|
88
88
|
};
|
|
89
89
|
signedTxs.push(await devWallet.signTransaction(createTxRequest));
|
|
90
|
-
// ✅
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
}
|
|
90
|
+
// ✅ Four.meme 特殊机制:使用 0x0 地址作为占位符
|
|
91
|
+
// Four.meme 的 buyTokenAMAP 方法支持传入 0x0 地址,合约会自动解析为最新创建的代币
|
|
92
|
+
// 这是 Four.meme 独有的机制,允许在创建代币的同时进行买入
|
|
93
|
+
const predictedTokenAddress = ZERO_ADDRESS; // 使用 0x0 作为占位符
|
|
94
|
+
console.log('✅ 使用 Four.meme 特殊机制:0x0 地址将被合约自动解析为新创建的代币地址');
|
|
124
95
|
let metadata;
|
|
125
|
-
|
|
96
|
+
// ✅ 即使地址是 0x0,也可以生成买入交易(Four.meme 会自动处理)
|
|
97
|
+
if (buyerKeys.length > 0) {
|
|
126
98
|
const buyers = createWallets(buyerKeys, provider);
|
|
99
|
+
// 🔍 找出买入金额最多的买家(由他支付所有利润)
|
|
100
|
+
let maxBuyerIndex = 0;
|
|
101
|
+
let maxAmount = ethers.parseEther(buyAmounts[0]);
|
|
102
|
+
for (let i = 1; i < buyAmounts.length; i++) {
|
|
103
|
+
const amount = ethers.parseEther(buyAmounts[i]);
|
|
104
|
+
if (amount > maxAmount) {
|
|
105
|
+
maxAmount = amount;
|
|
106
|
+
maxBuyerIndex = i;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
127
109
|
const buyFlow = await executeBuyFlow({
|
|
128
110
|
wallets: buyers,
|
|
129
111
|
buyAmounts,
|
|
@@ -133,16 +115,12 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
133
115
|
contractAddress: tmBuyAddr,
|
|
134
116
|
gasPrice,
|
|
135
117
|
chainId,
|
|
136
|
-
profitMode: { type: '
|
|
118
|
+
profitMode: { type: 'aggregated', payer: buyers[maxBuyerIndex] }, // ✅ 聚合模式:由买入最多的人支付
|
|
137
119
|
txType
|
|
138
120
|
});
|
|
139
121
|
signedTxs.push(...buyFlow.signedTxs);
|
|
140
122
|
metadata = buyFlow.metadata;
|
|
141
123
|
}
|
|
142
|
-
else if (buyerKeys.length > 0) {
|
|
143
|
-
// ⚠️ 无法预测代币地址,但用户传入了买家私钥
|
|
144
|
-
throw new Error('❌ 无法预测代币地址,无法生成买入交易。请检查 Four.meme API 返回的 createResp 是否包含代币地址信息。');
|
|
145
|
-
}
|
|
146
124
|
nonceManager.clearTemp();
|
|
147
125
|
return {
|
|
148
126
|
signedTransactions: signedTxs,
|