@pyron-finance/pyron-client 2.1.0 → 2.2.1

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_common = require('./common-DPdmGMEV.cjs');
1
+ const require_common = require('./common-C1TNbOrw.cjs');
2
2
  const __coral_xyz_anchor = require_common.__toESM(require("@coral-xyz/anchor"));
3
3
  const __solana_spl_token = require_common.__toESM(require("@solana/spl-token"));
4
4
  const __solana_web3_js = require_common.__toESM(require("@solana/web3.js"));
@@ -229,6 +229,7 @@ var FogoMetadataFetcher = class {
229
229
 
230
230
  //#endregion
231
231
  //#region src/config.ts
232
+ require_common.init_constants();
232
233
  function getConfig({ environment = "production", overrides } = {}) {
233
234
  return {
234
235
  environment,
@@ -9880,6 +9881,7 @@ const LENDR_IDL = lendr_0_1_6_default;
9880
9881
 
9881
9882
  //#endregion
9882
9883
  //#region src/errors.ts
9884
+ require_common.init_constants();
9883
9885
  let ProcessTransactionErrorType = /* @__PURE__ */ function(ProcessTransactionErrorType$1) {
9884
9886
  ProcessTransactionErrorType$1[ProcessTransactionErrorType$1["TransactionBuildingError"] = 0] = "TransactionBuildingError";
9885
9887
  ProcessTransactionErrorType$1[ProcessTransactionErrorType$1["TransactionSendingError"] = 1] = "TransactionSendingError";
@@ -10485,6 +10487,7 @@ let AccountType = /* @__PURE__ */ function(AccountType$2) {
10485
10487
 
10486
10488
  //#endregion
10487
10489
  //#region src/services/bank/utils/deserialize.utils.ts
10490
+ require_common.init_constants();
10488
10491
  function decodeBankRaw(encoded, idl) {
10489
10492
  const coder = new __coral_xyz_anchor.BorshCoder(idl);
10490
10493
  return coder.accounts.decode(AccountType.Bank, encoded);
@@ -11150,554 +11153,576 @@ const getStakeAccount = (data) => {
11150
11153
 
11151
11154
  //#endregion
11152
11155
  //#region src/vendor/single-spl-pool/index.ts
11153
- var SinglePoolInstructionType = /* @__PURE__ */ function(SinglePoolInstructionType$1) {
11154
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["InitializePool"] = 0] = "InitializePool";
11155
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["ReplenishPool"] = 1] = "ReplenishPool";
11156
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["DepositStake"] = 2] = "DepositStake";
11157
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["WithdrawStake"] = 3] = "WithdrawStake";
11158
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["CreateTokenMetadata"] = 4] = "CreateTokenMetadata";
11159
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["UpdateTokenMetadata"] = 5] = "UpdateTokenMetadata";
11160
- SinglePoolInstructionType$1[SinglePoolInstructionType$1["InitializeOnRamp"] = 6] = "InitializeOnRamp";
11161
- return SinglePoolInstructionType$1;
11162
- }(SinglePoolInstructionType || {});
11163
- const SinglePoolInstruction = {
11164
- initializePool: (voteAccount) => {
11165
- const pool = findPoolAddress(voteAccount);
11166
- const stake = findPoolStakeAddress(pool);
11167
- const mint = findPoolMintAddress(pool);
11168
- const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11169
- const mintAuthority = findPoolMintAuthorityAddress(pool);
11170
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11171
- {
11172
- pubkey: voteAccount,
11173
- isSigner: false,
11174
- isWritable: false
11175
- },
11176
- {
11177
- pubkey: pool,
11178
- isSigner: false,
11179
- isWritable: true
11180
- },
11181
- {
11182
- pubkey: stake,
11183
- isSigner: false,
11184
- isWritable: true
11185
- },
11186
- {
11187
- pubkey: mint,
11188
- isSigner: false,
11189
- isWritable: true
11190
- },
11191
- {
11192
- pubkey: stakeAuthority,
11193
- isSigner: false,
11194
- isWritable: false
11195
- },
11196
- {
11197
- pubkey: mintAuthority,
11198
- isSigner: false,
11199
- isWritable: false
11200
- },
11201
- {
11202
- pubkey: require_common.SYSVAR_RENT_ID,
11203
- isSigner: false,
11204
- isWritable: false
11205
- },
11206
- {
11207
- pubkey: require_common.SYSVAR_CLOCK_ID,
11208
- isSigner: false,
11209
- isWritable: false
11210
- },
11211
- {
11212
- pubkey: require_common.SYSVAR_STAKE_HISTORY_ID,
11213
- isSigner: false,
11214
- isWritable: false
11215
- },
11216
- {
11217
- pubkey: __solana_web3_js.STAKE_CONFIG_ID,
11218
- isSigner: false,
11219
- isWritable: false
11220
- },
11221
- {
11222
- pubkey: require_common.SYSTEM_PROGRAM_ID,
11223
- isSigner: false,
11224
- isWritable: false
11225
- },
11226
- {
11227
- pubkey: __solana_spl_token.TOKEN_PROGRAM_ID,
11228
- isSigner: false,
11229
- isWritable: false
11230
- },
11231
- {
11232
- pubkey: require_common.STAKE_PROGRAM_ID,
11233
- isSigner: false,
11234
- isWritable: false
11235
- }
11236
- ], Buffer.from([SinglePoolInstructionType.InitializePool]));
11237
- },
11238
- initializeOnRamp: (pool) => {
11239
- const onRamp = findPoolOnRampAddress(pool);
11240
- const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11241
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11242
- {
11243
- pubkey: pool,
11244
- isSigner: false,
11245
- isWritable: false
11246
- },
11247
- {
11248
- pubkey: onRamp,
11249
- isSigner: false,
11250
- isWritable: true
11251
- },
11252
- {
11253
- pubkey: stakeAuthority,
11254
- isSigner: false,
11255
- isWritable: false
11256
- },
11257
- {
11258
- pubkey: require_common.SYSVAR_RENT_ID,
11259
- isSigner: false,
11260
- isWritable: false
11261
- },
11262
- {
11263
- pubkey: require_common.SYSTEM_PROGRAM_ID,
11264
- isSigner: false,
11265
- isWritable: false
11266
- },
11267
- {
11268
- pubkey: require_common.STAKE_PROGRAM_ID,
11269
- isSigner: false,
11270
- isWritable: false
11271
- }
11272
- ], Buffer.from([SinglePoolInstructionType.InitializeOnRamp]));
11273
- },
11274
- depositStake: async (pool, userStakeAccount, userTokenAccount, userLamportAccount) => {
11275
- const stake = findPoolStakeAddress(pool);
11276
- const mint = findPoolMintAddress(pool);
11277
- const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11278
- const mintAuthority = findPoolMintAuthorityAddress(pool);
11279
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11280
- {
11281
- pubkey: pool,
11282
- isSigner: false,
11283
- isWritable: false
11284
- },
11285
- {
11286
- pubkey: stake,
11287
- isSigner: false,
11288
- isWritable: true
11289
- },
11290
- {
11291
- pubkey: mint,
11292
- isSigner: false,
11293
- isWritable: true
11294
- },
11295
- {
11296
- pubkey: stakeAuthority,
11297
- isSigner: false,
11298
- isWritable: false
11299
- },
11300
- {
11301
- pubkey: mintAuthority,
11302
- isSigner: false,
11303
- isWritable: false
11304
- },
11305
- {
11306
- pubkey: userStakeAccount,
11307
- isSigner: false,
11308
- isWritable: true
11309
- },
11310
- {
11311
- pubkey: userTokenAccount,
11312
- isSigner: false,
11313
- isWritable: true
11314
- },
11315
- {
11316
- pubkey: userLamportAccount,
11317
- isSigner: false,
11318
- isWritable: true
11319
- },
11320
- {
11321
- pubkey: require_common.SYSVAR_CLOCK_ID,
11322
- isSigner: false,
11323
- isWritable: false
11324
- },
11325
- {
11326
- pubkey: require_common.SYSVAR_STAKE_HISTORY_ID,
11327
- isSigner: false,
11328
- isWritable: false
11329
- },
11330
- {
11331
- pubkey: __solana_spl_token.TOKEN_PROGRAM_ID,
11332
- isSigner: false,
11333
- isWritable: false
11334
- },
11335
- {
11336
- pubkey: require_common.STAKE_PROGRAM_ID,
11337
- isSigner: false,
11338
- isWritable: false
11156
+ var single_spl_pool_exports = {};
11157
+ require_common.__export(single_spl_pool_exports, {
11158
+ SinglePoolInstruction: () => SinglePoolInstruction,
11159
+ createAccountIx: () => createAccountIx,
11160
+ createPoolOnrampIx: () => createPoolOnrampIx,
11161
+ findMplMetadataAddress: () => findMplMetadataAddress,
11162
+ findPoolAddress: () => findPoolAddress,
11163
+ findPoolMintAddress: () => findPoolMintAddress,
11164
+ findPoolMintAddressByVoteAccount: () => findPoolMintAddressByVoteAccount,
11165
+ findPoolMintAuthorityAddress: () => findPoolMintAuthorityAddress,
11166
+ findPoolMplAuthorityAddress: () => findPoolMplAuthorityAddress,
11167
+ findPoolOnRampAddress: () => findPoolOnRampAddress,
11168
+ findPoolStakeAddress: () => findPoolStakeAddress,
11169
+ findPoolStakeAuthorityAddress: () => findPoolStakeAuthorityAddress,
11170
+ initializeStakedPoolIxs: () => initializeStakedPoolIxs,
11171
+ initializeStakedPoolTx: () => initializeStakedPoolTx,
11172
+ replenishPoolIx: () => replenishPoolIx
11173
+ });
11174
+ async function initializeStakedPoolTx(connection, payer, voteAccountAddress) {
11175
+ const instructions$3 = await initializeStakedPoolIxs(connection, payer, voteAccountAddress);
11176
+ const tx = new __solana_web3_js.Transaction().add(...instructions$3);
11177
+ return tx;
11178
+ }
11179
+ async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
11180
+ const poolAddress = findPoolAddress(voteAccountAddress);
11181
+ const stakeAddress = findPoolStakeAddress(poolAddress);
11182
+ const mintAddress = findPoolMintAddress(poolAddress);
11183
+ const onRampAddress = findPoolOnRampAddress(poolAddress);
11184
+ const [poolRent, stakeRent, mintRent, minimumDelegationObj] = await Promise.all([
11185
+ connection.getMinimumBalanceForRentExemption(Number(SINGLE_POOL_ACCOUNT_SIZE), "confirmed"),
11186
+ connection.getMinimumBalanceForRentExemption(Number(STAKE_ACCOUNT_SIZE), "confirmed"),
11187
+ connection.getMinimumBalanceForRentExemption(Number(MINT_SIZE), "confirmed"),
11188
+ connection.getStakeMinimumDelegation()
11189
+ ]);
11190
+ const minimumDelegation = minimumDelegationObj.value;
11191
+ const instructions$3 = [];
11192
+ instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11193
+ fromPubkey: payer,
11194
+ toPubkey: poolAddress,
11195
+ lamports: poolRent
11196
+ }));
11197
+ instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11198
+ fromPubkey: payer,
11199
+ toPubkey: stakeAddress,
11200
+ lamports: stakeRent + minimumDelegation + __solana_web3_js.LAMPORTS_PER_SOL * 1
11201
+ }));
11202
+ instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11203
+ fromPubkey: payer,
11204
+ toPubkey: onRampAddress,
11205
+ lamports: stakeRent
11206
+ }));
11207
+ instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11208
+ fromPubkey: payer,
11209
+ toPubkey: mintAddress,
11210
+ lamports: mintRent
11211
+ }));
11212
+ instructions$3.push(SinglePoolInstruction.initializePool(voteAccountAddress));
11213
+ instructions$3.push(SinglePoolInstruction.initializeOnRamp(poolAddress));
11214
+ instructions$3.push(await SinglePoolInstruction.createTokenMetadata(poolAddress, payer));
11215
+ return instructions$3;
11216
+ }
11217
+ var SinglePoolInstructionType, SinglePoolInstruction, createTransactionInstruction, findPda, findPoolMintAddressByVoteAccount, findPoolAddress, findPoolMintAddress, findPoolStakeAddress, findPoolStakeAuthorityAddress, findPoolMintAuthorityAddress, findPoolMplAuthorityAddress, findPoolOnRampAddress, findMplMetadataAddress, SINGLE_POOL_ACCOUNT_SIZE, STAKE_ACCOUNT_SIZE, MINT_SIZE, createAccountIx, createPoolOnrampIx, replenishPoolIx;
11218
+ var init_single_spl_pool = require_common.__esm({ "src/vendor/single-spl-pool/index.ts"() {
11219
+ require_common.init_constants();
11220
+ SinglePoolInstructionType = /* @__PURE__ */ function(SinglePoolInstructionType$1) {
11221
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["InitializePool"] = 0] = "InitializePool";
11222
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["ReplenishPool"] = 1] = "ReplenishPool";
11223
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["DepositStake"] = 2] = "DepositStake";
11224
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["WithdrawStake"] = 3] = "WithdrawStake";
11225
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["CreateTokenMetadata"] = 4] = "CreateTokenMetadata";
11226
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["UpdateTokenMetadata"] = 5] = "UpdateTokenMetadata";
11227
+ SinglePoolInstructionType$1[SinglePoolInstructionType$1["InitializeOnRamp"] = 6] = "InitializeOnRamp";
11228
+ return SinglePoolInstructionType$1;
11229
+ }(SinglePoolInstructionType || {});
11230
+ SinglePoolInstruction = {
11231
+ initializePool: (voteAccount) => {
11232
+ const pool = findPoolAddress(voteAccount);
11233
+ const stake = findPoolStakeAddress(pool);
11234
+ const mint = findPoolMintAddress(pool);
11235
+ const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11236
+ const mintAuthority = findPoolMintAuthorityAddress(pool);
11237
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11238
+ {
11239
+ pubkey: voteAccount,
11240
+ isSigner: false,
11241
+ isWritable: false
11242
+ },
11243
+ {
11244
+ pubkey: pool,
11245
+ isSigner: false,
11246
+ isWritable: true
11247
+ },
11248
+ {
11249
+ pubkey: stake,
11250
+ isSigner: false,
11251
+ isWritable: true
11252
+ },
11253
+ {
11254
+ pubkey: mint,
11255
+ isSigner: false,
11256
+ isWritable: true
11257
+ },
11258
+ {
11259
+ pubkey: stakeAuthority,
11260
+ isSigner: false,
11261
+ isWritable: false
11262
+ },
11263
+ {
11264
+ pubkey: mintAuthority,
11265
+ isSigner: false,
11266
+ isWritable: false
11267
+ },
11268
+ {
11269
+ pubkey: require_common.SYSVAR_RENT_ID,
11270
+ isSigner: false,
11271
+ isWritable: false
11272
+ },
11273
+ {
11274
+ pubkey: require_common.SYSVAR_CLOCK_ID,
11275
+ isSigner: false,
11276
+ isWritable: false
11277
+ },
11278
+ {
11279
+ pubkey: require_common.SYSVAR_STAKE_HISTORY_ID,
11280
+ isSigner: false,
11281
+ isWritable: false
11282
+ },
11283
+ {
11284
+ pubkey: __solana_web3_js.STAKE_CONFIG_ID,
11285
+ isSigner: false,
11286
+ isWritable: false
11287
+ },
11288
+ {
11289
+ pubkey: require_common.SYSTEM_PROGRAM_ID,
11290
+ isSigner: false,
11291
+ isWritable: false
11292
+ },
11293
+ {
11294
+ pubkey: __solana_spl_token.TOKEN_PROGRAM_ID,
11295
+ isSigner: false,
11296
+ isWritable: false
11297
+ },
11298
+ {
11299
+ pubkey: require_common.STAKE_PROGRAM_ID,
11300
+ isSigner: false,
11301
+ isWritable: false
11302
+ }
11303
+ ], Buffer.from([SinglePoolInstructionType.InitializePool]));
11304
+ },
11305
+ initializeOnRamp: (pool) => {
11306
+ const onRamp = findPoolOnRampAddress(pool);
11307
+ const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11308
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11309
+ {
11310
+ pubkey: pool,
11311
+ isSigner: false,
11312
+ isWritable: false
11313
+ },
11314
+ {
11315
+ pubkey: onRamp,
11316
+ isSigner: false,
11317
+ isWritable: true
11318
+ },
11319
+ {
11320
+ pubkey: stakeAuthority,
11321
+ isSigner: false,
11322
+ isWritable: false
11323
+ },
11324
+ {
11325
+ pubkey: require_common.SYSVAR_RENT_ID,
11326
+ isSigner: false,
11327
+ isWritable: false
11328
+ },
11329
+ {
11330
+ pubkey: require_common.SYSTEM_PROGRAM_ID,
11331
+ isSigner: false,
11332
+ isWritable: false
11333
+ },
11334
+ {
11335
+ pubkey: require_common.STAKE_PROGRAM_ID,
11336
+ isSigner: false,
11337
+ isWritable: false
11338
+ }
11339
+ ], Buffer.from([SinglePoolInstructionType.InitializeOnRamp]));
11340
+ },
11341
+ depositStake: async (pool, userStakeAccount, userTokenAccount, userLamportAccount) => {
11342
+ const stake = findPoolStakeAddress(pool);
11343
+ const mint = findPoolMintAddress(pool);
11344
+ const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11345
+ const mintAuthority = findPoolMintAuthorityAddress(pool);
11346
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11347
+ {
11348
+ pubkey: pool,
11349
+ isSigner: false,
11350
+ isWritable: false
11351
+ },
11352
+ {
11353
+ pubkey: stake,
11354
+ isSigner: false,
11355
+ isWritable: true
11356
+ },
11357
+ {
11358
+ pubkey: mint,
11359
+ isSigner: false,
11360
+ isWritable: true
11361
+ },
11362
+ {
11363
+ pubkey: stakeAuthority,
11364
+ isSigner: false,
11365
+ isWritable: false
11366
+ },
11367
+ {
11368
+ pubkey: mintAuthority,
11369
+ isSigner: false,
11370
+ isWritable: false
11371
+ },
11372
+ {
11373
+ pubkey: userStakeAccount,
11374
+ isSigner: false,
11375
+ isWritable: true
11376
+ },
11377
+ {
11378
+ pubkey: userTokenAccount,
11379
+ isSigner: false,
11380
+ isWritable: true
11381
+ },
11382
+ {
11383
+ pubkey: userLamportAccount,
11384
+ isSigner: false,
11385
+ isWritable: true
11386
+ },
11387
+ {
11388
+ pubkey: require_common.SYSVAR_CLOCK_ID,
11389
+ isSigner: false,
11390
+ isWritable: false
11391
+ },
11392
+ {
11393
+ pubkey: require_common.SYSVAR_STAKE_HISTORY_ID,
11394
+ isSigner: false,
11395
+ isWritable: false
11396
+ },
11397
+ {
11398
+ pubkey: __solana_spl_token.TOKEN_PROGRAM_ID,
11399
+ isSigner: false,
11400
+ isWritable: false
11401
+ },
11402
+ {
11403
+ pubkey: require_common.STAKE_PROGRAM_ID,
11404
+ isSigner: false,
11405
+ isWritable: false
11406
+ }
11407
+ ], Buffer.from([SinglePoolInstructionType.DepositStake]));
11408
+ },
11409
+ withdrawStake: async (pool, userStakeAccount, userStakeAuthority, userTokenAccount, tokenAmount) => {
11410
+ const stake = findPoolStakeAddress(pool);
11411
+ const mint = findPoolMintAddress(pool);
11412
+ const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11413
+ const mintAuthority = findPoolMintAuthorityAddress(pool);
11414
+ const rawAmount = BigInt(tokenAmount.multipliedBy(1e9).toString());
11415
+ const data = Buffer.concat([
11416
+ Buffer.from([SinglePoolInstructionType.WithdrawStake]),
11417
+ userStakeAuthority.toBuffer(),
11418
+ Buffer.from(new bn_js.BN(rawAmount.toString()).toArray("le", 8))
11419
+ ]);
11420
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11421
+ {
11422
+ pubkey: pool,
11423
+ isSigner: false,
11424
+ isWritable: false
11425
+ },
11426
+ {
11427
+ pubkey: stake,
11428
+ isSigner: false,
11429
+ isWritable: true
11430
+ },
11431
+ {
11432
+ pubkey: mint,
11433
+ isSigner: false,
11434
+ isWritable: true
11435
+ },
11436
+ {
11437
+ pubkey: stakeAuthority,
11438
+ isSigner: false,
11439
+ isWritable: false
11440
+ },
11441
+ {
11442
+ pubkey: mintAuthority,
11443
+ isSigner: false,
11444
+ isWritable: false
11445
+ },
11446
+ {
11447
+ pubkey: userStakeAccount,
11448
+ isSigner: false,
11449
+ isWritable: true
11450
+ },
11451
+ {
11452
+ pubkey: userTokenAccount,
11453
+ isSigner: false,
11454
+ isWritable: true
11455
+ },
11456
+ {
11457
+ pubkey: require_common.SYSVAR_CLOCK_ID,
11458
+ isSigner: false,
11459
+ isWritable: false
11460
+ },
11461
+ {
11462
+ pubkey: __solana_spl_token.TOKEN_PROGRAM_ID,
11463
+ isSigner: false,
11464
+ isWritable: false
11465
+ },
11466
+ {
11467
+ pubkey: require_common.STAKE_PROGRAM_ID,
11468
+ isSigner: false,
11469
+ isWritable: false
11470
+ }
11471
+ ], data);
11472
+ },
11473
+ createTokenMetadata: async (pool, payer) => {
11474
+ const mint = findPoolMintAddress(pool);
11475
+ const [mintAuthority, mplAuthority, mplMetadata] = await Promise.all([
11476
+ findPoolMintAuthorityAddress(pool),
11477
+ findPoolMplAuthorityAddress(pool),
11478
+ findMplMetadataAddress(mint)
11479
+ ]);
11480
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11481
+ {
11482
+ pubkey: pool,
11483
+ isSigner: false,
11484
+ isWritable: false
11485
+ },
11486
+ {
11487
+ pubkey: mint,
11488
+ isSigner: false,
11489
+ isWritable: false
11490
+ },
11491
+ {
11492
+ pubkey: mintAuthority,
11493
+ isSigner: false,
11494
+ isWritable: false
11495
+ },
11496
+ {
11497
+ pubkey: mplAuthority,
11498
+ isSigner: false,
11499
+ isWritable: false
11500
+ },
11501
+ {
11502
+ pubkey: payer,
11503
+ isSigner: true,
11504
+ isWritable: true
11505
+ },
11506
+ {
11507
+ pubkey: mplMetadata,
11508
+ isSigner: false,
11509
+ isWritable: true
11510
+ },
11511
+ {
11512
+ pubkey: require_common.MPL_METADATA_PROGRAM_ID,
11513
+ isSigner: false,
11514
+ isWritable: false
11515
+ },
11516
+ {
11517
+ pubkey: require_common.SYSTEM_PROGRAM_ID,
11518
+ isSigner: false,
11519
+ isWritable: false
11520
+ }
11521
+ ], Buffer.from([SinglePoolInstructionType.CreateTokenMetadata]));
11522
+ },
11523
+ updateTokenMetadata: async (voteAccount, authorizedWithdrawer, tokenName, tokenSymbol, tokenUri = "") => {
11524
+ if (tokenName.length > 32) {
11525
+ throw new Error("maximum token name length is 32 characters");
11339
11526
  }
11340
- ], Buffer.from([SinglePoolInstructionType.DepositStake]));
11341
- },
11342
- withdrawStake: async (pool, userStakeAccount, userStakeAuthority, userTokenAccount, tokenAmount) => {
11343
- const stake = findPoolStakeAddress(pool);
11344
- const mint = findPoolMintAddress(pool);
11345
- const stakeAuthority = findPoolStakeAuthorityAddress(pool);
11346
- const mintAuthority = findPoolMintAuthorityAddress(pool);
11347
- const rawAmount = BigInt(tokenAmount.multipliedBy(1e9).toString());
11527
+ if (tokenSymbol.length > 10) {
11528
+ throw new Error("maximum token symbol length is 10 characters");
11529
+ }
11530
+ if (tokenUri.length > 200) {
11531
+ throw new Error("maximum token uri length is 200 characters");
11532
+ }
11533
+ const pool = findPoolAddress(voteAccount);
11534
+ const [mint, mplAuthority] = await Promise.all([findPoolMintAddress(pool), findPoolMplAuthorityAddress(pool)]);
11535
+ const mplMetadata = await findMplMetadataAddress(mint);
11536
+ const data = Buffer.concat([
11537
+ Buffer.from([SinglePoolInstructionType.UpdateTokenMetadata]),
11538
+ Buffer.from(new Uint32Array([tokenName.length]).buffer),
11539
+ Buffer.from(tokenName),
11540
+ Buffer.from(new Uint32Array([tokenSymbol.length]).buffer),
11541
+ Buffer.from(tokenSymbol),
11542
+ Buffer.from(new Uint32Array([tokenUri.length]).buffer),
11543
+ Buffer.from(tokenUri)
11544
+ ]);
11545
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11546
+ {
11547
+ pubkey: voteAccount,
11548
+ isSigner: false,
11549
+ isWritable: false
11550
+ },
11551
+ {
11552
+ pubkey: pool,
11553
+ isSigner: false,
11554
+ isWritable: false
11555
+ },
11556
+ {
11557
+ pubkey: mplAuthority,
11558
+ isSigner: false,
11559
+ isWritable: false
11560
+ },
11561
+ {
11562
+ pubkey: authorizedWithdrawer,
11563
+ isSigner: true,
11564
+ isWritable: false
11565
+ },
11566
+ {
11567
+ pubkey: mplMetadata,
11568
+ isSigner: false,
11569
+ isWritable: true
11570
+ },
11571
+ {
11572
+ pubkey: require_common.MPL_METADATA_PROGRAM_ID,
11573
+ isSigner: false,
11574
+ isWritable: false
11575
+ }
11576
+ ], data);
11577
+ }
11578
+ };
11579
+ createTransactionInstruction = (programId, keys, data) => {
11580
+ return {
11581
+ programId,
11582
+ keys,
11583
+ data
11584
+ };
11585
+ };
11586
+ findPda = (baseAddress, prefix, programId = require_common.SINGLE_POOL_PROGRAM_ID) => {
11587
+ const [pda] = __solana_web3_js.PublicKey.findProgramAddressSync([Buffer.from(prefix), baseAddress.toBuffer()], programId);
11588
+ return pda;
11589
+ };
11590
+ findPoolMintAddressByVoteAccount = (voteAccountAddress) => findPda(findPoolAddress(voteAccountAddress), "mint");
11591
+ findPoolAddress = (voteAccountAddress) => findPda(voteAccountAddress, "pool");
11592
+ findPoolMintAddress = (poolAddress) => findPda(poolAddress, "mint");
11593
+ findPoolStakeAddress = (poolAddress) => findPda(poolAddress, "stake");
11594
+ findPoolStakeAuthorityAddress = (poolAddress) => findPda(poolAddress, "stake_authority");
11595
+ findPoolMintAuthorityAddress = (poolAddress) => findPda(poolAddress, "mint_authority");
11596
+ findPoolMplAuthorityAddress = (poolAddress) => findPda(poolAddress, "mpl_authority");
11597
+ findPoolOnRampAddress = (poolAddress) => findPda(poolAddress, "onramp");
11598
+ findMplMetadataAddress = async (poolMintAddress) => {
11599
+ const [pda] = __solana_web3_js.PublicKey.findProgramAddressSync([
11600
+ Buffer.from("metadata"),
11601
+ require_common.MPL_METADATA_PROGRAM_ID.toBuffer(),
11602
+ poolMintAddress.toBuffer()
11603
+ ], require_common.MPL_METADATA_PROGRAM_ID);
11604
+ return pda;
11605
+ };
11606
+ SINGLE_POOL_ACCOUNT_SIZE = BigInt(33);
11607
+ STAKE_ACCOUNT_SIZE = BigInt(200);
11608
+ MINT_SIZE = BigInt(82);
11609
+ createAccountIx = (from, newAccount, lamports, space, programAddress) => {
11348
11610
  const data = Buffer.concat([
11349
- Buffer.from([SinglePoolInstructionType.WithdrawStake]),
11350
- userStakeAuthority.toBuffer(),
11351
- Buffer.from(new bn_js.BN(rawAmount.toString()).toArray("le", 8))
11611
+ Buffer.from([0]),
11612
+ Buffer.from(new bn_js.BN(lamports).toArray("le", 8)),
11613
+ Buffer.from(new bn_js.BN(space).toArray("le", 8)),
11614
+ programAddress.toBuffer()
11352
11615
  ]);
11353
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11616
+ const accounts$2 = [{
11617
+ pubkey: from,
11618
+ isSigner: true,
11619
+ isWritable: true
11620
+ }, {
11621
+ pubkey: newAccount,
11622
+ isSigner: true,
11623
+ isWritable: true
11624
+ }];
11625
+ return createTransactionInstruction(require_common.SYSTEM_PROGRAM_ID, accounts$2, data);
11626
+ };
11627
+ createPoolOnrampIx = (voteAccount) => {
11628
+ const poolAccount = findPoolAddress(voteAccount);
11629
+ const onRampAccount = findPoolOnRampAddress(poolAccount);
11630
+ const poolStakeAuthority = findPoolStakeAuthorityAddress(poolAccount);
11631
+ const keys = [
11354
11632
  {
11355
- pubkey: pool,
11633
+ pubkey: poolAccount,
11356
11634
  isSigner: false,
11357
11635
  isWritable: false
11358
11636
  },
11359
11637
  {
11360
- pubkey: stake,
11361
- isSigner: false,
11362
- isWritable: true
11363
- },
11364
- {
11365
- pubkey: mint,
11638
+ pubkey: onRampAccount,
11366
11639
  isSigner: false,
11367
11640
  isWritable: true
11368
11641
  },
11369
11642
  {
11370
- pubkey: stakeAuthority,
11371
- isSigner: false,
11372
- isWritable: false
11373
- },
11374
- {
11375
- pubkey: mintAuthority,
11643
+ pubkey: poolStakeAuthority,
11376
11644
  isSigner: false,
11377
11645
  isWritable: false
11378
11646
  },
11379
11647
  {
11380
- pubkey: userStakeAccount,
11381
- isSigner: false,
11382
- isWritable: true
11383
- },
11384
- {
11385
- pubkey: userTokenAccount,
11386
- isSigner: false,
11387
- isWritable: true
11388
- },
11389
- {
11390
- pubkey: require_common.SYSVAR_CLOCK_ID,
11648
+ pubkey: __solana_web3_js.SYSVAR_RENT_PUBKEY,
11391
11649
  isSigner: false,
11392
11650
  isWritable: false
11393
11651
  },
11394
11652
  {
11395
- pubkey: __solana_spl_token.TOKEN_PROGRAM_ID,
11653
+ pubkey: __solana_web3_js.SystemProgram.programId,
11396
11654
  isSigner: false,
11397
11655
  isWritable: false
11398
11656
  },
11399
11657
  {
11400
- pubkey: require_common.STAKE_PROGRAM_ID,
11658
+ pubkey: __solana_web3_js.StakeProgram.programId,
11401
11659
  isSigner: false,
11402
11660
  isWritable: false
11403
11661
  }
11404
- ], data);
11405
- },
11406
- createTokenMetadata: async (pool, payer) => {
11407
- const mint = findPoolMintAddress(pool);
11408
- const [mintAuthority, mplAuthority, mplMetadata] = await Promise.all([
11409
- findPoolMintAuthorityAddress(pool),
11410
- findPoolMplAuthorityAddress(pool),
11411
- findMplMetadataAddress(mint)
11412
- ]);
11413
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11414
- {
11415
- pubkey: pool,
11416
- isSigner: false,
11417
- isWritable: false
11418
- },
11662
+ ];
11663
+ const data = Buffer.from(Uint8Array.of(6));
11664
+ return new __solana_web3_js.TransactionInstruction({
11665
+ keys,
11666
+ programId: require_common.SINGLE_POOL_PROGRAM_ID,
11667
+ data
11668
+ });
11669
+ };
11670
+ replenishPoolIx = (voteAccount) => {
11671
+ const poolAccount = findPoolAddress(voteAccount);
11672
+ const stakePool = findPoolStakeAddress(poolAccount);
11673
+ const onRampPool = findPoolOnRampAddress(poolAccount);
11674
+ const authority = findPoolStakeAuthorityAddress(poolAccount);
11675
+ const keys = [
11419
11676
  {
11420
- pubkey: mint,
11677
+ pubkey: voteAccount,
11421
11678
  isSigner: false,
11422
11679
  isWritable: false
11423
11680
  },
11424
11681
  {
11425
- pubkey: mintAuthority,
11682
+ pubkey: poolAccount,
11426
11683
  isSigner: false,
11427
11684
  isWritable: false
11428
11685
  },
11429
11686
  {
11430
- pubkey: mplAuthority,
11687
+ pubkey: stakePool,
11431
11688
  isSigner: false,
11432
- isWritable: false
11433
- },
11434
- {
11435
- pubkey: payer,
11436
- isSigner: true,
11437
11689
  isWritable: true
11438
11690
  },
11439
11691
  {
11440
- pubkey: mplMetadata,
11692
+ pubkey: onRampPool,
11441
11693
  isSigner: false,
11442
11694
  isWritable: true
11443
11695
  },
11444
11696
  {
11445
- pubkey: require_common.MPL_METADATA_PROGRAM_ID,
11697
+ pubkey: authority,
11446
11698
  isSigner: false,
11447
11699
  isWritable: false
11448
11700
  },
11449
11701
  {
11450
- pubkey: require_common.SYSTEM_PROGRAM_ID,
11451
- isSigner: false,
11452
- isWritable: false
11453
- }
11454
- ], Buffer.from([SinglePoolInstructionType.CreateTokenMetadata]));
11455
- },
11456
- updateTokenMetadata: async (voteAccount, authorizedWithdrawer, tokenName, tokenSymbol, tokenUri = "") => {
11457
- if (tokenName.length > 32) {
11458
- throw new Error("maximum token name length is 32 characters");
11459
- }
11460
- if (tokenSymbol.length > 10) {
11461
- throw new Error("maximum token symbol length is 10 characters");
11462
- }
11463
- if (tokenUri.length > 200) {
11464
- throw new Error("maximum token uri length is 200 characters");
11465
- }
11466
- const pool = findPoolAddress(voteAccount);
11467
- const [mint, mplAuthority] = await Promise.all([findPoolMintAddress(pool), findPoolMplAuthorityAddress(pool)]);
11468
- const mplMetadata = await findMplMetadataAddress(mint);
11469
- const data = Buffer.concat([
11470
- Buffer.from([SinglePoolInstructionType.UpdateTokenMetadata]),
11471
- Buffer.from(new Uint32Array([tokenName.length]).buffer),
11472
- Buffer.from(tokenName),
11473
- Buffer.from(new Uint32Array([tokenSymbol.length]).buffer),
11474
- Buffer.from(tokenSymbol),
11475
- Buffer.from(new Uint32Array([tokenUri.length]).buffer),
11476
- Buffer.from(tokenUri)
11477
- ]);
11478
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, [
11479
- {
11480
- pubkey: voteAccount,
11702
+ pubkey: __solana_web3_js.SYSVAR_CLOCK_PUBKEY,
11481
11703
  isSigner: false,
11482
11704
  isWritable: false
11483
11705
  },
11484
11706
  {
11485
- pubkey: pool,
11707
+ pubkey: require_common.SYSVAR_STAKE_HISTORY_ID,
11486
11708
  isSigner: false,
11487
11709
  isWritable: false
11488
11710
  },
11489
11711
  {
11490
- pubkey: mplAuthority,
11712
+ pubkey: __solana_web3_js.STAKE_CONFIG_ID,
11491
11713
  isSigner: false,
11492
11714
  isWritable: false
11493
11715
  },
11494
11716
  {
11495
- pubkey: authorizedWithdrawer,
11496
- isSigner: true,
11497
- isWritable: false
11498
- },
11499
- {
11500
- pubkey: mplMetadata,
11501
- isSigner: false,
11502
- isWritable: true
11503
- },
11504
- {
11505
- pubkey: require_common.MPL_METADATA_PROGRAM_ID,
11717
+ pubkey: __solana_web3_js.StakeProgram.programId,
11506
11718
  isSigner: false,
11507
11719
  isWritable: false
11508
11720
  }
11509
- ], data);
11510
- }
11511
- };
11512
- const createTransactionInstruction = (programId, keys, data) => {
11513
- return {
11514
- programId,
11515
- keys,
11516
- data
11721
+ ];
11722
+ const data = Buffer.from(Uint8Array.of(1));
11723
+ return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, keys, data);
11517
11724
  };
