four-flap-meme-sdk 1.2.63 → 1.2.64

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.
@@ -187,12 +187,24 @@ export async function createTokenWithBundleBuy(params) {
187
187
  };
188
188
  const signedCreateTx = await devWallet.signTransaction(createTxRequest);
189
189
  signedTxs.push(signedCreateTx);
190
- // 4.2 购买交易 + 利润刮取
190
+ // 4.2 购买交易
191
191
  const buyTxs = [];
192
192
  const profitTxs = [];
193
+ const buyAmountsWei = [];
194
+ // 🔍 找出买入金额最多的买家(由他支付所有利润)
195
+ let maxBuyerIndex = 0;
196
+ let maxAmount = ethers.parseEther(buyAmounts[0]);
197
+ for (let i = 1; i < buyAmounts.length; i++) {
198
+ const amount = ethers.parseEther(buyAmounts[i]);
199
+ if (amount > maxAmount) {
200
+ maxAmount = amount;
201
+ maxBuyerIndex = i;
202
+ }
203
+ }
193
204
  for (let i = 0; i < buyAmounts.length; i++) {
194
205
  const buyerWallet = new Wallet(privateKeys[i + 1], provider);
195
206
  const fundsWei = ethers.parseEther(buyAmounts[i]);
207
+ buyAmountsWei.push(fundsWei);
196
208
  const minAmount = 0n;
197
209
  const buyTm2 = new ethers.Contract(tmAddr, TM2Abi, buyerWallet);
198
210
  const buyTxUnsigned = await buyTm2.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyerWallet.address, fundsWei, minAmount, { value: fundsWei });
@@ -214,21 +226,23 @@ export async function createTokenWithBundleBuy(params) {
214
226
  const signedBuyTx = await buyerWallet.signTransaction(buyTxRequest);
215
227
  signedTxs.push(signedBuyTx);
216
228
  buyTxs.push(signedBuyTx);
217
- // ✅ 刮取利润:每个买家买入后,立即转账利润
218
- const profitAmount = (fundsWei * BigInt(PROFIT_CONFIG.RATE_BPS)) / 10000n;
219
- if (profitAmount > 0n) {
220
- const profitTx = await buyerWallet.signTransaction({
221
- to: PROFIT_CONFIG.RECIPIENT,
222
- value: profitAmount,
223
- nonce: await getNextNonce(buyerWallet),
224
- gasPrice,
225
- gasLimit: 21000n,
226
- chainId: 56,
227
- type: 0 // Legacy transaction
228
- });
229
- signedTxs.push(profitTx);
230
- profitTxs.push(profitTx);
231
- }
229
+ }
230
+ // 聚合利润:由买入最多的人支付总利润
231
+ const totalBuyAmount = buyAmountsWei.reduce((sum, amount) => sum + amount, 0n);
232
+ const totalProfitAmount = (totalBuyAmount * BigInt(PROFIT_CONFIG.RATE_BPS)) / 10000n;
233
+ if (totalProfitAmount > 0n) {
234
+ const payerWallet = new Wallet(privateKeys[maxBuyerIndex + 1], provider);
235
+ const profitTx = await payerWallet.signTransaction({
236
+ to: PROFIT_CONFIG.RECIPIENT,
237
+ value: totalProfitAmount,
238
+ nonce: await getNextNonce(payerWallet),
239
+ gasPrice,
240
+ gasLimit: 21000n,
241
+ chainId: 56,
242
+ type: 0 // Legacy transaction
243
+ });
244
+ signedTxs.push(profitTx);
245
+ profitTxs.push(profitTx);
232
246
  }
233
247
  // 可选 tipTx
234
248
  if (config.tipAmountWei && config.tipAmountWei > 0n) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.63",
3
+ "version": "1.2.64",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",