@kamino-finance/klend-sdk 5.11.2-beta.0 → 5.11.2

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 (72) hide show
  1. package/dist/classes/action.d.ts +2 -12
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +29 -245
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/lut_utils.d.ts +29 -0
  6. package/dist/classes/lut_utils.d.ts.map +1 -0
  7. package/dist/classes/lut_utils.js +62 -0
  8. package/dist/classes/lut_utils.js.map +1 -0
  9. package/dist/classes/obligation.d.ts +1 -1
  10. package/dist/classes/obligation.d.ts.map +1 -1
  11. package/dist/classes/obligation.js +1 -1
  12. package/dist/classes/obligation.js.map +1 -1
  13. package/dist/classes/vault.js +18 -18
  14. package/dist/classes/vault.js.map +1 -1
  15. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -3
  16. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  17. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +6 -6
  18. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  19. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
  20. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
  21. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
  22. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
  23. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
  24. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
  25. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
  26. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
  27. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
  28. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
  29. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
  30. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
  31. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
  32. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
  33. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
  34. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
  35. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
  36. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
  37. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
  38. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
  39. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  40. package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
  41. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  42. package/dist/lending_operations/repay_with_collateral_operations.d.ts +0 -5
  43. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  44. package/dist/lending_operations/repay_with_collateral_operations.js +1 -26
  45. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  46. package/dist/utils/lookupTable.d.ts +0 -27
  47. package/dist/utils/lookupTable.d.ts.map +1 -1
  48. package/dist/utils/lookupTable.js +0 -58
  49. package/dist/utils/lookupTable.js.map +1 -1
  50. package/dist/utils/seeds.d.ts +1 -11
  51. package/dist/utils/seeds.d.ts.map +1 -1
  52. package/dist/utils/seeds.js +3 -13
  53. package/dist/utils/seeds.js.map +1 -1
  54. package/dist/utils/userMetadata.js +6 -6
  55. package/dist/utils/userMetadata.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/classes/action.ts +49 -378
  58. package/src/classes/lut_utils.ts +63 -0
  59. package/src/classes/obligation.ts +1 -1
  60. package/src/classes/vault.ts +15 -15
  61. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +8 -8
  62. package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
  63. package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
  64. package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
  65. package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
  66. package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
  67. package/src/idl_kamino_vault.json +7 -7
  68. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
  69. package/src/lending_operations/repay_with_collateral_operations.ts +20 -63
  70. package/src/utils/lookupTable.ts +0 -62
  71. package/src/utils/seeds.ts +4 -14
  72. package/src/utils/userMetadata.ts +14 -14
