pinpet-sdk 2.0.11 → 2.1.0

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.
@@ -41872,17 +41872,17 @@ class CurveAMM$7 {
41872
41872
  static INITIAL_MIN_PRICE_DECIMAL = new Decimal('0.000000001');
41873
41873
 
41874
41874
  /**
41875
- * Decimal representation of precision factor = 10000000000000000000000000000
41875
+ * Decimal representation of precision factor = 10^23
41876
41876
  * @type {Decimal}
41877
41877
  */
41878
41878
  //static PRICE_PRECISION_FACTOR_DECIMAL = new Decimal('10000000000000000000000000000');
41879
- static PRICE_PRECISION_FACTOR_DECIMAL = new Decimal('100000000000000000000000000');
41879
+ static PRICE_PRECISION_FACTOR_DECIMAL = new Decimal('100000000000000000000000');
41880
41880
 
41881
41881
  /**
41882
- * Decimal representation of Token precision factor = 1000000
41882
+ * Decimal representation of Token precision factor = 1000000000 (10^9)
41883
41883
  * @type {Decimal}
41884
41884
  */
41885
- static TOKEN_PRECISION_FACTOR_DECIMAL = new Decimal('1000000');
41885
+ static TOKEN_PRECISION_FACTOR_DECIMAL = new Decimal('1000000000');
41886
41886
 
41887
41887
  /**
41888
41888
  * Decimal representation of SOL precision factor = 1000000000
@@ -41892,10 +41892,10 @@ class CurveAMM$7 {
41892
41892
 
41893
41893
 
41894
41894
  /**
41895
- * Maximum price for u128
41895
+ * Maximum price for u128 (matches PRICE_CALCULATION_LIMIT in Rust)
41896
41896
  * @type {bigint}
41897
41897
  */
41898
- static MAX_U128_PRICE = 50000000000000000000000000000n;
41898
+ static MAX_U128_PRICE = 50000000000000000000000000000000n;
41899
41899
 
41900
41900
 
41901
41901
  /**
@@ -42012,8 +42012,8 @@ class CurveAMM$7 {
42012
42012
  }
42013
42013
 
42014
42014
  /**
42015
- * Convert Decimal token amount to u64, using 6-digit precision, rounded down
42016
- *
42015
+ * Convert Decimal token amount to u64, using 9-digit precision, rounded down
42016
+ *
42017
42017
  * @param {Decimal} amount - Decimal token amount to be converted
42018
42018
  * @returns {bigint|null} Converted u64 token amount, returns null if overflow
42019
42019
  */
@@ -42028,8 +42028,8 @@ class CurveAMM$7 {
42028
42028
  }
42029
42029
 
42030
42030
  /**
42031
- * Convert Decimal token amount to u64, using 6-digit precision, rounded up
42032
- *
42031
+ * Convert Decimal token amount to u64, using 9-digit precision, rounded up
42032
+ *
42033
42033
  * @param {Decimal} amount - Decimal token amount to be converted
42034
42034
  * @returns {bigint|null} Converted u64 token amount, returns null if overflow
42035
42035
  */
@@ -42076,8 +42076,8 @@ class CurveAMM$7 {
42076
42076
  }
42077
42077
 
42078
42078
  /**
42079
- * Convert u64 token amount to Decimal, using 6-digit precision
42080
- *
42079
+ * Convert u64 token amount to Decimal, using 9-digit precision
42080
+ *
42081
42081
  * @param {bigint|string|number} amount - u64 token amount to be converted
42082
42082
  * @returns {Decimal} Converted Decimal token amount
42083
42083
  */
@@ -42131,7 +42131,7 @@ class CurveAMM$7 {
42131
42131
  * @param {bigint|string|number} startLowPrice - Starting price (lower)
42132
42132
  * @param {bigint|string|number} endHighPrice - Target price (higher)
42133
42133
  * @returns {[bigint, bigint]|null} Returns [SOL amount to invest, token amount to obtain] on success, null on failure
42134
- * SOL amount in 9-digit precision rounded up; token amount in 6-digit precision rounded down
42134
+ * SOL amount in 9-digit precision rounded up; token amount in 9-digit precision rounded down
42135
42135
  */
42136
42136
  static buyFromPriceToPrice(startLowPrice, endHighPrice) {
42137
42137
  // Convert to Decimal for calculation
@@ -42169,7 +42169,7 @@ class CurveAMM$7 {
42169
42169
  }
42170
42170
 
42171
42171
  // Convert back to u64
42172
- // SOL uses 9-digit precision rounded up, token uses 6-digit precision rounded down
42172
+ // SOL uses 9-digit precision rounded up, token uses 9-digit precision rounded down
42173
42173
  const solAmountU64 = this.solDecimalToU64Ceil(solInputAmount);
42174
42174
  const tokenAmountU64 = this.tokenDecimalToU64(tokenOutputAmount);
42175
42175
 
@@ -42186,7 +42186,7 @@ class CurveAMM$7 {
42186
42186
  * @param {bigint|string|number} startHighPrice - Starting price (higher)
42187
42187
  * @param {bigint|string|number} endLowPrice - Target price (lower)
42188
42188
  * @returns {[bigint, bigint]|null} Returns [token amount to sell, SOL amount to obtain] on success, null on failure
42189
- * token amount in 6-digit precision rounded up; SOL amount in 9-digit precision rounded down
42189
+ * token amount in 9-digit precision rounded up; SOL amount in 9-digit precision rounded down
42190
42190
  */
42191
42191
  static sellFromPriceToPrice(startHighPrice, endLowPrice) {
42192
42192
  // console.log('\n=== sellFromPriceToPrice debug info ===');
@@ -42256,7 +42256,7 @@ class CurveAMM$7 {
42256
42256
  }
42257
42257
 
42258
42258
  // Convert back to u64
42259
- // token uses 6-digit precision rounded up, SOL uses 9-digit precision rounded down
42259
+ // token uses 9-digit precision rounded up, SOL uses 9-digit precision rounded down
42260
42260
  const tokenAmountU64 = this.tokenDecimalToU64Ceil(tokenInputAmount);
42261
42261
  const solAmountU64 = this.solDecimalToU64(solOutputAmount);
42262
42262
 
@@ -42661,8 +42661,8 @@ class CurveAMM$7 {
42661
42661
 
42662
42662
  /**
42663
42663
  * Calculate price based on liquidity pool reserves (how much SOL 1 token is worth)
42664
- *
42665
- * @param {bigint|string|number|BN} lpTokenReserve - Token reserves in liquidity pool (u64 format, 6-digit precision)
42664
+ *
42665
+ * @param {bigint|string|number|BN} lpTokenReserve - Token reserves in liquidity pool (u64 format, 9-digit precision)
42666
42666
  * @param {bigint|string|number|BN} lpSolReserve - SOL reserves in liquidity pool (u64 format, 9-digit precision)
42667
42667
  * @returns {string|null} Returns 28-digit decimal price string on success, null on failure
42668
42668
  */
@@ -43074,28 +43074,28 @@ class FastModule$1 {
43074
43074
  // User address
43075
43075
  user: order.user,
43076
43076
 
43077
- // Price fields (keep as strings)
43078
- lock_lp_start_price: order.lock_lp_start_price,
43079
- lock_lp_end_price: order.lock_lp_end_price,
43080
- open_price: order.open_price,
43077
+ // Price fields (ensure strings)
43078
+ lock_lp_start_price: String(order.lock_lp_start_price),
43079
+ lock_lp_end_price: String(order.lock_lp_end_price),
43080
+ open_price: String(order.open_price),
43081
43081
 
43082
43082
  // Order ID (ensure string)
43083
- order_id: order.order_id != null ? order.order_id.toString() : undefined,
43083
+ order_id: order.order_id != null ? String(order.order_id) : undefined,
43084
43084
 
43085
- // Amount fields
43086
- lock_lp_sol_amount: order.lock_lp_sol_amount,
43087
- lock_lp_token_amount: order.lock_lp_token_amount,
43088
- next_lp_sol_amount: order.next_lp_sol_amount,
43089
- next_lp_token_amount: order.next_lp_token_amount,
43085
+ // Amount fields (ensure strings) - Fix precision issue
43086
+ lock_lp_sol_amount: String(order.lock_lp_sol_amount),
43087
+ lock_lp_token_amount: String(order.lock_lp_token_amount),
43088
+ next_lp_sol_amount: String(order.next_lp_sol_amount),
43089
+ next_lp_token_amount: String(order.next_lp_token_amount),
43090
43090
 
43091
- // Margin fields
43092
- margin_init_sol_amount: order.margin_init_sol_amount,
43093
- margin_sol_amount: order.margin_sol_amount,
43091
+ // Margin fields (ensure strings) - Fix precision issue
43092
+ margin_init_sol_amount: String(order.margin_init_sol_amount),
43093
+ margin_sol_amount: String(order.margin_sol_amount),
43094
43094
 
43095
- // Position fields
43096
- borrow_amount: order.borrow_amount,
43097
- position_asset_amount: order.position_asset_amount,
43098
- realized_sol_amount: order.realized_sol_amount,
43095
+ // Position fields (ensure strings) - Fix precision issue
43096
+ borrow_amount: String(order.borrow_amount),
43097
+ position_asset_amount: String(order.position_asset_amount),
43098
+ realized_sol_amount: String(order.realized_sol_amount),
43099
43099
 
43100
43100
  // Version
43101
43101
  version: order.version,
@@ -43354,28 +43354,28 @@ class FastModule$1 {
43354
43354
  mint: order.mint,
43355
43355
  user: order.user,
43356
43356
 
43357
- // Price fields (keep as strings)
43358
- lock_lp_start_price: order.lock_lp_start_price,
43359
- lock_lp_end_price: order.lock_lp_end_price,
43360
- open_price: order.open_price,
43357
+ // Price fields (ensure strings)
43358
+ lock_lp_start_price: String(order.lock_lp_start_price),
43359
+ lock_lp_end_price: String(order.lock_lp_end_price),
43360
+ open_price: String(order.open_price),
43361
43361
 
43362
43362
  // Order ID (ensure string)
43363
- order_id: order.order_id != null ? order.order_id.toString() : undefined,
43363
+ order_id: order.order_id != null ? String(order.order_id) : undefined,
43364
43364
 
43365
- // Amount fields
43366
- lock_lp_sol_amount: order.lock_lp_sol_amount,
43367
- lock_lp_token_amount: order.lock_lp_token_amount,
43368
- next_lp_sol_amount: order.next_lp_sol_amount,
43369
- next_lp_token_amount: order.next_lp_token_amount,
43365
+ // Amount fields (ensure strings) - Fix precision issue
43366
+ lock_lp_sol_amount: String(order.lock_lp_sol_amount),
43367
+ lock_lp_token_amount: String(order.lock_lp_token_amount),
43368
+ next_lp_sol_amount: String(order.next_lp_sol_amount),
43369
+ next_lp_token_amount: String(order.next_lp_token_amount),
43370
43370
 
43371
- // Margin fields
43372
- margin_init_sol_amount: order.margin_init_sol_amount,
43373
- margin_sol_amount: order.margin_sol_amount,
43371
+ // Margin fields (ensure strings) - Fix precision issue
43372
+ margin_init_sol_amount: String(order.margin_init_sol_amount),
43373
+ margin_sol_amount: String(order.margin_sol_amount),
43374
43374
 
43375
- // Position fields
43376
- borrow_amount: order.borrow_amount,
43377
- position_asset_amount: order.position_asset_amount,
43378
- realized_sol_amount: order.realized_sol_amount,
43375
+ // Position fields (ensure strings) - Fix precision issue
43376
+ borrow_amount: String(order.borrow_amount),
43377
+ position_asset_amount: String(order.position_asset_amount),
43378
+ realized_sol_amount: String(order.realized_sol_amount),
43379
43379
 
43380
43380
  // Time fields
43381
43381
  start_time: order.start_time,
@@ -44673,7 +44673,7 @@ jsonBigintExports({ storeAsString: false });
44673
44673
  * 并返回合约执行时需要的插入位置索引数组。
44674
44674
  *
44675
44675
  * @param {string} mint - Token address / 代币地址
44676
- * @param {bigint|string|number} buyTokenAmount - Token amount to buy for long position (u64 format, precision 10^6) / 做多买入的代币数量 (u64格式, 精度 10^6)
44676
+ * @param {bigint|string|number} buyTokenAmount - Token amount to buy for long position (u64 format, precision 10^9) / 做多买入的代币数量 (u64格式, 精度 10^9)
44677
44677
  * @param {bigint|string|number} stopLossPrice - User desired stop loss price (u128 format) / 用户期望的止损价格 (u128格式)
44678
44678
  * @param {Object|null} lastPrice - Token info, default null / 代币当前价格信息,默认null会自动获取
44679
44679
  * @param {Object|null} ordersData - Orders data, default null / 订单数据,默认null会自动获取
@@ -44737,7 +44737,7 @@ jsonBigintExports({ storeAsString: false });
44737
44737
  * // 基础用法: 做多1个代币,止损价格为当前价格的97%
44738
44738
  * const result = await sdk.simulator.simulateLongStopLoss(
44739
44739
  * '4Kq51Kt48FCwdo5CeKjRVPodH1ticHa7mZ5n5gqMEy1X', // mint
44740
- * 1000000n, // 1 token (精度10^6)
44740
+ * 1000000000n, // 1 token (精度10^9)
44741
44741
  * BigInt('97000000000000000000') // 止损价格
44742
44742
  * );
44743
44743
  *
@@ -44983,7 +44983,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
44983
44983
  * 并返回合约执行时需要的插入位置索引数组。
44984
44984
  *
44985
44985
  * @param {string} mint - Token address / 代币地址
44986
- * @param {bigint|string|number} sellTokenAmount - Token amount to sell for short position (u64 format, precision 10^6) / 做空卖出的代币数量 (u64格式, 精度 10^6)
44986
+ * @param {bigint|string|number} sellTokenAmount - Token amount to sell for short position (u64 format, precision 10^9) / 做空卖出的代币数量 (u64格式, 精度 10^9)
44987
44987
  * @param {bigint|string|number} stopLossPrice - User desired stop loss price (u128 format) / 用户期望的止损价格 (u128格式)
44988
44988
  * @param {Object|null} lastPrice - Token info, default null / 代币当前价格信息,默认null会自动获取
44989
44989
  * @param {Object|null} ordersData - Orders data, default null / 订单数据,默认null会自动获取
@@ -45047,7 +45047,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
45047
45047
  * // 基础用法: 做空1个代币,止损价格为当前价格的103%
45048
45048
  * const result = await sdk.simulator.simulateShortStopLoss(
45049
45049
  * '4Kq51Kt48FCwdo5CeKjRVPodH1ticHa7mZ5n5gqMEy1X', // mint
45050
- * 1000000n, // 1 token (精度10^6)
45050
+ * 1000000000n, // 1 token (精度10^9)
45051
45051
  * BigInt('103000000000000000000') // 止损价格
45052
45052
  * );
45053
45053
  *
@@ -45436,7 +45436,7 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
45436
45436
  // 如果没有找到合法解,使用一个很小的 tokenAmount 作为安全回退
45437
45437
  //console.log(`No valid solution found (estimatedMargin < buySolAmount), using minimal tokenAmount`);
45438
45438
  buyTokenAmount = buyTokenAmount / 10n; // 使用更小的值
45439
- if (buyTokenAmount <= 0n) buyTokenAmount = 1000000n; // 最小值保护
45439
+ if (buyTokenAmount <= 0n) buyTokenAmount = 1000000000n; // 最小值保护 (0.001 token with 9 decimals)
45440
45440
  stopLossResult = await simulateLongStopLoss$1.call(this, mint, buyTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
45441
45441
  }
45442
45442
 
@@ -45603,7 +45603,7 @@ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, la
45603
45603
  // 如果没有找到合法解,使用一个很小的 tokenAmount 作为安全回退
45604
45604
  //console.log(`No valid solution found (estimatedMargin < sellSolAmount), using minimal tokenAmount`);
45605
45605
  sellTokenAmount = sellTokenAmount / 10n; // 使用更小的值
45606
- if (sellTokenAmount <= 0n) sellTokenAmount = 1000000n; // 最小值保护
45606
+ if (sellTokenAmount <= 0n) sellTokenAmount = 1000000000n; // 最小值保护 (0.001 token with 9 decimals)
45607
45607
  stopLossResult = await simulateShortStopLoss$1.call(this, mint, sellTokenAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
45608
45608
  }
45609
45609
 
@@ -46487,7 +46487,7 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
46487
46487
  /**
46488
46488
  * Simulate token sell transaction analysis
46489
46489
  * @param {string} mint - Token address
46490
- * @param {bigint|string|number} sellTokenAmount - Token amount to sell (u64 format, precision 10^6)
46490
+ * @param {bigint|string|number} sellTokenAmount - Token amount to sell (u64 format, precision 10^9)
46491
46491
  * @param {string} passOrder - Optional order address to skip (won't be liquidated) 可选的跳过订单地址
46492
46492
  * @param {Object|null} lastPrice - Token price info, default null
46493
46493
  * @param {Object|null} ordersData - Orders response object, default null
@@ -47769,22 +47769,22 @@ class ChainModule$1 {
47769
47769
  // Order ID field (u64 -> string)
47770
47770
  order_id: order.orderId.toString(),
47771
47771
 
47772
- // Amount fields (u64 -> number)
47773
- lock_lp_sol_amount: Number(order.lockLpSolAmount),
47774
- lock_lp_token_amount: Number(order.lockLpTokenAmount),
47775
- next_lp_sol_amount: Number(order.nextLpSolAmount),
47776
- next_lp_token_amount: Number(order.nextLpTokenAmount),
47772
+ // Amount fields (u64 -> string) - Fix precision issue
47773
+ lock_lp_sol_amount: order.lockLpSolAmount.toString(),
47774
+ lock_lp_token_amount: order.lockLpTokenAmount.toString(),
47775
+ next_lp_sol_amount: order.nextLpSolAmount.toString(),
47776
+ next_lp_token_amount: order.nextLpTokenAmount.toString(),
47777
47777
 
47778
47778
  // Time fields (u32 -> number)
47779
47779
  start_time: order.startTime,
47780
47780
  end_time: order.endTime,
47781
47781
 
47782
- // Margin and position fields (u64 -> number)
47783
- margin_init_sol_amount: Number(order.marginInitSolAmount),
47784
- margin_sol_amount: Number(order.marginSolAmount),
47785
- borrow_amount: Number(order.borrowAmount),
47786
- position_asset_amount: Number(order.positionAssetAmount),
47787
- realized_sol_amount: Number(order.realizedSolAmount),
47782
+ // Margin and position fields (u64 -> string) - Fix precision issue
47783
+ margin_init_sol_amount: order.marginInitSolAmount.toString(),
47784
+ margin_sol_amount: order.marginSolAmount.toString(),
47785
+ borrow_amount: order.borrowAmount.toString(),
47786
+ position_asset_amount: order.positionAssetAmount.toString(),
47787
+ realized_sol_amount: order.realizedSolAmount.toString(),
47788
47788
 
47789
47789
  // Fee field (u16 -> number)
47790
47790
  borrow_fee: order.borrowFee,
@@ -48218,22 +48218,22 @@ class ChainModule$1 {
48218
48218
  // Order ID field (u64 -> string)
48219
48219
  order_id: order.orderId.toString(),
48220
48220
 
48221
- // Amount fields (u64 -> number)
48222
- lock_lp_sol_amount: Number(order.lockLpSolAmount),
48223
- lock_lp_token_amount: Number(order.lockLpTokenAmount),
48224
- next_lp_sol_amount: Number(order.nextLpSolAmount),
48225
- next_lp_token_amount: Number(order.nextLpTokenAmount),
48221
+ // Amount fields (u64 -> string) - Fix precision issue
48222
+ lock_lp_sol_amount: order.lockLpSolAmount.toString(),
48223
+ lock_lp_token_amount: order.lockLpTokenAmount.toString(),
48224
+ next_lp_sol_amount: order.nextLpSolAmount.toString(),
48225
+ next_lp_token_amount: order.nextLpTokenAmount.toString(),
48226
48226
 
48227
48227
  // Time fields (u32 -> number)
48228
48228
  start_time: order.startTime,
48229
48229
  end_time: order.endTime,
48230
48230
 
48231
- // Margin and position fields (u64 -> number)
48232
- margin_init_sol_amount: Number(order.marginInitSolAmount),
48233
- margin_sol_amount: Number(order.marginSolAmount),
48234
- borrow_amount: Number(order.borrowAmount),
48235
- position_asset_amount: Number(order.positionAssetAmount),
48236
- realized_sol_amount: Number(order.realizedSolAmount),
48231
+ // Margin and position fields (u64 -> string) - Fix precision issue
48232
+ margin_init_sol_amount: order.marginInitSolAmount.toString(),
48233
+ margin_sol_amount: order.marginSolAmount.toString(),
48234
+ borrow_amount: order.borrowAmount.toString(),
48235
+ position_asset_amount: order.positionAssetAmount.toString(),
48236
+ realized_sol_amount: order.realizedSolAmount.toString(),
48237
48237
 
48238
48238
  // Fee field (u16 -> number)
48239
48239
  borrow_fee: order.borrowFee,
@@ -48419,22 +48419,22 @@ class ChainModule$1 {
48419
48419
  // Order ID field (u64 -> string)
48420
48420
  order_id: order.orderId.toString(),
48421
48421
 
48422
- // Amount fields (u64 -> number)
48423
- lock_lp_sol_amount: Number(order.lockLpSolAmount),
48424
- lock_lp_token_amount: Number(order.lockLpTokenAmount),
48425
- next_lp_sol_amount: Number(order.nextLpSolAmount),
48426
- next_lp_token_amount: Number(order.nextLpTokenAmount),
48422
+ // Amount fields (u64 -> string) - Fix precision issue
48423
+ lock_lp_sol_amount: order.lockLpSolAmount.toString(),
48424
+ lock_lp_token_amount: order.lockLpTokenAmount.toString(),
48425
+ next_lp_sol_amount: order.nextLpSolAmount.toString(),
48426
+ next_lp_token_amount: order.nextLpTokenAmount.toString(),
48427
48427
 
48428
48428
  // Time fields (u32 -> number)
48429
48429
  start_time: order.startTime,
48430
48430
  end_time: order.endTime,
48431
48431
 
48432
- // Margin and position fields (u64 -> number)
48433
- margin_init_sol_amount: Number(order.marginInitSolAmount),
48434
- margin_sol_amount: Number(order.marginSolAmount),
48435
- borrow_amount: Number(order.borrowAmount),
48436
- position_asset_amount: Number(order.positionAssetAmount),
48437
- realized_sol_amount: Number(order.realizedSolAmount),
48432
+ // Margin and position fields (u64 -> string) - Fix precision issue
48433
+ margin_init_sol_amount: order.marginInitSolAmount.toString(),
48434
+ margin_sol_amount: order.marginSolAmount.toString(),
48435
+ borrow_amount: order.borrowAmount.toString(),
48436
+ position_asset_amount: order.positionAssetAmount.toString(),
48437
+ realized_sol_amount: order.realizedSolAmount.toString(),
48438
48438
 
48439
48439
  // Fee field (u16 -> number)
48440
48440
  borrow_fee: order.borrowFee,