four-flap-meme-sdk 1.2.7 → 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();
|
|
@@ -104,12 +104,6 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
104
104
|
const extractProfit = shouldExtractProfit(config);
|
|
105
105
|
let totalProfit = 0n;
|
|
106
106
|
let totalBuyAmount = 0n;
|
|
107
|
-
console.log('🔍 创建+跟买 利润提取检查:', {
|
|
108
|
-
extractProfit,
|
|
109
|
-
profitRecipient: config.profitRecipient,
|
|
110
|
-
profitRateBps: config.profitRateBps,
|
|
111
|
-
buyersCount: privateKeys.length - 1
|
|
112
|
-
});
|
|
113
107
|
// 计算每个买家的实际购买金额和利润
|
|
114
108
|
const fundsList = [];
|
|
115
109
|
const profitList = [];
|
|
@@ -121,12 +115,10 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
121
115
|
totalProfit += profit;
|
|
122
116
|
fundsList.push(remaining); // ✅ 扣除利润后的金额用于购买
|
|
123
117
|
profitList.push(profit); // ✅ 记录每个买家的利润
|
|
124
|
-
console.log(` 买家 ${idx}: 原金额 ${ethers.formatEther(originalAmount)} BNB, 购买 ${ethers.formatEther(remaining)} BNB, 利润 ${ethers.formatEther(profit)} BNB`);
|
|
125
118
|
}
|
|
126
119
|
else {
|
|
127
120
|
fundsList.push(originalAmount);
|
|
128
121
|
profitList.push(0n);
|
|
129
|
-
console.log(` 买家 ${idx}: 购买 ${ethers.formatEther(originalAmount)} BNB (无利润提取)`);
|
|
130
122
|
}
|
|
131
123
|
});
|
|
132
124
|
const minOuts = new Array(buyers.length).fill(0n);
|
|
@@ -157,10 +149,7 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
157
149
|
buyTxs.push(...signedBuys);
|
|
158
150
|
// ✅ 添加利润转账(每个买家单独转自己的利润)
|
|
159
151
|
if (extractProfit && totalProfit > 0n && buyers.length > 0) {
|
|
160
|
-
console.log(`💰 开始添加利润转账...`);
|
|
161
|
-
console.log(` 总利润: ${ethers.formatEther(totalProfit)} BNB → ${config.profitRecipient}`);
|
|
162
152
|
for (let i = 0; i < buyers.length; i++) {
|
|
163
|
-
console.log(` 买家 ${i}: profitList[${i}] = ${profitList[i] ? ethers.formatEther(profitList[i]) : 'undefined'} BNB`);
|
|
164
153
|
if (profitList[i] > 0n) {
|
|
165
154
|
const profitNonce = await nonceManager.getNextNonce(buyers[i]);
|
|
166
155
|
const profitTx = await buyers[i].signTransaction({
|
|
@@ -173,25 +162,11 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
173
162
|
type: getTxType(config)
|
|
174
163
|
});
|
|
175
164
|
signedTxs.push(profitTx);
|
|
176
|
-
console.log(` ✅ 买家 ${i}: 已添加利润转账 ${ethers.formatEther(profitList[i])} BNB`);
|
|
177
165
|
}
|
|
178
166
|
}
|
|
179
|
-
console.log(`✅ 利润转账添加完成,共 ${profitList.filter(p => p > 0n).length} 笔\n`);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
console.log(`⚠️ 跳过利润转账:`, {
|
|
183
|
-
extractProfit,
|
|
184
|
-
totalProfit: totalProfit ? ethers.formatEther(totalProfit) : '0',
|
|
185
|
-
buyersLength: buyers.length
|
|
186
|
-
});
|
|
187
167
|
}
|
|
188
168
|
// ✅ 清理临时 nonce 缓存
|
|
189
169
|
nonceManager.clearTemp();
|
|
190
|
-
console.log(`\n📦 交易汇总:`);
|
|
191
|
-
console.log(` - 创建代币: 1 笔`);
|
|
192
|
-
console.log(` - 购买交易: ${buyTxs.length} 笔`);
|
|
193
|
-
console.log(` - 利润转账: ${signedTxs.length - 1 - buyTxs.length} 笔`);
|
|
194
|
-
console.log(` - 总交易数: ${signedTxs.length} 笔\n`);
|
|
195
170
|
// ✅ 简化返回:只返回签名交易和代币地址
|
|
196
171
|
return {
|
|
197
172
|
signedTransactions: signedTxs,
|