@kamino-finance/klend-sdk 5.11.18 → 5.12.1

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 (112) hide show
  1. package/dist/classes/action.d.ts +9 -1
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +15 -1
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/fraction.d.ts +6 -5
  6. package/dist/classes/fraction.d.ts.map +1 -1
  7. package/dist/classes/fraction.js +13 -8
  8. package/dist/classes/fraction.js.map +1 -1
  9. package/dist/classes/manager.d.ts +3 -2
  10. package/dist/classes/manager.d.ts.map +1 -1
  11. package/dist/classes/manager.js +13 -2
  12. package/dist/classes/manager.js.map +1 -1
  13. package/dist/classes/obligation.d.ts +54 -1
  14. package/dist/classes/obligation.d.ts.map +1 -1
  15. package/dist/classes/obligation.js +47 -1
  16. package/dist/classes/obligation.js.map +1 -1
  17. package/dist/classes/obligationOrder.d.ts +206 -0
  18. package/dist/classes/obligationOrder.d.ts.map +1 -0
  19. package/dist/classes/obligationOrder.js +359 -0
  20. package/dist/classes/obligationOrder.js.map +1 -0
  21. package/dist/classes/reserve.d.ts +5 -5
  22. package/dist/classes/reserve.d.ts.map +1 -1
  23. package/dist/classes/reserve.js +80 -264
  24. package/dist/classes/reserve.js.map +1 -1
  25. package/dist/classes/types.d.ts +14 -1
  26. package/dist/classes/types.d.ts.map +1 -1
  27. package/dist/classes/utils.d.ts +9 -0
  28. package/dist/classes/utils.d.ts.map +1 -1
  29. package/dist/classes/utils.js +21 -0
  30. package/dist/classes/utils.js.map +1 -1
  31. package/dist/classes/vault.d.ts +2 -1
  32. package/dist/classes/vault.d.ts.map +1 -1
  33. package/dist/classes/vault.js +4 -2
  34. package/dist/classes/vault.js.map +1 -1
  35. package/dist/client_kamino_manager.js +6 -6
  36. package/dist/client_kamino_manager.js.map +1 -1
  37. package/dist/idl.json +244 -23
  38. package/dist/idl_codegen/accounts/LendingMarket.d.ts +12 -6
  39. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  40. package/dist/idl_codegen/accounts/LendingMarket.js +15 -3
  41. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  42. package/dist/idl_codegen/accounts/Obligation.d.ts +27 -6
  43. package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
  44. package/dist/idl_codegen/accounts/Obligation.js +26 -9
  45. package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
  46. package/dist/idl_codegen/errors/custom.d.ts +36 -4
  47. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  48. package/dist/idl_codegen/errors/custom.js +64 -8
  49. package/dist/idl_codegen/errors/custom.js.map +1 -1
  50. package/dist/idl_codegen/instructions/index.d.ts +2 -0
  51. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  52. package/dist/idl_codegen/instructions/index.js +3 -1
  53. package/dist/idl_codegen/instructions/index.js.map +1 -1
  54. package/dist/idl_codegen/instructions/setObligationOrder.d.ts +14 -0
  55. package/dist/idl_codegen/instructions/setObligationOrder.d.ts.map +1 -0
  56. package/dist/idl_codegen/instructions/setObligationOrder.js +62 -0
  57. package/dist/idl_codegen/instructions/setObligationOrder.js.map +1 -0
  58. package/dist/idl_codegen/types/ObligationOrder.d.ts +284 -0
  59. package/dist/idl_codegen/types/ObligationOrder.d.ts.map +1 -0
  60. package/dist/idl_codegen/types/ObligationOrder.js +205 -0
  61. package/dist/idl_codegen/types/ObligationOrder.js.map +1 -0
  62. package/dist/idl_codegen/types/ReserveConfig.d.ts +26 -11
  63. package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -1
  64. package/dist/idl_codegen/types/ReserveConfig.js +15 -10
  65. package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
  66. package/dist/idl_codegen/types/UpdateConfigMode.d.ts +34 -21
  67. package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -1
  68. package/dist/idl_codegen/types/UpdateConfigMode.js +58 -34
  69. package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
  70. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
  71. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  72. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
  73. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  74. package/dist/idl_codegen/types/index.d.ts +6 -4
  75. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  76. package/dist/idl_codegen/types/index.js +3 -1
  77. package/dist/idl_codegen/types/index.js.map +1 -1
  78. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +13 -6
  79. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
  80. package/dist/idl_codegen/zero_padding/ObligationZP.js +25 -11
  81. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  82. package/dist/utils/instruction.d.ts +1 -1
  83. package/dist/utils/instruction.d.ts.map +1 -1
  84. package/dist/utils/instruction.js +5 -1
  85. package/dist/utils/instruction.js.map +1 -1
  86. package/dist/utils/managerTypes.js +2 -2
  87. package/dist/utils/managerTypes.js.map +1 -1
  88. package/package.json +1 -1
  89. package/src/classes/action.ts +26 -1
  90. package/src/classes/fraction.ts +16 -12
  91. package/src/classes/manager.ts +17 -2
  92. package/src/classes/obligation.ts +77 -1
  93. package/src/classes/obligationOrder.ts +514 -0
  94. package/src/classes/reserve.ts +257 -336
  95. package/src/classes/types.ts +15 -1
  96. package/src/classes/utils.ts +21 -0
  97. package/src/classes/vault.ts +5 -2
  98. package/src/client_kamino_manager.ts +6 -6
  99. package/src/idl.json +244 -23
  100. package/src/idl_codegen/accounts/LendingMarket.ts +23 -7
  101. package/src/idl_codegen/accounts/Obligation.ts +50 -13
  102. package/src/idl_codegen/errors/custom.ts +68 -6
  103. package/src/idl_codegen/instructions/index.ts +5 -0
  104. package/src/idl_codegen/instructions/setObligationOrder.ts +45 -0
  105. package/src/idl_codegen/types/ObligationOrder.ts +347 -0
  106. package/src/idl_codegen/types/ReserveConfig.ts +31 -16
  107. package/src/idl_codegen/types/UpdateConfigMode.ts +69 -39
  108. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
  109. package/src/idl_codegen/types/index.ts +15 -6
  110. package/src/idl_codegen/zero_padding/ObligationZP.ts +37 -15
  111. package/src/utils/instruction.ts +5 -1
  112. package/src/utils/managerTypes.ts +2 -2