11518
- };
11519
- const findPda = (baseAddress, prefix, programId = require_common.SINGLE_POOL_PROGRAM_ID) => {
11520
- const [pda] = __solana_web3_js.PublicKey.findProgramAddressSync([Buffer.from(prefix), baseAddress.toBuffer()], programId);
11521
- return pda;
11522
- };
11523
- const findPoolMintAddressByVoteAccount = (voteAccountAddress) => findPda(findPoolAddress(voteAccountAddress), "mint");
11524
- const findPoolAddress = (voteAccountAddress) => findPda(voteAccountAddress, "pool");
11525
- const findPoolMintAddress = (poolAddress) => findPda(poolAddress, "mint");
11526
- const findPoolStakeAddress = (poolAddress) => findPda(poolAddress, "stake");
11527
- const findPoolStakeAuthorityAddress = (poolAddress) => findPda(poolAddress, "stake_authority");
11528
- const findPoolMintAuthorityAddress = (poolAddress) => findPda(poolAddress, "mint_authority");
11529
- const findPoolMplAuthorityAddress = (poolAddress) => findPda(poolAddress, "mpl_authority");
11530
- const findPoolOnRampAddress = (poolAddress) => findPda(poolAddress, "onramp");
11531
- const findMplMetadataAddress = async (poolMintAddress) => {
11532
- const [pda] = __solana_web3_js.PublicKey.findProgramAddressSync([
11533
- Buffer.from("metadata"),
11534
- require_common.MPL_METADATA_PROGRAM_ID.toBuffer(),
11535
- poolMintAddress.toBuffer()
11536
- ], require_common.MPL_METADATA_PROGRAM_ID);
11537
- return pda;
11538
- };
11539
- const SINGLE_POOL_ACCOUNT_SIZE = BigInt(33);
11540
- const STAKE_ACCOUNT_SIZE = BigInt(200);
11541
- const MINT_SIZE = BigInt(82);
11542
- async function initializeStakedPoolTx(connection, payer, voteAccountAddress) {
11543
- const instructions$3 = await initializeStakedPoolIxs(connection, payer, voteAccountAddress);
11544
- const tx = new __solana_web3_js.Transaction().add(...instructions$3);
11545
- return tx;
11546
- }
11547
- async function initializeStakedPoolIxs(connection, payer, voteAccountAddress) {
11548
- const poolAddress = findPoolAddress(voteAccountAddress);
11549
- const stakeAddress = findPoolStakeAddress(poolAddress);
11550
- const mintAddress = findPoolMintAddress(poolAddress);
11551
- const onRampAddress = findPoolOnRampAddress(poolAddress);
11552
- const [poolRent, stakeRent, mintRent, minimumDelegationObj] = await Promise.all([
11553
- connection.getMinimumBalanceForRentExemption(Number(SINGLE_POOL_ACCOUNT_SIZE), "confirmed"),
11554
- connection.getMinimumBalanceForRentExemption(Number(STAKE_ACCOUNT_SIZE), "confirmed"),
11555
- connection.getMinimumBalanceForRentExemption(Number(MINT_SIZE), "confirmed"),
11556
- connection.getStakeMinimumDelegation()
11557
- ]);
11558
- const minimumDelegation = minimumDelegationObj.value;
11559
- const instructions$3 = [];
11560
- instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11561
- fromPubkey: payer,
11562
- toPubkey: poolAddress,
11563
- lamports: poolRent
11564
- }));
11565
- instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11566
- fromPubkey: payer,
11567
- toPubkey: stakeAddress,
11568
- lamports: stakeRent + minimumDelegation + __solana_web3_js.LAMPORTS_PER_SOL * 1
11569
- }));
11570
- instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11571
- fromPubkey: payer,
11572
- toPubkey: onRampAddress,
11573
- lamports: stakeRent
11574
- }));
11575
- instructions$3.push(__solana_web3_js.SystemProgram.transfer({
11576
- fromPubkey: payer,
11577
- toPubkey: mintAddress,
11578
- lamports: mintRent
11579
- }));
11580
- instructions$3.push(SinglePoolInstruction.initializePool(voteAccountAddress));
11581
- instructions$3.push(SinglePoolInstruction.initializeOnRamp(poolAddress));
11582
- instructions$3.push(await SinglePoolInstruction.createTokenMetadata(poolAddress, payer));
11583
- return instructions$3;
11584
- }
11585
- const createAccountIx = (from, newAccount, lamports, space, programAddress) => {
11586
- const data = Buffer.concat([
11587
- Buffer.from([0]),
11588
- Buffer.from(new bn_js.BN(lamports).toArray("le", 8)),
11589
- Buffer.from(new bn_js.BN(space).toArray("le", 8)),
11590
- programAddress.toBuffer()
11591
- ]);
11592
- const accounts$2 = [{
11593
- pubkey: from,
11594
- isSigner: true,
11595
- isWritable: true
11596
- }, {
11597
- pubkey: newAccount,
11598
- isSigner: true,
11599
- isWritable: true
11600
- }];
11601
- return createTransactionInstruction(require_common.SYSTEM_PROGRAM_ID, accounts$2, data);
11602
- };
11603
- const createPoolOnrampIx = (voteAccount) => {
11604
- const poolAccount = findPoolAddress(voteAccount);
11605
- const onRampAccount = findPoolOnRampAddress(poolAccount);
11606
- const poolStakeAuthority = findPoolStakeAuthorityAddress(poolAccount);
11607
- const keys = [
11608
- {
11609
- pubkey: poolAccount,
11610
- isSigner: false,
11611
- isWritable: false
11612
- },
11613
- {
11614
- pubkey: onRampAccount,
11615
- isSigner: false,
11616
- isWritable: true
11617
- },
11618
- {
11619
- pubkey: poolStakeAuthority,
11620
- isSigner: false,
11621
- isWritable: false
11622
- },
11623
- {
11624
- pubkey: __solana_web3_js.SYSVAR_RENT_PUBKEY,
11625
- isSigner: false,
11626
- isWritable: false
11627
- },
11628
- {
11629
- pubkey: __solana_web3_js.SystemProgram.programId,
11630
- isSigner: false,
11631
- isWritable: false
11632
- },
11633
- {
11634
- pubkey: __solana_web3_js.StakeProgram.programId,
11635
- isSigner: false,
11636
- isWritable: false
11637
- }
11638
- ];
11639
- const data = Buffer.from(Uint8Array.of(6));
11640
- return new __solana_web3_js.TransactionInstruction({
11641
- keys,
11642
- programId: require_common.SINGLE_POOL_PROGRAM_ID,
11643
- data
11644
- });
11645
- };
11646
- const replenishPoolIx = (voteAccount) => {
11647
- const poolAccount = findPoolAddress(voteAccount);
11648
- const stakePool = findPoolStakeAddress(poolAccount);
11649
- const onRampPool = findPoolOnRampAddress(poolAccount);
11650
- const authority = findPoolStakeAuthorityAddress(poolAccount);
11651
- const keys = [
11652
- {
11653
- pubkey: voteAccount,
11654
- isSigner: false,
11655
- isWritable: false
11656
- },
11657
- {
11658
- pubkey: poolAccount,
11659
- isSigner: false,
11660
- isWritable: false
11661
- },
11662
- {
11663
- pubkey: stakePool,
11664
- isSigner: false,
11665
- isWritable: true
11666
- },
11667
- {
11668
- pubkey: onRampPool,
11669
- isSigner: false,
11670
- isWritable: true
11671
- },
11672
- {
11673
- pubkey: authority,
11674
- isSigner: false,
11675
- isWritable: false
11676
- },
11677
- {
11678
- pubkey: __solana_web3_js.SYSVAR_CLOCK_PUBKEY,
11679
- isSigner: false,
11680
- isWritable: false
11681
- },
11682
- {
11683
- pubkey: require_common.SYSVAR_STAKE_HISTORY_ID,
11684
- isSigner: false,
11685
- isWritable: false
11686
- },
11687
- {
11688
- pubkey: __solana_web3_js.STAKE_CONFIG_ID,
11689
- isSigner: false,
11690
- isWritable: false
11691
- },
11692
- {
11693
- pubkey: __solana_web3_js.StakeProgram.programId,
11694
- isSigner: false,
11695
- isWritable: false
11696
- }
11697
- ];
11698
- const data = Buffer.from(Uint8Array.of(1));
11699
- return createTransactionInstruction(require_common.SINGLE_POOL_PROGRAM_ID, keys, data);
11700
- };
11725
+ } });
11701
11726
 