@@ -0,0 +1,63 @@
1
+ import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ /**
4
+ * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
5
+ * @param payer - the owner of the lookup table
6
+ * @param slot - the current slot
7
+ * @returns - the instruction to create the lookup table and its address
8
+ */
9
+ export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
10
+ const [ixn, address] = AddressLookupTableProgram.createLookupTable({
11
+ authority: payer,
12
+ payer,
13
+ recentSlot: slot,
14
+ });
15
+
16
+ return [ixn, address];
17
+ }
18
+
19
+ /**
20
+ * This method retuns an instruction that deactivates a lookup table, which is needed to close it
21
+ * @param payer - the owner of the lookup table
22
+ * @param lookupTable - the lookup table to deactivate
23
+ * @returns - the instruction to deactivate the lookup table
24
+ */
25
+ export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
26
+ const ixn = AddressLookupTableProgram.deactivateLookupTable({
27
+ authority: payer,
28
+ lookupTable: lookupTable,
29
+ });
30
+
31
+ return ixn;
32
+ }
33
+
34
+ /**
35
+ * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
36
+ * @param payer - the owner of the lookup table
37
+ * @param lookupTable - the lookup table to close
38
+ * @returns - the instruction to close the lookup table
39
+ */
40
+ /// this require the LUT to be deactivated at least 500 blocks before
41
+ export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
42
+ const ixn = AddressLookupTableProgram.closeLookupTable({
43
+ authority: payer,
44
+ recipient: payer,
45
+ lookupTable: lookupTable,
46
+ });
47
+
48
+ return ixn;
49
+ }
50
+
51
+ /**
52
+ * Returns the accounts in a lookup table
53
+ * @param lookupTable - lookup table to get the accounts from
54
+ * @returns - an array of accounts in the lookup table
55
+ */
56
+ export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
57
+ const lutState = await connection.getAddressLookupTable(lookupTable);
58
+ if (!lutState || !lutState.value) {
59
+ throw new Error(`Lookup table ${lookupTable} not found`);
60
+ }
61
+
62
+ return lutState.value.state.addresses;
63
+ }
@@ -266,7 +266,7 @@ export class KaminoObligation {
266
266
  /**
267
267
  * @returns total borrow power of the obligation, relative to max LTV of each asset's reserve
268
268
  */
269
- getMaxAllowedBorrowValue(): Decimal {
269
+ getAllowedBorrowValue(): Decimal {
270
270
  return new Fraction(this.state.allowedBorrowValueSf).toDecimal();
271
271
  }
272
272
 
@@ -82,7 +82,7 @@ import {
82
82
  import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
83
83
  import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
84
84
  import { FarmState } from '@kamino-finance/farms-sdk/dist';
85
- import { getAccountsInLUT, initLookupTableIx } from '../utils/lookupTable';
85
+ import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
86
86
  import {
87
87
  getFarmStakeIxs,
88
88
  getFarmUnstakeAndWithdrawIxs,
@@ -293,7 +293,7 @@ export class KaminoVaultClient {
293
293
  );
294
294
 
295
295
  const updateReserveAllocationAccounts: UpdateReserveAllocationAccounts = {
296
- signer: vaultState.adminAuthority,
296
+ signer: vaultState.vaultAdminAuthority,
297
297
  vaultState: vault.address,
298
298
  baseVaultAuthority: vaultState.baseVaultAuthority,
299
299
  reserveCollateralMint: reserveState.collateral.mintPubkey,
@@ -325,7 +325,7 @@ export class KaminoVaultClient {
325
325
  accountsToAddToLUT.push(lendingMarketAuth);
326
326
 
327
327
  const insertIntoLUTIxs = await this.insertIntoLookupTableIxs(
328
- vaultState.adminAuthority,
328
+ vaultState.vaultAdminAuthority,
329
329
  vaultState.vaultLookupTable,
330
330
  accountsToAddToLUT
331
331
  );
@@ -355,12 +355,12 @@ export class KaminoVaultClient {
355
355
  const vaultState: VaultState = await vault.getState(this.getConnection());
356
356
 
357
357
  const updateVaultConfigAccs: UpdateVaultConfigAccounts = {
358
- adminAuthority: vaultState.adminAuthority,
358
+ vaultAdminAuthority: vaultState.vaultAdminAuthority,
359
359
  vaultState: vault.address,
360
360
  klendProgram: this._kaminoLendProgramId,
361
361
  };
362
362
  if (signer) {
363
- updateVaultConfigAccs.adminAuthority = signer;
363
+ updateVaultConfigAccs.vaultAdminAuthority = signer;
364
364
  }
365
365
 
366
366
  const updateVaultConfigArgs: UpdateVaultConfigArgs = {
@@ -414,7 +414,7 @@ export class KaminoVaultClient {
414
414
  if (mode.kind === new VaultConfigField.PendingVaultAdmin().kind) {
415
415
  const newPubkey = new PublicKey(value);
416
416
  const insertIntoLutIxs = await this.insertIntoLookupTableIxs(
417
- vaultState.adminAuthority,
417
+ vaultState.vaultAdminAuthority,
418
418
  vaultState.vaultLookupTable,
419
419
  [newPubkey]
420
420
  );
@@ -432,7 +432,7 @@ export class KaminoVaultClient {
432
432
  farmState!.globalConfig
433
433
  );
434
434
  const insertIntoLutIxs = await this.insertIntoLookupTableIxs(
435
- vaultState.adminAuthority,
435
+ vaultState.vaultAdminAuthority,
436
436
  vaultState.vaultLookupTable,
437
437
  keysToAddToLUT
438
438
  );
@@ -481,7 +481,7 @@ export class KaminoVaultClient {
481
481
  value: string
482
482
  ): TransactionInstruction {
483
483
  const updateVaultConfigAccs: UpdateVaultConfigAccounts = {
484
- adminAuthority: admin,
484
+ vaultAdminAuthority: admin,
485
485
  vaultState: vault,
486
486
  klendProgram: this._kaminoLendProgramId,
487
487
  };
@@ -531,7 +531,7 @@ export class KaminoVaultClient {
531
531
 
532
532
  // read the current LUT and create a new one for the new admin and backfill it
533
533
  const accountsInExistentLUT = (await getAccountsInLUT(this.getConnection(), vaultState.vaultLookupTable)).filter(
534
- (account) => !account.equals(vaultState.adminAuthority)
534
+ (account) => !account.equals(vaultState.vaultAdminAuthority)
535
535
  );
536
536
 
537
537
  const LUTIxs: TransactionInstruction[] = [];
@@ -574,7 +574,7 @@ export class KaminoVaultClient {
574
574
  const vaultState: VaultState = await vault.getState(this.getConnection());
575
575
 
576
576
  const giveUpPendingFeesAccounts: GiveUpPendingFeesAccounts = {
577
- adminAuthority: vaultState.adminAuthority,
577
+ vaultAdminAuthority: vaultState.vaultAdminAuthority,
578
578
  vaultState: vault.address,
579
579
  klendProgram: this._kaminoLendProgramId,
580
580
  };
@@ -604,7 +604,7 @@ export class KaminoVaultClient {
604
604
  ): Promise<TransactionInstruction[]> {
605
605
  const vaultState: VaultState = await vault.getState(this.getConnection());
606
606
  const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
607
- const [{ ata: adminTokenAta, createAtaIx }] = createAtasIdempotent(vaultState.adminAuthority, [
607
+ const [{ ata: adminTokenAta, createAtaIx }] = createAtasIdempotent(vaultState.vaultAdminAuthority, [
608
608
  {
609
609
  mint: vaultState.tokenMint,
610
610
  tokenProgram: TOKEN_PROGRAM_ID,
@@ -1295,7 +1295,7 @@ export class KaminoVaultClient {
1295
1295
  const lendingMarketAuth = lendingMarketAuthPda(marketAddress, this._kaminoLendProgramId)[0];
1296
1296
 
1297
1297
  const withdrawPendingFeesAccounts: WithdrawPendingFeesAccounts = {
1298
- adminAuthority: vaultState.adminAuthority,
1298
+ vaultAdminAuthority: vaultState.vaultAdminAuthority,
1299
1299
  vaultState: vault.address,
1300
1300
  reserve: reserve.address,
1301
1301
  tokenVault: vaultState.tokenVault,
@@ -1355,7 +1355,7 @@ export class KaminoVaultClient {
1355
1355
  const vaultState = await vault.getState(this.getConnection());
1356
1356
  const allAccountsToBeInserted = [
1357
1357
  vault.address,
1358
- vaultState.adminAuthority,
1358
+ vaultState.vaultAdminAuthority,
1359
1359
  vaultState.baseVaultAuthority,
1360
1360
  vaultState.tokenMint,
1361
1361
  vaultState.tokenVault,
@@ -1400,7 +1400,7 @@ export class KaminoVaultClient {
1400
1400
  let lut = vaultState.vaultLookupTable;
1401
1401
  if (lut.equals(PublicKey.default)) {
1402
1402
  const recentSlot = await this.getConnection().getSlot();
1403
- const [ixn, address] = initLookupTableIx(vaultState.adminAuthority, recentSlot);
1403
+ const [ixn, address] = initLookupTableIx(vaultState.vaultAdminAuthority, recentSlot);
1404
1404
  setupLUTIfNeededIxs.push(ixn);
1405
1405
  lut = address;
1406
1406
 
@@ -1420,7 +1420,7 @@ export class KaminoVaultClient {
1420
1420
  }
1421
1421
  ixns.push(
1422
1422
  ...(await this.insertIntoLookupTableIxs(
1423
- vaultState.adminAuthority,
1423
+ vaultState.vaultAdminAuthority,
1424
1424
  lut,
1425
1425
  allAccountsToBeInserted,
1426
1426
  overridenExistentAccounts
@@ -5,7 +5,7 @@ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-u
5
5
  import { PROGRAM_ID } from "../programId"
6
6
 
7
7
  export interface VaultStateFields {
8
- adminAuthority: PublicKey
8
+ vaultAdminAuthority: PublicKey
9
9
  baseVaultAuthority: PublicKey
10
10
  baseVaultAuthorityBump: BN
11
11
  tokenMint: PublicKey
@@ -43,7 +43,7 @@ export interface VaultStateFields {
43
43
  }
44
44
 
45
45
  export interface VaultStateJSON {
46
- adminAuthority: string
46
+ vaultAdminAuthority: string
47
47
  baseVaultAuthority: string
48
48
  baseVaultAuthorityBump: string
49
49
  tokenMint: string
@@ -81,7 +81,7 @@ export interface VaultStateJSON {
81
81
  }
82
82
 
83
83
  export class VaultState {
84
- readonly adminAuthority: PublicKey
84
+ readonly vaultAdminAuthority: PublicKey
85
85
  readonly baseVaultAuthority: PublicKey
86
86
  readonly baseVaultAuthorityBump: BN
87
87
  readonly tokenMint: PublicKey
@@ -122,7 +122,7 @@ export class VaultState {
122
122
  ])
123
123
 
124
124
  static readonly layout = borsh.struct([
125
- borsh.publicKey("adminAuthority"),
125
+ borsh.publicKey("vaultAdminAuthority"),
126
126
  borsh.publicKey("baseVaultAuthority"),
127
127
  borsh.u64("baseVaultAuthorityBump"),
128
128
  borsh.publicKey("tokenMint"),
@@ -160,7 +160,7 @@ export class VaultState {
160
160
  ])
161
161
 
162
162
  constructor(fields: VaultStateFields) {
163
- this.adminAuthority = fields.adminAuthority
163
+ this.vaultAdminAuthority = fields.vaultAdminAuthority
164
164
  this.baseVaultAuthority = fields.baseVaultAuthority
165
165
  this.baseVaultAuthorityBump = fields.baseVaultAuthorityBump
166
166
  this.tokenMint = fields.tokenMint
@@ -243,7 +243,7 @@ export class VaultState {
243
243
  const dec = VaultState.layout.decode(data.slice(8))
244
244
 
245
245
  return new VaultState({
246
- adminAuthority: dec.adminAuthority,
246
+ vaultAdminAuthority: dec.vaultAdminAuthority,
247
247
  baseVaultAuthority: dec.baseVaultAuthority,
248
248
  baseVaultAuthorityBump: dec.baseVaultAuthorityBump,
249
249
  tokenMint: dec.tokenMint,
@@ -287,7 +287,7 @@ export class VaultState {
287
287
 
288
288
  toJSON(): VaultStateJSON {
289
289
  return {
290
- adminAuthority: this.adminAuthority.toString(),
290
+ vaultAdminAuthority: this.vaultAdminAuthority.toString(),
291
291
  baseVaultAuthority: this.baseVaultAuthority.toString(),
292
292
  baseVaultAuthorityBump: this.baseVaultAuthorityBump.toString(),
293
293
  tokenMint: this.tokenMint.toString(),
@@ -329,7 +329,7 @@ export class VaultState {
329
329
 
330
330
  static fromJSON(obj: VaultStateJSON): VaultState {
331
331
  return new VaultState({
332
- adminAuthority: new PublicKey(obj.adminAuthority),
332
+ vaultAdminAuthority: new PublicKey(obj.vaultAdminAuthority),
333
333
  baseVaultAuthority: new PublicKey(obj.baseVaultAuthority),
334
334
  baseVaultAuthorityBump: new BN(obj.baseVaultAuthorityBump),
335
335
  tokenMint: new PublicKey(obj.tokenMint),
@@ -9,7 +9,7 @@ export interface GiveUpPendingFeesArgs {
9
9
  }
10
10
 
11
11
  export interface GiveUpPendingFeesAccounts {
12
- adminAuthority: PublicKey
12
+ vaultAdminAuthority: PublicKey
13
13
  vaultState: PublicKey
14
14
  klendProgram: PublicKey
15
15
  }
@@ -22,7 +22,7 @@ export function giveUpPendingFees(
22
22
  programId: PublicKey = PROGRAM_ID
23
23
  ) {
24
24
  const keys: Array<AccountMeta> = [
25
- { pubkey: accounts.adminAuthority, isSigner: true, isWritable: true },
25
+ { pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
26
26
  { pubkey: accounts.vaultState, isSigner: false, isWritable: true },
27
27
  { pubkey: accounts.klendProgram, isSigner: false, isWritable: false },
28
28
  ]
@@ -11,7 +11,7 @@ export interface InitializeSharesMetadataArgs {
11
11
  }
12
12
 
13
13
  export interface InitializeSharesMetadataAccounts {
14
- adminAuthority: PublicKey
14
+ vaultAdminAuthority: PublicKey
15
15
  vaultState: PublicKey
16
16
  sharesMint: PublicKey
17
17
  baseVaultAuthority: PublicKey
@@ -33,7 +33,7 @@ export function initializeSharesMetadata(
33
33
  programId: PublicKey = PROGRAM_ID
34
34
  ) {
35
35
  const keys: Array<AccountMeta> = [
36
- { pubkey: accounts.adminAuthority, isSigner: true, isWritable: true },
36
+ { pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
37
37
  { pubkey: accounts.vaultState, isSigner: false, isWritable: false },
38
38
  { pubkey: accounts.sharesMint, isSigner: false, isWritable: false },
39
39
  { pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: false },
@@ -11,7 +11,7 @@ export interface UpdateSharesMetadataArgs {
11
11
  }
12
12
 
13
13
  export interface UpdateSharesMetadataAccounts {
14
- adminAuthority: PublicKey
14
+ vaultAdminAuthority: PublicKey
15
15
  vaultState: PublicKey
16
16
  baseVaultAuthority: PublicKey
17
17
  sharesMetadata: PublicKey
@@ -30,7 +30,7 @@ export function updateSharesMetadata(
30
30
  programId: PublicKey = PROGRAM_ID
31
31
  ) {
32
32
  const keys: Array<AccountMeta> = [
33
- { pubkey: accounts.adminAuthority, isSigner: true, isWritable: true },
33
+ { pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
34
34
  { pubkey: accounts.vaultState, isSigner: false, isWritable: false },
35
35
  { pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: false },
36
36
  { pubkey: accounts.sharesMetadata, isSigner: false, isWritable: true },
@@ -10,7 +10,7 @@ export interface UpdateVaultConfigArgs {
10
10
  }
11
11
 
12
12
  export interface UpdateVaultConfigAccounts {
13
- adminAuthority: PublicKey
13
+ vaultAdminAuthority: PublicKey
14
14
  vaultState: PublicKey
15
15
  klendProgram: PublicKey
16
16
  }
@@ -26,7 +26,7 @@ export function updateVaultConfig(
26
26
  programId: PublicKey = PROGRAM_ID
27
27
  ) {
28
28
  const keys: Array<AccountMeta> = [
29
- { pubkey: accounts.adminAuthority, isSigner: true, isWritable: false },
29
+ { pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: false },
30
30
  { pubkey: accounts.vaultState, isSigner: false, isWritable: true },
31
31
  { pubkey: accounts.klendProgram, isSigner: false, isWritable: false },
32
32
  ]
@@ -5,7 +5,7 @@ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-u
5
5
  import { PROGRAM_ID } from "../programId"
6
6
 
7
7
  export interface WithdrawPendingFeesAccounts {
8
- adminAuthority: PublicKey
8
+ vaultAdminAuthority: PublicKey
9
9
  vaultState: PublicKey
10
10
  reserve: PublicKey
11
11
  tokenVault: PublicKey
@@ -29,7 +29,7 @@ export function withdrawPendingFees(
29
29
  programId: PublicKey = PROGRAM_ID
30
30
  ) {
31
31
  const keys: Array<AccountMeta> = [
32
- { pubkey: accounts.adminAuthority, isSigner: true, isWritable: true },
32
+ { pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
33
33
  { pubkey: accounts.vaultState, isSigner: false, isWritable: true },
34
34
  { pubkey: accounts.reserve, isSigner: false, isWritable: true },
35
35
  { pubkey: accounts.tokenVault, isSigner: false, isWritable: true },
@@ -403,7 +403,7 @@
403
403
  "name": "updateVaultConfig",
404
404
  "accounts": [
405
405
  {
406
- "name": "adminAuthority",
406
+ "name": "vaultAdminAuthority",
407
407
  "isMut": false,
408
408
  "isSigner": true
409
409
  },
@@ -435,7 +435,7 @@
435
435
  "name": "withdrawPendingFees",
436
436
  "accounts": [
437
437
  {
438
- "name": "adminAuthority",
438
+ "name": "vaultAdminAuthority",
439
439
  "isMut": true,
440
440
  "isSigner": true
441
441
  },
@@ -540,7 +540,7 @@
540
540
  "name": "giveUpPendingFees",
541
541
  "accounts": [
542
542
  {
543
- "name": "adminAuthority",
543
+ "name": "vaultAdminAuthority",
544
544
  "isMut": true,
545
545
  "isSigner": true
546
546
  },
@@ -566,7 +566,7 @@
566
566
  "name": "initializeSharesMetadata",
567
567
  "accounts": [
568
568
  {
569
- "name": "adminAuthority",
569
+ "name": "vaultAdminAuthority",
570
570
  "isMut": true,
571
571
  "isSigner": true
572
572
  },
@@ -625,7 +625,7 @@
625
625
  "name": "updateSharesMetadata",
626
626
  "accounts": [
627
627
  {
628
- "name": "adminAuthority",
628
+ "name": "vaultAdminAuthority",
629
629
  "isMut": true,
630
630
  "isSigner": true
631
631
  },
@@ -858,7 +858,7 @@
858
858
  "kind": "struct",
859
859
  "fields": [
860
860
  {
861
- "name": "adminAuthority",
861
+ "name": "vaultAdminAuthority",
862
862
  "type": "publicKey"
863
863
  },
864
864
  {
@@ -2189,4 +2189,4 @@
2189
2189
  "msg": "Wrong admin or allocation admin"
2190
2190
  }
2191
2191
  ]
2192
- }
2192
+ }
@@ -2,7 +2,6 @@ import Decimal from 'decimal.js';
2
2
  import { KaminoMarket, KaminoObligation, KaminoReserve, numberToLamportsDecimal } from '../classes';
3
3
  import { PublicKey } from '@solana/web3.js';
4
4
  import { lamportsToDecimal } from '../classes/utils';
5
- import { MaxWithdrawLtvCheck, getMaxWithdrawLtvCheck } from './repay_with_collateral_operations';
6
5
 
7
6
  export function calcRepayAmountWithSlippage(
8
7
  kaminoMarket: KaminoMarket,
@@ -103,7 +102,6 @@ export function calcMaxWithdrawCollateral(
103
102
  .filter((p) => !p.reserveAddress.equals(borrow.reserveAddress))
104
103
  .reduce((acc, b) => acc.add(b.marketValueRefreshed), new Decimal('0'));
105
104
  }
106
- const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
107
105
 
108
106
  let remainingDepositsValueWithLtv = new Decimal('0');
109
107
  if (obligation.getDeposits().length > 1) {
@@ -111,13 +109,8 @@ export function calcMaxWithdrawCollateral(
111
109
  .getDeposits()
112
110
  .filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
113
111
  .reduce((acc, d) => {
114
- const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
115
- market,
116
- market.getReserveByAddress(d.reserveAddress)!
117
- );
118
- const maxWithdrawLtv =
119
- maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
120
- return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
112
+ const { maxLtv } = obligation.getLtvForReserve(market, market.getReserveByAddress(d.reserveAddress)!);
113
+ return acc.add(d.marketValueRefreshed.mul(maxLtv));
121
114
  }, new Decimal('0'));
122
115
  }
123
116
 
@@ -130,18 +123,16 @@ export function calcMaxWithdrawCollateral(
130
123
  repayingAllDebt: repayAmountLamports.gte(borrow.amount),
131
124
  };
132
125
  } else {
133
- const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
126
+ const { maxLtv: collMaxLtv } = obligation.getLtvForReserve(
134
127
  market,
135
128
  market.getReserveByAddress(depositReserve.address)!
136
129
  );
137
- const maxWithdrawLtv =
138
- maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
139
130
  const numerator = deposit.marketValueRefreshed
140
- .mul(maxWithdrawLtv)
131
+ .mul(collMaxLtv)
141
132
  .add(remainingDepositsValueWithLtv)
142
133
  .sub(remainingBorrowsValue);
143
134
 
144
- const denominator = depositReserve.getOracleMarketPrice().mul(maxWithdrawLtv);
135
+ const denominator = depositReserve.getOracleMarketPrice().mul(collMaxLtv);
145
136
  const maxCollWithdrawAmount = numerator.div(denominator);
146
137
  const withdrawableCollLamports = maxCollWithdrawAmount.mul(depositReserve.getMintFactor()).floor();
147
138
 
@@ -56,11 +56,6 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
56
56
  quoter: SwapQuoteProvider<QuoteResponse>;
57
57
  }
58
58
 
59
- export enum MaxWithdrawLtvCheck {
60
- MAX_LTV,
61
- LIQUIDATION_THRESHOLD,
62
- }
63
-
64
59
  export async function getRepayWithCollSwapInputs<QuoteResponse>({
65
60
  collTokenMint,
66
61
  currentSlot,
@@ -217,17 +212,8 @@ export async function getRepayWithCollIxs<QuoteResponse>({
217
212
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
218
213
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
219
214
 
220
- const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
221
-
222
- if (!collReserve) {
223
- throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
224
- }
225
-
226
- const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
227
-
228
- if (!debtReserve) {
229
- throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
230
- }
215
+ const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
216
+ const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
231
217
 
232
218
  // the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
233
219
  // there is also a chance that the tx will consume debt token from the user's ata which they would not expect
@@ -317,48 +303,25 @@ async function buildRepayWithCollateralIxs(
317
303
 
318
304
  const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
319
305
 
320
- const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
321
-
322
306
  // 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
323
- let repayAndWithdrawAction;
324
- if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
325
- repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
326
- market,
327
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
328
- debtReserve.getLiquidityMint(),
329
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
330
- collReserve.getLiquidityMint(),
331
- obligation.state.owner,
332
- currentSlot,
333
- obligation,
334
- useV2Ixs,
335
- 0,
336
- false,
337
- requestElevationGroup,
338
- undefined,
339
- undefined,
340
- referrer,
341
- scopeRefresh
342
- );
343
- } else {
344
- repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
345
- market,
346
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
347
- debtReserve.getLiquidityMint(),
348
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
349
- collReserve.getLiquidityMint(),
350
- obligation.state.owner,
351
- currentSlot,
352
- obligation,
353
- 0,
354
- false,
355
- requestElevationGroup,
356
- undefined,
357
- undefined,
358
- referrer,
359
- scopeRefresh
360
- );
361
- }
307
+ const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
308
+ market,
309
+ isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
310
+ debtReserve.getLiquidityMint(),
311
+ isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
312
+ collReserve.getLiquidityMint(),
313
+ obligation.state.owner,
314
+ currentSlot,
315
+ obligation,
316
+ useV2Ixs,
317
+ 0,
318
+ false,
319
+ requestElevationGroup,
320
+ undefined,
321
+ undefined,
322
+ referrer,
323
+ scopeRefresh
324
+ );
362
325
 
363
326
  // 4. Swap collateral to debt to repay flash loan
364
327
  const { preActionIxs, swapIxs } = swapQuoteIxs;
@@ -374,9 +337,3 @@ async function buildRepayWithCollateralIxs(
374
337
  flashRepayIxn,
375
338
  ];
376
339
  }
377
-
378
- export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
379
- return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
380
- ? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
381
- : MaxWithdrawLtvCheck.MAX_LTV;
382
- };
@@ -53,65 +53,3 @@ export const extendLookupTableIxs = (
53
53
 
54
54
  return extendLookupIxs;
55
55
  };
56
-
57
- /**
58
- * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
59
- * @param payer - the owner of the lookup table
60
- * @param slot - the current slot
61
- * @returns - the instruction to create the lookup table and its address
62
- */
63
- export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
64
- const [ixn, address] = AddressLookupTableProgram.createLookupTable({
65
- authority: payer,
66
- payer,
67
- recentSlot: slot,
68
- });
69
-
70
- return [ixn, address];
71
- }
72
-
73
- /**
74
- * This method retuns an instruction that deactivates a lookup table, which is needed to close it
75
- * @param payer - the owner of the lookup table
76
- * @param lookupTable - the lookup table to deactivate
77
- * @returns - the instruction to deactivate the lookup table
78
- */
79
- export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
80
- const ixn = AddressLookupTableProgram.deactivateLookupTable({
81
- authority: payer,
82
- lookupTable: lookupTable,
83
- });
84
-
85
- return ixn;
86
- }
87
-
88
- /**
89
- * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
90
- * @param payer - the owner of the lookup table
91
- * @param lookupTable - the lookup table to close
92
- * @returns - the instruction to close the lookup table
93
- */
94
- /// this require the LUT to be deactivated at least 500 blocks before
95
- export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
96
- const ixn = AddressLookupTableProgram.closeLookupTable({
97
- authority: payer,
98
- recipient: payer,
99
- lookupTable: lookupTable,
100
- });
101
-
102
- return ixn;
103
- }
104
-
105
- /**
106
- * Returns the accounts in a lookup table
107
- * @param lookupTable - lookup table to get the accounts from
108
- * @returns - an array of accounts in the lookup table
109
- */
110
- export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
111
- const lutState = await connection.getAddressLookupTable(lookupTable);
112
- if (!lutState || !lutState.value) {
113
- throw new Error(`Lookup table ${lookupTable} not found`);
114
- }
115
-
116
- return lutState.value.state.addresses;
117
- }