four-flap-meme-sdk 1.4.5 → 1.4.6

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.
@@ -848,23 +848,34 @@ export async function directV2BatchSell(params) {
848
848
  }
849
849
  const totalSellAmount = sellAmountsWei.reduce((sum, o) => sum + o, 0n);
850
850
  // ✅ 修复:对于卖出操作,利润应基于【得到的 BNB/原生代币】而不是【卖出的代币数量】
851
- // 需要先获取卖出报价,然后基于预估得到的原生代币数量计算利润
851
+ // 使用 V2 Router 获取卖出报价,然后基于预估得到的原生代币数量计算利润
852
852
  const nativeProfitPromise = (async () => {
853
- if (useNativeOutput) {
854
- // 卖出代币 → 得到 BNB:先获取报价,再计算利润
855
- const estimatedBNBOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain);
856
- if (estimatedBNBOut <= 0n)
857
- return 0n;
858
- return calculateProfitAmount(estimatedBNBOut); // 0.3% × 得到的 BNB
853
+ try {
854
+ if (useNativeOutput) {
855
+ // 卖出代币 得到 BNB:先获取报价,再计算利润
856
+ const estimatedBNBOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain);
857
+ console.log(`[V2 Sell Profit] totalSellAmount: ${totalSellAmount}, estimatedBNBOut: ${estimatedBNBOut}, estimatedBNB: ${ethers.formatEther(estimatedBNBOut)}`);
858
+ if (estimatedBNBOut <= 0n)
859
+ return 0n;
860
+ const profit = calculateProfitAmount(estimatedBNBOut);
861
+ console.log(`[V2 Sell Profit] profit: ${profit}, profitBNB: ${ethers.formatEther(profit)}`);
862
+ return profit;
863
+ }
864
+ else if (quoteToken) {
865
+ // 卖出代币 → 得到 ERC20:需要先获取代币→ERC20报价,再计算利润
866
+ // ⚠️ 这里也需要修复!应该先获取卖出报价
867
+ const estimatedQuoteOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain);
868
+ if (estimatedQuoteOut <= 0n)
869
+ return 0n;
870
+ const baseProfitWei = calculateProfitAmount(estimatedQuoteOut);
871
+ return baseProfitWei; // 已经是原生代币,不需要再转换
872
+ }
873
+ return 0n;
859
874
  }
860
- else if (quoteToken) {
861
- // 卖出代币 得到 ERC20:先计算 ERC20 利润,再转换为 BNB
862
- const baseProfitWei = calculateProfitAmount(totalSellAmount);
863
- if (baseProfitWei <= 0n)
864
- return 0n;
865
- return getTokenToNativeQuote(provider, quoteToken, baseProfitWei, chain);
875
+ catch (error) {
876
+ console.error(`[V2 Sell Profit] Error:`, error);
877
+ return 0n;
866
878
  }
867
- return 0n;
868
879
  })();
869
880
  // 构建路径和 Router
870
881
  const outputToken = useNativeOutput ? wrappedNative : quoteToken;
@@ -1099,23 +1110,33 @@ export async function directV3BatchSell(params) {
1099
1110
  }
1100
1111
  const totalSellAmount = sellAmountsWei.reduce((sum, o) => sum + o, 0n);
1101
1112
  // ✅ 修复:对于卖出操作,利润应基于【得到的 BNB/原生代币】而不是【卖出的代币数量】
1102
- // 需要先获取卖出报价,然后基于预估得到的原生代币数量计算利润
1113
+ // 使用 V2 Router 获取卖出报价,然后基于预估得到的原生代币数量计算利润
1103
1114
  const nativeProfitPromise = (async () => {
1104
- if (useNativeOutput) {
1105
- // 卖出代币 → 得到 BNB:先获取报价,再计算利润
1106
- const estimatedBNBOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain);
1107
- if (estimatedBNBOut <= 0n)
1108
- return 0n;
1109
- return calculateProfitAmount(estimatedBNBOut); // 0.3% × 得到的 BNB
1115
+ try {
1116
+ if (useNativeOutput) {
1117
+ // 卖出代币 得到 BNB:先获取报价,再计算利润
1118
+ const estimatedBNBOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain);
1119
+ console.log(`[V3 Sell Profit] totalSellAmount: ${totalSellAmount}, estimatedBNBOut: ${estimatedBNBOut}, estimatedBNB: ${ethers.formatEther(estimatedBNBOut)}`);
1120
+ if (estimatedBNBOut <= 0n)
1121
+ return 0n;
1122
+ const profit = calculateProfitAmount(estimatedBNBOut);
1123
+ console.log(`[V3 Sell Profit] profit: ${profit}, profitBNB: ${ethers.formatEther(profit)}`);
1124
+ return profit;
1125
+ }
1126
+ else if (quoteToken) {
1127
+ // 卖出代币 → 得到 ERC20:需要先获取代币→BNB报价,再计算利润
1128
+ const estimatedBNBOut = await getTokenToNativeQuote(provider, tokenAddress, totalSellAmount, chain);
1129
+ if (estimatedBNBOut <= 0n)
1130
+ return 0n;
1131
+ const profit = calculateProfitAmount(estimatedBNBOut);
1132
+ return profit;
1133
+ }
1134
+ return 0n;
1110
1135
  }
1111
- else if (quoteToken) {
1112
- // 卖出代币 得到 ERC20:先计算 ERC20 利润,再转换为 BNB
1113
- const baseProfitWei = calculateProfitAmount(totalSellAmount);
1114
- if (baseProfitWei <= 0n)
1115
- return 0n;
1116
- return getTokenToNativeQuote(provider, quoteToken, baseProfitWei, chain);
1136
+ catch (error) {
1137
+ console.error(`[V3 Sell Profit] Error:`, error);
1138
+ return 0n;
1117
1139
  }
1118
- return 0n;
1119
1140
  })();
1120
1141
  const routerIface = new ethers.Interface(routerAbi);
1121
1142
  const outputToken = useNativeOutput ? wrappedNative : quoteToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",