100x-sdk 1.0.2 → 1.0.4

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.
@@ -1,11 +1,11 @@
1
1
  const { ComputeBudgetProgram, PublicKey, Transaction, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js');
2
2
  const { createAssociatedTokenAccountInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } = require('@solana/spl-token');
3
3
  const anchor = require('@coral-xyz/anchor');
4
- // 统一使用 buffer 包,所有平台一致
4
+ // Use the buffer package uniformly, consistent across all platforms
5
5
  const { Buffer } = require('buffer');
6
6
  const { MAX_CANDIDATE_INDICES } = require('./simulator/utils');
7
7
 
8
- // 环境检测和条件加载
8
+ // Environment detection and conditional loading
9
9
  const IS_NODE = typeof process !== 'undefined' && process.versions && process.versions.node;
10
10
 
11
11
  /**
@@ -293,11 +293,11 @@ class TradingModule {
293
293
  * Margin Long
294
294
  * @param {Object} params - Long parameters
295
295
  * @param {string|PublicKey} params.mintAccount - Token mint account address
296
- * @param {anchor.BN} params.buyTokenAmount - Amount of tokens to buy (确定值)
297
- * @param {anchor.BN} params.maxSolAmount - Maximum SOL to spend (实际有可能会少点)
298
- * @param {anchor.BN} params.marginSol - Margin amount (保证金数量 SOL)
299
- * @param {anchor.BN} params.closePrice - Close price (平仓价格/止损价格)
300
- * @param {Array<number>} params.closeInsertIndices - Close insert indices array (平仓时插入订单簿的位置索引数组)
296
+ * @param {anchor.BN} params.buyTokenAmount - Amount of tokens to buy (fixed value)
297
+ * @param {anchor.BN} params.maxSolAmount - Maximum SOL to spend (the actual amount may be slightly less)
298
+ * @param {anchor.BN} params.marginSol - Margin amount (margin in SOL)
299
+ * @param {anchor.BN} params.closePrice - Close price (close price / stop loss price)
300
+ * @param {Array<number>} params.closeInsertIndices - Close insert indices array (position indices for inserting into the orderbook at close)
301
301
  * @param {PublicKey} params.payer - Payer public key
302
302
  * @param {Object} options - Optional parameters
303
303
  * @param {number} options.computeUnits - Compute units limit, default 1400000
@@ -310,14 +310,14 @@ class TradingModule {
310
310
  * maxSolAmount: new anchor.BN("1100000000"),
311
311
  * marginSol: new anchor.BN("2200000000"),
312
312
  * closePrice: new anchor.BN("1000000000000000"),
313
- * closeInsertIndices: [0, 1, 2], // 插入位置索引数组
313
+ * closeInsertIndices: [0, 1, 2], // insert position index array
314
314
  * payer: wallet.publicKey
315
315
  * });
316
316
  */
317
317
  async long({ mintAccount, buyTokenAmount, maxSolAmount, marginSol, closePrice, closeInsertIndices, payer }, options = {}) {
318
318
  const { computeUnits = 1400000 } = options;
319
319
 
320
- // 1. 参数验证和转换
320
+ // 1. Parameter validation and conversion
321
321
  const mint = typeof mintAccount === 'string' ? new PublicKey(mintAccount) : mintAccount;
322
322
 
323
323
  if (!anchor.BN.isBN(buyTokenAmount) || !anchor.BN.isBN(maxSolAmount) ||
@@ -402,18 +402,18 @@ class TradingModule {
402
402
  }
403
403
 
404
404
  /**
405
- * 保证金做空 / Margin Short
406
- * @param {Object} params - 做空参数 / Short parameters
407
- * @param {string|PublicKey} params.mintAccount - 代币铸造账户地址 / Token mint account address
408
- * @param {anchor.BN} params.borrowSellTokenAmount - 借出卖出的代币数量 (希望卖出的token数量) / Borrowed token amount to sell
409
- * @param {anchor.BN} params.minSolOutput - 最小 SOL 输出 (卖出后最少得到的sol数量) / Minimum SOL output
410
- * @param {anchor.BN} params.marginSol - 保证金数量 (SOL) / Margin amount
411
- * @param {anchor.BN} params.closePrice - 平仓价格 (止损价格) / Close price
412
- * @param {Array<number>} params.closeInsertIndices - Close insert indices array (平仓时插入订单簿的位置索引数组)
413
- * @param {PublicKey} params.payer - 支付者公钥 / Payer public key
414
- * @param {Object} options - 可选参数 / Optional parameters
415
- * @param {number} options.computeUnits - 计算单元限制,默认 1400000 / Compute units limit, default 1400000
416
- * @returns {Promise<Object>} 包含交易对象、签名者和账户信息的对象 / Object containing transaction, signers and account info
405
+ * Margin Short
406
+ * @param {Object} params - Short parameters
407
+ * @param {string|PublicKey} params.mintAccount - Token mint account address
408
+ * @param {anchor.BN} params.borrowSellTokenAmount - Borrowed token amount to sell (the amount of tokens you wish to sell)
409
+ * @param {anchor.BN} params.minSolOutput - Minimum SOL output (the minimum SOL received after selling)
410
+ * @param {anchor.BN} params.marginSol - Margin amount (SOL)
411
+ * @param {anchor.BN} params.closePrice - Close price (stop loss price)
412
+ * @param {Array<number>} params.closeInsertIndices - Close insert indices array (position indices for inserting into the orderbook at close)
413
+ * @param {PublicKey} params.payer - Payer public key
414
+ * @param {Object} options - Optional parameters
415
+ * @param {number} options.computeUnits - Compute units limit, default 1400000
416
+ * @returns {Promise<Object>} Object containing transaction, signers and account info
417
417
  *
418
418
  * @example
419
419
  * const result = await sdk.trading.short({
@@ -422,14 +422,14 @@ class TradingModule {
422
422
  * minSolOutput: new anchor.BN("100"),
423
423
  * marginSol: new anchor.BN("2200000000"),
424
424
  * closePrice: new anchor.BN("1000000000000000"),
425
- * closeInsertIndices: [0, 1, 2], // 插入位置索引数组
425
+ * closeInsertIndices: [0, 1, 2], // insert position index array
426
426
  * payer: wallet.publicKey
427
427
  * });
428
428
  */
429
429
  async short({ mintAccount, borrowSellTokenAmount, minSolOutput, marginSol, closePrice, closeInsertIndices, payer }, options = {}) {
430
430
  const { computeUnits = 1400000 } = options;
431
431
 
432
- // 1. 参数验证和转换 / Parameter validation and conversion
432
+ // 1. Parameter validation and conversion
433
433
  const mint = typeof mintAccount === 'string' ? new PublicKey(mintAccount) : mintAccount;
434
434
 
435
435
  if (!anchor.BN.isBN(borrowSellTokenAmount) || !anchor.BN.isBN(minSolOutput) ||
@@ -445,7 +445,7 @@ class TradingModule {
445
445
  throw new Error('closeInsertIndices array cannot exceed 20 elements');
446
446
  }
447
447
 
448
- // 2. 计算 PDA 账户 / Calculate PDA accounts
448
+ // 2. Calculate PDA accounts
449
449
  const accounts = this._calculatePDAAccounts(mint);
450
450
 
451
451
  // 3. Calculate OrderBook PDA addresses
@@ -459,7 +459,7 @@ class TradingModule {
459
459
  this.sdk.programId
460
460
  );
461
461
 
462
- // 4. 构建交易指令 / Build transaction instructions
462
+ // 4. Build transaction instructions
463
463
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
464
464
  units: computeUnits
465
465
  });
@@ -489,15 +489,15 @@ class TradingModule {
489
489
  })
490
490
  .instruction();
491
491
 
492
- // 5. 创建交易并添加指令 / Create transaction and add instructions
492
+ // 5. Create transaction and add instructions
493
493
  const transaction = new Transaction();
494
494
  transaction.add(modifyComputeUnits);
495
495
  transaction.add(shortIx);
496
496
 
497
- // 6. 返回交易对象和相关信息 / Return transaction object and related info
497
+ // 6. Return transaction object and related info
498
498
  return {
499
499
  transaction,
500
- signers: [], // 做空交易不需要额外的签名者,只需要 payer 签名 / Short transaction doesn't need additional signers, only payer signature
500
+ signers: [], // Short transaction doesn't need additional signers, only payer signature
501
501
  accounts: {
502
502
  mint: mint,
503
503
  curveAccount: accounts.curveAccount,
@@ -514,26 +514,26 @@ class TradingModule {
514
514
  }
515
515
 
516
516
  /**
517
- * 平仓做多 / Close Long Position
518
- * @param {Object} params - 平仓参数 / Close position parameters
519
- * @param {string|PublicKey} params.mintAccount - 代币铸造账户地址 / Token mint account address
520
- * @param {anchor.BN} params.sellTokenAmount - 希望卖出的token数量 / Amount of tokens to sell
521
- * @param {anchor.BN} params.minSolOutput - 卖出后最少得到的sol数量 / Minimum SOL output after selling
522
- * @param {number|anchor.BN} params.closeOrderId - 订单的唯一编号 / Order unique ID
523
- * @param {Array<number>} params.closeOrderIndices - 平仓时订单的位置索引数组 / Close order position indices array
524
- * @param {PublicKey} params.payer - 支付者公钥 / Payer public key
525
- * @param {PublicKey} params.userSolAccount - 开仓用户的SOL账户(接收资金)/ User SOL account to receive funds (must be order opener)
526
- * @param {Object} options - 可选参数 / Optional parameters
527
- * @param {number} options.computeUnits - 计算单元限制,默认1400000 / Compute units limit, default 1400000
528
- * @returns {Promise<Object>} 包含交易对象、签名者和账户信息的对象 / Object containing transaction, signers and account info
517
+ * Close Long Position
518
+ * @param {Object} params - Close position parameters
519
+ * @param {string|PublicKey} params.mintAccount - Token mint account address
520
+ * @param {anchor.BN} params.sellTokenAmount - Amount of tokens to sell
521
+ * @param {anchor.BN} params.minSolOutput - Minimum SOL output after selling
522
+ * @param {number|anchor.BN} params.closeOrderId - Order unique ID
523
+ * @param {Array<number>} params.closeOrderIndices - Close order position indices array
524
+ * @param {PublicKey} params.payer - Payer public key
525
+ * @param {PublicKey} params.userSolAccount - User SOL account to receive funds (must be order opener)
526
+ * @param {Object} options - Optional parameters
527
+ * @param {number} options.computeUnits - Compute units limit, default 1400000
528
+ * @returns {Promise<Object>} Object containing transaction, signers and account info
529
529
  *
530
530
  * @example
531
531
  * const result = await sdk.trading.closeLong({
532
532
  * mintAccount: "HZBos3RNhExDcAtzmdKXhTd4sVcQFBiT3FDBgmBBMk7",
533
533
  * sellTokenAmount: new anchor.BN("1000000000"),
534
534
  * minSolOutput: new anchor.BN("100000000"),
535
- * closeOrderId: 12345, // 订单唯一编号
536
- * closeOrderIndices: [10, 11, 12], // 候选索引数组
535
+ * closeOrderId: 12345, // order unique ID
536
+ * closeOrderIndices: [10, 11, 12], // candidate index array
537
537
  * payer: wallet.publicKey,
538
538
  * userSolAccount: orderOwnerPublicKey
539
539
  * });
@@ -541,17 +541,17 @@ class TradingModule {
541
541
  async closeLong({ mintAccount, sellTokenAmount, minSolOutput, closeOrderId, closeOrderIndices, payer, userSolAccount }, options = {}) {
542
542
  const { computeUnits = 1400000 } = options;
543
543
 
544
- // 1. 参数验证和转换 / Parameter validation and conversion
544
+ // 1. Parameter validation and conversion
545
545
  const mint = typeof mintAccount === 'string' ? new PublicKey(mintAccount) : mintAccount;
546
546
 
547
547
  if (!anchor.BN.isBN(sellTokenAmount) || !anchor.BN.isBN(minSolOutput)) {
548
548
  throw new Error('sellTokenAmount and minSolOutput must be anchor.BN type');
549
549
  }
550
550
 
551
- // 转换 closeOrderId 为 anchor.BN (u64)
551
+ // Convert closeOrderId to anchor.BN (u64)
552
552
  const closeOrderIdBN = anchor.BN.isBN(closeOrderId) ? closeOrderId : new anchor.BN(closeOrderId);
553
553
 
554
- // 验证 closeOrderIndices 参数
554
+ // Validate the closeOrderIndices parameter
555
555
  if (!Array.isArray(closeOrderIndices) || closeOrderIndices.length === 0) {
556
556
  throw new Error('closeOrderIndices must be a non-empty array');
557
557
  }
@@ -560,7 +560,7 @@ class TradingModule {
560
560
  throw new Error(`closeOrderIndices array cannot exceed ${MAX_CANDIDATE_INDICES} elements`);
561
561
  }
562
562
 
563
- // 验证和转换 userSolAccount - 支持字符串或 PublicKey 对象
563
+ // Validate and convert userSolAccount - supports string or PublicKey object
564
564
  let userSolAccountPubkey;
565
565
  if (!userSolAccount) {
566
566
  throw new Error('userSolAccount is required');
@@ -575,7 +575,7 @@ class TradingModule {
575
575
  } else if (userSolAccount instanceof PublicKey) {
576
576
  userSolAccountPubkey = userSolAccount;
577
577
  } else if (userSolAccount.constructor && userSolAccount.constructor.name === 'PublicKey') {
578
- // 处理跨包 PublicKey 实例 - 提取字符串后重新创建
578
+ // Handle cross-package PublicKey instances - extract the string and recreate
579
579
  try {
580
580
  userSolAccountPubkey = new PublicKey(userSolAccount.toString());
581
581
  } catch (error) {
@@ -585,10 +585,10 @@ class TradingModule {
585
585
  throw new Error('userSolAccount must be a valid PublicKey or PublicKey string');
586
586
  }
587
587
 
588
- // 2. 计算 PDA 账户 / Calculate PDA accounts
588
+ // 2. Calculate PDA accounts
589
589
  const accounts = this._calculatePDAAccounts(mint);
590
590
 
591
- // 3. 计算 OrderBook PDA 地址 / Calculate OrderBook PDA addresses
591
+ // 3. Calculate OrderBook PDA addresses
592
592
  const [upOrderbook] = PublicKey.findProgramAddressSync(
593
593
  [Buffer.from('up_orderbook'), mint.toBuffer()],
594
594
  this.sdk.programId
@@ -599,22 +599,22 @@ class TradingModule {
599
599
  this.sdk.programId
600
600
  );
601
601
 
602
- // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account (skipBalances: only need addresses)
602
+ // 4. Get fee recipient accounts from curve account (skipBalances: only need addresses)
603
603
  const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
604
604
  const feeRecipientAccount = new PublicKey(curveAccountInfo.feeRecipient);
605
605
  const baseFeeRecipientAccount = new PublicKey(curveAccountInfo.baseFeeRecipient);
606
606
 
607
- // 5. 构建交易指令 / Build transaction instructions
607
+ // 5. Build transaction instructions
608
608
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
609
609
  units: computeUnits
610
610
  });
611
611
 
612
612
  const closeLongIx = await this.sdk.program.methods
613
613
  .closeLong(
614
- sellTokenAmount, // sell_token_amount: 希望卖出的token数量 / Amount of tokens to sell
615
- minSolOutput, // min_sol_output: 卖出后最少得到的sol数量 / Minimum SOL output
616
- closeOrderIdBN, // close_order_id: 订单的唯一编号 / Order unique ID
617
- closeOrderIndices // close_order_indices: 平仓时订单的位置索引数组 / Close order indices array
614
+ sellTokenAmount, // sell_token_amount: amount of tokens to sell
615
+ minSolOutput, // min_sol_output: minimum SOL output
616
+ closeOrderIdBN, // close_order_id: order unique ID
617
+ closeOrderIndices // close_order_indices: close order indices array
618
618
  )
619
619
  .accounts({
620
620
  payer: payer,
@@ -623,7 +623,7 @@ class TradingModule {
623
623
  poolTokenAccount: accounts.poolTokenAccount,
624
624
  poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
625
625
  poolSolAccount: accounts.poolSolAccount,
626
- userSolAccount: userSolAccountPubkey, // 开仓用户的SOL账户 / User SOL account (must be order opener)
626
+ userSolAccount: userSolAccountPubkey, // User SOL account (must be order opener)
627
627
  tokenProgram: TOKEN_PROGRAM_ID,
628
628
  systemProgram: SystemProgram.programId,
629
629
  rent: SYSVAR_RENT_PUBKEY,
@@ -634,15 +634,15 @@ class TradingModule {
634
634
  })
635
635
  .instruction();
636
636
 
637
- // 6. 创建交易并添加指令 / Create transaction and add instructions
637
+ // 6. Create transaction and add instructions
638
638
  const transaction = new Transaction();
639
639
  transaction.add(modifyComputeUnits);
640
640
  transaction.add(closeLongIx);
641
641
 
642
- // 7. 返回交易对象和相关信息 / Return transaction object and related info
642
+ // 7. Return transaction object and related info
643
643
  return {
644
644
  transaction,
645
- signers: [], // 平仓做多交易不需要额外的签名者,只需要 payer 签名 / Close long transaction doesn't need additional signers, only payer signature
645
+ signers: [], // Close long transaction doesn't need additional signers, only payer signature
646
646
  accounts: {
647
647
  mint: mint,
648
648
  curveAccount: accounts.curveAccount,
@@ -664,26 +664,26 @@ class TradingModule {
664
664
 
665
665
 
666
666
  /**
667
- * 平仓做空 / Close Short Position
668
- * @param {Object} params - 平仓参数 / Close position parameters
669
- * @param {string|PublicKey} params.mintAccount - 代币铸造账户地址 / Token mint account address
670
- * @param {anchor.BN} params.buyTokenAmount - 希望买入的token数量 / Amount of tokens to buy
671
- * @param {anchor.BN} params.maxSolAmount - 愿意给出的最大sol数量 / Maximum SOL amount to spend
672
- * @param {number|anchor.BN} params.closeOrderId - 订单的唯一编号 / Order unique ID
673
- * @param {Array<number>} params.closeOrderIndices - 平仓时订单的位置索引数组 / Close order position indices array
674
- * @param {PublicKey} params.payer - 支付者公钥 / Payer public key
675
- * @param {PublicKey} params.userSolAccount - 开仓用户的SOL账户(接收资金)/ User SOL account to receive funds (must be order opener)
676
- * @param {Object} options - 可选参数 / Optional parameters
677
- * @param {number} options.computeUnits - 计算单元限制,默认1400000 / Compute units limit, default 1400000
678
- * @returns {Promise<Object>} 包含交易对象、签名者和账户信息的对象 / Object containing transaction, signers and account info
667
+ * Close Short Position
668
+ * @param {Object} params - Close position parameters
669
+ * @param {string|PublicKey} params.mintAccount - Token mint account address
670
+ * @param {anchor.BN} params.buyTokenAmount - Amount of tokens to buy
671
+ * @param {anchor.BN} params.maxSolAmount - Maximum SOL amount to spend
672
+ * @param {number|anchor.BN} params.closeOrderId - Order unique ID
673
+ * @param {Array<number>} params.closeOrderIndices - Close order position indices array
674
+ * @param {PublicKey} params.payer - Payer public key
675
+ * @param {PublicKey} params.userSolAccount - User SOL account to receive funds (must be order opener)
676
+ * @param {Object} options - Optional parameters
677
+ * @param {number} options.computeUnits - Compute units limit, default 1400000
678
+ * @returns {Promise<Object>} Object containing transaction, signers and account info
679
679
  *
680
680
  * @example
681
681
  * const result = await sdk.trading.closeShort({
682
682
  * mintAccount: "HZBos3RNhExDcAtzmdKXhTd4sVcQFBiT3FDBgmBBMk7",
683
683
  * buyTokenAmount: new anchor.BN("1000000000"),
684
684
  * maxSolAmount: new anchor.BN("100000000"),
685
- * closeOrderId: 12345, // 订单唯一编号
686
- * closeOrderIndices: [10, 11, 12], // 候选索引数组
685
+ * closeOrderId: 12345, // order unique ID
686
+ * closeOrderIndices: [10, 11, 12], // candidate index array
687
687
  * payer: wallet.publicKey,
688
688
  * userSolAccount: orderOwnerPublicKey
689
689
  * });
@@ -691,17 +691,17 @@ class TradingModule {
691
691
  async closeShort({ mintAccount, buyTokenAmount, maxSolAmount, closeOrderId, closeOrderIndices, payer, userSolAccount }, options = {}) {
692
692
  const { computeUnits = 1400000 } = options;
693
693
 
694
- // 1. 参数验证和转换 / Parameter validation and conversion
694
+ // 1. Parameter validation and conversion
695
695
  const mint = typeof mintAccount === 'string' ? new PublicKey(mintAccount) : mintAccount;
696
696
 
697
697
  if (!anchor.BN.isBN(buyTokenAmount) || !anchor.BN.isBN(maxSolAmount)) {
698
698
  throw new Error('buyTokenAmount and maxSolAmount must be anchor.BN type');
699
699
  }
700
700
 
701
- // 转换 closeOrderId 为 anchor.BN (u64)
701
+ // Convert closeOrderId to anchor.BN (u64)
702
702
  const closeOrderIdBN = anchor.BN.isBN(closeOrderId) ? closeOrderId : new anchor.BN(closeOrderId);
703
703
 
704
- // 验证 closeOrderIndices 参数
704
+ // Validate the closeOrderIndices parameter
705
705
  if (!Array.isArray(closeOrderIndices) || closeOrderIndices.length === 0) {
706
706
  throw new Error('closeOrderIndices must be a non-empty array');
707
707
  }
@@ -710,7 +710,7 @@ class TradingModule {
710
710
  throw new Error(`closeOrderIndices array cannot exceed ${MAX_CANDIDATE_INDICES} elements`);
711
711
  }
712
712
 
713
- // 验证和转换 userSolAccount - 支持字符串或 PublicKey 对象
713
+ // Validate and convert userSolAccount - supports string or PublicKey object
714
714
  let userSolAccountPubkey;
715
715
  if (!userSolAccount) {
716
716
  throw new Error('userSolAccount is required');
@@ -725,7 +725,7 @@ class TradingModule {
725
725
  } else if (userSolAccount instanceof PublicKey) {
726
726
  userSolAccountPubkey = userSolAccount;
727
727
  } else if (userSolAccount.constructor && userSolAccount.constructor.name === 'PublicKey') {
728
- // 处理跨包 PublicKey 实例 - 提取字符串后重新创建
728
+ // Handle cross-package PublicKey instances - extract the string and recreate
729
729
  try {
730
730
  userSolAccountPubkey = new PublicKey(userSolAccount.toString());
731
731
  } catch (error) {
@@ -735,10 +735,10 @@ class TradingModule {
735
735
  throw new Error('userSolAccount must be a valid PublicKey or PublicKey string');
736
736
  }
737
737
 
738
- // 2. 计算 PDA 账户 / Calculate PDA accounts
738
+ // 2. Calculate PDA accounts
739
739
  const accounts = this._calculatePDAAccounts(mint);
740
740
 
741
- // 3. 计算 OrderBook PDA 地址 / Calculate OrderBook PDA addresses
741
+ // 3. Calculate OrderBook PDA addresses
742
742
  const [upOrderbook] = PublicKey.findProgramAddressSync(
743
743
  [Buffer.from('up_orderbook'), mint.toBuffer()],
744
744
  this.sdk.programId
@@ -749,22 +749,22 @@ class TradingModule {
749
749
  this.sdk.programId
750
750
  );
751
751
 
752
- // 4. 从 curve account 获取手续费接收账户 / Get fee recipient accounts from curve account (skipBalances: only need addresses)
752
+ // 4. Get fee recipient accounts from curve account (skipBalances: only need addresses)
753
753
  const curveAccountInfo = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
754
754
  const feeRecipientAccount = new PublicKey(curveAccountInfo.feeRecipient);
755
755
  const baseFeeRecipientAccount = new PublicKey(curveAccountInfo.baseFeeRecipient);
756
756
 
757
- // 5. 构建交易指令 / Build transaction instructions
757
+ // 5. Build transaction instructions
758
758
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
759
759
  units: computeUnits
760
760
  });
761
761
 
762
762
  const closeShortIx = await this.sdk.program.methods
763
763
  .closeShort(
764
- buyTokenAmount, // buy_token_amount: 希望买入的token数量 / Amount of tokens to buy
765
- maxSolAmount, // max_sol_amount: 愿意给出的最大sol数量 / Maximum SOL amount to spend
766
- closeOrderIdBN, // close_order_id: 订单的唯一编号 / Order unique ID
767
- closeOrderIndices // close_order_indices: 平仓时订单的位置索引数组 / Close order indices array
764
+ buyTokenAmount, // buy_token_amount: amount of tokens to buy
765
+ maxSolAmount, // max_sol_amount: maximum SOL amount to spend
766
+ closeOrderIdBN, // close_order_id: order unique ID
767
+ closeOrderIndices // close_order_indices: close order indices array
768
768
  )
769
769
  .accounts({
770
770
  payer: payer,
@@ -773,7 +773,7 @@ class TradingModule {
773
773
  poolTokenAccount: accounts.poolTokenAccount,
774
774
  poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
775
775
  poolSolAccount: accounts.poolSolAccount,
776
- userSolAccount: userSolAccountPubkey, // 开仓用户的SOL账户 / User SOL account (must be order opener)
776
+ userSolAccount: userSolAccountPubkey, // User SOL account (must be order opener)
777
777
  tokenProgram: TOKEN_PROGRAM_ID,
778
778
  systemProgram: SystemProgram.programId,
779
779
  rent: SYSVAR_RENT_PUBKEY,
@@ -784,15 +784,15 @@ class TradingModule {
784
784
  })
785
785
  .instruction();
786
786
 
787
- // 6. 创建交易并添加指令 / Create transaction and add instructions
787
+ // 6. Create transaction and add instructions
788
788
  const transaction = new Transaction();
789
789
  transaction.add(modifyComputeUnits);
790
790
  transaction.add(closeShortIx);
791
791
 
792
- // 7. 返回交易对象和相关信息 / Return transaction object and related info
792
+ // 7. Return transaction object and related info
793
793
  return {
794
794
  transaction,
795
- signers: [], // 平仓做空交易不需要额外的签名者,只需要 payer 签名 / Close short transaction doesn't need additional signers, only payer signature
795
+ signers: [], // Close short transaction doesn't need additional signers, only payer signature
796
796
  accounts: {
797
797
  mint: mint,
798
798
  curveAccount: accounts.curveAccount,
@@ -815,31 +815,31 @@ class TradingModule {
815
815
  // ========== PDA Calculation Methods ==========
816
816
 
817
817
  /**
818
- * 计算 PDA 账户
818
+ * Calculate PDA accounts
819
819
  * @private
820
- * @param {PublicKey} mintAccount - 代币铸造账户
821
- * @returns {Object} PDA 账户对象
820
+ * @param {PublicKey} mintAccount - Token mint account
821
+ * @returns {Object} PDA accounts object
822
822
  */
823
823
  _calculatePDAAccounts(mintAccount) {
824
- // 计算曲线账户 PDA
824
+ // Calculate the curve account PDA
825
825
  const [curveAccount] = PublicKey.findProgramAddressSync(
826
826
  [Buffer.from('borrowing_curve'), mintAccount.toBuffer()],
827
827
  this.sdk.programId
828
828
  );
829
829
 
830
- // 计算池子代币账户 PDA
830
+ // Calculate the pool token account PDA
831
831
  const [poolTokenAccount] = PublicKey.findProgramAddressSync(
832
832
  [Buffer.from('pool_token'), mintAccount.toBuffer()],
833
833
  this.sdk.programId
834
834
  );
835
835
 
836
- // 计算借贷池专用代币账户 PDA
836
+ // Calculate the borrow-pool-specific token account PDA
837
837
  const [poolBorrowTokenAccount] = PublicKey.findProgramAddressSync(
838
838
  [Buffer.from('pool_borrow_token'), mintAccount.toBuffer()],
839
839
  this.sdk.programId
840
840
  );
841
841
 
842
- // 计算池子 SOL 账户 PDA
842
+ // Calculate the pool SOL account PDA
843
843
  const [poolSolAccount] = PublicKey.findProgramAddressSync(
844
844
  [Buffer.from('pool_sol'), mintAccount.toBuffer()],
845
845
  this.sdk.programId
package/src/sdk.js CHANGED
@@ -1,12 +1,12 @@
1
1
  const anchor = require('@coral-xyz/anchor');
2
2
  const { PublicKey } = require('@solana/web3.js');
3
- // 统一使用 buffer 包,所有平台一致
3
+ // Use the buffer package consistently across all platforms
4
4
  const { Buffer } = require('buffer');
5
5
 
6
- // 环境检测和条件加载
6
+ // Environment detection and conditional loading
7
7
  const IS_NODE = typeof process !== 'undefined' && process.versions && process.versions.node;
8
8
 
9
- // 确保全局可用(兼容现有代码)
9
+ // Ensure global availability (compatible with existing code)
10
10
  if (typeof global !== 'undefined' && !global.Buffer) {
11
11
  global.Buffer = Buffer;
12
12
  }
@@ -73,7 +73,7 @@ class Fun100xSdk {
73
73
  // Maximum number of orders to fetch during queries
74
74
  this.FIND_MAX_ORDERS_COUNT = 1000
75
75
 
76
- // 在流动性不足时, 建议实际使用流动性的比例, 分每 (1000=100%)
76
+ // When liquidity is insufficient, the suggested ratio of liquidity to actually use, per-mille (1000=100%)
77
77
  this.SUGGEST_LIQ_RATIO = 975; // 97.5% (1000=100%)
78
78
 
79
79
  // Initialize Anchor program
@@ -92,20 +92,19 @@ class Fun100xSdk {
92
92
  this.curve = CurveAMM;
93
93
 
94
94
  /**
95
- * 统一数据接口 - 根据 defaultDataSource 配置自动路由到 fast 或 chain 模块
96
95
  * Unified data interface - automatically routes to fast or chain module based on defaultDataSource config
97
96
  *
98
97
  * @example
99
- * // 使用默认数据源获取订单
98
+ * // Fetch orders using the default data source
100
99
  * const ordersData = await sdk.data.orders(mint, { type: 'down_orders' });
101
100
  *
102
- * // 临时指定数据源
101
+ * // Temporarily specify a data source
103
102
  * const ordersData = await sdk.data.orders(mint, {
104
103
  * type: 'down_orders',
105
- * dataSource: 'chain' // 临时使用链上数据源
104
+ * dataSource: 'chain' // Temporarily use the on-chain data source
106
105
  * });
107
106
  *
108
- * // 获取用户订单
107
+ * // Fetch user orders
109
108
  * const userOrders = await sdk.data.user_orders(user, mint, {
110
109
  * page: 1,
111
110
  * limit: 200,
@@ -114,27 +113,27 @@ class Fun100xSdk {
114
113
  */
115
114
  this.data = {
116
115
  /**
117
- * 获取代币订单数据
118
- * @param {string} mint - 代币地址
119
- * @param {Object} options - 查询参数,支持 dataSource 字段临时指定数据源
120
- * @returns {Promise<Object>} 订单数据
116
+ * Get token orders data
117
+ * @param {string} mint - Token address
118
+ * @param {Object} options - Query parameters; supports the dataSource field to temporarily specify a data source
119
+ * @returns {Promise<Object>} Orders data
121
120
  */
122
121
  orders: (mint, options = {}) => this._getDataWithSource('orders', [mint, options]),
123
122
 
124
123
  /**
125
- * 获取代币价格数据
126
- * @param {string} mint - 代币地址
127
- * @param {Object} options - 查询参数,支持 dataSource 字段临时指定数据源
128
- * @returns {Promise<string>} 价格字符串
124
+ * Get token price data
125
+ * @param {string} mint - Token address
126
+ * @param {Object} options - Query parameters; supports the dataSource field to temporarily specify a data source
127
+ * @returns {Promise<string>} Price string
129
128
  */
130
129
  price: (mint, options = {}) => this._getDataWithSource('price', [mint, options]),
131
130
 
132
131
  /**
133
- * 获取用户订单数据
134
- * @param {string} user - 用户地址
135
- * @param {string} mint - 代币地址
136
- * @param {Object} options - 查询参数,支持 dataSource 字段临时指定数据源
137
- * @returns {Promise<Object>} 用户订单数据
132
+ * Get user orders data
133
+ * @param {string} user - User address
134
+ * @param {string} mint - Token address
135
+ * @param {Object} options - Query parameters; supports the dataSource field to temporarily specify a data source
136
+ * @returns {Promise<Object>} User orders data
138
137
  */
139
138
  user_orders: (user, mint, options = {}) => this._getDataWithSource('user_orders', [user, mint, options])
140
139
  };
@@ -199,7 +198,7 @@ class Fun100xSdk {
199
198
 
200
199
  }
201
200
 
202
- // 将工具类作为静态属性添加到 Fun100xSdk 类
201
+ // Add utility classes as static properties on the Fun100xSdk class
203
202
  Fun100xSdk.CurveAMM = CurveAMM;
204
203
  Fun100xSdk.OrderUtils = OrderUtils;
205
204