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.
@@ -30587,7 +30587,7 @@ const MAX_FEE_RATE = 10_000n;
30587
30587
  * Implements constant product (xy=k) algorithm for automated market maker functionality
30588
30588
  * Usage when importing: const CurveAMM = require("../tools/curve_amm");
30589
30589
  */
30590
- class CurveAMM$7 {
30590
+ class CurveAMM$8 {
30591
30591
  /**
30592
30592
  * Initial SOL reserve amount, represented as Decimal
30593
30593
  * @type {Decimal}
@@ -31740,10 +31740,10 @@ class CurveAMM$7 {
31740
31740
  }
31741
31741
  }
31742
31742
 
31743
- var curve_amm = CurveAMM$7;
31743
+ var curve_amm = CurveAMM$8;
31744
31744
 
31745
31745
  const axios = axios_1;
31746
- const CurveAMM$6 = curve_amm;
31746
+ const CurveAMM$7 = curve_amm;
31747
31747
 
31748
31748
  /**
31749
31749
  * Fast API Module
@@ -32235,7 +32235,7 @@ class FastModule$1 {
32235
32235
 
32236
32236
  if (!latestPrice) {
32237
32237
  // If no price data, calculate initial price
32238
- const initialPrice = CurveAMM$6.getInitialPrice();
32238
+ const initialPrice = CurveAMM$7.getInitialPrice();
32239
32239
  if (initialPrice === null) {
32240
32240
  throw new Error('price: 无法计算初始价格 Unable to calculate initial price');
32241
32241
  }
@@ -33700,7 +33700,7 @@ jsonBigint.exports.stringify = json_stringify;
33700
33700
 
33701
33701
  var jsonBigintExports = jsonBigint.exports;
33702
33702
 
33703
- const CurveAMM$5 = curve_amm;
33703
+ const CurveAMM$6 = curve_amm;
33704
33704
  const {transformOrdersData , checkPriceRangeOverlap} = stop_loss_utils;
33705
33705
  const { PRICE_ADJUSTMENT_PERCENTAGE, MIN_STOP_LOSS_PERCENT } = utils$2;
33706
33706
  jsonBigintExports({ storeAsString: false });
@@ -33858,12 +33858,12 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
33858
33858
  let currentPrice;
33859
33859
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
33860
33860
  console.log('Current price is empty, using initial price');
33861
- currentPrice = CurveAMM$5.getInitialPrice();
33861
+ currentPrice = CurveAMM$6.getInitialPrice();
33862
33862
  } else {
33863
33863
  currentPrice = BigInt(lastPrice);
33864
33864
  if (!currentPrice || currentPrice === 0n) {
33865
33865
  console.log('Current price is 0, using initial price');
33866
- currentPrice = CurveAMM$5.getInitialPrice();
33866
+ currentPrice = CurveAMM$6.getInitialPrice();
33867
33867
  }
33868
33868
  }
33869
33869
 
@@ -33908,7 +33908,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
33908
33908
  // console.log(` - buyTokenAmount: ${buyTokenAmount.toString()}`);
33909
33909
  // console.log(` - Calling CurveAMM.sellFromPriceWithTokenInput...`);
33910
33910
 
33911
- const tradeResult = CurveAMM$5.sellFromPriceWithTokenInput(stopLossStartPrice, buyTokenAmount);
33911
+ const tradeResult = CurveAMM$6.sellFromPriceWithTokenInput(stopLossStartPrice, buyTokenAmount);
33912
33912
 
33913
33913
  //console.log(` - tradeResult:`, tradeResult);
33914
33914
 
@@ -33972,12 +33972,12 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
33972
33972
  let estimatedMargin = 0n;
33973
33973
  try {
33974
33974
  // 1. 计算从当前价格买入所需的SOL
33975
- const buyResult = CurveAMM$5.buyFromPriceWithTokenOutput(currentPrice, buyTokenAmount);
33975
+ const buyResult = CurveAMM$6.buyFromPriceWithTokenOutput(currentPrice, buyTokenAmount);
33976
33976
  if (buyResult) {
33977
33977
  const requiredSol = buyResult[1]; // SOL input amount
33978
33978
 
33979
33979
  // 2. 计算平仓时扣除手续费后的收益
33980
- const closeOutputSolAfterFee = CurveAMM$5.calculateAmountAfterFee(finalTradeAmount, borrowFee);
33980
+ const closeOutputSolAfterFee = CurveAMM$6.calculateAmountAfterFee(finalTradeAmount, borrowFee);
33981
33981
 
33982
33982
  // 3. 计算保证金 = 买入成本 - 平仓收益(扣费后)
33983
33983
  if (closeOutputSolAfterFee !== null && requiredSol > closeOutputSolAfterFee) {
@@ -34167,12 +34167,12 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
34167
34167
  let currentPrice;
34168
34168
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
34169
34169
  console.log('Current price is empty, using initial price');
34170
- currentPrice = CurveAMM$5.getInitialPrice();
34170
+ currentPrice = CurveAMM$6.getInitialPrice();
34171
34171
  } else {
34172
34172
  currentPrice = BigInt(lastPrice);
34173
34173
  if (!currentPrice || currentPrice === 0n) {
34174
34174
  console.log('Current price is 0, using initial price');
34175
- currentPrice = CurveAMM$5.getInitialPrice();
34175
+ currentPrice = CurveAMM$6.getInitialPrice();
34176
34176
  }
34177
34177
  }
34178
34178
 
@@ -34215,7 +34215,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
34215
34215
  // console.log(` - sellTokenAmount: ${sellTokenAmount.toString()}`);
34216
34216
  // console.log(` - Calling CurveAMM.buyFromPriceWithTokenOutput...`);
34217
34217
 
34218
- const tradeResult = CurveAMM$5.buyFromPriceWithTokenOutput(stopLossStartPrice, sellTokenAmount);
34218
+ const tradeResult = CurveAMM$6.buyFromPriceWithTokenOutput(stopLossStartPrice, sellTokenAmount);
34219
34219
 
34220
34220
  //console.log(` - tradeResult:`, tradeResult);
34221
34221
 
@@ -34254,8 +34254,8 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
34254
34254
  //console.log(`调整后起始价格: ${stopLossStartPrice} / Adjusted start price: ${stopLossStartPrice}`);
34255
34255
 
34256
34256
  // 安全检查:确保价格不会超过最大值 / Safety check: ensure price doesn't exceed maximum
34257
- if (stopLossStartPrice >= CurveAMM$5.MAX_U128_PRICE) {
34258
- throw new Error(`Stop loss price exceeded maximum after adjustment: ${stopLossStartPrice} >= ${CurveAMM$5.MAX_U128_PRICE}`);
34257
+ if (stopLossStartPrice >= CurveAMM$6.MAX_U128_PRICE) {
34258
+ throw new Error(`Stop loss price exceeded maximum after adjustment: ${stopLossStartPrice} >= ${CurveAMM$6.MAX_U128_PRICE}`);
34259
34259
  }
34260
34260
  }
34261
34261
 
@@ -34278,7 +34278,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
34278
34278
  let estimatedMargin = 0n;
34279
34279
  try {
34280
34280
  // 1. 计算从当前价格卖出代币获得的SOL(开仓收益,不含手续费)
34281
- const sellResult = CurveAMM$5.sellFromPriceWithTokenInput(currentPrice, sellTokenAmount);
34281
+ const sellResult = CurveAMM$6.sellFromPriceWithTokenInput(currentPrice, sellTokenAmount);
34282
34282
  if (sellResult) {
34283
34283
  const openingSolGain = sellResult[1]; // 卖出获得的SOL
34284
34284
 
@@ -34402,17 +34402,17 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
34402
34402
 
34403
34403
  // Calculate current price
34404
34404
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
34405
- currentPrice = CurveAMM$5.getInitialPrice();
34405
+ currentPrice = CurveAMM$6.getInitialPrice();
34406
34406
  } else {
34407
34407
  currentPrice = BigInt(lastPrice);
34408
34408
  if (!currentPrice || currentPrice === 0n) {
34409
- currentPrice = CurveAMM$5.getInitialPrice();
34409
+ currentPrice = CurveAMM$6.getInitialPrice();
34410
34410
  }
34411
34411
  }
34412
34412
 
34413
34413
  // Calculate initial token amount from SOL amount using sellFromPriceWithSolOutput
34414
34414
  // This gives us how many tokens we can get when we later sell for buySolAmount SOL
34415
- const initialResult = CurveAMM$5.sellFromPriceWithSolOutput(currentPrice, buySolAmount);
34415
+ const initialResult = CurveAMM$6.sellFromPriceWithSolOutput(currentPrice, buySolAmount);
34416
34416
  if (!initialResult) {
34417
34417
  throw new Error('Failed to calculate token amount from SOL amount');
34418
34418
  }
@@ -34569,17 +34569,17 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
34569
34569
 
34570
34570
  // Calculate current price
34571
34571
  if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
34572
- currentPrice = CurveAMM$5.getInitialPrice();
34572
+ currentPrice = CurveAMM$6.getInitialPrice();
34573
34573
  } else {
34574
34574
  currentPrice = BigInt(lastPrice);
34575
34575
  if (!currentPrice || currentPrice === 0n) {
34576
- currentPrice = CurveAMM$5.getInitialPrice();
34576
+ currentPrice = CurveAMM$6.getInitialPrice();
34577
34577
  }
34578
34578
  }
34579
34579
 
34580
34580
  // Calculate initial token amount from SOL amount using buyFromPriceWithSolInput
34581
34581
  // This gives us how many tokens we need to buy later using sellSolAmount SOL
34582
- const initialResult = CurveAMM$5.buyFromPriceWithSolInput(currentPrice, sellSolAmount);
34582
+ const initialResult = CurveAMM$6.buyFromPriceWithSolInput(currentPrice, sellSolAmount);
34583
34583
  if (!initialResult) {
34584
34584
  throw new Error('Failed to calculate token amount from SOL amount');
34585
34585
  }
@@ -34671,7 +34671,7 @@ var long_shrot_stop = {
34671
34671
  simulateShortSolStopLoss: simulateShortSolStopLoss$1
34672
34672
  };
34673
34673
 
34674
- const CurveAMM$4 = curve_amm;
34674
+ const CurveAMM$5 = curve_amm;
34675
34675
 
34676
34676
 
34677
34677
  /**
@@ -34790,7 +34790,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34790
34790
  const priceBigInt = BigInt(price);
34791
34791
  const initialVirtualSolBigInt = BigInt(initialVirtualSol.toString());
34792
34792
  const initialVirtualTokenBigInt = BigInt(initialVirtualToken.toString());
34793
- [, result.ideal_lp_sol_amount] = CurveAMM$4.buyFromPriceWithTokenOutputWithParams(
34793
+ [, result.ideal_lp_sol_amount] = CurveAMM$5.buyFromPriceWithTokenOutputWithParams(
34794
34794
  priceBigInt,
34795
34795
  buyTokenAmountBigInt,
34796
34796
  initialVirtualSolBigInt,
@@ -34804,7 +34804,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34804
34804
 
34805
34805
  // orders 长度为0 时要单独计算
34806
34806
  if (orders.length === 0) {
34807
- [result.free_lp_sol_amount_sum, result.free_lp_token_amount_sum] = CurveAMM$4.buyFromPriceToPrice(BigInt(price), CurveAMM$4.MAX_U128_PRICE);
34807
+ [result.free_lp_sol_amount_sum, result.free_lp_token_amount_sum] = CurveAMM$5.buyFromPriceToPrice(BigInt(price), CurveAMM$5.MAX_U128_PRICE);
34808
34808
  result.has_infinite_lp = true;
34809
34809
  result.real_lp_sol_amount = result.ideal_lp_sol_amount;
34810
34810
  return result
@@ -34852,7 +34852,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34852
34852
  // 如果存在价格间隙,计算自由流动性
34853
34853
  if (endPrice > startPrice) {
34854
34854
  try {
34855
- const gapLiquidity = CurveAMM$4.buyFromPriceToPrice(startPrice, endPrice);
34855
+ const gapLiquidity = CurveAMM$5.buyFromPriceToPrice(startPrice, endPrice);
34856
34856
  if (gapLiquidity && Array.isArray(gapLiquidity) && gapLiquidity.length === 2) {
34857
34857
  const [solAmount, tokenAmount] = gapLiquidity;
34858
34858
 
@@ -34874,7 +34874,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34874
34874
  try {
34875
34875
  const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
34876
34876
  // console.log("actualBuyAmount",actualBuyAmount)
34877
- const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(startPrice, actualBuyAmount);
34877
+ const [, preciseSol] = CurveAMM$5.buyFromPriceWithTokenOutput(startPrice, actualBuyAmount);
34878
34878
  result.real_lp_sol_amount = prev_free_lp_sol_amount_sum + BigInt(preciseSol);
34879
34879
 
34880
34880
  // console.log(`实际计算[${i}]: 自由流动性已足够, actualBuyAmount=${actualBuyAmount}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
@@ -34928,7 +34928,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34928
34928
  // 从当前价格开始计算需要多少SOL来买到精确的token数量
34929
34929
  const targetPrice = i === 0 ? BigInt(price) : BigInt(orders[i - 1].lock_lp_end_price);
34930
34930
  const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(order.lock_lp_token_amount));
34931
- const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(targetPrice, actualBuyAmount);
34931
+ const [, preciseSol] = CurveAMM$5.buyFromPriceWithTokenOutput(targetPrice, actualBuyAmount);
34932
34932
  result.real_lp_sol_amount = prevFreeSolSum + BigInt(preciseSol);
34933
34933
  // console.log(`实际计算[${i}]: 跳过订单后足够, targetPrice=${targetPrice}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
34934
34934
  result.force_close_num = counti;
@@ -34982,7 +34982,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34982
34982
  let lastEndPrice, maxPrice;
34983
34983
  try {
34984
34984
  lastEndPrice = BigInt(lastOrder.lock_lp_end_price);
34985
- maxPrice = CurveAMM$4.MAX_U128_PRICE;
34985
+ maxPrice = CurveAMM$5.MAX_U128_PRICE;
34986
34986
  } catch (error) {
34987
34987
  throw new Error(`价格转换错误:无法转换最后订单价格或最大价格 Price conversion error: Cannot convert last order price or max price - ${error.message}`);
34988
34988
  }
@@ -34990,7 +34990,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
34990
34990
 
34991
34991
  if (maxPrice > lastEndPrice) {
34992
34992
  try {
34993
- const infiniteLiquidity = CurveAMM$4.buyFromPriceToPrice(lastEndPrice, maxPrice);
34993
+ const infiniteLiquidity = CurveAMM$5.buyFromPriceToPrice(lastEndPrice, maxPrice);
34994
34994
  if (infiniteLiquidity && Array.isArray(infiniteLiquidity) && infiniteLiquidity.length === 2) {
34995
34995
  const [solAmount, tokenAmount] = infiniteLiquidity;
34996
34996
 
@@ -35009,7 +35009,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
35009
35009
  // 计算最后精确需要买多少token
35010
35010
  try {
35011
35011
  const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
35012
- const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(lastEndPrice, actualBuyAmount);
35012
+ const [, preciseSol] = CurveAMM$5.buyFromPriceWithTokenOutput(lastEndPrice, actualBuyAmount);
35013
35013
  result.real_lp_sol_amount += BigInt(preciseSol);
35014
35014
  result.force_close_num = counti; // 强平订单数量
35015
35015
  } catch (error) {
@@ -35149,7 +35149,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35149
35149
  const priceBigInt = BigInt(price);
35150
35150
  const initialVirtualSolBigInt = BigInt(initialVirtualSol.toString());
35151
35151
  const initialVirtualTokenBigInt = BigInt(initialVirtualToken.toString());
35152
- [, result.ideal_lp_sol_amount] = CurveAMM$4.sellFromPriceWithTokenInputWithParams(
35152
+ [, result.ideal_lp_sol_amount] = CurveAMM$5.sellFromPriceWithTokenInputWithParams(
35153
35153
  priceBigInt,
35154
35154
  sellTokenAmountBigInt,
35155
35155
  initialVirtualSolBigInt,
@@ -35164,9 +35164,9 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35164
35164
  if (orders.length === 0) {
35165
35165
  const initialVirtualSolBigInt = BigInt(initialVirtualSol.toString());
35166
35166
  const initialVirtualTokenBigInt = BigInt(initialVirtualToken.toString());
35167
- const sellResult = CurveAMM$4.sellFromPriceToPriceWithParams(
35167
+ const sellResult = CurveAMM$5.sellFromPriceToPriceWithParams(
35168
35168
  BigInt(price),
35169
- CurveAMM$4.MIN_U128_PRICE,
35169
+ CurveAMM$5.MIN_U128_PRICE,
35170
35170
  initialVirtualSolBigInt,
35171
35171
  initialVirtualTokenBigInt
35172
35172
  );
@@ -35225,7 +35225,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35225
35225
  // 如果存在价格间隙(卖出时startPrice应该大于endPrice)
35226
35226
  if (startPrice > endPrice) {
35227
35227
  try {
35228
- const gapLiquidity = CurveAMM$4.sellFromPriceToPrice(startPrice, endPrice);
35228
+ const gapLiquidity = CurveAMM$5.sellFromPriceToPrice(startPrice, endPrice);
35229
35229
  if (gapLiquidity && Array.isArray(gapLiquidity) && gapLiquidity.length === 2) {
35230
35230
  const [tokenAmount, solAmount] = gapLiquidity;
35231
35231
 
@@ -35245,7 +35245,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35245
35245
  // 计算精确能获得多少SOL
35246
35246
  try {
35247
35247
  const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
35248
- const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(startPrice, actualSellAmount);
35248
+ const [, preciseSol] = CurveAMM$5.sellFromPriceWithTokenInput(startPrice, actualSellAmount);
35249
35249
  result.real_lp_sol_amount = prev_free_lp_sol_amount_sum + preciseSol;
35250
35250
  // console.log(`卖出实际计算[${i}]: 自由流动性已足够, actualSellAmount=${actualSellAmount}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
35251
35251
  result.force_close_num = counti; // 强平订单数量
@@ -35294,7 +35294,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35294
35294
  // 计算精确能获得多少SOL
35295
35295
  const targetPrice = i === 0 ? BigInt(price) : BigInt(orders[i - 1].lock_lp_end_price);
35296
35296
  const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(order.lock_lp_token_amount));
35297
- const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(targetPrice, actualSellAmount);
35297
+ const [, preciseSol] = CurveAMM$5.sellFromPriceWithTokenInput(targetPrice, actualSellAmount);
35298
35298
  result.real_lp_sol_amount = prevFreeSolSum + preciseSol;
35299
35299
  result.force_close_num = counti;
35300
35300
  } catch (error) {
@@ -35344,7 +35344,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35344
35344
  let lastEndPrice, minPrice;
35345
35345
  try {
35346
35346
  lastEndPrice = BigInt(lastOrder.lock_lp_end_price);
35347
- minPrice = CurveAMM$4.MIN_U128_PRICE;
35347
+ minPrice = CurveAMM$5.MIN_U128_PRICE;
35348
35348
  } catch (error) {
35349
35349
  throw new Error(`价格转换错误:无法转换最后订单价格或最小价格 Price conversion error: Cannot convert last order price or min price - ${error.message}`);
35350
35350
  }
@@ -35353,7 +35353,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35353
35353
  if (lastEndPrice > minPrice) {
35354
35354
 
35355
35355
  try {
35356
- const infiniteLiquidity = CurveAMM$4.sellFromPriceToPrice(lastEndPrice, minPrice);
35356
+ const infiniteLiquidity = CurveAMM$5.sellFromPriceToPrice(lastEndPrice, minPrice);
35357
35357
  if (infiniteLiquidity && Array.isArray(infiniteLiquidity) && infiniteLiquidity.length === 2) {
35358
35358
  const [tokenAmount, solAmount] = infiniteLiquidity;
35359
35359
 
@@ -35373,7 +35373,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
35373
35373
  // 无限流动性够卖出需求了
35374
35374
  try {
35375
35375
  const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
35376
- const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(lastEndPrice, actualSellAmount);
35376
+ const [, preciseSol] = CurveAMM$5.sellFromPriceWithTokenInput(lastEndPrice, actualSellAmount);
35377
35377
  result.real_lp_sol_amount = prevFreeSolSum + preciseSol;
35378
35378
  result.force_close_num = counti; // 强平订单数量
35379
35379
  } catch (error) {
@@ -35431,7 +35431,7 @@ const { calcLiqTokenBuy, calcLiqTokenSell } = calcLiq;
35431
35431
  async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
35432
35432
  // 获取价格和订单数据
35433
35433
 
35434
- //console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
35434
+ console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
35435
35435
 
35436
35436
  let price = lastPrice;
35437
35437
  if (!price) {
@@ -35476,17 +35476,20 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
35476
35476
  curveData.initialVirtualToken
35477
35477
  );
35478
35478
 
35479
- // console.log('\n=== calcLiqTokenBuy 返回结果 ===');
35480
- // console.log('自由流动性 SOL 总量:', liqResult.free_lp_sol_amount_sum.toString());
35481
- // console.log('自由流动性 Token 总量:', liqResult.free_lp_token_amount_sum.toString());
35482
- // console.log('锁定流动性 SOL 总量:', liqResult.lock_lp_sol_amount_sum.toString());
35483
- // console.log('锁定流动性 Token 总量:', liqResult.lock_lp_token_amount_sum.toString());
35484
- // console.log('是否包含无限流动性:', liqResult.has_infinite_lp);
35485
- // console.log('跳过的订单索引:', liqResult.pass_order_id);
35486
- // console.log('需要强平的订单数量:', liqResult.force_close_num);
35487
- // console.log('理想 SOL 使用量:', liqResult.ideal_lp_sol_amount.toString());
35488
- // console.log('实际 SOL 使用量:', liqResult.real_lp_sol_amount.toString());
35489
- // console.log('===============================\n');
35479
+ console.log("liqResult:",liqResult);
35480
+
35481
+
35482
+ console.log('\n=== calcLiqTokenBuy 返回结果 ===');
35483
+ console.log('自由流动性 SOL 总量:', liqResult.free_lp_sol_amount_sum.toString());
35484
+ console.log('自由流动性 Token 总量:', liqResult.free_lp_token_amount_sum.toString());
35485
+ console.log('锁定流动性 SOL 总量:', liqResult.lock_lp_sol_amount_sum.toString());
35486
+ console.log('锁定流动性 Token 总量:', liqResult.lock_lp_token_amount_sum.toString());
35487
+ console.log('是否包含无限流动性:', liqResult.has_infinite_lp);
35488
+ console.log('跳过的订单索引:', liqResult.pass_order_id);
35489
+ console.log('需要强平的订单数量:', liqResult.force_close_num);
35490
+ console.log('理想 SOL 使用量:', liqResult.ideal_lp_sol_amount.toString());
35491
+ console.log('实际 SOL 使用量:', liqResult.real_lp_sol_amount.toString());
35492
+ console.log('===============================\n');
35490
35493
 
35491
35494
  // Convert to BigInt for calculations
35492
35495
  const buyTokenAmountBig = BigInt(buyTokenAmount);
@@ -35942,11 +35945,268 @@ var close_indices = {
35942
35945
  simulateShortClose: simulateShortClose$1
35943
35946
  };
35944
35947
 
35948
+ const CurveAMM$4 = curve_amm;
35949
+
35950
+ /**
35951
+ * 计算使用指定SOL数量买入时能获得的Token数量
35952
+ * @param {bigint|string} price - 当前交易价格 (u128格式)
35953
+ * @param {bigint|string|number} buySolAmount - 需要花费的SOL数量 (lamports, 9位精度)
35954
+ * @param {Array} orders - 锁定流动性的订单数组
35955
+ * @param {number} onceMaxOrder - 单次循环最大订单数
35956
+ * @param {string|number|null} passOrderID - 需要跳过的订单ID(与order_id字段比较)
35957
+ * @param {string|number|Decimal|null} initialVirtualSol - 流动池SOL数量
35958
+ * @param {string|number|Decimal|null} initialVirtualToken - 流动池Token数量
35959
+ * @returns {Object} { tokenAmount: bigint, msg: string, closedOrdersCount: number }
35960
+ */
35961
+ function calcLiqSolBuy$1(price, buySolAmount, orders, onceMaxOrder, passOrderID = null, initialVirtualSol = null, initialVirtualToken = null){
35962
+
35963
+ // 1. 参数验证
35964
+ // 转换为 bigint 以便比较
35965
+ let priceBigInt;
35966
+ let buySolAmountBigInt;
35967
+
35968
+ try {
35969
+ priceBigInt = typeof price === 'bigint' ? price : BigInt(price);
35970
+ buySolAmountBigInt = typeof buySolAmount === 'bigint' ? buySolAmount : BigInt(buySolAmount);
35971
+ } catch (error) {
35972
+ return {
35973
+ tokenAmount: 0n,
35974
+ msg: '参数格式错误:无法转换为bigint',
35975
+ closedOrdersCount: 0
35976
+ };
35977
+ }
35978
+
35979
+ // 检查价格和金额是否有效
35980
+ if (priceBigInt <= 0n) {
35981
+ return {
35982
+ tokenAmount: 0n,
35983
+ msg: '计算失败:价格必须大于0',
35984
+ closedOrdersCount: 0
35985
+ };
35986
+ }
35987
+
35988
+ if (buySolAmountBigInt <= 0n) {
35989
+ return {
35990
+ tokenAmount: 0n,
35991
+ msg: '计算失败:买入金额必须大于0',
35992
+ closedOrdersCount: 0
35993
+ };
35994
+ }
35995
+
35996
+ // 2. 设置默认流动池参数
35997
+ const virtualSol = initialVirtualSol !== null ? initialVirtualSol : CurveAMM$4.INITIAL_SOL_RESERVE_DECIMAL;
35998
+ const virtualToken = initialVirtualToken !== null ? initialVirtualToken : CurveAMM$4.INITIAL_TOKEN_RESERVE_DECIMAL;
35999
+
36000
+ // 3. 处理空订单情况(第一阶段)
36001
+ if (!orders || orders.length === 0) {
36002
+ // 直接计算完整流动性下的买入
36003
+ const result = CurveAMM$4.buyFromPriceWithSolInputWithParams(
36004
+ price,
36005
+ buySolAmount,
36006
+ virtualSol,
36007
+ virtualToken
36008
+ );
36009
+
36010
+ if (result === null) {
36011
+ return {
36012
+ tokenAmount: 0n,
36013
+ msg: '计算失败:价格或参数无效',
36014
+ closedOrdersCount: 0
36015
+ };
36016
+ }
36017
+
36018
+ const [endPrice, tokenAmount] = result;
36019
+ return {
36020
+ tokenAmount: tokenAmount,
36021
+ msg: '流动性完整,无锁定订单',
36022
+ closedOrdersCount: 0
36023
+ };
36024
+ }
36025
+
36026
+ // 4. 处理有订单的情况(第二阶段:分段流动性计算)
36027
+
36028
+ // 初始化变量
36029
+ let currentPrice = priceBigInt; // 当前价格指针
36030
+ let remainingSol = buySolAmountBigInt; // 剩余可用 SOL
36031
+ let totalTokenAmount = 0n; // 累计获得的 token
36032
+ let closedOrdersCount = 0; // 平仓订单数量
36033
+ let processedOrders = 0; // 已处理订单数
36034
+
36035
+ // 检查当前价格是否高于第一个订单的结束价格
36036
+ if (orders.length > 0) {
36037
+ const firstOrderEndPrice = typeof orders[0].lock_lp_end_price === 'bigint'
36038
+ ? orders[0].lock_lp_end_price
36039
+ : BigInt(orders[0].lock_lp_end_price);
36040
+
36041
+ if (currentPrice >= firstOrderEndPrice) {
36042
+ return {
36043
+ tokenAmount: 0n,
36044
+ msg: '错误:当前价格已高于第一个订单的结束价格',
36045
+ closedOrdersCount: 0
36046
+ };
36047
+ }
36048
+ }
36049
+
36050
+ // 遍历订单(最多 onceMaxOrder 个)
36051
+ for (let i = 0; i < orders.length && processedOrders < onceMaxOrder; i++) {
36052
+ const order = orders[i];
36053
+
36054
+ // 检查是否需要跳过此订单
36055
+ if (passOrderID !== null && order.order_id !== undefined) {
36056
+ // 将两者都转换为字符串进行比较
36057
+ const orderIdStr = String(order.order_id);
36058
+ const passOrderIdStr = String(passOrderID);
36059
+
36060
+ if (orderIdStr === passOrderIdStr) {
36061
+ // 跳过此订单,不处理其锁定区间,继续下一个订单
36062
+ continue;
36063
+ }
36064
+ }
36065
+
36066
+ // 转换订单价格为 bigint
36067
+ let lockStartPrice, lockEndPrice;
36068
+ try {
36069
+ lockStartPrice = typeof order.lock_lp_start_price === 'bigint'
36070
+ ? order.lock_lp_start_price
36071
+ : BigInt(order.lock_lp_start_price);
36072
+ lockEndPrice = typeof order.lock_lp_end_price === 'bigint'
36073
+ ? order.lock_lp_end_price
36074
+ : BigInt(order.lock_lp_end_price);
36075
+ } catch (error) {
36076
+ return {
36077
+ tokenAmount: 0n,
36078
+ msg: `错误:订单${i}的价格格式无效`,
36079
+ closedOrdersCount: closedOrdersCount
36080
+ };
36081
+ }
36082
+
36083
+ // 步骤1:计算可用区间(currentPrice → lockStartPrice)
36084
+ if (currentPrice < lockStartPrice) {
36085
+ // 1.1 计算这段区间需要多少 SOL 和能获得多少 token
36086
+ const result = CurveAMM$4.buyFromPriceToPriceWithParams(
36087
+ currentPrice,
36088
+ lockStartPrice,
36089
+ virtualSol,
36090
+ virtualToken
36091
+ );
36092
+
36093
+ // 检查计算是否成功
36094
+ if (result === null) {
36095
+ return {
36096
+ tokenAmount: 0n,
36097
+ msg: `错误:计算价格区间失败(订单${i})`,
36098
+ closedOrdersCount: closedOrdersCount
36099
+ };
36100
+ }
36101
+
36102
+ const [solNeeded, tokenGained] = result;
36103
+
36104
+ // 1.2 判断剩余 SOL 是否足够
36105
+ if (remainingSol >= solNeeded) {
36106
+ // 足够:买完这段区间,继续下一段
36107
+ remainingSol -= solNeeded;
36108
+ totalTokenAmount += tokenGained;
36109
+ currentPrice = lockStartPrice;
36110
+ } else {
36111
+ // 不够:用完剩余 SOL,计算能买多少,然后返回
36112
+ const finalResult = CurveAMM$4.buyFromPriceWithSolInputWithParams(
36113
+ currentPrice,
36114
+ remainingSol,
36115
+ virtualSol,
36116
+ virtualToken
36117
+ );
36118
+
36119
+ if (finalResult === null) {
36120
+ return {
36121
+ tokenAmount: 0n,
36122
+ msg: '错误:计算最终买入失败',
36123
+ closedOrdersCount: closedOrdersCount
36124
+ };
36125
+ }
36126
+
36127
+ const [finalPrice, finalTokenGained] = finalResult;
36128
+ totalTokenAmount += finalTokenGained;
36129
+
36130
+ return {
36131
+ tokenAmount: totalTokenAmount,
36132
+ msg: `SOL用完,最终价格: ${finalPrice.toString()}`,
36133
+ closedOrdersCount: closedOrdersCount
36134
+ };
36135
+ }
36136
+ }
36137
+
36138
+ // 步骤2:跳过锁定区间(lockStartPrice → lockEndPrice)
36139
+ currentPrice = lockEndPrice;
36140
+ processedOrders++;
36141
+
36142
+ // 步骤3:判断是否平仓
36143
+ // 如果价格到达 lockEndPrice,说明这个订单被平仓
36144
+ closedOrdersCount++;
36145
+
36146
+ // 检查 SOL 是否已用完
36147
+ if (remainingSol === 0n) {
36148
+ return {
36149
+ tokenAmount: totalTokenAmount,
36150
+ msg: `SOL刚好用完,最终价格: ${currentPrice.toString()}`,
36151
+ closedOrdersCount: closedOrdersCount
36152
+ };
36153
+ }
36154
+ }
36155
+
36156
+ // 步骤4:处理最后的无限流动性区间
36157
+ // 所有订单处理完后,用剩余 SOL 继续买入
36158
+ if (remainingSol > 0n) {
36159
+ const finalResult = CurveAMM$4.buyFromPriceWithSolInputWithParams(
36160
+ currentPrice,
36161
+ remainingSol,
36162
+ virtualSol,
36163
+ virtualToken
36164
+ );
36165
+
36166
+ if (finalResult === null) {
36167
+ return {
36168
+ tokenAmount: 0n,
36169
+ msg: '错误:计算无限流动性区间失败',
36170
+ closedOrdersCount: closedOrdersCount
36171
+ };
36172
+ }
36173
+
36174
+ const [finalPrice, finalTokenGained] = finalResult;
36175
+ totalTokenAmount += finalTokenGained;
36176
+
36177
+ return {
36178
+ tokenAmount: totalTokenAmount,
36179
+ msg: `买入完成,最终价格: ${finalPrice.toString()}`,
36180
+ closedOrdersCount: closedOrdersCount
36181
+ };
36182
+ }
36183
+
36184
+ // 步骤5:SOL 刚好用完
36185
+ return {
36186
+ tokenAmount: totalTokenAmount,
36187
+ msg: `SOL刚好用完,最终价格: ${currentPrice.toString()}`,
36188
+ closedOrdersCount: closedOrdersCount
36189
+ };
36190
+
36191
+ }
36192
+
36193
+
36194
+ function calcLiqSolSell$1(price, sellSolAmount, orders, onceMaxOrder, passOrder = null, initialVirtualSol = null, initialVirtualToken = null) {
36195
+
36196
+
36197
+ }
36198
+
36199
+
36200
+ var calc_sol_liq = {
36201
+ calcLiqSolBuy: calcLiqSolBuy$1,
36202
+ calcLiqSolSell: calcLiqSolSell$1
36203
+ };
36204
+
35945
36205
  const CurveAMM$3 = curve_amm;
35946
36206
  const { simulateLongStopLoss, simulateShortStopLoss, simulateLongSolStopLoss, simulateShortSolStopLoss } = long_shrot_stop;
35947
36207
  const { simulateTokenBuy, simulateTokenSell } = buy_sell_token;
35948
36208
  const { simulateLongClose, simulateShortClose } = close_indices;
35949
-
36209
+ const {calcLiqSolBuy,calcLiqSolSell } = calc_sol_liq;
35950
36210
 
35951
36211
 
35952
36212
 
@@ -36152,6 +36412,12 @@ class SimulatorModule$1 {
36152
36412
  const priceResult = await this.sdk.data.price(mint);
36153
36413
  const ordersResult = await this.sdk.data.orders(mint, { type: 'down_orders' });
36154
36414
 
36415
+ console.log("ordersResult:",ordersResult);
36416
+
36417
+ const upOrdersResult = await this.sdk.data.orders(mint, { type: 'up_orders' });
36418
+ console.log("upOrdersResult:",upOrdersResult);
36419
+ console.log("upOrdersResult:",upOrdersResult.data.orders);
36420
+
36155
36421
  if (!priceResult || !ordersResult) {
36156
36422
  return {
36157
36423
  success: false,
@@ -36171,6 +36437,15 @@ class SimulatorModule$1 {
36171
36437
  const solInDecimal = Number(solAmountBigInt) / 1e9; // Convert lamports to SOL
36172
36438
  const estimatedTokenAmount = BigInt(Math.floor((solInDecimal / priceDecimal) * 1e9)); // Convert to token lamports (9-digit precision)
36173
36439
 
36440
+ // Get curve account data for initialVirtualSol and initialVirtualToken
36441
+ const curveAccount = await this.sdk.chain.getCurveAccount(mint);
36442
+ const initialVirtualSol = curveAccount.initialVirtualSol;
36443
+ const initialVirtualToken = curveAccount.initialVirtualToken;
36444
+
36445
+ const reSolBuy = calcLiqSolBuy(currentPrice, buySolAmount, upOrdersResult.data.orders, 50, null, initialVirtualSol, initialVirtualToken);
36446
+
36447
+
36448
+
36174
36449
  // Call simulateTokenBuy with estimated amount
36175
36450
  const tokenBuyResult = await this.simulateTokenBuy(mint, estimatedTokenAmount, null, priceResult, ordersResult);
36176
36451
 
@@ -37993,7 +38268,7 @@ class OrderUtils$2 {
37993
38268
 
37994
38269
  var orderUtils = OrderUtils$2;
37995
38270
 
37996
- var address = "AGpTikur4Sxf9xutmJrwVmyKWYQEsqzoiiEm2mvr82cp";
38271
+ var address = "F2FzigE1Z374iDvreiM6hZQe6oGXgomJfv8PyybvUXye";
37997
38272
  var metadata = {
37998
38273
  name: "pinpet",
37999
38274
  version: "0.1.0",
@@ -40478,7 +40753,7 @@ var errors = [
40478
40753
  {
40479
40754
  code: 6003,
40480
40755
  name: "SellCalculationOverflow",
40481
- msg: "Sell trade calculation overflow"
40756
+ msg: "Sell trade calculation overflow"
40482
40757
  },
40483
40758
  {
40484
40759
  code: 6004,
@@ -41795,7 +42070,7 @@ class PinPetSdk$1 {
41795
42070
  this.pinPetFastApiUrl = this.options.pinPetFastApiUrl;
41796
42071
 
41797
42072
  // Maximum number of orders that can be processed at once in the contract
41798
- this.MAX_ORDERS_COUNT = 9;
42073
+ this.MAX_ORDERS_COUNT = 50;
41799
42074
  // Maximum number of orders to fetch during queries
41800
42075
  this.FIND_MAX_ORDERS_COUNT = 1000;
41801
42076
 
@@ -41959,13 +42234,13 @@ const DEFAULT_NETWORKS = {
41959
42234
  LOCALNET: {
41960
42235
  name: 'localnet',
41961
42236
  defaultDataSource: 'fast', // 'fast' or 'chain'
41962
- // solanaEndpoint: 'http://127.0.0.1:8899',
41963
- // pinPetFastApiUrl: 'http://127.0.0.1:3000',
41964
- solanaEndpoint: 'http://162.250.124.66:8899',
41965
- pinPetFastApiUrl: 'http://162.250.124.66:3000',
42237
+ solanaEndpoint: 'http://127.0.0.1:8899',
42238
+ pinPetFastApiUrl: 'http://127.0.0.1:3000',
42239
+ // solanaEndpoint: 'http://162.250.124.66:8899',
42240
+ // pinPetFastApiUrl: 'http://162.250.124.66:3000',
41966
42241
  feeRecipient: 'GesAj2dTn2wdNcxj4x8qsqS9aNRVPBPkE76aaqg7skxu',
41967
42242
  baseFeeRecipient: '5YHi1HsxobLiTD6NQfHJQpoPoRjMuNyXp4RroTvR6dKi',
41968
- paramsAccount: 'BvChe3C88ezFvcSutX5TsTUnUdToHAHqwfSQ85cmNq1A'
42243
+ paramsAccount: '8tn4XdqWAAh97WwfLrDrwnagRsQp7Nu5nrUmXVBJvgMU'
41969
42244
  }
41970
42245
  };
41971
42246