@@ -1,4 +1,4 @@
1
- import { TransactionInstruction } from '@solana/web3.js';
1
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
2
2
  import Decimal from 'decimal.js/decimal';
3
3
 
4
4
  /** the populateLUTIxs should be executed in a separate transaction as we cannot create and populate a lookup table in the same tx */
@@ -62,3 +62,17 @@ export type APYs = {
62
62
  netAPY: Decimal;
63
63
  };
64
64
 
65
+ /**
66
+ * Some amount of a specific token type.
67
+ */
68
+ export type TokenAmount = {
69
+ /**
70
+ * Token's mint key.
71
+ */
72
+ mint: PublicKey;
73
+
74
+ /**
75
+ * Amount, in lamports.
76
+ */
77
+ amount: Decimal;
78
+ };
@@ -332,6 +332,27 @@ export function assertNever(x: never): never {
332
332
  throw new Error('Unexpected object: ' + x);
333
333
  }
334
334
 
335
+ export function orThrow(message: string): never {
336
+ throw new Error(message);
337
+ }
338
+
339
+ export function getSingleElement<T>(array: T[], message: string): T {
340
+ if (array.length !== 1) {
341
+ throw new Error(`${message} (found ${array.length})`);
342
+ }
343
+ return array[0];
344
+ }
345
+
346
+ /**
347
+ * Returns an integer {@link Decimal} nearest to the given one.
348
+ *
349
+ * NOTE: the `Decimal.round()` should actually be called `.trunc()` (by default, it uses floor rounding). In most cases,
350
+ * we prefer the traditional behavior (as `Math.round()`).
351
+ */
352
+ export function roundNearest(decimal: Decimal): Decimal {
353
+ return decimal.toDecimalPlaces(0, Decimal.ROUND_HALF_CEIL);
354
+ }
355
+
335
356
  /**
336
357
  * Fetch median slot duration in milliseconds from the last 10 epochs
337
358
  */
