four-flap-meme-sdk 1.2.4 → 1.2.6

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.
@@ -104,16 +104,30 @@ export async function createTokenWithBundleBuyMerkle(params) {
104
104
  const extractProfit = shouldExtractProfit(config);
105
105
  let totalProfit = 0n;
106
106
  let totalBuyAmount = 0n;
107
- // 计算每个买家的实际购买金额(扣除利润)
108
- const fundsList = buyAmounts.map((v) => {
107
+ console.log('🔍 创建+跟买 利润提取检查:', {
108
+ extractProfit,
109
+ profitRecipient: config.profitRecipient,
110
+ profitRateBps: config.profitRateBps,
111
+ buyersCount: privateKeys.length - 1
112
+ });
113
+ // 计算每个买家的实际购买金额和利润
114
+ const fundsList = [];
115
+ const profitList = [];
116
+ buyAmounts.forEach((v, idx) => {
109
117
  const originalAmount = ethers.parseEther(v);
110
118
  totalBuyAmount += originalAmount;
111
119
  if (extractProfit) {
112
120
  const { remaining, profit } = calculateProfit(originalAmount, config);
113
121
  totalProfit += profit;
114
- return remaining; // ✅ 扣除利润后的金额用于购买
122
+ fundsList.push(remaining); // ✅ 扣除利润后的金额用于购买
123
+ profitList.push(profit); // ✅ 记录每个买家的利润
124
+ console.log(` 买家 ${idx}: 原金额 ${ethers.formatEther(originalAmount)} BNB, 购买 ${ethers.formatEther(remaining)} BNB, 利润 ${ethers.formatEther(profit)} BNB`);
125
+ }
126
+ else {
127
+ fundsList.push(originalAmount);
128
+ profitList.push(0n);
129
+ console.log(` 买家 ${idx}: 购买 ${ethers.formatEther(originalAmount)} BNB (无利润提取)`);
115
130
  }
116
- return originalAmount;
117
131
  });
118
132
  const minOuts = new Array(buyers.length).fill(0n);
119
133
  const buyPortals = buyers.map(w => new ethers.Contract(portalAddr, PORTAL_ABI, w));
@@ -141,22 +155,43 @@ export async function createTokenWithBundleBuyMerkle(params) {
141
155
  })));
142
156
  signedTxs.push(...signedBuys);
143
157
  buyTxs.push(...signedBuys);
144
- // ✅ 添加利润转账(汇总所有利润,由第一个买家转账)
158
+ // ✅ 添加利润转账(每个买家单独转自己的利润)
145
159
  if (extractProfit && totalProfit > 0n && buyers.length > 0) {
146
- const profitNonce = await nonceManager.getNextNonce(buyers[0]);
147
- const profitTx = await buyers[0].signTransaction({
148
- to: config.profitRecipient,
149
- value: totalProfit,
150
- nonce: profitNonce,
151
- gasPrice,
152
- gasLimit: 21000n,
153
- chainId,
154
- type: getTxType(config)
160
+ console.log(`💰 开始添加利润转账...`);
161
+ console.log(` 总利润: ${ethers.formatEther(totalProfit)} BNB ${config.profitRecipient}`);
162
+ for (let i = 0; i < buyers.length; i++) {
163
+ console.log(` 买家 ${i}: profitList[${i}] = ${profitList[i] ? ethers.formatEther(profitList[i]) : 'undefined'} BNB`);
164
+ if (profitList[i] > 0n) {
165
+ const profitNonce = await nonceManager.getNextNonce(buyers[i]);
166
+ const profitTx = await buyers[i].signTransaction({
167
+ to: config.profitRecipient,
168
+ value: profitList[i], // ✅ 每个买家转自己的利润
169
+ nonce: profitNonce,
170
+ gasPrice,
171
+ gasLimit: 21000n,
172
+ chainId,
173
+ type: getTxType(config)
174
+ });
175
+ signedTxs.push(profitTx);
176
+ console.log(` ✅ 买家 ${i}: 已添加利润转账 ${ethers.formatEther(profitList[i])} BNB`);
177
+ }
178
+ }
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
155
186
  });
156
- signedTxs.push(profitTx);
157
187
  }
158
188
  // ✅ 清理临时 nonce 缓存
159
189
  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`);
160
195
  // ✅ 简化返回:只返回签名交易和代币地址
161
196
  return {
162
197
  signedTransactions: signedTxs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",