pinpet-sdk 2.0.0 → 2.0.2
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.
- package/dist/pinpet-sdk.cjs.js +51 -51
- package/dist/pinpet-sdk.cjs.js.map +1 -1
- package/dist/pinpet-sdk.esm.js +51 -51
- package/dist/pinpet-sdk.esm.js.map +1 -1
- package/dist/pinpet-sdk.js +51 -51
- package/dist/pinpet-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +4 -4
package/dist/pinpet-sdk.cjs.js
CHANGED
|
@@ -41882,7 +41882,7 @@ const MAX_FEE_RATE = 10_000n;
|
|
|
41882
41882
|
* Implements constant product (xy=k) algorithm for automated market maker functionality
|
|
41883
41883
|
* Usage when importing: const CurveAMM = require("../tools/curve_amm");
|
|
41884
41884
|
*/
|
|
41885
|
-
class CurveAMM$
|
|
41885
|
+
class CurveAMM$7 {
|
|
41886
41886
|
/**
|
|
41887
41887
|
* Initial SOL reserve amount, represented as Decimal
|
|
41888
41888
|
* @type {Decimal}
|
|
@@ -42736,10 +42736,10 @@ class CurveAMM$6 {
|
|
|
42736
42736
|
}
|
|
42737
42737
|
}
|
|
42738
42738
|
|
|
42739
|
-
var curve_amm = CurveAMM$
|
|
42739
|
+
var curve_amm = CurveAMM$7;
|
|
42740
42740
|
|
|
42741
42741
|
const axios = axios_1;
|
|
42742
|
-
const CurveAMM$
|
|
42742
|
+
const CurveAMM$6 = curve_amm;
|
|
42743
42743
|
|
|
42744
42744
|
/**
|
|
42745
42745
|
* Fast API Module
|
|
@@ -43231,7 +43231,7 @@ class FastModule$1 {
|
|
|
43231
43231
|
|
|
43232
43232
|
if (!latestPrice) {
|
|
43233
43233
|
// If no price data, calculate initial price
|
|
43234
|
-
const initialPrice = CurveAMM$
|
|
43234
|
+
const initialPrice = CurveAMM$6.getInitialPrice();
|
|
43235
43235
|
if (initialPrice === null) {
|
|
43236
43236
|
throw new Error('price: 无法计算初始价格 Unable to calculate initial price');
|
|
43237
43237
|
}
|
|
@@ -44696,7 +44696,7 @@ jsonBigint.exports.stringify = json_stringify;
|
|
|
44696
44696
|
|
|
44697
44697
|
var jsonBigintExports = jsonBigint.exports;
|
|
44698
44698
|
|
|
44699
|
-
const CurveAMM$
|
|
44699
|
+
const CurveAMM$5 = curve_amm;
|
|
44700
44700
|
const {transformOrdersData , checkPriceRangeOverlap} = stop_loss_utils;
|
|
44701
44701
|
const { PRICE_ADJUSTMENT_PERCENTAGE, MIN_STOP_LOSS_PERCENT } = utils$2;
|
|
44702
44702
|
jsonBigintExports({ storeAsString: false });
|
|
@@ -44854,12 +44854,12 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
|
|
|
44854
44854
|
let currentPrice;
|
|
44855
44855
|
if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
|
|
44856
44856
|
console.log('Current price is empty, using initial price');
|
|
44857
|
-
currentPrice = CurveAMM$
|
|
44857
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
44858
44858
|
} else {
|
|
44859
44859
|
currentPrice = BigInt(lastPrice);
|
|
44860
44860
|
if (!currentPrice || currentPrice === 0n) {
|
|
44861
44861
|
console.log('Current price is 0, using initial price');
|
|
44862
|
-
currentPrice = CurveAMM$
|
|
44862
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
44863
44863
|
}
|
|
44864
44864
|
}
|
|
44865
44865
|
|
|
@@ -44904,7 +44904,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
|
|
|
44904
44904
|
// console.log(` - buyTokenAmount: ${buyTokenAmount.toString()}`);
|
|
44905
44905
|
// console.log(` - Calling CurveAMM.sellFromPriceWithTokenInput...`);
|
|
44906
44906
|
|
|
44907
|
-
const tradeResult = CurveAMM$
|
|
44907
|
+
const tradeResult = CurveAMM$5.sellFromPriceWithTokenInput(stopLossStartPrice, buyTokenAmount);
|
|
44908
44908
|
|
|
44909
44909
|
//console.log(` - tradeResult:`, tradeResult);
|
|
44910
44910
|
|
|
@@ -44968,12 +44968,12 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
|
|
|
44968
44968
|
let estimatedMargin = 0n;
|
|
44969
44969
|
try {
|
|
44970
44970
|
// 1. 计算从当前价格买入所需的SOL
|
|
44971
|
-
const buyResult = CurveAMM$
|
|
44971
|
+
const buyResult = CurveAMM$5.buyFromPriceWithTokenOutput(currentPrice, buyTokenAmount);
|
|
44972
44972
|
if (buyResult) {
|
|
44973
44973
|
const requiredSol = buyResult[1]; // SOL input amount
|
|
44974
44974
|
|
|
44975
44975
|
// 2. 计算平仓时扣除手续费后的收益
|
|
44976
|
-
const closeOutputSolAfterFee = CurveAMM$
|
|
44976
|
+
const closeOutputSolAfterFee = CurveAMM$5.calculateAmountAfterFee(finalTradeAmount, borrowFee);
|
|
44977
44977
|
|
|
44978
44978
|
// 3. 计算保证金 = 买入成本 - 平仓收益(扣费后)
|
|
44979
44979
|
if (closeOutputSolAfterFee !== null && requiredSol > closeOutputSolAfterFee) {
|
|
@@ -45163,12 +45163,12 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45163
45163
|
let currentPrice;
|
|
45164
45164
|
if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
|
|
45165
45165
|
console.log('Current price is empty, using initial price');
|
|
45166
|
-
currentPrice = CurveAMM$
|
|
45166
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
45167
45167
|
} else {
|
|
45168
45168
|
currentPrice = BigInt(lastPrice);
|
|
45169
45169
|
if (!currentPrice || currentPrice === 0n) {
|
|
45170
45170
|
console.log('Current price is 0, using initial price');
|
|
45171
|
-
currentPrice = CurveAMM$
|
|
45171
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
45172
45172
|
}
|
|
45173
45173
|
}
|
|
45174
45174
|
|
|
@@ -45211,7 +45211,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45211
45211
|
// console.log(` - sellTokenAmount: ${sellTokenAmount.toString()}`);
|
|
45212
45212
|
// console.log(` - Calling CurveAMM.buyFromPriceWithTokenOutput...`);
|
|
45213
45213
|
|
|
45214
|
-
const tradeResult = CurveAMM$
|
|
45214
|
+
const tradeResult = CurveAMM$5.buyFromPriceWithTokenOutput(stopLossStartPrice, sellTokenAmount);
|
|
45215
45215
|
|
|
45216
45216
|
//console.log(` - tradeResult:`, tradeResult);
|
|
45217
45217
|
|
|
@@ -45250,8 +45250,8 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45250
45250
|
//console.log(`调整后起始价格: ${stopLossStartPrice} / Adjusted start price: ${stopLossStartPrice}`);
|
|
45251
45251
|
|
|
45252
45252
|
// 安全检查:确保价格不会超过最大值 / Safety check: ensure price doesn't exceed maximum
|
|
45253
|
-
if (stopLossStartPrice >= CurveAMM$
|
|
45254
|
-
throw new Error(`Stop loss price exceeded maximum after adjustment: ${stopLossStartPrice} >= ${CurveAMM$
|
|
45253
|
+
if (stopLossStartPrice >= CurveAMM$5.MAX_U128_PRICE) {
|
|
45254
|
+
throw new Error(`Stop loss price exceeded maximum after adjustment: ${stopLossStartPrice} >= ${CurveAMM$5.MAX_U128_PRICE}`);
|
|
45255
45255
|
}
|
|
45256
45256
|
}
|
|
45257
45257
|
|
|
@@ -45274,7 +45274,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45274
45274
|
let estimatedMargin = 0n;
|
|
45275
45275
|
try {
|
|
45276
45276
|
// 1. 计算从当前价格卖出代币获得的SOL(开仓收益,不含手续费)
|
|
45277
|
-
const sellResult = CurveAMM$
|
|
45277
|
+
const sellResult = CurveAMM$5.sellFromPriceWithTokenInput(currentPrice, sellTokenAmount);
|
|
45278
45278
|
if (sellResult) {
|
|
45279
45279
|
const openingSolGain = sellResult[1]; // 卖出获得的SOL
|
|
45280
45280
|
|
|
@@ -45398,17 +45398,17 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
|
|
|
45398
45398
|
|
|
45399
45399
|
// Calculate current price
|
|
45400
45400
|
if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
|
|
45401
|
-
currentPrice = CurveAMM$
|
|
45401
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
45402
45402
|
} else {
|
|
45403
45403
|
currentPrice = BigInt(lastPrice);
|
|
45404
45404
|
if (!currentPrice || currentPrice === 0n) {
|
|
45405
|
-
currentPrice = CurveAMM$
|
|
45405
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
45406
45406
|
}
|
|
45407
45407
|
}
|
|
45408
45408
|
|
|
45409
45409
|
// Calculate initial token amount from SOL amount using sellFromPriceWithSolOutput
|
|
45410
45410
|
// This gives us how many tokens we can get when we later sell for buySolAmount SOL
|
|
45411
|
-
const initialResult = CurveAMM$
|
|
45411
|
+
const initialResult = CurveAMM$5.sellFromPriceWithSolOutput(currentPrice, buySolAmount);
|
|
45412
45412
|
if (!initialResult) {
|
|
45413
45413
|
throw new Error('Failed to calculate token amount from SOL amount');
|
|
45414
45414
|
}
|
|
@@ -45565,17 +45565,17 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
|
|
|
45565
45565
|
|
|
45566
45566
|
// Calculate current price
|
|
45567
45567
|
if (lastPrice === null || lastPrice === undefined || lastPrice === '0') {
|
|
45568
|
-
currentPrice = CurveAMM$
|
|
45568
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
45569
45569
|
} else {
|
|
45570
45570
|
currentPrice = BigInt(lastPrice);
|
|
45571
45571
|
if (!currentPrice || currentPrice === 0n) {
|
|
45572
|
-
currentPrice = CurveAMM$
|
|
45572
|
+
currentPrice = CurveAMM$5.getInitialPrice();
|
|
45573
45573
|
}
|
|
45574
45574
|
}
|
|
45575
45575
|
|
|
45576
45576
|
// Calculate initial token amount from SOL amount using buyFromPriceWithSolInput
|
|
45577
45577
|
// This gives us how many tokens we need to buy later using sellSolAmount SOL
|
|
45578
|
-
const initialResult = CurveAMM$
|
|
45578
|
+
const initialResult = CurveAMM$5.buyFromPriceWithSolInput(currentPrice, sellSolAmount);
|
|
45579
45579
|
if (!initialResult) {
|
|
45580
45580
|
throw new Error('Failed to calculate token amount from SOL amount');
|
|
45581
45581
|
}
|
|
@@ -45667,7 +45667,7 @@ var long_shrot_stop = {
|
|
|
45667
45667
|
simulateShortSolStopLoss: simulateShortSolStopLoss$1
|
|
45668
45668
|
};
|
|
45669
45669
|
|
|
45670
|
-
const CurveAMM$
|
|
45670
|
+
const CurveAMM$4 = curve_amm;
|
|
45671
45671
|
|
|
45672
45672
|
|
|
45673
45673
|
/**
|
|
@@ -45781,7 +45781,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45781
45781
|
|
|
45782
45782
|
try {
|
|
45783
45783
|
const priceBigInt = BigInt(price);
|
|
45784
|
-
[, result.ideal_lp_sol_amount] = CurveAMM$
|
|
45784
|
+
[, result.ideal_lp_sol_amount] = CurveAMM$4.buyFromPriceWithTokenOutput(priceBigInt, buyTokenAmountBigInt);
|
|
45785
45785
|
// console.log(`理想计算: 当前价格=${priceBigInt}, 目标代币=${buyTokenAmountBigInt}, 理想SOL=${result.ideal_lp_sol_amount}`);
|
|
45786
45786
|
} catch (error) {
|
|
45787
45787
|
throw new Error(`buy流动性计算错误:理想流动性计算失败 Liquidity calculation error: Ideal liquidity calculation failed - ${error.message}`);
|
|
@@ -45790,7 +45790,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45790
45790
|
|
|
45791
45791
|
// orders 长度为0 时要单独计算
|
|
45792
45792
|
if (orders.length === 0) {
|
|
45793
|
-
[result.free_lp_sol_amount_sum, result.free_lp_token_amount_sum] = CurveAMM$
|
|
45793
|
+
[result.free_lp_sol_amount_sum, result.free_lp_token_amount_sum] = CurveAMM$4.buyFromPriceToPrice(BigInt(price), CurveAMM$4.MAX_U128_PRICE);
|
|
45794
45794
|
result.has_infinite_lp = true;
|
|
45795
45795
|
result.real_lp_sol_amount = result.ideal_lp_sol_amount;
|
|
45796
45796
|
return result
|
|
@@ -45838,7 +45838,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45838
45838
|
// 如果存在价格间隙,计算自由流动性
|
|
45839
45839
|
if (endPrice > startPrice) {
|
|
45840
45840
|
try {
|
|
45841
|
-
const gapLiquidity = CurveAMM$
|
|
45841
|
+
const gapLiquidity = CurveAMM$4.buyFromPriceToPrice(startPrice, endPrice);
|
|
45842
45842
|
if (gapLiquidity && Array.isArray(gapLiquidity) && gapLiquidity.length === 2) {
|
|
45843
45843
|
const [solAmount, tokenAmount] = gapLiquidity;
|
|
45844
45844
|
|
|
@@ -45860,7 +45860,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45860
45860
|
try {
|
|
45861
45861
|
const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
|
|
45862
45862
|
// console.log("actualBuyAmount",actualBuyAmount)
|
|
45863
|
-
const [, preciseSol] = CurveAMM$
|
|
45863
|
+
const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(startPrice, actualBuyAmount);
|
|
45864
45864
|
result.real_lp_sol_amount = prev_free_lp_sol_amount_sum + BigInt(preciseSol);
|
|
45865
45865
|
|
|
45866
45866
|
// console.log(`实际计算[${i}]: 自由流动性已足够, actualBuyAmount=${actualBuyAmount}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
|
|
@@ -45914,7 +45914,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45914
45914
|
// 从当前价格开始计算需要多少SOL来买到精确的token数量
|
|
45915
45915
|
const targetPrice = i === 0 ? BigInt(price) : BigInt(orders[i - 1].lock_lp_end_price);
|
|
45916
45916
|
const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(order.lock_lp_token_amount));
|
|
45917
|
-
const [, preciseSol] = CurveAMM$
|
|
45917
|
+
const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(targetPrice, actualBuyAmount);
|
|
45918
45918
|
result.real_lp_sol_amount = prevFreeSolSum + BigInt(preciseSol);
|
|
45919
45919
|
// console.log(`实际计算[${i}]: 跳过订单后足够, targetPrice=${targetPrice}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
|
|
45920
45920
|
result.force_close_num = counti;
|
|
@@ -45968,7 +45968,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45968
45968
|
let lastEndPrice, maxPrice;
|
|
45969
45969
|
try {
|
|
45970
45970
|
lastEndPrice = BigInt(lastOrder.lock_lp_end_price);
|
|
45971
|
-
maxPrice = CurveAMM$
|
|
45971
|
+
maxPrice = CurveAMM$4.MAX_U128_PRICE;
|
|
45972
45972
|
} catch (error) {
|
|
45973
45973
|
throw new Error(`价格转换错误:无法转换最后订单价格或最大价格 Price conversion error: Cannot convert last order price or max price - ${error.message}`);
|
|
45974
45974
|
}
|
|
@@ -45976,7 +45976,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45976
45976
|
|
|
45977
45977
|
if (maxPrice > lastEndPrice) {
|
|
45978
45978
|
try {
|
|
45979
|
-
const infiniteLiquidity = CurveAMM$
|
|
45979
|
+
const infiniteLiquidity = CurveAMM$4.buyFromPriceToPrice(lastEndPrice, maxPrice);
|
|
45980
45980
|
if (infiniteLiquidity && Array.isArray(infiniteLiquidity) && infiniteLiquidity.length === 2) {
|
|
45981
45981
|
const [solAmount, tokenAmount] = infiniteLiquidity;
|
|
45982
45982
|
|
|
@@ -45995,7 +45995,7 @@ function calcLiqTokenBuy$1(price, buyTokenAmount, orders, onceMaxOrder, passOrde
|
|
|
45995
45995
|
// 计算最后精确需要买多少token
|
|
45996
45996
|
try {
|
|
45997
45997
|
const actualBuyAmount = buyTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
|
|
45998
|
-
const [, preciseSol] = CurveAMM$
|
|
45998
|
+
const [, preciseSol] = CurveAMM$4.buyFromPriceWithTokenOutput(lastEndPrice, actualBuyAmount);
|
|
45999
45999
|
result.real_lp_sol_amount += BigInt(preciseSol);
|
|
46000
46000
|
result.force_close_num = counti; // 强平订单数量
|
|
46001
46001
|
} catch (error) {
|
|
@@ -46130,7 +46130,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46130
46130
|
// 计算理想情况下卖出能获得的SOL数量
|
|
46131
46131
|
try {
|
|
46132
46132
|
const priceBigInt = BigInt(price);
|
|
46133
|
-
[, result.ideal_lp_sol_amount] = CurveAMM$
|
|
46133
|
+
[, result.ideal_lp_sol_amount] = CurveAMM$4.sellFromPriceWithTokenInput(priceBigInt, sellTokenAmountBigInt);
|
|
46134
46134
|
// console.log(`理想计算: 当前价格=${priceBigInt}, 卖出代币=${sellTokenAmountBigInt}, 理想SOL=${result.ideal_lp_sol_amount}`);
|
|
46135
46135
|
} catch (error) {
|
|
46136
46136
|
throw new Error(`sell流动性计算错误:理想流动性计算失败 Liquidity calculation error: Ideal liquidity calculation failed - ${error.message}`);
|
|
@@ -46138,7 +46138,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46138
46138
|
|
|
46139
46139
|
// orders 长度为0 时要单独计算
|
|
46140
46140
|
if (orders.length === 0) {
|
|
46141
|
-
const sellResult = CurveAMM$
|
|
46141
|
+
const sellResult = CurveAMM$4.sellFromPriceToPrice(BigInt(price), CurveAMM$4.MIN_U128_PRICE);
|
|
46142
46142
|
if (sellResult) {
|
|
46143
46143
|
[result.free_lp_token_amount_sum, result.free_lp_sol_amount_sum] = sellResult;
|
|
46144
46144
|
} else {
|
|
@@ -46194,7 +46194,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46194
46194
|
// 如果存在价格间隙(卖出时startPrice应该大于endPrice)
|
|
46195
46195
|
if (startPrice > endPrice) {
|
|
46196
46196
|
try {
|
|
46197
|
-
const gapLiquidity = CurveAMM$
|
|
46197
|
+
const gapLiquidity = CurveAMM$4.sellFromPriceToPrice(startPrice, endPrice);
|
|
46198
46198
|
if (gapLiquidity && Array.isArray(gapLiquidity) && gapLiquidity.length === 2) {
|
|
46199
46199
|
const [tokenAmount, solAmount] = gapLiquidity;
|
|
46200
46200
|
|
|
@@ -46214,7 +46214,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46214
46214
|
// 计算精确能获得多少SOL
|
|
46215
46215
|
try {
|
|
46216
46216
|
const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
|
|
46217
|
-
const [, preciseSol] = CurveAMM$
|
|
46217
|
+
const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(startPrice, actualSellAmount);
|
|
46218
46218
|
result.real_lp_sol_amount = prev_free_lp_sol_amount_sum + preciseSol;
|
|
46219
46219
|
// console.log(`卖出实际计算[${i}]: 自由流动性已足够, actualSellAmount=${actualSellAmount}, preciseSol=${preciseSol}, 实际SOL=${result.real_lp_sol_amount}`);
|
|
46220
46220
|
result.force_close_num = counti; // 强平订单数量
|
|
@@ -46263,7 +46263,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46263
46263
|
// 计算精确能获得多少SOL
|
|
46264
46264
|
const targetPrice = i === 0 ? BigInt(price) : BigInt(orders[i - 1].lock_lp_end_price);
|
|
46265
46265
|
const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(order.lock_lp_token_amount));
|
|
46266
|
-
const [, preciseSol] = CurveAMM$
|
|
46266
|
+
const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(targetPrice, actualSellAmount);
|
|
46267
46267
|
result.real_lp_sol_amount = prevFreeSolSum + preciseSol;
|
|
46268
46268
|
result.force_close_num = counti;
|
|
46269
46269
|
} catch (error) {
|
|
@@ -46313,7 +46313,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46313
46313
|
let lastEndPrice, minPrice;
|
|
46314
46314
|
try {
|
|
46315
46315
|
lastEndPrice = BigInt(lastOrder.lock_lp_end_price);
|
|
46316
|
-
minPrice = CurveAMM$
|
|
46316
|
+
minPrice = CurveAMM$4.MIN_U128_PRICE;
|
|
46317
46317
|
} catch (error) {
|
|
46318
46318
|
throw new Error(`价格转换错误:无法转换最后订单价格或最小价格 Price conversion error: Cannot convert last order price or min price - ${error.message}`);
|
|
46319
46319
|
}
|
|
@@ -46322,7 +46322,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46322
46322
|
if (lastEndPrice > minPrice) {
|
|
46323
46323
|
|
|
46324
46324
|
try {
|
|
46325
|
-
const infiniteLiquidity = CurveAMM$
|
|
46325
|
+
const infiniteLiquidity = CurveAMM$4.sellFromPriceToPrice(lastEndPrice, minPrice);
|
|
46326
46326
|
if (infiniteLiquidity && Array.isArray(infiniteLiquidity) && infiniteLiquidity.length === 2) {
|
|
46327
46327
|
const [tokenAmount, solAmount] = infiniteLiquidity;
|
|
46328
46328
|
|
|
@@ -46342,7 +46342,7 @@ function calcLiqTokenSell$1(price, sellTokenAmount, orders, onceMaxOrder, passOr
|
|
|
46342
46342
|
// 无限流动性够卖出需求了
|
|
46343
46343
|
try {
|
|
46344
46344
|
const actualSellAmount = sellTokenAmountBigInt - (result.free_lp_token_amount_sum - BigInt(tokenAmount));
|
|
46345
|
-
const [, preciseSol] = CurveAMM$
|
|
46345
|
+
const [, preciseSol] = CurveAMM$4.sellFromPriceWithTokenInput(lastEndPrice, actualSellAmount);
|
|
46346
46346
|
result.real_lp_sol_amount = prevFreeSolSum + preciseSol;
|
|
46347
46347
|
result.force_close_num = counti; // 强平订单数量
|
|
46348
46348
|
} catch (error) {
|
|
@@ -46887,7 +46887,7 @@ var close_indices = {
|
|
|
46887
46887
|
simulateShortClose: simulateShortClose$1
|
|
46888
46888
|
};
|
|
46889
46889
|
|
|
46890
|
-
const CurveAMM$
|
|
46890
|
+
const CurveAMM$3 = curve_amm;
|
|
46891
46891
|
const { simulateLongStopLoss, simulateShortStopLoss, simulateLongSolStopLoss, simulateShortSolStopLoss } = long_shrot_stop;
|
|
46892
46892
|
const { simulateTokenBuy, simulateTokenSell } = buy_sell_token;
|
|
46893
46893
|
const { simulateLongClose, simulateShortClose } = close_indices;
|
|
@@ -47112,7 +47112,7 @@ class SimulatorModule$1 {
|
|
|
47112
47112
|
|
|
47113
47113
|
// Estimate token amount: tokenAmount ≈ solAmount / (price / 2^64)
|
|
47114
47114
|
// price is u128 with 28 decimal places encoded
|
|
47115
|
-
const priceDecimal = CurveAMM$
|
|
47115
|
+
const priceDecimal = CurveAMM$3.u128ToDecimal(currentPrice);
|
|
47116
47116
|
const solInDecimal = Number(solAmountBigInt) / 1e9; // Convert lamports to SOL
|
|
47117
47117
|
const estimatedTokenAmount = BigInt(Math.floor((solInDecimal / priceDecimal) * 1e6)); // Convert to token lamports
|
|
47118
47118
|
|
|
@@ -47223,7 +47223,7 @@ class SimulatorModule$1 {
|
|
|
47223
47223
|
const tokenSellResult = await this.simulateTokenSell(mint, tokenAmountBigInt, null, priceResult, ordersResult);
|
|
47224
47224
|
|
|
47225
47225
|
// Estimate ideal SOL amount
|
|
47226
|
-
const priceDecimal = CurveAMM$
|
|
47226
|
+
const priceDecimal = CurveAMM$3.u128ToDecimal(currentPrice);
|
|
47227
47227
|
const tokenInDecimal = Number(tokenAmountBigInt) / 1e6; // Convert token lamports to tokens
|
|
47228
47228
|
const estimatedSolAmount = BigInt(Math.floor((tokenInDecimal * priceDecimal) * 1e9)); // Convert to SOL lamports
|
|
47229
47229
|
|
|
@@ -47266,7 +47266,7 @@ var simulator = SimulatorModule$1;
|
|
|
47266
47266
|
|
|
47267
47267
|
const { PublicKey: PublicKey$3 } = require$$0__default["default"];
|
|
47268
47268
|
const anchor$2 = require$$0__default$3["default"];
|
|
47269
|
-
const CurveAMM$
|
|
47269
|
+
const CurveAMM$2 = curve_amm;
|
|
47270
47270
|
// 统一使用 buffer 包,所有平台一致
|
|
47271
47271
|
const { Buffer: Buffer$2 } = require$$3__default["default"];
|
|
47272
47272
|
|
|
@@ -47630,7 +47630,7 @@ class ChainModule$1 {
|
|
|
47630
47630
|
return decodedData.price.toString();
|
|
47631
47631
|
} else {
|
|
47632
47632
|
// If no price data, return initial price
|
|
47633
|
-
const initialPrice = CurveAMM$
|
|
47633
|
+
const initialPrice = CurveAMM$2.getInitialPrice();
|
|
47634
47634
|
if (initialPrice === null) {
|
|
47635
47635
|
throw new Error('price: Unable to calculate initial price');
|
|
47636
47636
|
}
|
|
@@ -47641,7 +47641,7 @@ class ChainModule$1 {
|
|
|
47641
47641
|
// If getting fails, return initial price
|
|
47642
47642
|
console.warn(`price: Failed to get chain price, using initial price: ${error.message}`);
|
|
47643
47643
|
|
|
47644
|
-
const initialPrice = CurveAMM$
|
|
47644
|
+
const initialPrice = CurveAMM$2.getInitialPrice();
|
|
47645
47645
|
if (initialPrice === null) {
|
|
47646
47646
|
throw new Error('price: Unable to calculate initial price');
|
|
47647
47647
|
}
|
|
@@ -52899,7 +52899,7 @@ const FastModule = fast;
|
|
|
52899
52899
|
const SimulatorModule = simulator;
|
|
52900
52900
|
const ChainModule = chain;
|
|
52901
52901
|
const ToolsModule = tools;
|
|
52902
|
-
const CurveAMM = curve_amm;
|
|
52902
|
+
const CurveAMM$1 = curve_amm;
|
|
52903
52903
|
const spinpetIdl$1 = require$$1;
|
|
52904
52904
|
|
|
52905
52905
|
/**
|
|
@@ -52969,7 +52969,7 @@ class PinPetSdk$1 {
|
|
|
52969
52969
|
this.tools = new ToolsModule(this);
|
|
52970
52970
|
|
|
52971
52971
|
// Initialize curve AMM utility
|
|
52972
|
-
this.curve = CurveAMM;
|
|
52972
|
+
this.curve = CurveAMM$1;
|
|
52973
52973
|
|
|
52974
52974
|
/**
|
|
52975
52975
|
* 统一数据接口 - 根据 defaultDataSource 配置自动路由到 fast 或 chain 模块
|
|
@@ -53189,13 +53189,12 @@ const PinPetSdk = sdk;
|
|
|
53189
53189
|
const spinpetIdl = require$$1;
|
|
53190
53190
|
const { PublicKey } = require$$0__default["default"];
|
|
53191
53191
|
|
|
53192
|
-
|
|
53193
|
-
|
|
53194
53192
|
// Import configuration utilities
|
|
53195
53193
|
const { getDefaultOptions } = constants;
|
|
53196
53194
|
|
|
53197
53195
|
// Import utility classes
|
|
53198
53196
|
const OrderUtils = orderUtils;
|
|
53197
|
+
const CurveAMM = curve_amm;
|
|
53199
53198
|
|
|
53200
53199
|
// Import constants (if needed)
|
|
53201
53200
|
const SPINPET_PROGRAM_ID = new PublicKey(spinpetIdl.address); // Replace with actual program ID
|
|
@@ -53204,15 +53203,16 @@ const SPINPET_PROGRAM_ID = new PublicKey(spinpetIdl.address); // Replace with ac
|
|
|
53204
53203
|
src$1.exports = {
|
|
53205
53204
|
// Main SDK class
|
|
53206
53205
|
PinPetSdk,
|
|
53207
|
-
|
|
53206
|
+
|
|
53208
53207
|
// Constants
|
|
53209
53208
|
SPINPET_PROGRAM_ID,
|
|
53210
|
-
|
|
53209
|
+
|
|
53211
53210
|
// Configuration utilities
|
|
53212
53211
|
getDefaultOptions,
|
|
53213
53212
|
|
|
53214
53213
|
// Utility classes
|
|
53215
53214
|
OrderUtils,
|
|
53215
|
+
CurveAMM,
|
|
53216
53216
|
};
|
|
53217
53217
|
|
|
53218
53218
|
// Default export SDK class
|