@@ -316,11 +316,13 @@ export class KaminoVaultClient {
316
316
  * This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
317
317
  * @param vault - vault to be updated
318
318
  * @param reserveAllocationConfig - new reserve allocation config
319
+ * @param [signer] - optional parameter to pass a different signer for the instruction. If not provided, the admin of the vault will be used
319
320
  * @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
320
321
  */
321
322
  async updateReserveAllocationIxs(
322
323
  vault: KaminoVault,
323
- reserveAllocationConfig: ReserveAllocationConfig
324
+ reserveAllocationConfig: ReserveAllocationConfig,
325
+ signer?: PublicKey
324
326
  ): Promise<UpdateReserveAllocationIxs> {
325
327
  const vaultState: VaultState = await vault.getState(this.getConnection());
326
328
  const reserveState: Reserve = reserveAllocationConfig.getReserveState();
@@ -331,8 +333,9 @@ export class KaminoVaultClient {
331
333
  this._kaminoVaultProgramId
332
334
  );
333
335
 
336
+ const allocationSigner = signer ? signer : vaultState.vaultAdminAuthority;
334
337
  const updateReserveAllocationAccounts: UpdateReserveAllocationAccounts = {
335
- signer: vaultState.vaultAdminAuthority,
338
+ signer: allocationSigner,
336
339
  vaultState: vault.address,
337
340
  baseVaultAuthority: vaultState.baseVaultAuthority,
338
341
  reserveCollateralMint: reserveState.collateral.mintPubkey,
@@ -1570,7 +1570,8 @@ function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
1570
1570
  liquidationThresholdPct: reserveConfigFromFile.liquidationThresholdPct,
1571
1571
  minLiquidationBonusBps: reserveConfigFromFile.minLiquidationBonusBps,
1572
1572
  protocolLiquidationFeePct: reserveConfigFromFile.protocolLiquidationFeePct,
1573
- protocolTakeRatePct: reserveConfigFromFile.protocolLiquidationFeePct,
1573
+ protocolOrderExecutionFeePct: reserveConfigFromFile.protocolOrderExecutionFeePct,
1574
+ protocolTakeRatePct: reserveConfigFromFile.protocolTakeRatePct,
1574
1575
  assetTier: reserveConfigFromFile.assetTier,
1575
1576
  maxLiquidationBonusBps: reserveConfigFromFile.maxLiquidationBonusBps,
1576
1577
  badDebtLiquidationBonusBps: reserveConfigFromFile.badDebtLiquidationBonusBps,
@@ -1621,8 +1622,7 @@ function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
1621
1622
  borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile),
1622
1623
  deleveragingBonusIncreaseBpsPerDay: new BN(reserveConfigFromFile.deleveragingBonusIncreaseBpsPerDay),
1623
1624
  reserved1: Array(1).fill(0),
1624
- reserved2: Array(2).fill(0),
1625
- reserved3: Array(8).fill(0),
1625
+ reserved2: Array(9).fill(0),
1626
1626
  };
1627
1627
 
1628
1628
  return new ReserveConfig(reserveConfigFields);
@@ -1700,7 +1700,8 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
1700
1700
  liquidationThresholdPct: reserveConfig.liquidationThresholdPct,
1701
1701
  minLiquidationBonusBps: reserveConfig.minLiquidationBonusBps,
1702
1702
  protocolLiquidationFeePct: reserveConfig.protocolLiquidationFeePct,
1703
- protocolTakeRatePct: reserveConfig.protocolLiquidationFeePct,
1703
+ protocolOrderExecutionFeePct: reserveConfig.protocolOrderExecutionFeePct,
1704
+ protocolTakeRatePct: reserveConfig.protocolTakeRatePct,
1704
1705
  assetTier: reserveConfig.assetTier,
1705
1706
  maxLiquidationBonusBps: reserveConfig.maxLiquidationBonusBps,
1706
1707
  badDebtLiquidationBonusBps: reserveConfig.badDebtLiquidationBonusBps,
@@ -1742,7 +1743,6 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
1742
1743
  reserveConfig.borrowLimitAgainstThisCollateralInElevationGroup.map((entry) => entry.toString()),
1743
1744
  deleveragingBonusIncreaseBpsPerDay: reserveConfig.deleveragingBonusIncreaseBpsPerDay.toString(),
1744
1745
  reserved1: Array(2).fill(0),
1745
- reserved2: Array(2).fill(0),
1746
- reserved3: Array(8).fill(0),
1746
+ reserved2: Array(9).fill(0),
1747
1747
  };
