pinpet-sdk 2.1.28 → 2.1.30

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.
@@ -20253,9 +20253,9 @@ const MIN_STOP_LOSS_PERCENT$1 = 40; // 4.0%
20253
20253
 
20254
20254
  // Maximum number of candidate indices to include in close_insert_indices
20255
20255
  // This represents: 1 main position + N nodes before + N nodes after
20256
- // Must be an odd number >= 1 (e.g., 21 = 1 main + 10 before + 10 after)
20257
- // The contract accepts up to 20, we use 21 to provide more flexibility
20258
- const MAX_CANDIDATE_INDICES$3 = 31;
20256
+ // Must be an odd number >= 1 (e.g., 41 = 1 main + 20 before + 20 after)
20257
+ // The contract accepts up to 41
20258
+ const MAX_CANDIDATE_INDICES$3 = 19;
20259
20259
 
20260
20260
 
20261
20261
  /**
@@ -20374,8 +20374,8 @@ class TradingModule$1 {
20374
20374
  )
20375
20375
  : null;
20376
20376
 
20377
- // 6. Get fee recipient accounts from curve account
20378
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
20377
+ // 6. Get fee recipient accounts from curve account (skipBalances: only need addresses)
20378
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
20379
20379
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
20380
20380
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
20381
20381
 
@@ -20510,8 +20510,8 @@ class TradingModule$1 {
20510
20510
  )
20511
20511
  : null;
20512
20512
 
20513
- // 6. Get fee recipient accounts from curve account
20514
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
20513
+ // 6. Get fee recipient accounts from curve account (skipBalances: only need addresses)
20514
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
20515
20515
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
20516
20516
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
20517
20517
 
@@ -20890,8 +20890,8 @@ class TradingModule$1 {
20890
20890
  this.sdk.programId
20891
20891
  );
20892
20892
 
20893
- // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account
20894
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
20893
+ // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account (skipBalances: only need addresses)
20894
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
20895
20895
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
20896
20896
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
20897
20897
 
@@ -21039,8 +21039,8 @@ class TradingModule$1 {
21039
21039
  this.sdk.programId
21040
21040
  );
21041
21041
 
21042
- // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account
21043
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
21042
+ // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account (skipBalances: only need addresses)
21043
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
21044
21044
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
21045
21045
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
21046
21046
 
@@ -21142,7 +21142,7 @@ class TradingModule$1 {
21142
21142
 
21143
21143
  var trading = TradingModule$1;
21144
21144
 
21145
- const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1, VersionedTransaction, TransactionMessage } = require$$2$1;
21145
+ const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = require$$2$1;
21146
21146
  const { TOKEN_PROGRAM_ID: TOKEN_PROGRAM_ID$1, getAssociatedTokenAddress: getAssociatedTokenAddress$1, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID: ASSOCIATED_TOKEN_PROGRAM_ID$1 } = cjs$3;
21147
21147
  const anchor$3 = require$$0;
21148
21148
  // 统一使用 buffer 包,所有平台一致
@@ -21379,13 +21379,8 @@ class TokenModule$1 {
21379
21379
  }
21380
21380
 
21381
21381
  /**
21382
- * Create token and buy in one transaction (使用 VersionedTransaction v0)
21383
- * 将 create 和 buy 两个指令合并到一个 v0 交易中,一次签名提交
21384
- *
21385
- * 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
21386
- * - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
21387
- * - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
21388
- * - 发送方式:connection.sendRawTransaction(signedTx.serialize())
21382
+ * Create token and buy in one transaction
21383
+ * 将 create 和 buy 两个指令合并到一个交易中,一次签名提交
21389
21384
  *
21390
21385
  * @param {Object} params - Creation and buy parameters
21391
21386
  * @param {Keypair} params.mint - Token mint keypair
@@ -21405,20 +21400,7 @@ class TokenModule$1 {
21405
21400
  *
21406
21401
  * @param {Object} options - Optional parameters
21407
21402
  * @param {number} options.computeUnits - Compute units limit, default 1800000
21408
- * @returns {Promise<Object>} Object containing VersionedTransaction, signers, accounts and blockhashInfo
21409
- *
21410
- * @example
21411
- * // Node.js 环境
21412
- * const result = await sdk.token.createAndBuy({...});
21413
- * result.transaction.sign([wallet, ...result.signers]);
21414
- * const sig = await connection.sendRawTransaction(result.transaction.serialize());
21415
- *
21416
- * @example
21417
- * // 浏览器 Phantom 环境
21418
- * const result = await sdk.token.createAndBuy({...});
21419
- * result.transaction.sign(result.signers); // mint keypair 先签名
21420
- * const signed = await phantom.signTransaction(result.transaction); // Phantom 追加 payer 签名
21421
- * const sig = await connection.sendRawTransaction(signed.serialize());
21403
+ * @returns {Promise<Object>} Object containing transaction, signers and account info
21422
21404
  */
