four-flap-meme-sdk 1.4.98 → 1.5.1

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.
@@ -176,7 +176,21 @@ function resolveBuyerAmounts(buyers, totalAmountStr, useNativeToken, quoteTokenD
176
176
  const provided = buyers.map(b => b?.buyAmount).filter(v => v != null && String(v).trim() !== '');
177
177
  const allProvided = provided.length === buyers.length;
178
178
  if (allProvided) {
179
- return buyers.map(b => parseQuoteAmount(String(b.buyAmount), useNativeToken, quoteTokenDecimals));
179
+ // 所有买家都显式提供了 buyAmount:按传入金额构建,但要修正“浮点/四舍五入导致总和偏差”
180
+ const amounts = buyers.map(b => parseQuoteAmount(String(b.buyAmount), useNativeToken, quoteTokenDecimals));
181
+ const totalWei = parseQuoteAmount(totalAmountStr, useNativeToken, quoteTokenDecimals);
182
+ const sum = amounts.reduce((a, b) => a + b, 0n);
183
+ const delta = totalWei - sum;
184
+ if (delta !== 0n && amounts.length > 0) {
185
+ // 优先修正最后一个金额(对应 create-to-dex 里“最后一单可能触发毕业”的假设)
186
+ const lastIdx = amounts.length - 1;
187
+ const next = amounts[lastIdx] + delta;
188
+ if (next <= 0n) {
189
+ throw new Error(`买入金额总和与总额不一致且无法修正:sum=${sum} total=${totalWei} delta=${delta}`);
190
+ }
191
+ amounts[lastIdx] = next;
192
+ }
193
+ return amounts;
180
194
  }
181
195
  const totalWei = parseQuoteAmount(totalAmountStr, useNativeToken, quoteTokenDecimals);
182
196
  return splitAmount(totalWei, buyers.length);
@@ -423,8 +437,12 @@ export async function flapBundleCreateToDex(params) {
423
437
  // ✅ 使用动态 Router 地址
424
438
  const smartRouter = dexPoolType === 'v3' ? chainConfig.v3Router : chainConfig.v2Router;
425
439
  const wrappedNative = chainConfig.wrappedNative;
426
- // ✅ 根据 quoteToken 选择 V3 费率
427
- const actualV3Fee = v3Fee || (useNativeToken ? DEFAULT_V3_FEE : USD1_V3_FEE);
440
+ // ✅ 根据 quoteToken 强制选择 V3 费率(参考 Flap 官方配置)
441
+ // Flap 合约在毕业时创建的 V3 池子费率由 quoteToken 决定:
442
+ // - BNB (原生代币) → 0.25% (2500)
443
+ // - USD1 等稳定币 → 0.01% (100)
444
+ // 即使传入了 lpFeeProfile,Flap 合约也可能忽略,所以这里强制匹配
445
+ const actualV3Fee = useNativeToken ? DEFAULT_V3_FEE : USD1_V3_FEE;
428
446
  // ✅ ERC20: 先构建 approve 交易
429
447
  if (!useNativeToken) {
430
448
  const approveNonce = noncesMap.get(addr);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.4.98",
3
+ "version": "1.5.01",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",