@kamino-finance/klend-sdk 5.13.18-beta.0 → 5.14.0-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 (133) hide show
  1. package/dist/classes/configItems.d.ts +137 -0
  2. package/dist/classes/configItems.d.ts.map +1 -0
  3. package/dist/classes/configItems.js +143 -0
  4. package/dist/classes/configItems.js.map +1 -0
  5. package/dist/classes/farm_utils.d.ts.map +1 -1
  6. package/dist/classes/farm_utils.js +3 -10
  7. package/dist/classes/farm_utils.js.map +1 -1
  8. package/dist/classes/manager.d.ts +4 -7
  9. package/dist/classes/manager.d.ts.map +1 -1
  10. package/dist/classes/manager.js +37 -292
  11. package/dist/classes/manager.js.map +1 -1
  12. package/dist/classes/obligation.d.ts +3 -1
  13. package/dist/classes/obligation.d.ts.map +1 -1
  14. package/dist/classes/obligation.js +4 -2
  15. package/dist/classes/obligation.js.map +1 -1
  16. package/dist/classes/obligationOrder.d.ts +1 -2
  17. package/dist/classes/obligationOrder.d.ts.map +1 -1
  18. package/dist/classes/obligationOrder.js +3 -16
  19. package/dist/classes/obligationOrder.js.map +1 -1
  20. package/dist/classes/reserve.d.ts +5 -14
  21. package/dist/classes/reserve.d.ts.map +1 -1
  22. package/dist/classes/reserve.js +91 -463
  23. package/dist/classes/reserve.js.map +1 -1
  24. package/dist/classes/utils.d.ts +1 -0
  25. package/dist/classes/utils.d.ts.map +1 -1
  26. package/dist/classes/utils.js +12 -0
  27. package/dist/classes/utils.js.map +1 -1
  28. package/dist/classes/vault.d.ts +1 -1
  29. package/dist/classes/vault.d.ts.map +1 -1
  30. package/dist/classes/vault.js +4 -5
  31. package/dist/classes/vault.js.map +1 -1
  32. package/dist/client_kamino_manager.d.ts.map +1 -1
  33. package/dist/client_kamino_manager.js +27 -26
  34. package/dist/client_kamino_manager.js.map +1 -1
  35. package/dist/idl.json +186 -9
  36. package/dist/idl_codegen/accounts/GlobalConfig.d.ts +40 -0
  37. package/dist/idl_codegen/accounts/GlobalConfig.d.ts.map +1 -0
  38. package/dist/idl_codegen/accounts/GlobalConfig.js +116 -0
  39. package/dist/idl_codegen/accounts/GlobalConfig.js.map +1 -0
  40. package/dist/idl_codegen/accounts/LendingMarket.d.ts +24 -3
  41. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  42. package/dist/idl_codegen/accounts/LendingMarket.js +25 -7
  43. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  44. package/dist/idl_codegen/accounts/index.d.ts +2 -0
  45. package/dist/idl_codegen/accounts/index.d.ts.map +1 -1
  46. package/dist/idl_codegen/accounts/index.js +3 -1
  47. package/dist/idl_codegen/accounts/index.js.map +1 -1
  48. package/dist/idl_codegen/errors/custom.d.ts +25 -1
  49. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  50. package/dist/idl_codegen/errors/custom.js +43 -1
  51. package/dist/idl_codegen/errors/custom.js.map +1 -1
  52. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +2 -1
  53. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -1
  54. package/dist/idl_codegen/instructions/idlMissingTypes.js +2 -1
  55. package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
  56. package/dist/idl_codegen/instructions/index.d.ts +6 -0
  57. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  58. package/dist/idl_codegen/instructions/index.js +7 -1
  59. package/dist/idl_codegen/instructions/index.js.map +1 -1
  60. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts +10 -0
  61. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts.map +1 -0
  62. package/dist/idl_codegen/instructions/initGlobalConfig.js +19 -0
  63. package/dist/idl_codegen/instructions/initGlobalConfig.js.map +1 -0
  64. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts +13 -0
  65. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts.map +1 -0
  66. package/dist/idl_codegen/instructions/updateGlobalConfig.js +61 -0
  67. package/dist/idl_codegen/instructions/updateGlobalConfig.js.map +1 -0
  68. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts +7 -0
  69. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts.map +1 -0
  70. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js +16 -0
  71. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js.map +1 -0
  72. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +4 -3
  73. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -1
  74. package/dist/idl_codegen/instructions/updateReserveConfig.js +5 -3
  75. package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
  76. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +2 -2
  77. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -1
  78. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +2 -6
  79. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
  80. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts +32 -0
  81. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts.map +1 -0
  82. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js +108 -0
  83. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js.map +1 -0
  84. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +33 -7
  85. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  86. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +60 -12
  87. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  88. package/dist/idl_codegen/types/index.d.ts +6 -2
  89. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  90. package/dist/idl_codegen/types/index.js +3 -1
  91. package/dist/idl_codegen/types/index.js.map +1 -1
  92. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  93. package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
  94. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  95. package/dist/utils/lookupTable.d.ts.map +1 -1
  96. package/dist/utils/lookupTable.js +1 -6
  97. package/dist/utils/lookupTable.js.map +1 -1
  98. package/dist/utils/managerTypes.d.ts.map +1 -1
  99. package/dist/utils/managerTypes.js +10 -4
  100. package/dist/utils/managerTypes.js.map +1 -1
  101. package/dist/utils/seeds.d.ts +16 -0
  102. package/dist/utils/seeds.d.ts.map +1 -1
  103. package/dist/utils/seeds.js +23 -1
  104. package/dist/utils/seeds.js.map +1 -1
  105. package/package.json +1 -1
  106. package/src/classes/configItems.ts +229 -0
  107. package/src/classes/farm_utils.ts +3 -11
  108. package/src/classes/manager.ts +49 -392
  109. package/src/classes/obligation.ts +4 -9
  110. package/src/classes/obligationOrder.ts +3 -22
  111. package/src/classes/reserve.ts +119 -783
  112. package/src/classes/utils.ts +12 -0
  113. package/src/classes/vault.ts +6 -7
  114. package/src/client_kamino_manager.ts +42 -34
  115. package/src/idl.json +186 -9
  116. package/src/idl_codegen/accounts/GlobalConfig.ts +125 -0
  117. package/src/idl_codegen/accounts/LendingMarket.ts +41 -9
  118. package/src/idl_codegen/accounts/index.ts +2 -0
  119. package/src/idl_codegen/errors/custom.ts +45 -0
  120. package/src/idl_codegen/instructions/idlMissingTypes.ts +4 -2
  121. package/src/idl_codegen/instructions/index.ts +9 -0
  122. package/src/idl_codegen/instructions/initGlobalConfig.ts +30 -0
  123. package/src/idl_codegen/instructions/updateGlobalConfig.ts +47 -0
  124. package/src/idl_codegen/instructions/updateGlobalConfigAdmin.ts +24 -0
  125. package/src/idl_codegen/instructions/updateReserveConfig.ts +7 -5
  126. package/src/idl_codegen/instructions/withdrawProtocolFee.ts +4 -8
  127. package/src/idl_codegen/types/UpdateGlobalConfigMode.ts +90 -0
  128. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +73 -13
  129. package/src/idl_codegen/types/index.ts +16 -2
  130. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -2
  131. package/src/utils/lookupTable.ts +1 -7
  132. package/src/utils/managerTypes.ts +10 -4
  133. package/src/utils/seeds.ts +25 -0