1748
1748
  }
package/src/idl.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.0",
2
+ "version": "1.11.0",
3
3
  "name": "kamino_lending",
4
4
  "instructions": [
5
5
  {
@@ -2900,6 +2900,38 @@
2900
2900
  ],
2901
2901
  "args": []
2902
2902
  },
2903
+ {
2904
+ "name": "setObligationOrder",
2905
+ "accounts": [
2906
+ {
2907
+ "name": "owner",
2908
+ "isMut": false,
2909
+ "isSigner": true
2910
+ },
2911
+ {
2912
+ "name": "obligation",
2913
+ "isMut": true,
2914
+ "isSigner": false
2915
+ },
2916
+ {
2917
+ "name": "lendingMarket",
2918
+ "isMut": false,
2919
+ "isSigner": false
2920
+ }
2921
+ ],
2922
+ "args": [
2923
+ {
2924
+ "name": "index",
2925
+ "type": "u8"
2926
+ },
2927
+ {
2928
+ "name": "order",
2929
+ "type": {
2930
+ "defined": "ObligationOrder"
2931
+ }
2932
+ }
2933
+ ]
2934
+ },
2903
2935
  {
2904
2936
  "name": "idlMissingTypes",
2905
2937
  "accounts": [
@@ -3165,8 +3197,7 @@
3165
3197
  "Whether the obligations on this market should be subject to auto-deleveraging after deposit",
3166
3198
  "or borrow limit is crossed.",
3167
3199
  "Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`).",
3168
- "**NOTE:** the manual \"target LTV\" deleveraging (enabled by the risk council for individual",
3169
- "obligations) is NOT affected by this flag."
3200
+ "**NOTE:** this also affects the individual \"target LTV\" deleveraging."
3170
3201
  ],
3171
3202
  "type": "u8"
3172
3203
  },
@@ -3321,12 +3352,28 @@
3321
3352
  ],
3322
3353
  "type": "u64"
3323
3354
  },
3355
+ {
3356
+ "name": "obligationOrdersEnabled",
3357
+ "docs": [
3358
+ "Whether the obligation orders should be evaluated during liquidations."
3359
+ ],
3360
+ "type": "u8"
3361
+ },
3362
+ {
3363
+ "name": "padding2",
3364
+ "type": {
3365
+ "array": [
3366
+ "u8",
3367
+ 7
3368
+ ]
3369
+ }
3370
+ },
3324
3371
  {
3325
3372
  "name": "padding1",
3326
3373
  "type": {
3327
3374
  "array": [
3328
3375
  "u64",
3329
- 170
3376
+ 169
3330
3377
  ]
3331
3378
  }
3332
3379
  }
@@ -3473,9 +3520,9 @@
3473
3520
  "type": "u8"
3474
3521
  },
3475
3522
  {
3476
- "name": "numOfObsoleteReserves",
3523
+ "name": "numOfObsoleteDepositReserves",
3477
3524
  "docs": [
3478
- "The number of deprecated reserves the obligation has a deposit"
3525
+ "The number of obsolete reserves the obligation has a deposit in"
3479
3526
  ],
3480
3527
  "type": "u8"
3481
3528
  },
@@ -3515,12 +3562,19 @@
3515
3562
  ],
3516
3563
  "type": "u8"
3517
3564
  },
3565
+ {
3566
+ "name": "numOfObsoleteBorrowReserves",
3567
+ "docs": [
3568
+ "The number of obsolete reserves the obligation has a borrow in"
3569
+ ],
3570
+ "type": "u8"
3571
+ },
3518
3572
  {
3519
3573
  "name": "reserved",
3520
3574
  "type": {
3521
3575
  "array": [
3522
3576
  "u8",
3523
- 5
3577
+ 4
3524
3578
  ]
3525
3579
  }
3526
3580
  },
