@kamino-finance/klend-sdk 5.11.14 → 5.11.16

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.
Files changed (42) hide show
  1. package/dist/classes/manager.d.ts +1 -1
  2. package/dist/classes/manager.d.ts.map +1 -1
  3. package/dist/classes/manager.js +3 -3
  4. package/dist/classes/manager.js.map +1 -1
  5. package/dist/classes/market.d.ts.map +1 -1
  6. package/dist/classes/market.js +3 -0
  7. package/dist/classes/market.js.map +1 -1
  8. package/dist/classes/reserve.d.ts +7 -1
  9. package/dist/classes/reserve.d.ts.map +1 -1
  10. package/dist/classes/reserve.js +145 -255
  11. package/dist/classes/reserve.js.map +1 -1
  12. package/dist/classes/types.d.ts +2 -0
  13. package/dist/classes/types.d.ts.map +1 -1
  14. package/dist/classes/utils.d.ts +1 -1
  15. package/dist/classes/utils.d.ts.map +1 -1
  16. package/dist/classes/utils.js +8 -2
  17. package/dist/classes/utils.js.map +1 -1
  18. package/dist/classes/vault.d.ts +1 -1
  19. package/dist/classes/vault.d.ts.map +1 -1
  20. package/dist/classes/vault.js +24 -5
  21. package/dist/classes/vault.js.map +1 -1
  22. package/dist/client_kamino_manager.d.ts.map +1 -1
  23. package/dist/client_kamino_manager.js +99 -89
  24. package/dist/client_kamino_manager.js.map +1 -1
  25. package/dist/utils/ata.d.ts +15 -2
  26. package/dist/utils/ata.d.ts.map +1 -1
  27. package/dist/utils/ata.js +68 -3
  28. package/dist/utils/ata.js.map +1 -1
  29. package/dist/utils/constants.d.ts +1 -0
  30. package/dist/utils/constants.d.ts.map +1 -1
  31. package/dist/utils/constants.js +2 -1
  32. package/dist/utils/constants.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/classes/manager.ts +5 -6
  35. package/src/classes/market.ts +4 -0
  36. package/src/classes/reserve.ts +178 -319
  37. package/src/classes/types.ts +3 -0
  38. package/src/classes/utils.ts +9 -3
  39. package/src/classes/vault.ts +44 -12
  40. package/src/client_kamino_manager.ts +225 -92
  41. package/src/utils/ata.ts +102 -4
  42. package/src/utils/constants.ts +2 -0
@@ -3,9 +3,11 @@ import Decimal from 'decimal.js/decimal';
3
3
 
4
4
  /** the populateLUTIxs should be executed in a separate transaction as we cannot create and populate a lookup table in the same tx */
5
5
  export type InitVaultIxs = {
6
+ createAtaIfNeededIxs: TransactionInstruction[];
6
7
  initVaultIxs: TransactionInstruction[];
7
8
  createLUTIx: TransactionInstruction;
8
9
  populateLUTIxs: TransactionInstruction[];
10
+ cleanupIxs: TransactionInstruction[];
9
11
  };
10
12
 