@@ -73,7 +73,14 @@ export interface LendingMarketFields {
73
73
  */
74
74
  minInitialDepositAmount: BN
75
75
  /** Whether the obligation orders should be evaluated during liquidations. */
76
- obligationOrdersEnabled: number
76
+ obligationOrderExecutionEnabled: number
77
+ /** Whether the lending market is set as immutable. */
78
+ immutable: number
79
+ /**
80
+ * Whether new obligation orders can be created.
81
+ * Note: updating or cancelling existing orders is *not* affected by this flag.
82
+ */
83
+ obligationOrderCreationEnabled: number
77
84
  padding2: Array<number>
78
85
  padding1: Array<BN>
79
86
  }
@@ -147,7 +154,14 @@ export interface LendingMarketJSON {
147
154
  */
148
155
  minInitialDepositAmount: string
149
156
  /** Whether the obligation orders should be evaluated during liquidations. */
150
- obligationOrdersEnabled: number
157
+ obligationOrderExecutionEnabled: number
158
+ /** Whether the lending market is set as immutable. */
159
+ immutable: number
160
+ /**
161
+ * Whether new obligation orders can be created.
162
+ * Note: updating or cancelling existing orders is *not* affected by this flag.
163
+ */
164
+ obligationOrderCreationEnabled: number
151
165
  padding2: Array<number>
152
166
  padding1: Array<string>
153
167
  }