21423
21405
  async createAndBuy({
21424
21406
  mint,
@@ -21437,7 +21419,7 @@ class TokenModule$1 {
21437
21419
  }, options = {}) {
21438
21420
  const { computeUnits = 1800000 } = options;
21439
21421
 
21440
- console.log('Token Module - CreateAndBuy (VersionedTransaction):', {
21422
+ console.log('Token Module - CreateAndBuy:', {
21441
21423
  mint: mint.publicKey.toString(),
21442
21424
  name,
21443
21425
  symbol,
@@ -21473,6 +21455,7 @@ class TokenModule$1 {
21473
21455
  console.log('Step 2: Fetching fee recipient accounts from params...');
21474
21456
 
21475
21457
  // 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
21458
+ // 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
21476
21459
  const feeRecipientAccount = this.sdk.feeRecipient;
21477
21460
  const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
21478
21461
 
@@ -21563,54 +21546,42 @@ class TokenModule$1 {
21563
21546
  })
21564
21547
  .instruction();
21565
21548
 
21566
- // 7. 收集所有指令
21567
- console.log('Step 6: Building VersionedTransaction (v0)...');
21568
- const instructions = [];
21549
+ // 7. 合并交易:create + buy
21550
+ console.log('Step 6: Merging create and buy transactions...');
21551
+ const transaction = new Transaction$2();
21569
21552
 
21570
21553
  // 设置计算单元限制
21571
21554
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
21572
21555
  units: computeUnits
21573
21556
  });
21574
- instructions.push(modifyComputeUnits);
21557
+ transaction.add(modifyComputeUnits);
21575
21558
 
21576
21559
  // 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
21577
21560
  createResult.transaction.instructions.forEach(ix => {
21561
+ // 跳过 create 交易中的计算单元指令(我们已经添加了)
21578
21562
  if (ix.programId.equals(ComputeBudgetProgram.programId)) {
21579
21563
  return;
21580
21564
  }
21581
- instructions.push(ix);
21565
+ transaction.add(ix);
21582
21566
  });
21583
21567
 
21584
21568
  // 添加 ATA 创建指令(如果需要)
21585
21569
  if (createAtaIx) {
21586
- instructions.push(createAtaIx);
21570
+ transaction.add(createAtaIx);
21587
21571
  }
21588
21572
 
21589
- // 添加 buy 指令
21590
- instructions.push(buyIx);
21591
-
21592
- // 8. 获取最新 blockhash 并构建 VersionedTransaction
21593
- const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
21594
-
21595
- const messageV0 = new TransactionMessage({
21596
- payerKey: payer,
21597
- recentBlockhash: blockhashResult.blockhash,
21598
- instructions: instructions,
21599
- }).compileToV0Message();
21600
-
21601
- const transaction = new VersionedTransaction(messageV0);
21602
-
21603
- // 9. 用 mint keypair 预签名(调用方只需 payer 签名)
21604
- transaction.sign([mint]);
21573
+ // 添加 buy 指令
21574
+ transaction.add(buyIx);
21605
21575
 
21606
- console.log('CreateAndBuy VersionedTransaction built successfully:');
21607
- console.log(' Total instructions:', instructions.length);
21576
+ console.log('CreateAndBuy transaction built successfully:');
21577
+ console.log(' Total instructions:', transaction.instructions.length);
21608
21578
  console.log(' Compute units:', computeUnits);
21609
- console.log(' mint keypair pre-signed, caller only needs payer signature');
21579
+ console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
21610
21580
 
21611
- // 10. 返回 VersionedTransaction(mint 已预签名)
21581
+ // 8. 返回合并后的交易
21612
21582
  return {
21613
- transaction, // 已包含 mint 签名
21583
+ transaction,
21584
+ signers: [mint], // mint keypair 需要签名
21614
21585
  accounts: {
21615
21586
  // create 的账户
21616
21587
  ...createResult.accounts,
@@ -21619,23 +21590,10 @@ class TokenModule$1 {
21619
21590
  cooldown: cooldownPDA,
21620
21591
  feeRecipientAccount,
21621
21592
  baseFeeRecipientAccount
21622
- },
21623
- // 返回 blockhash 信息供调用方确认交易使用
21624
- blockhashInfo: {
21625
- blockhash: blockhashResult.blockhash,
21626
- lastValidBlockHeight: blockhashResult.lastValidBlockHeight
21627
21593
  }
21628
21594
  };
21629
21595
  }
21630
21596
 
21631
- /**
21632
- * createAndBuy 的别名(功能完全相同)
21633
- * 保留此方法以保持向后兼容
21634
- */
21635
- async createAndBuySign(params, options = {}) {
21636
- return this.createAndBuy(params, options);
21637
- }
21638
-
21639
21597
  }
21640
21598
 
21641
21599
  var token = TokenModule$1;
@@ -33907,7 +33865,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
33907
33865
 
33908
33866
  // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
33909
33867
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
33910
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
33868
+ const curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
33911
33869
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
33912
33870
  // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
33913
33871
  // 与 calcLiq.js 中的转换方式一致
@@ -34227,7 +34185,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
34227
34185
 
34228
34186
  // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
34229
34187
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
34230
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
34188
+ const curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
34231
34189
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
34232
34190
  // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
34233
34191
  // 与 calcLiq.js 中的转换方式一致
@@ -34475,19 +34433,19 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
34475
34433
  * @since 2.0.0
34476
34434
  * @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
34477
34435
  */
34478
- async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
34436
+ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
34479
34437
  try {
34480
34438
  // Parameter validation
34481
34439
  if (!mint || !buySolAmount || !stopLossPrice) {
34482
34440
  throw new Error('Missing required parameters');
34483
34441
  }
34484
34442
 
34485
- // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
34443
+ // 如果没有传入 borrowFee 或池子参数,从链上一次性获取(支持外部传入 curveAccount 避免重复 RPC)
34486
34444
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
34487
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
34445
+ if (!curveAccount) {
34446
+ curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
34447
+ }
34488
34448
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
34489
- // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
34490
- // 与 calcLiq.js 中的转换方式一致
34491
34449
  if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
34492
34450
  if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
34493
34451
  }
@@ -34659,19 +34617,19 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
34659
34617
  * @since 2.0.0
34660
34618
  * @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
34661
34619
  */
34662
- async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
34620
+ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
34663
34621
  try {
34664
34622
  // Parameter validation
34665
34623
  if (!mint || !sellSolAmount || !stopLossPrice) {
34666
34624
  throw new Error('Missing required parameters');
34667
34625
  }
34668
34626
 
34669
- // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
34627
+ // 如果没有传入 borrowFee 或池子参数,从链上一次性获取(支持外部传入 curveAccount 避免重复 RPC)
34670
34628
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
34671
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
34629
+ if (!curveAccount) {
34630
+ curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
34631
+ }
34672
34632
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
34673
- // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
34674
- // 与 calcLiq.js 中的转换方式一致
34675
34633
  if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
34676
34634
  if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
34677
34635
  }
@@ -35600,7 +35558,7 @@ const { calcLiqTokenBuy, calcLiqTokenSell } = calcLiq;
35600
35558
  * - suggestedTokenAmount: {string} Recommended token amount to buy based on available liquidity
35601
35559
  * - suggestedSolAmount: {string} Required SOL amount for suggested token purchase
35602
35560
  */
35603
- async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
35561
+ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
35604
35562
  // 获取价格和订单数据
35605
35563
 
35606
35564
  //console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
@@ -35623,12 +35581,13 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
35623
35581
  orders = ordersData.data.orders.slice(0, this.sdk.MAX_ORDERS_COUNT + 1);
35624
35582
  }
35625
35583
 
35626
- // 获取动态流动池参数
35627
- let curveData;
35628
- try {
35629
- curveData = await this.sdk.chain.getCurveAccount(mint);
35630
- } catch (error) {
35631
- throw new Error(`Failed to get curve account data: ${error.message}`);
35584
+ // 获取动态流动池参数(支持外部传入,避免重复请求)
35585
+ if (!curveData) {
35586
+ try {
35587
+ curveData = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
35588
+ } catch (error) {
35589
+ throw new Error(`Failed to get curve account data: ${error.message}`);
35590
+ }
35632
35591
  }
35633
35592
 
35634
35593
  // 调用 calcLiqTokenBuy 进行流动性计算(传入动态流动池参数)
@@ -35756,7 +35715,7 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
35756
35715
  * - suggestedTokenAmount: {string} Recommended token amount to sell based on available liquidity
35757
35716
  * - suggestedSolAmount: {string} Expected SOL amount from suggested token sale
35758
35717
  */
35759
- async function simulateTokenSell$1(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
35718
+ async function simulateTokenSell$1(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
35760
35719
  // 获取价格和订单数据
35761
35720
  let price = lastPrice;
35762
35721
  if (!price) {
@@ -35778,12 +35737,13 @@ async function simulateTokenSell$1(mint, sellTokenAmount, passOrder = null, last
35778
35737
  orders = ordersData.data.orders.slice(0, this.sdk.MAX_ORDERS_COUNT + 1);
35779
35738
  }
35780
35739
 
35781
- // 获取动态流动池参数
35782
- let curveData;
35783
- try {
35784
- curveData = await this.sdk.chain.getCurveAccount(mint);
35785
- } catch (error) {
35786
- throw new Error(`Failed to get curve account data: ${error.message}`);
35740
+ // 获取动态流动池参数(支持外部传入,避免重复请求)
35741
+ if (!curveData) {
35742
+ try {
35743
+ curveData = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
35744
+ } catch (error) {
35745
+ throw new Error(`Failed to get curve account data: ${error.message}`);
35746
+ }
35787
35747
  }
35788
35748
 
35789
35749
  // console.log('simulateTokenSell 获取的数据:');
@@ -36427,8 +36387,8 @@ class SimulatorModule$1 {
36427
36387
  * - suggestedTokenAmount: {string} Recommended token amount to buy based on available liquidity
36428
36388
  * - suggestedSolAmount: {string} Required SOL amount for suggested token purchase
36429
36389
  */
36430
- async simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
36431
- return simulateTokenBuy.call(this, mint, buyTokenAmount, passOrder, lastPrice, ordersData);
36390
+ async simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
36391
+ return simulateTokenBuy.call(this, mint, buyTokenAmount, passOrder, lastPrice, ordersData, curveData);
36432
36392
  }
36433
36393
 
36434
36394
  /**
@@ -36454,8 +36414,8 @@ class SimulatorModule$1 {
36454
36414
  * - suggestedTokenAmount: {string} Recommended token amount to sell based on available liquidity
36455
36415
  * - suggestedSolAmount: {string} Expected SOL amount from suggested token sale
36456
36416
  */
36457
- async simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
36458
- return simulateTokenSell.call(this, mint, sellTokenAmount, passOrder, lastPrice, ordersData);
36417
+ async simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
36418
+ return simulateTokenSell.call(this, mint, sellTokenAmount, passOrder, lastPrice, ordersData, curveData);
36459
36419
  }
36460
36420
 
36461
36421
  /**
@@ -36494,8 +36454,8 @@ class SimulatorModule$1 {
36494
36454
  * @param {number} borrowFee - Borrow fee rate, default 2000 (2000/100000 = 0.02%)
36495
36455
  * @returns {Promise<Object>} Stop loss analysis result (same as simulateLongStopLoss)
36496
36456
  */
36497
- async simulateLongSolStopLoss(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
36498
- return simulateLongSolStopLoss.call(this, mint, buySolAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
36457
+ async simulateLongSolStopLoss(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
36458
+ return simulateLongSolStopLoss.call(this, mint, buySolAmount, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken, curveAccount);
36499
36459
  }
36500
36460
 
36501
36461
  /**
@@ -36508,8 +36468,8 @@ class SimulatorModule$1 {
36508
36468
  * @param {number} borrowFee - Borrow fee rate, default 2000 (2000/100000 = 0.02%)
36509
36469
  * @returns {Promise<Object>} Stop loss analysis result (same as simulateShortStopLoss)
36510
36470
  */
36511
- async simulateShortSolStopLoss(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
36512
- return simulateShortSolStopLoss.call(this, mint, sellSolAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
36471
+ async simulateShortSolStopLoss(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
36472
+ return simulateShortSolStopLoss.call(this, mint, sellSolAmount, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken, curveAccount);
36513
36473
  }
36514
36474
 
36515
36475
  /**
@@ -36588,15 +36548,13 @@ class SimulatorModule$1 {
36588
36548
  };
36589
36549
  }
36590
36550
 
36591
- // Get current price and orders data
36592
- const priceResult = await this.sdk.data.price(mint);
36593
- const ordersResult = await this.sdk.data.orders(mint, { type: 'down_orders' });
36594
-
36595
- console.log("ordersResult:",ordersResult);
36596
-
36597
- const upOrdersResult = await this.sdk.data.orders(mint, { type: 'up_orders' });
36598
- console.log("upOrdersResult:",upOrdersResult);
36599
- console.log("upOrdersResult:",upOrdersResult.data.orders);
36551
+ // Get current price, orders data, and curve account in parallel
36552
+ const [priceResult, ordersResult, upOrdersResult, curveAccount] = await Promise.all([
36553
+ this.sdk.data.price(mint),
36554
+ this.sdk.data.orders(mint, { type: 'down_orders' }),
36555
+ this.sdk.data.orders(mint, { type: 'up_orders' }),
36556
+ this.sdk.chain.getCurveAccount(mint, { skipBalances: true })
36557
+ ]);
36600
36558
 
36601
36559
  if (!priceResult || !ordersResult) {
36602
36560
  return {
@@ -36612,7 +36570,6 @@ class SimulatorModule$1 {
36612
36570
  const currentPrice = typeof priceResult === 'string' ? BigInt(priceResult) : BigInt(priceResult.last_price || priceResult);
36613
36571
 
36614
36572
  // Get curve account data for initialVirtualSol and initialVirtualToken
36615
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
36616
36573
  const initialVirtualSol = curveAccount.initialVirtualSol;
36617
36574
  const initialVirtualToken = curveAccount.initialVirtualToken;
36618
36575
 
@@ -36622,8 +36579,8 @@ class SimulatorModule$1 {
36622
36579
 
36623
36580
  const estimatedTokenAmount = reSolBuy.tokenAmount;
36624
36581
 
36625
- // Call simulateTokenBuy with estimated amount
36626
- const tokenBuyResult = await this.simulateTokenBuy(mint, estimatedTokenAmount, null, priceResult, ordersResult);
36582
+ // Call simulateTokenBuy with estimated amount, pass curveAccount to avoid duplicate RPC
36583
+ const tokenBuyResult = await this.simulateTokenBuy(mint, estimatedTokenAmount, null, priceResult, ordersResult, curveAccount);
36627
36584
 
36628
36585
  // Transform result to match simulateBuy format
36629
36586
  return {
@@ -36709,10 +36666,12 @@ class SimulatorModule$1 {
36709
36666
  };
36710
36667
  }
36711
36668
 
36712
- // Get current price and orders data
36669
+ // Get current price and orders data in parallel
36713
36670
  // For sell transactions, we need down_orders (long orders that provide buy liquidity)
36714
- const priceResult = await this.sdk.data.price(mint);
36715
- const ordersResult = await this.sdk.data.orders(mint, { type: 'down_orders' });
36671
+ const [priceResult, ordersResult] = await Promise.all([
36672
+ this.sdk.data.price(mint),
36673
+ this.sdk.data.orders(mint, { type: 'down_orders' })
36674
+ ]);
36716
36675
 
36717
36676
  if (!priceResult || !ordersResult) {
36718
36677
  return {
@@ -36785,6 +36744,21 @@ const { Buffer: Buffer$3 } = require$$2;
36785
36744
  class ChainModule$1 {
36786
36745
  constructor(sdk) {
36787
36746
  this.sdk = sdk;
36747
+ // getCurveAccount 缓存:key = mint string, value = { data, timestamp }
36748
+ this._curveAccountCache = new Map();
36749
+ this._CACHE_TTL = 10000; // 10 秒 TTL
36750
+ }
36751
+
36752
+ /**
36753
+ * 清除指定 mint 的 curveAccount 缓存(交易后调用)
36754
+ * @param {string} [mint] - 指定 mint 地址,不传则清除全部
36755
+ */
36756
+ invalidateCurveCache(mint) {
36757
+ if (mint) {
36758
+ this._curveAccountCache.delete(typeof mint === 'string' ? mint : mint.toString());
36759
+ } else {
36760
+ this._curveAccountCache.clear();
36761
+ }
36788
36762
  }
36789
36763
 
36790
36764
  /**
@@ -36913,10 +36887,23 @@ class ChainModule$1 {
36913
36887
  * @version 2.0.0 - Updated to use new OrderBook structure (up_orderbook/down_orderbook instead of upHead/downHead)
36914
36888
  * @author SpinPet SDK Team
36915
36889
  */
36916
- async getCurveAccount(mint) {
36890
+ async getCurveAccount(mint, options = {}) {
36891
+ const { skipBalances = false } = options;
36917
36892
  try {
36918
36893
  // Parameter validation and conversion
36919
36894
  const mintPubkey = typeof mint === 'string' ? new PublicKey$3(mint) : mint;
36895
+ const mintKey = mintPubkey.toString();
36896
+
36897
+ // 检查缓存
36898
+ const cached = this._curveAccountCache.get(mintKey);
36899
+ if (cached && (Date.now() - cached.timestamp < this._CACHE_TTL)) {
36900
+ // 缓存命中:如果请求包含余额但缓存没有,需要重新获取余额部分
36901
+ if (!skipBalances && cached.skipBalances) {
36902
+ // 缓存是 skipBalances 的,但现在需要余额,需要补充查询
36903
+ } else {
36904
+ return cached.data;
36905
+ }
36906
+ }
36920
36907
 
36921
36908
  // Calculate curve_account PDA address
36922
36909
  // Use the same seeds as in the contract: [b"borrowing_curve", mint_account.key().as_ref()]
@@ -36974,18 +36961,25 @@ class ChainModule$1 {
36974
36961
  this.sdk.programId
36975
36962
  );
36976
36963
 
36977
- // Query all balances concurrently
36978
- const [
36979
- baseFeeRecipientBalance,
36980
- feeRecipientBalance,
36981
- poolTokenBalance,
36982
- poolSolBalance
36983
- ] = await Promise.all([
36984
- this.sdk.connection.getBalance(decodedData.baseFeeRecipient),
36985
- this.sdk.connection.getBalance(decodedData.feeRecipient),
36986
- this.sdk.connection.getTokenAccountBalance(poolTokenAccountPDA).catch(() => ({ value: { amount: '0' } })),
36987
- this.sdk.connection.getBalance(poolSolAccountPDA)
36988
- ]);
36964
+ // Query balances (skip if not needed)
36965
+ let baseFeeRecipientBalance = 0;
36966
+ let feeRecipientBalance = 0;
36967
+ let poolTokenBalance = { value: { amount: '0' } };
36968
+ let poolSolBalance = 0;
36969
+
36970
+ if (!skipBalances) {
36971
+ [
36972
+ baseFeeRecipientBalance,
36973
+ feeRecipientBalance,
36974
+ poolTokenBalance,
36975
+ poolSolBalance
36976
+ ] = await Promise.all([
36977
+ this.sdk.connection.getBalance(decodedData.baseFeeRecipient),
36978
+ this.sdk.connection.getBalance(decodedData.feeRecipient),
36979
+ this.sdk.connection.getTokenAccountBalance(poolTokenAccountPDA).catch(() => ({ value: { amount: '0' } })),
36980
+ this.sdk.connection.getBalance(poolSolAccountPDA)
36981
+ ]);
36982
+ }
36989
36983
 
36990
36984
  // Convert data format
36991
36985
  const convertedData = {
@@ -37041,6 +37035,13 @@ class ChainModule$1 {
37041
37035
  }
37042
37036
  };
37043
37037
 
37038
+ // 写入缓存
37039
+ this._curveAccountCache.set(mintKey, {
37040
+ data: convertedData,
37041
+ timestamp: Date.now(),
37042
+ skipBalances: skipBalances
37043
+ });
37044
+
37044
37045
  // Return converted data
37045
37046
  return convertedData;
37046
37047
 
@@ -37097,58 +37098,13 @@ class ChainModule$1 {
37097
37098
  }
37098
37099
 
37099
37100
  try {
37100
- // Parameter validation and conversion
37101
- let mintPubkey;
37102
- try {
37103
- mintPubkey = typeof mint === 'string' ? new PublicKey$3(mint) : mint;
37104
- } catch (pubkeyError) {
37105
- throw new Error(`Invalid mint address: ${mint}`);
37106
- }
37107
-
37108
- // Validate mintPubkey
37109
- if (!mintPubkey || typeof mintPubkey.toBuffer !== 'function') {
37110
- throw new Error(`Invalid mintPubkey`);
37111
- }
37112
-
37113
- // Calculate curve_account PDA address
37114
- const [curveAccountPDA] = PublicKey$3.findProgramAddressSync(
37115
- [
37116
- Buffer$3.from("borrowing_curve"),
37117
- mintPubkey.toBuffer()
37118
- ],
37119
- this.sdk.programId
37120
- );
37121
-
37122
- // Use Anchor program to fetch account data directly
37123
- let decodedData;
37124
- try {
37125
- decodedData = await this.sdk.program.account.borrowingBondingCurve.fetch(curveAccountPDA);
37126
- } catch (fetchError) {
37127
- // If fetch fails, use raw method
37128
- const accountInfo = await this.sdk.connection.getAccountInfo(curveAccountPDA);
37129
- if (!accountInfo) {
37130
- throw new Error(`curve_account does not exist`);
37131
- }
37101
+ // 复用 getCurveAccount 缓存,避免重复 fetch 同一个账户
37102
+ const curveData = await this.getCurveAccount(mint, { skipBalances: true });
37103
+ const price = curveData.price;
37132
37104
 
37133
- // Manually decode with BorshAccountsCoder
37134
- const accountsCoder = new anchor$2.BorshAccountsCoder(this.sdk.program.idl);
37135
-
37136
- try {
37137
- decodedData = accountsCoder.decode('BorrowingBondingCurve', accountInfo.data);
37138
- } catch (decodeError1) {
37139
- try {
37140
- decodedData = accountsCoder.decode('borrowingBondingCurve', accountInfo.data);
37141
- } catch (decodeError2) {
37142
- throw new Error(`Cannot decode account data: ${decodeError1.message}`);
37143
- }
37144
- }
37145
- }
37146
-
37147
- // Check price data and return
37148
- if (decodedData.price && decodedData.price.toString() !== '0') {
37149
- return decodedData.price.toString();
37105
+ if (price && price !== 0n) {
37106
+ return price.toString();
37150
37107
  } else {
37151
- // If no price data, return initial price
37152
37108
  const initialPrice = CurveAMM$2.getInitialPrice();
37153
37109
  if (initialPrice === null) {
37154
37110
  throw new Error('price: Unable to calculate initial price');
@@ -37244,14 +37200,16 @@ class ChainModule$1 {
37244
37200
  // Convert API type to orderbook direction
37245
37201
  // "up_orders" = short orders = upOrderbook (orderType=2)
37246
37202
  // "down_orders" = long orders = downOrderbook (orderType=1)
37247
- const orderbookField = orderType === 'up_orders' ? 'upOrderbook' : 'downOrderbook';
37203
+ const seed = orderType === 'up_orders' ? 'up_orderbook' : 'down_orderbook';
37248
37204
 
37249
- // Get curve_account data to get orderbook address
37250
- const curveData = await this.getCurveAccount(mint);
37251
- const orderbookAddress = curveData[orderbookField];
37205
+ // 本地计算 orderbook PDA,避免调用 getCurveAccount(省 5 RPC)
37206
+ const mintPubkey = new PublicKey$3(mint);
37207
+ const [orderbookPubkey] = PublicKey$3.findProgramAddressSync(
37208
+ [Buffer$3.from(seed), mintPubkey.toBuffer()],
37209
+ this.sdk.programId
37210
+ );
37252
37211
 
37253
37212
  // Get OrderBook account data
37254
- const orderbookPubkey = new PublicKey$3(orderbookAddress);
37255
37213
  const accountInfo = await this.sdk.connection.getAccountInfo(orderbookPubkey);
37256
37214
 
37257
37215
  if (!accountInfo) {
@@ -37702,15 +37660,15 @@ class ChainModule$1 {
37702
37660
  throw new Error('debug_orders: order type must be "up_orders" or "down_orders"');
37703
37661
  }
37704
37662
 
37705
- // Convert API type to orderbook direction
37706
- const orderbookField = orderType === 'up_orders' ? 'upOrderbook' : 'downOrderbook';
37707
-
37708
- // Get curve_account data to get orderbook address
37709
- const curveData = await this.getCurveAccount(mint);
37710
- const orderbookAddress = curveData[orderbookField];
37663
+ // 本地计算 orderbook PDA,避免调用 getCurveAccount(省 5 个 RPC)
37664
+ const seed = orderType === 'up_orders' ? 'up_orderbook' : 'down_orderbook';
37665
+ const mintPubkey = new PublicKey$3(mint);
37666
+ const [orderbookPubkey] = PublicKey$3.findProgramAddressSync(
37667
+ [Buffer$3.from(seed), mintPubkey.toBuffer()],
37668
+ this.sdk.programId
37669
+ );
37711
37670
 
37712
37671
  // Get OrderBook account data
37713
- const orderbookPubkey = new PublicKey$3(orderbookAddress);
37714
37672
  const accountInfo = await this.sdk.connection.getAccountInfo(orderbookPubkey);
37715
37673
 
37716
37674
  if (!accountInfo) {
@@ -37913,10 +37871,18 @@ class ChainModule$1 {
37913
37871
  const page = 1; // Always return page 1
37914
37872
  const orderBy = options.order_by || 'start_time_desc';
37915
37873
 
37916
- // Get curve_account data to get both OrderBook addresses
37917
- const curveData = await this.getCurveAccount(mint);
37918
- const upOrderbookAddress = curveData.upOrderbook; // Short orders (orderType=2)
37919
- const downOrderbookAddress = curveData.downOrderbook; // Long orders (orderType=1)
37874
+ // 本地计算 orderbook PDA,避免调用 getCurveAccount(省 5 RPC)
37875
+ const mintPubkey = new PublicKey$3(mint);
37876
+ const [upOrderbookPubkey] = PublicKey$3.findProgramAddressSync(
37877
+ [Buffer$3.from('up_orderbook'), mintPubkey.toBuffer()],
37878
+ this.sdk.programId
37879
+ );
37880
+ const [downOrderbookPubkey] = PublicKey$3.findProgramAddressSync(
37881
+ [Buffer$3.from('down_orderbook'), mintPubkey.toBuffer()],
37882
+ this.sdk.programId
37883
+ );
37884
+ const upOrderbookAddress = upOrderbookPubkey.toString(); // Short orders (orderType=2)
37885
+ const downOrderbookAddress = downOrderbookPubkey.toString(); // Long orders (orderType=1)
37920
37886
 
37921
37887
  // Collect all user orders from both OrderBooks
37922
37888
  const allUserOrders = [];
@@ -38444,7 +38410,7 @@ class OrderUtils$2 {
38444
38410
 
38445
38411
  var orderUtils = OrderUtils$2;
38446
38412
 
38447
- var address = "CYdRzRacZ5kTc9Ht3U7mFhbsyxG3sZGEzC4cNf2Gjg2W";
38413
+ var address = "F2FzigE1Z374iDvreiM6hZQe6oGXgomJfv8PyybvUXye";
38448
38414
  var metadata = {
38449
38415
  name: "pinpet",
38450
38416
  version: "0.1.0",
@@ -41018,476 +40984,471 @@ var errors = [
41018
40984
  },
41019
40985
  {
41020
40986
  code: 6021,
41021
- name: "CloseShortImpossibleState",
41022
- msg: "Close short impossible state: current_total should always be greater than remaining_close_reduced_sol_with_fee"
41023
- },
41024
- {
41025
- code: 6022,
41026
40987
  name: "FeeSplitCalculationOverflow",
41027
40988
  msg: "Fee split calculation overflow"
41028
40989
  },
41029
40990
  {
41030
- code: 6023,
40991
+ code: 6022,
41031
40992
  name: "FeeAccumulationOverflow",
41032
40993
  msg: "Fee accumulation overflow"
41033
40994
  },
41034
40995
  {
41035
- code: 6024,
40996
+ code: 6023,
41036
40997
  name: "PartnerFeeAdditionOverflow",
41037
40998
  msg: "Partner fee addition overflow"
41038
40999
  },
41039
41000
  {
41040
- code: 6025,
41001
+ code: 6024,
41041
41002
  name: "BaseFeeAdditionOverflow",
41042
41003
  msg: "Base fee addition overflow"
41043
41004
  },
41044
41005
  {
41045
- code: 6026,
41006
+ code: 6025,
41046
41007
  name: "PoolFeeDeductionOverflow",
41047
41008
  msg: "Pool fee deduction overflow"
41048
41009
  },
41049
41010
  {
41050
- code: 6027,
41011
+ code: 6026,
41051
41012
  name: "FeeRandomDiscountOverflow",
41052
41013
  msg: "Fee random discount calculation overflow"
41053
41014
  },
41054
41015
  {
41055
- code: 6028,
41016
+ code: 6027,
41056
41017
  name: "SolReserveAdditionOverflow",
41057
41018
  msg: "SOL reserve addition overflow"
41058
41019
  },
41059
41020
  {
41060
- code: 6029,
41021
+ code: 6028,
41061
41022
  name: "SolReserveDeductionOverflow",
41062
41023
  msg: "SOL reserve deduction overflow"
41063
41024
  },
41064
41025
  {
41065
- code: 6030,
41026
+ code: 6029,
41066
41027
  name: "TokenReserveAdditionOverflow",
41067
41028
  msg: "Token reserve addition overflow"
41068
41029
  },
41069
41030
  {
41070
- code: 6031,
41031
+ code: 6030,
41071
41032
  name: "LamportsAdditionOverflow",
41072
41033
  msg: "Lamports addition overflow"
41073
41034
  },
41074
41035
  {
41075
- code: 6032,
41036
+ code: 6031,
41076
41037
  name: "LamportsDeductionOverflow",
41077
41038
  msg: "Lamports deduction overflow"
41078
41039
  },
41079
41040
  {
41080
- code: 6033,
41041
+ code: 6032,
41081
41042
  name: "DeadlineCalculationOverflow",
41082
41043
  msg: "Deadline calculation overflow"
41083
41044
  },
41084
41045
  {
41085
- code: 6034,
41046
+ code: 6033,
41086
41047
  name: "FeeDiscountFlagOverflow",
41087
41048
  msg: "Fee discount flag calculation overflow"
41088
41049
  },
41089
41050
  {
41090
- code: 6035,
41051
+ code: 6034,
41091
41052
  name: "Unauthorized",
41092
41053
  msg: "Unauthorized operation"
41093
41054
  },
41094
41055
  {
41095
- code: 6036,
41056
+ code: 6035,
41096
41057
  name: "RequiredParameter",
41097
41058
  msg: "All parameters are required during initialization"
41098
41059
  },
41099
41060
  {
41100
- code: 6037,
41061
+ code: 6036,
41101
41062
  name: "CurveCalculationError",
41102
41063
  msg: "Curve calculation error"
41103
41064
  },
41104
41065
  {
41105
- code: 6038,
41066
+ code: 6037,
41106
41067
  name: "InitialPriceCalculationError",
41107
41068
  msg: "Initial price calculation failed"
41108
41069
  },
41109
41070
  {
41110
- code: 6039,
41071
+ code: 6038,
41111
41072
  name: "BuyReserveRecalculationError",
41112
41073
  msg: "Reserve recalculation failed (after buy)"
41113
41074
  },
41114
41075
  {
41115
- code: 6040,
41076
+ code: 6039,
41116
41077
  name: "SellReserveRecalculationError",
41117
41078
  msg: "Reserve recalculation failed (after sell)"
41118
41079
  },
41119
41080
  {
41120
- code: 6041,
41081
+ code: 6040,
41121
41082
  name: "TotalAmountWithFeeError",
41122
41083
  msg: "Total amount with fee calculation failed"
41123
41084
  },
41124
41085
  {
41125
- code: 6042,
41086
+ code: 6041,
41126
41087
  name: "AmountAfterFeeError",
41127
41088
  msg: "Amount after fee calculation failed"
41128
41089
  },
41129
41090
  {
41130
- code: 6043,
41091
+ code: 6042,
41131
41092
  name: "BuyPriceRangeCalculationError",
41132
41093
  msg: "Buy price range calculation failed"
41133
41094
  },
41134
41095
  {
41135
- code: 6044,
41096
+ code: 6043,
41136
41097
  name: "SellPriceRangeCalculationError",
41137
41098
  msg: "Sell price range calculation failed"
41138
41099
  },
41139
41100
  {
41140
- code: 6045,
41101
+ code: 6044,
41141
41102
  name: "PriceAtStopLossBoundary",
41142
41103
  msg: "Price has reached stop-loss boundary, head order must be liquidated first"
41143
41104
  },
41144
41105
  {
41145
- code: 6046,
41106
+ code: 6045,
41146
41107
  name: "RemainingRangeCalculationError",
41147
41108
  msg: "Remaining range calculation failed"
41148
41109
  },
41149
41110
  {
41150
- code: 6047,
41111
+ code: 6046,
41151
41112
  name: "FullRangeCalculationError",
41152
41113
  msg: "Full range calculation failed"
41153
41114
  },
41154
41115
  {
41155
- code: 6048,
41116
+ code: 6047,
41156
41117
  name: "BuyFromPriceWithTokenNoneError",
41157
41118
  msg: "Curve function returned None: buy_from_price_with_token_output"
41158
41119
  },
41159
41120
  {
41160
- code: 6049,
41121
+ code: 6048,
41161
41122
  name: "SellFromPriceWithTokenNoneError",
41162
41123
  msg: "Curve function returned None: sell_from_price_with_token_input"
41163
41124
  },
41164
41125
  {
41165
- code: 6050,
41126
+ code: 6049,
41166
41127
  name: "ExceedsMaxSolAmount",
41167
41128
  msg: "Required SOL amount exceeds user-set maximum"
41168
41129
  },
41169
41130
  {
41170
- code: 6051,
41131
+ code: 6050,
41171
41132
  name: "InsufficientSolOutput",
41172
41133
  msg: "Insufficient SOL output"
41173
41134
  },
41174
41135
  {
41175
- code: 6052,
41136
+ code: 6051,
41176
41137
  name: "InsufficientRepayment",
41177
41138
  msg: "Insufficient proceeds to repay loan"
41178
41139
  },
41179
41140
  {
41180
- code: 6053,
41141
+ code: 6052,
41181
41142
  name: "InsufficientBorrowingReserve",
41182
41143
  msg: "Insufficient borrowing reserve"
41183
41144
  },
41184
41145
  {
41185
- code: 6054,
41146
+ code: 6053,
41186
41147
  name: "InsufficientTokenSale",
41187
41148
  msg: "Insufficient token sale amount"
41188
41149
  },
41189
41150
  {
41190
- code: 6055,
41151
+ code: 6054,
41191
41152
  name: "InsufficientLiquidity",
41192
41153
  msg: "Insufficient liquidity in current order"
41193
41154
  },
41194
41155
  {
41195
- code: 6056,
41156
+ code: 6055,
41196
41157
  name: "InsufficientMarketLiquidity",
41197
41158
  msg: "Insufficient market liquidity, cannot satisfy trade even after liquidating all stop-loss orders"
41198
41159
  },
41199
41160
  {
41200
- code: 6057,
41161
+ code: 6056,
41201
41162
  name: "TokenAmountDifferenceOutOfRange",
41202
41163
  msg: "Token amount difference exceeds valid range in margin trade"
41203
41164
  },
41204
41165
  {
41205
- code: 6058,
41166
+ code: 6057,
41206
41167
  name: "BorrowAmountMismatch",
41207
41168
  msg: "Borrow amount mismatch with locked tokens"
41208
41169
  },
41209
41170
  {
41210
- code: 6059,
41171
+ code: 6058,
41211
41172
  name: "CloseFeeCalculationError",
41212
41173
  msg: "Close fee calculation error"
41213
41174
  },
41214
41175
  {
41215
- code: 6060,
41176
+ code: 6059,
41216
41177
  name: "InsufficientMargin",
41217
41178
  msg: "Insufficient margin"
41218
41179
  },
41219
41180
  {
41220
- code: 6061,
41181
+ code: 6060,
41221
41182
  name: "InsufficientMinimumMargin",
41222
41183
  msg: "Margin below minimum requirement"
41223
41184
  },
41224
41185
  {
41225
- code: 6062,
41186
+ code: 6061,
41226
41187
  name: "InvalidAccountOwner",
41227
41188
  msg: "Invalid account owner"
41228
41189
  },
41229
41190
  {
41230
- code: 6063,
41191
+ code: 6062,
41231
41192
  name: "SellAmountExceedsOrderAmount",
41232
41193
  msg: "Sell amount exceeds order's token holdings"
41233
41194
  },
41234
41195
  {
41235
- code: 6064,
41196
+ code: 6063,
41236
41197
  name: "OrderNotExpiredMustCloseByOwner",
41237
41198
  msg: "Non-expired order must be closed by owner"
41238
41199
  },
41239
41200
  {
41240
- code: 6065,
41201
+ code: 6064,
41241
41202
  name: "SettlementAddressMustBeOwnerAddress",
41242
41203
  msg: "Settlement address must be owner address"
41243
41204
  },
41244
41205
  {
41245
- code: 6066,
41206
+ code: 6065,
41246
41207
  name: "BuyAmountExceedsOrderAmount",
41247
41208
  msg: "Buy amount exceeds order's token holdings"
41248
41209
  },
41249
41210
  {
41250
- code: 6067,
41211
+ code: 6066,
41251
41212
  name: "InsufficientTradeAmount",
41252
41213
  msg: "Trade amount below minimum requirement"
41253
41214
  },
41254
41215
  {
41255
- code: 6068,
41216
+ code: 6067,
41256
41217
  name: "SolAmountTooLarge",
41257
41218
  msg: "SOL amount exceeds maximum limit (10000000 SOL per transaction)"
41258
41219
  },
41259
41220
  {
41260
- code: 6069,
41221
+ code: 6068,
41261
41222
  name: "RemainingTokenAmountTooSmall",
41262
41223
  msg: "Remaining token amount below minimum trade requirement"
41263
41224
  },
41264
41225
  {
41265
- code: 6070,
41226
+ code: 6069,
41266
41227
  name: "TradeCooldownNotExpired",
41267
41228
  msg: "Trade cooldown period not expired, please try again later"
41268
41229
  },
41269
41230
  {
41270
- code: 6071,
41231
+ code: 6070,
41271
41232
  name: "ExceedApprovalAmount",
41272
41233
  msg: "Sell amount exceeds approved amount, please call approval function first"
41273
41234
  },
41274
41235
  {
41275
- code: 6072,
41236
+ code: 6071,
41276
41237
  name: "CooldownNotInitialized",
41277
41238
  msg: "Sell trade requires calling approval or buy function first to initialize cooldown PDA"
41278
41239
  },
41279
41240
  {
41280
- code: 6073,
41241
+ code: 6072,
41281
41242
  name: "CannotCloseCooldownWithBalance",
41282
41243
  msg: "Cannot close cooldown PDA with non-zero token balance"
41283
41244
  },
41284
41245
  {
41285
- code: 6074,
41246
+ code: 6073,
41286
41247
  name: "PriceCalculationError",
41287
41248
  msg: "Price calculation error"
41288
41249
  },
41289
41250
  {
41290
- code: 6075,
41251
+ code: 6074,
41291
41252
  name: "InvalidPartnerFeeRecipientAccount",
41292
41253
  msg: "Invalid partner fee recipient account"
41293
41254
  },
41294
41255
  {
41295
- code: 6076,
41256
+ code: 6075,
41296
41257
  name: "InvalidBaseFeeRecipientAccount",
41297
41258
  msg: "Invalid base fee recipient account"
41298
41259
  },
41299
41260
  {
41300
- code: 6077,
41261
+ code: 6076,
41301
41262
  name: "InvalidOrderbookAddress",
41302
41263
  msg: "Orderbook address does not match curve account orderbook"
41303
41264
  },
41304
41265
  {
41305
- code: 6078,
41266
+ code: 6077,
41306
41267
  name: "InvalidFeePercentage",
41307
41268
  msg: "Fee percentage must be between 0-100"
41308
41269
  },
41309
41270
  {
41310
- code: 6079,
41271
+ code: 6078,
41311
41272
  name: "InvalidFeeRate",
41312
41273
  msg: "Fee rate exceeds maximum limit (10%)"
41313
41274
  },
41314
41275
  {
41315
- code: 6080,
41276
+ code: 6079,
41316
41277
  name: "InvalidCustomFeeRate",
41317
41278
  msg: "Custom fee rate must be between 1000 (1%) and 5000 (5%)"
41318
41279
  },
41319
41280
  {
41320
- code: 6081,
41281
+ code: 6080,
41321
41282
  name: "InvalidBorrowDuration",
41322
41283
  msg: "Borrow duration out of valid range (3-30 days)"
41323
41284
  },
41324
41285
  {
41325
- code: 6082,
41286
+ code: 6081,
41326
41287
  name: "InvalidStopLossPrice",
41327
41288
  msg: "Stop loss price does not meet minimum interval requirement"
41328
41289
  },
41329
41290
  {
41330
- code: 6083,
41291
+ code: 6082,
41331
41292
  name: "NoProfitableFunds",
41332
41293
  msg: "No profitable funds to transfer"
41333
41294
  },
41334
41295
  {
41335
- code: 6084,
41296
+ code: 6083,
41336
41297
  name: "InsufficientPoolFunds",
41337
41298
  msg: "Insufficient pool funds"
41338
41299
  },
41339
41300
  {
41340
- code: 6085,
41301
+ code: 6084,
41341
41302
  name: "InsufficientPoolBalance",
41342
41303
  msg: "Pool SOL account balance would fall below minimum required balance"
41343
41304
  },
41344
41305
  {
41345
- code: 6086,
41306
+ code: 6085,
41346
41307
  name: "OrderBookManagerOverflow",
41347
41308
  msg: "Math operation overflow"
41348
41309
  },
41349
41310
  {
41350
- code: 6087,
41311
+ code: 6086,
41351
41312
  name: "OrderBookManagerInvalidSlotIndex",
41352
41313
  msg: "Invalid slot index"
41353
41314
  },
41354
41315
  {
41355
- code: 6088,
41316
+ code: 6087,
41356
41317
  name: "OrderBookManagerInvalidAccountData",
41357
41318
  msg: "Invalid account data"
41358
41319
  },
41359
41320
  {
41360
- code: 6089,
41321
+ code: 6088,
41361
41322
  name: "OrderBookManagerExceedsMaxCapacity",
41362
41323
  msg: "New capacity exceeds maximum limit"
41363
41324
  },
41364
41325
  {
41365
- code: 6090,
41326
+ code: 6089,
41366
41327
  name: "OrderBookManagerExceedsAccountSizeLimit",
41367
41328
  msg: "Account size exceeds 10MB limit"
41368
41329
  },
41369
41330
  {
41370
- code: 6091,
41331
+ code: 6090,
41371
41332
  name: "OrderBookManagerOrderIdMismatch",
41372
41333
  msg: "Order ID mismatch"
41373
41334
  },
41374
41335
  {
41375
- code: 6092,
41336
+ code: 6091,
41376
41337
  name: "OrderBookManagerEmptyOrderBook",
41377
41338
  msg: "Order book is empty"
41378
41339
  },
41379
41340
  {
41380
- code: 6093,
41341
+ code: 6092,
41381
41342
  name: "OrderBookManagerAccountNotWritable",
41382
41343
  msg: "Account is not writable"
41383
41344
  },
41384
41345
  {
41385
- code: 6094,
41346
+ code: 6093,
41386
41347
  name: "OrderBookManagerNotRentExempt",
41387
41348
  msg: "Account not rent-exempt"
41388
41349
  },
41389
41350
  {
41390
- code: 6095,
41351
+ code: 6094,
41391
41352
  name: "OrderBookManagerInvalidRentBalance",
41392
41353
  msg: "Invalid rent balance"
41393
41354
  },
41394
41355
  {
41395
- code: 6096,
41356
+ code: 6095,
41396
41357
  name: "OrderBookManagerInsufficientFunds",
41397
41358
  msg: "Insufficient funds"
41398
41359
  },
41399
41360
  {
41400
- code: 6097,
41361
+ code: 6096,
41401
41362
  name: "OrderBookManagerInvalidAccountOwner",
41402
41363
  msg: "OrderBook account owner mismatch"
41403
41364
  },
41404
41365
  {
41405
- code: 6098,
41366
+ code: 6097,
41406
41367
  name: "OrderBookManagerDataOutOfBounds",
41407
41368
  msg: "Data access out of bounds"
41408
41369
  },
41409
41370
  {
41410
- code: 6099,
41371
+ code: 6098,
41411
41372
  name: "NoValidInsertPosition",
41412
41373
  msg: "Cannot find valid insert position, all candidates failed due to price range overlap"
41413
41374
  },
41414
41375
  {
41415
- code: 6100,
41376
+ code: 6099,
41416
41377
  name: "EmptyCloseInsertIndices",
41417
41378
  msg: "close_insert_indices array cannot be empty"
41418
41379
  },
41419
41380
  {
41420
- code: 6101,
41381
+ code: 6100,
41421
41382
  name: "TooManyCloseInsertIndices",
41422
41383
  msg: "close_insert_indices array cannot exceed 20 elements"
41423
41384
  },
41424
41385
  {
41425
- code: 6102,
41386
+ code: 6101,
41426
41387
  name: "CloseOrderNotFound",
41427
41388
  msg: "Specified close order not found"
41428
41389
  },
41429
41390
  {
41430
- code: 6103,
41391
+ code: 6102,
41431
41392
  name: "LinkedListDeleteCountMismatch",
41432
41393
  msg: "Linked list delete count mismatch: count inconsistent before/after deletion"
41433
41394
  },
41434
41395
  {
41435
- code: 6104,
41396
+ code: 6103,
41436
41397
  name: "NameTooLong",
41437
41398
  msg: "Token name too long, max 32 bytes"
41438
41399
  },
41439
41400
  {
41440
- code: 6105,
41401
+ code: 6104,
41441
41402
  name: "NameEmpty",
41442
41403
  msg: "Token name cannot be empty"
41443
41404
  },
41444
41405
  {
41445
- code: 6106,
41406
+ code: 6105,
41446
41407
  name: "SymbolTooLong",
41447
41408
  msg: "Token symbol too long, max 10 bytes"
41448
41409
  },
41449
41410
  {
41450
- code: 6107,
41411
+ code: 6106,
41451
41412
  name: "SymbolEmpty",
41452
41413
  msg: "Token symbol cannot be empty"
41453
41414
  },
41454
41415
  {
41455
- code: 6108,
41416
+ code: 6107,
41456
41417
  name: "UriTooLong",
41457
41418
  msg: "URI too long, max 200 bytes"
41458
41419
  },
41459
41420
  {
41460
- code: 6109,
41421
+ code: 6108,
41461
41422
  name: "UriEmpty",
41462
41423
  msg: "URI cannot be empty"
41463
41424
  },
41464
41425
  {
41465
- code: 6110,
41426
+ code: 6109,
41466
41427
  name: "IncompleteAdvancedPoolParams",
41467
41428
  msg: "Incomplete advanced pool parameters: custom_lp_sol, custom_lp_token, custom_borrow_ratio, custom_borrow_duration must be provided together"
41468
41429
  },
41469
41430
  {
41470
- code: 6111,
41431
+ code: 6110,
41471
41432
  name: "InvalidInitialVirtualSol",
41472
41433
  msg: "Initial virtual SOL out of valid range"
41473
41434
  },
41474
41435
  {
41475
- code: 6112,
41436
+ code: 6111,
41476
41437
  name: "InvalidInitialVirtualToken",
41477
41438
  msg: "Initial virtual Token out of valid range"
41478
41439
  },
41479
41440
  {
41480
- code: 6113,
41441
+ code: 6112,
41481
41442
  name: "InvalidBorrowPoolRatio",
41482
41443
  msg: "Borrow pool ratio out of valid range"
41483
41444
  },
41484
41445
  {
41485
- code: 6114,
41446
+ code: 6113,
41486
41447
  name: "BorrowTokenCalculationOverflow",
41487
41448
  msg: "Borrow pool token amount calculation overflow"
41488
41449
  },
41489
41450
  {
41490
- code: 6115,
41451
+ code: 6114,
41491
41452
  name: "BorrowTokenAmountZero",
41492
41453
  msg: "Borrow pool token amount cannot be zero"
41493
41454
  }