11
13
  export type AcceptVaultOwnershipIxs = {
@@ -59,3 +61,4 @@ export type APYs = {
59
61
  grossAPY: Decimal;
60
62
  netAPY: Decimal;
61
63
  };
64
+
@@ -222,11 +222,17 @@ export function calculateAPRFromAPY(apy: Decimal.Value) {
222
222
  .times(SLOTS_PER_YEAR);
223
223
  }
224
224
 
225
- export function sameLengthArrayEquals(left: Array<number>, right: Array<number>): boolean {
225
+ export function sameLengthArrayEquals<T>(left: Array<T>, right: Array<T>): boolean {
226
226
  if (left.length != right.length) {
227
- throw new Error(`Not same length: ${left.length} != ${left.length}`);
227
+ throw new Error(`Not same length: ${left.length} != ${right.length}`);
228
228
  }
229
- return left.every((value, index) => value === right[index]);
229
+ return left.every((value, index) => {
230
+ const other = right[index];
231
+ if (value != null && typeof (value as any).eq === 'function') {
232
+ return (value as any).eq(other);
233
+ }
234
+ return value === other;
235
+ });
230
236
  }
231
237
 
232
238
  export function getTokenBalanceFromAccountInfoLamports(accountInfo: AccountInfo<Buffer>): Decimal {
@@ -64,9 +64,17 @@ import {
64
64
  import { deposit } from '../idl_codegen_kamino_vault/instructions';
65
65
  import { withdraw } from '../idl_codegen_kamino_vault/instructions';
66
66
  import { PROGRAM_ID } from '../idl_codegen/programId';
67
- import { DEFAULT_RECENT_SLOT_DURATION_MS, ReserveWithAddress } from './reserve';
67
+ import { ReserveWithAddress } from './reserve';
68
68
  import { Fraction } from './fraction';
69
- import { createAtasIdempotent, lendingMarketAuthPda, PublicKeySet, SECONDS_PER_YEAR, U64_MAX } from '../utils';
69
+ import {
70
+ createAtasIdempotent,
71
+ createWsolAtaIfMissing,
72
+ lendingMarketAuthPda,
73
+ PublicKeySet,
74
+ SECONDS_PER_YEAR,
75
+ U64_MAX,
76
+ VAULT_INITIAL_DEPOSIT,
77
+ } from '../utils';
70
78
  import bs58 from 'bs58';
71
79
  import { getAccountOwner, getProgramAccounts } from '../utils/rpc';
72
80
  import {
@@ -115,14 +123,14 @@ export class KaminoVaultClient {
115
123
 
116
124
  constructor(
117
125
  connection: Connection,
126
+ recentSlotDurationMs: number,
118
127
  kaminoVaultprogramId?: PublicKey,
119
- kaminoLendProgramId?: PublicKey,
120
- recentSlotDurationMs?: number
128
+ kaminoLendProgramId?: PublicKey
121
129
  ) {
122
130
  this._connection = connection;
131
+ this.recentSlotDurationMs = recentSlotDurationMs;
123
132
  this._kaminoVaultProgramId = kaminoVaultprogramId ? kaminoVaultprogramId : kaminoVaultId;
124
133
  this._kaminoLendProgramId = kaminoLendProgramId ? kaminoLendProgramId : PROGRAM_ID;
125
- this.recentSlotDurationMs = recentSlotDurationMs ? recentSlotDurationMs : DEFAULT_RECENT_SLOT_DURATION_MS;
126
134
  }
127
135
 
128
136
  getConnection() {
@@ -199,12 +207,27 @@ export class KaminoVaultClient {
199
207
  this._kaminoVaultProgramId
200
208
  )[0];
201
209
 
202
- const adminTokenAccount = getAssociatedTokenAddressSync(
203
- vaultConfig.tokenMint,
204
- vaultConfig.admin,
205
- false,
206
- vaultConfig.tokenMintProgramId
207
- );
210
+ let adminTokenAccount: PublicKey;
211
+ const prerequisiteIxs: TransactionInstruction[] = [];
212
+ const cleanupIxs: TransactionInstruction[] = [];
213
+ if (vaultConfig.tokenMint.equals(NATIVE_MINT)) {
214
+ const { wsolAta, createAtaIxs, closeAtaIxs } = await createWsolAtaIfMissing(
215
+ this.getConnection(),
216
+ new Decimal(VAULT_INITIAL_DEPOSIT),
217
+ vaultConfig.admin
218
+ );
219
+ adminTokenAccount = wsolAta;
220
+
221
+ prerequisiteIxs.push(...createAtaIxs);
222
+ cleanupIxs.push(...closeAtaIxs);
223
+ } else {
224
+ adminTokenAccount = getAssociatedTokenAddressSync(
225
+ vaultConfig.tokenMint,
226
+ vaultConfig.admin,
227
+ false,
228
+ vaultConfig.tokenMintProgramId
229
+ );
230
+ }
208
231
 
209
232
  const initVaultAccounts: InitVaultAccounts = {
210
233
  adminAuthority: vaultConfig.admin,
@@ -277,7 +300,16 @@ export class KaminoVaultClient {
277
300
  ixns.push(setNameIx);
278
301
  }
279
302
 
280
- return { vault: vaultState, initVaultIxs: { initVaultIxs: ixns, createLUTIx, populateLUTIxs: insertIntoLUTIxs } };
303
+ return {
304
+ vault: vaultState,
305
+ initVaultIxs: {
306
+ createAtaIfNeededIxs: prerequisiteIxs,
307
+ initVaultIxs: ixns,
308
+ createLUTIx,
309
+ populateLUTIxs: insertIntoLUTIxs,
310
+ cleanupIxs,
311
+ },
312
+ };
281
313
  }
282
314
 
283
315
  /**