four-flap-meme-sdk 1.7.34 → 1.7.36

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.
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * 只生成签名,由调用方决定如何提交
14
14
  */
15
- import { ethers } from 'ethers';
15
+ import { ethers, Contract } from 'ethers';
16
16
  import { getCachedProvider, createWallet, signAuthorizationsWithNonces, batchGetNonces, buildEIP7702TransactionSync, calculateProfitAmountByTxCount, getProfitRecipient, } from './utils.js';
17
17
  import { UNIFIED_DELEGATE_ADDRESS, UNIFIED_DELEGATE_ABI, FLAP_PORTAL_ABI, FLAP_PORTAL_ADDRESS, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, WOKB_ADDRESS, V3_FEE_TIERS, ERC20_ABI, } from './constants.js';
18
18
  import { bundleBuy } from './bundle-buy.js';
@@ -94,6 +94,18 @@ export async function washVolume(params) {
94
94
  // 并行获取数据
95
95
  // ========================================
96
96
  const allAddresses = allWallets.map(w => w.address);
97
+ // ✅ 对 FLAP 模式,预估买入会得到多少代币(用于卖出调用)
98
+ let estimatedTokenAmount = 0n;
99
+ if (poolType === 'FLAP') {
100
+ try {
101
+ const portalContract = new Contract(FLAP_PORTAL_ADDRESS, FLAP_PORTAL_ABI, provider);
102
+ estimatedTokenAmount = await portalContract.quoteBuy(tokenAddress, buyAmountWei);
103
+ console.log(`[washVolume] FLAP quoteBuy 预估: ${buyAmountWei} wei OKB -> ${estimatedTokenAmount} wei 代币`);
104
+ }
105
+ catch (e) {
106
+ console.warn(`[washVolume] quoteBuy 失败,使用 0 作为卖出金额:`, e);
107
+ }
108
+ }
97
109
  const [nonces, feeData] = await Promise.all([
98
110
  batchGetNonces(allAddresses, provider),
99
111
  provider.getFeeData(),
@@ -107,25 +119,29 @@ export async function washVolume(params) {
107
119
  // 构建调用
108
120
  // ========================================
109
121
  const calls = [];
110
- // 利润刮取(从主钱包)
111
- if (profitAmount > 0n) {
112
- calls.push({
113
- target: mainWallet.address,
114
- allowFailure: false,
115
- value: profitAmount,
116
- callData: delegateInterface.encodeFunctionData('transferTo', [profitRecipient]),
117
- });
118
- }
122
+ // ✅ 修复:先执行买卖,最后执行利润转账(与 bundleBuy 调用顺序一致)
119
123
  // 每个钱包执行买入 + 卖出
120
124
  for (let i = 0; i < wallets.length; i++) {
121
125
  const wallet = wallets[i];
122
126
  // 买入调用
123
127
  const buyCall = buildBuyCall(wallet, buyAmountWei, tokenAddress, poolType, actualRouter, fee, delegateInterface, portalInterface);
124
128
  calls.push(buyCall);
125
- // 卖出调用(使用 sellPercent)
126
- const sellCall = buildSellCall(wallet, tokenAddress, sellPercent, tokenDecimals, poolType, actualRouter, fee, delegateInterface, portalInterface);
129
+ // 卖出调用(使用预估的代币数量或 sellPercent)
130
+ // FLAP 模式使用 buildSellCallWithAmount,其他模式使用 buildSellCall
131
+ const sellCall = poolType === 'FLAP' && estimatedTokenAmount > 0n
132
+ ? buildSellCallWithAmount(wallet, estimatedTokenAmount, tokenAddress, poolType, actualRouter, fee, delegateInterface, portalInterface)
133
+ : buildSellCall(wallet, tokenAddress, sellPercent, tokenDecimals, poolType, actualRouter, fee, delegateInterface, portalInterface);
127
134
  calls.push(sellCall);
128
135
  }
136
+ // 利润刮取(放在最后,与 bundleBuy 一致)
137
+ if (profitAmount > 0n) {
138
+ calls.push({
139
+ target: mainWallet.address,
140
+ allowFailure: false,
141
+ value: profitAmount,
142
+ callData: delegateInterface.encodeFunctionData('transferTo', [profitRecipient]),
143
+ });
144
+ }
129
145
  // ========================================
130
146
  // 构建交易
131
147
  // ========================================
@@ -263,15 +279,7 @@ export async function bundleVolume(params) {
263
279
  // 构建调用
264
280
  // ========================================
265
281
  const calls = [];
266
- // 利润刮取
267
- if (profitAmount > 0n) {
268
- calls.push({
269
- target: mainWallet.address,
270
- allowFailure: false,
271
- value: profitAmount,
272
- callData: delegateInterface.encodeFunctionData('transferTo', [profitRecipient]),
273
- });
274
- }
282
+ // ✅ 修复:先执行买卖,最后执行利润转账(与 bundleBuy 调用顺序一致)
275
283
  // 买入调用
276
284
  for (let i = 0; i < buyerWallets.length; i++) {
277
285
  const buyCall = buildBuyCall(buyerWallets[i], buyAmountsWei[i], tokenAddress, poolType, actualRouter, fee, delegateInterface, portalInterface);
@@ -284,6 +292,15 @@ export async function bundleVolume(params) {
284
292
  const sellCall = buildSellCallWithAmount(sellerWallets[i], sellAmountsWei[i], tokenAddress, poolType, actualRouter, fee, delegateInterface, portalInterface);
285
293
  calls.push(sellCall);
286
294
  }
295
+ // 利润刮取(放在最后,与 bundleBuy 一致)
296
+ if (profitAmount > 0n) {
297
+ calls.push({
298
+ target: mainWallet.address,
299
+ allowFailure: false,
300
+ value: profitAmount,
301
+ callData: delegateInterface.encodeFunctionData('transferTo', [profitRecipient]),
302
+ });
303
+ }
287
304
  // ========================================
288
305
  // 构建交易
289
306
  // ========================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.34",
3
+ "version": "1.7.36",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",