four-flap-meme-sdk 1.2.99 → 1.3.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.
@@ -86,8 +86,20 @@ export async function createTokenWithBundleBuyMerkle(params) {
86
86
  const extractProfit = shouldExtractProfit(config);
87
87
  const { fundsList, originalAmounts, totalBuyAmount, totalProfit } = analyzeBuyFunds(buyAmounts, config, extractProfit);
88
88
  const maxFundsIndex = findMaxIndex(originalAmounts);
89
- const unsignedBuys = await populateBuyTransactions(buyers, portalAddr, tokenAddress, fundsList);
90
89
  const gasLimits = buildGasLimitList(buyers.length, config);
90
+ // ✅ 支持 quoteToken:如果传入了 quoteToken 且非零地址,则使用它
91
+ const inputToken = params.quoteToken && params.quoteToken !== ZERO_ADDRESS ? params.quoteToken : ZERO_ADDRESS;
92
+ const useNativeToken = inputToken === ZERO_ADDRESS;
93
+ // ✅ 如果使用非原生代币(如 USDC),需要根据精度转换金额
94
+ let adjustedFundsList = fundsList;
95
+ if (!useNativeToken && params.quoteTokenDecimals !== undefined && params.quoteTokenDecimals !== 18) {
96
+ const decimalsDiff = 18 - params.quoteTokenDecimals;
97
+ const divisor = BigInt(10 ** decimalsDiff);
98
+ adjustedFundsList = fundsList.map(amount => amount / divisor);
99
+ console.log('🔍 createToken SDK 精度转换: 18 -> ', params.quoteTokenDecimals, ', 原始:', fundsList, ', 转换后:', adjustedFundsList);
100
+ }
101
+ console.log('🔍 createToken SDK - quoteToken:', params.quoteToken, 'inputToken:', inputToken, 'useNativeToken:', useNativeToken);
102
+ const unsignedBuys = await populateBuyTransactionsWithQuote(buyers, portalAddr, tokenAddress, adjustedFundsList, inputToken, useNativeToken);
91
103
  const buyerNonces = await allocateBuyerNonces(buyers, extractProfit, maxFundsIndex, totalProfit, nonceManager);
92
104
  const signedBuys = await signBuyTransactions({
93
105
  unsignedBuys,
@@ -97,7 +109,8 @@ export async function createTokenWithBundleBuyMerkle(params) {
97
109
  gasPrice,
98
110
  chainId,
99
111
  config,
100
- fundsList
112
+ fundsList: adjustedFundsList, // ✅ 使用调整后的金额
113
+ useNativeToken // ✅ 传递是否使用原生代币
101
114
  });
102
115
  signedTxs.push(...signedBuys);
103
116
  await appendProfitTransaction({
@@ -344,7 +357,8 @@ async function allocateBuyerNonces(buyers, extractProfit, maxIndex, totalProfit,
344
357
  }
345
358
  return nonces;
346
359
  }
347
- async function signBuyTransactions({ unsignedBuys, buyers, nonces, gasLimits, gasPrice, chainId, config, fundsList }) {
360
+ async function signBuyTransactions({ unsignedBuys, buyers, nonces, gasLimits, gasPrice, chainId, config, fundsList, useNativeToken = true // ✅ 默认使用原生代币
361
+ }) {
348
362
  return await Promise.all(unsignedBuys.map((unsigned, i) => buyers[i].signTransaction({
349
363
  ...unsigned,
350
364
  from: buyers[i].address,
@@ -353,7 +367,7 @@ async function signBuyTransactions({ unsignedBuys, buyers, nonces, gasLimits, ga
353
367
  gasPrice,
354
368
  chainId,
355
369
  type: getTxType(config),
356
- value: fundsList[i]
370
+ value: useNativeToken ? fundsList[i] : 0n // ✅ 非原生代币时 value 为 0
357
371
  })));
358
372
  }
359
373
  async function appendProfitTransaction({ extractProfit, totalProfit, buyers, maxIndex, nonces, gasPrice, chainId, config, signedTxs }) {
@@ -89,6 +89,8 @@ export type FlapCreateWithBundleBuySignParams = {
89
89
  meta: string;
90
90
  };
91
91
  quoteToken?: string;
92
+ /** ✅ 报价代币精度(如 USDC 为 6),不传默认 18 */
93
+ quoteTokenDecimals?: number;
92
94
  tokenAddress: string;
93
95
  minOutputAmounts?: (string | bigint)[];
94
96
  config: FlapSignConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.99",
3
+ "version": "1.3.01",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",