11702
11727
  //#endregion
11703
11728
  //#region src/vendor/switchboard_legacy/account.ts
@@ -15995,9 +16020,11 @@ require_common.__export(vendor_exports, {
15995
16020
  replenishPoolIx: () => replenishPoolIx,
15996
16021
  switchboardAccountCoder: () => switchboardAccountCoder
15997
16022
  });
16023
+ init_single_spl_pool();
15998
16024
 
15999
16025
  //#endregion
16000
16026
  //#region src/utils.ts
16027
+ require_common.init_constants();
16001
16028
  function getBankVaultSeeds(type) {
16002
16029
  switch (type) {
16003
16030
  case BankVaultType.LiquidityVault: return require_common.PDA_BANK_LIQUIDITY_VAULT_SEED;
@@ -18729,6 +18756,7 @@ let PriceBias = /* @__PURE__ */ function(PriceBias$1) {
18729
18756
 
18730
18757
  //#endregion
18731
18758
  //#region src/services/price/utils/compute.utils.ts
18759
+ require_common.init_constants();
18732
18760
  function getPriceWithConfidence(oraclePrice, weighted) {
18733
18761
  return weighted ? oraclePrice.priceWeighted : oraclePrice.priceRealtime;
18734
18762
  }
@@ -19355,15 +19383,89 @@ function computeInterestRates(bank) {
19355
19383
  borrowingRate
19356
19384
  };
19357
19385
  }
19358
- function computeBaseInterestRate(bank) {
19359
- const { optimalUtilizationRate, plateauInterestRate, maxInterestRate } = bank.config.interestRateConfig;
19360
- const utilizationRate = computeUtilizationRate(bank);
19386
+ /**
19387
+ * Maximum value for u32
19388
+ */
19389
+ const U32_MAX = 4294967295;
19390
+ /**
19391
+ * Convert u32 encoded rate to APR percentage (0.0 to 10.0)
19392
+ * Rate is encoded as: rate / u32::MAX * 1000%
19393
+ * Example: 100% APR = 0.1 * u32::MAX
19394
+ */
19395
+ function rateFromU32(rate) {
19396
+ const ratio = new bignumber_js.default(rate).div(U32_MAX);
19397
+ return ratio.times(10);
19398
+ }
19399
+ /**
19400
+ * Convert u32 encoded utilization to percentage (0.0 to 1.0)
19401
+ * Util is encoded as: util / u32::MAX * 100%
19402
+ * Example: 50% = 0.5 * u32::MAX
19403
+ */
19404
+ function utilFromU32(util) {
19405
+ return new bignumber_js.default(util).div(U32_MAX);
19406
+ }
19407
+ /**
19408
+ * Linear interpolation between two points
19409
+ * Given points (startX, startY) and (endX, endY), find Y at targetX
19410
+ */
19411
+ function calculateRateBetweenPoints(startX, startY, endX, endY, targetX) {
19412
+ if (endX.lte(startX)) return startY;
19413
+ if (targetX.lt(startX)) return startY;
19414
+ if (targetX.gt(endX)) return endY;
19415
+ if (endY.lt(startY)) return startY;
19416
+ const deltaX = endX.minus(startX);
19417
+ if (deltaX.isZero()) return startY;
19418
+ const offset = targetX.minus(startX);
19419
+ const proportion = offset.div(deltaX);
19420
+ const deltaY = endY.minus(startY);
19421
+ const scaledDelta = deltaY.times(proportion);
19422
+ return startY.plus(scaledDelta);
19423
+ }
19424
+ /**
19425
+ * Compute base interest rate using the legacy 3-point curve
19426
+ */
19427
+ function computeLegacyCurve(utilizationRate, optimalUtilizationRate, plateauInterestRate, maxInterestRate) {
19361
19428
  if (utilizationRate.lte(optimalUtilizationRate)) {
19362
19429
  return utilizationRate.times(plateauInterestRate).div(optimalUtilizationRate);
19363
19430
  } else {
19364
19431
  return utilizationRate.minus(optimalUtilizationRate).div(new bignumber_js.default(1).minus(optimalUtilizationRate)).times(maxInterestRate.minus(plateauInterestRate)).plus(plateauInterestRate);
19365
19432
  }
19366
19433
  }
19434
+ /**
19435
+ * Compute base interest rate using the 7-point multipoint curve
19436
+ * Locates utilization on a linear function with up to 7 points:
19437
+ * - Point 1: (0%, zeroUtilRate)
19438
+ * - Points 2-6: Custom points from the points array
19439
+ * - Point 7: (100%, hundredUtilRate)
19440
+ */
19441
+ function computeMultipointCurve(utilizationRate, zeroUtilRate, hundredUtilRate, points) {
19442
+ const zeroRate = rateFromU32(zeroUtilRate);
19443
+ const hundredRate = rateFromU32(hundredUtilRate);
19444
+ const clampedUtilizationRate = bignumber_js.default.max(0, bignumber_js.default.min(1, utilizationRate));
19445
+ const nonPaddingPoints = points.filter((point) => point.util !== 0);
19446
+ let prevUtil = new bignumber_js.default(0);
19447
+ let prevRate = zeroRate;
19448
+ for (const point of nonPaddingPoints) {
19449
+ const pointUtil = utilFromU32(point.util);
19450
+ const pointRate = rateFromU32(point.rate);
19451
+ if (clampedUtilizationRate.lte(pointUtil)) {
19452
+ return calculateRateBetweenPoints(prevUtil, prevRate, pointUtil, pointRate, clampedUtilizationRate);
19453
+ }
19454
+ prevUtil = pointUtil;
19455
+ prevRate = pointRate;
19456
+ }
19457
+ return calculateRateBetweenPoints(prevUtil, prevRate, new bignumber_js.default(1), hundredRate, clampedUtilizationRate);
19458
+ }
19459
+ function computeBaseInterestRate(bank) {
19460
+ const interestRateConfig = bank.config.interestRateConfig;
19461
+ const utilizationRate = computeUtilizationRate(bank);
19462
+ const curveType = interestRateConfig.curveType;
19463
+ if (curveType === 1) {
19464
+ return computeMultipointCurve(utilizationRate, interestRateConfig.zeroUtilRate, interestRateConfig.hundredUtilRate, interestRateConfig.points);
19465
+ } else {
19466
+ return computeLegacyCurve(utilizationRate, interestRateConfig.optimalUtilizationRate, interestRateConfig.plateauInterestRate, interestRateConfig.maxInterestRate);
19467
+ }
19468
+ }
19367
19469
  function computeUtilizationRate(bank) {
19368
19470
  const assets = getTotalAssetQuantity(bank);
19369
19471
  const liabilities = getTotalLiabilityQuantity(bank);
@@ -19696,6 +19798,7 @@ function bankConfigRawToDto(bankConfigRaw) {
19696
19798
 
19697
19799
  //#endregion
19698
19800
  //#region src/services/bank/bank.service.ts
19801
+ require_common.init_constants();
19699
19802
  async function freezeBankConfigIx(program, bankAddress, bankConfigOpt) {
19700
19803
  if (!bankConfigOpt) {}
19701
19804
  const bankConfigRaw = serializeBankConfigOpt(bankConfigOpt);
@@ -20067,6 +20170,7 @@ async function executeBundleSimulation(rpcEndpoint, encodedTransactions, config)
20067
20170
 
20068
20171
  //#endregion
20069
20172
  //#region src/services/transaction/transaction.service.ts
20173
+ require_common.init_constants();
20070
20174
  const DEFAULT_PROCESS_TX_OPTS = {
20071
20175
  broadcastType: "RPC",
20072
20176
  isSequentialTxs: true,
@@ -20663,6 +20767,7 @@ function addTransactionTxTags(transactions) {
20663
20767
 
20664
20768
  //#endregion
20665
20769
  //#region src/services/account/utils/compute.utils.ts
20770
+ init_single_spl_pool();
20666
20771
  /**
20667
20772
  * Lendr Account Computes
20668
20773
  * =========================
@@ -21614,6 +21719,8 @@ function getActiveStaleBanks(balances, banks, additionalBanks, oraclePrices, max
21614
21719
 
21615
21720
  //#endregion
21616
21721
  //#region src/services/group/group.service.ts
21722
+ require_common.init_constants();
21723
+ init_single_spl_pool();
21617
21724
  async function makePoolConfigureBankIx(program, bank, args) {
21618
21725
  const ix = await instructions_default.makePoolConfigureBankIx(program, { bank }, { bankConfigOpt: args });
21619
21726
  return {
@@ -21747,6 +21854,8 @@ function dtoToValidatorStakeGroup(validatorStakeGroupDto) {
21747
21854
 
21748
21855
  //#endregion
21749
21856
  //#region src/services/native-stake/utils/fetch.utils.ts
21857
+ require_common.init_constants();
21858
+ init_single_spl_pool();
21750
21859
  /**
21751
21860
  * Retrieves all active stake accounts associated with a given public key grouped by validator
21752
21861
  *
@@ -22654,7 +22763,7 @@ var LendrAccount = class LendrAccount {
22654
22763
  keys: []
22655
22764
  };
22656
22765
  }
22657
- async prepareWithdrawInstruction(program, bankMap, mintDatas, bankAddress, withdrawAll = false, withdrawOpts = {}) {
22766
+ async prepareWithdrawInstruction(program, bankMap, mintDatas, bankMetadataMap, bankAddress, withdrawAll = false, withdrawOpts = {}) {
22658
22767
  const bank = bankMap.get(bankAddress.toBase58());
22659
22768
  if (!bank) throw Error(`Bank ${bankAddress.toBase58()} not found`);
22660
22769
  const mintData = mintDatas.get(bankAddress.toBase58());
@@ -22678,9 +22787,23 @@ var LendrAccount = class LendrAccount {
22678
22787
  if (withdrawOpts.observationBanksOverride) {
22679
22788
  remainingAccounts.push(...withdrawOpts.observationBanksOverride);
22680
22789
  } else {
22681
- const accountMetas = computeHealthAccountMetas(healthAccounts);
22790
+ const accountMetas = computeHealthAccountMetas(healthAccounts, bankMetadataMap);
22682
22791
  remainingAccounts.push(...accountMetas);
22683
22792
  }
22793
+ if (withdrawAll) {
22794
+ remainingAccounts.push(bank.address, bank.config.oracleKeys[0]);
22795
+ if (bank.config.assetTag === 2) {
22796
+ const bankMetadata = bankMetadataMap?.[bankAddress.toBase58()];
22797
+ if (!bankMetadata?.validatorVoteAccount) {
22798
+ throw Error(`No validator vote account for staked bank ${bankAddress.toBase58()}`);
22799
+ }
22800
+ const { findPoolAddress: findPoolAddress$1, findPoolStakeAddress: findPoolStakeAddress$1, findPoolMintAddress: findPoolMintAddress$1 } = (init_single_spl_pool(), require_common.__toCommonJS(single_spl_pool_exports));
22801
+ const pool = findPoolAddress$1(new __solana_web3_js.PublicKey(bankMetadata.validatorVoteAccount));
22802
+ const solPool = findPoolStakeAddress$1(pool);
22803
+ const lstMint = findPoolMintAddress$1(pool);
22804
+ remainingAccounts.push(lstMint, solPool);
22805
+ }
22806
+ }
22684
22807
  return {
22685
22808
  withdrawIxs,
22686
22809
  wrapAndUnwrapSol,
@@ -22694,8 +22817,8 @@ var LendrAccount = class LendrAccount {
22694
22817
  }))
22695
22818
  };
22696
22819
  }
22697
- async makeWithdrawIx(program, bankMap, mintDatas, amount, bankAddress, withdrawAll = false, withdrawOpts = {}) {
22698
- const { withdrawIxs, wrapAndUnwrapSol, userAta, mintData, bank, remainingAccounts } = await this.prepareWithdrawInstruction(program, bankMap, mintDatas, bankAddress, withdrawAll, withdrawOpts);
22820
+ async makeWithdrawIx(program, bankMap, mintDatas, bankMetadataMap, amount, bankAddress, withdrawAll = false, withdrawOpts = {}) {
22821
+ const { withdrawIxs, wrapAndUnwrapSol, userAta, mintData, bank, remainingAccounts } = await this.prepareWithdrawInstruction(program, bankMap, mintDatas, bankMetadataMap, bankAddress, withdrawAll, withdrawOpts);
22699
22822
  const [bankLiquidityVaultAuthority] = getBankVaultAuthority(BankVaultType.LiquidityVault, bank.address, program.programId);
22700
22823
  const withdrawIx = await instructions_default.makeWithdrawIx(program, {
22701
22824
  lendrAccount: this.address,
@@ -22719,8 +22842,8 @@ var LendrAccount = class LendrAccount {
22719
22842
  keys: []
22720
22843
  };
22721
22844
  }
22722
- async makeWithdrawWithSessionIx(program, bankMap, mintDatas, amount, bankAddress, session, withdrawAll = false, withdrawOpts = {}) {
22723
- const { withdrawIxs, wrapAndUnwrapSol, userAta, mintData, bank, remainingAccounts } = await this.prepareWithdrawInstruction(program, bankMap, mintDatas, bankAddress, withdrawAll, {
22845
+ async makeWithdrawWithSessionIx(program, bankMap, mintDatas, bankMetadataMap, amount, bankAddress, session, withdrawAll = false, withdrawOpts = {}) {
22846
+ const { withdrawIxs, wrapAndUnwrapSol, userAta, mintData, bank, remainingAccounts } = await this.prepareWithdrawInstruction(program, bankMap, mintDatas, bankMetadataMap, bankAddress, withdrawAll, {
22724
22847
  ...withdrawOpts,
22725
22848
  createAtaPayer: session.payer
22726
22849
  });
@@ -23038,6 +23161,7 @@ function isWeightedPrice(reqType) {
23038
23161
 
23039
23162
  //#endregion
23040
23163
  //#region src/models/account/wrapper.ts
23164
+ require_common.init_constants();
23041
23165
  var LendrAccountWrapper = class LendrAccountWrapper {
23042
23166
  address;
23043
23167
  _lendrAccount;
@@ -23945,7 +24069,8 @@ var LendrAccountWrapper = class LendrAccountWrapper {
23945
24069
  async makeWithdrawIx(amount, bankAddress, withdrawAll = false, withdrawOpts = {}) {
23946
24070
  const tokenProgramAddress = this.client.mintDatas.get(bankAddress.toBase58())?.tokenProgram;
23947
24071
  if (!tokenProgramAddress) throw Error("Withdraw mint not found");
23948
- return this._lendrAccount.makeWithdrawIx(this._program, this.client.banks, this.client.mintDatas, amount, bankAddress, withdrawAll, withdrawOpts);
24072
+ if (!this.client.bankMetadataMap) throw Error("Bank metadata map not found");
24073
+ return this._lendrAccount.makeWithdrawIx(this._program, this.client.banks, this.client.mintDatas, this.client.bankMetadataMap, amount, bankAddress, withdrawAll, withdrawOpts);
23949
24074
  }
23950
24075
  /**
23951
24076
  * Creates instructions for withdrawing tokens from a lendr bank account.
@@ -23961,7 +24086,8 @@ var LendrAccountWrapper = class LendrAccountWrapper {
23961
24086
  async makeWithdrawWithSessionIx(amount, bankAddress, session, withdrawAll = false, withdrawOpts = {}) {
23962
24087
  const tokenProgramAddress = this.client.mintDatas.get(bankAddress.toBase58())?.tokenProgram;
23963
24088
  if (!tokenProgramAddress) throw Error("Withdraw mint not found");
23964
- return this._lendrAccount.makeWithdrawWithSessionIx(this._program, this.client.banks, this.client.mintDatas, amount, bankAddress, session, withdrawAll, withdrawOpts);
24089
+ if (!this.client.bankMetadataMap) throw Error("Bank metadata map not found");
24090
+ return this._lendrAccount.makeWithdrawWithSessionIx(this._program, this.client.banks, this.client.mintDatas, this.client.bankMetadataMap, amount, bankAddress, session, withdrawAll, withdrawOpts);
23965
24091
  }
23966
24092
  /**
23967
24093
  * Creates a transaction for withdrawing tokens from a lendr bank account and staking them.
@@ -24787,6 +24913,7 @@ var LendrGroup = class LendrGroup {
24787
24913
 
24788
24914
  //#endregion
24789
24915
  //#region src/clients/client.ts
24916
+ require_common.init_constants();
24790
24917
  /**
24791
24918
  * Entrypoint to interact with the lendr contract.
24792
24919
  */
@@ -25698,6 +25825,10 @@ var EmodeSettings = class EmodeSettings {
25698
25825
  }
25699
25826
  };
25700
25827
 
25828
+ //#endregion
25829
+ //#region src/index.ts
25830
+ init_constants();
25831
+
25701
25832
  //#endregion
25702
25833
  exports.AccountFlags = AccountFlags;
25703
25834
  exports.AccountType = AccountType;