@exponent-labs/kamino-reserve-deserializer 0.0.3

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 (71) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/fraction.d.ts +23 -0
  3. package/build/fraction.js +61 -0
  4. package/build/fraction.js.map +1 -0
  5. package/build/index.d.ts +102 -0
  6. package/build/index.js +214 -0
  7. package/build/index.js.map +1 -0
  8. package/build/types/BigFractionBytes.d.ts +26 -0
  9. package/build/types/BigFractionBytes.js +72 -0
  10. package/build/types/BigFractionBytes.js.map +1 -0
  11. package/build/types/BorrowRateCurve.d.ts +27 -0
  12. package/build/types/BorrowRateCurve.js +63 -0
  13. package/build/types/BorrowRateCurve.js.map +1 -0
  14. package/build/types/CurvePoint.d.ts +25 -0
  15. package/build/types/CurvePoint.js +68 -0
  16. package/build/types/CurvePoint.js.map +1 -0
  17. package/build/types/LastUpdate.d.ts +46 -0
  18. package/build/types/LastUpdate.js +88 -0
  19. package/build/types/LastUpdate.js.map +1 -0
  20. package/build/types/PriceHeuristic.d.ts +40 -0
  21. package/build/types/PriceHeuristic.js +81 -0
  22. package/build/types/PriceHeuristic.js.map +1 -0
  23. package/build/types/PythConfiguration.d.ts +24 -0
  24. package/build/types/PythConfiguration.js +64 -0
  25. package/build/types/PythConfiguration.js.map +1 -0
  26. package/build/types/ReserveCollateral.d.ts +52 -0
  27. package/build/types/ReserveCollateral.js +101 -0
  28. package/build/types/ReserveCollateral.js.map +1 -0
  29. package/build/types/ReserveConfig.d.ts +366 -0
  30. package/build/types/ReserveConfig.js +307 -0
  31. package/build/types/ReserveConfig.js.map +1 -0
  32. package/build/types/ReserveFees.d.ts +77 -0
  33. package/build/types/ReserveFees.js +98 -0
  34. package/build/types/ReserveFees.js.map +1 -0
  35. package/build/types/ReserveLiquidity.d.ts +181 -0
  36. package/build/types/ReserveLiquidity.js +214 -0
  37. package/build/types/ReserveLiquidity.js.map +1 -0
  38. package/build/types/ScopeConfiguration.d.ts +40 -0
  39. package/build/types/ScopeConfiguration.js +82 -0
  40. package/build/types/ScopeConfiguration.js.map +1 -0
  41. package/build/types/SwitchboardConfiguration.d.ts +29 -0
  42. package/build/types/SwitchboardConfiguration.js +70 -0
  43. package/build/types/SwitchboardConfiguration.js.map +1 -0
  44. package/build/types/TokenInfo.d.ts +121 -0
  45. package/build/types/TokenInfo.js +154 -0
  46. package/build/types/TokenInfo.js.map +1 -0
  47. package/build/types/WithdrawalCaps.d.ts +37 -0
  48. package/build/types/WithdrawalCaps.js +90 -0
  49. package/build/types/WithdrawalCaps.js.map +1 -0
  50. package/build/types/index.d.ts +46 -0
  51. package/build/types/index.js +88 -0
  52. package/build/types/index.js.map +1 -0
  53. package/package.json +20 -0
  54. package/src/fraction.ts +70 -0
  55. package/src/index.ts +269 -0
  56. package/src/types/BigFractionBytes.ts +59 -0
  57. package/src/types/BorrowRateCurve.ts +53 -0
  58. package/src/types/CurvePoint.ts +58 -0
  59. package/src/types/LastUpdate.ts +88 -0
  60. package/src/types/PriceHeuristic.ts +76 -0
  61. package/src/types/PythConfiguration.ts +54 -0
  62. package/src/types/ReserveCollateral.ts +103 -0
  63. package/src/types/ReserveConfig.ts +431 -0
  64. package/src/types/ReserveFees.ts +116 -0
  65. package/src/types/ReserveLiquidity.ts +280 -0
  66. package/src/types/ScopeConfiguration.ts +83 -0
  67. package/src/types/SwitchboardConfiguration.ts +62 -0
  68. package/src/types/TokenInfo.ts +178 -0
  69. package/src/types/WithdrawalCaps.ts +84 -0
  70. package/src/types/index.ts +88 -0
  71. package/tsconfig.json +18 -0
