pinpet-sdk 2.1.7 → 2.1.8
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/pinpet-sdk.cjs.js +530 -171
- package/dist/pinpet-sdk.esm.js +530 -171
- package/dist/pinpet-sdk.js +530 -171
- package/dist/pinpet-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/idl/pinpet.json +194 -60
- package/src/modules/chain.js +8 -0
- package/src/modules/token.js +78 -12
- package/src/utils/curve_amm.js +250 -99
package/dist/pinpet-sdk.cjs.js
CHANGED
|
@@ -16490,28 +16490,86 @@ class TokenModule$1 {
|
|
|
16490
16490
|
}
|
|
16491
16491
|
|
|
16492
16492
|
/**
|
|
16493
|
-
*
|
|
16494
|
-
* @param {Object} params -
|
|
16495
|
-
* @param {Keypair} params.mint -
|
|
16496
|
-
* @param {string} params.name -
|
|
16497
|
-
* @param {string} params.symbol -
|
|
16498
|
-
* @param {string} params.uri -
|
|
16499
|
-
* @param {PublicKey} params.payer -
|
|
16500
|
-
*
|
|
16493
|
+
* 创建新代币
|
|
16494
|
+
* @param {Object} params - 创建参数
|
|
16495
|
+
* @param {Keypair} params.mint - 代币mint keypair
|
|
16496
|
+
* @param {string} params.name - 代币名称
|
|
16497
|
+
* @param {string} params.symbol - 代币符号
|
|
16498
|
+
* @param {string} params.uri - 元数据URI
|
|
16499
|
+
* @param {PublicKey} params.payer - 创建者公钥(付款方)
|
|
16500
|
+
*
|
|
16501
|
+
* === 第二阶段新增:高级版池子可选参数 ===
|
|
16502
|
+
* @param {anchor.BN} [params.customLpSol] - 自定义流动池SOL数量(lamports,9位精度)
|
|
16503
|
+
* - 不传或传null:创建普通版池子,使用默认值30 SOL
|
|
16504
|
+
* - 传入值:创建高级版池子,需在 10 SOL ~ 1000 SOL 范围内
|
|
16505
|
+
* - ⚠️ 必须与 customLpToken, customBorrowRatio, customBorrowDuration 同时提供
|
|
16506
|
+
*
|
|
16507
|
+
* @param {anchor.BN} [params.customLpToken] - 自定义流动池Token数量(最小单位,9位精度)
|
|
16508
|
+
* - 不传或传null:使用默认值10.73亿 Token
|
|
16509
|
+
* - 传入值:需在 1亿 ~ 100亿 Token 范围内
|
|
16510
|
+
*
|
|
16511
|
+
* @param {number} [params.customBorrowRatio] - 自定义借贷池代币占比(5-30表示5%-30%)
|
|
16512
|
+
* - 不传或传null:使用默认值20%
|
|
16513
|
+
* - 传入值:需在 5 ~ 30 范围内
|
|
16514
|
+
*
|
|
16515
|
+
* @param {number} [params.customBorrowDuration] - 自定义借贷时长(秒)
|
|
16516
|
+
* - 不传或传null:使用Params账户配置的默认值
|
|
16517
|
+
* - 传入值:需在 3天(259200秒) ~ 6个月(15552000秒) 范围内
|
|
16518
|
+
*
|
|
16519
|
+
* @returns {Promise<Object>} 包含transaction、signers和账户信息的对象
|
|
16520
|
+
*
|
|
16521
|
+
* @example
|
|
16522
|
+
* // 创建普通版代币(使用默认参数)
|
|
16523
|
+
* const result = await sdk.token.create({
|
|
16524
|
+
* mint: mintKeypair,
|
|
16525
|
+
* name: "My Token",
|
|
16526
|
+
* symbol: "MTK",
|
|
16527
|
+
* uri: "https://example.com/metadata.json",
|
|
16528
|
+
* payer: wallet.publicKey
|
|
16529
|
+
* });
|
|
16530
|
+
*
|
|
16531
|
+
* @example
|
|
16532
|
+
* // 创建高级版代币(自定义流动池参数)
|
|
16533
|
+
* const anchor = require('@coral-xyz/anchor');
|
|
16534
|
+
* const result = await sdk.token.create({
|
|
16535
|
+
* mint: mintKeypair,
|
|
16536
|
+
* name: "Advanced Token",
|
|
16537
|
+
* symbol: "ADV",
|
|
16538
|
+
* uri: "https://example.com/metadata.json",
|
|
16539
|
+
* payer: wallet.publicKey,
|
|
16540
|
+
* customLpSol: new anchor.BN('60000000000'), // 60 SOL
|
|
16541
|
+
* customLpToken: new anchor.BN('1073000000000000000'), // 10.73亿 Token
|
|
16542
|
+
* customBorrowRatio: 15, // 15%
|
|
16543
|
+
* customBorrowDuration: 7 * 24 * 3600 // 7天
|
|
16544
|
+
* });
|
|
16501
16545
|
*/
|
|
16502
16546
|
async create({
|
|
16503
16547
|
mint,
|
|
16504
16548
|
name,
|
|
16505
16549
|
symbol,
|
|
16506
16550
|
uri,
|
|
16507
|
-
payer
|
|
16551
|
+
payer,
|
|
16552
|
+
// 新增参数
|
|
16553
|
+
customLpSol = null,
|
|
16554
|
+
customLpToken = null,
|
|
16555
|
+
customBorrowRatio = null,
|
|
16556
|
+
customBorrowDuration = null
|
|
16508
16557
|
}) {
|
|
16509
16558
|
console.log('Token Module - Create:', {
|
|
16510
16559
|
mint: mint.publicKey.toString(),
|
|
16511
16560
|
name,
|
|
16512
16561
|
symbol,
|
|
16513
16562
|
uri,
|
|
16514
|
-
payer: payer.toString()
|
|
16563
|
+
payer: payer.toString(),
|
|
16564
|
+
// 新增参数日志
|
|
16565
|
+
poolType: (customLpSol === null && customLpToken === null &&
|
|
16566
|
+
customBorrowRatio === null && customBorrowDuration === null)
|
|
16567
|
+
? 'Standard (default params)'
|
|
16568
|
+
: 'Advanced (custom params)',
|
|
16569
|
+
customLpSol: customLpSol?.toString() || 'null',
|
|
16570
|
+
customLpToken: customLpToken?.toString() || 'null',
|
|
16571
|
+
customBorrowRatio: customBorrowRatio ?? 'null',
|
|
16572
|
+
customBorrowDuration: customBorrowDuration ?? 'null'
|
|
16515
16573
|
});
|
|
16516
16574
|
|
|
16517
16575
|
// Calculate borrowing liquidity pool account address (borrowing_curve)
|
|
@@ -16587,9 +16645,17 @@ class TokenModule$1 {
|
|
|
16587
16645
|
units: 400000
|
|
16588
16646
|
});
|
|
16589
16647
|
|
|
16590
|
-
//
|
|
16648
|
+
// 构建创建代币指令(传入自定义参数)
|
|
16591
16649
|
const createIx = await this.sdk.program.methods
|
|
16592
|
-
.
|
|
16650
|
+
.createToken(
|
|
16651
|
+
name,
|
|
16652
|
+
symbol,
|
|
16653
|
+
uri,
|
|
16654
|
+
customLpSol, // Option<u64>
|
|
16655
|
+
customLpToken, // Option<u64>
|
|
16656
|
+
customBorrowRatio, // Option<u8>
|
|
16657
|
+
customBorrowDuration // Option<u32>
|
|
16658
|
+
)
|
|
16593
16659
|
.accounts({
|
|
16594
16660
|
payer: payer,
|
|
16595
16661
|
mintAccount: mint.publicKey,
|
|
@@ -41822,8 +41888,10 @@ var decimalExports = decimal.exports;
|
|
|
41822
41888
|
|
|
41823
41889
|
const Decimal = decimalExports;
|
|
41824
41890
|
|
|
41825
|
-
// Configure Decimal.js to use
|
|
41826
|
-
|
|
41891
|
+
// Configure Decimal.js to use 50-bit precision for better accuracy with tiny prices
|
|
41892
|
+
// Increased from 28 to 50 to handle extremely small prices (e.g., 0.000000041571)
|
|
41893
|
+
// ROUND_HALF_UP ensures consistent rounding behavior
|
|
41894
|
+
Decimal.set({ precision: 50, rounding: Decimal.ROUND_HALF_UP });
|
|
41827
41895
|
|
|
41828
41896
|
|
|
41829
41897
|
/**
|
|
@@ -42104,36 +42172,70 @@ class CurveAMM$7 {
|
|
|
42104
42172
|
}
|
|
42105
42173
|
|
|
42106
42174
|
/**
|
|
42107
|
-
*
|
|
42108
|
-
*
|
|
42175
|
+
* 根据自定义初始储备量计算 k 值
|
|
42176
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量(实际值,非lamports)
|
|
42177
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量(实际值,非最小单位)
|
|
42178
|
+
* @returns {Decimal} k值
|
|
42179
|
+
*
|
|
42180
|
+
* @example
|
|
42181
|
+
* // 使用默认参数(30 SOL, 10.73亿 Token)
|
|
42182
|
+
* const k1 = CurveAMM.calculateK(30, 1073000000);
|
|
42183
|
+
*
|
|
42184
|
+
* // 使用自定义参数(60 SOL, 10.73亿 Token)
|
|
42185
|
+
* const k2 = CurveAMM.calculateK(60, 1073000000);
|
|
42186
|
+
*/
|
|
42187
|
+
static calculateK(initialVirtualSol, initialVirtualToken) {
|
|
42188
|
+
const sol = new Decimal(initialVirtualSol);
|
|
42189
|
+
const token = new Decimal(initialVirtualToken);
|
|
42190
|
+
return sol.mul(token);
|
|
42191
|
+
}
|
|
42192
|
+
|
|
42193
|
+
/**
|
|
42194
|
+
* 使用默认参数计算初始k值(向后兼容)
|
|
42109
42195
|
* @returns {Decimal} Product k value of initial reserves
|
|
42110
42196
|
*/
|
|
42111
42197
|
static calculateInitialK() {
|
|
42112
|
-
return this.
|
|
42198
|
+
return this.calculateK(
|
|
42199
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42200
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42201
|
+
);
|
|
42202
|
+
}
|
|
42203
|
+
|
|
42204
|
+
/**
|
|
42205
|
+
* 根据自定义初始储备量获取初始价格
|
|
42206
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量
|
|
42207
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量
|
|
42208
|
+
* @returns {bigint|null} u128格式的初始价格
|
|
42209
|
+
*/
|
|
42210
|
+
static getInitialPriceWithParams(initialVirtualSol, initialVirtualToken) {
|
|
42211
|
+
const sol = new Decimal(initialVirtualSol);
|
|
42212
|
+
const token = new Decimal(initialVirtualToken);
|
|
42213
|
+
const initialPrice = sol.div(token);
|
|
42214
|
+
return this.decimalToU128(initialPrice);
|
|
42113
42215
|
}
|
|
42114
42216
|
|
|
42115
42217
|
/**
|
|
42218
|
+
* 使用默认参数获取初始价格(向后兼容)
|
|
42116
42219
|
* Get initial price (SOL amount for 1 token)
|
|
42117
|
-
*
|
|
42220
|
+
*
|
|
42118
42221
|
* @returns {bigint|null} Initial price in u128 format, returns null if calculation fails
|
|
42119
42222
|
*/
|
|
42120
42223
|
static getInitialPrice() {
|
|
42121
|
-
|
|
42122
|
-
|
|
42123
|
-
|
|
42124
|
-
|
|
42125
|
-
return this.decimalToU128(initialPrice);
|
|
42224
|
+
return this.getInitialPriceWithParams(
|
|
42225
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42226
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42227
|
+
);
|
|
42126
42228
|
}
|
|
42127
42229
|
|
|
42128
42230
|
/**
|
|
42129
|
-
*
|
|
42130
|
-
*
|
|
42131
|
-
* @param {bigint|string|number}
|
|
42132
|
-
* @param {
|
|
42133
|
-
* @
|
|
42134
|
-
*
|
|
42231
|
+
* 根据自定义初始储备量计算从低价买入到高价所需的SOL和获得的Token
|
|
42232
|
+
* @param {bigint|string|number} startLowPrice - 起始价格(较低)
|
|
42233
|
+
* @param {bigint|string|number} endHighPrice - 目标价格(较高)
|
|
42234
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量
|
|
42235
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量
|
|
42236
|
+
* @returns {[bigint, bigint]|null} 成功返回 [需投入SOL数量, 获得token数量], 失败返回null
|
|
42135
42237
|
*/
|
|
42136
|
-
static
|
|
42238
|
+
static buyFromPriceToPriceWithParams(startLowPrice, endHighPrice, initialVirtualSol, initialVirtualToken) {
|
|
42137
42239
|
// Convert to Decimal for calculation
|
|
42138
42240
|
const startPriceDec = this.u128ToDecimal(startLowPrice);
|
|
42139
42241
|
const endPriceDec = this.u128ToDecimal(endHighPrice);
|
|
@@ -42143,8 +42245,8 @@ class CurveAMM$7 {
|
|
|
42143
42245
|
return null;
|
|
42144
42246
|
}
|
|
42145
42247
|
|
|
42146
|
-
// Use
|
|
42147
|
-
const k = this.
|
|
42248
|
+
// Use custom k value
|
|
42249
|
+
const k = this.calculateK(initialVirtualSol, initialVirtualToken);
|
|
42148
42250
|
|
|
42149
42251
|
// Calculate reserves for starting and ending states
|
|
42150
42252
|
const startReserves = this.calculateReservesByPrice(startPriceDec, k);
|
|
@@ -42181,77 +42283,63 @@ class CurveAMM$7 {
|
|
|
42181
42283
|
}
|
|
42182
42284
|
|
|
42183
42285
|
/**
|
|
42184
|
-
*
|
|
42185
|
-
*
|
|
42186
|
-
*
|
|
42187
|
-
* @param {bigint|string|number}
|
|
42188
|
-
* @
|
|
42189
|
-
*
|
|
42286
|
+
* 使用默认参数计算从低价买入到高价(向后兼容)
|
|
42287
|
+
* Calculate SOL required and token amount obtained when buying tokens from low to high price
|
|
42288
|
+
*
|
|
42289
|
+
* @param {bigint|string|number} startLowPrice - Starting price (lower)
|
|
42290
|
+
* @param {bigint|string|number} endHighPrice - Target price (higher)
|
|
42291
|
+
* @returns {[bigint, bigint]|null} Returns [SOL amount to invest, token amount to obtain] on success, null on failure
|
|
42292
|
+
* SOL amount in 9-digit precision rounded up; token amount in 9-digit precision rounded down
|
|
42190
42293
|
*/
|
|
42191
|
-
static
|
|
42192
|
-
|
|
42193
|
-
|
|
42194
|
-
|
|
42195
|
-
|
|
42294
|
+
static buyFromPriceToPrice(startLowPrice, endHighPrice) {
|
|
42295
|
+
return this.buyFromPriceToPriceWithParams(
|
|
42296
|
+
startLowPrice,
|
|
42297
|
+
endHighPrice,
|
|
42298
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42299
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42300
|
+
);
|
|
42301
|
+
}
|
|
42196
42302
|
|
|
42303
|
+
/**
|
|
42304
|
+
* 根据自定义初始储备量计算从高价卖出到低价所需的Token和获得的SOL
|
|
42305
|
+
* @param {bigint|string|number} startHighPrice - 起始价格(较高)
|
|
42306
|
+
* @param {bigint|string|number} endLowPrice - 目标价格(较低)
|
|
42307
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量
|
|
42308
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量
|
|
42309
|
+
* @returns {[bigint, bigint]|null} 成功返回 [需卖出token数量, 获得SOL数量], 失败返回null
|
|
42310
|
+
*/
|
|
42311
|
+
static sellFromPriceToPriceWithParams(startHighPrice, endLowPrice, initialVirtualSol, initialVirtualToken) {
|
|
42197
42312
|
// Convert to Decimal for calculation
|
|
42198
42313
|
const startPriceDec = this.u128ToDecimal(startHighPrice);
|
|
42199
42314
|
const endPriceDec = this.u128ToDecimal(endLowPrice);
|
|
42200
42315
|
|
|
42201
|
-
// console.log('Price conversion results:');
|
|
42202
|
-
// console.log(' startPriceDec:', startPriceDec.toString());
|
|
42203
|
-
// console.log(' endPriceDec:', endPriceDec.toString());
|
|
42204
|
-
|
|
42205
42316
|
// Ensure starting price is higher than ending price
|
|
42206
42317
|
if (startPriceDec.lte(endPriceDec)) {
|
|
42207
|
-
// console.log('❌ Failure reason: starting price is lower than or equal to ending price');
|
|
42208
|
-
// console.log(' startPriceDec.lte(endPriceDec):', startPriceDec.lte(endPriceDec));
|
|
42209
42318
|
return null;
|
|
42210
42319
|
}
|
|
42211
42320
|
|
|
42212
|
-
// Use
|
|
42213
|
-
const k = this.
|
|
42214
|
-
//console.log('k value:', k.toString());
|
|
42321
|
+
// Use custom k value
|
|
42322
|
+
const k = this.calculateK(initialVirtualSol, initialVirtualToken);
|
|
42215
42323
|
|
|
42216
42324
|
// Calculate reserves for starting and ending states
|
|
42217
42325
|
const startReserves = this.calculateReservesByPrice(startPriceDec, k);
|
|
42218
42326
|
const endReserves = this.calculateReservesByPrice(endPriceDec, k);
|
|
42219
42327
|
|
|
42220
|
-
|
|
42221
|
-
|
|
42222
|
-
|
|
42223
|
-
|
|
42224
|
-
// if (!startReserves || !endReserves) {
|
|
42225
|
-
// console.log('❌ Failure reason: reserve calculation failed');
|
|
42226
|
-
// console.log(' startReserves:', startReserves);
|
|
42227
|
-
// console.log(' endReserves:', endReserves);
|
|
42228
|
-
// return null;
|
|
42229
|
-
// }
|
|
42328
|
+
if (!startReserves || !endReserves) {
|
|
42329
|
+
return null;
|
|
42330
|
+
}
|
|
42230
42331
|
|
|
42231
42332
|
const [startSolReserve, startTokenReserve] = startReserves;
|
|
42232
42333
|
const [endSolReserve, endTokenReserve] = endReserves;
|
|
42233
42334
|
|
|
42234
|
-
// console.log('Detailed reserves:');
|
|
42235
|
-
// console.log(' Starting state - SOL reserve:', startSolReserve.toString());
|
|
42236
|
-
// console.log(' Starting state - Token reserve:', startTokenReserve.toString());
|
|
42237
|
-
// console.log(' Ending state - SOL reserve:', endSolReserve.toString());
|
|
42238
|
-
// console.log(' Ending state - Token reserve:', endTokenReserve.toString());
|
|
42239
|
-
|
|
42240
42335
|
// Calculate token amount to sell (increase in token reserves)
|
|
42241
42336
|
const tokenInputAmount = endTokenReserve.sub(startTokenReserve);
|
|
42242
42337
|
|
|
42243
42338
|
// Calculate SOL amount to obtain (decrease in SOL reserves)
|
|
42244
42339
|
const solOutputAmount = startSolReserve.sub(endSolReserve);
|
|
42245
42340
|
|
|
42246
|
-
// console.log('Transaction calculation results:');
|
|
42247
|
-
// console.log(' Token amount to sell (tokenInputAmount):', tokenInputAmount.toString());
|
|
42248
|
-
// console.log(' SOL amount to obtain (solOutputAmount):', solOutputAmount.toString());
|
|
42249
|
-
|
|
42250
42341
|
// Check if calculation results are valid
|
|
42251
42342
|
if (tokenInputAmount.lte(0) || solOutputAmount.lte(0)) {
|
|
42252
|
-
// console.log('❌ Failure reason: invalid transaction amount calculation results');
|
|
42253
|
-
// console.log(' tokenInputAmount.lte(0):', tokenInputAmount.lte(0));
|
|
42254
|
-
// console.log(' solOutputAmount.lte(0):', solOutputAmount.lte(0));
|
|
42255
42343
|
return null;
|
|
42256
42344
|
}
|
|
42257
42345
|
|
|
@@ -42260,28 +42348,94 @@ class CurveAMM$7 {
|
|
|
42260
42348
|
const tokenAmountU64 = this.tokenDecimalToU64Ceil(tokenInputAmount);
|
|
42261
42349
|
const solAmountU64 = this.solDecimalToU64(solOutputAmount);
|
|
42262
42350
|
|
|
42263
|
-
// console.log('u64 conversion results:');
|
|
42264
|
-
// console.log(' tokenAmountU64:', tokenAmountU64);
|
|
42265
|
-
// console.log(' solAmountU64:', solAmountU64);
|
|
42266
|
-
|
|
42267
42351
|
if (tokenAmountU64 === null || solAmountU64 === null) {
|
|
42268
|
-
// console.log('❌ Failure reason: u64 conversion failed');
|
|
42269
|
-
// console.log(' tokenAmountU64 === null:', tokenAmountU64 === null);
|
|
42270
|
-
// console.log(' solAmountU64 === null:', solAmountU64 === null);
|
|
42271
42352
|
return null;
|
|
42272
42353
|
}
|
|
42273
42354
|
|
|
42274
|
-
// console.log('✅ Success! Return results:');
|
|
42275
|
-
// console.log(' Token amount to sell:', tokenAmountU64.toString());
|
|
42276
|
-
// console.log(' SOL amount to obtain:', solAmountU64.toString());
|
|
42277
|
-
// console.log('=== sellFromPriceToPrice debug end ===\n');
|
|
42278
|
-
|
|
42279
42355
|
return [tokenAmountU64, solAmountU64];
|
|
42280
42356
|
}
|
|
42281
42357
|
|
|
42358
|
+
/**
|
|
42359
|
+
* 使用默认参数计算从高价卖出到低价(向后兼容)
|
|
42360
|
+
* Calculate SOL amount obtained when selling tokens from high to low price
|
|
42361
|
+
*
|
|
42362
|
+
* @param {bigint|string|number} startHighPrice - Starting price (higher)
|
|
42363
|
+
* @param {bigint|string|number} endLowPrice - Target price (lower)
|
|
42364
|
+
* @returns {[bigint, bigint]|null} Returns [token amount to sell, SOL amount to obtain] on success, null on failure
|
|
42365
|
+
* token amount in 9-digit precision rounded up; SOL amount in 9-digit precision rounded down
|
|
42366
|
+
*/
|
|
42367
|
+
static sellFromPriceToPrice(startHighPrice, endLowPrice) {
|
|
42368
|
+
return this.sellFromPriceToPriceWithParams(
|
|
42369
|
+
startHighPrice,
|
|
42370
|
+
endLowPrice,
|
|
42371
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42372
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42373
|
+
);
|
|
42374
|
+
}
|
|
42375
|
+
|
|
42376
|
+
/**
|
|
42377
|
+
* 根据价格和自定义k值计算储备量
|
|
42378
|
+
* @param {bigint|string} price - u128格式价格
|
|
42379
|
+
* @param {Decimal} k - 自定义k值
|
|
42380
|
+
* @returns {{solReserve: Decimal, tokenReserve: Decimal}|null}
|
|
42381
|
+
*/
|
|
42382
|
+
static priceToReservesWithK(price, k) {
|
|
42383
|
+
const priceDecimal = this.u128ToDecimal(price);
|
|
42384
|
+
|
|
42385
|
+
// Check if input parameters are valid
|
|
42386
|
+
if (priceDecimal.lte(0) || k.lte(0)) {
|
|
42387
|
+
return null;
|
|
42388
|
+
}
|
|
42389
|
+
|
|
42390
|
+
// Minimum price check to prevent overflow
|
|
42391
|
+
if (priceDecimal.lt(this.INITIAL_MIN_PRICE_DECIMAL)) {
|
|
42392
|
+
return null;
|
|
42393
|
+
}
|
|
42394
|
+
|
|
42395
|
+
// token_reserve = sqrt(k / price)
|
|
42396
|
+
const tokenReserve = k.div(priceDecimal).sqrt();
|
|
42397
|
+
|
|
42398
|
+
// sol_reserve = k / token_reserve
|
|
42399
|
+
const solReserve = k.div(tokenReserve);
|
|
42400
|
+
|
|
42401
|
+
if (tokenReserve.isNaN() || solReserve.isNaN()) {
|
|
42402
|
+
return null;
|
|
42403
|
+
}
|
|
42404
|
+
|
|
42405
|
+
return {
|
|
42406
|
+
solReserve,
|
|
42407
|
+
tokenReserve
|
|
42408
|
+
};
|
|
42409
|
+
}
|
|
42410
|
+
|
|
42411
|
+
/**
|
|
42412
|
+
* 根据价格和自定义初始储备量计算储备量
|
|
42413
|
+
* @param {bigint|string} price - u128格式价格
|
|
42414
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量
|
|
42415
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量
|
|
42416
|
+
* @returns {{solReserve: Decimal, tokenReserve: Decimal}|null}
|
|
42417
|
+
*/
|
|
42418
|
+
static priceToReservesWithParams(price, initialVirtualSol, initialVirtualToken) {
|
|
42419
|
+
const k = this.calculateK(initialVirtualSol, initialVirtualToken);
|
|
42420
|
+
return this.priceToReservesWithK(price, k);
|
|
42421
|
+
}
|
|
42422
|
+
|
|
42423
|
+
/**
|
|
42424
|
+
* 使用默认参数根据价格计算储备量(向后兼容)
|
|
42425
|
+
* @param {bigint|string} price - u128格式价格
|
|
42426
|
+
* @returns {{solReserve: Decimal, tokenReserve: Decimal}|null}
|
|
42427
|
+
*/
|
|
42428
|
+
static priceToReserves(price) {
|
|
42429
|
+
return this.priceToReservesWithParams(
|
|
42430
|
+
price,
|
|
42431
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42432
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42433
|
+
);
|
|
42434
|
+
}
|
|
42435
|
+
|
|
42282
42436
|
/**
|
|
42283
42437
|
* Calculate reserves given a price
|
|
42284
|
-
*
|
|
42438
|
+
*
|
|
42285
42439
|
* @param {Decimal} price - Price, representing SOL amount for 1 token
|
|
42286
42440
|
* @param {Decimal} k - Constant product
|
|
42287
42441
|
* @returns {[Decimal, Decimal]|null} Returns [SOL reserve, token reserve] on success, null on failure
|
|
@@ -42297,6 +42451,19 @@ class CurveAMM$7 {
|
|
|
42297
42451
|
return null;
|
|
42298
42452
|
}
|
|
42299
42453
|
|
|
42454
|
+
// Warning for extremely small prices that may have precision issues
|
|
42455
|
+
const warningPrice = new Decimal('0.0000001'); // 10^-7
|
|
42456
|
+
if (price.lt(warningPrice)) {
|
|
42457
|
+
// Only log once per execution to avoid spam (use a static flag)
|
|
42458
|
+
if (!this._tinyPriceWarningShown) {
|
|
42459
|
+
console.warn(
|
|
42460
|
+
`[CurveAMM] 警告: 价格非常小 (${price.toString()}),` +
|
|
42461
|
+
`计算精度可能受影响。建议验证结果。`
|
|
42462
|
+
);
|
|
42463
|
+
this._tinyPriceWarningShown = true;
|
|
42464
|
+
}
|
|
42465
|
+
}
|
|
42466
|
+
|
|
42300
42467
|
// According to AMM formula: k = sol_reserve * token_reserve
|
|
42301
42468
|
// and price = sol_reserve / token_reserve
|
|
42302
42469
|
// We get: sol_reserve = price * token_reserve
|
|
@@ -42317,18 +42484,33 @@ class CurveAMM$7 {
|
|
|
42317
42484
|
return null;
|
|
42318
42485
|
}
|
|
42319
42486
|
|
|
42487
|
+
// Verify calculation accuracy by checking if k is preserved (optional but recommended)
|
|
42488
|
+
// Only check for tiny prices to minimize performance impact
|
|
42489
|
+
if (price.lt(warningPrice)) {
|
|
42490
|
+
const verifyK = solReserve.mul(tokenReserve);
|
|
42491
|
+
const kDiff = verifyK.sub(k).abs().div(k);
|
|
42492
|
+
|
|
42493
|
+
// If k value deviation exceeds 0.1%, log a warning
|
|
42494
|
+
if (kDiff.gt('0.001')) {
|
|
42495
|
+
console.warn(
|
|
42496
|
+
`[CurveAMM] 储备量计算精度偏差: ${kDiff.mul(100).toFixed(4)}%,` +
|
|
42497
|
+
`价格=${price.toString()}`
|
|
42498
|
+
);
|
|
42499
|
+
}
|
|
42500
|
+
}
|
|
42501
|
+
|
|
42320
42502
|
return [solReserve, tokenReserve];
|
|
42321
42503
|
}
|
|
42322
42504
|
|
|
42323
42505
|
/**
|
|
42324
|
-
*
|
|
42325
|
-
*
|
|
42326
|
-
* @param {bigint|string|number}
|
|
42327
|
-
* @param {
|
|
42328
|
-
* @
|
|
42329
|
-
*
|
|
42506
|
+
* 根据自定义初始储备量,基于起始价格和SOL输入量计算token输出量和结束价格
|
|
42507
|
+
* @param {bigint|string|number} startLowPrice - 起始价格
|
|
42508
|
+
* @param {bigint|string|number} solInputAmount - 用于买入的SOL数量
|
|
42509
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量
|
|
42510
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量
|
|
42511
|
+
* @returns {[bigint, bigint]|null} 成功返回 [交易后价格, 获得的token数量], 失败返回null
|
|
42330
42512
|
*/
|
|
42331
|
-
static
|
|
42513
|
+
static buyFromPriceWithSolInputWithParams(startLowPrice, solInputAmount, initialVirtualSol, initialVirtualToken) {
|
|
42332
42514
|
// Convert to Decimal for calculation
|
|
42333
42515
|
const startPriceDec = this.u128ToDecimal(startLowPrice);
|
|
42334
42516
|
const solInputDec = this.u64ToSolDecimal(solInputAmount);
|
|
@@ -42337,20 +42519,20 @@ class CurveAMM$7 {
|
|
|
42337
42519
|
if (startPriceDec.lte(0)) {
|
|
42338
42520
|
return null;
|
|
42339
42521
|
}
|
|
42340
|
-
|
|
42522
|
+
|
|
42341
42523
|
// If SOL input amount is 0, return unchanged price and token output of 0
|
|
42342
42524
|
if (solInputDec.eq(0)) {
|
|
42343
42525
|
const endPriceU128 = this.decimalToU128(startPriceDec);
|
|
42344
42526
|
if (endPriceU128 === null) return null;
|
|
42345
42527
|
return [endPriceU128, 0n];
|
|
42346
42528
|
}
|
|
42347
|
-
|
|
42529
|
+
|
|
42348
42530
|
if (solInputDec.lt(0)) {
|
|
42349
42531
|
return null;
|
|
42350
42532
|
}
|
|
42351
42533
|
|
|
42352
|
-
// Use
|
|
42353
|
-
const k = this.
|
|
42534
|
+
// Use custom k value
|
|
42535
|
+
const k = this.calculateK(initialVirtualSol, initialVirtualToken);
|
|
42354
42536
|
|
|
42355
42537
|
// Calculate reserves for starting state
|
|
42356
42538
|
const startReserves = this.calculateReservesByPrice(startPriceDec, k);
|
|
@@ -42387,37 +42569,54 @@ class CurveAMM$7 {
|
|
|
42387
42569
|
}
|
|
42388
42570
|
|
|
42389
42571
|
/**
|
|
42390
|
-
*
|
|
42391
|
-
*
|
|
42392
|
-
*
|
|
42393
|
-
* @param {bigint|string|number}
|
|
42394
|
-
* @
|
|
42395
|
-
*
|
|
42572
|
+
* 使用默认参数计算token输出量和结束价格(向后兼容)
|
|
42573
|
+
* Calculate token output amount and ending price based on starting price and SOL input amount
|
|
42574
|
+
*
|
|
42575
|
+
* @param {bigint|string|number} startLowPrice - Starting price
|
|
42576
|
+
* @param {bigint|string|number} solInputAmount - SOL amount for buying
|
|
42577
|
+
* @returns {[bigint, bigint]|null} Returns [price after transaction, token amount obtained] on success, null on failure
|
|
42578
|
+
* Price rounded down, token amount rounded down
|
|
42396
42579
|
*/
|
|
42397
|
-
static
|
|
42580
|
+
static buyFromPriceWithSolInput(startLowPrice, solInputAmount) {
|
|
42581
|
+
return this.buyFromPriceWithSolInputWithParams(
|
|
42582
|
+
startLowPrice,
|
|
42583
|
+
solInputAmount,
|
|
42584
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42585
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42586
|
+
);
|
|
42587
|
+
}
|
|
42588
|
+
|
|
42589
|
+
/**
|
|
42590
|
+
* 根据自定义初始储备量,基于起始价格和token输入量计算SOL输出量和结束价格
|
|
42591
|
+
* @param {bigint|string|number} startHighPrice - 起始价格
|
|
42592
|
+
* @param {bigint|string|number} tokenInputAmount - 要卖出的token数量
|
|
42593
|
+
* @param {string|number|Decimal} initialVirtualSol - 初始虚拟SOL储备量
|
|
42594
|
+
* @param {string|number|Decimal} initialVirtualToken - 初始虚拟Token储备量
|
|
42595
|
+
* @returns {[bigint, bigint]|null} 成功返回 [交易后价格, 获得的SOL数量], 失败返回null
|
|
42596
|
+
*/
|
|
42597
|
+
static sellFromPriceWithTokenInputWithParams(startHighPrice, tokenInputAmount, initialVirtualSol, initialVirtualToken) {
|
|
42398
42598
|
// Convert to Decimal for calculation
|
|
42399
42599
|
const startPriceDec = this.u128ToDecimal(startHighPrice);
|
|
42400
42600
|
const tokenInputDec = this.u64ToTokenDecimal(tokenInputAmount);
|
|
42401
42601
|
|
|
42402
|
-
//console.log("startHighPrice, tokenInputAmount",startHighPrice, tokenInputAmount)
|
|
42403
42602
|
// Check if input parameters are valid
|
|
42404
42603
|
if (startPriceDec.lte(0)) {
|
|
42405
42604
|
return null;
|
|
42406
42605
|
}
|
|
42407
|
-
|
|
42606
|
+
|
|
42408
42607
|
// If token input amount is 0, return unchanged price and SOL output of 0
|
|
42409
42608
|
if (tokenInputDec.eq(0)) {
|
|
42410
42609
|
const endPriceU128 = this.decimalToU128(startPriceDec);
|
|
42411
42610
|
if (endPriceU128 === null) return null;
|
|
42412
42611
|
return [endPriceU128, 0n];
|
|
42413
42612
|
}
|
|
42414
|
-
|
|
42613
|
+
|
|
42415
42614
|
if (tokenInputDec.lt(0)) {
|
|
42416
42615
|
return null;
|
|
42417
42616
|
}
|
|
42418
42617
|
|
|
42419
|
-
// Use
|
|
42420
|
-
const k = this.
|
|
42618
|
+
// Use custom k value
|
|
42619
|
+
const k = this.calculateK(initialVirtualSol, initialVirtualToken);
|
|
42421
42620
|
|
|
42422
42621
|
// Calculate reserves for starting state
|
|
42423
42622
|
const startReserves = this.calculateReservesByPrice(startPriceDec, k);
|
|
@@ -42453,6 +42652,24 @@ class CurveAMM$7 {
|
|
|
42453
42652
|
return [endPriceU128, solAmountU64];
|
|
42454
42653
|
}
|
|
42455
42654
|
|
|
42655
|
+
/**
|
|
42656
|
+
* 使用默认参数计算SOL输出量和结束价格(向后兼容)
|
|
42657
|
+
* Calculate SOL output amount and ending price based on starting price and token input amount
|
|
42658
|
+
*
|
|
42659
|
+
* @param {bigint|string|number} startHighPrice - Starting price
|
|
42660
|
+
* @param {bigint|string|number} tokenInputAmount - Token amount to sell
|
|
42661
|
+
* @returns {[bigint, bigint]|null} Returns [price after transaction, SOL amount obtained] on success, null on failure
|
|
42662
|
+
* Price rounded down, SOL amount rounded down
|
|
42663
|
+
*/
|
|
42664
|
+
static sellFromPriceWithTokenInput(startHighPrice, tokenInputAmount) {
|
|
42665
|
+
return this.sellFromPriceWithTokenInputWithParams(
|
|
42666
|
+
startHighPrice,
|
|
42667
|
+
tokenInputAmount,
|
|
42668
|
+
this.INITIAL_SOL_RESERVE_DECIMAL,
|
|
42669
|
+
this.INITIAL_TOKEN_RESERVE_DECIMAL
|
|
42670
|
+
);
|
|
42671
|
+
}
|
|
42672
|
+
|
|
42456
42673
|
/**
|
|
42457
42674
|
* Calculate required SOL input amount and ending price based on starting price and expected token output amount
|
|
42458
42675
|
*
|
|
@@ -47474,6 +47691,14 @@ class ChainModule$1 {
|
|
|
47474
47691
|
// Creator address
|
|
47475
47692
|
creator: decodedData.creator.toString(),
|
|
47476
47693
|
|
|
47694
|
+
// === 第一阶段新增字段:动态流动池参数 ===
|
|
47695
|
+
initialVirtualSol: BigInt(decodedData.initialVirtualSol.toString()), // u64, lamports
|
|
47696
|
+
initialVirtualToken: BigInt(decodedData.initialVirtualToken.toString()), // u64, 最小单位
|
|
47697
|
+
|
|
47698
|
+
// === 第二阶段新增字段:高级版池子参数 ===
|
|
47699
|
+
poolType: decodedData.poolType, // u8, 0=普通版, 1=高级版
|
|
47700
|
+
borrowPoolRatio: decodedData.borrowPoolRatio, // u8, 5-30表示5%-30%
|
|
47701
|
+
|
|
47477
47702
|
// SOL balance information
|
|
47478
47703
|
baseFeeRecipientBalance: baseFeeRecipientBalance, // Unit: lamports
|
|
47479
47704
|
feeRecipientBalance: feeRecipientBalance, // Unit: lamports
|
|
@@ -48917,8 +49142,7 @@ var instructions = [
|
|
|
48917
49142
|
accounts: [
|
|
48918
49143
|
{
|
|
48919
49144
|
name: "payer",
|
|
48920
|
-
writable: true
|
|
48921
|
-
signer: true
|
|
49145
|
+
writable: true
|
|
48922
49146
|
},
|
|
48923
49147
|
{
|
|
48924
49148
|
name: "mint_account"
|
|
@@ -49409,8 +49633,7 @@ var instructions = [
|
|
|
49409
49633
|
accounts: [
|
|
49410
49634
|
{
|
|
49411
49635
|
name: "payer",
|
|
49412
|
-
writable: true
|
|
49413
|
-
signer: true
|
|
49636
|
+
writable: true
|
|
49414
49637
|
},
|
|
49415
49638
|
{
|
|
49416
49639
|
name: "mint_account",
|
|
@@ -49621,8 +49844,7 @@ var instructions = [
|
|
|
49621
49844
|
accounts: [
|
|
49622
49845
|
{
|
|
49623
49846
|
name: "payer",
|
|
49624
|
-
writable: true
|
|
49625
|
-
signer: true
|
|
49847
|
+
writable: true
|
|
49626
49848
|
},
|
|
49627
49849
|
{
|
|
49628
49850
|
name: "mint_account",
|
|
@@ -49833,8 +50055,7 @@ var instructions = [
|
|
|
49833
50055
|
accounts: [
|
|
49834
50056
|
{
|
|
49835
50057
|
name: "payer",
|
|
49836
|
-
writable: true
|
|
49837
|
-
signer: true
|
|
50058
|
+
writable: true
|
|
49838
50059
|
},
|
|
49839
50060
|
{
|
|
49840
50061
|
name: "mint_account"
|
|
@@ -50182,6 +50403,30 @@ var instructions = [
|
|
|
50182
50403
|
{
|
|
50183
50404
|
name: "uri",
|
|
50184
50405
|
type: "string"
|
|
50406
|
+
},
|
|
50407
|
+
{
|
|
50408
|
+
name: "custom_lp_sol",
|
|
50409
|
+
type: {
|
|
50410
|
+
option: "u64"
|
|
50411
|
+
}
|
|
50412
|
+
},
|
|
50413
|
+
{
|
|
50414
|
+
name: "custom_lp_token",
|
|
50415
|
+
type: {
|
|
50416
|
+
option: "u64"
|
|
50417
|
+
}
|
|
50418
|
+
},
|
|
50419
|
+
{
|
|
50420
|
+
name: "custom_borrow_ratio",
|
|
50421
|
+
type: {
|
|
50422
|
+
option: "u8"
|
|
50423
|
+
}
|
|
50424
|
+
},
|
|
50425
|
+
{
|
|
50426
|
+
name: "custom_borrow_duration",
|
|
50427
|
+
type: {
|
|
50428
|
+
option: "u32"
|
|
50429
|
+
}
|
|
50185
50430
|
}
|
|
50186
50431
|
]
|
|
50187
50432
|
},
|
|
@@ -50454,6 +50699,30 @@ var instructions = [
|
|
|
50454
50699
|
{
|
|
50455
50700
|
name: "uri",
|
|
50456
50701
|
type: "string"
|
|
50702
|
+
},
|
|
50703
|
+
{
|
|
50704
|
+
name: "custom_lp_sol",
|
|
50705
|
+
type: {
|
|
50706
|
+
option: "u64"
|
|
50707
|
+
}
|
|
50708
|
+
},
|
|
50709
|
+
{
|
|
50710
|
+
name: "custom_lp_token",
|
|
50711
|
+
type: {
|
|
50712
|
+
option: "u64"
|
|
50713
|
+
}
|
|
50714
|
+
},
|
|
50715
|
+
{
|
|
50716
|
+
name: "custom_borrow_ratio",
|
|
50717
|
+
type: {
|
|
50718
|
+
option: "u8"
|
|
50719
|
+
}
|
|
50720
|
+
},
|
|
50721
|
+
{
|
|
50722
|
+
name: "custom_borrow_duration",
|
|
50723
|
+
type: {
|
|
50724
|
+
option: "u32"
|
|
50725
|
+
}
|
|
50457
50726
|
}
|
|
50458
50727
|
]
|
|
50459
50728
|
},
|
|
@@ -50472,8 +50741,7 @@ var instructions = [
|
|
|
50472
50741
|
accounts: [
|
|
50473
50742
|
{
|
|
50474
50743
|
name: "payer",
|
|
50475
|
-
writable: true
|
|
50476
|
-
signer: true
|
|
50744
|
+
writable: true
|
|
50477
50745
|
},
|
|
50478
50746
|
{
|
|
50479
50747
|
name: "mint_account",
|
|
@@ -51011,8 +51279,7 @@ var instructions = [
|
|
|
51011
51279
|
accounts: [
|
|
51012
51280
|
{
|
|
51013
51281
|
name: "payer",
|
|
51014
|
-
writable: true
|
|
51015
|
-
signer: true
|
|
51282
|
+
writable: true
|
|
51016
51283
|
},
|
|
51017
51284
|
{
|
|
51018
51285
|
name: "mint_account",
|
|
@@ -51780,7 +52047,7 @@ var errors = [
|
|
|
51780
52047
|
{
|
|
51781
52048
|
code: 6048,
|
|
51782
52049
|
name: "ExceedsMaxSolAmount",
|
|
51783
|
-
msg: "
|
|
52050
|
+
msg: "Required SOL amount exceeds user-set maximum"
|
|
51784
52051
|
},
|
|
51785
52052
|
{
|
|
51786
52053
|
code: 6049,
|
|
@@ -51790,12 +52057,12 @@ var errors = [
|
|
|
51790
52057
|
{
|
|
51791
52058
|
code: 6050,
|
|
51792
52059
|
name: "InsufficientRepayment",
|
|
51793
|
-
msg: "
|
|
52060
|
+
msg: "Insufficient proceeds to repay loan"
|
|
51794
52061
|
},
|
|
51795
52062
|
{
|
|
51796
52063
|
code: 6051,
|
|
51797
52064
|
name: "InsufficientBorrowingReserve",
|
|
51798
|
-
msg: "
|
|
52065
|
+
msg: "Insufficient borrowing reserve"
|
|
51799
52066
|
},
|
|
51800
52067
|
{
|
|
51801
52068
|
code: 6052,
|
|
@@ -51805,7 +52072,7 @@ var errors = [
|
|
|
51805
52072
|
{
|
|
51806
52073
|
code: 6053,
|
|
51807
52074
|
name: "InsufficientLiquidity",
|
|
51808
|
-
msg: "Insufficient liquidity
|
|
52075
|
+
msg: "Insufficient liquidity in current order"
|
|
51809
52076
|
},
|
|
51810
52077
|
{
|
|
51811
52078
|
code: 6054,
|
|
@@ -51815,12 +52082,12 @@ var errors = [
|
|
|
51815
52082
|
{
|
|
51816
52083
|
code: 6055,
|
|
51817
52084
|
name: "TokenAmountDifferenceOutOfRange",
|
|
51818
|
-
msg: "
|
|
52085
|
+
msg: "Token amount difference exceeds valid range in margin trade"
|
|
51819
52086
|
},
|
|
51820
52087
|
{
|
|
51821
52088
|
code: 6056,
|
|
51822
52089
|
name: "BorrowAmountMismatch",
|
|
51823
|
-
msg: "Borrow amount
|
|
52090
|
+
msg: "Borrow amount mismatch with locked tokens"
|
|
51824
52091
|
},
|
|
51825
52092
|
{
|
|
51826
52093
|
code: 6057,
|
|
@@ -51869,188 +52136,228 @@ var errors = [
|
|
|
51869
52136
|
},
|
|
51870
52137
|
{
|
|
51871
52138
|
code: 6066,
|
|
52139
|
+
name: "SolAmountTooLarge",
|
|
52140
|
+
msg: "SOL amount exceeds maximum limit (10000000 SOL per transaction)"
|
|
52141
|
+
},
|
|
52142
|
+
{
|
|
52143
|
+
code: 6067,
|
|
52144
|
+
name: "RemainingTokenAmountTooSmall",
|
|
52145
|
+
msg: "Remaining token amount below minimum trade requirement"
|
|
52146
|
+
},
|
|
52147
|
+
{
|
|
52148
|
+
code: 6068,
|
|
51872
52149
|
name: "TradeCooldownNotExpired",
|
|
51873
52150
|
msg: "Trade cooldown period not expired, please try again later"
|
|
51874
52151
|
},
|
|
51875
52152
|
{
|
|
51876
|
-
code:
|
|
52153
|
+
code: 6069,
|
|
51877
52154
|
name: "ExceedApprovalAmount",
|
|
51878
52155
|
msg: "Sell amount exceeds approved amount, please call approval function first"
|
|
51879
52156
|
},
|
|
51880
52157
|
{
|
|
51881
|
-
code:
|
|
52158
|
+
code: 6070,
|
|
51882
52159
|
name: "CooldownNotInitialized",
|
|
51883
52160
|
msg: "Sell trade requires calling approval or buy function first to initialize cooldown PDA"
|
|
51884
52161
|
},
|
|
51885
52162
|
{
|
|
51886
|
-
code:
|
|
52163
|
+
code: 6071,
|
|
51887
52164
|
name: "CannotCloseCooldownWithBalance",
|
|
51888
52165
|
msg: "Cannot close cooldown PDA with non-zero token balance"
|
|
51889
52166
|
},
|
|
51890
52167
|
{
|
|
51891
|
-
code:
|
|
51892
|
-
name: "RemainingTokenAmountTooSmall",
|
|
51893
|
-
msg: "Remaining token amount below minimum trade requirement"
|
|
51894
|
-
},
|
|
51895
|
-
{
|
|
51896
|
-
code: 6071,
|
|
52168
|
+
code: 6072,
|
|
51897
52169
|
name: "PriceCalculationError",
|
|
51898
52170
|
msg: "Price calculation error"
|
|
51899
52171
|
},
|
|
51900
52172
|
{
|
|
51901
|
-
code:
|
|
52173
|
+
code: 6073,
|
|
51902
52174
|
name: "InvalidFeeRecipientAccount",
|
|
51903
|
-
msg: "
|
|
52175
|
+
msg: "Invalid fee recipient account"
|
|
51904
52176
|
},
|
|
51905
52177
|
{
|
|
51906
|
-
code:
|
|
52178
|
+
code: 6074,
|
|
51907
52179
|
name: "InvalidOrderMintAddress",
|
|
51908
52180
|
msg: "Order mint address does not match curve account mint"
|
|
51909
52181
|
},
|
|
51910
52182
|
{
|
|
51911
|
-
code:
|
|
52183
|
+
code: 6075,
|
|
51912
52184
|
name: "InvalidFeePercentage",
|
|
51913
52185
|
msg: "Fee percentage must be between 0-100"
|
|
51914
52186
|
},
|
|
51915
52187
|
{
|
|
51916
|
-
code:
|
|
52188
|
+
code: 6076,
|
|
51917
52189
|
name: "InvalidFeeRate",
|
|
51918
52190
|
msg: "Fee rate exceeds maximum limit (10%)"
|
|
51919
52191
|
},
|
|
51920
52192
|
{
|
|
51921
|
-
code:
|
|
52193
|
+
code: 6077,
|
|
52194
|
+
name: "InvalidBorrowDuration",
|
|
52195
|
+
msg: "Borrow duration out of valid range (3-30 days)"
|
|
52196
|
+
},
|
|
52197
|
+
{
|
|
52198
|
+
code: 6078,
|
|
51922
52199
|
name: "InvalidStopLossPrice",
|
|
51923
52200
|
msg: "Stop loss price does not meet minimum interval requirement"
|
|
51924
52201
|
},
|
|
51925
52202
|
{
|
|
51926
|
-
code:
|
|
52203
|
+
code: 6079,
|
|
51927
52204
|
name: "NoProfitableFunds",
|
|
51928
52205
|
msg: "No profitable funds to transfer"
|
|
51929
52206
|
},
|
|
51930
52207
|
{
|
|
51931
|
-
code:
|
|
52208
|
+
code: 6080,
|
|
51932
52209
|
name: "InsufficientPoolFunds",
|
|
51933
52210
|
msg: "Insufficient pool funds"
|
|
51934
52211
|
},
|
|
51935
52212
|
{
|
|
51936
|
-
code:
|
|
52213
|
+
code: 6081,
|
|
51937
52214
|
name: "OrderBookManagerOverflow",
|
|
51938
52215
|
msg: "Math operation overflow"
|
|
51939
52216
|
},
|
|
51940
52217
|
{
|
|
51941
|
-
code:
|
|
52218
|
+
code: 6082,
|
|
51942
52219
|
name: "OrderBookManagerInvalidSlotIndex",
|
|
51943
52220
|
msg: "Invalid slot index"
|
|
51944
52221
|
},
|
|
51945
52222
|
{
|
|
51946
|
-
code:
|
|
52223
|
+
code: 6083,
|
|
51947
52224
|
name: "OrderBookManagerInvalidAccountData",
|
|
51948
52225
|
msg: "Invalid account data"
|
|
51949
52226
|
},
|
|
51950
52227
|
{
|
|
51951
|
-
code:
|
|
52228
|
+
code: 6084,
|
|
51952
52229
|
name: "OrderBookManagerExceedsMaxCapacity",
|
|
51953
52230
|
msg: "New capacity exceeds maximum limit"
|
|
51954
52231
|
},
|
|
51955
52232
|
{
|
|
51956
|
-
code:
|
|
52233
|
+
code: 6085,
|
|
51957
52234
|
name: "OrderBookManagerExceedsAccountSizeLimit",
|
|
51958
52235
|
msg: "Account size exceeds 10MB limit"
|
|
51959
52236
|
},
|
|
51960
52237
|
{
|
|
51961
|
-
code:
|
|
52238
|
+
code: 6086,
|
|
51962
52239
|
name: "OrderBookManagerOrderIdMismatch",
|
|
51963
52240
|
msg: "Order ID mismatch"
|
|
51964
52241
|
},
|
|
51965
52242
|
{
|
|
51966
|
-
code:
|
|
52243
|
+
code: 6087,
|
|
51967
52244
|
name: "OrderBookManagerEmptyOrderBook",
|
|
51968
52245
|
msg: "Order book is empty"
|
|
51969
52246
|
},
|
|
51970
52247
|
{
|
|
51971
|
-
code:
|
|
52248
|
+
code: 6088,
|
|
51972
52249
|
name: "OrderBookManagerAccountNotWritable",
|
|
51973
52250
|
msg: "Account is not writable"
|
|
51974
52251
|
},
|
|
51975
52252
|
{
|
|
51976
|
-
code:
|
|
52253
|
+
code: 6089,
|
|
51977
52254
|
name: "OrderBookManagerNotRentExempt",
|
|
51978
52255
|
msg: "Account not rent-exempt"
|
|
51979
52256
|
},
|
|
51980
52257
|
{
|
|
51981
|
-
code:
|
|
52258
|
+
code: 6090,
|
|
51982
52259
|
name: "OrderBookManagerInvalidRentBalance",
|
|
51983
52260
|
msg: "Invalid rent balance"
|
|
51984
52261
|
},
|
|
51985
52262
|
{
|
|
51986
|
-
code:
|
|
52263
|
+
code: 6091,
|
|
51987
52264
|
name: "OrderBookManagerInsufficientFunds",
|
|
51988
52265
|
msg: "Insufficient funds"
|
|
51989
52266
|
},
|
|
51990
52267
|
{
|
|
51991
|
-
code:
|
|
52268
|
+
code: 6092,
|
|
51992
52269
|
name: "OrderBookManagerInvalidAccountOwner",
|
|
51993
|
-
msg: "
|
|
52270
|
+
msg: "OrderBook account owner mismatch"
|
|
51994
52271
|
},
|
|
51995
52272
|
{
|
|
51996
|
-
code:
|
|
52273
|
+
code: 6093,
|
|
51997
52274
|
name: "OrderBookManagerDataOutOfBounds",
|
|
51998
52275
|
msg: "Data access out of bounds"
|
|
51999
52276
|
},
|
|
52000
52277
|
{
|
|
52001
|
-
code:
|
|
52278
|
+
code: 6094,
|
|
52002
52279
|
name: "NoValidInsertPosition",
|
|
52003
52280
|
msg: "Cannot find valid insert position, all candidates failed due to price range overlap"
|
|
52004
52281
|
},
|
|
52005
52282
|
{
|
|
52006
|
-
code:
|
|
52283
|
+
code: 6095,
|
|
52007
52284
|
name: "EmptyCloseInsertIndices",
|
|
52008
52285
|
msg: "close_insert_indices array cannot be empty"
|
|
52009
52286
|
},
|
|
52010
52287
|
{
|
|
52011
|
-
code:
|
|
52288
|
+
code: 6096,
|
|
52012
52289
|
name: "TooManyCloseInsertIndices",
|
|
52013
52290
|
msg: "close_insert_indices array cannot exceed 20 elements"
|
|
52014
52291
|
},
|
|
52015
52292
|
{
|
|
52016
|
-
code:
|
|
52293
|
+
code: 6097,
|
|
52017
52294
|
name: "CloseOrderNotFound",
|
|
52018
52295
|
msg: "Specified close order not found"
|
|
52019
52296
|
},
|
|
52020
52297
|
{
|
|
52021
|
-
code:
|
|
52298
|
+
code: 6098,
|
|
52022
52299
|
name: "LinkedListDeleteCountMismatch",
|
|
52023
52300
|
msg: "Linked list delete count mismatch: count inconsistent before/after deletion"
|
|
52024
52301
|
},
|
|
52025
52302
|
{
|
|
52026
|
-
code:
|
|
52303
|
+
code: 6099,
|
|
52027
52304
|
name: "NameTooLong",
|
|
52028
52305
|
msg: "Token name too long, max 32 bytes"
|
|
52029
52306
|
},
|
|
52030
52307
|
{
|
|
52031
|
-
code:
|
|
52308
|
+
code: 6100,
|
|
52032
52309
|
name: "NameEmpty",
|
|
52033
52310
|
msg: "Token name cannot be empty"
|
|
52034
52311
|
},
|
|
52035
52312
|
{
|
|
52036
|
-
code:
|
|
52313
|
+
code: 6101,
|
|
52037
52314
|
name: "SymbolTooLong",
|
|
52038
52315
|
msg: "Token symbol too long, max 10 bytes"
|
|
52039
52316
|
},
|
|
52040
52317
|
{
|
|
52041
|
-
code:
|
|
52318
|
+
code: 6102,
|
|
52042
52319
|
name: "SymbolEmpty",
|
|
52043
52320
|
msg: "Token symbol cannot be empty"
|
|
52044
52321
|
},
|
|
52045
52322
|
{
|
|
52046
|
-
code:
|
|
52323
|
+
code: 6103,
|
|
52047
52324
|
name: "UriTooLong",
|
|
52048
52325
|
msg: "URI too long, max 200 bytes"
|
|
52049
52326
|
},
|
|
52050
52327
|
{
|
|
52051
|
-
code:
|
|
52328
|
+
code: 6104,
|
|
52052
52329
|
name: "UriEmpty",
|
|
52053
52330
|
msg: "URI cannot be empty"
|
|
52331
|
+
},
|
|
52332
|
+
{
|
|
52333
|
+
code: 6105,
|
|
52334
|
+
name: "IncompleteAdvancedPoolParams",
|
|
52335
|
+
msg: "高级版池子参数不完整:custom_lp_sol, custom_lp_token, custom_borrow_ratio, custom_borrow_duration 必须同时提供"
|
|
52336
|
+
},
|
|
52337
|
+
{
|
|
52338
|
+
code: 6106,
|
|
52339
|
+
name: "InvalidInitialVirtualSol",
|
|
52340
|
+
msg: "初始虚拟SOL超出有效范围(10 SOL ~ 1,000 SOL)"
|
|
52341
|
+
},
|
|
52342
|
+
{
|
|
52343
|
+
code: 6107,
|
|
52344
|
+
name: "InvalidInitialVirtualToken",
|
|
52345
|
+
msg: "初始虚拟Token超出有效范围(1亿 ~ 100亿 Token)"
|
|
52346
|
+
},
|
|
52347
|
+
{
|
|
52348
|
+
code: 6108,
|
|
52349
|
+
name: "InvalidBorrowPoolRatio",
|
|
52350
|
+
msg: "借贷池占比超出有效范围(5% ~ 30%)"
|
|
52351
|
+
},
|
|
52352
|
+
{
|
|
52353
|
+
code: 6109,
|
|
52354
|
+
name: "BorrowTokenCalculationOverflow",
|
|
52355
|
+
msg: "借贷池代币数量计算溢出"
|
|
52356
|
+
},
|
|
52357
|
+
{
|
|
52358
|
+
code: 6110,
|
|
52359
|
+
name: "BorrowTokenAmountZero",
|
|
52360
|
+
msg: "借贷池代币数量不能为0"
|
|
52054
52361
|
}
|
|
52055
52362
|
];
|
|
52056
52363
|
var types = [
|
|
@@ -52162,6 +52469,42 @@ var types = [
|
|
|
52162
52469
|
{
|
|
52163
52470
|
name: "bump",
|
|
52164
52471
|
type: "u8"
|
|
52472
|
+
},
|
|
52473
|
+
{
|
|
52474
|
+
name: "initial_virtual_sol",
|
|
52475
|
+
docs: [
|
|
52476
|
+
"初始虚拟SOL储备量 (lamports, 9位精度)",
|
|
52477
|
+
"用于计算 k 值和价格曲线",
|
|
52478
|
+
"默认值: 30_000_000_000 (30 SOL)"
|
|
52479
|
+
],
|
|
52480
|
+
type: "u64"
|
|
52481
|
+
},
|
|
52482
|
+
{
|
|
52483
|
+
name: "initial_virtual_token",
|
|
52484
|
+
docs: [
|
|
52485
|
+
"初始虚拟Token储备量 (最小单位, 9位精度)",
|
|
52486
|
+
"用于计算 k 值和价格曲线",
|
|
52487
|
+
"默认值: 1_073_000_000_000_000_000 (10.73亿 Token)"
|
|
52488
|
+
],
|
|
52489
|
+
type: "u64"
|
|
52490
|
+
},
|
|
52491
|
+
{
|
|
52492
|
+
name: "pool_type",
|
|
52493
|
+
docs: [
|
|
52494
|
+
"池子类型",
|
|
52495
|
+
"0 = 普通版(使用默认参数,支持手续费减半)",
|
|
52496
|
+
"1 = 高级版(自定义参数,手续费永不减半)"
|
|
52497
|
+
],
|
|
52498
|
+
type: "u8"
|
|
52499
|
+
},
|
|
52500
|
+
{
|
|
52501
|
+
name: "borrow_pool_ratio",
|
|
52502
|
+
docs: [
|
|
52503
|
+
"借贷池代币占比(仅记录,用于信息展示)",
|
|
52504
|
+
"实际数值范围:5-30(代表 5%-30%)",
|
|
52505
|
+
"普通版固定为 20"
|
|
52506
|
+
],
|
|
52507
|
+
type: "u8"
|
|
52165
52508
|
}
|
|
52166
52509
|
]
|
|
52167
52510
|
}
|
|
@@ -52664,6 +53007,22 @@ var types = [
|
|
|
52664
53007
|
{
|
|
52665
53008
|
name: "latest_price",
|
|
52666
53009
|
type: "u128"
|
|
53010
|
+
},
|
|
53011
|
+
{
|
|
53012
|
+
name: "initial_virtual_sol",
|
|
53013
|
+
type: "u64"
|
|
53014
|
+
},
|
|
53015
|
+
{
|
|
53016
|
+
name: "initial_virtual_token",
|
|
53017
|
+
type: "u64"
|
|
53018
|
+
},
|
|
53019
|
+
{
|
|
53020
|
+
name: "pool_type",
|
|
53021
|
+
type: "u8"
|
|
53022
|
+
},
|
|
53023
|
+
{
|
|
53024
|
+
name: "borrow_pool_ratio",
|
|
53025
|
+
type: "u8"
|
|
52667
53026
|
}
|
|
52668
53027
|
]
|
|
52669
53028
|
}
|