@kamino-finance/klend-sdk 5.11.5-beta.0 → 5.11.6-beta.0

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 (145) hide show
  1. package/dist/classes/action.d.ts +25 -35
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +225 -350
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/index.d.ts +0 -1
  6. package/dist/classes/index.d.ts.map +1 -1
  7. package/dist/classes/index.js +0 -1
  8. package/dist/classes/index.js.map +1 -1
  9. package/dist/classes/lut_utils.d.ts +29 -0
  10. package/dist/classes/lut_utils.d.ts.map +1 -0
  11. package/dist/classes/lut_utils.js +62 -0
  12. package/dist/classes/lut_utils.js.map +1 -0
  13. package/dist/classes/manager.d.ts +1 -6
  14. package/dist/classes/manager.d.ts.map +1 -1
  15. package/dist/classes/manager.js +1 -17
  16. package/dist/classes/manager.js.map +1 -1
  17. package/dist/classes/market.d.ts +3 -3
  18. package/dist/classes/market.d.ts.map +1 -1
  19. package/dist/classes/market.js +16 -30
  20. package/dist/classes/market.js.map +1 -1
  21. package/dist/classes/obligation.d.ts +1 -3
  22. package/dist/classes/obligation.d.ts.map +1 -1
  23. package/dist/classes/obligation.js +1 -6
  24. package/dist/classes/obligation.js.map +1 -1
  25. package/dist/classes/vault.d.ts +0 -1
  26. package/dist/classes/vault.d.ts.map +1 -1
  27. package/dist/classes/vault.js +22 -25
  28. package/dist/classes/vault.js.map +1 -1
  29. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -6
  30. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  31. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +7 -13
  32. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  33. package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -25
  34. package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
  35. package/dist/idl_codegen_kamino_vault/errors/custom.js +1 -43
  36. package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
  37. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
  38. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
  39. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
  40. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
  41. package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +0 -1
  42. package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
  43. package/dist/idl_codegen_kamino_vault/instructions/initVault.js +0 -1
  44. package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
  45. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
  46. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
  47. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
  48. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
  49. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
  50. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
  51. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
  52. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
  53. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
  54. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
  55. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
  56. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
  57. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
  58. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
  59. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
  60. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
  61. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
  62. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
  63. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
  64. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
  65. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +0 -13
  66. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
  67. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +1 -25
  68. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
  69. package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
  70. package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
  71. package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
  72. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  73. package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
  74. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  75. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -9
  76. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  77. package/dist/lending_operations/repay_with_collateral_operations.js +8 -35
  78. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  79. package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
  80. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  81. package/dist/lending_operations/swap_collateral_operations.js +6 -11
  82. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  83. package/dist/leverage/operations.d.ts +7 -9
  84. package/dist/leverage/operations.d.ts.map +1 -1
  85. package/dist/leverage/operations.js +66 -78
  86. package/dist/leverage/operations.js.map +1 -1
  87. package/dist/leverage/types.d.ts +4 -4
  88. package/dist/leverage/types.d.ts.map +1 -1
  89. package/dist/utils/ObligationType.d.ts +1 -1
  90. package/dist/utils/ObligationType.d.ts.map +1 -1
  91. package/dist/utils/constants.d.ts +0 -1
  92. package/dist/utils/constants.d.ts.map +1 -1
  93. package/dist/utils/constants.js +1 -2
  94. package/dist/utils/constants.js.map +1 -1
  95. package/dist/utils/lookupTable.d.ts +0 -27
  96. package/dist/utils/lookupTable.d.ts.map +1 -1
  97. package/dist/utils/lookupTable.js +0 -58
  98. package/dist/utils/lookupTable.js.map +1 -1
  99. package/dist/utils/managerTypes.d.ts.map +1 -1
  100. package/dist/utils/managerTypes.js +52 -7
  101. package/dist/utils/managerTypes.js.map +1 -1
  102. package/dist/utils/oracle.d.ts +3 -3
  103. package/dist/utils/oracle.d.ts.map +1 -1
  104. package/dist/utils/oracle.js +3 -4
  105. package/dist/utils/oracle.js.map +1 -1
  106. package/dist/utils/seeds.d.ts +1 -11
  107. package/dist/utils/seeds.d.ts.map +1 -1
  108. package/dist/utils/seeds.js +3 -13
  109. package/dist/utils/seeds.js.map +1 -1
  110. package/dist/utils/userMetadata.d.ts.map +1 -1
  111. package/dist/utils/userMetadata.js +7 -8
  112. package/dist/utils/userMetadata.js.map +1 -1
  113. package/package.json +2 -2
  114. package/src/classes/action.ts +261 -504
  115. package/src/classes/index.ts +0 -1
  116. package/src/classes/lut_utils.ts +63 -0
  117. package/src/classes/manager.ts +1 -30
  118. package/src/classes/market.ts +25 -34
  119. package/src/classes/obligation.ts +1 -7
  120. package/src/classes/vault.ts +23 -24
  121. package/src/client.ts +3 -8
  122. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +9 -17
  123. package/src/idl_codegen_kamino_vault/errors/custom.ts +0 -42
  124. package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
  125. package/src/idl_codegen_kamino_vault/instructions/initVault.ts +0 -2
  126. package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
  127. package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +2 -2
  128. package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
  129. package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
  130. package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
  131. package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +0 -30
  132. package/src/idl_codegen_kamino_vault/types/index.ts +0 -2
  133. package/src/idl_kamino_vault.json +8 -35
  134. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
  135. package/src/lending_operations/repay_with_collateral_operations.ts +29 -76
  136. package/src/lending_operations/swap_collateral_operations.ts +7 -19
  137. package/src/leverage/operations.ts +66 -114
  138. package/src/leverage/types.ts +4 -4
  139. package/src/utils/ObligationType.ts +1 -1
  140. package/src/utils/constants.ts +0 -1
  141. package/src/utils/lookupTable.ts +0 -62
  142. package/src/utils/managerTypes.ts +52 -10
  143. package/src/utils/oracle.ts +6 -7
  144. package/src/utils/seeds.ts +4 -14
  145. package/src/utils/userMetadata.ts +15 -16