@@ -221,7 +235,14 @@ export class LendingMarket {
221
235
  */
222
236
  readonly minInitialDepositAmount: BN
223
237
  /** Whether the obligation orders should be evaluated during liquidations. */
224
- readonly obligationOrdersEnabled: number
238
+ readonly obligationOrderExecutionEnabled: number
239
+ /** Whether the lending market is set as immutable. */
240
+ readonly immutable: number
241
+ /**
242
+ * Whether new obligation orders can be created.
243
+ * Note: updating or cancelling existing orders is *not* affected by this flag.
244
+ */
245
+ readonly obligationOrderCreationEnabled: number
225
246
  readonly padding2: Array<number>
226
247
  readonly padding1: Array<BN>
227
248
 
@@ -256,8 +277,10 @@ export class LendingMarket {
256
277
  borsh.u64("minValueSkipLiquidationBfChecks"),
257
278
  borsh.u64("individualAutodeleverageMarginCallPeriodSecs"),
258
279
  borsh.u64("minInitialDepositAmount"),
259
- borsh.u8("obligationOrdersEnabled"),
260
- borsh.array(borsh.u8(), 7, "padding2"),
280
+ borsh.u8("obligationOrderExecutionEnabled"),
281
+ borsh.u8("immutable"),
282
+ borsh.u8("obligationOrderCreationEnabled"),
283
+ borsh.array(borsh.u8(), 5, "padding2"),
261
284
  borsh.array(borsh.u64(), 169, "padding1"),
262
285
  ])
263
286
 
@@ -296,7 +319,10 @@ export class LendingMarket {
296
319
  this.individualAutodeleverageMarginCallPeriodSecs =
297
320
  fields.individualAutodeleverageMarginCallPeriodSecs
298
321
  this.minInitialDepositAmount = fields.minInitialDepositAmount
299
- this.obligationOrdersEnabled = fields.obligationOrdersEnabled
322
+ this.obligationOrderExecutionEnabled =
323
+ fields.obligationOrderExecutionEnabled
324
+ this.immutable = fields.immutable
325
+ this.obligationOrderCreationEnabled = fields.obligationOrderCreationEnabled
300
326
  this.padding2 = fields.padding2
301
327
  this.padding1 = fields.padding1
302
328
  }
@@ -377,7 +403,9 @@ export class LendingMarket {
377
403
  individualAutodeleverageMarginCallPeriodSecs:
378
404
  dec.individualAutodeleverageMarginCallPeriodSecs,
379
405
  minInitialDepositAmount: dec.minInitialDepositAmount,
380
- obligationOrdersEnabled: dec.obligationOrdersEnabled,
406
+ obligationOrderExecutionEnabled: dec.obligationOrderExecutionEnabled,
407
+ immutable: dec.immutable,
408
+ obligationOrderCreationEnabled: dec.obligationOrderCreationEnabled,
381
409
  padding2: dec.padding2,
382
410
  padding1: dec.padding1,
383
411
  })
@@ -418,7 +446,9 @@ export class LendingMarket {
418
446
  individualAutodeleverageMarginCallPeriodSecs:
419
447
  this.individualAutodeleverageMarginCallPeriodSecs.toString(),
420
448
  minInitialDepositAmount: this.minInitialDepositAmount.toString(),
421
- obligationOrdersEnabled: this.obligationOrdersEnabled,
449
+ obligationOrderExecutionEnabled: this.obligationOrderExecutionEnabled,
450
+ immutable: this.immutable,
451
+ obligationOrderCreationEnabled: this.obligationOrderCreationEnabled,
422
452
  padding2: this.padding2,
423
453
  padding1: this.padding1.map((item) => item.toString()),
424
454
  }
@@ -466,7 +496,9 @@ export class LendingMarket {
466
496
  obj.individualAutodeleverageMarginCallPeriodSecs
467
497
  ),
468
498
  minInitialDepositAmount: new BN(obj.minInitialDepositAmount),
469
- obligationOrdersEnabled: obj.obligationOrdersEnabled,
499
+ obligationOrderExecutionEnabled: obj.obligationOrderExecutionEnabled,
500
+ immutable: obj.immutable,
501
+ obligationOrderCreationEnabled: obj.obligationOrderCreationEnabled,
470
502
  padding2: obj.padding2,
471
503
  padding1: obj.padding1.map((item) => new BN(item)),
472
504
  })
@@ -1,5 +1,7 @@
1
1
  export { UserState } from "./UserState"
2
2
  export type { UserStateFields, UserStateJSON } from "./UserState"
3
+ export { GlobalConfig } from "./GlobalConfig"
4
+ export type { GlobalConfigFields, GlobalConfigJSON } from "./GlobalConfig"
3
5
  export { LendingMarket } from "./LendingMarket"
4
6
  export type { LendingMarketFields, LendingMarketJSON } from "./LendingMarket"
5
7
  export { Obligation } from "./Obligation"
@@ -126,6 +126,9 @@ export type CustomError =
126
126
  | InvalidOrderConfiguration
127
127
  | OrderConfigurationNotSupportedByObligation
128
128
  | OperationNotPermittedWithCurrentObligationOrders
