pinpet-sdk 2.1.13 → 2.1.15

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.
@@ -41945,7 +41945,7 @@ const MAX_FEE_RATE = 10_000n;
41945
41945
  * Implements constant product (xy=k) algorithm for automated market maker functionality
41946
41946
  * Usage when importing: const CurveAMM = require("../tools/curve_amm");
41947
41947
  */
41948
- class CurveAMM$7 {
41948
+ class CurveAMM$8 {
41949
41949
  /**
41950
41950
  * Initial SOL reserve amount, represented as Decimal
41951
41951
  * @type {Decimal}
@@ -43098,10 +43098,10 @@ class CurveAMM$7 {
43098
43098
  }
43099
43099
  }
43100
43100
 
43101
- var curve_amm = CurveAMM$7;
43101
+ var curve_amm = CurveAMM$8;
43102
43102
 
43103
43103
  const axios = axios_1;
43104
- const CurveAMM$6 = curve_amm;
43104
+ const CurveAMM$7 = curve_amm;
43105
43105
 
43106
43106
  /**
43107
43107
  * Fast API Module
@@ -43593,7 +43593,7 @@ class FastModule$1 {
43593
43593
 
43594
43594
  if (!latestPrice) {
43595
43595
  // If no price data, calculate initial price
43596
- const initialPrice = CurveAMM$6.getInitialPrice();
43596
+ const initialPrice = CurveAMM$7.getInitialPrice();
43597
43597
  if (initialPrice === null) {
43598
43598
  throw new Error('price: 无法计算初始价格 Unable to calculate initial price');
43599
43599
  }
@@ -45058,7 +45058,7 @@ jsonBigint.exports.stringify = json_stringify;
45058
45058
 
45059
45059
  var jsonBigintExports = jsonBigint.exports;
45060
45060
 
45061
- const CurveAMM$5 = curve_amm;
45061
+ const CurveAMM$6 = curve_amm;
45062
45062
  const {transformOrdersData , checkPriceRangeOverlap} = stop_loss_utils;
45063
45063
  const { PRICE_ADJUSTMENT_PERCENTAGE, MIN_STOP_LOSS_PERCENT } = utils$2;
45064
45064
  jsonBigintExports({ storeAsString: false });
@@ -45216,12 +45216,12 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
45216
45216
  let currentPrice;
45217
45217
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
45218
45218
  console.log('Current price is empty, using initial price');
45219
- currentPrice = CurveAMM$5.getInitialPrice();
45219
+ currentPrice = CurveAMM$6.getInitialPrice();
45220
45220
  } else {
45221
45221
  currentPrice = BigInt(lastPrice);
45222
45222
  if (!currentPrice || currentPrice === 0n) {
45223
45223
  console.log('Current price is 0, using initial price');
45224
- currentPrice = CurveAMM$5.getInitialPrice();
45224
+ currentPrice = CurveAMM$6.getInitialPrice();
45225
45225
  }
45226
45226
  }
45227
45227
 
@@ -45266,7 +45266,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
45266
45266
  // console.log(` - buyTokenAmount: ${buyTokenAmount.toString()}`);
45267
45267
  // console.log(` - Calling CurveAMM.sellFromPriceWithTokenInput...`);
45268
45268
 
45269
- const tradeResult = CurveAMM$5.sellFromPriceWithTokenInput(stopLossStartPrice, buyTokenAmount);
45269
+ const tradeResult = CurveAMM$6.sellFromPriceWithTokenInput(stopLossStartPrice, buyTokenAmount);
45270
45270
 
45271
45271
  //console.log(` - tradeResult:`, tradeResult);
45272
45272
 
@@ -45330,12 +45330,12 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
45330
45330
  let estimatedMargin = 0n;
45331
45331
  try {
45332
45332
  // 1. 计算从当前价格买入所需的SOL
45333
- const buyResult = CurveAMM$5.buyFromPriceWithTokenOutput(currentPrice, buyTokenAmount);
45333
+ const buyResult = CurveAMM$6.buyFromPriceWithTokenOutput(currentPrice, buyTokenAmount);
45334
45334
  if (buyResult) {
45335
45335
  const requiredSol = buyResult[1]; // SOL input amount
45336
45336
 
45337
45337
  // 2. 计算平仓时扣除手续费后的收益
45338
- const closeOutputSolAfterFee = CurveAMM$5.calculateAmountAfterFee(finalTradeAmount, borrowFee);
45338
+ const closeOutputSolAfterFee = CurveAMM$6.calculateAmountAfterFee(finalTradeAmount, borrowFee);
45339
45339
 
45340
45340
  // 3. 计算保证金 = 买入成本 - 平仓收益(扣费后)
45341
45341
  if (closeOutputSolAfterFee !== null && requiredSol > closeOutputSolAfterFee) {
@@ -45525,12 +45525,12 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
45525
45525
  let currentPrice;
45526
45526
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
45527
45527
  console.log('Current price is empty, using initial price');
45528
- currentPrice = CurveAMM$5.getInitialPrice();
45528
+ currentPrice = CurveAMM$6.getInitialPrice();
45529
45529
  } else {
45530
45530
  currentPrice = BigInt(lastPrice);
45531
45531
  if (!currentPrice || currentPrice === 0n) {
45532
45532
  console.log('Current price is 0, using initial price');
45533
- currentPrice = CurveAMM$5.getInitialPrice();
45533
+ currentPrice = CurveAMM$6.getInitialPrice();
45534
45534
  }
45535
45535
  }
45536
45536
 
@@ -45573,7 +45573,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
45573
45573
  // console.log(` - sellTokenAmount: ${sellTokenAmount.toString()}`);
45574
45574
  // console.log(` - Calling CurveAMM.buyFromPriceWithTokenOutput...`);
45575
45575
 
45576
- const tradeResult = CurveAMM$5.buyFromPriceWithTokenOutput(stopLossStartPrice, sellTokenAmount);
45576
+ const tradeResult = CurveAMM$6.buyFromPriceWithTokenOutput(stopLossStartPrice, sellTokenAmount);
45577
45577
 
45578
45578
  //console.log(` - tradeResult:`, tradeResult);
45579
45579
 
@@ -45612,8 +45612,8 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
45612
45612
  //console.log(`调整后起始价格: ${stopLossStartPrice} / Adjusted start price: ${stopLossStartPrice}`);
45613
45613
 
45614
45614
  // 安全检查:确保价格不会超过最大值 / Safety check: ensure price doesn't exceed maximum
45615
- if (stopLossStartPrice >= CurveAMM$5.MAX_U128_PRICE) {
45616
- throw new Error(`Stop loss price exceeded maximum after adjustment: ${stopLossStartPrice} >= ${CurveAMM$5.MAX_U128_PRICE}`);
45615
+ if (stopLossStartPrice >= CurveAMM$6.MAX_U128_PRICE) {
45616
+ throw new Error(`Stop loss price exceeded maximum after adjustment: ${stopLossStartPrice} >= ${CurveAMM$6.MAX_U128_PRICE}`);
45617
45617
  }
45618
45618
  }
45619
45619
 
@@ -45636,7 +45636,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
45636
45636
  let estimatedMargin = 0n;
45637
45637
  try {
45638
45638
  // 1. 计算从当前价格卖出代币获得的SOL(开仓收益,不含手续费)
45639
- const sellResult = CurveAMM$5.sellFromPriceWithTokenInput(currentPrice, sellTokenAmount);
45639
+ const sellResult = CurveAMM$6.sellFromPriceWithTokenInput(currentPrice, sellTokenAmount);
45640
45640
  if (sellResult) {
45641
45641
  const openingSolGain = sellResult[1]; // 卖出获得的SOL
45642
45642
 
@@ -45760,17 +45760,17 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
45760
45760
 
45761
45761
  // Calculate current price
45762
45762
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
45763
- currentPrice = CurveAMM$5.getInitialPrice();
45763
+ currentPrice = CurveAMM$6.getInitialPrice();
45764
45764
  } else {
45765
45765
  currentPrice = BigInt(lastPrice);
45766
45766
  if (!currentPrice || currentPrice === 0n) {
45767
- currentPrice = CurveAMM$5.getInitialPrice();
45767
+ currentPrice = CurveAMM$6.getInitialPrice();
45768
45768
  }
45769
45769
  }
45770
45770
 
45771
45771
  // Calculate initial token amount from SOL amount using sellFromPriceWithSolOutput
45772
45772
  // This gives us how many tokens we can get when we later sell for buySolAmount SOL
45773
- const initialResult = CurveAMM$5.sellFromPriceWithSolOutput(currentPrice, buySolAmount);
45773
+ const initialResult = CurveAMM$6.sellFromPriceWithSolOutput(currentPrice, buySolAmount);
45774
45774
  if (!initialResult) {
45775
45775
  throw new Error('Failed to calculate token amount from SOL amount');
45776
45776
  }
@@ -45927,17 +45927,17 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
45927
45927
 
45928
45928
  // Calculate current price
45929
45929
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
45930
- currentPrice = CurveAMM$5.getInitialPrice();
45930
+ currentPrice = CurveAMM$6.getInitialPrice();
45931
45931
  } else {
45932
45932
  currentPrice = BigInt(lastPrice);
45933
45933
  if (!currentPrice || currentPrice === 0n) {
45934
- currentPrice = CurveAMM$5.getInitialPrice();
45934
+ currentPrice = CurveAMM$6.getInitialPrice();
45935
45935
  }
45936
45936
  }
45937
45937
 
45938
45938
  // Calculate initial token amount from SOL amount using buyFromPriceWithSolInput
45939
45939
  // This gives us how many tokens we need to buy later using sellSolAmount SOL
45940
- const initialResult = CurveAMM$5.buyFromPriceWithSolInput(currentPrice, sellSolAmount);
45940
+ const initialResult = CurveAMM$6.buyFromPriceWithSolInput(currentPrice, sellSolAmount);
45941
45941
  if (!initialResult) {
45942
45942
  throw new Error('Failed to calculate token amount from SOL amount');
45943
45943
  }
@@ -46029,7 +46029,7 @@ var long_shrot_stop = {
46029
46029
  simulateShortSolStopLoss: simulateShortSolStopLoss$1
46030
46030
  };
46031
46031
 
46032
- const CurveAMM$4 = curve_amm;
46032
+ const CurveAMM$5 = curve_amm;
46033
46033
 
46034
46034
 
46035
46035
  /**
@@ -46148,7 +46148,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46148
46148
  const priceBigInt = BigInt(price);
46149
46149
  const initialVirtualSolBigInt = BigInt(initialVirtualSol.toString());
46150
46150
  const initialVirtualTokenBigInt = BigInt(initialVirtualToken.toString());
46151
- [, result.ideal_lp_sol_amount] = CurveAMM$4.buyFromPriceWithTokenOutputWithParams(
46151
+ [, result.ideal_lp_sol_amount] = CurveAMM$5.buyFromPriceWithTokenOutputWithParams(
46152
46152
  priceBigInt,
46153
46153
  buyTokenAmountBigInt,
46154
46154
  initialVirtualSolBigInt,
@@ -46162,7 +46162,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46162
46162
 
46163
46163
  // orders 长度为0 时要单独计算
46164
46164
  if (orders.length === 0) {
46165
- [result.free_lp_sol_amount_sum, result.free_lp_token_amount_sum] = CurveAMM$4.buyFromPriceToPrice(BigInt(price), CurveAMM$4.MAX_U128_PRICE);
46165
+ [result.free_lp_sol_amount_sum, result.free_lp_token_amount_sum] = CurveAMM$5.buyFromPriceToPrice(BigInt(price), CurveAMM$5.MAX_U128_PRICE);
46166
46166
  result.has_infinite_lp = true;
46167
46167
  result.real_lp_sol_amount = result.ideal_lp_sol_amount;
46168
46168
  return result
@@ -46210,7 +46210,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46210
46210
  // 如果存在价格间隙,计算自由流动性
46211
46211
  if (endPrice > startPrice) {
46212
46212
  try {
46213
- const gapLiquidity = CurveAMM$4.buyFromPriceToPrice(startPrice, endPrice);
46213
+ const gapLiquidity = CurveAMM$5.buyFromPriceToPrice(startPrice, endPrice);
46214
46214
  if (gapLiquidity && Array.isArray(gapLiquidity) && gapLiquidity.length === 2) {
46215
46215
  const [solAmount, tokenAmount] = gapLiquidity;
46216
46216
 
@@ -46232,7 +46232,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46232
46232
  try {
46233
46233
  const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
46234
46234
  // console.log("actualBuyAmount",actualBuyAmount)
46235
- const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(startPrice, actualBuyAmount);
46235
+ const [, preciseSol] = CurveAMM$5.buyFromPriceWithTokenOutput(startPrice, actualBuyAmount);
46236
46236
  result.real_lp_sol_amount = prev_free_lp_sol_amount_sum + BigInt(preciseSol);
46237
46237
 
46238
46238
  // console.log(`实际计算[${i}]: 自由流动性已足够, actualBuyAmount=${actualBuyAmount}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
@@ -46286,7 +46286,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46286
46286
  // 从当前价格开始计算需要多少SOL来买到精确的token数量
46287
46287
  const targetPrice = i === 0 ? BigInt(price) : BigInt(orders[i - 1].lock_lp_end_price);
46288
46288
  const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(order.lock_lp_token_amount));
46289
- const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(targetPrice, actualBuyAmount);
46289
+ const [, preciseSol] = CurveAMM$5.buyFromPriceWithTokenOutput(targetPrice, actualBuyAmount);
46290
46290
  result.real_lp_sol_amount = prevFreeSolSum + BigInt(preciseSol);
46291
46291
  // console.log(`实际计算[${i}]: 跳过订单后足够, targetPrice=${targetPrice}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
46292
46292
  result.force_close_num = counti;
@@ -46340,7 +46340,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46340
46340
  let lastEndPrice, maxPrice;
46341
46341
  try {
46342
46342
  lastEndPrice = BigInt(lastOrder.lock_lp_end_price);
46343
- maxPrice = CurveAMM$4.MAX_U128_PRICE;
46343
+ maxPrice = CurveAMM$5.MAX_U128_PRICE;
46344
46344
  } catch (error) {
46345
46345
  throw new Error(`价格转换错误:无法转换最后订单价格或最大价格 Price conversion error: Cannot convert last order price or max price - ${error.message}`);
46346
46346
  }
@@ -46348,7 +46348,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46348
46348
 
46349
46349
  if (maxPrice > lastEndPrice) {
46350
46350
  try {
46351
- const infiniteLiquidity = CurveAMM$4.buyFromPriceToPrice(lastEndPrice, maxPrice);
46351
+ const infiniteLiquidity = CurveAMM$5.buyFromPriceToPrice(lastEndPrice, maxPrice);
46352
46352
  if (infiniteLiquidity && Array.isArray(infiniteLiquidity) && infiniteLiquidity.length === 2) {
46353
46353
  const [solAmount, tokenAmount] = infiniteLiquidity;
46354
46354
 
@@ -46367,7 +46367,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
46367
46367
  // 计算最后精确需要买多少token
46368
46368
  try {
46369
46369
  const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
46370
- const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(lastEndPrice, actualBuyAmount);
46370
+ const [, preciseSol] = CurveAMM$5.buyFromPriceWithTokenOutput(lastEndPrice, actualBuyAmount);
46371
46371
  result.real_lp_sol_amount += BigInt(preciseSol);
46372
46372
  result.force_close_num = counti; // 强平订单数量
46373
46373
  } catch (error) {
@@ -46507,7 +46507,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46507
46507
  const priceBigInt = BigInt(price);
46508
46508
  const initialVirtualSolBigInt = BigInt(initialVirtualSol.toString());
46509
46509
  const initialVirtualTokenBigInt = BigInt(initialVirtualToken.toString());
46510
- [, result.ideal_lp_sol_amount] = CurveAMM$4.sellFromPriceWithTokenInputWithParams(
46510
+ [, result.ideal_lp_sol_amount] = CurveAMM$5.sellFromPriceWithTokenInputWithParams(
46511
46511
  priceBigInt,
46512
46512
  sellTokenAmountBigInt,
46513
46513
  initialVirtualSolBigInt,
@@ -46522,9 +46522,9 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46522
46522
  if (orders.length === 0) {
46523
46523
  const initialVirtualSolBigInt = BigInt(initialVirtualSol.toString());
46524
46524
  const initialVirtualTokenBigInt = BigInt(initialVirtualToken.toString());
46525
- const sellResult = CurveAMM$4.sellFromPriceToPriceWithParams(
46525
+ const sellResult = CurveAMM$5.sellFromPriceToPriceWithParams(
46526
46526
  BigInt(price),
46527
- CurveAMM$4.MIN_U128_PRICE,
46527
+ CurveAMM$5.MIN_U128_PRICE,
46528
46528
  initialVirtualSolBigInt,
46529
46529
  initialVirtualTokenBigInt
46530
46530
  );
@@ -46583,7 +46583,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46583
46583
  // 如果存在价格间隙(卖出时startPrice应该大于endPrice)
46584
46584
  if (startPrice > endPrice) {
46585
46585
  try {
46586
- const gapLiquidity = CurveAMM$4.sellFromPriceToPrice(startPrice, endPrice);
46586
+ const gapLiquidity = CurveAMM$5.sellFromPriceToPrice(startPrice, endPrice);
46587
46587
  if (gapLiquidity && Array.isArray(gapLiquidity) && gapLiquidity.length === 2) {
46588
46588
  const [tokenAmount, solAmount] = gapLiquidity;
46589
46589
 
@@ -46603,7 +46603,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46603
46603
  // 计算精确能获得多少SOL
46604
46604
  try {
46605
46605
  const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
46606
- const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(startPrice, actualSellAmount);
46606
+ const [, preciseSol] = CurveAMM$5.sellFromPriceWithTokenInput(startPrice, actualSellAmount);
46607
46607
  result.real_lp_sol_amount = prev_free_lp_sol_amount_sum + preciseSol;
46608
46608
  // console.log(`卖出实际计算[${i}]: 自由流动性已足够, actualSellAmount=${actualSellAmount}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
46609
46609
  result.force_close_num = counti; // 强平订单数量
@@ -46652,7 +46652,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46652
46652
  // 计算精确能获得多少SOL
46653
46653
  const targetPrice = i === 0 ? BigInt(price) : BigInt(orders[i - 1].lock_lp_end_price);
46654
46654
  const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(order.lock_lp_token_amount));
46655
- const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(targetPrice, actualSellAmount);
46655
+ const [, preciseSol] = CurveAMM$5.sellFromPriceWithTokenInput(targetPrice, actualSellAmount);
46656
46656
  result.real_lp_sol_amount = prevFreeSolSum + preciseSol;
46657
46657
  result.force_close_num = counti;
46658
46658
  } catch (error) {
@@ -46702,7 +46702,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46702
46702
  let lastEndPrice, minPrice;
46703
46703
  try {
46704
46704
  lastEndPrice = BigInt(lastOrder.lock_lp_end_price);
46705
- minPrice = CurveAMM$4.MIN_U128_PRICE;
46705
+ minPrice = CurveAMM$5.MIN_U128_PRICE;
46706
46706
  } catch (error) {
46707
46707
  throw new Error(`价格转换错误:无法转换最后订单价格或最小价格 Price conversion error: Cannot convert last order price or min price - ${error.message}`);
46708
46708
  }
@@ -46711,7 +46711,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46711
46711
  if (lastEndPrice > minPrice) {
46712
46712
 
46713
46713
  try {
46714
- const infiniteLiquidity = CurveAMM$4.sellFromPriceToPrice(lastEndPrice, minPrice);
46714
+ const infiniteLiquidity = CurveAMM$5.sellFromPriceToPrice(lastEndPrice, minPrice);
46715
46715
  if (infiniteLiquidity && Array.isArray(infiniteLiquidity) && infiniteLiquidity.length === 2) {
46716
46716
  const [tokenAmount, solAmount] = infiniteLiquidity;
46717
46717
 
@@ -46731,7 +46731,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
46731
46731
  // 无限流动性够卖出需求了
46732
46732
  try {
46733
46733
  const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
46734
- const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(lastEndPrice, actualSellAmount);
46734
+ const [, preciseSol] = CurveAMM$5.sellFromPriceWithTokenInput(lastEndPrice, actualSellAmount);
46735
46735
  result.real_lp_sol_amount = prevFreeSolSum + preciseSol;
46736
46736
  result.force_close_num = counti; // 强平订单数量
46737
46737
  } catch (error) {
@@ -46789,7 +46789,7 @@ const { calcLiqTokenBuy, calcLiqTokenSell } = calcLiq;
46789
46789
  async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
46790
46790
  // 获取价格和订单数据
46791
46791
 
46792
- //console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
46792
+ console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
46793
46793
 
46794
46794
  let price = lastPrice;
46795
46795
  if (!price) {
@@ -46834,17 +46834,20 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
46834
46834
  curveData.initialVirtualToken
46835
46835
  );
46836
46836
 
46837
- // console.log('\n=== calcLiqTokenBuy 返回结果 ===');
46838
- // console.log('自由流动性 SOL 总量:', liqResult.free_lp_sol_amount_sum.toString());
46839
- // console.log('自由流动性 Token 总量:', liqResult.free_lp_token_amount_sum.toString());
46840
- // console.log('锁定流动性 SOL 总量:', liqResult.lock_lp_sol_amount_sum.toString());
46841
- // console.log('锁定流动性 Token 总量:', liqResult.lock_lp_token_amount_sum.toString());
46842
- // console.log('是否包含无限流动性:', liqResult.has_infinite_lp);
46843
- // console.log('跳过的订单索引:', liqResult.pass_order_id);
46844
- // console.log('需要强平的订单数量:', liqResult.force_close_num);
46845
- // console.log('理想 SOL 使用量:', liqResult.ideal_lp_sol_amount.toString());
46846
- // console.log('实际 SOL 使用量:', liqResult.real_lp_sol_amount.toString());
46847
- // console.log('===============================\n');
46837
+ console.log("liqResult:",liqResult);
46838
+
46839
+
46840
+ console.log('\n=== calcLiqTokenBuy 返回结果 ===');
46841
+ console.log('自由流动性 SOL 总量:', liqResult.free_lp_sol_amount_sum.toString());
46842
+ console.log('自由流动性 Token 总量:', liqResult.free_lp_token_amount_sum.toString());
46843
+ console.log('锁定流动性 SOL 总量:', liqResult.lock_lp_sol_amount_sum.toString());
46844
+ console.log('锁定流动性 Token 总量:', liqResult.lock_lp_token_amount_sum.toString());
46845
+ console.log('是否包含无限流动性:', liqResult.has_infinite_lp);
46846
+ console.log('跳过的订单索引:', liqResult.pass_order_id);
46847
+ console.log('需要强平的订单数量:', liqResult.force_close_num);
46848
+ console.log('理想 SOL 使用量:', liqResult.ideal_lp_sol_amount.toString());
46849
+ console.log('实际 SOL 使用量:', liqResult.real_lp_sol_amount.toString());
46850
+ console.log('===============================\n');
46848
46851
 
46849
46852
  // Convert to BigInt for calculations
46850
46853
  const buyTokenAmountBig = BigInt(buyTokenAmount);
@@ -47300,11 +47303,268 @@ var close_indices = {
47300
47303
  simulateShortClose: simulateShortClose$1
47301
47304
  };
47302
47305
 
47306
+ const CurveAMM$4 = curve_amm;
47307
+
47308
+ /**
47309
+ * 计算使用指定SOL数量买入时能获得的Token数量
47310
+ * @param {bigint|string} price - 当前交易价格 (u128格式)
47311
+ * @param {bigint|string|number} buySolAmount - 需要花费的SOL数量 (lamports, 9位精度)
47312
+ * @param {Array} orders - 锁定流动性的订单数组
47313
+ * @param {number} onceMaxOrder - 单次循环最大订单数
47314
+ * @param {string|number|null} passOrderID - 需要跳过的订单ID(与order_id字段比较)
47315
+ * @param {string|number|Decimal|null} initialVirtualSol - 流动池SOL数量
47316
+ * @param {string|number|Decimal|null} initialVirtualToken - 流动池Token数量
47317
+ * @returns {Object} { tokenAmount: bigint, msg: string, closedOrdersCount: number }
47318
+ */
47319
+ function calcLiqSolBuy$1(price, buySolAmount, orders, onceMaxOrder, passOrderID = null, initialVirtualSol = null, initialVirtualToken = null){
47320
+
47321
+ // 1. 参数验证
47322
+ // 转换为 bigint 以便比较
47323
+ let priceBigInt;
47324
+ let buySolAmountBigInt;
47325
+
47326
+ try {
47327
+ priceBigInt = typeof price === 'bigint' ? price : BigInt(price);
47328
+ buySolAmountBigInt = typeof buySolAmount === 'bigint' ? buySolAmount : BigInt(buySolAmount);
47329
+ } catch (error) {
47330
+ return {
47331
+ tokenAmount: 0n,
47332
+ msg: '参数格式错误:无法转换为bigint',
47333
+ closedOrdersCount: 0
47334
+ };
47335
+ }
47336
+
47337
+ // 检查价格和金额是否有效
47338
+ if (priceBigInt <= 0n) {
47339
+ return {
47340
+ tokenAmount: 0n,
47341
+ msg: '计算失败:价格必须大于0',
47342
+ closedOrdersCount: 0
47343
+ };
47344
+ }
47345
+
47346
+ if (buySolAmountBigInt <= 0n) {
47347
+ return {
47348
+ tokenAmount: 0n,
47349
+ msg: '计算失败:买入金额必须大于0',
47350
+ closedOrdersCount: 0
47351
+ };
47352
+ }
47353
+
47354
+ // 2. 设置默认流动池参数
47355
+ const virtualSol = initialVirtualSol !== null ? initialVirtualSol : CurveAMM$4.INITIAL_SOL_RESERVE_DECIMAL;
47356
+ const virtualToken = initialVirtualToken !== null ? initialVirtualToken : CurveAMM$4.INITIAL_TOKEN_RESERVE_DECIMAL;
47357
+
47358
+ // 3. 处理空订单情况(第一阶段)
47359
+ if (!orders || orders.length === 0) {
47360
+ // 直接计算完整流动性下的买入
47361
+ const result = CurveAMM$4.buyFromPriceWithSolInputWithParams(
47362
+ price,
47363
+ buySolAmount,
47364
+ virtualSol,
47365
+ virtualToken
47366
+ );
47367
+
47368
+ if (result === null) {
47369
+ return {
47370
+ tokenAmount: 0n,
47371
+ msg: '计算失败:价格或参数无效',
47372
+ closedOrdersCount: 0
47373
+ };
47374
+ }
47375
+
47376
+ const [endPrice, tokenAmount] = result;
47377
+ return {
47378
+ tokenAmount: tokenAmount,
47379
+ msg: '流动性完整,无锁定订单',
47380
+ closedOrdersCount: 0
47381
+ };
47382
+ }
47383
+
47384
+ // 4. 处理有订单的情况(第二阶段:分段流动性计算)
47385
+
47386
+ // 初始化变量
47387
+ let currentPrice = priceBigInt; // 当前价格指针
47388
+ let remainingSol = buySolAmountBigInt; // 剩余可用 SOL
47389
+ let totalTokenAmount = 0n; // 累计获得的 token
47390
+ let closedOrdersCount = 0; // 平仓订单数量
47391
+ let processedOrders = 0; // 已处理订单数
47392
+
47393
+ // 检查当前价格是否高于第一个订单的结束价格
47394
+ if (orders.length > 0) {
47395
+ const firstOrderEndPrice = typeof orders[0].lock_lp_end_price === 'bigint'
47396
+ ? orders[0].lock_lp_end_price
47397
+ : BigInt(orders[0].lock_lp_end_price);
47398
+
47399
+ if (currentPrice >= firstOrderEndPrice) {
47400
+ return {
47401
+ tokenAmount: 0n,
47402
+ msg: '错误:当前价格已高于第一个订单的结束价格',
47403
+ closedOrdersCount: 0
47404
+ };
47405
+ }
47406
+ }
47407
+
47408
+ // 遍历订单(最多 onceMaxOrder 个)
47409
+ for (let i = 0; i < orders.length && processedOrders < onceMaxOrder; i++) {
47410
+ const order = orders[i];
47411
+
47412
+ // 检查是否需要跳过此订单
47413
+ if (passOrderID !== null && order.order_id !== undefined) {
47414
+ // 将两者都转换为字符串进行比较
47415
+ const orderIdStr = String(order.order_id);
47416
+ const passOrderIdStr = String(passOrderID);
47417
+
47418
+ if (orderIdStr === passOrderIdStr) {
47419
+ // 跳过此订单,不处理其锁定区间,继续下一个订单
47420
+ continue;
47421
+ }
47422
+ }
47423
+
47424
+ // 转换订单价格为 bigint
47425
+ let lockStartPrice, lockEndPrice;
47426
+ try {
47427
+ lockStartPrice = typeof order.lock_lp_start_price === 'bigint'
47428
+ ? order.lock_lp_start_price
47429
+ : BigInt(order.lock_lp_start_price);
47430
+ lockEndPrice = typeof order.lock_lp_end_price === 'bigint'
47431
+ ? order.lock_lp_end_price
47432
+ : BigInt(order.lock_lp_end_price);
47433
+ } catch (error) {
47434
+ return {
47435
+ tokenAmount: 0n,
47436
+ msg: `错误:订单${i}的价格格式无效`,
47437
+ closedOrdersCount: closedOrdersCount
47438
+ };
47439
+ }
47440
+
47441
+ // 步骤1:计算可用区间(currentPrice → lockStartPrice)
47442
+ if (currentPrice < lockStartPrice) {
47443
+ // 1.1 计算这段区间需要多少 SOL 和能获得多少 token
47444
+ const result = CurveAMM$4.buyFromPriceToPriceWithParams(
47445
+ currentPrice,
47446
+ lockStartPrice,
47447
+ virtualSol,
47448
+ virtualToken
47449
+ );
47450
+
47451
+ // 检查计算是否成功
47452
+ if (result === null) {
47453
+ return {
47454
+ tokenAmount: 0n,
47455
+ msg: `错误:计算价格区间失败(订单${i})`,
47456
+ closedOrdersCount: closedOrdersCount
47457
+ };
47458
+ }
47459
+
47460
+ const [solNeeded, tokenGained] = result;
47461
+
47462
+ // 1.2 判断剩余 SOL 是否足够
47463
+ if (remainingSol >= solNeeded) {
47464
+ // 足够:买完这段区间,继续下一段
47465
+ remainingSol -= solNeeded;
47466
+ totalTokenAmount += tokenGained;
47467
+ currentPrice = lockStartPrice;
47468
+ } else {
47469
+ // 不够:用完剩余 SOL,计算能买多少,然后返回
47470
+ const finalResult = CurveAMM$4.buyFromPriceWithSolInputWithParams(
47471
+ currentPrice,
47472
+ remainingSol,
47473
+ virtualSol,
47474
+ virtualToken
47475
+ );
47476
+
47477
+ if (finalResult === null) {
47478
+ return {
47479
+ tokenAmount: 0n,
47480
+ msg: '错误:计算最终买入失败',
47481
+ closedOrdersCount: closedOrdersCount
47482
+ };
47483
+ }
47484
+
47485
+ const [finalPrice, finalTokenGained] = finalResult;
47486
+ totalTokenAmount += finalTokenGained;
47487
+
47488
+ return {
47489
+ tokenAmount: totalTokenAmount,
47490
+ msg: `SOL用完,最终价格: ${finalPrice.toString()}`,
47491
+ closedOrdersCount: closedOrdersCount
47492
+ };
47493
+ }
47494
+ }
47495
+
47496
+ // 步骤2:跳过锁定区间(lockStartPrice → lockEndPrice)
47497
+ currentPrice = lockEndPrice;
47498
+ processedOrders++;
47499
+
47500
+ // 步骤3:判断是否平仓
47501
+ // 如果价格到达 lockEndPrice,说明这个订单被平仓
47502
+ closedOrdersCount++;
47503
+
47504
+ // 检查 SOL 是否已用完
47505
+ if (remainingSol === 0n) {
47506
+ return {
47507
+ tokenAmount: totalTokenAmount,
47508
+ msg: `SOL刚好用完,最终价格: ${currentPrice.toString()}`,
47509
+ closedOrdersCount: closedOrdersCount
47510
+ };
47511
+ }
47512
+ }
47513
+
47514
+ // 步骤4:处理最后的无限流动性区间
47515
+ // 所有订单处理完后,用剩余 SOL 继续买入
47516
+ if (remainingSol > 0n) {
47517
+ const finalResult = CurveAMM$4.buyFromPriceWithSolInputWithParams(
47518
+ currentPrice,
47519
+ remainingSol,
47520
+ virtualSol,
47521
+ virtualToken
47522
+ );
47523
+
47524
+ if (finalResult === null) {
47525
+ return {
47526
+ tokenAmount: 0n,
47527
+ msg: '错误:计算无限流动性区间失败',
47528
+ closedOrdersCount: closedOrdersCount
47529
+ };
47530
+ }
47531
+
47532
+ const [finalPrice, finalTokenGained] = finalResult;
47533
+ totalTokenAmount += finalTokenGained;
47534
+
47535
+ return {
47536
+ tokenAmount: totalTokenAmount,
47537
+ msg: `买入完成,最终价格: ${finalPrice.toString()}`,
47538
+ closedOrdersCount: closedOrdersCount
47539
+ };
47540
+ }
47541
+
47542
+ // 步骤5:SOL 刚好用完
47543
+ return {
47544
+ tokenAmount: totalTokenAmount,
47545
+ msg: `SOL刚好用完,最终价格: ${currentPrice.toString()}`,
47546
+ closedOrdersCount: closedOrdersCount
47547
+ };
47548
+
47549
+ }
47550
+
47551
+
47552
+ function calcLiqSolSell$1(price, sellSolAmount, orders, onceMaxOrder, passOrder = null, initialVirtualSol = null, initialVirtualToken = null) {
47553
+
47554
+
47555
+ }
47556
+
47557
+
47558
+ var calc_sol_liq = {
47559
+ calcLiqSolBuy: calcLiqSolBuy$1,
47560
+ calcLiqSolSell: calcLiqSolSell$1
47561
+ };
47562
+
47303
47563
  const CurveAMM$3 = curve_amm;
47304
47564
  const { simulateLongStopLoss, simulateShortStopLoss, simulateLongSolStopLoss, simulateShortSolStopLoss } = long_shrot_stop;
47305
47565
  const { simulateTokenBuy, simulateTokenSell } = buy_sell_token;
47306
47566
  const { simulateLongClose, simulateShortClose } = close_indices;
47307
-
47567
+ const {calcLiqSolBuy,calcLiqSolSell } = calc_sol_liq;
47308
47568
 
47309
47569
 
47310
47570
 
@@ -47510,6 +47770,12 @@ class SimulatorModule$1 {
47510
47770
  const priceResult = await this.sdk.data.price(mint);
47511
47771
  const ordersResult = await this.sdk.data.orders(mint, { type: 'down_orders' });
47512
47772
 
47773
+ console.log("ordersResult:",ordersResult);
47774
+
47775
+ const upOrdersResult = await this.sdk.data.orders(mint, { type: 'up_orders' });
47776
+ console.log("upOrdersResult:",upOrdersResult);
47777
+ console.log("upOrdersResult:",upOrdersResult.data.orders);
47778
+
47513
47779
  if (!priceResult || !ordersResult) {
47514
47780
  return {
47515
47781
  success: false,
@@ -47529,6 +47795,15 @@ class SimulatorModule$1 {
47529
47795
  const solInDecimal = Number(solAmountBigInt) / 1e9; // Convert lamports to SOL
47530
47796
  const estimatedTokenAmount = BigInt(Math.floor((solInDecimal / priceDecimal) * 1e9)); // Convert to token lamports (9-digit precision)
47531
47797
 
47798
+ // Get curve account data for initialVirtualSol and initialVirtualToken
47799
+ const curveAccount = await this.sdk.chain.getCurveAccount(mint);
47800
+ const initialVirtualSol = curveAccount.initialVirtualSol;
47801
+ const initialVirtualToken = curveAccount.initialVirtualToken;
47802
+
47803
+ const reSolBuy = calcLiqSolBuy(currentPrice, buySolAmount, upOrdersResult.data.orders, 50, null, initialVirtualSol, initialVirtualToken);
47804
+
47805
+
47806
+
47532
47807
  // Call simulateTokenBuy with estimated amount
47533
47808
  const tokenBuyResult = await this.simulateTokenBuy(mint, estimatedTokenAmount, null, priceResult, ordersResult);
47534
47809
 
@@ -49351,7 +49626,7 @@ class OrderUtils$2 {
49351
49626
 
49352
49627
  var orderUtils = OrderUtils$2;
49353
49628
 
49354
- var address = "AGpTikur4Sxf9xutmJrwVmyKWYQEsqzoiiEm2mvr82cp";
49629
+ var address = "F2FzigE1Z374iDvreiM6hZQe6oGXgomJfv8PyybvUXye";
49355
49630
  var metadata = {
49356
49631
  name: "pinpet",
49357
49632
  version: "0.1.0",
@@ -51836,7 +52111,7 @@ var errors = [
51836
52111
  {
51837
52112
  code: 6003,
51838
52113
  name: "SellCalculationOverflow",
51839
- msg: "Sell trade calculation overflow"
52114
+ msg: "Sell trade calculation overflow"
51840
52115
  },
51841
52116
  {
51842
52117
  code: 6004,
@@ -53156,7 +53431,7 @@ class PinPetSdk$1 {
53156
53431
  this.pinPetFastApiUrl = this.options.pinPetFastApiUrl;
53157
53432
 
53158
53433
  // Maximum number of orders that can be processed at once in the contract
53159
- this.MAX_ORDERS_COUNT = 9;
53434
+ this.MAX_ORDERS_COUNT = 50;
53160
53435
  // Maximum number of orders to fetch during queries
53161
53436
  this.FIND_MAX_ORDERS_COUNT = 1000;
53162
53437
 
@@ -53320,13 +53595,13 @@ const DEFAULT_NETWORKS = {
53320
53595
  LOCALNET: {
53321
53596
  name: 'localnet',
53322
53597
  defaultDataSource: 'fast', // 'fast' or 'chain'
53323
- // solanaEndpoint: 'http://127.0.0.1:8899',
53324
- // pinPetFastApiUrl: 'http://127.0.0.1:3000',
53325
- solanaEndpoint: 'http://162.250.124.66:8899',
53326
- pinPetFastApiUrl: 'http://162.250.124.66:3000',
53598
+ solanaEndpoint: 'http://127.0.0.1:8899',
53599
+ pinPetFastApiUrl: 'http://127.0.0.1:3000',
53600
+ // solanaEndpoint: 'http://162.250.124.66:8899',
53601
+ // pinPetFastApiUrl: 'http://162.250.124.66:3000',
53327
53602
  feeRecipient: 'GesAj2dTn2wdNcxj4x8qsqS9aNRVPBPkE76aaqg7skxu',
53328
53603
  baseFeeRecipient: '5YHi1HsxobLiTD6NQfHJQpoPoRjMuNyXp4RroTvR6dKi',
53329
- paramsAccount: 'BvChe3C88ezFvcSutX5TsTUnUdToHAHqwfSQ85cmNq1A'
53604
+ paramsAccount: '8tn4XdqWAAh97WwfLrDrwnagRsQp7Nu5nrUmXVBJvgMU'
53330
53605
  }
53331
53606
  };
53332
53607