@kamino-finance/klend-sdk 5.2.12 → 5.2.13

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.
@@ -65,6 +65,13 @@ import { Data } from '@kamino-finance/kliquidity-sdk';
65
65
  import bs58 from 'bs58';
66
66
  import { getProgramAccounts } from '../utils/rpc';
67
67
  import { VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
68
+ import {
69
+ AcceptVaultOwnershipIxs,
70
+ InitVaultIxs,
71
+ SyncVaultLUTIxs,
72
+ UpdateReserveAllocationIxs,
73
+ UpdateVaultConfigIxs,
74
+ } from './types';
68
75
 
69
76
  /**
70
77
  * KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
@@ -190,9 +197,9 @@ export class KaminoManager {
190
197
  * This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
191
198
  * @param vaultConfig - the config object used to create a vault
192
199
  * @returns vault - keypair, should be used to sign the transaction which creates the vault account
193
- * @returns ixns - an array of instructions to create the vault
200
+ * @returns vault: the keypair of the vault, used to sign the initialization transaction; initVaultIxs: a struct with ixs to initialize the vault and its lookup table + populateLUTIxs, a list to populate the lookup table which has to be executed in a separate transaction
194
201
  */
195
- async createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{ vault: Keypair; ixns: TransactionInstruction[] }> {
202
+ async createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{ vault: Keypair; initVaultIxs: InitVaultIxs }> {
196
203
  return this._vaultClient.createVaultIxs(vaultConfig);
197
204
  }
198
205
 
@@ -200,12 +207,12 @@ export class KaminoManager {
200
207
  * This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
201
208
  * @param vault - vault to be updated
202
209
  * @param reserveAllocationConfig - new reserve allocation config
203
- * @returns - a list of instructions
210
+ * @returns - a struct of instructions
204
211
  */
205
212
  async updateVaultReserveAllocationIxs(
206
213
  vault: KaminoVault,
207
214
  reserveAllocationConfig: ReserveAllocationConfig
208
- ): Promise<TransactionInstruction> {
215
+ ): Promise<UpdateReserveAllocationIxs> {
209
216
  return this._vaultClient.updateReserveAllocationIxs(vault, reserveAllocationConfig);
210
217
  }
211
218
 
@@ -331,21 +338,28 @@ export class KaminoManager {
331
338
  return this._vaultClient.depositIxs(user, vault, tokenAmount, vaultReservesMap);
332
339
  }
333
340
 
334
- async updateVaultConfigIx(
341
+ /**
342
+ * Update a field of the vault. If the field is a pubkey it will return an extra instruction to add that account into the lookup table
343
+ * @param vault the vault to update
344
+ * @param mode the field to update (based on VaultConfigFieldKind enum)
345
+ * @param value the value to update the field with
346
+ * @returns a struct that contains the instruction to update the field and an optional list of instructions to update the lookup table
347
+ */
348
+ async updateVaultConfigIxs(
335
349
  vault: KaminoVault,
336
350
  mode: VaultConfigFieldKind,
337
351
  value: string
338
- ): Promise<TransactionInstruction> {
339
- return this._vaultClient.updateVaultConfigIx(vault, mode, value);
352
+ ): Promise<UpdateVaultConfigIxs> {
353
+ return this._vaultClient.updateVaultConfigIxs(vault, mode, value);
340
354
  }
341
355
 
342
356
  /**
343
- * This function creates the instruction for the `pendingAdmin` of the vault to accept to become the owner of the vault (step 2/2 of the ownership transfer)
357
+ * This function creates the instruction for the `pendingAdmin` of the vault to accept to become the owner of the vault (step 2/2 of the ownership transfer) and the instructions to sync the vault LUT to the new state
344
358
  * @param vault - vault to change the ownership for
345
359
  * @returns - an instruction to be used to be executed
346
360
  */
347
- async acceptVaultOwnershipIx(vault: KaminoVault): Promise<TransactionInstruction> {
348
- return this._vaultClient.acceptVaultOwnershipIx(vault);
361
+ async acceptVaultOwnershipIxs(vault: KaminoVault): Promise<AcceptVaultOwnershipIxs> {
362
+ return this._vaultClient.acceptVaultOwnershipIxs(vault);
349
363
  }
350
364
 
351
365
  /**
@@ -385,6 +399,30 @@ export class KaminoManager {
385
399
  return this._vaultClient.withdrawPendingFeesIxs(vault, slot);
386
400
  }
387
401
 
402
+ /**
403
+ * This method append the given keys to the lookup table
404
+ * @param payer - the owner of the lookup table
405
+ * @param slot - the LUT into which the keys will be inserted
406
+ * @param keys - the keys to be inserted
407
+ * @returns - list of instructions to insert the keys into the lookup table
408
+ */
409
+ async insertIntoLUT(payer: PublicKey, lut: PublicKey, keys: PublicKey[]): Promise<TransactionInstruction[]> {
410
+ return this._vaultClient.insertIntoLookupTableIxs(payer, lut, keys);
411
+ }
412
+
413
+ /**
414
+ * Sync a vault for lookup table; create and set the LUT for the vault if needed and fill it with all the needed accounts
415
+ * @param vault the vault to sync and set the LUT for if needed
416
+ * @param vaultReserves optional; the state of the reserves in the vault allocation
417
+ * @returns a struct that contains a list of ix to create the LUT and assign it to the vault if needed + a list of ixs to insert all the accounts in the LUT
418
+ */
419
+ async syncVaultLUT(
420
+ vault: KaminoVault,
421
+ vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
422
+ ): Promise<SyncVaultLUTIxs> {
423
+ return this._vaultClient.syncVaultLookupTable(vault, vaultReserves);
424
+ }
425
+
388
426
  /**
389
427
  * This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
390
428
  * @param vault - vault to calculate tokensPerShare for
@@ -439,6 +477,15 @@ export class KaminoManager {
439
477
  return this._vaultClient.getVaultFeesPct(vaultState);
440
478
  }
441
479
 
480
+ /**
481
+ * This method returns the vault name
482
+ * @param vault - vault to retrieve the onchain name for
483
+ * @returns - the vault name as string
484
+ */
485
+ getDecodedVaultName(vaultState: VaultState): string {
486
+ return this._vaultClient.decodeVaultName(vaultState.name);
487
+ }
488
+
442
489
  /**
443
490
  * @returns - the KaminoVault client
444
491
  */
@@ -0,0 +1,28 @@
1
+ import { TransactionInstruction } from "@solana/web3.js"
2
+
3
+
4
+ /** the populateLUTIxs should be executed in a separate transaction as we cannot create and populate a lookup table in the same tx */
5
+ export type InitVaultIxs = {
6
+ initVaultIxs: TransactionInstruction[];
7
+ populateLUTIxs: TransactionInstruction[];
8
+ }
9
+
10
+ export type AcceptVaultOwnershipIxs = {
11
+ acceptVaultOwnershipIx: TransactionInstruction;
12
+ updateLUTIxs: TransactionInstruction[];
13
+ }
14
+
15
+ export type UpdateReserveAllocationIxs = {
16
+ updateReserveAllocationIx: TransactionInstruction;
17
+ updateLUTIxs: TransactionInstruction[];
18
+ }
19
+
20
+ export type UpdateVaultConfigIxs = {
21
+ updateVaultConfigIx: TransactionInstruction;
22
+ updateLUTIxs: TransactionInstruction[];
23
+ }
24
+
25
+ export type SyncVaultLUTIxs = {
26
+ setupLUTIfNeededIxs: TransactionInstruction[];
27
+ syncLUTIxs: TransactionInstruction[];
28
+ }