four-flap-meme-sdk 1.2.95 → 1.2.96

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.
@@ -124,9 +124,9 @@ export async function createTokenWithBundleBuyMerkle(params) {
124
124
  * ✅ 支持 quoteToken:传入 USDC 等地址时使用该代币购买,否则使用原生代币
125
125
  */
126
126
  export async function batchBuyWithBundleMerkle(params) {
127
- const { chain, privateKeys, buyAmounts, tokenAddress, quoteToken, config } = params;
127
+ const { chain, privateKeys, buyAmounts, tokenAddress, quoteToken, quoteTokenDecimals, config } = params;
128
128
  console.log('🔍 SDK batchBuyWithBundleMerkle - quoteToken:', quoteToken);
129
- console.log('🔍 SDK batchBuyWithBundleMerkle - params.quoteToken:', params.quoteToken);
129
+ console.log('🔍 SDK batchBuyWithBundleMerkle - quoteTokenDecimals:', quoteTokenDecimals);
130
130
  if (privateKeys.length === 0 || buyAmounts.length !== privateKeys.length) {
131
131
  throw new Error(getErrorMessage('KEY_AMOUNT_MISMATCH'));
132
132
  }
@@ -142,12 +142,25 @@ export async function batchBuyWithBundleMerkle(params) {
142
142
  const inputToken = quoteToken && quoteToken !== ZERO_ADDRESS ? quoteToken : ZERO_ADDRESS;
143
143
  // ✅ 如果使用非原生代币,则 value 应为 0(不发送原生代币)
144
144
  const useNativeToken = inputToken === ZERO_ADDRESS;
145
+ // ✅ 如果使用非原生代币(如 USDC),需要根据精度转换金额
146
+ // buyAmounts 是按 18 位精度传入的,需要转换为目标代币精度
147
+ let adjustedFundsList = fundsList;
148
+ if (!useNativeToken && quoteTokenDecimals !== undefined && quoteTokenDecimals !== 18) {
149
+ // 从 18 位精度转换为目标精度
150
+ // 例如:0.1 ETH (18位) = 100000000000000000 wei
151
+ // 转为 USDC (6位) = 100000 (0.1 USDC)
152
+ const decimalsDiff = 18 - quoteTokenDecimals;
153
+ const divisor = BigInt(10 ** decimalsDiff);
154
+ adjustedFundsList = fundsList.map(amount => amount / divisor);
155
+ console.log('🔍 SDK 精度转换: 18 -> ', quoteTokenDecimals, ', 原始:', fundsList, ', 转换后:', adjustedFundsList);
156
+ }
145
157
  console.log('🔍 SDK inputToken 计算结果:', inputToken);
146
158
  console.log('🔍 SDK useNativeToken:', useNativeToken);
159
+ console.log('🔍 SDK adjustedFundsList:', adjustedFundsList);
147
160
  // ✅ 优化:并行执行 gasPrice 和 populateBuyTransactions(最耗时的两个操作)
148
161
  const [gasPrice, unsignedBuys] = await Promise.all([
149
162
  resolveGasPrice(provider, config),
150
- populateBuyTransactionsWithQuote(buyers, FLAP_PORTAL_ADDRESSES[chain], tokenAddress, fundsList, inputToken, useNativeToken)
163
+ populateBuyTransactionsWithQuote(buyers, FLAP_PORTAL_ADDRESSES[chain], tokenAddress, adjustedFundsList, inputToken, useNativeToken)
151
164
  ]);
152
165
  const buyerNonces = await allocateBuyerNonces(buyers, extractProfit, maxFundsIndex, totalProfit, nonceManager);
153
166
  const signedBuys = await signBuyTransactions({
@@ -121,6 +121,8 @@ export type FlapBatchBuySignParams = {
121
121
  tokenAddress: string;
122
122
  /** 报价代币地址(如 USDC),零地址或不传表示使用原生代币(MON/BNB) */
123
123
  quoteToken?: string;
124
+ /** ✅ 报价代币精度(如 USDC 为 6),不传默认 18 */
125
+ quoteTokenDecimals?: number;
124
126
  minOutputAmounts?: (string | bigint)[];
125
127
  config: FlapSignConfig;
126
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.95",
3
+ "version": "1.2.96",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",