four-flap-meme-sdk 1.7.35 → 1.7.37

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,36 @@ export async function washVolume(params) {
94
94
  // 并行获取数据
95
95
  // ========================================
96
96
  const allAddresses = allWallets.map(w => w.address);
97
+ // ✅ 对 FLAP 模式,使用【总金额报价 + 按比例分配】(与 AA 模式一致)
98
+ // 因为所有钱包在同一笔交易中执行,会累积影响价格
99
+ let estimatedTokenAmounts = [];
100
+ if (poolType === 'FLAP') {
101
+ const totalBuyWei = buyAmountWei * BigInt(wallets.length);
102
+ console.log(`[washVolume] FLAP 总金额报价: ${wallets.length} 个钱包, 每个 ${buyAmountWei} wei, 总计 ${totalBuyWei} wei`);
103
+ try {
104
+ const portalContract = new Contract(FLAP_PORTAL_ADDRESS, FLAP_PORTAL_ABI, provider);
105
+ // 使用总金额获取总代币数量
106
+ const totalTokenAmount = await portalContract.quoteBuy(tokenAddress, totalBuyWei);
107
+ console.log(`[washVolume] FLAP quoteBuy 总预估: ${totalBuyWei} wei OKB -> ${totalTokenAmount} wei 代币`);
108
+ // 按每个钱包的买入金额比例分配(由于每个钱包金额相同,均分即可)
109
+ if (totalBuyWei > 0n && totalTokenAmount > 0n) {
110
+ const sharePerWallet = totalTokenAmount / BigInt(wallets.length);
111
+ let allocated = 0n;
112
+ estimatedTokenAmounts = wallets.map((_, i) => {
113
+ if (i === wallets.length - 1) {
114
+ // 最后一个钱包分配剩余的全部(避免精度损失)
115
+ return totalTokenAmount - allocated;
116
+ }
117
+ allocated += sharePerWallet;
118
+ return sharePerWallet;
119
+ });
120
+ }
121
+ console.log(`[washVolume] FLAP 代币分配:`, estimatedTokenAmounts.map(a => a.toString()));
122
+ }
123
+ catch (e) {
124
+ console.warn(`[washVolume] quoteBuy 失败:`, e);
125
+ }
126
+ }
97
127
  const [nonces, feeData] = await Promise.all([
98
128
  batchGetNonces(allAddresses, provider),
99
129
  provider.getFeeData(),
@@ -114,8 +144,12 @@ export async function washVolume(params) {
114
144
  // 买入调用
115
145
  const buyCall = buildBuyCall(wallet, buyAmountWei, tokenAddress, poolType, actualRouter, fee, delegateInterface, portalInterface);
116
146
  calls.push(buyCall);
117
- // 卖出调用(使用 sellPercent)
118
- const sellCall = buildSellCall(wallet, tokenAddress, sellPercent, tokenDecimals, poolType, actualRouter, fee, delegateInterface, portalInterface);
147
+ // 卖出调用(使用预估的代币数量)
148
+ // FLAP 模式使用按比例分配的预估数量
149
+ const estimatedAmount = estimatedTokenAmounts[i] || 0n;
150
+ const sellCall = poolType === 'FLAP' && estimatedAmount > 0n
151
+ ? buildSellCallWithAmount(wallet, estimatedAmount, tokenAddress, poolType, actualRouter, fee, delegateInterface, portalInterface)
152
+ : buildSellCall(wallet, tokenAddress, sellPercent, tokenDecimals, poolType, actualRouter, fee, delegateInterface, portalInterface);
119
153
  calls.push(sellCall);
120
154
  }
121
155
  // 利润刮取(放在最后,与 bundleBuy 一致)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.35",
3
+ "version": "1.7.37",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",