@@ -3536,12 +3590,27 @@
3536
3590
  ],
3537
3591
  "type": "u64"
3538
3592
  },
3593
+ {
3594
+ "name": "orders",
3595
+ "docs": [
3596
+ "Owner-defined, liquidator-executed orders applicable to this obligation.",
3597
+ "Typical use-cases would be a stop-loss and a take-profit (possibly co-existing)."
3598
+ ],
3599
+ "type": {
3600
+ "array": [
3601
+ {
3602
+ "defined": "ObligationOrder"
3603
+ },
3604
+ 2
3605
+ ]
3606
+ }
3607
+ },
3539
3608
  {
3540
3609
  "name": "padding3",
3541
3610
  "type": {
3542
3611
  "array": [
3543
3612
  "u64",
3544
- 125
3613
+ 93
3545
3614
  ]
3546
3615
  }
3547
3616
  }
@@ -3840,7 +3909,7 @@
3840
3909
  "name": "UpdateFeesFlashLoanFee"
3841
3910
  },
3842
3911
  {
3843
- "name": "UpdateFeesReferralFeeBps"
3912
+ "name": "DeprecatedUpdateFeesReferralFeeBps"
3844
3913
  },
3845
3914
  {
3846
3915
  "name": "UpdateDepositLimit"
@@ -3900,10 +3969,10 @@
3900
3969
  "name": "UpdateDepositWithdrawalCap"
3901
3970
  },
3902
3971
  {
3903
- "name": "UpdateDebtWithdrawalCapCurrentTotal"
3972
+ "name": "DeprecatedUpdateDebtWithdrawalCapCurrentTotal"
3904
3973
  },
3905
3974
  {
3906
- "name": "UpdateDepositWithdrawalCapCurrentTotal"
3975
+ "name": "DeprecatedUpdateDepositWithdrawalCapCurrentTotal"
3907
3976
  },
3908
3977
  {
3909
3978
  "name": "UpdateBadDebtLiquidationBonusBps"
@@ -3964,6 +4033,9 @@
3964
4033
  },
3965
4034
  {
3966
4035
  "name": "UpdateDeleveragingBonusIncreaseBpsPerDay"
4036
+ },
4037
+ {
4038
+ "name": "UpdateProtocolOrderExecutionFee"
3967
4039
  }
3968
4040
  ]
3969
4041
  }
@@ -4112,6 +4184,9 @@
4112
4184
  },
4113
4185
  {
4114
4186
  "name": "UpdateInitialDepositAmount"
4187
+ },
4188
+ {
4189
+ "name": "UpdateObligationOrdersEnabled"
4115
4190
  }
4116
4191
  ]
4117
4192
  }
@@ -4344,6 +4419,134 @@
4344
4419
  ]
4345
4420
  }
4346
4421
  },
