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.
@@ -15579,9 +15579,9 @@ const MIN_STOP_LOSS_PERCENT$1 = 40; // 4.0%
15579
15579
 
15580
15580
  // Maximum number of candidate indices to include in close_insert_indices
15581
15581
  // This represents: 1 main position + N nodes before + N nodes after
15582
- // Must be an odd number >= 1 (e.g., 21 = 1 main + 10 before + 10 after)
15583
- // The contract accepts up to 20, we use 21 to provide more flexibility
15584
- const MAX_CANDIDATE_INDICES$3 = 31;
15582
+ // Must be an odd number >= 1 (e.g., 41 = 1 main + 20 before + 20 after)
15583
+ // The contract accepts up to 41
15584
+ const MAX_CANDIDATE_INDICES$3 = 19;
15585
15585
 
15586
15586
 
15587
15587
  /**
@@ -15703,8 +15703,8 @@ class TradingModule$1 {
15703
15703
  )
15704
15704
  : null;
15705
15705
 
15706
- // 6. Get fee recipient accounts from curve account
15707
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
15706
+ // 6. Get fee recipient accounts from curve account (skipBalances: only need addresses)
15707
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
15708
15708
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
15709
15709
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
15710
15710
 
@@ -15839,8 +15839,8 @@ class TradingModule$1 {
15839
15839
  )
15840
15840
  : null;
15841
15841
 
15842
- // 6. Get fee recipient accounts from curve account
15843
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
15842
+ // 6. Get fee recipient accounts from curve account (skipBalances: only need addresses)
15843
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
15844
15844
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
15845
15845
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
15846
15846
 
@@ -16219,8 +16219,8 @@ class TradingModule$1 {
16219
16219
  this.sdk.programId
16220
16220
  );
16221
16221
 
16222
- // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account
16223
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
16222
+ // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account (skipBalances: only need addresses)
16223
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
16224
16224
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
16225
16225
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
16226
16226
 
@@ -16368,8 +16368,8 @@ class TradingModule$1 {
16368
16368
  this.sdk.programId
16369
16369
  );
16370
16370
 
16371
- // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account
16372
- const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint);
16371
+ // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account (skipBalances: only need addresses)
16372
+ const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
16373
16373
  const feeRecipientAccount = new PublicKey$6(curveAccountInfo.feeRecipient);
16374
16374
  const baseFeeRecipientAccount = new PublicKey$6(curveAccountInfo.baseFeeRecipient);
16375
16375
 
@@ -16471,7 +16471,7 @@ class TradingModule$1 {
16471
16471
 
16472
16472
  var trading = TradingModule$1;
16473
16473
 
16474
- const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1, VersionedTransaction, TransactionMessage } = require$$0__default["default"];
16474
+ const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = require$$0__default["default"];
16475
16475
  const { TOKEN_PROGRAM_ID: TOKEN_PROGRAM_ID$1, getAssociatedTokenAddress: getAssociatedTokenAddress$1, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID: ASSOCIATED_TOKEN_PROGRAM_ID$1 } = cjs$3;
16476
16476
  const anchor$3 = require$$0__default$3["default"];
16477
16477
  // 统一使用 buffer 包,所有平台一致
@@ -16708,13 +16708,8 @@ class TokenModule$1 {
16708
16708
  }
16709
16709
 
16710
16710
  /**
16711
- * Create token and buy in one transaction (使用 VersionedTransaction v0)
16712
- * 将 create 和 buy 两个指令合并到一个 v0 交易中,一次签名提交
16713
- *
16714
- * 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
16715
- * - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
16716
- * - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
16717
- * - 发送方式:connection.sendRawTransaction(signedTx.serialize())
16711
+ * Create token and buy in one transaction
16712
+ * 将 create 和 buy 两个指令合并到一个交易中,一次签名提交
16718
16713
  *
16719
16714
  * @param {Object} params - Creation and buy parameters
16720
16715
  * @param {Keypair} params.mint - Token mint keypair
@@ -16734,20 +16729,7 @@ class TokenModule$1 {
16734
16729
  *
16735
16730
  * @param {Object} options - Optional parameters
16736
16731
  * @param {number} options.computeUnits - Compute units limit, default 1800000
16737
- * @returns {Promise<Object>} Object containing VersionedTransaction, signers, accounts and blockhashInfo
16738
- *
16739
- * @example
16740
- * // Node.js 环境
16741
- * const result = await sdk.token.createAndBuy({...});
16742
- * result.transaction.sign([wallet, ...result.signers]);
16743
- * const sig = await connection.sendRawTransaction(result.transaction.serialize());
16744
- *
16745
- * @example
16746
- * // 浏览器 Phantom 环境
16747
- * const result = await sdk.token.createAndBuy({...});
16748
- * result.transaction.sign(result.signers); // mint keypair 先签名
16749
- * const signed = await phantom.signTransaction(result.transaction); // Phantom 追加 payer 签名
16750
- * const sig = await connection.sendRawTransaction(signed.serialize());
16732
+ * @returns {Promise<Object>} Object containing transaction, signers and account info
16751
16733
  */
