100x-sdk 1.0.1 → 1.0.3
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.
- package/dist/100x-sdk.cjs.js +595 -6
- package/dist/100x-sdk.esm.js +598 -9
- package/dist/100x-sdk.js +598 -9
- package/dist/100x-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/idl/fun100x_localnet.json +268 -0
- package/src/idl/fun100x_main.json +268 -0
- package/src/modules/chain.js +33 -6
- package/src/modules/token.js +13 -0
- package/src/modules/trading.js +13 -0
package/src/modules/chain.js
CHANGED
|
@@ -68,12 +68,20 @@ class ChainModule {
|
|
|
68
68
|
* @returns {string} returns.downOrderbook - Down orderbook (long orders) PDA address
|
|
69
69
|
* @returns {string} returns.creator - Token creator address, the wallet that created this token
|
|
70
70
|
* @returns {string} returns.poolTokenAccount - Pool token account address, stores tokens in the liquidity pool
|
|
71
|
+
* @returns {string} returns.poolBorrowTokenAccount - Pool borrow token account address (PDA seed "pool_borrow_token"), stores tokens for the borrow pool
|
|
71
72
|
* @returns {string} returns.poolSolAccount - Pool SOL account address, stores native SOL in the liquidity pool
|
|
72
73
|
*
|
|
74
|
+
* **Dynamic Liquidity Pool Parameters:**
|
|
75
|
+
* @returns {bigint} returns.initialVirtualSol - Initial virtual SOL reserve (lamports), used for k value / price curve
|
|
76
|
+
* @returns {bigint} returns.initialVirtualToken - Initial virtual Token reserve (smallest unit), used for k value / price curve
|
|
77
|
+
* @returns {bigint} returns.initialBorrowTokenReserve - Borrow pool initial funding (smallest unit), never changes after creation. Borrowed out = initialBorrowTokenReserve - borrowTokenReserve
|
|
78
|
+
* @returns {number} returns.poolType - Pool type (0: basic version, 1: advanced version)
|
|
79
|
+
* @returns {number} returns.borrowPoolRatio - Borrow pool token ratio (5-30 means 5%-30%, basic version fixed at 20)
|
|
80
|
+
*
|
|
73
81
|
* **Token Supply Information:**
|
|
74
82
|
* @returns {bigint} returns.totalSupply - Total token supply (smallest unit)
|
|
75
83
|
* @returns {number} returns.decimals - Token decimal places
|
|
76
|
-
* @returns {bigint} returns.initialBorrowPool - Initial borrow pool size =
|
|
84
|
+
* @returns {bigint} returns.initialBorrowPool - Initial borrow pool size (= initialBorrowTokenReserve from chain)
|
|
77
85
|
* @returns {bigint} returns.circulatingSupply - Circulating supply = totalSupply - borrowTokenReserve
|
|
78
86
|
*
|
|
79
87
|
* **Balance Information:**
|
|
@@ -229,6 +237,15 @@ class ChainModule {
|
|
|
229
237
|
this.sdk.programId
|
|
230
238
|
);
|
|
231
239
|
|
|
240
|
+
// 借贷池专用 token 账户 PDA(合约新增,seed = "pool_borrow_token")
|
|
241
|
+
const [poolBorrowTokenAccountPDA] = PublicKey.findProgramAddressSync(
|
|
242
|
+
[
|
|
243
|
+
Buffer.from("pool_borrow_token"),
|
|
244
|
+
mintPubkey.toBuffer()
|
|
245
|
+
],
|
|
246
|
+
this.sdk.programId
|
|
247
|
+
);
|
|
248
|
+
|
|
232
249
|
const [poolSolAccountPDA] = PublicKey.findProgramAddressSync(
|
|
233
250
|
[
|
|
234
251
|
Buffer.from("pool_sol"),
|
|
@@ -241,6 +258,7 @@ class ChainModule {
|
|
|
241
258
|
let baseFeeRecipientBalance = 0;
|
|
242
259
|
let feeRecipientBalance = 0;
|
|
243
260
|
let poolTokenBalance = { value: { amount: '0' } };
|
|
261
|
+
let poolBorrowTokenBalance = { value: { amount: '0' } };
|
|
244
262
|
let poolSolBalance = 0;
|
|
245
263
|
let tokenSupply = { value: { amount: '0', decimals: 0 } };
|
|
246
264
|
|
|
@@ -249,12 +267,14 @@ class ChainModule {
|
|
|
249
267
|
baseFeeRecipientBalance,
|
|
250
268
|
feeRecipientBalance,
|
|
251
269
|
poolTokenBalance,
|
|
270
|
+
poolBorrowTokenBalance,
|
|
252
271
|
poolSolBalance,
|
|
253
272
|
tokenSupply
|
|
254
273
|
] = await Promise.all([
|
|
255
274
|
this.sdk.connection.getBalance(decodedData.baseFeeRecipient),
|
|
256
275
|
this.sdk.connection.getBalance(decodedData.feeRecipient),
|
|
257
276
|
this.sdk.connection.getTokenAccountBalance(poolTokenAccountPDA).catch(() => ({ value: { amount: '0' } })),
|
|
277
|
+
this.sdk.connection.getTokenAccountBalance(poolBorrowTokenAccountPDA).catch(() => ({ value: { amount: '0' } })),
|
|
258
278
|
this.sdk.connection.getBalance(poolSolAccountPDA),
|
|
259
279
|
this.sdk.connection.getTokenSupply(mintPubkey)
|
|
260
280
|
]);
|
|
@@ -293,6 +313,10 @@ class ChainModule {
|
|
|
293
313
|
initialVirtualSol: BigInt(decodedData.initialVirtualSol.toString()), // u64, lamports
|
|
294
314
|
initialVirtualToken: BigInt(decodedData.initialVirtualToken.toString()), // u64, 最小单位
|
|
295
315
|
|
|
316
|
+
// 借贷池初始资金(合约新增),创建后永不变
|
|
317
|
+
// 已借出量 = initialBorrowTokenReserve - borrowTokenReserve
|
|
318
|
+
initialBorrowTokenReserve: BigInt(decodedData.initialBorrowTokenReserve.toString()), // u64, 最小单位
|
|
319
|
+
|
|
296
320
|
// === 第二阶段新增字段:高级版池子参数 ===
|
|
297
321
|
poolType: decodedData.poolType, // u8, 0=普通版, 1=高级版
|
|
298
322
|
borrowPoolRatio: decodedData.borrowPoolRatio, // u8, 5-30表示5%-30%
|
|
@@ -300,7 +324,8 @@ class ChainModule {
|
|
|
300
324
|
// Token Supply 信息
|
|
301
325
|
totalSupply: BigInt(tokenSupply.value.amount),
|
|
302
326
|
decimals: tokenSupply.value.decimals,
|
|
303
|
-
|
|
327
|
+
// 借贷池初始总量,直接取链上字段(旧公式 totalSupply - initialVirtualToken 已废弃)
|
|
328
|
+
initialBorrowPool: BigInt(decodedData.initialBorrowTokenReserve.toString()),
|
|
304
329
|
circulatingSupply: BigInt(decodedData.initialVirtualToken.toString())
|
|
305
330
|
+ (BigInt(tokenSupply.value.amount) - BigInt(decodedData.initialVirtualToken.toString()) - BigInt(decodedData.borrowTokenReserve.toString())),
|
|
306
331
|
|
|
@@ -309,10 +334,12 @@ class ChainModule {
|
|
|
309
334
|
feeRecipientBalance: feeRecipientBalance, // Unit: lamports
|
|
310
335
|
|
|
311
336
|
// Pool account information
|
|
312
|
-
poolTokenAccount: poolTokenAccountPDA.toString(),
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
337
|
+
poolTokenAccount: poolTokenAccountPDA.toString(), // Pool token account address
|
|
338
|
+
poolBorrowTokenAccount: poolBorrowTokenAccountPDA.toString(), // Pool borrow token account address (新增)
|
|
339
|
+
poolSolAccount: poolSolAccountPDA.toString(), // Pool SOL account address
|
|
340
|
+
poolTokenBalance: BigInt(poolTokenBalance.value.amount), // Pool token balance
|
|
341
|
+
poolBorrowTokenBalance: BigInt(poolBorrowTokenBalance.value.amount), // Pool borrow token balance (= borrowTokenReserve, 新增)
|
|
342
|
+
poolSolBalance: poolSolBalance, // Pool SOL balance (lamports)
|
|
316
343
|
|
|
317
344
|
// Additional metadata
|
|
318
345
|
_metadata: {
|
package/src/modules/token.js
CHANGED
|
@@ -127,6 +127,15 @@ class TokenModule {
|
|
|
127
127
|
this.sdk.programId
|
|
128
128
|
);
|
|
129
129
|
|
|
130
|
+
// Calculate borrow pool token account address (pool_borrow_token)
|
|
131
|
+
const [poolBorrowTokenAccount] = PublicKey.findProgramAddressSync(
|
|
132
|
+
[
|
|
133
|
+
Buffer.from("pool_borrow_token"),
|
|
134
|
+
mint.publicKey.toBuffer(),
|
|
135
|
+
],
|
|
136
|
+
this.sdk.programId
|
|
137
|
+
);
|
|
138
|
+
|
|
130
139
|
// Calculate liquidity pool SOL account address (pool_sol)
|
|
131
140
|
const [poolSolAccount] = PublicKey.findProgramAddressSync(
|
|
132
141
|
[
|
|
@@ -166,6 +175,7 @@ class TokenModule {
|
|
|
166
175
|
console.log('Calculated account addresses:');
|
|
167
176
|
console.log(' Borrowing liquidity pool account:', curveAccount.toString());
|
|
168
177
|
console.log(' Liquidity pool token account:', poolTokenAccount.toString());
|
|
178
|
+
console.log(' Borrow pool token account:', poolBorrowTokenAccount.toString());
|
|
169
179
|
console.log(' Liquidity pool SOL account:', poolSolAccount.toString());
|
|
170
180
|
console.log(' Up orderbook:', upOrderbook.toString());
|
|
171
181
|
console.log(' Down orderbook:', downOrderbook.toString());
|
|
@@ -199,6 +209,7 @@ class TokenModule {
|
|
|
199
209
|
mintAccount: mint.publicKey,
|
|
200
210
|
curveAccount: curveAccount,
|
|
201
211
|
poolTokenAccount: poolTokenAccount,
|
|
212
|
+
poolBorrowTokenAccount: poolBorrowTokenAccount,
|
|
202
213
|
poolSolAccount: poolSolAccount,
|
|
203
214
|
upOrderbook: upOrderbook,
|
|
204
215
|
downOrderbook: downOrderbook,
|
|
@@ -225,6 +236,7 @@ class TokenModule {
|
|
|
225
236
|
mint: mint.publicKey,
|
|
226
237
|
curveAccount,
|
|
227
238
|
poolTokenAccount,
|
|
239
|
+
poolBorrowTokenAccount,
|
|
228
240
|
poolSolAccount,
|
|
229
241
|
upOrderbook,
|
|
230
242
|
downOrderbook,
|
|
@@ -388,6 +400,7 @@ class TokenModule {
|
|
|
388
400
|
mintAccount: mintPubkey,
|
|
389
401
|
curveAccount: createResult.accounts.curveAccount,
|
|
390
402
|
poolTokenAccount: createResult.accounts.poolTokenAccount,
|
|
403
|
+
poolBorrowTokenAccount: createResult.accounts.poolBorrowTokenAccount,
|
|
391
404
|
poolSolAccount: createResult.accounts.poolSolAccount,
|
|
392
405
|
upOrderbook: upOrderbook,
|
|
393
406
|
downOrderbook: downOrderbook,
|
package/src/modules/trading.js
CHANGED
|
@@ -106,6 +106,7 @@ class TradingModule {
|
|
|
106
106
|
mintAccount: mint,
|
|
107
107
|
curveAccount: accounts.curveAccount,
|
|
108
108
|
poolTokenAccount: accounts.poolTokenAccount,
|
|
109
|
+
poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
|
|
109
110
|
poolSolAccount: accounts.poolSolAccount,
|
|
110
111
|
upOrderbook: upOrderbook,
|
|
111
112
|
downOrderbook: downOrderbook,
|
|
@@ -242,6 +243,7 @@ class TradingModule {
|
|
|
242
243
|
mintAccount: mint,
|
|
243
244
|
curveAccount: accounts.curveAccount,
|
|
244
245
|
poolTokenAccount: accounts.poolTokenAccount,
|
|
246
|
+
poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
|
|
245
247
|
poolSolAccount: accounts.poolSolAccount,
|
|
246
248
|
upOrderbook: upOrderbook,
|
|
247
249
|
downOrderbook: downOrderbook,
|
|
@@ -363,6 +365,7 @@ class TradingModule {
|
|
|
363
365
|
mintAccount: mint,
|
|
364
366
|
curveAccount: accounts.curveAccount,
|
|
365
367
|
poolTokenAccount: accounts.poolTokenAccount,
|
|
368
|
+
poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
|
|
366
369
|
poolSolAccount: accounts.poolSolAccount,
|
|
367
370
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
368
371
|
systemProgram: SystemProgram.programId,
|
|
@@ -474,6 +477,7 @@ class TradingModule {
|
|
|
474
477
|
mintAccount: mint,
|
|
475
478
|
curveAccount: accounts.curveAccount,
|
|
476
479
|
poolTokenAccount: accounts.poolTokenAccount,
|
|
480
|
+
poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
|
|
477
481
|
poolSolAccount: accounts.poolSolAccount,
|
|
478
482
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
479
483
|
systemProgram: SystemProgram.programId,
|
|
@@ -617,6 +621,7 @@ class TradingModule {
|
|
|
617
621
|
mintAccount: mint,
|
|
618
622
|
curveAccount: accounts.curveAccount,
|
|
619
623
|
poolTokenAccount: accounts.poolTokenAccount,
|
|
624
|
+
poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
|
|
620
625
|
poolSolAccount: accounts.poolSolAccount,
|
|
621
626
|
userSolAccount: userSolAccountPubkey, // 开仓用户的SOL账户 / User SOL account (must be order opener)
|
|
622
627
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
@@ -766,6 +771,7 @@ class TradingModule {
|
|
|
766
771
|
mintAccount: mint,
|
|
767
772
|
curveAccount: accounts.curveAccount,
|
|
768
773
|
poolTokenAccount: accounts.poolTokenAccount,
|
|
774
|
+
poolBorrowTokenAccount: accounts.poolBorrowTokenAccount,
|
|
769
775
|
poolSolAccount: accounts.poolSolAccount,
|
|
770
776
|
userSolAccount: userSolAccountPubkey, // 开仓用户的SOL账户 / User SOL account (must be order opener)
|
|
771
777
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
@@ -827,6 +833,12 @@ class TradingModule {
|
|
|
827
833
|
this.sdk.programId
|
|
828
834
|
);
|
|
829
835
|
|
|
836
|
+
// 计算借贷池专用代币账户 PDA
|
|
837
|
+
const [poolBorrowTokenAccount] = PublicKey.findProgramAddressSync(
|
|
838
|
+
[Buffer.from('pool_borrow_token'), mintAccount.toBuffer()],
|
|
839
|
+
this.sdk.programId
|
|
840
|
+
);
|
|
841
|
+
|
|
830
842
|
// 计算池子 SOL 账户 PDA
|
|
831
843
|
const [poolSolAccount] = PublicKey.findProgramAddressSync(
|
|
832
844
|
[Buffer.from('pool_sol'), mintAccount.toBuffer()],
|
|
@@ -836,6 +848,7 @@ class TradingModule {
|
|
|
836
848
|
return {
|
|
837
849
|
curveAccount,
|
|
838
850
|
poolTokenAccount,
|
|
851
|
+
poolBorrowTokenAccount,
|
|
839
852
|
poolSolAccount
|
|
840
853
|
};
|
|
841
854
|
}
|