4422
+ {
4423
+ "name": "ObligationOrder",
4424
+ "docs": [
4425
+ "A single obligation order.",
4426
+ "See [Obligation::orders]."
4427
+ ],
4428
+ "type": {
4429
+ "kind": "struct",
4430
+ "fields": [
4431
+ {
4432
+ "name": "conditionThresholdSf",
4433
+ "docs": [
4434
+ "A threshold value used by the condition (scaled [Fraction]).",
4435
+ "The exact meaning depends on the specific [Self::condition_type].",
4436
+ "",
4437
+ "Examples:",
4438
+ "- when `condition_type == 2 (UserLtvBelow)`:",
4439
+ "then a value of `0.455` here means that the order is active only when the obligation's",
4440
+ "user LTV is less than `0.455` (i.e. < 45.5%).",
4441
+ "- when `condition_type == 3 (DebtCollPriceRatioAbove)`:",
4442
+ "assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here",
4443
+ "means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e.",
4444
+ "> 491.3 SOL per BTC)."
4445
+ ],
4446
+ "type": "u128"
4447
+ },
4448
+ {
4449
+ "name": "opportunityParameterSf",
4450
+ "docs": [
4451
+ "A configuration parameter used by the opportunity (scaled [Fraction]).",
4452
+ "The exact meaning depends on the specific [Self::opportunity_type].",
4453
+ "",
4454
+ "Examples:",
4455
+ "- when `opportunity_type == 0 (DeleverageSingleDebtAmount)`:",
4456
+ "Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000`",
4457
+ "here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this",
4458
+ "obligation.",
4459
+ "Note: the special value of [Fraction::MAX] is *not* allowed in this case.",
4460
+ "- when `opportunity_type == 1 (DeleverageAllDebtAmount)`:",
4461
+ "The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt",
4462
+ "should be repaid)."
4463
+ ],
4464
+ "type": "u128"
4465
+ },
4466
+ {
4467
+ "name": "minExecutionBonusBps",
4468
+ "docs": [
4469
+ "A *minimum* additional fraction of collateral transferred to the liquidator, in bps.",
4470
+ "",
4471
+ "The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and",
4472
+ "grows linearly towards the [Self::max_execution_bonus_bps].",
4473
+ "",
4474
+ "Example: a value of `50` here means 50bps == 0.5% bonus for an \"LTV > 65%\" order, when",
4475
+ "executed precisely at the moment LTV exceeds 65%."
4476
+ ],
4477
+ "type": "u16"
4478
+ },
4479
+ {
4480
+ "name": "maxExecutionBonusBps",
4481
+ "docs": [
4482
+ "A *maximum* additional fraction of collateral transferred to the liquidator, in bps.",
4483
+ "",
4484
+ "The maximum bonus is applied at the relevant \"extreme\" state of the obligation, i.e.:",
4485
+ "- for a stop-loss condition, it is a point at which the obligation becomes liquidatable;",
4486
+ "- for a take-profit condition, it is a point at which obligation has 0% LTV.",
4487
+ "",
4488
+ "In non-extreme states, the actual bonus value is interpolated linearly, starting from",
4489
+ "[Self::min_execution_bonus_bps] (at the point specified by the order's condition).",
4490
+ "",
4491
+ "Example: a value of `300` here means 300bps == 3.0% bonus for a \"debt/coll price > 140\"",
4492
+ "order, when executed at a higher price = 200, at which the obligation's LTV happens to",
4493
+ "be equal to its liquidation LTV."
4494
+ ],
4495
+ "type": "u16"
4496
+ },
4497
+ {
4498
+ "name": "conditionType",
4499
+ "docs": [
4500
+ "Serialized [ConditionType].",
4501
+ "The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]).",
4502
+ "",
4503
+ "Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to",
4504
+ "interpret this condition, we also need to take the [Self::condition_threshold_sf] into",
4505
+ "account."
4506
+ ],
4507
+ "type": "u8"
4508
+ },
4509
+ {
4510
+ "name": "opportunityType",
4511
+ "docs": [
4512
+ "Serialized [OpportunityType].",
4513
+ "",
4514
+ "Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to",
4515
+ "interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into",
4516
+ "account."
4517
+ ],
4518
+ "type": "u8"
4519
+ },
4520
+ {
4521
+ "name": "padding1",
4522
+ "docs": [
4523
+ "Internal padding.",
4524
+ "The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to",
4525
+ "align with `u128`s."
4526
+ ],
4527
+ "type": {
4528
+ "array": [
4529
+ "u8",
4530
+ 10
4531
+ ]
4532
+ }
4533
+ },
4534
+ {
4535
+ "name": "padding2",
4536
+ "docs": [
4537
+ "End padding.",
4538
+ "The total size of a single instance is 8*u128 = 128 bytes."
4539
+ ],
4540
+ "type": {
4541
+ "array": [
4542
+ "u128",
4543
+ 5
4544
+ ]
4545
+ }
4546
+ }
4547
+ ]
4548
+ }
4549
+ },
4347
4550
  {
4348
4551
  "name": "AssetTier",
4349
4552
  "type": {
@@ -4486,26 +4689,24 @@
4486
4689
  {
4487
4690
  "name": "reserved2",
4488
4691
  "docs": [
4489
- "[DEPRECATED] Boost for side (debt or collateral)"
4692
+ "[DEPRECATED] Space that used to hold 2 fields:",
4693
+ "- Boost for side (debt or collateral)",
4694
+ "- Reward points multiplier per obligation type",
4695
+ "Can be re-used after making sure all underlying production account data is zeroed."
4490
4696
  ],
4491
4697
  "type": {
4492
4698
  "array": [
4493
4699
  "u8",
4494
- 2
4700
+ 9
4495
4701
  ]
4496
4702
  }
4497
4703
  },
4498
4704
  {
4499
- "name": "reserved3",
4705
+ "name": "protocolOrderExecutionFeePct",
4500
4706
  "docs": [
4501
- "[DEPRECATED] Reward points multiplier per obligation type"
4707
+ "Cut of the order execution bonus that the protocol receives, as a percentage"
4502
4708
  ],
4503
- "type": {
4504
- "array": [
4505
- "u8",
4506
- 8
4507
- ]
4508
- }
4709
+ "type": "u8"
4509
4710
  },
4510
4711
  {
4511
4712
  "name": "protocolTakeRatePct",
@@ -5619,8 +5820,8 @@
5619
5820
  },
5620
5821
  {
5621
5822
  "code": 6084,
5622
- "name": "ObligationInDeprecatedReserve",
5623
- "msg": "Obligation has a deposit in a deprecated reserve"
5823
+ "name": "ObligationInObsoleteReserve",
5824
+ "msg": "Obligation has a deposit or borrow in an obsolete reserve"
5624
5825
  },
5625
5826
  {
5626
5827
  "code": 6085,
@@ -5811,6 +6012,26 @@
5811
6012
  "code": 6122,
5812
6013
  "name": "InsufficientRepayAmount",
5813
6014
  "msg": "Liquidator provided repay amount lower than required by liquidation rules"
6015
+ },
6016
+ {
6017
+ "code": 6123,
6018
+ "name": "OrderIndexOutOfBounds",
6019
+ "msg": "Obligation order of the given index cannot exist"
6020
+ },
6021
+ {
6022
+ "code": 6124,
6023
+ "name": "InvalidOrderConfiguration",
6024
+ "msg": "Given order configuration has wrong parameters"
6025
+ },
6026
+ {
6027
+ "code": 6125,
6028
+ "name": "OrderConfigurationNotSupportedByObligation",
6029
+ "msg": "Given order configuration cannot be used with the current state of the obligation"
6030
+ },
6031
+ {
6032
+ "code": 6126,
6033
+ "name": "OperationNotPermittedWithCurrentObligationOrders",
6034
+ "msg": "Single debt, single collateral obligation orders have to be cancelled before changing the deposit/borrow count"
5814
6035
  }
5815
6036
  ]
5816
6037
  }