16752
16734
  async createAndBuy({
16753
16735
  mint,
@@ -16766,7 +16748,7 @@ class TokenModule$1 {
16766
16748
  }, options = {}) {
16767
16749
  const { computeUnits = 1800000 } = options;
16768
16750
 
16769
- console.log('Token Module - CreateAndBuy (VersionedTransaction):', {
16751
+ console.log('Token Module - CreateAndBuy:', {
16770
16752
  mint: mint.publicKey.toString(),
16771
16753
  name,
16772
16754
  symbol,
@@ -16802,6 +16784,7 @@ class TokenModule$1 {
16802
16784
  console.log('Step 2: Fetching fee recipient accounts from params...');
16803
16785
 
16804
16786
  // 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
16787
+ // 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
16805
16788
  const feeRecipientAccount = this.sdk.feeRecipient;
16806
16789
  const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
16807
16790
 
@@ -16892,54 +16875,42 @@ class TokenModule$1 {
16892
16875
  })
16893
16876
  .instruction();
16894
16877
 
16895
- // 7. 收集所有指令
16896
- console.log('Step 6: Building VersionedTransaction (v0)...');
16897
- const instructions = [];
16878
+ // 7. 合并交易:create + buy
16879
+ console.log('Step 6: Merging create and buy transactions...');
16880
+ const transaction = new Transaction$2();
16898
16881
 
16899
16882
  // 设置计算单元限制
16900
16883
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
16901
16884
  units: computeUnits
16902
16885
  });
16903
- instructions.push(modifyComputeUnits);
16886
+ transaction.add(modifyComputeUnits);
16904
16887
 
16905
16888
  // 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
16906
16889
  createResult.transaction.instructions.forEach(ix => {
16890
+ // 跳过 create 交易中的计算单元指令(我们已经添加了)
16907
16891
  if (ix.programId.equals(ComputeBudgetProgram.programId)) {
16908
16892
  return;
16909
16893
  }
16910
- instructions.push(ix);
16894
+ transaction.add(ix);
16911
16895
  });
16912
16896
 
16913
16897
  // 添加 ATA 创建指令(如果需要)
16914
16898
  if (createAtaIx) {
16915
- instructions.push(createAtaIx);
16899
+ transaction.add(createAtaIx);
16916
16900
  }
16917
16901
 
16918
- // 添加 buy 指令
16919
- instructions.push(buyIx);
16920
-
16921
- // 8. 获取最新 blockhash 并构建 VersionedTransaction
16922
- const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
16923
-
16924
- const messageV0 = new TransactionMessage({
16925
- payerKey: payer,
16926
- recentBlockhash: blockhashResult.blockhash,
16927
- instructions: instructions,
16928
- }).compileToV0Message();
16929
-
16930
- const transaction = new VersionedTransaction(messageV0);
16931
-
16932
- // 9. 用 mint keypair 预签名(调用方只需 payer 签名)
16933
- transaction.sign([mint]);
16902
+ // 添加 buy 指令
16903
+ transaction.add(buyIx);
16934
16904
 
16935
- console.log('CreateAndBuy VersionedTransaction built successfully:');
16936
- console.log(' Total instructions:', instructions.length);
16905
+ console.log('CreateAndBuy transaction built successfully:');
16906
+ console.log(' Total instructions:', transaction.instructions.length);
16937
16907
  console.log(' Compute units:', computeUnits);
16938
- console.log(' mint keypair pre-signed, caller only needs payer signature');
16908
+ console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
16939
16909
 
16940
- // 10. 返回 VersionedTransaction(mint 已预签名)
16910
+ // 8. 返回合并后的交易
16941
16911
  return {
16942
- transaction, // 已包含 mint 签名
16912
+ transaction,
16913
+ signers: [mint], // mint keypair 需要签名
16943
16914
  accounts: {
16944
16915
  // create 的账户
16945
16916
  ...createResult.accounts,
@@ -16948,23 +16919,10 @@ class TokenModule$1 {
16948
16919
  cooldown: cooldownPDA,
16949
16920
  feeRecipientAccount,
16950
16921
  baseFeeRecipientAccount
16951
- },
16952
- // 返回 blockhash 信息供调用方确认交易使用
16953
- blockhashInfo: {
16954
- blockhash: blockhashResult.blockhash,
16955
- lastValidBlockHeight: blockhashResult.lastValidBlockHeight
16956
16922
  }
16957
16923
  };
16958
16924
  }
16959
16925
 
16960
- /**
16961
- * createAndBuy 的别名(功能完全相同)
16962
- * 保留此方法以保持向后兼容
16963
- */
16964
- async createAndBuySign(params, options = {}) {
16965
- return this.createAndBuy(params, options);
16966
- }
16967
-
16968
16926
  }
16969
16927
 
16970
16928
  var token = TokenModule$1;
@@ -45265,7 +45223,7 @@ async function simulateLongStopLoss$1(mint, buyTokenAmount, stopLossPrice, lastP
45265
45223
 
45266
45224
  // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
45267
45225
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
45268
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
45226
+ const curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
45269
45227
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
45270
45228
  // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
45271
45229
  // 与 calcLiq.js 中的转换方式一致
@@ -45585,7 +45543,7 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
45585
45543
 
45586
45544
  // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
45587
45545
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
45588
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
45546
+ const curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
45589
45547
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
45590
45548
  // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
45591
45549
  // 与 calcLiq.js 中的转换方式一致
@@ -45833,19 +45791,19 @@ async function simulateShortStopLoss$1(mint, sellTokenAmount, stopLossPrice, las
45833
45791
  * @since 2.0.0
45834
45792
  * @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
45835
45793
  */
45836
- async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
45794
+ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
45837
45795
  try {
45838
45796
  // Parameter validation
45839
45797
  if (!mint || !buySolAmount || !stopLossPrice) {
45840
45798
  throw new Error('Missing required parameters');
45841
45799
  }
45842
45800
 
45843
- // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
45801
+ // 如果没有传入 borrowFee 或池子参数,从链上一次性获取(支持外部传入 curveAccount 避免重复 RPC)
45844
45802
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
45845
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
45803
+ if (!curveAccount) {
45804
+ curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
45805
+ }
45846
45806
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
45847
- // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
45848
- // 与 calcLiq.js 中的转换方式一致
45849
45807
  if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
45850
45808
  if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
45851
45809
  }
@@ -46017,19 +45975,19 @@ async function simulateLongSolStopLoss$1(mint, buySolAmount, stopLossPrice, last
46017
45975
  * @since 2.0.0
46018
45976
  * @version 2.0.0 - 从返回 prev_order_pda/next_order_pda 改为返回 close_insert_indices
46019
45977
  */
46020
- async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null) {
45978
+ async function simulateShortSolStopLoss$1(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
46021
45979
  try {
46022
45980
  // Parameter validation
46023
45981
  if (!mint || !sellSolAmount || !stopLossPrice) {
46024
45982
  throw new Error('Missing required parameters');
46025
45983
  }
46026
45984
 
46027
- // 如果没有传入 borrowFee 或池子参数,从链上一次性获取
45985
+ // 如果没有传入 borrowFee 或池子参数,从链上一次性获取(支持外部传入 curveAccount 避免重复 RPC)
46028
45986
  if (borrowFee === null || initialVirtualSol === null || initialVirtualToken === null) {
46029
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
45987
+ if (!curveAccount) {
45988
+ curveAccount = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
45989
+ }
46030
45990
  if (borrowFee === null) borrowFee = curveAccount.borrowFee;
46031
- // 链上返回的是 u64 原始单位(lamports/最小单位),需要除以 10^9 转为人类可读单位
46032
- // 与 calcLiq.js 中的转换方式一致
46033
45991
  if (initialVirtualSol === null) initialVirtualSol = new Decimal$1(curveAccount.initialVirtualSol.toString()).div(CurveAMM$6.SOL_PRECISION_FACTOR_DECIMAL).toString();
46034
45992
  if (initialVirtualToken === null) initialVirtualToken = new Decimal$1(curveAccount.initialVirtualToken.toString()).div(CurveAMM$6.TOKEN_PRECISION_FACTOR_DECIMAL).toString();
46035
45993
  }
@@ -46958,7 +46916,7 @@ const { calcLiqTokenBuy, calcLiqTokenSell } = calcLiq;
46958
46916
  * - suggestedTokenAmount: {string} Recommended token amount to buy based on available liquidity
46959
46917
  * - suggestedSolAmount: {string} Required SOL amount for suggested token purchase
46960
46918
  */
46961
- async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
46919
+ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
46962
46920
  // 获取价格和订单数据
46963
46921
 
46964
46922
  //console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
@@ -46981,12 +46939,13 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
46981
46939
  orders = ordersData.data.orders.slice(0, this.sdk.MAX_ORDERS_COUNT + 1);
46982
46940
  }
46983
46941
 
46984
- // 获取动态流动池参数
46985
- let curveData;
46986
- try {
46987
- curveData = await this.sdk.chain.getCurveAccount(mint);
46988
- } catch (error) {
46989
- throw new Error(`Failed to get curve account data: ${error.message}`);
46942
+ // 获取动态流动池参数(支持外部传入,避免重复请求)
46943
+ if (!curveData) {
46944
+ try {
46945
+ curveData = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
46946
+ } catch (error) {
46947
+ throw new Error(`Failed to get curve account data: ${error.message}`);
46948
+ }
46990
46949
  }
46991
46950
 
46992
46951
  // 调用 calcLiqTokenBuy 进行流动性计算(传入动态流动池参数)
@@ -47114,7 +47073,7 @@ async function simulateTokenBuy$1(mint, buyTokenAmount, passOrder = null, lastPr
47114
47073
  * - suggestedTokenAmount: {string} Recommended token amount to sell based on available liquidity
47115
47074
  * - suggestedSolAmount: {string} Expected SOL amount from suggested token sale
47116
47075
  */
47117
- async function simulateTokenSell$1(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
47076
+ async function simulateTokenSell$1(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
47118
47077
  // 获取价格和订单数据
47119
47078
  let price = lastPrice;
47120
47079
  if (!price) {
@@ -47136,12 +47095,13 @@ async function simulateTokenSell$1(mint, sellTokenAmount, passOrder = null, last
47136
47095
  orders = ordersData.data.orders.slice(0, this.sdk.MAX_ORDERS_COUNT + 1);
47137
47096
  }
47138
47097
 
47139
- // 获取动态流动池参数
47140
- let curveData;
47141
- try {
47142
- curveData = await this.sdk.chain.getCurveAccount(mint);
47143
- } catch (error) {
47144
- throw new Error(`Failed to get curve account data: ${error.message}`);
47098
+ // 获取动态流动池参数(支持外部传入,避免重复请求)
47099
+ if (!curveData) {
47100
+ try {
47101
+ curveData = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
47102
+ } catch (error) {
47103
+ throw new Error(`Failed to get curve account data: ${error.message}`);
47104
+ }
47145
47105
  }
47146
47106
 
47147
47107
  // console.log('simulateTokenSell 获取的数据:');
@@ -47785,8 +47745,8 @@ class SimulatorModule$1 {
47785
47745
  * - suggestedTokenAmount: {string} Recommended token amount to buy based on available liquidity
47786
47746
  * - suggestedSolAmount: {string} Required SOL amount for suggested token purchase
47787
47747
  */
47788
- async simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
47789
- return simulateTokenBuy.call(this, mint, buyTokenAmount, passOrder, lastPrice, ordersData);
47748
+ async simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
47749
+ return simulateTokenBuy.call(this, mint, buyTokenAmount, passOrder, lastPrice, ordersData, curveData);
47790
47750
  }
47791
47751
 
47792
47752
  /**
@@ -47812,8 +47772,8 @@ class SimulatorModule$1 {
47812
47772
  * - suggestedTokenAmount: {string} Recommended token amount to sell based on available liquidity
47813
47773
  * - suggestedSolAmount: {string} Expected SOL amount from suggested token sale
47814
47774
  */
47815
- async simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null) {
47816
- return simulateTokenSell.call(this, mint, sellTokenAmount, passOrder, lastPrice, ordersData);
47775
+ async simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
47776
+ return simulateTokenSell.call(this, mint, sellTokenAmount, passOrder, lastPrice, ordersData, curveData);
47817
47777
  }
47818
47778
 
47819
47779
  /**
@@ -47852,8 +47812,8 @@ class SimulatorModule$1 {
47852
47812
  * @param {number} borrowFee - Borrow fee rate, default 2000 (2000/100000 = 0.02%)
47853
47813
  * @returns {Promise<Object>} Stop loss analysis result (same as simulateLongStopLoss)
47854
47814
  */
47855
- async simulateLongSolStopLoss(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
47856
- return simulateLongSolStopLoss.call(this, mint, buySolAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
47815
+ async simulateLongSolStopLoss(mint, buySolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
47816
+ return simulateLongSolStopLoss.call(this, mint, buySolAmount, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken, curveAccount);
47857
47817
  }
47858
47818
 
47859
47819
  /**
@@ -47866,8 +47826,8 @@ class SimulatorModule$1 {
47866
47826
  * @param {number} borrowFee - Borrow fee rate, default 2000 (2000/100000 = 0.02%)
47867
47827
  * @returns {Promise<Object>} Stop loss analysis result (same as simulateShortStopLoss)
47868
47828
  */
47869
- async simulateShortSolStopLoss(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null) {
47870
- return simulateShortSolStopLoss.call(this, mint, sellSolAmount, stopLossPrice, lastPrice, ordersData, borrowFee);
47829
+ async simulateShortSolStopLoss(mint, sellSolAmount, stopLossPrice, lastPrice = null, ordersData = null, borrowFee = null, initialVirtualSol = null, initialVirtualToken = null, curveAccount = null) {
47830
+ return simulateShortSolStopLoss.call(this, mint, sellSolAmount, stopLossPrice, lastPrice, ordersData, borrowFee, initialVirtualSol, initialVirtualToken, curveAccount);
47871
47831
  }
47872
47832
 
47873
47833
  /**
@@ -47946,15 +47906,13 @@ class SimulatorModule$1 {
47946
47906
  };
47947
47907
  }
47948
47908
 
47949
- // Get current price and orders data
47950
- const priceResult = await this.sdk.data.price(mint);
47951
- const ordersResult = await this.sdk.data.orders(mint, { type: 'down_orders' });
47952
-
47953
- console.log("ordersResult:",ordersResult);
47954
-
47955
- const upOrdersResult = await this.sdk.data.orders(mint, { type: 'up_orders' });
47956
- console.log("upOrdersResult:",upOrdersResult);
47957
- console.log("upOrdersResult:",upOrdersResult.data.orders);
47909
+ // Get current price, orders data, and curve account in parallel
47910
+ const [priceResult, ordersResult, upOrdersResult, curveAccount] = await Promise.all([
47911
+ this.sdk.data.price(mint),
47912
+ this.sdk.data.orders(mint, { type: 'down_orders' }),
47913
+ this.sdk.data.orders(mint, { type: 'up_orders' }),
47914
+ this.sdk.chain.getCurveAccount(mint, { skipBalances: true })
47915
+ ]);
47958
47916
 
47959
47917
  if (!priceResult || !ordersResult) {
47960
47918
  return {
@@ -47970,7 +47928,6 @@ class SimulatorModule$1 {
47970
47928
  const currentPrice = typeof priceResult === 'string' ? BigInt(priceResult) : BigInt(priceResult.last_price || priceResult);
47971
47929
 
47972
47930
  // Get curve account data for initialVirtualSol and initialVirtualToken
47973
- const curveAccount = await this.sdk.chain.getCurveAccount(mint);
47974
47931
  const initialVirtualSol = curveAccount.initialVirtualSol;
47975
47932
  const initialVirtualToken = curveAccount.initialVirtualToken;
47976
47933
 
@@ -47980,8 +47937,8 @@ class SimulatorModule$1 {
47980
47937
 
47981
47938
  const estimatedTokenAmount = reSolBuy.tokenAmount;
47982
47939
 
47983
- // Call simulateTokenBuy with estimated amount
47984
- const tokenBuyResult = await this.simulateTokenBuy(mint, estimatedTokenAmount, null, priceResult, ordersResult);
47940
+ // Call simulateTokenBuy with estimated amount, pass curveAccount to avoid duplicate RPC
47941
+ const tokenBuyResult = await this.simulateTokenBuy(mint, estimatedTokenAmount, null, priceResult, ordersResult, curveAccount);
47985
47942
 
47986
47943
  // Transform result to match simulateBuy format
47987
47944
  return {
@@ -48067,10 +48024,12 @@ class SimulatorModule$1 {
48067
48024
  };
48068
48025
  }
48069
48026
 
48070
- // Get current price and orders data
48027
+ // Get current price and orders data in parallel
48071
48028
  // For sell transactions, we need down_orders (long orders that provide buy liquidity)
48072
- const priceResult = await this.sdk.data.price(mint);
48073
- const ordersResult = await this.sdk.data.orders(mint, { type: 'down_orders' });
48029
+ const [priceResult, ordersResult] = await Promise.all([
48030
+ this.sdk.data.price(mint),
48031
+ this.sdk.data.orders(mint, { type: 'down_orders' })
48032
+ ]);
48074
48033
 
48075
48034
  if (!priceResult || !ordersResult) {
48076
48035
  return {
@@ -48143,6 +48102,21 @@ const { Buffer: Buffer$3 } = require$$3__default["default"];
48143
48102
  class ChainModule$1 {
48144
48103
  constructor(sdk) {
48145
48104
  this.sdk = sdk;
48105
+ // getCurveAccount 缓存:key = mint string, value = { data, timestamp }
48106
+ this._curveAccountCache = new Map();
48107
+ this._CACHE_TTL = 10000; // 10 秒 TTL
48108
+ }
48109
+
48110
+ /**
48111
+ * 清除指定 mint 的 curveAccount 缓存(交易后调用)
48112
+ * @param {string} [mint] - 指定 mint 地址,不传则清除全部
48113
+ */
48114
+ invalidateCurveCache(mint) {
48115
+ if (mint) {
48116
+ this._curveAccountCache.delete(typeof mint === 'string' ? mint : mint.toString());
48117
+ } else {
48118
+ this._curveAccountCache.clear();
48119
+ }
48146
48120
  }
48147
48121
 
48148
48122
  /**
@@ -48271,10 +48245,23 @@ class ChainModule$1 {
48271
48245
  * @version 2.0.0 - Updated to use new OrderBook structure (up_orderbook/down_orderbook instead of upHead/downHead)
48272
48246
  * @author SpinPet SDK Team
48273
48247
  */
48274
- async getCurveAccount(mint) {
48248
+ async getCurveAccount(mint, options = {}) {
48249
+ const { skipBalances = false } = options;
48275
48250
  try {
48276
48251
  // Parameter validation and conversion
48277
48252
  const mintPubkey = typeof mint === 'string' ? new PublicKey$3(mint) : mint;
48253
+ const mintKey = mintPubkey.toString();
48254
+
48255
+ // 检查缓存
48256
+ const cached = this._curveAccountCache.get(mintKey);
48257
+ if (cached && (Date.now() - cached.timestamp < this._CACHE_TTL)) {
48258
+ // 缓存命中:如果请求包含余额但缓存没有,需要重新获取余额部分
48259
+ if (!skipBalances && cached.skipBalances) {
48260
+ // 缓存是 skipBalances 的,但现在需要余额,需要补充查询
48261
+ } else {
48262
+ return cached.data;
48263
+ }
48264
+ }
48278
48265
 
48279
48266
  // Calculate curve_account PDA address
48280
48267
  // Use the same seeds as in the contract: [b"borrowing_curve", mint_account.key().as_ref()]
@@ -48332,18 +48319,25 @@ class ChainModule$1 {
48332
48319
  this.sdk.programId
48333
48320
  );
48334
48321
 
48335
- // Query all balances concurrently
48336
- const [
48337
- baseFeeRecipientBalance,
48338
- feeRecipientBalance,
48339
- poolTokenBalance,
48340
- poolSolBalance
48341
- ] = await Promise.all([
48342
- this.sdk.connection.getBalance(decodedData.baseFeeRecipient),
48343
- this.sdk.connection.getBalance(decodedData.feeRecipient),
48344
- this.sdk.connection.getTokenAccountBalance(poolTokenAccountPDA).catch(() => ({ value: { amount: '0' } })),
48345
- this.sdk.connection.getBalance(poolSolAccountPDA)
48346
- ]);
48322
+ // Query balances (skip if not needed)
48323
+ let baseFeeRecipientBalance = 0;
48324
+ let feeRecipientBalance = 0;
48325
+ let poolTokenBalance = { value: { amount: '0' } };
48326
+ let poolSolBalance = 0;
48327
+
48328
+ if (!skipBalances) {
48329
+ [
48330
+ baseFeeRecipientBalance,
48331
+ feeRecipientBalance,
48332
+ poolTokenBalance,
48333
+ poolSolBalance
48334
+ ] = await Promise.all([
48335
+ this.sdk.connection.getBalance(decodedData.baseFeeRecipient),
48336
+ this.sdk.connection.getBalance(decodedData.feeRecipient),
48337
+ this.sdk.connection.getTokenAccountBalance(poolTokenAccountPDA).catch(() => ({ value: { amount: '0' } })),
48338
+ this.sdk.connection.getBalance(poolSolAccountPDA)
48339
+ ]);
48340
+ }
48347
48341
 
48348
48342
  // Convert data format
48349
48343
  const convertedData = {
@@ -48399,6 +48393,13 @@ class ChainModule$1 {
48399
48393
  }
48400
48394
  };
48401
48395
 
48396
+ // 写入缓存
48397
+ this._curveAccountCache.set(mintKey, {
48398
+ data: convertedData,
48399
+ timestamp: Date.now(),
48400
+ skipBalances: skipBalances
48401
+ });
48402
+
48402
48403
  // Return converted data
48403
48404
  return convertedData;
48404
48405
 
@@ -48455,58 +48456,13 @@ class ChainModule$1 {
48455
48456
  }
48456
48457
 
48457
48458
  try {
48458
- // Parameter validation and conversion
48459
- let mintPubkey;
48460
- try {
48461
- mintPubkey = typeof mint === 'string' ? new PublicKey$3(mint) : mint;
48462
- } catch (pubkeyError) {
48463
- throw new Error(`Invalid mint address: ${mint}`);
48464
- }
48465
-
48466
- // Validate mintPubkey
48467
- if (!mintPubkey || typeof mintPubkey.toBuffer !== 'function') {
48468
- throw new Error(`Invalid mintPubkey`);
48469
- }
48470
-
48471
- // Calculate curve_account PDA address
48472
- const [curveAccountPDA] = PublicKey$3.findProgramAddressSync(
48473
- [
48474
- Buffer$3.from("borrowing_curve"),
48475
- mintPubkey.toBuffer()
48476
- ],
48477
- this.sdk.programId
48478
- );
48479
-
48480
- // Use Anchor program to fetch account data directly
48481
- let decodedData;
48482
- try {
48483
- decodedData = await this.sdk.program.account.borrowingBondingCurve.fetch(curveAccountPDA);
48484
- } catch (fetchError) {
48485
- // If fetch fails, use raw method
48486
- const accountInfo = await this.sdk.connection.getAccountInfo(curveAccountPDA);
48487
- if (!accountInfo) {
48488
- throw new Error(`curve_account does not exist`);
48489
- }
48459
+ // 复用 getCurveAccount 缓存,避免重复 fetch 同一个账户
48460
+ const curveData = await this.getCurveAccount(mint, { skipBalances: true });
48461
+ const price = curveData.price;
48490
48462
 
48491
- // Manually decode with BorshAccountsCoder
48492
- const accountsCoder = new anchor$2.BorshAccountsCoder(this.sdk.program.idl);
48493
-
48494
- try {
48495
- decodedData = accountsCoder.decode('BorrowingBondingCurve', accountInfo.data);
48496
- } catch (decodeError1) {
48497
- try {
48498
- decodedData = accountsCoder.decode('borrowingBondingCurve', accountInfo.data);
48499
- } catch (decodeError2) {
48500
- throw new Error(`Cannot decode account data: ${decodeError1.message}`);
48501
- }
48502
- }
48503
- }
48504
-
48505
- // Check price data and return
48506
- if (decodedData.price && decodedData.price.toString() !== '0') {
48507
- return decodedData.price.toString();
48463
+ if (price && price !== 0n) {
48464
+ return price.toString();
48508
48465
  } else {
48509
- // If no price data, return initial price
48510
48466
  const initialPrice = CurveAMM$2.getInitialPrice();
48511
48467
  if (initialPrice === null) {
48512
48468
  throw new Error('price: Unable to calculate initial price');
@@ -48602,14 +48558,16 @@ class ChainModule$1 {
48602
48558
  // Convert API type to orderbook direction
48603
48559
  // "up_orders" = short orders = upOrderbook (orderType=2)
48604
48560
  // "down_orders" = long orders = downOrderbook (orderType=1)
48605
- const orderbookField = orderType === 'up_orders' ? 'upOrderbook' : 'downOrderbook';
48561
+ const seed = orderType === 'up_orders' ? 'up_orderbook' : 'down_orderbook';
48606
48562
 
48607
- // Get curve_account data to get orderbook address
48608
- const curveData = await this.getCurveAccount(mint);
48609
- const orderbookAddress = curveData[orderbookField];
48563
+ // 本地计算 orderbook PDA,避免调用 getCurveAccount(省 5 RPC)
48564
+ const mintPubkey = new PublicKey$3(mint);
48565
+ const [orderbookPubkey] = PublicKey$3.findProgramAddressSync(
48566
+ [Buffer$3.from(seed), mintPubkey.toBuffer()],
48567
+ this.sdk.programId
48568
+ );
48610
48569
 
48611
48570
  // Get OrderBook account data
48612
- const orderbookPubkey = new PublicKey$3(orderbookAddress);
48613
48571
  const accountInfo = await this.sdk.connection.getAccountInfo(orderbookPubkey);
48614
48572
 
48615
48573
  if (!accountInfo) {
@@ -49060,15 +49018,15 @@ class ChainModule$1 {
49060
49018
  throw new Error('debug_orders: order type must be "up_orders" or "down_orders"');
49061
49019
  }
49062
49020
 
49063
- // Convert API type to orderbook direction
49064
- const orderbookField = orderType === 'up_orders' ? 'upOrderbook' : 'downOrderbook';
49065
-
49066
- // Get curve_account data to get orderbook address
49067
- const curveData = await this.getCurveAccount(mint);
49068
- const orderbookAddress = curveData[orderbookField];
49021
+ // 本地计算 orderbook PDA,避免调用 getCurveAccount(省 5 个 RPC)
49022
+ const seed = orderType === 'up_orders' ? 'up_orderbook' : 'down_orderbook';
49023
+ const mintPubkey = new PublicKey$3(mint);
49024
+ const [orderbookPubkey] = PublicKey$3.findProgramAddressSync(
49025
+ [Buffer$3.from(seed), mintPubkey.toBuffer()],
49026
+ this.sdk.programId
49027
+ );
49069
49028
 
49070
49029
  // Get OrderBook account data
49071
- const orderbookPubkey = new PublicKey$3(orderbookAddress);
49072
49030
  const accountInfo = await this.sdk.connection.getAccountInfo(orderbookPubkey);
49073
49031
 
49074
49032
  if (!accountInfo) {
@@ -49271,10 +49229,18 @@ class ChainModule$1 {
49271
49229
  const page = 1; // Always return page 1
49272
49230
  const orderBy = options.order_by || 'start_time_desc';
49273
49231
 
49274
- // Get curve_account data to get both OrderBook addresses
49275
- const curveData = await this.getCurveAccount(mint);
49276
- const upOrderbookAddress = curveData.upOrderbook; // Short orders (orderType=2)
49277
- const downOrderbookAddress = curveData.downOrderbook; // Long orders (orderType=1)
49232
+ // 本地计算 orderbook PDA,避免调用 getCurveAccount(省 5 RPC)
49233
+ const mintPubkey = new PublicKey$3(mint);
49234
+ const [upOrderbookPubkey] = PublicKey$3.findProgramAddressSync(
49235
+ [Buffer$3.from('up_orderbook'), mintPubkey.toBuffer()],
49236
+ this.sdk.programId
49237
+ );
49238
+ const [downOrderbookPubkey] = PublicKey$3.findProgramAddressSync(
49239
+ [Buffer$3.from('down_orderbook'), mintPubkey.toBuffer()],
49240
+ this.sdk.programId
49241
+ );
49242
+ const upOrderbookAddress = upOrderbookPubkey.toString(); // Short orders (orderType=2)
49243
+ const downOrderbookAddress = downOrderbookPubkey.toString(); // Long orders (orderType=1)
49278
49244
 
49279
49245
  // Collect all user orders from both OrderBooks
49280
49246
  const allUserOrders = [];
@@ -49802,7 +49768,7 @@ class OrderUtils$2 {
49802
49768
 
49803
49769
  var orderUtils = OrderUtils$2;
49804
49770
 
49805
- var address = "CYdRzRacZ5kTc9Ht3U7mFhbsyxG3sZGEzC4cNf2Gjg2W";
49771
+ var address = "F2FzigE1Z374iDvreiM6hZQe6oGXgomJfv8PyybvUXye";
49806
49772
  var metadata = {
49807
49773
  name: "pinpet",
49808
49774
  version: "0.1.0",
@@ -52376,476 +52342,471 @@ var errors = [
52376
52342
  },
52377
52343
  {
52378
52344
  code: 6021,
52379
- name: "CloseShortImpossibleState",
52380
- msg: "Close short impossible state: current_total should always be greater than remaining_close_reduced_sol_with_fee"
52381
- },
52382
- {
52383
- code: 6022,
52384
52345
  name: "FeeSplitCalculationOverflow",
52385
52346
  msg: "Fee split calculation overflow"
52386
52347
  },
52387
52348
  {
52388
- code: 6023,
52349
+ code: 6022,
52389
52350
  name: "FeeAccumulationOverflow",
52390
52351
  msg: "Fee accumulation overflow"
52391
52352
  },
52392
52353
  {
52393
- code: 6024,
52354
+ code: 6023,
52394
52355
  name: "PartnerFeeAdditionOverflow",
52395
52356
  msg: "Partner fee addition overflow"
52396
52357
  },
52397
52358
  {
52398
- code: 6025,
52359
+ code: 6024,
52399
52360
  name: "BaseFeeAdditionOverflow",
52400
52361
  msg: "Base fee addition overflow"
52401
52362
  },
52402
52363
  {
52403
- code: 6026,
52364
+ code: 6025,
52404
52365
  name: "PoolFeeDeductionOverflow",
52405
52366
  msg: "Pool fee deduction overflow"
52406
52367
  },
52407
52368
  {
52408
- code: 6027,
52369
+ code: 6026,
52409
52370
  name: "FeeRandomDiscountOverflow",
52410
52371
  msg: "Fee random discount calculation overflow"
52411
52372
  },
52412
52373
  {
52413
- code: 6028,
52374
+ code: 6027,
52414
52375
  name: "SolReserveAdditionOverflow",
52415
52376
  msg: "SOL reserve addition overflow"
52416
52377
  },
52417
52378
  {
52418
- code: 6029,
52379
+ code: 6028,
52419
52380
  name: "SolReserveDeductionOverflow",
52420
52381
  msg: "SOL reserve deduction overflow"
52421
52382
  },
52422
52383
  {
52423
- code: 6030,
52384
+ code: 6029,
52424
52385
  name: "TokenReserveAdditionOverflow",
52425
52386
  msg: "Token reserve addition overflow"
52426
52387
  },
52427
52388
  {
52428
- code: 6031,
52389
+ code: 6030,
52429
52390
  name: "LamportsAdditionOverflow",
52430
52391
  msg: "Lamports addition overflow"
52431
52392
  },
52432
52393
  {
52433
- code: 6032,
52394
+ code: 6031,
52434
52395
  name: "LamportsDeductionOverflow",
52435
52396
  msg: "Lamports deduction overflow"
52436
52397
  },
52437
52398
  {
52438
- code: 6033,
52399
+ code: 6032,
52439
52400
  name: "DeadlineCalculationOverflow",
52440
52401
  msg: "Deadline calculation overflow"
52441
52402
  },
52442
52403
  {
52443
- code: 6034,
52404
+ code: 6033,
52444
52405
  name: "FeeDiscountFlagOverflow",
52445
52406
  msg: "Fee discount flag calculation overflow"
52446
52407
  },
52447
52408
  {
52448
- code: 6035,
52409
+ code: 6034,
52449
52410
  name: "Unauthorized",
52450
52411
  msg: "Unauthorized operation"
52451
52412
  },
52452
52413
  {
52453
- code: 6036,
52414
+ code: 6035,
52454
52415
  name: "RequiredParameter",
52455
52416
  msg: "All parameters are required during initialization"
52456
52417
  },
52457
52418
  {
52458
- code: 6037,
52419
+ code: 6036,
52459
52420
  name: "CurveCalculationError",
52460
52421
  msg: "Curve calculation error"
52461
52422
  },
52462
52423
  {
52463
- code: 6038,
52424
+ code: 6037,
52464
52425
  name: "InitialPriceCalculationError",
52465
52426
  msg: "Initial price calculation failed"
52466
52427
  },
52467
52428
  {
52468
- code: 6039,
52429
+ code: 6038,
52469
52430
  name: "BuyReserveRecalculationError",
52470
52431
  msg: "Reserve recalculation failed (after buy)"
52471
52432
  },
52472
52433
  {
52473
- code: 6040,
52434
+ code: 6039,
52474
52435
  name: "SellReserveRecalculationError",
52475
52436
  msg: "Reserve recalculation failed (after sell)"
52476
52437
  },
52477
52438
  {
52478
- code: 6041,
52439
+ code: 6040,
52479
52440
  name: "TotalAmountWithFeeError",
52480
52441
  msg: "Total amount with fee calculation failed"
52481
52442
  },
52482
52443
  {
52483
- code: 6042,
52444
+ code: 6041,
52484
52445
  name: "AmountAfterFeeError",
52485
52446
  msg: "Amount after fee calculation failed"
52486
52447
  },
52487
52448
  {
52488
- code: 6043,
52449
+ code: 6042,
52489
52450
  name: "BuyPriceRangeCalculationError",
52490
52451
  msg: "Buy price range calculation failed"
52491
52452
  },
52492
52453
  {
52493
- code: 6044,
52454
+ code: 6043,
52494
52455
  name: "SellPriceRangeCalculationError",
52495
52456
  msg: "Sell price range calculation failed"
52496
52457
  },
52497
52458
  {
52498
- code: 6045,
52459
+ code: 6044,
52499
52460
  name: "PriceAtStopLossBoundary",
52500
52461
  msg: "Price has reached stop-loss boundary, head order must be liquidated first"
52501
52462
  },
52502
52463
  {
52503
- code: 6046,
52464
+ code: 6045,
52504
52465
  name: "RemainingRangeCalculationError",
52505
52466
  msg: "Remaining range calculation failed"
52506
52467
  },
52507
52468
  {
52508
- code: 6047,
52469
+ code: 6046,
52509
52470
  name: "FullRangeCalculationError",
52510
52471
  msg: "Full range calculation failed"
52511
52472
  },
52512
52473
  {
52513
- code: 6048,
52474
+ code: 6047,
52514
52475
  name: "BuyFromPriceWithTokenNoneError",
52515
52476
  msg: "Curve function returned None: buy_from_price_with_token_output"
52516
52477
  },
52517
52478
  {
52518
- code: 6049,
52479
+ code: 6048,
52519
52480
  name: "SellFromPriceWithTokenNoneError",
52520
52481
  msg: "Curve function returned None: sell_from_price_with_token_input"
52521
52482
  },
52522
52483
  {
52523
- code: 6050,
52484
+ code: 6049,
52524
52485
  name: "ExceedsMaxSolAmount",
52525
52486
  msg: "Required SOL amount exceeds user-set maximum"
52526
52487
  },
52527
52488
  {
52528
- code: 6051,
52489
+ code: 6050,
52529
52490
  name: "InsufficientSolOutput",
52530
52491
  msg: "Insufficient SOL output"
52531
52492
  },
52532
52493
  {
52533
- code: 6052,
52494
+ code: 6051,
52534
52495
  name: "InsufficientRepayment",
52535
52496
  msg: "Insufficient proceeds to repay loan"
52536
52497
  },
52537
52498
  {
52538
- code: 6053,
52499
+ code: 6052,
52539
52500
  name: "InsufficientBorrowingReserve",
52540
52501
  msg: "Insufficient borrowing reserve"
52541
52502
  },
52542
52503
  {
52543
- code: 6054,
52504
+ code: 6053,
52544
52505
  name: "InsufficientTokenSale",
52545
52506
  msg: "Insufficient token sale amount"
52546
52507
  },
52547
52508
  {
52548
- code: 6055,
52509
+ code: 6054,
52549
52510
  name: "InsufficientLiquidity",
52550
52511
  msg: "Insufficient liquidity in current order"
52551
52512
  },
52552
52513
  {
52553
- code: 6056,
52514
+ code: 6055,
52554
52515
  name: "InsufficientMarketLiquidity",
52555
52516
  msg: "Insufficient market liquidity, cannot satisfy trade even after liquidating all stop-loss orders"
52556
52517
  },
52557
52518
  {
52558
- code: 6057,
52519
+ code: 6056,
52559
52520
  name: "TokenAmountDifferenceOutOfRange",
52560
52521
  msg: "Token amount difference exceeds valid range in margin trade"
52561
52522
  },
52562
52523
  {
52563
- code: 6058,
52524
+ code: 6057,
52564
52525
  name: "BorrowAmountMismatch",
52565
52526
  msg: "Borrow amount mismatch with locked tokens"
52566
52527
  },
52567
52528
  {
52568
- code: 6059,
52529
+ code: 6058,
52569
52530
  name: "CloseFeeCalculationError",
52570
52531
  msg: "Close fee calculation error"
52571
52532
  },
52572
52533
  {
52573
- code: 6060,
52534
+ code: 6059,
52574
52535
  name: "InsufficientMargin",
52575
52536
  msg: "Insufficient margin"
52576
52537
  },
52577
52538
  {
52578
- code: 6061,
52539
+ code: 6060,
52579
52540
  name: "InsufficientMinimumMargin",
52580
52541
  msg: "Margin below minimum requirement"
52581
52542
  },
52582
52543
  {
52583
- code: 6062,
52544
+ code: 6061,
52584
52545
  name: "InvalidAccountOwner",
52585
52546
  msg: "Invalid account owner"
52586
52547
  },
52587
52548
  {
52588
- code: 6063,
52549
+ code: 6062,
52589
52550
  name: "SellAmountExceedsOrderAmount",
52590
52551
  msg: "Sell amount exceeds order's token holdings"
52591
52552
  },
52592
52553
  {
52593
- code: 6064,
52554
+ code: 6063,
52594
52555
  name: "OrderNotExpiredMustCloseByOwner",
52595
52556
  msg: "Non-expired order must be closed by owner"
52596
52557
  },
52597
52558
  {
52598
- code: 6065,
52559
+ code: 6064,
52599
52560
  name: "SettlementAddressMustBeOwnerAddress",
52600
52561
  msg: "Settlement address must be owner address"
52601
52562
  },
52602
52563
  {
52603
- code: 6066,
52564
+ code: 6065,
52604
52565
  name: "BuyAmountExceedsOrderAmount",
52605
52566
  msg: "Buy amount exceeds order's token holdings"
52606
52567
  },
52607
52568
  {
52608
- code: 6067,
52569
+ code: 6066,
52609
52570
  name: "InsufficientTradeAmount",
52610
52571
  msg: "Trade amount below minimum requirement"
52611
52572
  },
52612
52573
  {
52613
- code: 6068,
52574
+ code: 6067,
52614
52575
  name: "SolAmountTooLarge",
52615
52576
  msg: "SOL amount exceeds maximum limit (10000000 SOL per transaction)"
52616
52577
  },
52617
52578
  {
52618
- code: 6069,
52579
+ code: 6068,
52619
52580
  name: "RemainingTokenAmountTooSmall",
52620
52581
  msg: "Remaining token amount below minimum trade requirement"
52621
52582
  },
52622
52583
  {
52623
- code: 6070,
52584
+ code: 6069,
52624
52585
  name: "TradeCooldownNotExpired",
52625
52586
  msg: "Trade cooldown period not expired, please try again later"
52626
52587
  },
52627
52588
  {
52628
- code: 6071,
52589
+ code: 6070,
52629
52590
  name: "ExceedApprovalAmount",
52630
52591
  msg: "Sell amount exceeds approved amount, please call approval function first"
52631
52592
  },
52632
52593
  {
52633
- code: 6072,
52594
+ code: 6071,
52634
52595
  name: "CooldownNotInitialized",
52635
52596
  msg: "Sell trade requires calling approval or buy function first to initialize cooldown PDA"
52636
52597
  },
52637
52598
  {
52638
- code: 6073,
52599
+ code: 6072,
52639
52600
  name: "CannotCloseCooldownWithBalance",
52640
52601
  msg: "Cannot close cooldown PDA with non-zero token balance"
52641
52602
  },
52642
52603
  {
52643
- code: 6074,
52604
+ code: 6073,
52644
52605
  name: "PriceCalculationError",
52645
52606
  msg: "Price calculation error"
52646
52607
  },
52647
52608
  {
52648
- code: 6075,
52609
+ code: 6074,
52649
52610
  name: "InvalidPartnerFeeRecipientAccount",
52650
52611
  msg: "Invalid partner fee recipient account"
52651
52612
  },
52652
52613
  {
52653
- code: 6076,
52614
+ code: 6075,
52654
52615
  name: "InvalidBaseFeeRecipientAccount",
52655
52616
  msg: "Invalid base fee recipient account"
52656
52617
  },
52657
52618
  {
52658
- code: 6077,
52619
+ code: 6076,
52659
52620
  name: "InvalidOrderbookAddress",
52660
52621
  msg: "Orderbook address does not match curve account orderbook"
52661
52622
  },
52662
52623
  {
52663
- code: 6078,
52624
+ code: 6077,
52664
52625
  name: "InvalidFeePercentage",
52665
52626
  msg: "Fee percentage must be between 0-100"
52666
52627
  },
52667
52628
  {
52668
- code: 6079,
52629
+ code: 6078,
52669
52630
  name: "InvalidFeeRate",
52670
52631
  msg: "Fee rate exceeds maximum limit (10%)"
52671
52632
  },
52672
52633
  {
52673
- code: 6080,
52634
+ code: 6079,
52674
52635
  name: "InvalidCustomFeeRate",
52675
52636
  msg: "Custom fee rate must be between 1000 (1%) and 5000 (5%)"
52676
52637
  },
52677
52638
  {
52678
- code: 6081,
52639
+ code: 6080,
52679
52640
  name: "InvalidBorrowDuration",
52680
52641
  msg: "Borrow duration out of valid range (3-30 days)"
52681
52642
  },
52682
52643
  {
52683
- code: 6082,
52644
+ code: 6081,
52684
52645
  name: "InvalidStopLossPrice",
52685
52646
  msg: "Stop loss price does not meet minimum interval requirement"
52686
52647
  },
52687
52648
  {
52688
- code: 6083,
52649
+ code: 6082,
52689
52650
  name: "NoProfitableFunds",
52690
52651
  msg: "No profitable funds to transfer"
52691
52652
  },
52692
52653
  {
52693
- code: 6084,
52654
+ code: 6083,
52694
52655
  name: "InsufficientPoolFunds",
52695
52656
  msg: "Insufficient pool funds"
52696
52657
  },
52697
52658
  {
52698
- code: 6085,
52659
+ code: 6084,
52699
52660
  name: "InsufficientPoolBalance",
52700
52661
  msg: "Pool SOL account balance would fall below minimum required balance"
52701
52662
  },
52702
52663
  {
52703
- code: 6086,
52664
+ code: 6085,
52704
52665
  name: "OrderBookManagerOverflow",
52705
52666
  msg: "Math operation overflow"
52706
52667
  },
52707
52668
  {
52708
- code: 6087,
52669
+ code: 6086,
52709
52670
  name: "OrderBookManagerInvalidSlotIndex",
52710
52671
  msg: "Invalid slot index"
52711
52672
  },
52712
52673
  {
52713
- code: 6088,
52674
+ code: 6087,
52714
52675
  name: "OrderBookManagerInvalidAccountData",
52715
52676
  msg: "Invalid account data"
52716
52677
  },
52717
52678
  {
52718
- code: 6089,
52679
+ code: 6088,
52719
52680
  name: "OrderBookManagerExceedsMaxCapacity",
52720
52681
  msg: "New capacity exceeds maximum limit"
52721
52682
  },
52722
52683
  {
52723
- code: 6090,
52684
+ code: 6089,
52724
52685
  name: "OrderBookManagerExceedsAccountSizeLimit",
52725
52686
  msg: "Account size exceeds 10MB limit"
52726
52687
  },
52727
52688
  {
52728
- code: 6091,
52689
+ code: 6090,
52729
52690
  name: "OrderBookManagerOrderIdMismatch",
52730
52691
  msg: "Order ID mismatch"
52731
52692
  },
52732
52693
  {
52733
- code: 6092,
52694
+ code: 6091,
52734
52695
  name: "OrderBookManagerEmptyOrderBook",
52735
52696
  msg: "Order book is empty"
52736
52697
  },
52737
52698
  {
52738
- code: 6093,
52699
+ code: 6092,
52739
52700
  name: "OrderBookManagerAccountNotWritable",
52740
52701
  msg: "Account is not writable"
52741
52702
  },
52742
52703
  {
52743
- code: 6094,
52704
+ code: 6093,
52744
52705
  name: "OrderBookManagerNotRentExempt",
52745
52706
  msg: "Account not rent-exempt"
52746
52707
  },
52747
52708
  {
52748
- code: 6095,
52709
+ code: 6094,
52749
52710
  name: "OrderBookManagerInvalidRentBalance",
52750
52711
  msg: "Invalid rent balance"
52751
52712
  },
52752
52713
  {
52753
- code: 6096,
52714
+ code: 6095,
52754
52715
  name: "OrderBookManagerInsufficientFunds",
52755
52716
  msg: "Insufficient funds"
52756
52717
  },
52757
52718
  {
52758
- code: 6097,
52719
+ code: 6096,
52759
52720
  name: "OrderBookManagerInvalidAccountOwner",
52760
52721
  msg: "OrderBook account owner mismatch"
52761
52722
  },
52762
52723
  {
52763
- code: 6098,
52724
+ code: 6097,
52764
52725
  name: "OrderBookManagerDataOutOfBounds",
52765
52726
  msg: "Data access out of bounds"
52766
52727
  },
52767
52728
  {
52768
- code: 6099,
52729
+ code: 6098,
52769
52730
  name: "NoValidInsertPosition",
52770
52731
  msg: "Cannot find valid insert position, all candidates failed due to price range overlap"
52771
52732
  },
52772
52733
  {
52773
- code: 6100,
52734
+ code: 6099,
52774
52735
  name: "EmptyCloseInsertIndices",
52775
52736
  msg: "close_insert_indices array cannot be empty"
52776
52737
  },
52777
52738
  {
52778
- code: 6101,
52739
+ code: 6100,
52779
52740
  name: "TooManyCloseInsertIndices",
52780
52741
  msg: "close_insert_indices array cannot exceed 20 elements"
52781
52742
  },
52782
52743
  {
52783
- code: 6102,
52744
+ code: 6101,
52784
52745
  name: "CloseOrderNotFound",
52785
52746
  msg: "Specified close order not found"
52786
52747
  },
52787
52748
  {
52788
- code: 6103,
52749
+ code: 6102,
52789
52750
  name: "LinkedListDeleteCountMismatch",
52790
52751
  msg: "Linked list delete count mismatch: count inconsistent before/after deletion"
52791
52752
  },
52792
52753
  {
52793
- code: 6104,
52754
+ code: 6103,
52794
52755
  name: "NameTooLong",
52795
52756
  msg: "Token name too long, max 32 bytes"
52796
52757
  },
52797
52758
  {
52798
- code: 6105,
52759
+ code: 6104,
52799
52760
  name: "NameEmpty",
52800
52761
  msg: "Token name cannot be empty"
52801
52762
  },
52802
52763
  {
52803
- code: 6106,
52764
+ code: 6105,
52804
52765
  name: "SymbolTooLong",
52805
52766
  msg: "Token symbol too long, max 10 bytes"
52806
52767
  },
52807
52768
  {
52808
- code: 6107,
52769
+ code: 6106,
52809
52770
  name: "SymbolEmpty",
52810
52771
  msg: "Token symbol cannot be empty"
52811
52772
  },
52812
52773
  {
52813
- code: 6108,
52774
+ code: 6107,
52814
52775
  name: "UriTooLong",
52815
52776
  msg: "URI too long, max 200 bytes"
52816
52777
  },
52817
52778
  {
52818
- code: 6109,
52779
+ code: 6108,
52819
52780
  name: "UriEmpty",
52820
52781
  msg: "URI cannot be empty"
52821
52782
  },
52822
52783
  {
52823
- code: 6110,
52784
+ code: 6109,
52824
52785
  name: "IncompleteAdvancedPoolParams",
52825
52786
  msg: "Incomplete advanced pool parameters: custom_lp_sol, custom_lp_token, custom_borrow_ratio, custom_borrow_duration must be provided together"
52826
52787
  },
52827
52788
  {
52828
- code: 6111,
52789
+ code: 6110,
52829
52790
  name: "InvalidInitialVirtualSol",
52830
52791
  msg: "Initial virtual SOL out of valid range"
52831
52792
  },
52832
52793
  {
52833
- code: 6112,
52794
+ code: 6111,
52834
52795
  name: "InvalidInitialVirtualToken",
52835
52796
  msg: "Initial virtual Token out of valid range"
52836
52797
  },
52837
52798
  {
52838
- code: 6113,
52799
+ code: 6112,
52839
52800
  name: "InvalidBorrowPoolRatio",
52840
52801
  msg: "Borrow pool ratio out of valid range"
52841
52802
  },
52842
52803
  {
52843
- code: 6114,
52804
+ code: 6113,
52844
52805
  name: "BorrowTokenCalculationOverflow",
52845
52806
  msg: "Borrow pool token amount calculation overflow"
52846
52807
  },
52847
52808
  {
52848
- code: 6115,
52809
+ code: 6114,
52849
52810
  name: "BorrowTokenAmountZero",
52850
52811
  msg: "Borrow pool token amount cannot be zero"
52851
52812
  }