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,6 +1,6 @@
1
1
  const { PublicKey, Transaction, SystemProgram } = require('@solana/web3.js');
2
2
  const anchor = require('@coral-xyz/anchor');
3
- // 统一使用 buffer 包,所有平台一致
3
+ // Use the buffer package consistently across all platforms
4
4
  const { Buffer } = require('buffer');
5
5
 
6
6
  /**
@@ -73,7 +73,7 @@ class ParamModule {
73
73
  * @returns {Promise<Object>} Parameters account data
74
74
  */
75
75
  async getParams(partner) {
76
- // 计算合作伙伴参数账户地址
76
+ // Calculate partner parameters account address
77
77
  const [paramsAccount] = PublicKey.findProgramAddressSync(
78
78
  [Buffer.from("params"), partner.toBuffer()],
79
79
  this.sdk.programId
@@ -117,13 +117,13 @@ class ParamModule {
117
117
  );
118
118
 
119
119
  try {
120
- // 检查账户是否存在
120
+ // Check if account exists
121
121
  const accountInfo = await this.sdk.connection.getAccountInfo(adminAccount);
122
122
  if (!accountInfo) {
123
123
  throw new Error('Admin account does not exist');
124
124
  }
125
-
126
- // 尝试使用 Anchor 解析数据
125
+
126
+ // Try to parse data using Anchor
127
127
  if (this.sdk.program.account.admin) {
128
128
  const adminData = await this.sdk.program.account.admin.fetch(adminAccount);
129
129
  return {
@@ -131,7 +131,7 @@ class ParamModule {
131
131
  data: adminData
132
132
  };
133
133
  } else {
134
- // 如果 Anchor 不可用,返回基本信息
134
+ // If Anchor is not available, return basic info
135
135
  return {
136
136
  address: adminAccount,
137
137
  accountInfo: accountInfo
@@ -4,10 +4,9 @@ const { calcLiqTokenBuy, calcLiqTokenSell } = require('./calcLiq');
4
4
 
5
5
  /**
6
6
  * Simulate token buy transaction - calculate if target token amount can be purchased
7
- * 模拟以 Token 数量为目标的买入交易 - 计算是否能买到指定数量的 Token
8
- * @param {string} mint - Token address 代币地址
9
- * @param {bigint|string|number} buyTokenAmount - Target token amount to buy 目标购买的 Token 数量
10
- * @param {string} passOrder - Optional order address to skip (won't be liquidated) 可选的跳过订单地址
7
+ * @param {string} mint - Token address
8
+ * @param {bigint|string|number} buyTokenAmount - Target token amount to buy
9
+ * @param {string} passOrder - Optional order address to skip (won't be liquidated)
11
10
  * @param {Object|null} lastPrice - Token price info, default null
12
11
  * @param {Object|null} ordersData - Orders response object, default null
13
12
  * @returns {Promise<Object>} Token buy simulation result with the following structure:
@@ -27,7 +26,7 @@ const { calcLiqTokenBuy, calcLiqTokenSell } = require('./calcLiq');
27
26
  * - suggestedSolAmount: {string} Required SOL amount for suggested token purchase
28
27
  */
29
28
  async function simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
30
- // 获取价格和订单数据
29
+ // Get price and orders data
31
30
 
32
31
  //console.log('simulateTokenBuy', mint, buyTokenAmount, passOrder, lastPrice, ordersData);
33
32
 
@@ -42,14 +41,14 @@ async function simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPric
42
41
  type: 'up_orders',
43
42
  limit: this.sdk.MAX_ORDERS_COUNT + 1
44
43
  });
45
- // 提取实际的订单数组
44
+ // Extract the actual orders array
46
45
  orders = ordersResponse.data.orders;
47
46
  } else {
48
- // 如果传入了 ordersData,从响应对象中提取订单数组并限制长度
47
+ // If ordersData is provided, extract the orders array from the response object and limit its length
49
48
  orders = ordersData.data.orders.slice(0, this.sdk.MAX_ORDERS_COUNT + 1);
50
49
  }
51
50
 
52
- // 获取动态流动池参数(支持外部传入,避免重复请求)
51
+ // Get dynamic liquidity pool parameters (supports external input to avoid duplicate requests)
53
52
  if (!curveData) {
54
53
  try {
55
54
  curveData = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
@@ -58,7 +57,7 @@ async function simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPric
58
57
  }
59
58
  }
60
59
 
61
- // 调用 calcLiqTokenBuy 进行流动性计算(传入动态流动池参数)
60
+ // Call calcLiqTokenBuy to perform liquidity calculation (passing dynamic liquidity pool parameters)
62
61
  try {
63
62
  const liqResult = calcLiqTokenBuy(
64
63
  price,
@@ -73,16 +72,16 @@ async function simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPric
73
72
  // console.log("liqResult:",liqResult);
74
73
 
75
74
 
76
- // console.log('\n=== calcLiqTokenBuy 返回结果 ===');
77
- // console.log('自由流动性 SOL 总量:', liqResult.free_lp_sol_amount_sum.toString());
78
- // console.log('自由流动性 Token 总量:', liqResult.free_lp_token_amount_sum.toString());
79
- // console.log('锁定流动性 SOL 总量:', liqResult.lock_lp_sol_amount_sum.toString());
80
- // console.log('锁定流动性 Token 总量:', liqResult.lock_lp_token_amount_sum.toString());
81
- // console.log('是否包含无限流动性:', liqResult.has_infinite_lp);
82
- // console.log('跳过的订单索引:', liqResult.pass_order_id);
83
- // console.log('需要强平的订单数量:', liqResult.force_close_num);
84
- // console.log('理想 SOL 使用量:', liqResult.ideal_lp_sol_amount.toString());
85
- // console.log('实际 SOL 使用量:', liqResult.real_lp_sol_amount.toString());
75
+ // console.log('\n=== calcLiqTokenBuy return result ===');
76
+ // console.log('Free liquidity SOL total:', liqResult.free_lp_sol_amount_sum.toString());
77
+ // console.log('Free liquidity Token total:', liqResult.free_lp_token_amount_sum.toString());
78
+ // console.log('Locked liquidity SOL total:', liqResult.lock_lp_sol_amount_sum.toString());
79
+ // console.log('Locked liquidity Token total:', liqResult.lock_lp_token_amount_sum.toString());
80
+ // console.log('Whether includes infinite liquidity:', liqResult.has_infinite_lp);
81
+ // console.log('Skipped order index:', liqResult.pass_order_id);
82
+ // console.log('Number of orders needing force close:', liqResult.force_close_num);
83
+ // console.log('Ideal SOL usage:', liqResult.ideal_lp_sol_amount.toString());
84
+ // console.log('Actual SOL usage:', liqResult.real_lp_sol_amount.toString());
86
85
  // console.log('===============================\n');
87
86
 
88
87
  // Convert to BigInt for calculations
@@ -164,7 +163,7 @@ async function simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPric
164
163
  * Simulate token sell transaction analysis
165
164
  * @param {string} mint - Token address
166
165
  * @param {bigint|string|number} sellTokenAmount - Token amount to sell (u64 format, precision 10^9)
167
- * @param {string} passOrder - Optional order address to skip (won't be liquidated) 可选的跳过订单地址
166
+ * @param {string} passOrder - Optional order address to skip (won't be liquidated)
168
167
  * @param {Object|null} lastPrice - Token price info, default null
169
168
  * @param {Object|null} ordersData - Orders response object, default null
170
169
  * @returns {Promise<Object>} Token sell simulation result with the following structure:
@@ -184,7 +183,7 @@ async function simulateTokenBuy(mint, buyTokenAmount, passOrder = null, lastPric
184
183
  * - suggestedSolAmount: {string} Expected SOL amount from suggested token sale
185
184
  */
186
185
  async function simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPrice = null, ordersData = null, curveData = null) {
187
- // 获取价格和订单数据
186
+ // Get price and orders data
188
187
  let price = lastPrice;
189
188
  if (!price) {
190
189
  price = await this.sdk.data.price(mint);
@@ -198,14 +197,14 @@ async function simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPr
198
197
  type: 'down_orders',
199
198
  limit: this.sdk.MAX_ORDERS_COUNT + 1
200
199
  });
201
- // 提取实际的订单数组
200
+ // Extract the actual orders array
202
201
  orders = ordersResponse.data.orders;
203
202
  } else {
204
- // 如果传入了 ordersData,从响应对象中提取订单数组并限制长度
203
+ // If ordersData is provided, extract the orders array from the response object and limit its length
205
204
  orders = ordersData.data.orders.slice(0, this.sdk.MAX_ORDERS_COUNT + 1);
206
205
  }
207
206
 
208
- // 获取动态流动池参数(支持外部传入,避免重复请求)
207
+ // Get dynamic liquidity pool parameters (supports external input to avoid duplicate requests)
209
208
  if (!curveData) {
210
209
  try {
211
210
  curveData = await this.sdk.chain.getCurveAccount(mint, { skipBalances: true });
@@ -214,12 +213,12 @@ async function simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPr
214
213
  }
215
214
  }
216
215
 
217
- // console.log('simulateTokenSell 获取的数据:');
218
- // console.log('价格:', price);
219
- // console.log('订单数量:', orders.length);
220
- // orders.forEach((order, i) => console.log(`订单${i}: start=${order.lock_lp_start_price}, end=${order.lock_lp_end_price}, sol=${order.lock_lp_sol_amount}, token=${order.lock_lp_token_amount}`));
216
+ // console.log('Data obtained by simulateTokenSell:');
217
+ // console.log('Price:', price);
218
+ // console.log('Number of orders:', orders.length);
219
+ // orders.forEach((order, i) => console.log(`Order ${i}: start=${order.lock_lp_start_price}, end=${order.lock_lp_end_price}, sol=${order.lock_lp_sol_amount}, token=${order.lock_lp_token_amount}`));
221
220
 
222
- // 调用 calcLiqTokenSell 进行流动性计算(传入动态流动池参数)
221
+ // Call calcLiqTokenSell to perform liquidity calculation (passing dynamic liquidity pool parameters)
223
222
  try {
224
223
  const liqResult = calcLiqTokenSell(
225
224
  price,
@@ -231,16 +230,16 @@ async function simulateTokenSell(mint, sellTokenAmount, passOrder = null, lastPr
231
230
  curveData.initialVirtualToken
232
231
  );
233
232
 
234
- // console.log('\n=== calcLiqTokenSell 返回结果 ===');
235
- // console.log('自由流动性 SOL 总量:', liqResult.free_lp_sol_amount_sum.toString());
236
- // console.log('自由流动性 Token 总量:', liqResult.free_lp_token_amount_sum.toString());
237
- // console.log('锁定流动性 SOL 总量:', liqResult.lock_lp_sol_amount_sum.toString());
238
- // console.log('锁定流动性 Token 总量:', liqResult.lock_lp_token_amount_sum.toString());
239
- // console.log('是否包含无限流动性:', liqResult.has_infinite_lp);
240
- // console.log('跳过的订单索引:', liqResult.pass_order_id);
241
- // console.log('需要强平的订单数量:', liqResult.force_close_num);
242
- // console.log('理想 SOL 获得量:', liqResult.ideal_lp_sol_amount.toString());
243
- // console.log('实际 SOL 获得量:', liqResult.real_lp_sol_amount.toString());
233
+ // console.log('\n=== calcLiqTokenSell return result ===');
234
+ // console.log('Free liquidity SOL total:', liqResult.free_lp_sol_amount_sum.toString());
235
+ // console.log('Free liquidity Token total:', liqResult.free_lp_token_amount_sum.toString());
236
+ // console.log('Locked liquidity SOL total:', liqResult.lock_lp_sol_amount_sum.toString());
237
+ // console.log('Locked liquidity Token total:', liqResult.lock_lp_token_amount_sum.toString());
238
+ // console.log('Whether includes infinite liquidity:', liqResult.has_infinite_lp);
239
+ // console.log('Skipped order index:', liqResult.pass_order_id);
240
+ // console.log('Number of orders needing force close:', liqResult.force_close_num);
241
+ // console.log('Ideal SOL obtained:', liqResult.ideal_lp_sol_amount.toString());
242
+ // console.log('Actual SOL obtained:', liqResult.real_lp_sol_amount.toString());
244
243
  // console.log('===============================\n');
245
244
 
246
245
  // Convert to BigInt for calculations