@@ -43,9 +43,6 @@ export type CustomError =
43
43
  | ManagementFeeGreaterThanMaxAllowed
44
44
  | VaultAUMZero
45
45
  | MissingReserveForBatchRefresh
46
- | MinWithdrawAmountTooBig
47
- | InvestTooSoon
48
- | WrongAdminOrAllocationAdmin
49
46
 
50
47
  export class DepositAmountsZero extends Error {
51
48
  static readonly code = 7000
@@ -531,39 +528,6 @@ export class MissingReserveForBatchRefresh extends Error {
531
528
  }
532
529
  }
533
530
 
534
- export class MinWithdrawAmountTooBig extends Error {
535
- static readonly code = 7044
536
- readonly code = 7044
537
- readonly name = "MinWithdrawAmountTooBig"
538
- readonly msg = "Min withdraw amount is too big"
539
-
540
- constructor(readonly logs?: string[]) {
541
- super("7044: Min withdraw amount is too big")
542
- }
543
- }
544
-
545
- export class InvestTooSoon extends Error {
546
- static readonly code = 7045
547
- readonly code = 7045
548
- readonly name = "InvestTooSoon"
549
- readonly msg = "Invest is called too soon after last invest"
550
-
551
- constructor(readonly logs?: string[]) {
552
- super("7045: Invest is called too soon after last invest")
553
- }
554
- }
555
-
556
- export class WrongAdminOrAllocationAdmin extends Error {
557
- static readonly code = 7046
558
- readonly code = 7046
559
- readonly name = "WrongAdminOrAllocationAdmin"
560
- readonly msg = "Wrong admin or allocation admin"
561
-
562
- constructor(readonly logs?: string[]) {
563
- super("7046: Wrong admin or allocation admin")
564
- }
565
- }
566
-
567
531
  export function fromCode(code: number, logs?: string[]): CustomError | null {
568
532
  switch (code) {
569
533
  case 7000:
@@ -654,12 +618,6 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
654
618
  return new VaultAUMZero(logs)
655
619
  case 7043:
656
620
  return new MissingReserveForBatchRefresh(logs)
657
- case 7044:
658
- return new MinWithdrawAmountTooBig(logs)
659
- case 7045:
660
- return new InvestTooSoon(logs)
661
- case 7046:
662
- return new WrongAdminOrAllocationAdmin(logs)
663
621
  }
664
622
 
665
623
  return null
@@ -9,7 +9,7 @@ export interface GiveUpPendingFeesArgs {
9
9
  }
10
10
 
11
11
  export interface GiveUpPendingFeesAccounts {
12
- vaultAdminAuthority: PublicKey
12
+ adminAuthority: 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.vaultAdminAuthority, isSigner: true, isWritable: true },
25
+ { pubkey: accounts.adminAuthority, 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,6 @@ export interface InitVaultAccounts {
11
11
  tokenVault: PublicKey
12
12
  baseTokenMint: PublicKey
13
13
  sharesMint: PublicKey
14
- adminTokenAccount: PublicKey
15
14
  systemProgram: PublicKey
16
15
  rent: PublicKey
17
16
  tokenProgram: PublicKey
@@ -29,7 +28,6 @@ export function initVault(
29
28
  { pubkey: accounts.tokenVault, isSigner: false, isWritable: true },
30
29
  { pubkey: accounts.baseTokenMint, isSigner: false, isWritable: false },
31
30
  { pubkey: accounts.sharesMint, isSigner: false, isWritable: true },
32
- { pubkey: accounts.adminTokenAccount, isSigner: false, isWritable: true },
33
31
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
34
32
  { pubkey: accounts.rent, isSigner: false, isWritable: false },
35
33
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
@@ -11,7 +11,7 @@ export interface InitializeSharesMetadataArgs {
11
11
  }
12
12
 
13
13
  export interface InitializeSharesMetadataAccounts {
14
- vaultAdminAuthority: PublicKey
14
+ adminAuthority: 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.vaultAdminAuthority, isSigner: true, isWritable: true },
36
+ { pubkey: accounts.adminAuthority, 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 },
@@ -10,7 +10,7 @@ export interface UpdateReserveAllocationArgs {
10
10
  }
11
11
 
12
12
  export interface UpdateReserveAllocationAccounts {
13
- signer: PublicKey
13
+ adminAuthority: PublicKey
14
14
  vaultState: PublicKey
15
15
  baseVaultAuthority: PublicKey
16
16
  reserveCollateralMint: PublicKey
@@ -29,7 +29,7 @@ export function updateReserveAllocation(
29
29
  programId: PublicKey = PROGRAM_ID
30
30
  ) {
31
31
  const keys: Array<AccountMeta> = [
32
- { pubkey: accounts.signer, isSigner: true, isWritable: true },
32
+ { pubkey: accounts.adminAuthority, isSigner: true, isWritable: true },
33
33
  { pubkey: accounts.vaultState, isSigner: false, isWritable: true },
34
34
  { pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: false },
35
35
  {
@@ -11,7 +11,7 @@ export interface UpdateSharesMetadataArgs {
11
11
  }
12
12
 
13
13
  export interface UpdateSharesMetadataAccounts {
14
- vaultAdminAuthority: PublicKey
14
+ adminAuthority: 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.vaultAdminAuthority, isSigner: true, isWritable: true },
33
+ { pubkey: accounts.adminAuthority, 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
- vaultAdminAuthority: PublicKey
13
+ adminAuthority: 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.vaultAdminAuthority, isSigner: true, isWritable: false },
29
+ { pubkey: accounts.adminAuthority, 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
- vaultAdminAuthority: PublicKey
8
+ adminAuthority: 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.vaultAdminAuthority, isSigner: true, isWritable: true },
32
+ { pubkey: accounts.adminAuthority, 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 },
@@ -256,29 +256,6 @@ export class Farm {
256
256
  }
257
257
  }
258
258
 
259
- export interface AllocationAdminJSON {
260
- kind: "AllocationAdmin"
261
- }
262
-
263
- export class AllocationAdmin {
264
- static readonly discriminator = 11
265
- static readonly kind = "AllocationAdmin"
266
- readonly discriminator = 11
267
- readonly kind = "AllocationAdmin"
268
-
269
- toJSON(): AllocationAdminJSON {
270
- return {
271
- kind: "AllocationAdmin",
272
- }
273
- }
274
-
275
- toEncodable() {
276
- return {
277
- AllocationAdmin: {},
278
- }
279
- }
280
- }
281
-
282
259
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
260
  export function fromDecoded(obj: any): types.VaultConfigFieldKind {
284
261
  if (typeof obj !== "object") {
@@ -318,9 +295,6 @@ export function fromDecoded(obj: any): types.VaultConfigFieldKind {
318
295
  if ("Farm" in obj) {
319
296
  return new Farm()
320
297
  }
321
- if ("AllocationAdmin" in obj) {
322
- return new AllocationAdmin()
323
- }
324
298
 
325
299
  throw new Error("Invalid enum object")
326
300
  }
@@ -362,9 +336,6 @@ export function fromJSON(
362
336
  case "Farm": {
363
337
  return new Farm()
364
338
  }
365
- case "AllocationAdmin": {
366
- return new AllocationAdmin()
367
- }
368
339
  }
369
340
  }
370
341
 
@@ -381,7 +352,6 @@ export function layout(property?: string) {
381
352
  borsh.struct([], "Name"),
382
353
  borsh.struct([], "LookupTable"),
383
354
  borsh.struct([], "Farm"),
384
- borsh.struct([], "AllocationAdmin"),
385
355
  ])
386
356
  if (property !== undefined) {
387
357
  return ret.replicate(property)
@@ -63,7 +63,6 @@ export type VaultConfigFieldKind =
63
63
  | VaultConfigField.Name
64
64
  | VaultConfigField.LookupTable
65
65
  | VaultConfigField.Farm
66
- | VaultConfigField.AllocationAdmin
67
66
  export type VaultConfigFieldJSON =
68
67
  | VaultConfigField.PerformanceFeeBpsJSON
69
68
  | VaultConfigField.ManagementFeeBpsJSON
@@ -76,7 +75,6 @@ export type VaultConfigFieldJSON =
76
75
  | VaultConfigField.NameJSON
77
76
  | VaultConfigField.LookupTableJSON
78
77
  | VaultConfigField.FarmJSON
79
- | VaultConfigField.AllocationAdminJSON
80
78
 
81
79
  export { VaultAllocation } from "./VaultAllocation"
82
80
  export type {
@@ -35,11 +35,6 @@
35
35
  "isMut": true,
36
36
  "isSigner": false
37
37
  },
38
- {
39
- "name": "adminTokenAccount",
40
- "isMut": true,
41
- "isSigner": false
42
- },
43
38
  {
44
39
  "name": "systemProgram",
45
40
  "isMut": false,
@@ -67,7 +62,7 @@
67
62
  "name": "updateReserveAllocation",
68
63
  "accounts": [
69
64
  {
70
- "name": "signer",
65
+ "name": "adminAuthority",
71
66
  "isMut": true,
72
67
  "isSigner": true
73
68
  },
@@ -403,7 +398,7 @@
403
398
  "name": "updateVaultConfig",
404
399
  "accounts": [
405
400
  {
406
- "name": "vaultAdminAuthority",
401
+ "name": "adminAuthority",
407
402
  "isMut": false,
408
403
  "isSigner": true
409
404
  },
@@ -435,7 +430,7 @@
435
430
  "name": "withdrawPendingFees",
436
431
  "accounts": [
437
432
  {
438
- "name": "vaultAdminAuthority",
433
+ "name": "adminAuthority",
439
434
  "isMut": true,
440
435
  "isSigner": true
441
436
  },
@@ -540,7 +535,7 @@
540
535
  "name": "giveUpPendingFees",
541
536
  "accounts": [
542
537
  {
543
- "name": "vaultAdminAuthority",
538
+ "name": "adminAuthority",
544
539
  "isMut": true,
545
540
  "isSigner": true
546
541
  },
@@ -566,7 +561,7 @@
566
561
  "name": "initializeSharesMetadata",
567
562
  "accounts": [
568
563
  {
569
- "name": "vaultAdminAuthority",
564
+ "name": "adminAuthority",
570
565
  "isMut": true,
571
566
  "isSigner": true
572
567
  },
@@ -625,7 +620,7 @@
625
620
  "name": "updateSharesMetadata",
626
621
  "accounts": [
627
622
  {
628
- "name": "vaultAdminAuthority",
623
+ "name": "adminAuthority",
629
624
  "isMut": true,
630
625
  "isSigner": true
631
626
  },
@@ -858,7 +853,7 @@
858
853
  "kind": "struct",
859
854
  "fields": [
860
855
  {
861
- "name": "vaultAdminAuthority",
856
+ "name": "adminAuthority",
862
857
  "type": "publicKey"
863
858
  },
864
859
  {
@@ -1001,16 +996,12 @@
1001
996
  "name": "padding1",
1002
997
  "type": "u64"
1003
998
  },
1004
- {
1005
- "name": "allocationAdmin",
1006
- "type": "publicKey"
1007
- },
1008
999
  {
1009
1000
  "name": "padding2",
1010
1001
  "type": {
1011
1002
  "array": [
1012
1003
  "u128",
1013
- 242
1004
+ 244
1014
1005
  ]
1015
1006
  }
1016
1007
  }
@@ -1883,9 +1874,6 @@
1883
1874
  },
1884
1875
  {
1885
1876
  "name": "Farm"
1886
- },
1887
- {
1888
- "name": "AllocationAdmin"
1889
1877
  }
1890
1878
  ]
1891
1879
  }
@@ -2172,21 +2160,6 @@
2172
2160
  "code": 7043,
2173
2161
  "name": "MissingReserveForBatchRefresh",
2174
2162
  "msg": "Missing reserve for batch refresh"
2175
- },
2176
- {
2177
- "code": 7044,
2178
- "name": "MinWithdrawAmountTooBig",
2179
- "msg": "Min withdraw amount is too big"
2180
- },
2181
- {
2182
- "code": 7045,
2183
- "name": "InvestTooSoon",
2184
- "msg": "Invest is called too soon after last invest"
2185
- },
2186
- {
2187
- "code": 7046,
2188
- "name": "WrongAdminOrAllocationAdmin",
2189
- "msg": "Wrong admin or allocation admin"
2190
2163
  }
2191
2164
  ]
2192
2165
  }
@@ -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
 
@@ -6,13 +6,12 @@ import {
6
6
  SwapIxs,
7
7
  SwapIxsProvider,
8
8
  SwapQuoteProvider,
9
- getScopeRefreshIx,
10
9
  } from '../leverage';
11
10
  import {
12
11
  createAtasIdempotent,
13
12
  getComputeBudgetAndPriorityFeeIxns,
14
13
  removeBudgetAndAtaIxns,
15
- ScopePriceRefreshConfig,
14
+ ScopeRefresh,
16
15
  U64_MAX,
17
16
  uniqueAccounts,
18
17
  } from '../utils';
@@ -52,16 +51,11 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
52
51
  repayAmount: Decimal;
53
52
  isClosingPosition: boolean;
54
53
  budgetAndPriorityFeeIxs?: TransactionInstruction[];
55
- scopeRefreshConfig?: ScopePriceRefreshConfig;
54
+ scopeRefresh?: ScopeRefresh;
56
55
  useV2Ixs: boolean;
57
56
  quoter: SwapQuoteProvider<QuoteResponse>;
58
57
  }
59
58
 
60
- export enum MaxWithdrawLtvCheck {
61
- MAX_LTV,
62
- LIQUIDATION_THRESHOLD,
63
- }
64
-
65
59
  export async function getRepayWithCollSwapInputs<QuoteResponse>({
66
60
  collTokenMint,
67
61
  currentSlot,
@@ -73,7 +67,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
73
67
  repayAmount,
74
68
  isClosingPosition,
75
69
  budgetAndPriorityFeeIxs,
76
- scopeRefreshConfig,
70
+ scopeRefresh,
77
71
  useV2Ixs,
78
72
  }: RepayWithCollSwapInputsProps<QuoteResponse>): Promise<{
79
73
  swapInputs: SwapInputs;
@@ -132,7 +126,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
132
126
  referrer,
133
127
  currentSlot,
134
128
  budgetAndPriorityFeeIxs,
135
- scopeRefreshConfig,
129
+ scopeRefresh,
136
130
  {
137
131
  preActionIxs: [],
138
132
  swapIxs: [],
@@ -197,7 +191,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
197
191
  quoter,
198
192
  swapper,
199
193
  referrer,
200
- scopeRefreshConfig,
194
+ scopeRefresh,
201
195
  useV2Ixs,
202
196
  logger = console.log,
203
197
  }: RepayWithCollIxsProps<QuoteResponse>): Promise<RepayWithCollIxsResponse<QuoteResponse>> {
@@ -212,23 +206,14 @@ export async function getRepayWithCollIxs<QuoteResponse>({
212
206
  repayAmount,
213
207
  isClosingPosition,
214
208
  budgetAndPriorityFeeIxs,
215
- scopeRefreshConfig,
209
+ scopeRefresh,
216
210
  useV2Ixs,
217
211
  });
218
212
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
219
213
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
220
214
 
221
- const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
222
-
223
- if (!collReserve) {
224
- throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
225
- }
226
-
227
- const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
228
-
229
- if (!debtReserve) {
230
- throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
231
- }
215
+ const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
216
+ const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
232
217
 
233
218
  // the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
234
219
  // there is also a chance that the tx will consume debt token from the user's ata which they would not expect
@@ -259,7 +244,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
259
244
  referrer,
260
245
  currentSlot,
261
246
  budgetAndPriorityFeeIxs,
262
- scopeRefreshConfig,
247
+ scopeRefresh,
263
248
  swapResponse,
264
249
  isClosingPosition,
265
250
  debtRepayAmountLamports,
@@ -283,7 +268,7 @@ async function buildRepayWithCollateralIxs(
283
268
  referrer: PublicKey,
284
269
  currentSlot: number,
285
270
  budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
286
- scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
271
+ scopeRefresh: ScopeRefresh | undefined,
287
272
  swapQuoteIxs: SwapIxs,
288
273
  isClosingPosition: boolean,
289
274
  debtRepayAmountLamports: Decimal,
@@ -301,11 +286,9 @@ async function buildRepayWithCollateralIxs(
301
286
  const atasAndIxs = createAtasIdempotent(obligation.state.owner, atas);
302
287
  const [, { ata: debtTokenAta }] = atasAndIxs;
303
288
 
304
- const scopeRefreshIxn = await getScopeRefreshIx(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
305
-
306
289
  // 2. Flash borrow & repay the debt to repay amount needed
307
290
  const { flashBorrowIxn, flashRepayIxn } = getFlashLoanInstructions({
308
- borrowIxnIndex: budgetIxns.length + atasAndIxs.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
291
+ borrowIxnIndex: budgetIxns.length + atasAndIxs.length,
309
292
  walletPublicKey: obligation.state.owner,
310
293
  lendingMarketAuthority: market.getLendingMarketAuthority(),
311
294
  lendingMarketAddress: market.getAddress(),
@@ -320,55 +303,31 @@ async function buildRepayWithCollateralIxs(
320
303
 
321
304
  const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
322
305
 
323
- const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
324
-
325
306
  // 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
326
- let repayAndWithdrawAction;
327
- if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
328
- repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
329
- market,
330
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
331
- debtReserve.getLiquidityMint(),
332
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
333
- collReserve.getLiquidityMint(),
334
- obligation.state.owner,
335
- currentSlot,
336
- obligation,
337
- useV2Ixs,
338
- undefined,
339
- 0,
340
- false,
341
- requestElevationGroup,
342
- undefined,
343
- undefined,
344
- referrer
345
- );
346
- } else {
347
- repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
348
- market,
349
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
350
- debtReserve.getLiquidityMint(),
351
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
352
- collReserve.getLiquidityMint(),
353
- obligation.state.owner,
354
- currentSlot,
355
- obligation,
356
- undefined,
357
- 0,
358
- false,
359
- requestElevationGroup,
360
- undefined,
361
- undefined,
362
- referrer
363
- );
364
- }
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
+ );
365
325
 
366
326
  // 4. Swap collateral to debt to repay flash loan
367
327
  const { preActionIxs, swapIxs } = swapQuoteIxs;
368
328
  const swapInstructions = removeBudgetAndAtaIxns(swapIxs, []);
369
329
 
370
330
  return [
371
- ...scopeRefreshIxn,
372
331
  ...budgetIxns,
373
332
  ...atasAndIxs.map((x) => x.createAtaIx),
374
333
  flashBorrowIxn,
@@ -378,9 +337,3 @@ async function buildRepayWithCollateralIxs(
378
337
  flashRepayIxn,
379
338
  ];
380
339
  }
381
-
382
- export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
383
- return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
384
- ? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
385
- : MaxWithdrawLtvCheck.MAX_LTV;
386
- };