@@ -0,0 +1,431 @@
1
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import * as borsh from "@coral-xyz/borsh"
3
+ import { ReserveFees, ReserveFeesFields, ReserveFeesJSON } from "./ReserveFees"
4
+ import { BorrowRateCurve, BorrowRateCurveFields, BorrowRateCurveJSON } from "./BorrowRateCurve"
5
+ import { TokenInfo, TokenInfoFields, TokenInfoJSON } from "./TokenInfo"
6
+ import { WithdrawalCaps, WithdrawalCapsFields, WithdrawalCapsJSON } from "./WithdrawalCaps"
7
+
8
+ export interface ReserveConfigFields {
9
+ /** Status of the reserve Active/Obsolete/Hidden */
10
+ status: number
11
+ /** Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt */
12
+ assetTier: number
13
+ /** Flat rate that goes to the host */
14
+ hostFixedInterestRateBps: number
15
+ /** [DEPRECATED] Boost for side (debt or collateral) */
16
+ reserved2: Array<number>
17
+ /** [DEPRECATED] Reward points multiplier per obligation type */
18
+ reserved3: Array<number>
19
+ /** Protocol take rate is the amount borrowed interest protocol receives, as a percentage */
20
+ protocolTakeRatePct: number
21
+ /** Cut of the liquidation bonus that the protocol receives, as a percentage */
22
+ protocolLiquidationFeePct: number
23
+ /**
24
+ * Target ratio of the value of borrows to deposits, as a percentage
25
+ * 0 if use as collateral is disabled
26
+ */
27
+ loanToValuePct: number
28
+ /** Loan to value ratio at which an obligation can be liquidated, as percentage */
29
+ liquidationThresholdPct: number
30
+ /** Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
31
+ minLiquidationBonusBps: number
32
+ /** Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
33
+ maxLiquidationBonusBps: number
34
+ /** Bad debt liquidation bonus for an undercollateralized obligation, as bps */
35
+ badDebtLiquidationBonusBps: number
36
+ /** Time in seconds that must pass before redemptions are enabled after the deposit limit is crossed */
37
+ deleveragingMarginCallPeriodSecs: BN
38
+ /**
39
+ * The rate at which the deleveraging threshold decreases in slots per bps
40
+ * e.g. 1 bps per hour would be 7200 slots per bps (assuming 2 slots per second)
41
+ */
42
+ deleveragingThresholdSlotsPerBps: BN
43
+ /** Program owner fees assessed, separate from gains due to interest accrual */
44
+ fees: ReserveFeesFields
45
+ /** Borrow rate curve based on utilization */
46
+ borrowRateCurve: BorrowRateCurveFields
47
+ /** Borrow factor in percentage - used for risk adjustment */
48
+ borrowFactorPct: BN
49
+ /** Maximum deposit limit of liquidity in native units, u64::MAX for inf */
50
+ depositLimit: BN
51
+ /** Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits) */
52
+ borrowLimit: BN
53
+ /** Token id from TokenInfos struct */
54
+ tokenInfo: TokenInfoFields
55
+ /** Deposit withdrawl caps - deposit & redeem */
56
+ depositWithdrawalCap: WithdrawalCapsFields
57
+ /** Debt withdrawl caps - borrow & repay */
58
+ debtWithdrawalCap: WithdrawalCapsFields
59
+ elevationGroups: Array<number>
60
+ disableUsageAsCollOutsideEmode: number
61
+ utilizationLimitBlockBorrowingAbove: number
62
+ reserved1: Array<number>
63
+ /**
64
+ * Maximum amount liquidity of this reserve borrowed outside all elevation groups
65
+ * - u64::MAX for inf
66
+ * - 0 to disable borrows outside elevation groups
67
+ */
68
+ borrowLimitOutsideElevationGroup: BN
69
+ /**
70
+ * Defines the maximum amount (in lamports of elevation group debt asset)
71
+ * that can be borrowed when this reserve is used as collateral.
72
+ * - u64::MAX for inf
73
+ * - 0 to disable borrows in this elevation group (expected value for the debt asset)
74
+ */
75
+ borrowLimitAgainstThisCollateralInElevationGroup: Array<BN>
76
+ }
77
+
78
+ export interface ReserveConfigJSON {
79
+ /** Status of the reserve Active/Obsolete/Hidden */
80
+ status: number
81
+ /** Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt */
82
+ assetTier: number
83
+ /** Flat rate that goes to the host */
84
+ hostFixedInterestRateBps: number
85
+ /** [DEPRECATED] Boost for side (debt or collateral) */
86
+ reserved2: Array<number>
87
+ /** [DEPRECATED] Reward points multiplier per obligation type */
88
+ reserved3: Array<number>
89
+ /** Protocol take rate is the amount borrowed interest protocol receives, as a percentage */
90
+ protocolTakeRatePct: number
91
+ /** Cut of the liquidation bonus that the protocol receives, as a percentage */
92
+ protocolLiquidationFeePct: number
93
+ /**
94
+ * Target ratio of the value of borrows to deposits, as a percentage
95
+ * 0 if use as collateral is disabled
96
+ */
97
+ loanToValuePct: number
98
+ /** Loan to value ratio at which an obligation can be liquidated, as percentage */
99
+ liquidationThresholdPct: number
100
+ /** Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
101
+ minLiquidationBonusBps: number
102
+ /** Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
103
+ maxLiquidationBonusBps: number
104
+ /** Bad debt liquidation bonus for an undercollateralized obligation, as bps */
105
+ badDebtLiquidationBonusBps: number
106
+ /** Time in seconds that must pass before redemptions are enabled after the deposit limit is crossed */
107
+ deleveragingMarginCallPeriodSecs: string
108
+ /**
109
+ * The rate at which the deleveraging threshold decreases in slots per bps
110
+ * e.g. 1 bps per hour would be 7200 slots per bps (assuming 2 slots per second)
111
+ */
112
+ deleveragingThresholdSlotsPerBps: string
113
+ /** Program owner fees assessed, separate from gains due to interest accrual */
114
+ fees: ReserveFeesJSON
115
+ /** Borrow rate curve based on utilization */
116
+ borrowRateCurve: BorrowRateCurveJSON
117
+ /** Borrow factor in percentage - used for risk adjustment */
118
+ borrowFactorPct: string
119
+ /** Maximum deposit limit of liquidity in native units, u64::MAX for inf */
120
+ depositLimit: string
121
+ /** Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits) */
122
+ borrowLimit: string
123
+ /** Token id from TokenInfos struct */
124
+ tokenInfo: TokenInfoJSON
125
+ /** Deposit withdrawl caps - deposit & redeem */
126
+ depositWithdrawalCap: WithdrawalCapsJSON
127
+ /** Debt withdrawl caps - borrow & repay */
128
+ debtWithdrawalCap: WithdrawalCapsJSON
129
+ elevationGroups: Array<number>
130
+ disableUsageAsCollOutsideEmode: number
131
+ utilizationLimitBlockBorrowingAbove: number
132
+ reserved1: Array<number>
133
+ /**
134
+ * Maximum amount liquidity of this reserve borrowed outside all elevation groups
135
+ * - u64::MAX for inf
136
+ * - 0 to disable borrows outside elevation groups
137
+ */
138
+ borrowLimitOutsideElevationGroup: string
139
+ /**
140
+ * Defines the maximum amount (in lamports of elevation group debt asset)
141
+ * that can be borrowed when this reserve is used as collateral.
142
+ * - u64::MAX for inf
143
+ * - 0 to disable borrows in this elevation group (expected value for the debt asset)
144
+ */
145
+ borrowLimitAgainstThisCollateralInElevationGroup: Array<string>
146
+ }
147
+
148
+ /** Reserve configuration values */
149
+ export class ReserveConfig {
150
+ /** Status of the reserve Active/Obsolete/Hidden */
151
+ readonly status: number
152
+ /** Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt */
153
+ readonly assetTier: number
154
+ /** Flat rate that goes to the host */
155
+ readonly hostFixedInterestRateBps: number
156
+ /** [DEPRECATED] Boost for side (debt or collateral) */
157
+ readonly reserved2: Array<number>
158
+ /** [DEPRECATED] Reward points multiplier per obligation type */
159
+ readonly reserved3: Array<number>
160
+ /** Protocol take rate is the amount borrowed interest protocol receives, as a percentage */
161
+ readonly protocolTakeRatePct: number
162
+ /** Cut of the liquidation bonus that the protocol receives, as a percentage */
163
+ readonly protocolLiquidationFeePct: number
164
+ /**
165
+ * Target ratio of the value of borrows to deposits, as a percentage
166
+ * 0 if use as collateral is disabled
167
+ */
168
+ readonly loanToValuePct: number
169
+ /** Loan to value ratio at which an obligation can be liquidated, as percentage */
170
+ readonly liquidationThresholdPct: number
171
+ /** Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
172
+ readonly minLiquidationBonusBps: number
173
+ /** Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */
174
+ readonly maxLiquidationBonusBps: number
175
+ /** Bad debt liquidation bonus for an undercollateralized obligation, as bps */
176
+ readonly badDebtLiquidationBonusBps: number
177
+ /** Time in seconds that must pass before redemptions are enabled after the deposit limit is crossed */
178
+ readonly deleveragingMarginCallPeriodSecs: BN
179
+ /**
180
+ * The rate at which the deleveraging threshold decreases in slots per bps
181
+ * e.g. 1 bps per hour would be 7200 slots per bps (assuming 2 slots per second)
182
+ */
183
+ readonly deleveragingThresholdSlotsPerBps: BN
184
+ /** Program owner fees assessed, separate from gains due to interest accrual */
185
+ readonly fees: ReserveFees
186
+ /** Borrow rate curve based on utilization */
187
+ readonly borrowRateCurve: BorrowRateCurve
188
+ /** Borrow factor in percentage - used for risk adjustment */
189
+ readonly borrowFactorPct: BN
190
+ /** Maximum deposit limit of liquidity in native units, u64::MAX for inf */
191
+ readonly depositLimit: BN
192
+ /** Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits) */
193
+ readonly borrowLimit: BN
194
+ /** Token id from TokenInfos struct */
195
+ readonly tokenInfo: TokenInfo
196
+ /** Deposit withdrawl caps - deposit & redeem */
197
+ readonly depositWithdrawalCap: WithdrawalCaps
198
+ /** Debt withdrawl caps - borrow & repay */
199
+ readonly debtWithdrawalCap: WithdrawalCaps
200
+ readonly elevationGroups: Array<number>
201
+ readonly disableUsageAsCollOutsideEmode: number
202
+ readonly utilizationLimitBlockBorrowingAbove: number
203
+ readonly reserved1: Array<number>
204
+ /**
205
+ * Maximum amount liquidity of this reserve borrowed outside all elevation groups
206
+ * - u64::MAX for inf
207
+ * - 0 to disable borrows outside elevation groups
208
+ */
209
+ readonly borrowLimitOutsideElevationGroup: BN
210
+ /**
211
+ * Defines the maximum amount (in lamports of elevation group debt asset)
212
+ * that can be borrowed when this reserve is used as collateral.
213
+ * - u64::MAX for inf
214
+ * - 0 to disable borrows in this elevation group (expected value for the debt asset)
215
+ */
216
+ readonly borrowLimitAgainstThisCollateralInElevationGroup: Array<BN>
217
+
218
+ constructor(fields: ReserveConfigFields) {
219
+ this.status = fields.status
220
+ this.assetTier = fields.assetTier
221
+ this.hostFixedInterestRateBps = fields.hostFixedInterestRateBps
222
+ this.reserved2 = fields.reserved2
223
+ this.reserved3 = fields.reserved3
224
+ this.protocolTakeRatePct = fields.protocolTakeRatePct
225
+ this.protocolLiquidationFeePct = fields.protocolLiquidationFeePct
226
+ this.loanToValuePct = fields.loanToValuePct
227
+ this.liquidationThresholdPct = fields.liquidationThresholdPct
228
+ this.minLiquidationBonusBps = fields.minLiquidationBonusBps
229
+ this.maxLiquidationBonusBps = fields.maxLiquidationBonusBps
230
+ this.badDebtLiquidationBonusBps = fields.badDebtLiquidationBonusBps
231
+ this.deleveragingMarginCallPeriodSecs = fields.deleveragingMarginCallPeriodSecs
232
+ this.deleveragingThresholdSlotsPerBps = fields.deleveragingThresholdSlotsPerBps
233
+ this.fees = new ReserveFees({ ...fields.fees })
234
+ this.borrowRateCurve = new BorrowRateCurve({
235
+ ...fields.borrowRateCurve,
236
+ })
237
+ this.borrowFactorPct = fields.borrowFactorPct
238
+ this.depositLimit = fields.depositLimit
239
+ this.borrowLimit = fields.borrowLimit
240
+ this.tokenInfo = new TokenInfo({ ...fields.tokenInfo })
241
+ this.depositWithdrawalCap = new WithdrawalCaps({
242
+ ...fields.depositWithdrawalCap,
243
+ })
244
+ this.debtWithdrawalCap = new WithdrawalCaps({
245
+ ...fields.debtWithdrawalCap,
246
+ })
247
+ this.elevationGroups = fields.elevationGroups
248
+ this.disableUsageAsCollOutsideEmode = fields.disableUsageAsCollOutsideEmode
249
+ this.utilizationLimitBlockBorrowingAbove = fields.utilizationLimitBlockBorrowingAbove
250
+ this.reserved1 = fields.reserved1
251
+ this.borrowLimitOutsideElevationGroup = fields.borrowLimitOutsideElevationGroup
252
+ this.borrowLimitAgainstThisCollateralInElevationGroup = fields.borrowLimitAgainstThisCollateralInElevationGroup
253
+ }
254
+
255
+ static layout(property?: string) {
256
+ return borsh.struct(
257
+ [
258
+ borsh.u8("status"),
259
+ borsh.u8("assetTier"),
260
+ borsh.u16("hostFixedInterestRateBps"),
261
+ borsh.array(borsh.u8(), 2, "reserved2"),
262
+ borsh.array(borsh.u8(), 8, "reserved3"),
263
+ borsh.u8("protocolTakeRatePct"),
264
+ borsh.u8("protocolLiquidationFeePct"),
265
+ borsh.u8("loanToValuePct"),
266
+ borsh.u8("liquidationThresholdPct"),
267
+ borsh.u16("minLiquidationBonusBps"),
268
+ borsh.u16("maxLiquidationBonusBps"),
269
+ borsh.u16("badDebtLiquidationBonusBps"),
270
+ borsh.u64("deleveragingMarginCallPeriodSecs"),
271
+ borsh.u64("deleveragingThresholdSlotsPerBps"),
272
+ ReserveFees.layout("fees"),
273
+ BorrowRateCurve.layout("borrowRateCurve"),
274
+ borsh.u64("borrowFactorPct"),
275
+ borsh.u64("depositLimit"),
276
+ borsh.u64("borrowLimit"),
277
+ TokenInfo.layout("tokenInfo"),
278
+ WithdrawalCaps.layout("depositWithdrawalCap"),
279
+ WithdrawalCaps.layout("debtWithdrawalCap"),
280
+ borsh.array(borsh.u8(), 20, "elevationGroups"),
281
+ borsh.u8("disableUsageAsCollOutsideEmode"),
282
+ borsh.u8("utilizationLimitBlockBorrowingAbove"),
283
+ borsh.array(borsh.u8(), 2, "reserved1"),
284
+ borsh.u64("borrowLimitOutsideElevationGroup"),
285
+ borsh.array(borsh.u64(), 32, "borrowLimitAgainstThisCollateralInElevationGroup"),
286
+ ],
287
+ property,
288
+ )
289
+ }
290
+
291
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
+ static fromDecoded(obj: any) {
293
+ return new ReserveConfig({
294
+ status: obj.status,
295
+ assetTier: obj.assetTier,
296
+ hostFixedInterestRateBps: obj.hostFixedInterestRateBps,
297
+ reserved2: obj.reserved2,
298
+ reserved3: obj.reserved3,
299
+ protocolTakeRatePct: obj.protocolTakeRatePct,
300
+ protocolLiquidationFeePct: obj.protocolLiquidationFeePct,
301
+ loanToValuePct: obj.loanToValuePct,
302
+ liquidationThresholdPct: obj.liquidationThresholdPct,
303
+ minLiquidationBonusBps: obj.minLiquidationBonusBps,
304
+ maxLiquidationBonusBps: obj.maxLiquidationBonusBps,
305
+ badDebtLiquidationBonusBps: obj.badDebtLiquidationBonusBps,
306
+ deleveragingMarginCallPeriodSecs: obj.deleveragingMarginCallPeriodSecs,
307
+ deleveragingThresholdSlotsPerBps: obj.deleveragingThresholdSlotsPerBps,
308
+ fees: ReserveFees.fromDecoded(obj.fees),
309
+ borrowRateCurve: BorrowRateCurve.fromDecoded(obj.borrowRateCurve),
310
+ borrowFactorPct: obj.borrowFactorPct,
311
+ depositLimit: obj.depositLimit,
312
+ borrowLimit: obj.borrowLimit,
313
+ tokenInfo: TokenInfo.fromDecoded(obj.tokenInfo),
314
+ depositWithdrawalCap: WithdrawalCaps.fromDecoded(obj.depositWithdrawalCap),
315
+ debtWithdrawalCap: WithdrawalCaps.fromDecoded(obj.debtWithdrawalCap),
316
+ elevationGroups: obj.elevationGroups,
317
+ disableUsageAsCollOutsideEmode: obj.disableUsageAsCollOutsideEmode,
318
+ utilizationLimitBlockBorrowingAbove: obj.utilizationLimitBlockBorrowingAbove,
319
+ reserved1: obj.reserved1,
320
+ borrowLimitOutsideElevationGroup: obj.borrowLimitOutsideElevationGroup,
321
+ borrowLimitAgainstThisCollateralInElevationGroup: obj.borrowLimitAgainstThisCollateralInElevationGroup,
322
+ })
323
+ }
324
+
325
+ static toEncodable(fields: ReserveConfigFields) {
326
+ return {
327
+ status: fields.status,
328
+ assetTier: fields.assetTier,
329
+ hostFixedInterestRateBps: fields.hostFixedInterestRateBps,
330
+ reserved2: fields.reserved2,
331
+ reserved3: fields.reserved3,
332
+ protocolTakeRatePct: fields.protocolTakeRatePct,
333
+ protocolLiquidationFeePct: fields.protocolLiquidationFeePct,
334
+ loanToValuePct: fields.loanToValuePct,
335
+ liquidationThresholdPct: fields.liquidationThresholdPct,
336
+ minLiquidationBonusBps: fields.minLiquidationBonusBps,
337
+ maxLiquidationBonusBps: fields.maxLiquidationBonusBps,
338
+ badDebtLiquidationBonusBps: fields.badDebtLiquidationBonusBps,
339
+ deleveragingMarginCallPeriodSecs: fields.deleveragingMarginCallPeriodSecs,
340
+ deleveragingThresholdSlotsPerBps: fields.deleveragingThresholdSlotsPerBps,
341
+ fees: ReserveFees.toEncodable(fields.fees),
342
+ borrowRateCurve: BorrowRateCurve.toEncodable(fields.borrowRateCurve),
343
+ borrowFactorPct: fields.borrowFactorPct,
344
+ depositLimit: fields.depositLimit,
345
+ borrowLimit: fields.borrowLimit,
346
+ tokenInfo: TokenInfo.toEncodable(fields.tokenInfo),
347
+ depositWithdrawalCap: WithdrawalCaps.toEncodable(fields.depositWithdrawalCap),
348
+ debtWithdrawalCap: WithdrawalCaps.toEncodable(fields.debtWithdrawalCap),
349
+ elevationGroups: fields.elevationGroups,
350
+ disableUsageAsCollOutsideEmode: fields.disableUsageAsCollOutsideEmode,
351
+ utilizationLimitBlockBorrowingAbove: fields.utilizationLimitBlockBorrowingAbove,
352
+ reserved1: fields.reserved1,
353
+ borrowLimitOutsideElevationGroup: fields.borrowLimitOutsideElevationGroup,
354
+ borrowLimitAgainstThisCollateralInElevationGroup: fields.borrowLimitAgainstThisCollateralInElevationGroup,
355
+ }
356
+ }
357
+
358
+ toJSON(): ReserveConfigJSON {
359
+ return {
360
+ status: this.status,
361
+ assetTier: this.assetTier,
362
+ hostFixedInterestRateBps: this.hostFixedInterestRateBps,
363
+ reserved2: this.reserved2,
364
+ reserved3: this.reserved3,
365
+ protocolTakeRatePct: this.protocolTakeRatePct,
366
+ protocolLiquidationFeePct: this.protocolLiquidationFeePct,
367
+ loanToValuePct: this.loanToValuePct,
368
+ liquidationThresholdPct: this.liquidationThresholdPct,
369
+ minLiquidationBonusBps: this.minLiquidationBonusBps,
370
+ maxLiquidationBonusBps: this.maxLiquidationBonusBps,
371
+ badDebtLiquidationBonusBps: this.badDebtLiquidationBonusBps,
372
+ deleveragingMarginCallPeriodSecs: this.deleveragingMarginCallPeriodSecs.toString(),
373
+ deleveragingThresholdSlotsPerBps: this.deleveragingThresholdSlotsPerBps.toString(),
374
+ fees: this.fees.toJSON(),
375
+ borrowRateCurve: this.borrowRateCurve.toJSON(),
376
+ borrowFactorPct: this.borrowFactorPct.toString(),
377
+ depositLimit: this.depositLimit.toString(),
378
+ borrowLimit: this.borrowLimit.toString(),
379
+ tokenInfo: this.tokenInfo.toJSON(),
380
+ depositWithdrawalCap: this.depositWithdrawalCap.toJSON(),
381
+ debtWithdrawalCap: this.debtWithdrawalCap.toJSON(),
382
+ elevationGroups: this.elevationGroups,
383
+ disableUsageAsCollOutsideEmode: this.disableUsageAsCollOutsideEmode,
384
+ utilizationLimitBlockBorrowingAbove: this.utilizationLimitBlockBorrowingAbove,
385
+ reserved1: this.reserved1,
386
+ borrowLimitOutsideElevationGroup: this.borrowLimitOutsideElevationGroup.toString(),
387
+ borrowLimitAgainstThisCollateralInElevationGroup: this.borrowLimitAgainstThisCollateralInElevationGroup.map(
388
+ (item) => item.toString(),
389
+ ),
390
+ }
391
+ }
392
+
393
+ static fromJSON(obj: ReserveConfigJSON): ReserveConfig {
394
+ return new ReserveConfig({
395
+ status: obj.status,
396
+ assetTier: obj.assetTier,
397
+ hostFixedInterestRateBps: obj.hostFixedInterestRateBps,
398
+ reserved2: obj.reserved2,
399
+ reserved3: obj.reserved3,
400
+ protocolTakeRatePct: obj.protocolTakeRatePct,
401
+ protocolLiquidationFeePct: obj.protocolLiquidationFeePct,
402
+ loanToValuePct: obj.loanToValuePct,
403
+ liquidationThresholdPct: obj.liquidationThresholdPct,
404
+ minLiquidationBonusBps: obj.minLiquidationBonusBps,
405
+ maxLiquidationBonusBps: obj.maxLiquidationBonusBps,
406
+ badDebtLiquidationBonusBps: obj.badDebtLiquidationBonusBps,
407
+ deleveragingMarginCallPeriodSecs: new BN(obj.deleveragingMarginCallPeriodSecs),
408
+ deleveragingThresholdSlotsPerBps: new BN(obj.deleveragingThresholdSlotsPerBps),
409
+ fees: ReserveFees.fromJSON(obj.fees),
410
+ borrowRateCurve: BorrowRateCurve.fromJSON(obj.borrowRateCurve),
411
+ borrowFactorPct: new BN(obj.borrowFactorPct),
412
+ depositLimit: new BN(obj.depositLimit),
413
+ borrowLimit: new BN(obj.borrowLimit),
414
+ tokenInfo: TokenInfo.fromJSON(obj.tokenInfo),
415
+ depositWithdrawalCap: WithdrawalCaps.fromJSON(obj.depositWithdrawalCap),
416
+ debtWithdrawalCap: WithdrawalCaps.fromJSON(obj.debtWithdrawalCap),
417
+ elevationGroups: obj.elevationGroups,
418
+ disableUsageAsCollOutsideEmode: obj.disableUsageAsCollOutsideEmode,
419
+ utilizationLimitBlockBorrowingAbove: obj.utilizationLimitBlockBorrowingAbove,
420
+ reserved1: obj.reserved1,
421
+ borrowLimitOutsideElevationGroup: new BN(obj.borrowLimitOutsideElevationGroup),
422
+ borrowLimitAgainstThisCollateralInElevationGroup: obj.borrowLimitAgainstThisCollateralInElevationGroup.map(
423
+ (item) => new BN(item),
424
+ ),
425
+ })
426
+ }
427
+
428
+ toEncodable() {
429
+ return ReserveConfig.toEncodable(this)
430
+ }
431
+ }
@@ -0,0 +1,116 @@
1
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import * as borsh from "@coral-xyz/borsh"
3
+
4
+ export interface ReserveFeesFields {
5
+ /**
6
+ * Fee assessed on `BorrowObligationLiquidity`, as scaled fraction (60 bits fractional part)
7
+ * Must be between `0` and `2^60`, such that `2^60 = 1`. A few examples for
8
+ * clarity:
9
+ * 1% = (1 << 60) / 100 = 11529215046068470
10
+ * 0.01% (1 basis point) = 115292150460685
11
+ * 0.00001% (Aave borrow fee) = 115292150461
12
+ */
13
+ borrowFeeSf: BN
14
+ /**
15
+ * Fee for flash loan, expressed as scaled fraction.
16
+ * 0.3% (Aave flash loan fee) = 0.003 * 2^60 = 3458764513820541
17
+ */
18
+ flashLoanFeeSf: BN
19
+ /** Used for allignment */
20
+ padding: Array<number>
21
+ }
22
+
23
+ export interface ReserveFeesJSON {
24
+ /**
25
+ * Fee assessed on `BorrowObligationLiquidity`, as scaled fraction (60 bits fractional part)
26
+ * Must be between `0` and `2^60`, such that `2^60 = 1`. A few examples for
27
+ * clarity:
28
+ * 1% = (1 << 60) / 100 = 11529215046068470
29
+ * 0.01% (1 basis point) = 115292150460685
30
+ * 0.00001% (Aave borrow fee) = 115292150461
31
+ */
32
+ borrowFeeSf: string
33
+ /**
34
+ * Fee for flash loan, expressed as scaled fraction.
35
+ * 0.3% (Aave flash loan fee) = 0.003 * 2^60 = 3458764513820541
36
+ */
37
+ flashLoanFeeSf: string
38
+ /** Used for allignment */
39
+ padding: Array<number>
40
+ }
41
+
42
+ /**
43
+ * Additional fee information on a reserve
44
+ *
45
+ * These exist separately from interest accrual fees, and are specifically for the program owner
46
+ * and referral fee. The fees are paid out as a percentage of liquidity token amounts during
47
+ * repayments and liquidations.
48
+ */
49
+ export class ReserveFees {
50
+ /**
51
+ * Fee assessed on `BorrowObligationLiquidity`, as scaled fraction (60 bits fractional part)
52
+ * Must be between `0` and `2^60`, such that `2^60 = 1`. A few examples for
53
+ * clarity:
54
+ * 1% = (1 << 60) / 100 = 11529215046068470
55
+ * 0.01% (1 basis point) = 115292150460685
56
+ * 0.00001% (Aave borrow fee) = 115292150461
57
+ */
58
+ readonly borrowFeeSf: BN
59
+ /**
60
+ * Fee for flash loan, expressed as scaled fraction.
61
+ * 0.3% (Aave flash loan fee) = 0.003 * 2^60 = 3458764513820541
62
+ */
63
+ readonly flashLoanFeeSf: BN
64
+ /** Used for allignment */
65
+ readonly padding: Array<number>
66
+
67
+ constructor(fields: ReserveFeesFields) {
68
+ this.borrowFeeSf = fields.borrowFeeSf
69
+ this.flashLoanFeeSf = fields.flashLoanFeeSf
70
+ this.padding = fields.padding
71
+ }
72
+
73
+ static layout(property?: string) {
74
+ return borsh.struct(
75
+ [borsh.u64("borrowFeeSf"), borsh.u64("flashLoanFeeSf"), borsh.array(borsh.u8(), 8, "padding")],
76
+ property,
77
+ )
78
+ }
79
+
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ static fromDecoded(obj: any) {
82
+ return new ReserveFees({
83
+ borrowFeeSf: obj.borrowFeeSf,
84
+ flashLoanFeeSf: obj.flashLoanFeeSf,
85
+ padding: obj.padding,
86
+ })
87
+ }
88
+
89
+ static toEncodable(fields: ReserveFeesFields) {
90
+ return {
91
+ borrowFeeSf: fields.borrowFeeSf,
92
+ flashLoanFeeSf: fields.flashLoanFeeSf,
93
+ padding: fields.padding,
94
+ }
95
+ }
96
+
97
+ toJSON(): ReserveFeesJSON {
98
+ return {
99
+ borrowFeeSf: this.borrowFeeSf.toString(),
100
+ flashLoanFeeSf: this.flashLoanFeeSf.toString(),
101
+ padding: this.padding,
102
+ }
103
+ }
104
+
105
+ static fromJSON(obj: ReserveFeesJSON): ReserveFees {
106
+ return new ReserveFees({
107
+ borrowFeeSf: new BN(obj.borrowFeeSf),
108
+ flashLoanFeeSf: new BN(obj.flashLoanFeeSf),
109
+ padding: obj.padding,
110
+ })
111
+ }
112
+
113
+ toEncodable() {
114
+ return ReserveFees.toEncodable(this)
115
+ }
116
+ }