pinpet-sdk 2.1.24 → 2.1.26
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 +232 -155
- package/dist/pinpet-sdk.esm.js +232 -155
- package/dist/pinpet-sdk.js +232 -155
- package/dist/pinpet-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/idl/pinpet.json +99 -94
- package/src/modules/simulator/long_shrot_stop.js +73 -31
- package/src/modules/simulator.js +6 -6
- package/src/utils/constants.js +2 -2
- package/src/utils/curve_amm.js +30 -0
package/dist/pinpet-sdk.cjs.js
CHANGED
|
@@ -41917,12 +41917,12 @@ decimal.exports;
|
|
|
41917
41917
|
|
|
41918
41918
|
var decimalExports = decimal.exports;
|
|
41919
41919
|
|
|
41920
|
-
const Decimal$
|
|
41920
|
+
const Decimal$2 = decimalExports;
|
|
41921
41921
|
|
|
41922
41922
|
// Configure Decimal.js to use 50-bit precision for better accuracy with tiny prices
|
|
41923
41923
|
// Increased from 28 to 50 to handle extremely small prices (e.g., 0.000000041571)
|
|
41924
41924
|
// ROUND_HALF_UP ensures consistent rounding behavior
|
|
41925
|
-
Decimal$
|
|
41925
|
+
Decimal$2.set({ precision: 50, rounding: Decimal$2.ROUND_HALF_UP });
|
|
41926
41926
|
|
|
41927
41927
|
|
|
41928
41928
|
/**
|
|
@@ -41950,19 +41950,19 @@ class CurveAMM$8 {
|
|
|
41950
41950
|
* Initial SOL reserve amount, represented as Decimal
|
|
41951
41951
|
* @type {Decimal}
|
|
41952
41952
|
*/
|
|
41953
|
-
static INITIAL_SOL_RESERVE_DECIMAL = new Decimal$
|
|
41953
|
+
static INITIAL_SOL_RESERVE_DECIMAL = new Decimal$2('30');
|
|
41954
41954
|
|
|
41955
41955
|
/**
|
|
41956
41956
|
* Initial Token reserve amount, represented as Decimal
|
|
41957
41957
|
* @type {Decimal}
|
|
41958
41958
|
*/
|
|
41959
|
-
static INITIAL_TOKEN_RESERVE_DECIMAL = new Decimal$
|
|
41959
|
+
static INITIAL_TOKEN_RESERVE_DECIMAL = new Decimal$2('1073000000');
|
|
41960
41960
|
|
|
41961
41961
|
/**
|
|
41962
41962
|
* Initial constant K value, represented as Decimal
|
|
41963
41963
|
* @type {Decimal}
|
|
41964
41964
|
*/
|
|
41965
|
-
static INITIAL_K_DECIMAL = new Decimal$
|
|
41965
|
+
static INITIAL_K_DECIMAL = new Decimal$2('32190000000');
|
|
41966
41966
|
|
|
41967
41967
|
/**
|
|
41968
41968
|
* Minimum price that can appear, below this price may cause overflow
|
|
@@ -41970,26 +41970,26 @@ class CurveAMM$8 {
|
|
|
41970
41970
|
* Reduced from 1e-9 to 1e-12 to support wider range of pool configurations
|
|
41971
41971
|
* @type {Decimal}
|
|
41972
41972
|
*/
|
|
41973
|
-
static INITIAL_MIN_PRICE_DECIMAL = new Decimal$
|
|
41973
|
+
static INITIAL_MIN_PRICE_DECIMAL = new Decimal$2('0.000000000001'); // 1e-12
|
|
41974
41974
|
|
|
41975
41975
|
/**
|
|
41976
41976
|
* Decimal representation of precision factor = 10^23
|
|
41977
41977
|
* @type {Decimal}
|
|
41978
41978
|
*/
|
|
41979
41979
|
//static PRICE_PRECISION_FACTOR_DECIMAL = new Decimal('10000000000000000000000000000');
|
|
41980
|
-
static PRICE_PRECISION_FACTOR_DECIMAL = new Decimal$
|
|
41980
|
+
static PRICE_PRECISION_FACTOR_DECIMAL = new Decimal$2('100000000000000000000000');
|
|
41981
41981
|
|
|
41982
41982
|
/**
|
|
41983
41983
|
* Decimal representation of Token precision factor = 1000000000 (10^9)
|
|
41984
41984
|
* @type {Decimal}
|
|
41985
41985
|
*/
|
|
41986
|
-
static TOKEN_PRECISION_FACTOR_DECIMAL = new Decimal$
|
|
41986
|
+
static TOKEN_PRECISION_FACTOR_DECIMAL = new Decimal$2('1000000000');
|
|
41987
41987
|
|
|
41988
41988
|
/**
|
|
41989
41989
|
* Decimal representation of SOL precision factor = 1000000000
|
|
41990
41990
|
* @type {Decimal}
|
|
41991
41991
|
*/
|
|
41992
|
-
static SOL_PRECISION_FACTOR_DECIMAL = new Decimal$
|
|
41992
|
+
static SOL_PRECISION_FACTOR_DECIMAL = new Decimal$2('1000000000');
|
|
41993
41993
|
|
|
41994
41994
|
|
|
41995
41995
|
/**
|
|
@@ -42018,7 +42018,7 @@ class CurveAMM$8 {
|
|
|
42018
42018
|
if (typeof price === 'bigint') {
|
|
42019
42019
|
price = price.toString();
|
|
42020
42020
|
}
|
|
42021
|
-
const priceDecimal = new Decimal$
|
|
42021
|
+
const priceDecimal = new Decimal$2(price);
|
|
42022
42022
|
return priceDecimal.div(this.PRICE_PRECISION_FACTOR_DECIMAL);
|
|
42023
42023
|
}
|
|
42024
42024
|
|
|
@@ -42068,9 +42068,9 @@ class CurveAMM$8 {
|
|
|
42068
42068
|
if (typeof price === 'bigint') {
|
|
42069
42069
|
price = price.toString();
|
|
42070
42070
|
}
|
|
42071
|
-
const priceDecimal = new Decimal$
|
|
42071
|
+
const priceDecimal = new Decimal$2(price);
|
|
42072
42072
|
// Use old precision factor 10^15
|
|
42073
|
-
const oldPrecisionFactor = new Decimal$
|
|
42073
|
+
const oldPrecisionFactor = new Decimal$2('1000000000000000');
|
|
42074
42074
|
return priceDecimal.div(oldPrecisionFactor);
|
|
42075
42075
|
}
|
|
42076
42076
|
|
|
@@ -42083,7 +42083,7 @@ class CurveAMM$8 {
|
|
|
42083
42083
|
*/
|
|
42084
42084
|
static decimalToU64(price) {
|
|
42085
42085
|
// Directly use old precision factor for conversion
|
|
42086
|
-
const oldPrecisionFactor = new Decimal$
|
|
42086
|
+
const oldPrecisionFactor = new Decimal$2('1000000000000000');
|
|
42087
42087
|
const scaled = price.mul(oldPrecisionFactor);
|
|
42088
42088
|
const floored = scaled.floor();
|
|
42089
42089
|
if (floored.isNaN() || floored.isNegative() || floored.gt('18446744073709551615')) {
|
|
@@ -42102,7 +42102,7 @@ class CurveAMM$8 {
|
|
|
42102
42102
|
*/
|
|
42103
42103
|
static decimalToU64Ceil(price) {
|
|
42104
42104
|
// Directly use old precision factor for conversion
|
|
42105
|
-
const oldPrecisionFactor = new Decimal$
|
|
42105
|
+
const oldPrecisionFactor = new Decimal$2('1000000000000000');
|
|
42106
42106
|
const scaled = price.mul(oldPrecisionFactor);
|
|
42107
42107
|
const ceiled = scaled.ceil();
|
|
42108
42108
|
if (ceiled.isNaN() || ceiled.isNegative() || ceiled.gt('18446744073709551615')) {
|
|
@@ -42186,7 +42186,7 @@ class CurveAMM$8 {
|
|
|
42186
42186
|
if (typeof amount === 'bigint') {
|
|
42187
42187
|
amount = amount.toString();
|
|
42188
42188
|
}
|
|
42189
|
-
const amountDecimal = new Decimal$
|
|
42189
|
+
const amountDecimal = new Decimal$2(amount);
|
|
42190
42190
|
return amountDecimal.div(this.TOKEN_PRECISION_FACTOR_DECIMAL);
|
|
42191
42191
|
}
|
|
42192
42192
|
|
|
@@ -42200,7 +42200,7 @@ class CurveAMM$8 {
|
|
|
42200
42200
|
if (typeof amount === 'bigint') {
|
|
42201
42201
|
amount = amount.toString();
|
|
42202
42202
|
}
|
|
42203
|
-
const amountDecimal = new Decimal$
|
|
42203
|
+
const amountDecimal = new Decimal$2(amount);
|
|
42204
42204
|
return amountDecimal.div(this.SOL_PRECISION_FACTOR_DECIMAL);
|
|
42205
42205
|
}
|
|
42206
42206
|
|
|
@@ -42218,8 +42218,8 @@ class CurveAMM$8 {
|
|
|
42218
42218
|
* const k2 = CurveAMM.calculateK(60, 1073000000);
|
|
42219
42219
|
*/
|
|
42220
42220
|
static calculateK(initialVirtualSol, initialVirtualToken) {
|
|
42221
|
-
const sol = new Decimal$
|
|
42222
|
-
const token = new Decimal$
|
|
42221
|
+
const sol = new Decimal$2(initialVirtualSol);
|
|
42222
|
+
const token = new Decimal$2(initialVirtualToken);
|
|
42223
42223
|
return sol.mul(token);
|
|
42224
42224
|
}
|
|
42225
42225
|
|
|
@@ -42241,8 +42241,8 @@ class CurveAMM$8 {
|
|
|
42241
42241
|
* @returns {bigint|null} u128格式的初始价格
|
|
42242
42242
|
*/
|
|
42243
42243
|
static getInitialPriceWithParams(initialVirtualSol, initialVirtualToken) {
|
|
42244
|
-
const sol = new Decimal$
|
|
42245
|
-
const token = new Decimal$
|
|
42244
|
+
const sol = new Decimal$2(initialVirtualSol);
|
|
42245
|
+
const token = new Decimal$2(initialVirtualToken);
|
|
42246
42246
|
const initialPrice = sol.div(token);
|
|
42247
42247
|
return this.decimalToU128(initialPrice);
|
|
42248
42248
|
}
|
|
@@ -42485,7 +42485,7 @@ class CurveAMM$8 {
|
|
|
42485
42485
|
}
|
|
42486
42486
|
|
|
42487
42487
|
// Warning for extremely small prices that may have precision issues
|
|
42488
|
-
const warningPrice = new Decimal$
|
|
42488
|
+
const warningPrice = new Decimal$2('0.0000001'); // 10^-7
|
|
42489
42489
|
if (price.lt(warningPrice)) {
|
|
42490
42490
|
// Only log once per execution to avoid spam (use a static flag)
|
|
42491
42491
|
if (!this._tinyPriceWarningShown) {
|
|
@@ -43028,6 +43028,36 @@ class CurveAMM$8 {
|
|
|
43028
43028
|
}
|
|
43029
43029
|
}
|
|
43030
43030
|
|
|
43031
|
+
/**
|
|
43032
|
+
* Calculate total amount including fee (with ceiling division, matching Rust contract)
|
|
43033
|
+
*
|
|
43034
|
+
* @param {bigint|string|number} solAmount - Net amount (base amount)
|
|
43035
|
+
* @param {number} fee - Fee rate, expressed with FEE_DENOMINATOR as denominator
|
|
43036
|
+
* Example: 1000 represents 1% fee (1000/100000)
|
|
43037
|
+
* 2000 represents 2% fee (2000/100000)
|
|
43038
|
+
* @returns {bigint|null} Returns total amount including fee on success, null on failure
|
|
43039
|
+
* Total amount calculation uses ceiling division (rounding up), matching Rust contract behavior
|
|
43040
|
+
*/
|
|
43041
|
+
static calculateTotalAmountWithFee(solAmount, fee) {
|
|
43042
|
+
try {
|
|
43043
|
+
const amount = BigInt(solAmount.toString());
|
|
43044
|
+
const feeBig = BigInt(fee);
|
|
43045
|
+
|
|
43046
|
+
// Check if fee rate is valid (must be less than or equal to 10%)
|
|
43047
|
+
if (feeBig > MAX_FEE_RATE) {
|
|
43048
|
+
return null;
|
|
43049
|
+
}
|
|
43050
|
+
|
|
43051
|
+
// Ceiling division: (amount * (FEE_DENOMINATOR + fee) + FEE_DENOMINATOR - 1) / FEE_DENOMINATOR
|
|
43052
|
+
const numerator = amount * (FEE_DENOMINATOR + feeBig);
|
|
43053
|
+
const totalAmount = (numerator + FEE_DENOMINATOR - 1n) / FEE_DENOMINATOR;
|
|
43054
|
+
|
|
43055
|
+
return totalAmount;
|
|
43056
|
+
} catch (error) {
|
|
43057
|
+
return null;
|
|
43058
|
+
}
|
|
43059
|
+
}
|
|
43060
|
+
|
|
43031
43061
|
/**
|
|
43032
43062
|
* Convert u128 price to readable decimal string format for display
|
|
43033
43063
|
*
|
|
@@ -43039,7 +43069,7 @@ class CurveAMM$8 {
|
|
|
43039
43069
|
if (typeof price === 'bigint') {
|
|
43040
43070
|
price = price.toString();
|
|
43041
43071
|
}
|
|
43042
|
-
const priceDecimal = new Decimal$
|
|
43072
|
+
const priceDecimal = new Decimal$2(price);
|
|
43043
43073
|
const convertedPrice = priceDecimal.div(this.PRICE_PRECISION_FACTOR_DECIMAL);
|
|
43044
43074
|
return convertedPrice.toFixed(decimalPlaces);
|
|
43045
43075
|
}
|
|
@@ -45058,6 +45088,7 @@ jsonBigint.exports.stringify = json_stringify;
|
|
|
45058
45088
|
|
|
45059
45089
|
var jsonBigintExports = jsonBigint.exports;
|
|
45060
45090
|
|
|
45091
|
+
const Decimal$1 = decimalExports;
|
|
45061
45092
|
const CurveAMM$6 = curve_amm;
|
|
45062
45093
|
const {transformOrdersData , checkPriceRangeOverlap} = stop_loss_utils;
|
|
45063
45094
|
const { PRICE_ADJUSTMENT_PERCENTAGE, MIN_STOP_LOSS_PERCENT } = utils$2;
|
|
@@ -45183,13 +45214,23 @@ jsonBigintExports({ storeAsString: false });
|
|
|
45183
45214
|
* @since 2.0.0
|
|
45184
45215
|
* @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
|
|
45185
45216
|
*/
|
|
45186
|
-
async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee =
|
|
45217
|
+
async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
|
|
45187
45218
|
try {
|
|
45188
45219
|
// Parameter validation
|
|
45189
45220
|
if (!mint || !buyTokenAmount || !stopLossPrice) {
|
|
45190
45221
|
throw new Error('Missing required parameters');
|
|
45191
45222
|
}
|
|
45192
45223
|
|
|
45224
|
+
// 如果没有传入 borrowFee 或池子参数,从链上一次性获取
|
|
45225
|
+
if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
|
|
45226
|
+
const curveAccount = await this.sdk.chain.getCurveAccount(mint);
|
|
45227
|
+
if (borrowFee === null) borrowFee = curveAccount.borrowFee;
|
|
45228
|
+
// 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
|
|
45229
|
+
// 与 calcLiq.js 中的转换方式一致
|
|
45230
|
+
if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
|
|
45231
|
+
if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
|
|
45232
|
+
}
|
|
45233
|
+
|
|
45193
45234
|
// Get current price
|
|
45194
45235
|
if (!lastPrice) {
|
|
45195
45236
|
//console.log('Getting current price...');
|
|
@@ -45266,7 +45307,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
|
|
|
45266
45307
|
// console.log(` - buyTokenAmount: ${buyTokenAmount.toString()}`);
|
|
45267
45308
|
// console.log(` - Calling CurveAMM.sellFromPriceWithTokenInput...`);
|
|
45268
45309
|
|
|
45269
|
-
const tradeResult = CurveAMM$6.
|
|
45310
|
+
const tradeResult = CurveAMM$6.sellFromPriceWithTokenInputWithParams(stopLossStartPrice, buyTokenAmount, initialVirtualSol, initialVirtualToken);
|
|
45270
45311
|
|
|
45271
45312
|
//console.log(` - tradeResult:`, tradeResult);
|
|
45272
45313
|
|
|
@@ -45330,10 +45371,10 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
|
|
|
45330
45371
|
let estimatedMargin = 0n;
|
|
45331
45372
|
try {
|
|
45332
45373
|
// 1. 计算从当前价格买入所需的SOL
|
|
45333
|
-
const buyResult = CurveAMM$6.
|
|
45374
|
+
const buyResult = CurveAMM$6.buyFromPriceWithTokenOutputWithParams(currentPrice, buyTokenAmount, initialVirtualSol, initialVirtualToken);
|
|
45334
45375
|
if (buyResult) {
|
|
45335
45376
|
const requiredSol = buyResult[1]; // SOL input amount
|
|
45336
|
-
|
|
45377
|
+
|
|
45337
45378
|
// 2. 计算平仓时扣除手续费后的收益
|
|
45338
45379
|
const closeOutputSolAfterFee = CurveAMM$6.calculateAmountAfterFee(finalTradeAmount, borrowFee);
|
|
45339
45380
|
|
|
@@ -45493,13 +45534,23 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
|
|
|
45493
45534
|
* @since 2.0.0
|
|
45494
45535
|
* @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
|
|
45495
45536
|
*/
|
|
45496
|
-
async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee =
|
|
45537
|
+
async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
|
|
45497
45538
|
try {
|
|
45498
45539
|
// Parameter validation
|
|
45499
45540
|
if (!mint || !sellTokenAmount || !stopLossPrice) {
|
|
45500
45541
|
throw new Error('Missing required parameters');
|
|
45501
45542
|
}
|
|
45502
45543
|
|
|
45544
|
+
// 如果没有传入 borrowFee 或池子参数,从链上一次性获取
|
|
45545
|
+
if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
|
|
45546
|
+
const curveAccount = await this.sdk.chain.getCurveAccount(mint);
|
|
45547
|
+
if (borrowFee === null) borrowFee = curveAccount.borrowFee;
|
|
45548
|
+
// 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
|
|
45549
|
+
// 与 calcLiq.js 中的转换方式一致
|
|
45550
|
+
if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
|
|
45551
|
+
if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
|
|
45552
|
+
}
|
|
45553
|
+
|
|
45503
45554
|
// Get current price
|
|
45504
45555
|
if (!lastPrice) {
|
|
45505
45556
|
//console.log('Getting current price...');
|
|
@@ -45569,7 +45620,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45569
45620
|
// console.log(` - sellTokenAmount: ${sellTokenAmount.toString()}`);
|
|
45570
45621
|
// console.log(` - Calling CurveAMM.buyFromPriceWithTokenOutput...`);
|
|
45571
45622
|
|
|
45572
|
-
const tradeResult = CurveAMM$6.
|
|
45623
|
+
const tradeResult = CurveAMM$6.buyFromPriceWithTokenOutputWithParams(stopLossStartPrice, sellTokenAmount, initialVirtualSol, initialVirtualToken);
|
|
45573
45624
|
|
|
45574
45625
|
//console.log(` - tradeResult:`, tradeResult);
|
|
45575
45626
|
|
|
@@ -45629,24 +45680,24 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45629
45680
|
const leverage = Number((BigInt(10000) * currentPrice) / (executableStopLossPrice - currentPrice)) / 10000;
|
|
45630
45681
|
|
|
45631
45682
|
// 计算保证金 / Calculate margin requirement
|
|
45683
|
+
// 与合约公式一致 (long_short.rs 第890-894行):
|
|
45684
|
+
// real_margin_sol = close_buy_sol_with_fee - output_sol - fee_sol
|
|
45685
|
+
// 其中 output_sol 是扣费后净SOL, fee_sol 是开仓手续费
|
|
45686
|
+
// 展开: real_margin_sol = close_buy_sol_with_fee - raw_sell_sol
|
|
45632
45687
|
let estimatedMargin = 0n;
|
|
45688
|
+
let rawSellSol = 0n; // 卖出 token 获得的原始 SOL(未扣费),供调用方计算 minSolOutput
|
|
45633
45689
|
try {
|
|
45634
|
-
// 1.
|
|
45635
|
-
const sellResult = CurveAMM$6.
|
|
45690
|
+
// 1. 计算从当前价格卖出代币获得的原始SOL(未扣费)
|
|
45691
|
+
const sellResult = CurveAMM$6.sellFromPriceWithTokenInputWithParams(currentPrice, sellTokenAmount, initialVirtualSol, initialVirtualToken);
|
|
45636
45692
|
if (sellResult) {
|
|
45637
|
-
|
|
45638
|
-
|
|
45639
|
-
// 2.
|
|
45640
|
-
const
|
|
45641
|
-
|
|
45642
|
-
// 3.
|
|
45643
|
-
|
|
45644
|
-
|
|
45645
|
-
|
|
45646
|
-
// 4. 计算保证金 = 平仓成本(含手续费) + 开仓手续费 - 开仓收益
|
|
45647
|
-
// 开仓手续费是支出,应该加到成本中
|
|
45648
|
-
if (closeCostWithFee + openingFee > openingSolGain) {
|
|
45649
|
-
estimatedMargin = closeCostWithFee + openingFee - openingSolGain;
|
|
45693
|
+
rawSellSol = sellResult[1]; // 卖出获得的原始SOL(未扣费)
|
|
45694
|
+
|
|
45695
|
+
// 2. 计算平仓成本(含手续费,使用 ceiling 除法与合约一致)
|
|
45696
|
+
const closeCostWithFee = CurveAMM$6.calculateTotalAmountWithFee(finalTradeAmount, borrowFee);
|
|
45697
|
+
|
|
45698
|
+
// 3. 保证金 = 平仓成本(含费) - 原始卖出SOL
|
|
45699
|
+
if (closeCostWithFee !== null && closeCostWithFee > rawSellSol) {
|
|
45700
|
+
estimatedMargin = closeCostWithFee - rawSellSol;
|
|
45650
45701
|
}
|
|
45651
45702
|
}
|
|
45652
45703
|
} catch (marginError) {
|
|
@@ -45663,14 +45714,15 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45663
45714
|
|
|
45664
45715
|
return {
|
|
45665
45716
|
executableStopLossPrice: executableStopLossPrice, // Calculated reasonable stop loss value
|
|
45666
|
-
tradeAmount: finalTradeAmount, // SOL input amount
|
|
45717
|
+
tradeAmount: finalTradeAmount, // SOL input amount (平仓时买回 token 需要的 SOL)
|
|
45667
45718
|
stopLossPercentage: stopLossPercentage, // Stop loss percentage relative to current price
|
|
45668
45719
|
leverage: leverage, // Leverage ratio
|
|
45669
45720
|
currentPrice: currentPrice, // Current price
|
|
45670
45721
|
iterations: iteration, // Number of adjustments
|
|
45671
45722
|
originalStopLossPrice: BigInt(stopLossPrice), // Original stop loss price
|
|
45672
45723
|
close_insert_indices: finalOverlapResult.close_insert_indices, // Candidate insertion indices for closing order
|
|
45673
|
-
estimatedMargin: estimatedMargin // Estimated margin requirement in SOL (lamports)
|
|
45724
|
+
estimatedMargin: estimatedMargin, // Estimated margin requirement in SOL (lamports)
|
|
45725
|
+
rawSellSol: rawSellSol // 卖出 token 获得的原始 SOL(未扣费),用于调用方计算 minSolOutput
|
|
45674
45726
|
};
|
|
45675
45727
|
|
|
45676
45728
|
} catch (error) {
|
|
@@ -45739,13 +45791,23 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
|
|
|
45739
45791
|
* @since 2.0.0
|
|
45740
45792
|
* @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
|
|
45741
45793
|
*/
|
|
45742
|
-
async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee =
|
|
45794
|
+
async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
|
|
45743
45795
|
try {
|
|
45744
45796
|
// Parameter validation
|
|
45745
45797
|
if (!mint || !buySolAmount || !stopLossPrice) {
|
|
45746
45798
|
throw new Error('Missing required parameters');
|
|
45747
45799
|
}
|
|
45748
45800
|
|
|
45801
|
+
// 如果没有传入 borrowFee 或池子参数,从链上一次性获取
|
|
45802
|
+
if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
|
|
45803
|
+
const curveAccount = await this.sdk.chain.getCurveAccount(mint);
|
|
45804
|
+
if (borrowFee === null) borrowFee = curveAccount.borrowFee;
|
|
45805
|
+
// 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
|
|
45806
|
+
// 与 calcLiq.js 中的转换方式一致
|
|
45807
|
+
if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
|
|
45808
|
+
if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
|
|
45809
|
+
}
|
|
45810
|
+
|
|
45749
45811
|
// Get current price if not provided
|
|
45750
45812
|
let currentPrice;
|
|
45751
45813
|
if (!lastPrice) {
|
|
@@ -45767,7 +45829,7 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
|
|
|
45767
45829
|
|
|
45768
45830
|
// Calculate initial token amount from SOL amount using sellFromPriceWithSolOutput
|
|
45769
45831
|
// This gives us how many tokens we can get when we later sell for buySolAmount SOL
|
|
45770
|
-
const initialResult = CurveAMM$6.
|
|
45832
|
+
const initialResult = CurveAMM$6.sellFromPriceWithSolOutputWithParams(currentPrice, buySolAmount, initialVirtualSol, initialVirtualToken);
|
|
45771
45833
|
if (!initialResult) {
|
|
45772
45834
|
throw new Error('Failed to calculate token amount from SOL amount');
|
|
45773
45835
|
}
|
|
@@ -45799,7 +45861,7 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
|
|
|
45799
45861
|
const mid = (left + right) / 2n;
|
|
45800
45862
|
|
|
45801
45863
|
// 计算当前 token 数量的结果
|
|
45802
|
-
const currentResult = await simulateLongStopLoss$1.call(this, mint, mid, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
45864
|
+
const currentResult = await simulateLongStopLoss$1.call(this, mint, mid, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken);
|
|
45803
45865
|
const currentMargin = currentResult.estimatedMargin;
|
|
45804
45866
|
|
|
45805
45867
|
//console.log(`Binary search iteration ${iterations}: tokenAmount=${mid}, estimatedMargin=${currentMargin}, target=${buySolAmount}`);
|
|
@@ -45841,7 +45903,7 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
|
|
|
45841
45903
|
//console.log(`No valid solution found (estimatedMargin < buySolAmount), using minimal tokenAmount`);
|
|
45842
45904
|
buyTokenAmount = buyTokenAmount / 10n; // 使用更小的值
|
|
45843
45905
|
if (buyTokenAmount <= 0n) buyTokenAmount = 1000000000n; // 最小值保护 (0.001 token with 9 decimals)
|
|
45844
|
-
stopLossResult = await simulateLongStopLoss$1.call(this, mint, buyTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
45906
|
+
stopLossResult = await simulateLongStopLoss$1.call(this, mint, buyTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken);
|
|
45845
45907
|
}
|
|
45846
45908
|
|
|
45847
45909
|
// if (iterations >= maxIterations) {
|
|
@@ -45913,13 +45975,23 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
|
|
|
45913
45975
|
* @since 2.0.0
|
|
45914
45976
|
* @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
|
|
45915
45977
|
*/
|
|
45916
|
-
async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee =
|
|
45978
|
+
async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
|
|
45917
45979
|
try {
|
|
45918
45980
|
// Parameter validation
|
|
45919
45981
|
if (!mint || !sellSolAmount || !stopLossPrice) {
|
|
45920
45982
|
throw new Error('Missing required parameters');
|
|
45921
45983
|
}
|
|
45922
45984
|
|
|
45985
|
+
// 如果没有传入 borrowFee 或池子参数,从链上一次性获取
|
|
45986
|
+
if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
|
|
45987
|
+
const curveAccount = await this.sdk.chain.getCurveAccount(mint);
|
|
45988
|
+
if (borrowFee === null) borrowFee = curveAccount.borrowFee;
|
|
45989
|
+
// 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
|
|
45990
|
+
// 与 calcLiq.js 中的转换方式一致
|
|
45991
|
+
if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
|
|
45992
|
+
if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
|
|
45993
|
+
}
|
|
45994
|
+
|
|
45923
45995
|
// Get current price if not provided
|
|
45924
45996
|
let currentPrice;
|
|
45925
45997
|
if (!lastPrice) {
|
|
@@ -45943,7 +46015,7 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
|
|
|
45943
46015
|
|
|
45944
46016
|
// Calculate initial token amount from SOL amount using buyFromPriceWithSolInput
|
|
45945
46017
|
// This gives us how many tokens we need to buy later using sellSolAmount SOL
|
|
45946
|
-
const initialResult = CurveAMM$6.
|
|
46018
|
+
const initialResult = CurveAMM$6.buyFromPriceWithSolInputWithParams(currentPrice, sellSolAmount, initialVirtualSol, initialVirtualToken);
|
|
45947
46019
|
if (!initialResult) {
|
|
45948
46020
|
throw new Error('Failed to calculate token amount from SOL amount');
|
|
45949
46021
|
}
|
|
@@ -45975,7 +46047,7 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
|
|
|
45975
46047
|
const mid = (left + right) / 2n;
|
|
45976
46048
|
|
|
45977
46049
|
// 计算当前 token 数量的结果
|
|
45978
|
-
const currentResult = await simulateShortStopLoss$1.call(this, mint, mid, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
46050
|
+
const currentResult = await simulateShortStopLoss$1.call(this, mint, mid, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken);
|
|
45979
46051
|
const currentMargin = currentResult.estimatedMargin;
|
|
45980
46052
|
|
|
45981
46053
|
//console.log(`Binary search iteration ${iterations}: tokenAmount=${mid}, estimatedMargin=${currentMargin}, target=${sellSolAmount}`);
|
|
@@ -46017,7 +46089,7 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
|
|
|
46017
46089
|
//console.log(`No valid solution found (estimatedMargin < sellSolAmount), using minimal tokenAmount`);
|
|
46018
46090
|
sellTokenAmount = sellTokenAmount / 10n; // 使用更小的值
|
|
46019
46091
|
if (sellTokenAmount <= 0n) sellTokenAmount = 1000000000n; // 最小值保护 (0.001 token with 9 decimals)
|
|
46020
|
-
stopLossResult = await simulateShortStopLoss$1.call(this, mint, sellTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
46092
|
+
stopLossResult = await simulateShortStopLoss$1.call(this, mint, sellTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken);
|
|
46021
46093
|
}
|
|
46022
46094
|
|
|
46023
46095
|
// if (iterations >= maxIterations) {
|
|
@@ -47711,8 +47783,8 @@ class SimulatorModule$1 {
|
|
|
47711
47783
|
* @param {Object|null} ordersData - Orders data, default null
|
|
47712
47784
|
* @returns {Promise<Object>} Stop loss analysis result
|
|
47713
47785
|
*/
|
|
47714
|
-
async simulateLongStopLoss(mint, buyTokenAmount, stopLossPrice, lastPrice = null, ordersData = null) {
|
|
47715
|
-
return simulateLongStopLoss.call(this, mint, buyTokenAmount, stopLossPrice, lastPrice, ordersData);
|
|
47786
|
+
async simulateLongStopLoss(mint, buyTokenAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
|
|
47787
|
+
return simulateLongStopLoss.call(this, mint, buyTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
47716
47788
|
}
|
|
47717
47789
|
|
|
47718
47790
|
/**
|
|
@@ -47724,8 +47796,8 @@ class SimulatorModule$1 {
|
|
|
47724
47796
|
* @param {Object|null} ordersData - Orders data, default null
|
|
47725
47797
|
* @returns {Promise<Object>} Stop loss analysis result
|
|
47726
47798
|
*/
|
|
47727
|
-
async simulateShortStopLoss(mint, sellTokenAmount, stopLossPrice, lastPrice = null, ordersData = null) {
|
|
47728
|
-
return simulateShortStopLoss.call(this, mint, sellTokenAmount, stopLossPrice, lastPrice, ordersData);
|
|
47799
|
+
async simulateShortStopLoss(mint, sellTokenAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
|
|
47800
|
+
return simulateShortStopLoss.call(this, mint, sellTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
47729
47801
|
}
|
|
47730
47802
|
|
|
47731
47803
|
/**
|
|
@@ -47738,7 +47810,7 @@ class SimulatorModule$1 {
|
|
|
47738
47810
|
* @param {number} borrowFee - Borrow fee rate, default 2000 (2000/100000 = 0.02%)
|
|
47739
47811
|
* @returns {Promise<Object>} Stop loss analysis result (same as simulateLongStopLoss)
|
|
47740
47812
|
*/
|
|
47741
|
-
async simulateLongSolStopLoss(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee =
|
|
47813
|
+
async simulateLongSolStopLoss(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
|
|
47742
47814
|
return simulateLongSolStopLoss.call(this, mint, buySolAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
47743
47815
|
}
|
|
47744
47816
|
|
|
@@ -47752,7 +47824,7 @@ class SimulatorModule$1 {
|
|
|
47752
47824
|
* @param {number} borrowFee - Borrow fee rate, default 2000 (2000/100000 = 0.02%)
|
|
47753
47825
|
* @returns {Promise<Object>} Stop loss analysis result (same as simulateShortStopLoss)
|
|
47754
47826
|
*/
|
|
47755
|
-
async simulateShortSolStopLoss(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee =
|
|
47827
|
+
async simulateShortSolStopLoss(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
|
|
47756
47828
|
return simulateShortSolStopLoss.call(this, mint, sellSolAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
|
|
47757
47829
|
}
|
|
47758
47830
|
|
|
@@ -49688,7 +49760,7 @@ class OrderUtils$2 {
|
|
|
49688
49760
|
|
|
49689
49761
|
var orderUtils = OrderUtils$2;
|
|
49690
49762
|
|
|
49691
|
-
var address = "
|
|
49763
|
+
var address = "CYdRzRacZ5kTc9Ht3U7mFhbsyxG3sZGEzC4cNf2Gjg2W";
|
|
49692
49764
|
var metadata = {
|
|
49693
49765
|
name: "pinpet",
|
|
49694
49766
|
version: "0.1.0",
|
|
@@ -52262,471 +52334,476 @@ var errors = [
|
|
|
52262
52334
|
},
|
|
52263
52335
|
{
|
|
52264
52336
|
code: 6021,
|
|
52337
|
+
name: "CloseShortImpossibleState",
|
|
52338
|
+
msg: "Close short impossible state: current_total should always be greater than remaining_close_reduced_sol_with_fee"
|
|
52339
|
+
},
|
|
52340
|
+
{
|
|
52341
|
+
code: 6022,
|
|
52265
52342
|
name: "FeeSplitCalculationOverflow",
|
|
52266
52343
|
msg: "Fee split calculation overflow"
|
|
52267
52344
|
},
|
|
52268
52345
|
{
|
|
52269
|
-
code:
|
|
52346
|
+
code: 6023,
|
|
52270
52347
|
name: "FeeAccumulationOverflow",
|
|
52271
52348
|
msg: "Fee accumulation overflow"
|
|
52272
52349
|
},
|
|
52273
52350
|
{
|
|
52274
|
-
code:
|
|
52351
|
+
code: 6024,
|
|
52275
52352
|
name: "PartnerFeeAdditionOverflow",
|
|
52276
52353
|
msg: "Partner fee addition overflow"
|
|
52277
52354
|
},
|
|
52278
52355
|
{
|
|
52279
|
-
code:
|
|
52356
|
+
code: 6025,
|
|
52280
52357
|
name: "BaseFeeAdditionOverflow",
|
|
52281
52358
|
msg: "Base fee addition overflow"
|
|
52282
52359
|
},
|
|
52283
52360
|
{
|
|
52284
|
-
code:
|
|
52361
|
+
code: 6026,
|
|
52285
52362
|
name: "PoolFeeDeductionOverflow",
|
|
52286
52363
|
msg: "Pool fee deduction overflow"
|
|
52287
52364
|
},
|
|
52288
52365
|
{
|
|
52289
|
-
code:
|
|
52366
|
+
code: 6027,
|
|
52290
52367
|
name: "FeeRandomDiscountOverflow",
|
|
52291
52368
|
msg: "Fee random discount calculation overflow"
|
|
52292
52369
|
},
|
|
52293
52370
|
{
|
|
52294
|
-
code:
|
|
52371
|
+
code: 6028,
|
|
52295
52372
|
name: "SolReserveAdditionOverflow",
|
|
52296
52373
|
msg: "SOL reserve addition overflow"
|
|
52297
52374
|
},
|
|
52298
52375
|
{
|
|
52299
|
-
code:
|
|
52376
|
+
code: 6029,
|
|
52300
52377
|
name: "SolReserveDeductionOverflow",
|
|
52301
52378
|
msg: "SOL reserve deduction overflow"
|
|
52302
52379
|
},
|
|
52303
52380
|
{
|
|
52304
|
-
code:
|
|
52381
|
+
code: 6030,
|
|
52305
52382
|
name: "TokenReserveAdditionOverflow",
|
|
52306
52383
|
msg: "Token reserve addition overflow"
|
|
52307
52384
|
},
|
|
52308
52385
|
{
|
|
52309
|
-
code:
|
|
52386
|
+
code: 6031,
|
|
52310
52387
|
name: "LamportsAdditionOverflow",
|
|
52311
52388
|
msg: "Lamports addition overflow"
|
|
52312
52389
|
},
|
|
52313
52390
|
{
|
|
52314
|
-
code:
|
|
52391
|
+
code: 6032,
|
|
52315
52392
|
name: "LamportsDeductionOverflow",
|
|
52316
52393
|
msg: "Lamports deduction overflow"
|
|
52317
52394
|
},
|
|
52318
52395
|
{
|
|
52319
|
-
code:
|
|
52396
|
+
code: 6033,
|
|
52320
52397
|
name: "DeadlineCalculationOverflow",
|
|
52321
52398
|
msg: "Deadline calculation overflow"
|
|
52322
52399
|
},
|
|
52323
52400
|
{
|
|
52324
|
-
code:
|
|
52401
|
+
code: 6034,
|
|
52325
52402
|
name: "FeeDiscountFlagOverflow",
|
|
52326
52403
|
msg: "Fee discount flag calculation overflow"
|
|
52327
52404
|
},
|
|
52328
52405
|
{
|
|
52329
|
-
code:
|
|
52406
|
+
code: 6035,
|
|
52330
52407
|
name: "Unauthorized",
|
|
52331
52408
|
msg: "Unauthorized operation"
|
|
52332
52409
|
},
|
|
52333
52410
|
{
|
|
52334
|
-
code:
|
|
52411
|
+
code: 6036,
|
|
52335
52412
|
name: "RequiredParameter",
|
|
52336
52413
|
msg: "All parameters are required during initialization"
|
|
52337
52414
|
},
|
|
52338
52415
|
{
|
|
52339
|
-
code:
|
|
52416
|
+
code: 6037,
|
|
52340
52417
|
name: "CurveCalculationError",
|
|
52341
52418
|
msg: "Curve calculation error"
|
|
52342
52419
|
},
|
|
52343
52420
|
{
|
|
52344
|
-
code:
|
|
52421
|
+
code: 6038,
|
|
52345
52422
|
name: "InitialPriceCalculationError",
|
|
52346
52423
|
msg: "Initial price calculation failed"
|
|
52347
52424
|
},
|
|
52348
52425
|
{
|
|
52349
|
-
code:
|
|
52426
|
+
code: 6039,
|
|
52350
52427
|
name: "BuyReserveRecalculationError",
|
|
52351
52428
|
msg: "Reserve recalculation failed (after buy)"
|
|
52352
52429
|
},
|
|
52353
52430
|
{
|
|
52354
|
-
code:
|
|
52431
|
+
code: 6040,
|
|
52355
52432
|
name: "SellReserveRecalculationError",
|
|
52356
52433
|
msg: "Reserve recalculation failed (after sell)"
|
|
52357
52434
|
},
|
|
52358
52435
|
{
|
|
52359
|
-
code:
|
|
52436
|
+
code: 6041,
|
|
52360
52437
|
name: "TotalAmountWithFeeError",
|
|
52361
52438
|
msg: "Total amount with fee calculation failed"
|
|
52362
52439
|
},
|
|
52363
52440
|
{
|
|
52364
|
-
code:
|
|
52441
|
+
code: 6042,
|
|
52365
52442
|
name: "AmountAfterFeeError",
|
|
52366
52443
|
msg: "Amount after fee calculation failed"
|
|
52367
52444
|
},
|
|
52368
52445
|
{
|
|
52369
|
-
code:
|
|
52446
|
+
code: 6043,
|
|
52370
52447
|
name: "BuyPriceRangeCalculationError",
|
|
52371
52448
|
msg: "Buy price range calculation failed"
|
|
52372
52449
|
},
|
|
52373
52450
|
{
|
|
52374
|
-
code:
|
|
52451
|
+
code: 6044,
|
|
52375
52452
|
name: "SellPriceRangeCalculationError",
|
|
52376
52453
|
msg: "Sell price range calculation failed"
|
|
52377
52454
|
},
|
|
52378
52455
|
{
|
|
52379
|
-
code:
|
|
52456
|
+
code: 6045,
|
|
52380
52457
|
name: "PriceAtStopLossBoundary",
|
|
52381
52458
|
msg: "Price has reached stop-loss boundary, head order must be liquidated first"
|
|
52382
52459
|
},
|
|
52383
52460
|
{
|
|
52384
|
-
code:
|
|
52461
|
+
code: 6046,
|
|
52385
52462
|
name: "RemainingRangeCalculationError",
|
|
52386
52463
|
msg: "Remaining range calculation failed"
|
|
52387
52464
|
},
|
|
52388
52465
|
{
|
|
52389
|
-
code:
|
|
52466
|
+
code: 6047,
|
|
52390
52467
|
name: "FullRangeCalculationError",
|
|
52391
52468
|
msg: "Full range calculation failed"
|
|
52392
52469
|
},
|
|
52393
52470
|
{
|
|
52394
|
-
code:
|
|
52471
|
+
code: 6048,
|
|
52395
52472
|
name: "BuyFromPriceWithTokenNoneError",
|
|
52396
52473
|
msg: "Curve function returned None: buy_from_price_with_token_output"
|
|
52397
52474
|
},
|
|
52398
52475
|
{
|
|
52399
|
-
code:
|
|
52476
|
+
code: 6049,
|
|
52400
52477
|
name: "SellFromPriceWithTokenNoneError",
|
|
52401
52478
|
msg: "Curve function returned None: sell_from_price_with_token_input"
|
|
52402
52479
|
},
|
|
52403
52480
|
{
|
|
52404
|
-
code:
|
|
52481
|
+
code: 6050,
|
|
52405
52482
|
name: "ExceedsMaxSolAmount",
|
|
52406
52483
|
msg: "Required SOL amount exceeds user-set maximum"
|
|
52407
52484
|
},
|
|
52408
52485
|
{
|
|
52409
|
-
code:
|
|
52486
|
+
code: 6051,
|
|
52410
52487
|
name: "InsufficientSolOutput",
|
|
52411
52488
|
msg: "Insufficient SOL output"
|
|
52412
52489
|
},
|
|
52413
52490
|
{
|
|
52414
|
-
code:
|
|
52491
|
+
code: 6052,
|
|
52415
52492
|
name: "InsufficientRepayment",
|
|
52416
52493
|
msg: "Insufficient proceeds to repay loan"
|
|
52417
52494
|
},
|
|
52418
52495
|
{
|
|
52419
|
-
code:
|
|
52496
|
+
code: 6053,
|
|
52420
52497
|
name: "InsufficientBorrowingReserve",
|
|
52421
52498
|
msg: "Insufficient borrowing reserve"
|
|
52422
52499
|
},
|
|
52423
52500
|
{
|
|
52424
|
-
code:
|
|
52501
|
+
code: 6054,
|
|
52425
52502
|
name: "InsufficientTokenSale",
|
|
52426
52503
|
msg: "Insufficient token sale amount"
|
|
52427
52504
|
},
|
|
52428
52505
|
{
|
|
52429
|
-
code:
|
|
52506
|
+
code: 6055,
|
|
52430
52507
|
name: "InsufficientLiquidity",
|
|
52431
52508
|
msg: "Insufficient liquidity in current order"
|
|
52432
52509
|
},
|
|
52433
52510
|
{
|
|
52434
|
-
code:
|
|
52511
|
+
code: 6056,
|
|
52435
52512
|
name: "InsufficientMarketLiquidity",
|
|
52436
52513
|
msg: "Insufficient market liquidity, cannot satisfy trade even after liquidating all stop-loss orders"
|
|
52437
52514
|
},
|
|
52438
52515
|
{
|
|
52439
|
-
code:
|
|
52516
|
+
code: 6057,
|
|
52440
52517
|
name: "TokenAmountDifferenceOutOfRange",
|
|
52441
52518
|
msg: "Token amount difference exceeds valid range in margin trade"
|
|
52442
52519
|
},
|
|
52443
52520
|
{
|
|
52444
|
-
code:
|
|
52521
|
+
code: 6058,
|
|
52445
52522
|
name: "BorrowAmountMismatch",
|
|
52446
52523
|
msg: "Borrow amount mismatch with locked tokens"
|
|
52447
52524
|
},
|
|
52448
52525
|
{
|
|
52449
|
-
code:
|
|
52526
|
+
code: 6059,
|
|
52450
52527
|
name: "CloseFeeCalculationError",
|
|
52451
52528
|
msg: "Close fee calculation error"
|
|
52452
52529
|
},
|
|
52453
52530
|
{
|
|
52454
|
-
code:
|
|
52531
|
+
code: 6060,
|
|
52455
52532
|
name: "InsufficientMargin",
|
|
52456
52533
|
msg: "Insufficient margin"
|
|
52457
52534
|
},
|
|
52458
52535
|
{
|
|
52459
|
-
code:
|
|
52536
|
+
code: 6061,
|
|
52460
52537
|
name: "InsufficientMinimumMargin",
|
|
52461
52538
|
msg: "Margin below minimum requirement"
|
|
52462
52539
|
},
|
|
52463
52540
|
{
|
|
52464
|
-
code:
|
|
52541
|
+
code: 6062,
|
|
52465
52542
|
name: "InvalidAccountOwner",
|
|
52466
52543
|
msg: "Invalid account owner"
|
|
52467
52544
|
},
|
|
52468
52545
|
{
|
|
52469
|
-
code:
|
|
52546
|
+
code: 6063,
|
|
52470
52547
|
name: "SellAmountExceedsOrderAmount",
|
|
52471
52548
|
msg: "Sell amount exceeds order's token holdings"
|
|
52472
52549
|
},
|
|
52473
52550
|
{
|
|
52474
|
-
code:
|
|
52551
|
+
code: 6064,
|
|
52475
52552
|
name: "OrderNotExpiredMustCloseByOwner",
|
|
52476
52553
|
msg: "Non-expired order must be closed by owner"
|
|
52477
52554
|
},
|
|
52478
52555
|
{
|
|
52479
|
-
code:
|
|
52556
|
+
code: 6065,
|
|
52480
52557
|
name: "SettlementAddressMustBeOwnerAddress",
|
|
52481
52558
|
msg: "Settlement address must be owner address"
|
|
52482
52559
|
},
|
|
52483
52560
|
{
|
|
52484
|
-
code:
|
|
52561
|
+
code: 6066,
|
|
52485
52562
|
name: "BuyAmountExceedsOrderAmount",
|
|
52486
52563
|
msg: "Buy amount exceeds order's token holdings"
|
|
52487
52564
|
},
|
|
52488
52565
|
{
|
|
52489
|
-
code:
|
|
52566
|
+
code: 6067,
|
|
52490
52567
|
name: "InsufficientTradeAmount",
|
|
52491
52568
|
msg: "Trade amount below minimum requirement"
|
|
52492
52569
|
},
|
|
52493
52570
|
{
|
|
52494
|
-
code:
|
|
52571
|
+
code: 6068,
|
|
52495
52572
|
name: "SolAmountTooLarge",
|
|
52496
52573
|
msg: "SOL amount exceeds maximum limit (10000000 SOL per transaction)"
|
|
52497
52574
|
},
|
|
52498
52575
|
{
|
|
52499
|
-
code:
|
|
52576
|
+
code: 6069,
|
|
52500
52577
|
name: "RemainingTokenAmountTooSmall",
|
|
52501
52578
|
msg: "Remaining token amount below minimum trade requirement"
|
|
52502
52579
|
},
|
|
52503
52580
|
{
|
|
52504
|
-
code:
|
|
52581
|
+
code: 6070,
|
|
52505
52582
|
name: "TradeCooldownNotExpired",
|
|
52506
52583
|
msg: "Trade cooldown period not expired, please try again later"
|
|
52507
52584
|
},
|
|
52508
52585
|
{
|
|
52509
|
-
code:
|
|
52586
|
+
code: 6071,
|
|
52510
52587
|
name: "ExceedApprovalAmount",
|
|
52511
52588
|
msg: "Sell amount exceeds approved amount, please call approval function first"
|
|
52512
52589
|
},
|
|
52513
52590
|
{
|
|
52514
|
-
code:
|
|
52591
|
+
code: 6072,
|
|
52515
52592
|
name: "CooldownNotInitialized",
|
|
52516
52593
|
msg: "Sell trade requires calling approval or buy function first to initialize cooldown PDA"
|
|
52517
52594
|
},
|
|
52518
52595
|
{
|
|
52519
|
-
code:
|
|
52596
|
+
code: 6073,
|
|
52520
52597
|
name: "CannotCloseCooldownWithBalance",
|
|
52521
52598
|
msg: "Cannot close cooldown PDA with non-zero token balance"
|
|
52522
52599
|
},
|
|
52523
52600
|
{
|
|
52524
|
-
code:
|
|
52601
|
+
code: 6074,
|
|
52525
52602
|
name: "PriceCalculationError",
|
|
52526
52603
|
msg: "Price calculation error"
|
|
52527
52604
|
},
|
|
52528
52605
|
{
|
|
52529
|
-
code:
|
|
52606
|
+
code: 6075,
|
|
52530
52607
|
name: "InvalidPartnerFeeRecipientAccount",
|
|
52531
52608
|
msg: "Invalid partner fee recipient account"
|
|
52532
52609
|
},
|
|
52533
52610
|
{
|
|
52534
|
-
code:
|
|
52611
|
+
code: 6076,
|
|
52535
52612
|
name: "InvalidBaseFeeRecipientAccount",
|
|
52536
52613
|
msg: "Invalid base fee recipient account"
|
|
52537
52614
|
},
|
|
52538
52615
|
{
|
|
52539
|
-
code:
|
|
52616
|
+
code: 6077,
|
|
52540
52617
|
name: "InvalidOrderbookAddress",
|
|
52541
52618
|
msg: "Orderbook address does not match curve account orderbook"
|
|
52542
52619
|
},
|
|
52543
52620
|
{
|
|
52544
|
-
code:
|
|
52621
|
+
code: 6078,
|
|
52545
52622
|
name: "InvalidFeePercentage",
|
|
52546
52623
|
msg: "Fee percentage must be between 0-100"
|
|
52547
52624
|
},
|
|
52548
52625
|
{
|
|
52549
|
-
code:
|
|
52626
|
+
code: 6079,
|
|
52550
52627
|
name: "InvalidFeeRate",
|
|
52551
52628
|
msg: "Fee rate exceeds maximum limit (10%)"
|
|
52552
52629
|
},
|
|
52553
52630
|
{
|
|
52554
|
-
code:
|
|
52631
|
+
code: 6080,
|
|
52555
52632
|
name: "InvalidCustomFeeRate",
|
|
52556
52633
|
msg: "Custom fee rate must be between 1000 (1%) and 5000 (5%)"
|
|
52557
52634
|
},
|
|
52558
52635
|
{
|
|
52559
|
-
code:
|
|
52636
|
+
code: 6081,
|
|
52560
52637
|
name: "InvalidBorrowDuration",
|
|
52561
52638
|
msg: "Borrow duration out of valid range (3-30 days)"
|
|
52562
52639
|
},
|
|
52563
52640
|
{
|
|
52564
|
-
code:
|
|
52641
|
+
code: 6082,
|
|
52565
52642
|
name: "InvalidStopLossPrice",
|
|
52566
52643
|
msg: "Stop loss price does not meet minimum interval requirement"
|
|
52567
52644
|
},
|
|
52568
52645
|
{
|
|
52569
|
-
code:
|
|
52646
|
+
code: 6083,
|
|
52570
52647
|
name: "NoProfitableFunds",
|
|
52571
52648
|
msg: "No profitable funds to transfer"
|
|
52572
52649
|
},
|
|
52573
52650
|
{
|
|
52574
|
-
code:
|
|
52651
|
+
code: 6084,
|
|
52575
52652
|
name: "InsufficientPoolFunds",
|
|
52576
52653
|
msg: "Insufficient pool funds"
|
|
52577
52654
|
},
|
|
52578
52655
|
{
|
|
52579
|
-
code:
|
|
52656
|
+
code: 6085,
|
|
52580
52657
|
name: "InsufficientPoolBalance",
|
|
52581
52658
|
msg: "Pool SOL account balance would fall below minimum required balance"
|
|
52582
52659
|
},
|
|
52583
52660
|
{
|
|
52584
|
-
code:
|
|
52661
|
+
code: 6086,
|
|
52585
52662
|
name: "OrderBookManagerOverflow",
|
|
52586
52663
|
msg: "Math operation overflow"
|
|
52587
52664
|
},
|
|
52588
52665
|
{
|
|
52589
|
-
code:
|
|
52666
|
+
code: 6087,
|
|
52590
52667
|
name: "OrderBookManagerInvalidSlotIndex",
|
|
52591
52668
|
msg: "Invalid slot index"
|
|
52592
52669
|
},
|
|
52593
52670
|
{
|
|
52594
|
-
code:
|
|
52671
|
+
code: 6088,
|
|
52595
52672
|
name: "OrderBookManagerInvalidAccountData",
|
|
52596
52673
|
msg: "Invalid account data"
|
|
52597
52674
|
},
|
|
52598
52675
|
{
|
|
52599
|
-
code:
|
|
52676
|
+
code: 6089,
|
|
52600
52677
|
name: "OrderBookManagerExceedsMaxCapacity",
|
|
52601
52678
|
msg: "New capacity exceeds maximum limit"
|
|
52602
52679
|
},
|
|
52603
52680
|
{
|
|
52604
|
-
code:
|
|
52681
|
+
code: 6090,
|
|
52605
52682
|
name: "OrderBookManagerExceedsAccountSizeLimit",
|
|
52606
52683
|
msg: "Account size exceeds 10MB limit"
|
|
52607
52684
|
},
|
|
52608
52685
|
{
|
|
52609
|
-
code:
|
|
52686
|
+
code: 6091,
|
|
52610
52687
|
name: "OrderBookManagerOrderIdMismatch",
|
|
52611
52688
|
msg: "Order ID mismatch"
|
|
52612
52689
|
},
|
|
52613
52690
|
{
|
|
52614
|
-
code:
|
|
52691
|
+
code: 6092,
|
|
52615
52692
|
name: "OrderBookManagerEmptyOrderBook",
|
|
52616
52693
|
msg: "Order book is empty"
|
|
52617
52694
|
},
|
|
52618
52695
|
{
|
|
52619
|
-
code:
|
|
52696
|
+
code: 6093,
|
|
52620
52697
|
name: "OrderBookManagerAccountNotWritable",
|
|
52621
52698
|
msg: "Account is not writable"
|
|
52622
52699
|
},
|
|
52623
52700
|
{
|
|
52624
|
-
code:
|
|
52701
|
+
code: 6094,
|
|
52625
52702
|
name: "OrderBookManagerNotRentExempt",
|
|
52626
52703
|
msg: "Account not rent-exempt"
|
|
52627
52704
|
},
|
|
52628
52705
|
{
|
|
52629
|
-
code:
|
|
52706
|
+
code: 6095,
|
|
52630
52707
|
name: "OrderBookManagerInvalidRentBalance",
|
|
52631
52708
|
msg: "Invalid rent balance"
|
|
52632
52709
|
},
|
|
52633
52710
|
{
|
|
52634
|
-
code:
|
|
52711
|
+
code: 6096,
|
|
52635
52712
|
name: "OrderBookManagerInsufficientFunds",
|
|
52636
52713
|
msg: "Insufficient funds"
|
|
52637
52714
|
},
|
|
52638
52715
|
{
|
|
52639
|
-
code:
|
|
52716
|
+
code: 6097,
|
|
52640
52717
|
name: "OrderBookManagerInvalidAccountOwner",
|
|
52641
52718
|
msg: "OrderBook account owner mismatch"
|
|
52642
52719
|
},
|
|
52643
52720
|
{
|
|
52644
|
-
code:
|
|
52721
|
+
code: 6098,
|
|
52645
52722
|
name: "OrderBookManagerDataOutOfBounds",
|
|
52646
52723
|
msg: "Data access out of bounds"
|
|
52647
52724
|
},
|
|
52648
52725
|
{
|
|
52649
|
-
code:
|
|
52726
|
+
code: 6099,
|
|
52650
52727
|
name: "NoValidInsertPosition",
|
|
52651
52728
|
msg: "Cannot find valid insert position, all candidates failed due to price range overlap"
|
|
52652
52729
|
},
|
|
52653
52730
|
{
|
|
52654
|
-
code:
|
|
52731
|
+
code: 6100,
|
|
52655
52732
|
name: "EmptyCloseInsertIndices",
|
|
52656
52733
|
msg: "close_insert_indices array cannot be empty"
|
|
52657
52734
|
},
|
|
52658
52735
|
{
|
|
52659
|
-
code:
|
|
52736
|
+
code: 6101,
|
|
52660
52737
|
name: "TooManyCloseInsertIndices",
|
|
52661
52738
|
msg: "close_insert_indices array cannot exceed 20 elements"
|
|
52662
52739
|
},
|
|
52663
52740
|
{
|
|
52664
|
-
code:
|
|
52741
|
+
code: 6102,
|
|
52665
52742
|
name: "CloseOrderNotFound",
|
|
52666
52743
|
msg: "Specified close order not found"
|
|
52667
52744
|
},
|
|
52668
52745
|
{
|
|
52669
|
-
code:
|
|
52746
|
+
code: 6103,
|
|
52670
52747
|
name: "LinkedListDeleteCountMismatch",
|
|
52671
52748
|
msg: "Linked list delete count mismatch: count inconsistent before/after deletion"
|
|
52672
52749
|
},
|
|
52673
52750
|
{
|
|
52674
|
-
code:
|
|
52751
|
+
code: 6104,
|
|
52675
52752
|
name: "NameTooLong",
|
|
52676
52753
|
msg: "Token name too long, max 32 bytes"
|
|
52677
52754
|
},
|
|
52678
52755
|
{
|
|
52679
|
-
code:
|
|
52756
|
+
code: 6105,
|
|
52680
52757
|
name: "NameEmpty",
|
|
52681
52758
|
msg: "Token name cannot be empty"
|
|
52682
52759
|
},
|
|
52683
52760
|
{
|
|
52684
|
-
code:
|
|
52761
|
+
code: 6106,
|
|
52685
52762
|
name: "SymbolTooLong",
|
|
52686
52763
|
msg: "Token symbol too long, max 10 bytes"
|
|
52687
52764
|
},
|
|
52688
52765
|
{
|
|
52689
|
-
code:
|
|
52766
|
+
code: 6107,
|
|
52690
52767
|
name: "SymbolEmpty",
|
|
52691
52768
|
msg: "Token symbol cannot be empty"
|
|
52692
52769
|
},
|
|
52693
52770
|
{
|
|
52694
|
-
code:
|
|
52771
|
+
code: 6108,
|
|
52695
52772
|
name: "UriTooLong",
|
|
52696
52773
|
msg: "URI too long, max 200 bytes"
|
|
52697
52774
|
},
|
|
52698
52775
|
{
|
|
52699
|
-
code:
|
|
52776
|
+
code: 6109,
|
|
52700
52777
|
name: "UriEmpty",
|
|
52701
52778
|
msg: "URI cannot be empty"
|
|
52702
52779
|
},
|
|
52703
52780
|
{
|
|
52704
|
-
code:
|
|
52781
|
+
code: 6110,
|
|
52705
52782
|
name: "IncompleteAdvancedPoolParams",
|
|
52706
52783
|
msg: "Incomplete advanced pool parameters: custom_lp_sol, custom_lp_token, custom_borrow_ratio, custom_borrow_duration must be provided together"
|
|
52707
52784
|
},
|
|
52708
52785
|
{
|
|
52709
|
-
code:
|
|
52786
|
+
code: 6111,
|
|
52710
52787
|
name: "InvalidInitialVirtualSol",
|
|
52711
52788
|
msg: "Initial virtual SOL out of valid range"
|
|
52712
52789
|
},
|
|
52713
52790
|
{
|
|
52714
|
-
code:
|
|
52791
|
+
code: 6112,
|
|
52715
52792
|
name: "InvalidInitialVirtualToken",
|
|
52716
52793
|
msg: "Initial virtual Token out of valid range"
|
|
52717
52794
|
},
|
|
52718
52795
|
{
|
|
52719
|
-
code:
|
|
52796
|
+
code: 6113,
|
|
52720
52797
|
name: "InvalidBorrowPoolRatio",
|
|
52721
52798
|
msg: "Borrow pool ratio out of valid range"
|
|
52722
52799
|
},
|
|
52723
52800
|
{
|
|
52724
|
-
code:
|
|
52801
|
+
code: 6114,
|
|
52725
52802
|
name: "BorrowTokenCalculationOverflow",
|
|
52726
52803
|
msg: "Borrow pool token amount calculation overflow"
|
|
52727
52804
|
},
|
|
52728
52805
|
{
|
|
52729
|
-
code:
|
|
52806
|
+
code: 6115,
|
|
52730
52807
|
name: "BorrowTokenAmountZero",
|
|
52731
52808
|
msg: "Borrow pool token amount cannot be zero"
|
|
52732
52809
|
}
|
|
@@ -53639,7 +53716,7 @@ const DEFAULT_NETWORKS = {
|
|
|
53639
53716
|
MAINNET: {
|
|
53640
53717
|
name: 'mainnet-beta',
|
|
53641
53718
|
defaultDataSource: 'fast',
|
|
53642
|
-
solanaEndpoint: 'https://
|
|
53719
|
+
solanaEndpoint: 'https://solana-rpc.pinpet.fun',
|
|
53643
53720
|
pinPetFastApiUrl: 'https://api.pinpet.fun/',
|
|
53644
53721
|
feeRecipient: 'CmDe8JRAPJ7QpZNCb4ArVEyzyxYoCNL7WZw5qXLePULn',
|
|
53645
53722
|
baseFeeRecipient: '2xhAfEfnH8wg7ZGujSijJi4Zt4ge1ZuwMypo7etntgXA',
|
|
@@ -53648,7 +53725,7 @@ const DEFAULT_NETWORKS = {
|
|
|
53648
53725
|
DEVNET: {
|
|
53649
53726
|
name: 'devnet',
|
|
53650
53727
|
defaultDataSource: 'fast',
|
|
53651
|
-
solanaEndpoint: 'https://devnet.helius-rpc.com
|
|
53728
|
+
solanaEndpoint: 'https://lu-ura5lv-fast-devnet.helius-rpc.com',
|
|
53652
53729
|
pinPetFastApiUrl: 'https://devtestapi.pinpet.fun',
|
|
53653
53730
|
feeRecipient: 'GesAj2dTn2wdNcxj4x8qsqS9aNRVPBPkE76aaqg7skxu',
|
|
53654
53731
|
baseFeeRecipient: '5YHi1HsxobLiTD6NQfHJQpoPoRjMuNyXp4RroTvR6dKi',
|