@@ -25,8 +25,7 @@ export interface LendingMarketFields {
25
25
  * Whether the obligations on this market should be subject to auto-deleveraging after deposit
26
26
  * or borrow limit is crossed.
27
27
  * Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`).
28
- * **NOTE:** the manual "target LTV" deleveraging (enabled by the risk council for individual
29
- * obligations) is NOT affected by this flag.
28
+ * **NOTE:** this also affects the individual "target LTV" deleveraging.
30
29
  */
31
30
  autodeleverageEnabled: number
32
31
  borrowDisabled: number
@@ -73,6 +72,9 @@ export interface LendingMarketFields {
73
72
  * Note: this amount cannot be recovered, the ctoken associated are never minted
74
73
  */
75
74
  minInitialDepositAmount: BN
75
+ /** Whether the obligation orders should be evaluated during liquidations. */
76
+ obligationOrdersEnabled: number
77
+ padding2: Array<number>
76
78
  padding1: Array<BN>
77
79
  }
78
80
 
@@ -97,8 +99,7 @@ export interface LendingMarketJSON {
97
99
  * Whether the obligations on this market should be subject to auto-deleveraging after deposit
98
100
  * or borrow limit is crossed.
99
101
  * Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`).
100
- * **NOTE:** the manual "target LTV" deleveraging (enabled by the risk council for individual
101
- * obligations) is NOT affected by this flag.
102
+ * **NOTE:** this also affects the individual "target LTV" deleveraging.
102
103
  */
103
104
  autodeleverageEnabled: number
104
105
  borrowDisabled: number