129
+ | OperationNotPermittedMarketImmutable
130
+ | OrderCreationDisabled
131
+ | NoUpgradeAuthority
129
132
 
130
133
  export class InvalidMarketAuthority extends Error {
131
134
  static readonly code = 6000
@@ -1602,6 +1605,42 @@ export class OperationNotPermittedWithCurrentObligationOrders extends Error {
1602
1605
  }
1603
1606
  }
1604
1607
 
1608
+ export class OperationNotPermittedMarketImmutable extends Error {
1609
+ static readonly code = 6127
1610
+ readonly code = 6127
1611
+ readonly name = "OperationNotPermittedMarketImmutable"
1612
+ readonly msg = "Cannot update lending market because it is set as immutable"
1613
+
1614
+ constructor(readonly logs?: string[]) {
1615
+ super("6127: Cannot update lending market because it is set as immutable")
1616
+ }
1617
+ }
1618
+
1619
+ export class OrderCreationDisabled extends Error {
1620
+ static readonly code = 6128
1621
+ readonly code = 6128
1622
+ readonly name = "OrderCreationDisabled"
1623
+ readonly msg = "Creation of new orders is disabled"
1624
+
1625
+ constructor(readonly logs?: string[]) {
1626
+ super("6128: Creation of new orders is disabled")
1627
+ }
1628
+ }
1629
+
1630
+ export class NoUpgradeAuthority extends Error {
1631
+ static readonly code = 6129
1632
+ readonly code = 6129
1633
+ readonly name = "NoUpgradeAuthority"
1634
+ readonly msg =
1635
+ "Cannot initialize global config because there is no upgrade authority to the program"
1636
+
1637
+ constructor(readonly logs?: string[]) {
1638
+ super(
1639
+ "6129: Cannot initialize global config because there is no upgrade authority to the program"
1640
+ )
1641
+ }
1642
+ }
1643
+
1605
1644
  export function fromCode(code: number, logs?: string[]): CustomError | null {
1606
1645
  switch (code) {
1607
1646
  case 6000:
@@ -1858,6 +1897,12 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
1858
1897
  return new OrderConfigurationNotSupportedByObligation(logs)
1859
1898
  case 6126:
1860
1899
  return new OperationNotPermittedWithCurrentObligationOrders(logs)
1900
+ case 6127:
1901
+ return new OperationNotPermittedMarketImmutable(logs)
1902
+ case 6128:
1903
+ return new OrderCreationDisabled(logs)
1904
+ case 6129:
1905
+ return new NoUpgradeAuthority(logs)
1861
1906
  }
1862
1907
 
1863
1908
  return null
@@ -15,7 +15,8 @@ export interface IdlMissingTypesArgs {
15
15
  }
16
16
 
17
17
  export interface IdlMissingTypesAccounts {
18
- lendingMarketOwner: PublicKey
18
+ signer: PublicKey
19
+ globalConfig: PublicKey
19
20
  lendingMarket: PublicKey
20
21
  reserve: PublicKey
21
22
  }
@@ -36,7 +37,8 @@ export function idlMissingTypes(
36
37
  programId: PublicKey = PROGRAM_ID
37
38
  ) {
38
39
  const keys: Array<AccountMeta> = [
39
- { pubkey: accounts.lendingMarketOwner, isSigner: true, isWritable: false },
40
+ { pubkey: accounts.signer, isSigner: true, isWritable: false },
41
+ { pubkey: accounts.globalConfig, isSigner: false, isWritable: false },
40
42
  { pubkey: accounts.lendingMarket, isSigner: false, isWritable: false },
41
43
  { pubkey: accounts.reserve, isSigner: false, isWritable: true },
42
44
  ]
@@ -188,6 +188,15 @@ export type {
188
188
  SetObligationOrderArgs,
189
189
  SetObligationOrderAccounts,
190
190
  } from "./setObligationOrder"
191
+ export { initGlobalConfig } from "./initGlobalConfig"
192
+ export type { InitGlobalConfigAccounts } from "./initGlobalConfig"
193
+ export { updateGlobalConfig } from "./updateGlobalConfig"
194
+ export type {
195
+ UpdateGlobalConfigArgs,
196
+ UpdateGlobalConfigAccounts,
197
+ } from "./updateGlobalConfig"
198
+ export { updateGlobalConfigAdmin } from "./updateGlobalConfigAdmin"
199
+ export type { UpdateGlobalConfigAdminAccounts } from "./updateGlobalConfigAdmin"
191
200
  export { idlMissingTypes } from "./idlMissingTypes"
192
201
  export type {
193
202
  IdlMissingTypesArgs,
@@ -0,0 +1,30 @@
1
+ import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface InitGlobalConfigAccounts {
8
+ payer: PublicKey
9
+ globalConfig: PublicKey
10
+ programData: PublicKey
11
+ systemProgram: PublicKey
12
+ rent: PublicKey
13
+ }
14
+
15
+ export function initGlobalConfig(
16
+ accounts: InitGlobalConfigAccounts,
17
+ programId: PublicKey = PROGRAM_ID
18
+ ) {
19
+ const keys: Array<AccountMeta> = [
20
+ { pubkey: accounts.payer, isSigner: true, isWritable: true },
21
+ { pubkey: accounts.globalConfig, isSigner: false, isWritable: true },
22
+ { pubkey: accounts.programData, isSigner: false, isWritable: false },
23
+ { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
24
+ { pubkey: accounts.rent, isSigner: false, isWritable: false },
25
+ ]
26
+ const identifier = Buffer.from([140, 136, 214, 48, 87, 0, 120, 255])
27
+ const data = identifier
28
+ const ix = new TransactionInstruction({ keys, programId, data })
29
+ return ix
30
+ }
@@ -0,0 +1,47 @@
1
+ import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface UpdateGlobalConfigArgs {
8
+ mode: types.UpdateGlobalConfigModeKind
9
+ value: Uint8Array
10
+ }
11
+
12
+ export interface UpdateGlobalConfigAccounts {
13
+ globalAdmin: PublicKey
14
+ globalConfig: PublicKey
15
+ }
16
+
17
+ export const layout = borsh.struct([
18
+ types.UpdateGlobalConfigMode.layout("mode"),
19
+ borsh.vecU8("value"),
20
+ ])
21
+
22
+ export function updateGlobalConfig(
23
+ args: UpdateGlobalConfigArgs,
24
+ accounts: UpdateGlobalConfigAccounts,
25
+ programId: PublicKey = PROGRAM_ID
26
+ ) {
27
+ const keys: Array<AccountMeta> = [
28
+ { pubkey: accounts.globalAdmin, isSigner: true, isWritable: false },
29
+ { pubkey: accounts.globalConfig, isSigner: false, isWritable: true },
30
+ ]
31
+ const identifier = Buffer.from([164, 84, 130, 189, 111, 58, 250, 200])
32
+ const buffer = Buffer.alloc(1000)
33
+ const len = layout.encode(
34
+ {
35
+ mode: args.mode.toEncodable(),
36
+ value: Buffer.from(
37
+ args.value.buffer,
38
+ args.value.byteOffset,
39
+ args.value.length
40
+ ),
41
+ },
42
+ buffer
43
+ )
44
+ const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len)
45
+ const ix = new TransactionInstruction({ keys, programId, data })
46
+ return ix
47
+ }
@@ -0,0 +1,24 @@
1
+ import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface UpdateGlobalConfigAdminAccounts {
8
+ pendingAdmin: PublicKey
9
+ globalConfig: PublicKey
10
+ }
11
+
12
+ export function updateGlobalConfigAdmin(
13
+ accounts: UpdateGlobalConfigAdminAccounts,
14
+ programId: PublicKey = PROGRAM_ID
15
+ ) {
16
+ const keys: Array<AccountMeta> = [
17
+ { pubkey: accounts.pendingAdmin, isSigner: true, isWritable: false },
18
+ { pubkey: accounts.globalConfig, isSigner: false, isWritable: true },
19
+ ]
20
+ const identifier = Buffer.from([184, 87, 23, 193, 156, 238, 175, 119])
21
+ const data = identifier
22
+ const ix = new TransactionInstruction({ keys, programId, data })
23
+ return ix
24
+ }
@@ -5,19 +5,20 @@ 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 UpdateReserveConfigArgs {
8
- mode: BN
8
+ mode: types.UpdateConfigModeKind
9
9
  value: Uint8Array
10
10
  skipValidation: boolean
11
11
  }
12
12
 
13
13
  export interface UpdateReserveConfigAccounts {
14
- lendingMarketOwner: PublicKey
14
+ signer: PublicKey
15
+ globalConfig: PublicKey
15
16
  lendingMarket: PublicKey
16
17
  reserve: PublicKey
17
18
  }
18
19
 
19
20
  export const layout = borsh.struct([
20
- borsh.u64("mode"),
21
+ types.UpdateConfigMode.layout("mode"),
21
22
  borsh.vecU8("value"),
22
23
  borsh.bool("skipValidation"),
23
24
  ])
@@ -28,7 +29,8 @@ export function updateReserveConfig(
28
29
  programId: PublicKey = PROGRAM_ID
29
30
  ) {
30
31
  const keys: Array<AccountMeta> = [
31
- { pubkey: accounts.lendingMarketOwner, isSigner: true, isWritable: false },
32
+ { pubkey: accounts.signer, isSigner: true, isWritable: false },
33
+ { pubkey: accounts.globalConfig, isSigner: false, isWritable: false },
32
34
  { pubkey: accounts.lendingMarket, isSigner: false, isWritable: false },
33
35
  { pubkey: accounts.reserve, isSigner: false, isWritable: true },
34
36
  ]
@@ -36,7 +38,7 @@ export function updateReserveConfig(
36
38
  const buffer = Buffer.alloc(1000)
37
39
  const len = layout.encode(
38
40
  {
39
- mode: args.mode,
41
+ mode: args.mode.toEncodable(),
40
42
  value: Buffer.from(
41
43
  args.value.buffer,
42
44
  args.value.byteOffset,
@@ -9,13 +9,13 @@ export interface WithdrawProtocolFeeArgs {
9
9
  }
10
10
 
11
11
  export interface WithdrawProtocolFeeAccounts {
12
- lendingMarketOwner: PublicKey
12
+ globalConfig: PublicKey
13
13
  lendingMarket: PublicKey
14
14
  reserve: PublicKey
15
15
  reserveLiquidityMint: PublicKey
16
16
  lendingMarketAuthority: PublicKey
17
17
  feeVault: PublicKey
18
- lendingMarketOwnerAta: PublicKey
18
+ feeCollectorAta: PublicKey
19
19
  tokenProgram: PublicKey
20
20
  }
21
21
 
@@ -27,7 +27,7 @@ export function withdrawProtocolFee(
27
27
  programId: PublicKey = PROGRAM_ID
28
28
  ) {
29
29
  const keys: Array<AccountMeta> = [
30
- { pubkey: accounts.lendingMarketOwner, isSigner: true, isWritable: false },
30
+ { pubkey: accounts.globalConfig, isSigner: false, isWritable: false },
31
31
  { pubkey: accounts.lendingMarket, isSigner: false, isWritable: false },
32
32
  { pubkey: accounts.reserve, isSigner: false, isWritable: false },
33
33
  {
@@ -41,11 +41,7 @@ export function withdrawProtocolFee(
41
41
  isWritable: false,
42
42
  },
43
43
  { pubkey: accounts.feeVault, isSigner: false, isWritable: true },
44
- {
45
- pubkey: accounts.lendingMarketOwnerAta,
46
- isSigner: false,
47
- isWritable: true,
48
- },
44
+ { pubkey: accounts.feeCollectorAta, isSigner: false, isWritable: true },
49
45
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
50
46
  ]
51
47
  const identifier = Buffer.from([158, 201, 158, 189, 33, 93, 162, 103])
@@ -0,0 +1,90 @@
1
+ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as borsh from "@coral-xyz/borsh"
5
+
6
+ export interface PendingAdminJSON {
7
+ kind: "PendingAdmin"
8
+ }
9
+
10
+ export class PendingAdmin {
11
+ static readonly discriminator = 0
12
+ static readonly kind = "PendingAdmin"
13
+ readonly discriminator = 0
14
+ readonly kind = "PendingAdmin"
15
+
16
+ toJSON(): PendingAdminJSON {
17
+ return {
18
+ kind: "PendingAdmin",
19
+ }
20
+ }
21
+
22
+ toEncodable() {
23
+ return {
24
+ PendingAdmin: {},
25
+ }
26
+ }
27
+ }
28
+
29
+ export interface FeeCollectorJSON {
30
+ kind: "FeeCollector"
31
+ }
32
+
33
+ export class FeeCollector {
34
+ static readonly discriminator = 1
35
+ static readonly kind = "FeeCollector"
36
+ readonly discriminator = 1
37
+ readonly kind = "FeeCollector"
38
+
39
+ toJSON(): FeeCollectorJSON {
40
+ return {
41
+ kind: "FeeCollector",
42
+ }
43
+ }
44
+
45
+ toEncodable() {
46
+ return {
47
+ FeeCollector: {},
48
+ }
49
+ }
50
+ }
51
+
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ export function fromDecoded(obj: any): types.UpdateGlobalConfigModeKind {
54
+ if (typeof obj !== "object") {
55
+ throw new Error("Invalid enum object")
56
+ }
57
+
58
+ if ("PendingAdmin" in obj) {
59
+ return new PendingAdmin()
60
+ }
61
+ if ("FeeCollector" in obj) {
62
+ return new FeeCollector()
63
+ }
64
+
65
+ throw new Error("Invalid enum object")
66
+ }
67
+
68
+ export function fromJSON(
69
+ obj: types.UpdateGlobalConfigModeJSON
70
+ ): types.UpdateGlobalConfigModeKind {
71
+ switch (obj.kind) {
72
+ case "PendingAdmin": {
73
+ return new PendingAdmin()
74
+ }
75
+ case "FeeCollector": {
76
+ return new FeeCollector()
77
+ }
78
+ }
79
+ }
80
+
81
+ export function layout(property?: string) {
82
+ const ret = borsh.rustEnum([
83
+ borsh.struct([], "PendingAdmin"),
84
+ borsh.struct([], "FeeCollector"),
85
+ ])
86
+ if (property !== undefined) {
87
+ return ret.replicate(property)
88
+ }
89
+ return ret
90
+ }
@@ -509,25 +509,71 @@ export class UpdateInitialDepositAmount {
509
509
  }
510
510
  }
511
511
 
512
- export interface UpdateObligationOrdersEnabledJSON {
513
- kind: "UpdateObligationOrdersEnabled"
512
+ export interface UpdateObligationOrderExecutionEnabledJSON {
513
+ kind: "UpdateObligationOrderExecutionEnabled"
514
514
  }
515
515
 
516
- export class UpdateObligationOrdersEnabled {
516
+ export class UpdateObligationOrderExecutionEnabled {
517
517
  static readonly discriminator = 22
518
- static readonly kind = "UpdateObligationOrdersEnabled"
518
+ static readonly kind = "UpdateObligationOrderExecutionEnabled"
519
519
  readonly discriminator = 22
520
- readonly kind = "UpdateObligationOrdersEnabled"
520
+ readonly kind = "UpdateObligationOrderExecutionEnabled"
521
521
 
522
- toJSON(): UpdateObligationOrdersEnabledJSON {
522
+ toJSON(): UpdateObligationOrderExecutionEnabledJSON {
523
523
  return {
524
- kind: "UpdateObligationOrdersEnabled",
524
+ kind: "UpdateObligationOrderExecutionEnabled",
525
525
  }
526
526
  }
527
527
 
528
528
  toEncodable() {
529
529
  return {
530
- UpdateObligationOrdersEnabled: {},
530
+ UpdateObligationOrderExecutionEnabled: {},
531
+ }
532
+ }
533
+ }
534
+
535
+ export interface UpdateImmutableFlagJSON {
536
+ kind: "UpdateImmutableFlag"
537
+ }
538
+
539
+ export class UpdateImmutableFlag {
540
+ static readonly discriminator = 23
541
+ static readonly kind = "UpdateImmutableFlag"
542
+ readonly discriminator = 23
543
+ readonly kind = "UpdateImmutableFlag"
544
+
545
+ toJSON(): UpdateImmutableFlagJSON {
546
+ return {
547
+ kind: "UpdateImmutableFlag",
548
+ }
549
+ }
550
+
551
+ toEncodable() {
552
+ return {
553
+ UpdateImmutableFlag: {},
554
+ }
555
+ }
556
+ }
557
+
558
+ export interface UpdateObligationOrderCreationEnabledJSON {
559
+ kind: "UpdateObligationOrderCreationEnabled"
560
+ }
561
+
562
+ export class UpdateObligationOrderCreationEnabled {
563
+ static readonly discriminator = 24
564
+ static readonly kind = "UpdateObligationOrderCreationEnabled"
565
+ readonly discriminator = 24
566
+ readonly kind = "UpdateObligationOrderCreationEnabled"
567
+
568
+ toJSON(): UpdateObligationOrderCreationEnabledJSON {
569
+ return {
570
+ kind: "UpdateObligationOrderCreationEnabled",
571
+ }
572
+ }
573
+
574
+ toEncodable() {
575
+ return {
576
+ UpdateObligationOrderCreationEnabled: {},
531
577
  }
532
578
  }
533
579
  }
@@ -604,8 +650,14 @@ export function fromDecoded(obj: any): types.UpdateLendingMarketModeKind {
604
650
  if ("UpdateInitialDepositAmount" in obj) {
605
651
  return new UpdateInitialDepositAmount()
606
652
  }
607
- if ("UpdateObligationOrdersEnabled" in obj) {
608
- return new UpdateObligationOrdersEnabled()
653
+ if ("UpdateObligationOrderExecutionEnabled" in obj) {
654
+ return new UpdateObligationOrderExecutionEnabled()
655
+ }
656
+ if ("UpdateImmutableFlag" in obj) {
657
+ return new UpdateImmutableFlag()
658
+ }
659
+ if ("UpdateObligationOrderCreationEnabled" in obj) {
660
+ return new UpdateObligationOrderCreationEnabled()
609
661
  }
610
662
 
611
663
  throw new Error("Invalid enum object")
@@ -681,8 +733,14 @@ export function fromJSON(
681
733
  case "UpdateInitialDepositAmount": {
682
734
  return new UpdateInitialDepositAmount()
683
735
  }
684
- case "UpdateObligationOrdersEnabled": {
685
- return new UpdateObligationOrdersEnabled()
736
+ case "UpdateObligationOrderExecutionEnabled": {
737
+ return new UpdateObligationOrderExecutionEnabled()
738
+ }
739
+ case "UpdateImmutableFlag": {
740
+ return new UpdateImmutableFlag()
741
+ }
742
+ case "UpdateObligationOrderCreationEnabled": {
743
+ return new UpdateObligationOrderCreationEnabled()
686
744
  }
687
745
  }
688
746
  }
@@ -711,7 +769,9 @@ export function layout(property?: string) {
711
769
  borsh.struct([], "UpdateName"),
712
770
  borsh.struct([], "UpdateIndividualAutodeleverageMarginCallPeriodSecs"),
713
771
  borsh.struct([], "UpdateInitialDepositAmount"),
714
- borsh.struct([], "UpdateObligationOrdersEnabled"),
772
+ borsh.struct([], "UpdateObligationOrderExecutionEnabled"),
773
+ borsh.struct([], "UpdateImmutableFlag"),
774
+ borsh.struct([], "UpdateObligationOrderCreationEnabled"),
715
775
  ])
716
776
  if (property !== undefined) {
717
777
  return ret.replicate(property)
@@ -1,6 +1,7 @@
1
1
  import * as UpdateConfigMode from "./UpdateConfigMode"
2
2
  import * as UpdateLendingMarketConfigValue from "./UpdateLendingMarketConfigValue"
3
3
  import * as UpdateLendingMarketMode from "./UpdateLendingMarketMode"
4
+ import * as UpdateGlobalConfigMode from "./UpdateGlobalConfigMode"
4
5
  import * as AssetTier from "./AssetTier"
5
6
  import * as FeeCalculation from "./FeeCalculation"
6
7
  import * as ReserveFarmKind from "./ReserveFarmKind"
@@ -159,7 +160,9 @@ export type UpdateLendingMarketModeKind =
159
160
  | UpdateLendingMarketMode.UpdateName
160
161
  | UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs
161
162
  | UpdateLendingMarketMode.UpdateInitialDepositAmount
162
- | UpdateLendingMarketMode.UpdateObligationOrdersEnabled
163
+ | UpdateLendingMarketMode.UpdateObligationOrderExecutionEnabled
164
+ | UpdateLendingMarketMode.UpdateImmutableFlag
165
+ | UpdateLendingMarketMode.UpdateObligationOrderCreationEnabled
163
166
  export type UpdateLendingMarketModeJSON =
164
167
  | UpdateLendingMarketMode.UpdateOwnerJSON
165
168
  | UpdateLendingMarketMode.UpdateEmergencyModeJSON
@@ -183,7 +186,18 @@ export type UpdateLendingMarketModeJSON =
183
186
  | UpdateLendingMarketMode.UpdateNameJSON
184
187
  | UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecsJSON
185
188
  | UpdateLendingMarketMode.UpdateInitialDepositAmountJSON
186
- | UpdateLendingMarketMode.UpdateObligationOrdersEnabledJSON
189
+ | UpdateLendingMarketMode.UpdateObligationOrderExecutionEnabledJSON
190
+ | UpdateLendingMarketMode.UpdateImmutableFlagJSON
191
+ | UpdateLendingMarketMode.UpdateObligationOrderCreationEnabledJSON
192
+
193
+ export { UpdateGlobalConfigMode }
194
+
195
+ export type UpdateGlobalConfigModeKind =
196
+ | UpdateGlobalConfigMode.PendingAdmin
197
+ | UpdateGlobalConfigMode.FeeCollector
198
+ export type UpdateGlobalConfigModeJSON =
199
+ | UpdateGlobalConfigMode.PendingAdminJSON
200
+ | UpdateGlobalConfigMode.FeeCollectorJSON
187
201
 
188
202
  export { LastUpdate } from "./LastUpdate"
189
203
  export type { LastUpdateFields, LastUpdateJSON } from "./LastUpdate"
@@ -129,7 +129,10 @@ export function calcMaxWithdrawCollateral(
129
129
  .getDeposits()
130
130
  .filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
131
131
  .reduce((acc, d) => {
132
- const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(market, d.reserveAddress);
132
+ const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
133
+ market,
134
+ market.getExistingReserveByAddress(d.reserveAddress)
135
+ );
133
136
  const maxWithdrawLtv =
134
137
  maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
135
138
  return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
@@ -147,7 +150,7 @@ export function calcMaxWithdrawCollateral(
147
150
  } else {
148
151
  const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
149
152
  market,
150
- depositReserve.address
153
+ market.getReserveByAddress(depositReserve.address)!
151
154
  );
152
155
  const maxWithdrawLtv =
153
156
  maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;