four-flap-meme-sdk 1.2.8 → 1.2.9
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.
|
@@ -159,16 +159,22 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
159
159
|
const extractProfit = shouldExtractProfit(config);
|
|
160
160
|
let totalProfit = 0n;
|
|
161
161
|
let totalBuyAmount = 0n;
|
|
162
|
-
//
|
|
163
|
-
const fundsListWei =
|
|
162
|
+
// 计算每个买家的实际购买金额和利润
|
|
163
|
+
const fundsListWei = [];
|
|
164
|
+
const profitList = [];
|
|
165
|
+
buyAmounts.forEach((a) => {
|
|
164
166
|
const originalAmount = ethers.parseEther(a);
|
|
165
167
|
totalBuyAmount += originalAmount;
|
|
166
168
|
if (extractProfit) {
|
|
167
169
|
const { remaining, profit } = calculateProfit(originalAmount, config);
|
|
168
170
|
totalProfit += profit;
|
|
169
|
-
|
|
171
|
+
fundsListWei.push(remaining); // ✅ 扣除利润后的金额用于购买
|
|
172
|
+
profitList.push(profit); // ✅ 记录每个买家的利润
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
fundsListWei.push(originalAmount);
|
|
176
|
+
profitList.push(0n);
|
|
170
177
|
}
|
|
171
|
-
return originalAmount;
|
|
172
178
|
});
|
|
173
179
|
const buyContracts = buyers.map((w) => new ethers.Contract(tmBuyAddr, TM2_ABI, w));
|
|
174
180
|
// ✅ 使用预计算的代币地址
|
|
@@ -189,19 +195,23 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
189
195
|
})));
|
|
190
196
|
signedTxs.push(...signed);
|
|
191
197
|
buyTxs.push(...signed);
|
|
192
|
-
// ✅
|
|
198
|
+
// ✅ 添加利润转账(每个买家单独转自己的利润)
|
|
193
199
|
if (extractProfit && totalProfit > 0n && buyers.length > 0) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
for (let i = 0; i < buyers.length; i++) {
|
|
201
|
+
if (profitList[i] > 0n) {
|
|
202
|
+
const profitNonce = await nonceManager.getNextNonce(buyers[i]);
|
|
203
|
+
const profitTx = await buyers[i].signTransaction({
|
|
204
|
+
to: config.profitRecipient,
|
|
205
|
+
value: profitList[i], // ✅ 每个买家转自己的利润
|
|
206
|
+
nonce: profitNonce,
|
|
207
|
+
gasPrice,
|
|
208
|
+
gasLimit: 21000n,
|
|
209
|
+
chainId: 56,
|
|
210
|
+
type: getTxType(config)
|
|
211
|
+
});
|
|
212
|
+
signedTxs.push(profitTx);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
205
215
|
}
|
|
206
216
|
// ✅ 清理临时 nonce 缓存
|
|
207
217
|
nonceManager.clearTemp();
|
|
@@ -26,13 +26,6 @@ function getGasLimit(config, defaultGas = 800000) {
|
|
|
26
26
|
*/
|
|
27
27
|
export async function createTokenWithBundleBuyMerkle(params) {
|
|
28
28
|
const { chain, privateKeys, buyAmounts, tokenInfo, quoteToken, tokenAddress, config } = params;
|
|
29
|
-
// 🔍 调试:检查 config 对象
|
|
30
|
-
console.log('🔍 接收到的 params.config:', {
|
|
31
|
-
hasConfig: !!config,
|
|
32
|
-
configKeys: config ? Object.keys(config) : [],
|
|
33
|
-
profitRecipient: config?.profitRecipient,
|
|
34
|
-
profitRateBps: config?.profitRateBps
|
|
35
|
-
});
|
|
36
29
|
if (privateKeys.length === 0) {
|
|
37
30
|
throw new Error(getErrorMessage('NO_PRIVATE_KEY'));
|
|
38
31
|
}
|
|
@@ -111,15 +104,6 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
111
104
|
const extractProfit = shouldExtractProfit(config);
|
|
112
105
|
let totalProfit = 0n;
|
|
113
106
|
let totalBuyAmount = 0n;
|
|
114
|
-
console.log('🔍 创建+跟买 利润提取检查:', {
|
|
115
|
-
extractProfit,
|
|
116
|
-
profitRecipient: config.profitRecipient,
|
|
117
|
-
profitRecipientType: typeof config.profitRecipient,
|
|
118
|
-
profitRecipientLength: config.profitRecipient?.length,
|
|
119
|
-
isZeroAddress: config.profitRecipient === ethers.ZeroAddress,
|
|
120
|
-
profitRateBps: config.profitRateBps,
|
|
121
|
-
buyersCount: privateKeys.length - 1
|
|
122
|
-
});
|
|
123
107
|
// 计算每个买家的实际购买金额和利润
|
|
124
108
|
const fundsList = [];
|
|
125
109
|
const profitList = [];
|
|
@@ -131,12 +115,10 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
131
115
|
totalProfit += profit;
|
|
132
116
|
fundsList.push(remaining); // ✅ 扣除利润后的金额用于购买
|
|
133
117
|
profitList.push(profit); // ✅ 记录每个买家的利润
|
|
134
|
-
console.log(` 买家 ${idx}: 原金额 ${ethers.formatEther(originalAmount)} BNB, 购买 ${ethers.formatEther(remaining)} BNB, 利润 ${ethers.formatEther(profit)} BNB`);
|
|
135
118
|
}
|
|
136
119
|
else {
|
|
137
120
|
fundsList.push(originalAmount);
|
|
138
121
|
profitList.push(0n);
|
|
139
|
-
console.log(` 买家 ${idx}: 购买 ${ethers.formatEther(originalAmount)} BNB (无利润提取)`);
|
|
140
122
|
}
|
|
141
123
|
});
|
|
142
124
|
const minOuts = new Array(buyers.length).fill(0n);
|
|
@@ -167,10 +149,7 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
167
149
|
buyTxs.push(...signedBuys);
|
|
168
150
|
// ✅ 添加利润转账(每个买家单独转自己的利润)
|
|
169
151
|
if (extractProfit && totalProfit > 0n && buyers.length > 0) {
|
|
170
|
-
console.log(`💰 开始添加利润转账...`);
|
|
171
|
-
console.log(` 总利润: ${ethers.formatEther(totalProfit)} BNB → ${config.profitRecipient}`);
|
|
172
152
|
for (let i = 0; i < buyers.length; i++) {
|
|
173
|
-
console.log(` 买家 ${i}: profitList[${i}] = ${profitList[i] ? ethers.formatEther(profitList[i]) : 'undefined'} BNB`);
|
|
174
153
|
if (profitList[i] > 0n) {
|
|
175
154
|
const profitNonce = await nonceManager.getNextNonce(buyers[i]);
|
|
176
155
|
const profitTx = await buyers[i].signTransaction({
|
|
@@ -183,25 +162,11 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
183
162
|
type: getTxType(config)
|
|
184
163
|
});
|
|
185
164
|
signedTxs.push(profitTx);
|
|
186
|
-
console.log(` ✅ 买家 ${i}: 已添加利润转账 ${ethers.formatEther(profitList[i])} BNB`);
|
|
187
165
|
}
|
|
188
166
|
}
|
|
189
|
-
console.log(`✅ 利润转账添加完成,共 ${profitList.filter(p => p > 0n).length} 笔\n`);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
console.log(`⚠️ 跳过利润转账:`, {
|
|
193
|
-
extractProfit,
|
|
194
|
-
totalProfit: totalProfit ? ethers.formatEther(totalProfit) : '0',
|
|
195
|
-
buyersLength: buyers.length
|
|
196
|
-
});
|
|
197
167
|
}
|
|
198
168
|
// ✅ 清理临时 nonce 缓存
|
|
199
169
|
nonceManager.clearTemp();
|
|
200
|
-
console.log(`\n📦 交易汇总:`);
|
|
201
|
-
console.log(` - 创建代币: 1 笔`);
|
|
202
|
-
console.log(` - 购买交易: ${buyTxs.length} 笔`);
|
|
203
|
-
console.log(` - 利润转账: ${signedTxs.length - 1 - buyTxs.length} 笔`);
|
|
204
|
-
console.log(` - 总交易数: ${signedTxs.length} 笔\n`);
|
|
205
170
|
// ✅ 简化返回:只返回签名交易和代币地址
|
|
206
171
|
return {
|
|
207
172
|
signedTransactions: signedTxs,
|