@@ -145,6 +146,9 @@ export interface LendingMarketJSON {
145
146
  * Note: this amount cannot be recovered, the ctoken associated are never minted
146
147
  */
147
148
  minInitialDepositAmount: string
149
+ /** Whether the obligation orders should be evaluated during liquidations. */
150
+ obligationOrdersEnabled: number
151
+ padding2: Array<number>
148
152
  padding1: Array<string>
149
153
  }
150
154
 
@@ -169,8 +173,7 @@ export class LendingMarket {
169
173
  * Whether the obligations on this market should be subject to auto-deleveraging after deposit
170
174
  * or borrow limit is crossed.
171
175
  * Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`).
172
- * **NOTE:** the manual "target LTV" deleveraging (enabled by the risk council for individual
173
- * obligations) is NOT affected by this flag.
176
+ * **NOTE:** this also affects the individual "target LTV" deleveraging.
174
177
  */
175
178
  readonly autodeleverageEnabled: number
176
179
  readonly borrowDisabled: number
@@ -217,6 +220,9 @@ export class LendingMarket {
217
220
  * Note: this amount cannot be recovered, the ctoken associated are never minted
218
221
  */
219
222
  readonly minInitialDepositAmount: BN
223
+ /** Whether the obligation orders should be evaluated during liquidations. */
224
+ readonly obligationOrdersEnabled: number
225
+ readonly padding2: Array<number>
220
226
  readonly padding1: Array<BN>
221
227
 
222
228
  static readonly discriminator = Buffer.from([
@@ -250,7 +256,9 @@ export class LendingMarket {
250
256
  borsh.u64("minValueSkipLiquidationBfChecks"),
251
257
  borsh.u64("individualAutodeleverageMarginCallPeriodSecs"),
252
258
  borsh.u64("minInitialDepositAmount"),
253
- borsh.array(borsh.u64(), 170, "padding1"),
259
+ borsh.u8("obligationOrdersEnabled"),
260
+ borsh.array(borsh.u8(), 7, "padding2"),
261
+ borsh.array(borsh.u64(), 169, "padding1"),
254
262
  ])
255
263
 
256
264
  constructor(fields: LendingMarketFields) {
@@ -288,6 +296,8 @@ export class LendingMarket {
288
296
  this.individualAutodeleverageMarginCallPeriodSecs =
289
297
  fields.individualAutodeleverageMarginCallPeriodSecs
290
298
  this.minInitialDepositAmount = fields.minInitialDepositAmount
299
+ this.obligationOrdersEnabled = fields.obligationOrdersEnabled
300
+ this.padding2 = fields.padding2
291
301
  this.padding1 = fields.padding1
292
302
  }
293
303
 
@@ -367,6 +377,8 @@ export class LendingMarket {
367
377
  individualAutodeleverageMarginCallPeriodSecs:
368
378
  dec.individualAutodeleverageMarginCallPeriodSecs,
369
379
  minInitialDepositAmount: dec.minInitialDepositAmount,
380
+ obligationOrdersEnabled: dec.obligationOrdersEnabled,
381
+ padding2: dec.padding2,
370
382
  padding1: dec.padding1,
371
383
  })
372
384
  }
@@ -406,6 +418,8 @@ export class LendingMarket {
406
418
  individualAutodeleverageMarginCallPeriodSecs:
407
419
  this.individualAutodeleverageMarginCallPeriodSecs.toString(),
408
420
  minInitialDepositAmount: this.minInitialDepositAmount.toString(),
421
+ obligationOrdersEnabled: this.obligationOrdersEnabled,
422
+ padding2: this.padding2,
409
423
  padding1: this.padding1.map((item) => item.toString()),
410
424
  }
411
425
  }
@@ -452,6 +466,8 @@ export class LendingMarket {
452
466
  obj.individualAutodeleverageMarginCallPeriodSecs
453
467
  ),
454
468
  minInitialDepositAmount: new BN(obj.minInitialDepositAmount),
469
+ obligationOrdersEnabled: obj.obligationOrdersEnabled,
470
+ padding2: obj.padding2,
455
471
  padding1: obj.padding1.map((item) => new BN(item)),
456
472
  })
457
473
  }