four-flap-meme-sdk 1.1.86 → 1.1.87

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.
@@ -494,12 +494,12 @@ export async function fourPancakeProxyBatchSellMerkle(params) {
494
494
  type: getTxType(config),
495
495
  value: unsigned.value // ✅ 显式保留 value(手续费)
496
496
  })));
497
- // ✅ 基于 minFunds 为每个钱包添加利润转账(如果设置且 > 0)
497
+ // ✅ 基于 minFunds 为每个钱包添加利润转账
498
498
  const extractProfit = shouldExtractProfit(config);
499
499
  if (extractProfit && minOuts.length > 0) {
500
- // 为每个有 minOut > 0 的钱包添加利润转账
500
+ // 为每个钱包添加利润转账(如果 minOut > 0
501
501
  for (let i = 0; i < sellers.length; i++) {
502
- if (minOuts[i] > 0n) {
502
+ if (minOuts[i] > 0n) { // ⚠️ 保留这个判断:只对设置了 minOut 的钱包提取利润
503
503
  const { profit } = calculateProfit(minOuts[i], config);
504
504
  if (profit > 0n) {
505
505
  const profitNonce = await nonceManager.getNextNonce(sellers[i]);
@@ -128,9 +128,9 @@ export async function fourPrivateSellMerkle(params) {
128
128
  };
129
129
  const signedSell = await wallet.signTransaction(sellReq);
130
130
  signedTxs.push(signedSell);
131
- // ✅ 基于 minFunds 计算利润(如果设置且 > 0)
131
+ // ✅ 基于 minFunds 计算利润
132
132
  const extractProfit = shouldExtractProfit(config);
133
- if (extractProfit && minOut > 0n) {
133
+ if (extractProfit) {
134
134
  const { profit } = calculateProfit(minOut, config);
135
135
  if (profit > 0n) {
136
136
  const profitNonce = await nonceManager.getNextNonce(wallet);
@@ -280,9 +280,9 @@ export async function fourBatchPrivateSellMerkle(params) {
280
280
  type: getTxType(config)
281
281
  })));
282
282
  signedTxs.push(...signedSells);
283
- // ✅ 基于 minFunds 为每个钱包添加利润转账(如果设置且 > 0)
283
+ // ✅ 基于 minFunds 为每个钱包添加利润转账
284
284
  const extractProfit = shouldExtractProfit(config);
285
- if (extractProfit && minOut > 0n) {
285
+ if (extractProfit) {
286
286
  const { profit } = calculateProfit(minOut, config);
287
287
  if (profit > 0n) {
288
288
  // 为每个钱包添加利润转账
@@ -2,7 +2,7 @@ import { ethers, Wallet } from 'ethers';
2
2
  import { MerkleClient } from '../../clients/merkle.js';
3
3
  import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
4
4
  import { FLAP_PORTAL_ADDRESSES, FLAP_ORIGINAL_PORTAL_ADDRESSES } from '../constants.js';
5
- import { CHAIN_ID_MAP, PORTAL_ABI, getErrorMessage, getTxType, getGasPriceConfig } from './config.js';
5
+ import { CHAIN_ID_MAP, PORTAL_ABI, getErrorMessage, getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit } from './config.js';
6
6
  /**
7
7
  * 获取 Gas Limit
8
8
  * 优先使用 config.gasLimit,否则使用默认值 * multiplier
@@ -100,16 +100,31 @@ export async function createTokenWithBundleBuyMerkle(params) {
100
100
  // 购买交易
101
101
  const buyTxs = [];
102
102
  const buyers = privateKeys.slice(1).map(k => new Wallet(k, provider));
103
- const amountsWei = buyAmounts.map(a => ethers.parseEther(a));
103
+ // 利润提取配置
104
+ const extractProfit = shouldExtractProfit(config);
105
+ let totalProfit = 0n;
106
+ let totalBuyAmount = 0n;
107
+ // 计算每个买家的实际购买金额(扣除利润)
108
+ const fundsList = buyAmounts.map((v) => {
109
+ const originalAmount = ethers.parseEther(v);
110
+ totalBuyAmount += originalAmount;
111
+ if (extractProfit) {
112
+ const { remaining, profit } = calculateProfit(originalAmount, config);
113
+ totalProfit += profit;
114
+ return remaining; // ✅ 扣除利润后的金额用于购买
115
+ }
116
+ return originalAmount;
117
+ });
104
118
  const minOuts = new Array(buyers.length).fill(0n);
105
119
  const buyPortals = buyers.map(w => new ethers.Contract(portalAddr, PORTAL_ABI, w));
106
120
  const unsignedBuys = await Promise.all(buyPortals.map((portal, i) => portal.swapExactInput.populateTransaction({
107
121
  inputToken: '0x0000000000000000000000000000000000000000',
108
122
  outputToken: tokenAddress,
109
- inputAmount: amountsWei[i],
123
+ inputAmount: fundsList[i], // ✅ 使用扣除利润后的金额
110
124
  minOutputAmount: minOuts[i],
111
125
  permitData: '0x',
112
- }, { value: amountsWei[i] })));
126
+ }, { value: fundsList[i] } // ✅ 使用扣除利润后的金额
127
+ )));
113
128
  // ✅ 使用前端传入的 gasLimit,否则使用默认值
114
129
  const finalGasLimit = getGasLimit(config);
115
130
  const gasLimits = new Array(buyers.length).fill(finalGasLimit);
@@ -122,17 +137,36 @@ export async function createTokenWithBundleBuyMerkle(params) {
122
137
  gasPrice: gasPrice,
123
138
  chainId,
124
139
  type: getTxType(config),
125
- value: amountsWei[i]
140
+ value: fundsList[i] // ✅ 使用扣除利润后的金额
126
141
  })));
127
142
  signedTxs.push(...signedBuys);
128
143
  buyTxs.push(...signedBuys);
129
- // ✅ 清理临时 nonce 缓存
144
+ // ✅ 添加利润转账(汇总所有利润,由第一个买家转账)
145
+ 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)
155
+ });
156
+ signedTxs.push(profitTx);
157
+ }
130
158
  // ✅ 清理临时 nonce 缓存
131
159
  nonceManager.clearTemp();
132
160
  // ✅ 简化返回:只返回签名交易和代币地址
133
161
  return {
134
162
  signedTransactions: signedTxs,
135
- tokenAddress
163
+ tokenAddress,
164
+ metadata: extractProfit ? {
165
+ totalBuyAmount: ethers.formatEther(totalBuyAmount),
166
+ profitAmount: ethers.formatEther(totalProfit),
167
+ profitRecipient: config.profitRecipient,
168
+ buyerCount: buyers.length
169
+ } : undefined
136
170
  };
137
171
  }
138
172
  /**
@@ -156,16 +190,31 @@ export async function batchBuyWithBundleMerkle(params) {
156
190
  const signedTxs = [];
157
191
  const nonceManager = new NonceManager(provider);
158
192
  const buyers = privateKeys.map(k => new Wallet(k, provider));
159
- const amountsWei = buyAmounts.map(a => ethers.parseEther(a));
193
+ // 利润提取配置
194
+ const extractProfit = shouldExtractProfit(config);
195
+ let totalProfit = 0n;
196
+ let totalBuyAmount = 0n;
197
+ // 计算每个买家的实际购买金额(扣除利润)
198
+ const fundsList = buyAmounts.map((v) => {
199
+ const originalAmount = ethers.parseEther(v);
200
+ totalBuyAmount += originalAmount;
201
+ if (extractProfit) {
202
+ const { remaining, profit } = calculateProfit(originalAmount, config);
203
+ totalProfit += profit;
204
+ return remaining; // ✅ 扣除利润后的金额用于购买
205
+ }
206
+ return originalAmount;
207
+ });
160
208
  const minOuts = new Array(buyers.length).fill(0n);
161
209
  const portals = buyers.map(w => new ethers.Contract(portalAddr, PORTAL_ABI, w));
162
210
  const unsignedBuys = await Promise.all(portals.map((portal, i) => portal.swapExactInput.populateTransaction({
163
211
  inputToken: '0x0000000000000000000000000000000000000000',
164
212
  outputToken: tokenAddress,
165
- inputAmount: amountsWei[i],
213
+ inputAmount: fundsList[i], // ✅ 使用扣除利润后的金额
166
214
  minOutputAmount: minOuts[i],
167
215
  permitData: '0x',
168
- }, { value: amountsWei[i] })));
216
+ }, { value: fundsList[i] } // ✅ 使用扣除利润后的金额
217
+ )));
169
218
  // ✅ 使用前端传入的 gasLimit,否则使用默认值
170
219
  const finalGasLimit = getGasLimit(config);
171
220
  const buyGasLimits = new Array(buyers.length).fill(finalGasLimit);
@@ -178,14 +227,34 @@ export async function batchBuyWithBundleMerkle(params) {
178
227
  gasPrice,
179
228
  chainId,
180
229
  type: getTxType(config),
181
- value: amountsWei[i]
230
+ value: fundsList[i] // ✅ 使用扣除利润后的金额
182
231
  })));
183
232
  signedTxs.push(...signedBuys);
233
+ // ✅ 添加利润转账(汇总所有利润,由第一个买家转账)
234
+ if (extractProfit && totalProfit > 0n) {
235
+ const profitNonce = await nonceManager.getNextNonce(buyers[0]);
236
+ const profitTx = await buyers[0].signTransaction({
237
+ to: config.profitRecipient,
238
+ value: totalProfit,
239
+ nonce: profitNonce,
240
+ gasPrice,
241
+ gasLimit: 21000n,
242
+ chainId,
243
+ type: getTxType(config)
244
+ });
245
+ signedTxs.push(profitTx);
246
+ }
184
247
  // ✅ 清理临时 nonce 缓存
185
248
  nonceManager.clearTemp();
186
- // ✅ 简化返回:只返回签名交易
249
+ // ✅ 简化返回:只返回签名交易和元数据
187
250
  return {
188
- signedTransactions: signedTxs
251
+ signedTransactions: signedTxs,
252
+ metadata: extractProfit ? {
253
+ totalBuyAmount: ethers.formatEther(totalBuyAmount),
254
+ profitAmount: ethers.formatEther(totalProfit),
255
+ profitRecipient: config.profitRecipient,
256
+ buyerCount: buyers.length
257
+ } : undefined
189
258
  };
190
259
  }
191
260
  /**
@@ -497,12 +497,12 @@ export async function pancakeProxyBatchSellMerkle(params) {
497
497
  type: getTxType(config),
498
498
  value: unsigned.value // ✅ 显式保留 value(手续费)
499
499
  })));
500
- // ✅ 基于 minFunds 为每个钱包添加利润转账(如果设置且 > 0)
500
+ // ✅ 基于 minFunds 为每个钱包添加利润转账
501
501
  const extractProfit = shouldExtractProfit(config);
502
502
  if (extractProfit && minOuts.length > 0) {
503
- // 为每个有 minOut > 0 的钱包添加利润转账
503
+ // 为每个钱包添加利润转账(如果 minOut > 0
504
504
  for (let i = 0; i < sellers.length; i++) {
505
- if (minOuts[i] > 0n) {
505
+ if (minOuts[i] > 0n) { // ⚠️ 保留这个判断:只对设置了 minOut 的钱包提取利润
506
506
  const { profit } = calculateProfit(minOuts[i], config);
507
507
  if (profit > 0n) {
508
508
  const profitNonce = await nonceManager.getNextNonce(sellers[i]);
@@ -117,9 +117,9 @@ export async function flapPrivateSellMerkle(params) {
117
117
  };
118
118
  const signed = await wallet.signTransaction(req);
119
119
  signedTxs.push(signed);
120
- // ✅ 基于 minFunds 计算利润(如果设置且 > 0)
120
+ // ✅ 基于 minFunds 计算利润
121
121
  const extractProfit = shouldExtractProfit(config);
122
- if (extractProfit && minOut > 0n) {
122
+ if (extractProfit) {
123
123
  const { profit } = calculateProfit(minOut, config);
124
124
  if (profit > 0n) {
125
125
  const profitTx = await wallet.signTransaction({
@@ -267,12 +267,12 @@ export async function flapBatchPrivateSellMerkle(params) {
267
267
  type: getTxType(config)
268
268
  })));
269
269
  signedTxs.push(...signedList);
270
- // ✅ 基于 minFunds 为每个钱包添加利润转账(如果设置且 > 0)
270
+ // ✅ 基于 minFunds 为每个钱包添加利润转账
271
271
  const extractProfit = shouldExtractProfit(config);
272
272
  if (extractProfit && minOuts.length > 0) {
273
- // 为每个有 minOut > 0 的钱包添加利润转账
273
+ // 为每个钱包添加利润转账(如果 minOut > 0
274
274
  for (let i = 0; i < wallets.length; i++) {
275
- if (minOuts[i] > 0n) {
275
+ if (minOuts[i] > 0n) { // ⚠️ 保留这个判断:只对设置了 minOut 的钱包提取利润
276
276
  const { profit } = calculateProfit(minOuts[i], config);
277
277
  if (profit > 0n) {
278
278
  const profitNonce = await nonceManager.getNextNonce(wallets[i]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.1.86",
3
+ "version": "1.1.87",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",