@kamino-finance/klend-sdk 7.3.13 → 7.3.14

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 (122) hide show
  1. package/dist/@codegen/klend/accounts/LendingMarket.d.ts +51 -3
  2. package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
  3. package/dist/@codegen/klend/accounts/LendingMarket.js +39 -6
  4. package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
  5. package/dist/@codegen/klend/accounts/Obligation.d.ts +24 -15
  6. package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
  7. package/dist/@codegen/klend/accounts/Obligation.js +24 -21
  8. package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
  9. package/dist/@codegen/klend/accounts/Reserve.js +1 -1
  10. package/dist/@codegen/klend/accounts/UserState.d.ts +0 -75
  11. package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
  12. package/dist/@codegen/klend/accounts/UserState.js +0 -25
  13. package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
  14. package/dist/@codegen/klend/errors/custom.d.ts +89 -1
  15. package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
  16. package/dist/@codegen/klend/errors/custom.js +155 -1
  17. package/dist/@codegen/klend/errors/custom.js.map +1 -1
  18. package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +36 -0
  19. package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +1 -0
  20. package/dist/@codegen/klend/instructions/fillBorrowOrder.js +49 -0
  21. package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +1 -0
  22. package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +0 -1
  23. package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
  24. package/dist/@codegen/klend/instructions/idlMissingTypes.js +0 -2
  25. package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
  26. package/dist/@codegen/klend/instructions/index.d.ts +4 -0
  27. package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
  28. package/dist/@codegen/klend/instructions/index.js +6 -1
  29. package/dist/@codegen/klend/instructions/index.js.map +1 -1
  30. package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +33 -0
  31. package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +1 -0
  32. package/dist/@codegen/klend/instructions/setBorrowOrder.js +66 -0
  33. package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +1 -0
  34. package/dist/@codegen/klend/types/BorrowOrder.d.ts +192 -0
  35. package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -0
  36. package/dist/@codegen/klend/types/BorrowOrder.js +194 -0
  37. package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -0
  38. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +39 -0
  39. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -0
  40. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +100 -0
  41. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -0
  42. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +35 -5
  43. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
  44. package/dist/@codegen/klend/types/ObligationLiquidity.js +17 -7
  45. package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
  46. package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
  47. package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
  48. package/dist/@codegen/klend/types/ReserveConfig.d.ts +60 -5
  49. package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
  50. package/dist/@codegen/klend/types/ReserveConfig.js +36 -7
  51. package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
  52. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +33 -7
  53. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
  54. package/dist/@codegen/klend/types/UpdateConfigMode.js +61 -13
  55. package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
  56. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +52 -0
  57. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
  58. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +97 -1
  59. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
  60. package/dist/@codegen/klend/types/index.d.ts +8 -8
  61. package/dist/@codegen/klend/types/index.d.ts.map +1 -1
  62. package/dist/@codegen/klend/types/index.js +5 -3
  63. package/dist/@codegen/klend/types/index.js.map +1 -1
  64. package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +8 -5
  65. package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
  66. package/dist/@codegen/klend/zero_padding/ObligationZP.js +17 -14
  67. package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
  68. package/dist/classes/configItems.d.ts +10 -0
  69. package/dist/classes/configItems.d.ts.map +1 -1
  70. package/dist/classes/configItems.js +72 -1
  71. package/dist/classes/configItems.js.map +1 -1
  72. package/dist/classes/index.d.ts +1 -0
  73. package/dist/classes/index.d.ts.map +1 -1
  74. package/dist/classes/index.js +1 -0
  75. package/dist/classes/index.js.map +1 -1
  76. package/dist/classes/manager.d.ts.map +1 -1
  77. package/dist/classes/manager.js +4 -0
  78. package/dist/classes/manager.js.map +1 -1
  79. package/dist/classes/obligation.js +1 -1
  80. package/dist/classes/obligation.js.map +1 -1
  81. package/dist/classes/reserve.d.ts +2 -2
  82. package/dist/classes/reserve.d.ts.map +1 -1
  83. package/dist/classes/reserve.js +42 -22
  84. package/dist/classes/reserve.js.map +1 -1
  85. package/dist/idl/klend.json +581 -54
  86. package/dist/manager/client_kamino_manager.js +12 -6
  87. package/dist/manager/client_kamino_manager.js.map +1 -1
  88. package/dist/utils/managerTypes.d.ts.map +1 -1
  89. package/dist/utils/managerTypes.js +3 -1
  90. package/dist/utils/managerTypes.js.map +1 -1
  91. package/package.json +1 -1
  92. package/src/@codegen/klend/accounts/LendingMarket.ts +79 -8
  93. package/src/@codegen/klend/accounts/Obligation.ts +42 -31
  94. package/src/@codegen/klend/accounts/Reserve.ts +1 -1
  95. package/src/@codegen/klend/accounts/UserState.ts +0 -75
  96. package/src/@codegen/klend/errors/custom.ts +172 -0
  97. package/src/@codegen/klend/instructions/fillBorrowOrder.ts +96 -0
  98. package/src/@codegen/klend/instructions/idlMissingTypes.ts +0 -3
  99. package/src/@codegen/klend/instructions/index.ts +7 -0
  100. package/src/@codegen/klend/instructions/setBorrowOrder.ts +81 -0
  101. package/src/@codegen/klend/types/BorrowOrder.ts +267 -0
  102. package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +87 -0
  103. package/src/@codegen/klend/types/ObligationLiquidity.ts +39 -9
  104. package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
  105. package/src/@codegen/klend/types/ReserveConfig.ts +72 -9
  106. package/src/@codegen/klend/types/UpdateConfigMode.ts +73 -13
  107. package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +120 -0
  108. package/src/@codegen/klend/types/index.ts +21 -14
  109. package/src/@codegen/klend/zero_padding/ObligationZP.ts +17 -14
  110. package/src/classes/configItems.ts +83 -0
  111. package/src/classes/index.ts +1 -0
  112. package/src/classes/manager.ts +5 -0
  113. package/src/classes/obligation.ts +1 -1
  114. package/src/classes/reserve.ts +52 -34
  115. package/src/idl/klend.json +581 -54
  116. package/src/manager/client_kamino_manager.ts +12 -6
  117. package/src/utils/managerTypes.ts +3 -1
  118. package/dist/@codegen/klend/types/AssetTier.d.ts +0 -45
  119. package/dist/@codegen/klend/types/AssetTier.d.ts.map +0 -1
  120. package/dist/@codegen/klend/types/AssetTier.js +0 -132
  121. package/dist/@codegen/klend/types/AssetTier.js.map +0 -1
  122. package/src/@codegen/klend/types/AssetTier.ts +0 -119
@@ -0,0 +1,96 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import {
3
+ Address,
4
+ isSome,
5
+ AccountMeta,
6
+ AccountSignerMeta,
7
+ Instruction,
8
+ Option,
9
+ TransactionSigner,
10
+ } from "@solana/kit"
11
+ /* eslint-enable @typescript-eslint/no-unused-vars */
12
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
13
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
14
+ import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
16
+ import { PROGRAM_ID } from "../programId"
17
+
18
+ export const DISCRIMINATOR = Buffer.from([102, 4, 167, 76, 131, 170, 93, 19])
19
+
20
+ export interface FillBorrowOrderAccounts {
21
+ borrowAccounts: {
22
+ payer: TransactionSigner
23
+ /** The obligation with a [BorrowOrder]. */
24
+ obligation: Address
25
+ /** The [Self::obligation]'s market - needed for borrowing-related configuration. */
26
+ lendingMarket: Address
27
+ /** The [Self::lending_market]'s authority, needed to transfer the newly-borrowed funds out of the [Self::reserve_source_liquidity]. */
28
+ lendingMarketAuthority: Address
29
+ /** The reserve to borrow from. Its mint must match the asset requested by the [BorrowOrder::debt_liquidity_mint]. */
30
+ borrowReserve: Address
31
+ /** The mint of [Self::borrow_reserve] - needed to execute the transfer. */
32
+ borrowReserveLiquidityMint: Address
33
+ /** The vault of [Self::borrow_reserve], from which the funds are transferred. */
34
+ reserveSourceLiquidity: Address
35
+ /** The fee vault of [Self::borrow_reserve], to which the fees are transferred. */
36
+ borrowReserveLiquidityFeeReceiver: Address
37
+ /** The destination token account that should receive the newly borrowed funds. It must match [BorrowOrder::filled_debt_destination], owner and mint. **Warning:** An altered destination account will prevent an order from being filled. */
38
+ userDestinationLiquidity: Address
39
+ /** The referrer's account, for accumulating fees - needed if the [Obligation::has_referrer]. */
40
+ referrerTokenState: Option<Address>
41
+ /** The token program of [Self::borrow_reserve] - needed to execute the transfer. */
42
+ tokenProgram: Address
43
+ }
44
+ farmsAccounts: {
45
+ obligationFarmUserState: Option<Address>
46
+ reserveFarmState: Option<Address>
47
+ }
48
+ farmsProgram: Address
49
+ eventAuthority: Address
50
+ program: Address
51
+ }
52
+
53
+ export function fillBorrowOrder(
54
+ accounts: FillBorrowOrderAccounts,
55
+ remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
56
+ programAddress: Address = PROGRAM_ID
57
+ ) {
58
+ const keys: Array<AccountMeta | AccountSignerMeta> = [
59
+ {
60
+ address: accounts.borrowAccounts.payer.address,
61
+ role: 2,
62
+ signer: accounts.borrowAccounts.payer,
63
+ },
64
+ { address: accounts.borrowAccounts.obligation, role: 1 },
65
+ { address: accounts.borrowAccounts.lendingMarket, role: 0 },
66
+ { address: accounts.borrowAccounts.lendingMarketAuthority, role: 0 },
67
+ { address: accounts.borrowAccounts.borrowReserve, role: 1 },
68
+ { address: accounts.borrowAccounts.borrowReserveLiquidityMint, role: 0 },
69
+ { address: accounts.borrowAccounts.reserveSourceLiquidity, role: 1 },
70
+ {
71
+ address: accounts.borrowAccounts.borrowReserveLiquidityFeeReceiver,
72
+ role: 1,
73
+ },
74
+ { address: accounts.borrowAccounts.userDestinationLiquidity, role: 1 },
75
+ isSome(accounts.borrowAccounts.referrerTokenState)
76
+ ? { address: accounts.borrowAccounts.referrerTokenState.value, role: 1 }
77
+ : { address: programAddress, role: 0 },
78
+ { address: accounts.borrowAccounts.tokenProgram, role: 0 },
79
+ isSome(accounts.farmsAccounts.obligationFarmUserState)
80
+ ? {
81
+ address: accounts.farmsAccounts.obligationFarmUserState.value,
82
+ role: 1,
83
+ }
84
+ : { address: programAddress, role: 0 },
85
+ isSome(accounts.farmsAccounts.reserveFarmState)
86
+ ? { address: accounts.farmsAccounts.reserveFarmState.value, role: 1 }
87
+ : { address: programAddress, role: 0 },
88
+ { address: accounts.farmsProgram, role: 0 },
89
+ { address: accounts.eventAuthority, role: 0 },
90
+ { address: accounts.program, role: 0 },
91
+ ...remainingAccounts,
92
+ ]
93
+ const data = DISCRIMINATOR
94
+ const ix: Instruction = { accounts: keys, programAddress, data }
95
+ return ix
96
+ }
@@ -19,7 +19,6 @@ export const DISCRIMINATOR = Buffer.from([130, 80, 38, 153, 80, 212, 182, 253])
19
19
 
20
20
  export interface IdlMissingTypesArgs {
21
21
  reserveFarmKind: types.ReserveFarmKindKind
22
- assetTier: types.AssetTierKind
23
22
  feeCalculation: types.FeeCalculationKind
24
23
  reserveStatus: types.ReserveStatusKind
25
24
  updateConfigMode: types.UpdateConfigModeKind
@@ -36,7 +35,6 @@ export interface IdlMissingTypesAccounts {
36
35
 
37
36
  export const layout = borsh.struct([
38
37
  types.ReserveFarmKind.layout("reserveFarmKind"),
39
- types.AssetTier.layout("assetTier"),
40
38
  types.FeeCalculation.layout("feeCalculation"),
41
39
  types.ReserveStatus.layout("reserveStatus"),
42
40
  types.UpdateConfigMode.layout("updateConfigMode"),
@@ -61,7 +59,6 @@ export function idlMissingTypes(
61
59
  const len = layout.encode(
62
60
  {
63
61
  reserveFarmKind: args.reserveFarmKind.toEncodable(),
64
- assetTier: args.assetTier.toEncodable(),
65
62
  feeCalculation: args.feeCalculation.toEncodable(),
66
63
  reserveStatus: args.reserveStatus.toEncodable(),
67
64
  updateConfigMode: args.updateConfigMode.toEncodable(),
@@ -190,6 +190,13 @@ export type {
190
190
  SetObligationOrderArgs,
191
191
  SetObligationOrderAccounts,
192
192
  } from "./setObligationOrder"
193
+ export { setBorrowOrder } from "./setBorrowOrder"
194
+ export type {
195
+ SetBorrowOrderArgs,
196
+ SetBorrowOrderAccounts,
197
+ } from "./setBorrowOrder"
198
+ export { fillBorrowOrder } from "./fillBorrowOrder"
199
+ export type { FillBorrowOrderAccounts } from "./fillBorrowOrder"
193
200
  export { initGlobalConfig } from "./initGlobalConfig"
194
201
  export type { InitGlobalConfigAccounts } from "./initGlobalConfig"
195
202
  export { updateGlobalConfig } from "./updateGlobalConfig"
@@ -0,0 +1,81 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import {
3
+ Address,
4
+ isSome,
5
+ AccountMeta,
6
+ AccountSignerMeta,
7
+ Instruction,
8
+ Option,
9
+ TransactionSigner,
10
+ } from "@solana/kit"
11
+ /* eslint-enable @typescript-eslint/no-unused-vars */
12
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
13
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
14
+ import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
16
+ import { PROGRAM_ID } from "../programId"
17
+
18
+ export const DISCRIMINATOR = Buffer.from([177, 186, 45, 61, 235, 91, 68, 139])
19
+
20
+ export interface SetBorrowOrderArgs {
21
+ orderConfig: types.BorrowOrderConfigArgsFields
22
+ minExpectedCurrentRemainingDebtAmount: BN
23
+ }
24
+
25
+ export interface SetBorrowOrderAccounts {
26
+ /** The [Self::obligation]'s owner. */
27
+ owner: TransactionSigner
28
+ /** The obligation to set the [BorrowOrder] on. */
29
+ obligation: Address
30
+ /** The [Self::obligation]'s market - needed only to validate the borrow orders' feature flag. */
31
+ lendingMarket: Address
32
+ /**
33
+ * The [BorrowOrder::filled_debt_destination] to set on order creation. Not editable on order
34
+ * updates.
35
+ * Ignored when cancelling the order.
36
+ */
37
+ filledDebtDestination: Address
38
+ /**
39
+ * The [BorrowOrder::debt_liquidity_mint] to set on order creation. Not editable on order
40
+ * updates.
41
+ * Ignored when cancelling the order.
42
+ */
43
+ debtLiquidityMint: Address
44
+ eventAuthority: Address
45
+ program: Address
46
+ }
47
+
48
+ export const layout = borsh.struct<SetBorrowOrderArgs>([
49
+ types.BorrowOrderConfigArgs.layout("orderConfig"),
50
+ borsh.u64("minExpectedCurrentRemainingDebtAmount"),
51
+ ])
52
+
53
+ export function setBorrowOrder(
54
+ args: SetBorrowOrderArgs,
55
+ accounts: SetBorrowOrderAccounts,
56
+ remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
57
+ programAddress: Address = PROGRAM_ID
58
+ ) {
59
+ const keys: Array<AccountMeta | AccountSignerMeta> = [
60
+ { address: accounts.owner.address, role: 2, signer: accounts.owner },
61
+ { address: accounts.obligation, role: 1 },
62
+ { address: accounts.lendingMarket, role: 0 },
63
+ { address: accounts.filledDebtDestination, role: 0 },
64
+ { address: accounts.debtLiquidityMint, role: 0 },
65
+ { address: accounts.eventAuthority, role: 0 },
66
+ { address: accounts.program, role: 0 },
67
+ ...remainingAccounts,
68
+ ]
69
+ const buffer = Buffer.alloc(1000)
70
+ const len = layout.encode(
71
+ {
72
+ orderConfig: types.BorrowOrderConfigArgs.toEncodable(args.orderConfig),
73
+ minExpectedCurrentRemainingDebtAmount:
74
+ args.minExpectedCurrentRemainingDebtAmount,
75
+ },
76
+ buffer
77
+ )
78
+ const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len)
79
+ const ix: Instruction = { accounts: keys, programAddress, data }
80
+ return ix
81
+ }
@@ -0,0 +1,267 @@
1
+ import { address, Address } from "@solana/kit" // 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
+ import { borshAddress } from "../utils"
6
+
7
+ export interface BorrowOrderFields {
8
+ /**
9
+ * The asset to be borrowed.
10
+ * The reserves used for [Obligation::borrows] *must* all provide exactly this asset.
11
+ */
12
+ debtLiquidityMint: Address
13
+ /** The amount of debt that still needs to be filled, in lamports. */
14
+ remainingDebtAmount: BN
15
+ /**
16
+ * The token account owned by the [Obligation::owner] and holding [Self::debt_liquidity_mint],
17
+ * where the filled funds should be transferred to.
18
+ */
19
+ filledDebtDestination: Address
20
+ /**
21
+ * The minimum allowed debt term that the obligation owner agrees to.
22
+ * The reserves used to fill this order *cannot* define their debt term *lower* than this.
23
+ *
24
+ * If zeroed, then only indefinite-term reserves may be used.
25
+ */
26
+ minDebtTermSeconds: BN
27
+ /** The time until which the borrow order can still be filled. */
28
+ fillableUntilTimestamp: BN
29
+ /**
30
+ * The time at which this order was placed.
31
+ * Currently, this is only a piece of metadata.
32
+ */
33
+ placedAtTimestamp: BN
34
+ /**
35
+ * The time at which this order was most-recently updated (including: created).
36
+ * Currently, this is only a piece of metadata.
37
+ */
38
+ lastUpdatedAtTimestamp: BN
39
+ /**
40
+ * The amount of debt that was originally requested when this order was most-recently updated.
41
+ * In other words: this field holds a value of [Self::remaining_debt_amount] captured at
42
+ * [Self::last_updated_at_timestamp].
43
+ * Currently, this is only a piece of metadata.
44
+ */
45
+ requestedDebtAmount: BN
46
+ /**
47
+ * The maximum borrow rate that the obligation owner agrees to.
48
+ * The reserves used for [Obligation::borrows] *cannot* define their maximum borrow rate
49
+ * *higher* than this.
50
+ */
51
+ maxBorrowRateBps: number
52
+ /** Alignment padding. */
53
+ padding1: Array<number>
54
+ /** End padding. */
55
+ endPadding: Array<BN>
56
+ }
57
+
58
+ export interface BorrowOrderJSON {
59
+ /**
60
+ * The asset to be borrowed.
61
+ * The reserves used for [Obligation::borrows] *must* all provide exactly this asset.
62
+ */
63
+ debtLiquidityMint: string
64
+ /** The amount of debt that still needs to be filled, in lamports. */
65
+ remainingDebtAmount: string
66
+ /**
67
+ * The token account owned by the [Obligation::owner] and holding [Self::debt_liquidity_mint],
68
+ * where the filled funds should be transferred to.
69
+ */
70
+ filledDebtDestination: string
71
+ /**
72
+ * The minimum allowed debt term that the obligation owner agrees to.
73
+ * The reserves used to fill this order *cannot* define their debt term *lower* than this.
74
+ *
75
+ * If zeroed, then only indefinite-term reserves may be used.
76
+ */
77
+ minDebtTermSeconds: string
78
+ /** The time until which the borrow order can still be filled. */
79
+ fillableUntilTimestamp: string
80
+ /**
81
+ * The time at which this order was placed.
82
+ * Currently, this is only a piece of metadata.
83
+ */
84
+ placedAtTimestamp: string
85
+ /**
86
+ * The time at which this order was most-recently updated (including: created).
87
+ * Currently, this is only a piece of metadata.
88
+ */
89
+ lastUpdatedAtTimestamp: string
90
+ /**
91
+ * The amount of debt that was originally requested when this order was most-recently updated.
92
+ * In other words: this field holds a value of [Self::remaining_debt_amount] captured at
93
+ * [Self::last_updated_at_timestamp].
94
+ * Currently, this is only a piece of metadata.
95
+ */
96
+ requestedDebtAmount: string
97
+ /**
98
+ * The maximum borrow rate that the obligation owner agrees to.
99
+ * The reserves used for [Obligation::borrows] *cannot* define their maximum borrow rate
100
+ * *higher* than this.
101
+ */
102
+ maxBorrowRateBps: number
103
+ /** Alignment padding. */
104
+ padding1: Array<number>
105
+ /** End padding. */
106
+ endPadding: Array<string>
107
+ }
108
+
109
+ /**
110
+ * A borrow order.
111
+ *
112
+ * When the [Obligation::borrow_order] is populated (i.e. non-zeroed) on an Obligation, then the
113
+ * permissionless "fill" operations may borrow liquidity to the owner according to this
114
+ * specification.
115
+ */
116
+ export class BorrowOrder {
117
+ /**
118
+ * The asset to be borrowed.
119
+ * The reserves used for [Obligation::borrows] *must* all provide exactly this asset.
120
+ */
121
+ readonly debtLiquidityMint: Address
122
+ /** The amount of debt that still needs to be filled, in lamports. */
123
+ readonly remainingDebtAmount: BN
124
+ /**
125
+ * The token account owned by the [Obligation::owner] and holding [Self::debt_liquidity_mint],
126
+ * where the filled funds should be transferred to.
127
+ */
128
+ readonly filledDebtDestination: Address
129
+ /**
130
+ * The minimum allowed debt term that the obligation owner agrees to.
131
+ * The reserves used to fill this order *cannot* define their debt term *lower* than this.
132
+ *
133
+ * If zeroed, then only indefinite-term reserves may be used.
134
+ */
135
+ readonly minDebtTermSeconds: BN
136
+ /** The time until which the borrow order can still be filled. */
137
+ readonly fillableUntilTimestamp: BN
138
+ /**
139
+ * The time at which this order was placed.
140
+ * Currently, this is only a piece of metadata.
141
+ */
142
+ readonly placedAtTimestamp: BN
143
+ /**
144
+ * The time at which this order was most-recently updated (including: created).
145
+ * Currently, this is only a piece of metadata.
146
+ */
147
+ readonly lastUpdatedAtTimestamp: BN
148
+ /**
149
+ * The amount of debt that was originally requested when this order was most-recently updated.
150
+ * In other words: this field holds a value of [Self::remaining_debt_amount] captured at
151
+ * [Self::last_updated_at_timestamp].
152
+ * Currently, this is only a piece of metadata.
153
+ */
154
+ readonly requestedDebtAmount: BN
155
+ /**
156
+ * The maximum borrow rate that the obligation owner agrees to.
157
+ * The reserves used for [Obligation::borrows] *cannot* define their maximum borrow rate
158
+ * *higher* than this.
159
+ */
160
+ readonly maxBorrowRateBps: number
161
+ /** Alignment padding. */
162
+ readonly padding1: Array<number>
163
+ /** End padding. */
164
+ readonly endPadding: Array<BN>
165
+
166
+ constructor(fields: BorrowOrderFields) {
167
+ this.debtLiquidityMint = fields.debtLiquidityMint
168
+ this.remainingDebtAmount = fields.remainingDebtAmount
169
+ this.filledDebtDestination = fields.filledDebtDestination
170
+ this.minDebtTermSeconds = fields.minDebtTermSeconds
171
+ this.fillableUntilTimestamp = fields.fillableUntilTimestamp
172
+ this.placedAtTimestamp = fields.placedAtTimestamp
173
+ this.lastUpdatedAtTimestamp = fields.lastUpdatedAtTimestamp
174
+ this.requestedDebtAmount = fields.requestedDebtAmount
175
+ this.maxBorrowRateBps = fields.maxBorrowRateBps
176
+ this.padding1 = fields.padding1
177
+ this.endPadding = fields.endPadding
178
+ }
179
+
180
+ static layout(property?: string) {
181
+ return borsh.struct(
182
+ [
183
+ borshAddress("debtLiquidityMint"),
184
+ borsh.u64("remainingDebtAmount"),
185
+ borshAddress("filledDebtDestination"),
186
+ borsh.u64("minDebtTermSeconds"),
187
+ borsh.u64("fillableUntilTimestamp"),
188
+ borsh.u64("placedAtTimestamp"),
189
+ borsh.u64("lastUpdatedAtTimestamp"),
190
+ borsh.u64("requestedDebtAmount"),
191
+ borsh.u32("maxBorrowRateBps"),
192
+ borsh.array(borsh.u8(), 4, "padding1"),
193
+ borsh.array(borsh.u64(), 5, "endPadding"),
194
+ ],
195
+ property
196
+ )
197
+ }
198
+
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ static fromDecoded(obj: any) {
201
+ return new BorrowOrder({
202
+ debtLiquidityMint: obj.debtLiquidityMint,
203
+ remainingDebtAmount: obj.remainingDebtAmount,
204
+ filledDebtDestination: obj.filledDebtDestination,
205
+ minDebtTermSeconds: obj.minDebtTermSeconds,
206
+ fillableUntilTimestamp: obj.fillableUntilTimestamp,
207
+ placedAtTimestamp: obj.placedAtTimestamp,
208
+ lastUpdatedAtTimestamp: obj.lastUpdatedAtTimestamp,
209
+ requestedDebtAmount: obj.requestedDebtAmount,
210
+ maxBorrowRateBps: obj.maxBorrowRateBps,
211
+ padding1: obj.padding1,
212
+ endPadding: obj.endPadding,
213
+ })
214
+ }
215
+
216
+ static toEncodable(fields: BorrowOrderFields) {
217
+ return {
218
+ debtLiquidityMint: fields.debtLiquidityMint,
219
+ remainingDebtAmount: fields.remainingDebtAmount,
220
+ filledDebtDestination: fields.filledDebtDestination,
221
+ minDebtTermSeconds: fields.minDebtTermSeconds,
222
+ fillableUntilTimestamp: fields.fillableUntilTimestamp,
223
+ placedAtTimestamp: fields.placedAtTimestamp,
224
+ lastUpdatedAtTimestamp: fields.lastUpdatedAtTimestamp,
225
+ requestedDebtAmount: fields.requestedDebtAmount,
226
+ maxBorrowRateBps: fields.maxBorrowRateBps,
227
+ padding1: fields.padding1,
228
+ endPadding: fields.endPadding,
229
+ }
230
+ }
231
+
232
+ toJSON(): BorrowOrderJSON {
233
+ return {
234
+ debtLiquidityMint: this.debtLiquidityMint,
235
+ remainingDebtAmount: this.remainingDebtAmount.toString(),
236
+ filledDebtDestination: this.filledDebtDestination,
237
+ minDebtTermSeconds: this.minDebtTermSeconds.toString(),
238
+ fillableUntilTimestamp: this.fillableUntilTimestamp.toString(),
239
+ placedAtTimestamp: this.placedAtTimestamp.toString(),
240
+ lastUpdatedAtTimestamp: this.lastUpdatedAtTimestamp.toString(),
241
+ requestedDebtAmount: this.requestedDebtAmount.toString(),
242
+ maxBorrowRateBps: this.maxBorrowRateBps,
243
+ padding1: this.padding1,
244
+ endPadding: this.endPadding.map((item) => item.toString()),
245
+ }
246
+ }
247
+
248
+ static fromJSON(obj: BorrowOrderJSON): BorrowOrder {
249
+ return new BorrowOrder({
250
+ debtLiquidityMint: address(obj.debtLiquidityMint),
251
+ remainingDebtAmount: new BN(obj.remainingDebtAmount),
252
+ filledDebtDestination: address(obj.filledDebtDestination),
253
+ minDebtTermSeconds: new BN(obj.minDebtTermSeconds),
254
+ fillableUntilTimestamp: new BN(obj.fillableUntilTimestamp),
255
+ placedAtTimestamp: new BN(obj.placedAtTimestamp),
256
+ lastUpdatedAtTimestamp: new BN(obj.lastUpdatedAtTimestamp),
257
+ requestedDebtAmount: new BN(obj.requestedDebtAmount),
258
+ maxBorrowRateBps: obj.maxBorrowRateBps,
259
+ padding1: obj.padding1,
260
+ endPadding: obj.endPadding.map((item) => new BN(item)),
261
+ })
262
+ }
263
+
264
+ toEncodable() {
265
+ return BorrowOrder.toEncodable(this)
266
+ }
267
+ }
@@ -0,0 +1,87 @@
1
+ import { address, Address } from "@solana/kit" // 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
+ import { borshAddress } from "../utils"
6
+
7
+ export interface BorrowOrderConfigArgsFields {
8
+ remainingDebtAmount: BN
9
+ maxBorrowRateBps: number
10
+ minDebtTermSeconds: BN
11
+ fillableUntilTimestamp: BN
12
+ }
13
+
14
+ export interface BorrowOrderConfigArgsJSON {
15
+ remainingDebtAmount: string
16
+ maxBorrowRateBps: number
17
+ minDebtTermSeconds: string
18
+ fillableUntilTimestamp: string
19
+ }
20
+
21
+ /** A subset of [BorrowOrderConfig] excluding the accounts passed via [SetBorrowOrder]. */
22
+ export class BorrowOrderConfigArgs {
23
+ readonly remainingDebtAmount: BN
24
+ readonly maxBorrowRateBps: number
25
+ readonly minDebtTermSeconds: BN
26
+ readonly fillableUntilTimestamp: BN
27
+
28
+ constructor(fields: BorrowOrderConfigArgsFields) {
29
+ this.remainingDebtAmount = fields.remainingDebtAmount
30
+ this.maxBorrowRateBps = fields.maxBorrowRateBps
31
+ this.minDebtTermSeconds = fields.minDebtTermSeconds
32
+ this.fillableUntilTimestamp = fields.fillableUntilTimestamp
33
+ }
34
+
35
+ static layout(property?: string) {
36
+ return borsh.struct(
37
+ [
38
+ borsh.u64("remainingDebtAmount"),
39
+ borsh.u32("maxBorrowRateBps"),
40
+ borsh.u64("minDebtTermSeconds"),
41
+ borsh.u64("fillableUntilTimestamp"),
42
+ ],
43
+ property
44
+ )
45
+ }
46
+
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ static fromDecoded(obj: any) {
49
+ return new BorrowOrderConfigArgs({
50
+ remainingDebtAmount: obj.remainingDebtAmount,
51
+ maxBorrowRateBps: obj.maxBorrowRateBps,
52
+ minDebtTermSeconds: obj.minDebtTermSeconds,
53
+ fillableUntilTimestamp: obj.fillableUntilTimestamp,
54
+ })
55
+ }
56
+
57
+ static toEncodable(fields: BorrowOrderConfigArgsFields) {
58
+ return {
59
+ remainingDebtAmount: fields.remainingDebtAmount,
60
+ maxBorrowRateBps: fields.maxBorrowRateBps,
61
+ minDebtTermSeconds: fields.minDebtTermSeconds,
62
+ fillableUntilTimestamp: fields.fillableUntilTimestamp,
63
+ }
64
+ }
65
+
66
+ toJSON(): BorrowOrderConfigArgsJSON {
67
+ return {
68
+ remainingDebtAmount: this.remainingDebtAmount.toString(),
69
+ maxBorrowRateBps: this.maxBorrowRateBps,
70
+ minDebtTermSeconds: this.minDebtTermSeconds.toString(),
71
+ fillableUntilTimestamp: this.fillableUntilTimestamp.toString(),
72
+ }
73
+ }
74
+
75
+ static fromJSON(obj: BorrowOrderConfigArgsJSON): BorrowOrderConfigArgs {
76
+ return new BorrowOrderConfigArgs({
77
+ remainingDebtAmount: new BN(obj.remainingDebtAmount),
78
+ maxBorrowRateBps: obj.maxBorrowRateBps,
79
+ minDebtTermSeconds: new BN(obj.minDebtTermSeconds),
80
+ fillableUntilTimestamp: new BN(obj.fillableUntilTimestamp),
81
+ })
82
+ }
83
+
84
+ toEncodable() {
85
+ return BorrowOrderConfigArgs.toEncodable(this)
86
+ }
87
+ }
@@ -9,7 +9,17 @@ export interface ObligationLiquidityFields {
9
9
  borrowReserve: Address
10
10
  /** Borrow rate used for calculating interest (big scaled fraction) */
11
11
  cumulativeBorrowRateBsf: types.BigFractionBytesFields
12
- padding: BN
12
+ /**
13
+ * The timestamp at which this debt was taken.
14
+ * More specifically: when the *first* borrow operation from this reserve happened.
15
+ * This means that:
16
+ * - adding debt of the same reserve does *not* change this timestamp,
17
+ * - repaying the entire debt of this reserve *does* reset this timestamp.
18
+ *
19
+ * Note: this field is *not* only metadata: it is used in the logic, e.g. for enforcing the
20
+ * fixed-term borrows (i.e. those induced by [ReserveConfig::debt_term_seconds]).
21
+ */
22
+ firstBorrowedAtTimestamp: BN
13
23
  /** Amount of liquidity borrowed plus interest (scaled fraction) */
14
24
  borrowedAmountSf: BN
15
25
  /** Liquidity market value in quote currency (scaled fraction) */
@@ -26,7 +36,17 @@ export interface ObligationLiquidityJSON {
26
36
  borrowReserve: string
27
37
  /** Borrow rate used for calculating interest (big scaled fraction) */
28
38
  cumulativeBorrowRateBsf: types.BigFractionBytesJSON
29
- padding: string
39
+ /**
40
+ * The timestamp at which this debt was taken.
41
+ * More specifically: when the *first* borrow operation from this reserve happened.
42
+ * This means that:
43
+ * - adding debt of the same reserve does *not* change this timestamp,
44
+ * - repaying the entire debt of this reserve *does* reset this timestamp.
45
+ *
46
+ * Note: this field is *not* only metadata: it is used in the logic, e.g. for enforcing the
47
+ * fixed-term borrows (i.e. those induced by [ReserveConfig::debt_term_seconds]).
48
+ */
49
+ firstBorrowedAtTimestamp: string
30
50
  /** Amount of liquidity borrowed plus interest (scaled fraction) */
31
51
  borrowedAmountSf: string
32
52
  /** Liquidity market value in quote currency (scaled fraction) */
@@ -44,7 +64,17 @@ export class ObligationLiquidity {
44
64
  readonly borrowReserve: Address
45
65
  /** Borrow rate used for calculating interest (big scaled fraction) */
46
66
  readonly cumulativeBorrowRateBsf: types.BigFractionBytes
47
- readonly padding: BN
67
+ /**
68
+ * The timestamp at which this debt was taken.
69
+ * More specifically: when the *first* borrow operation from this reserve happened.
70
+ * This means that:
71
+ * - adding debt of the same reserve does *not* change this timestamp,
72
+ * - repaying the entire debt of this reserve *does* reset this timestamp.
73
+ *
74
+ * Note: this field is *not* only metadata: it is used in the logic, e.g. for enforcing the
75
+ * fixed-term borrows (i.e. those induced by [ReserveConfig::debt_term_seconds]).
76
+ */
77
+ readonly firstBorrowedAtTimestamp: BN
48
78
  /** Amount of liquidity borrowed plus interest (scaled fraction) */
49
79
  readonly borrowedAmountSf: BN
50
80
  /** Liquidity market value in quote currency (scaled fraction) */
@@ -60,7 +90,7 @@ export class ObligationLiquidity {
60
90
  this.cumulativeBorrowRateBsf = new types.BigFractionBytes({
61
91
  ...fields.cumulativeBorrowRateBsf,
62
92
  })
63
- this.padding = fields.padding
93
+ this.firstBorrowedAtTimestamp = fields.firstBorrowedAtTimestamp
64
94
  this.borrowedAmountSf = fields.borrowedAmountSf
65
95
  this.marketValueSf = fields.marketValueSf
66
96
  this.borrowFactorAdjustedMarketValueSf =
@@ -75,7 +105,7 @@ export class ObligationLiquidity {
75
105
  [
76
106
  borshAddress("borrowReserve"),
77
107
  types.BigFractionBytes.layout("cumulativeBorrowRateBsf"),
78
- borsh.u64("padding"),
108
+ borsh.u64("firstBorrowedAtTimestamp"),
79
109
  borsh.u128("borrowedAmountSf"),
80
110
  borsh.u128("marketValueSf"),
81
111
  borsh.u128("borrowFactorAdjustedMarketValueSf"),
@@ -93,7 +123,7 @@ export class ObligationLiquidity {
93
123
  cumulativeBorrowRateBsf: types.BigFractionBytes.fromDecoded(
94
124
  obj.cumulativeBorrowRateBsf
95
125
  ),
96
- padding: obj.padding,
126
+ firstBorrowedAtTimestamp: obj.firstBorrowedAtTimestamp,
97
127
  borrowedAmountSf: obj.borrowedAmountSf,
98
128
  marketValueSf: obj.marketValueSf,
99
129
  borrowFactorAdjustedMarketValueSf: obj.borrowFactorAdjustedMarketValueSf,
@@ -109,7 +139,7 @@ export class ObligationLiquidity {
109
139
  cumulativeBorrowRateBsf: types.BigFractionBytes.toEncodable(
110
140
  fields.cumulativeBorrowRateBsf
111
141
  ),
112
- padding: fields.padding,
142
+ firstBorrowedAtTimestamp: fields.firstBorrowedAtTimestamp,
113
143
  borrowedAmountSf: fields.borrowedAmountSf,
114
144
  marketValueSf: fields.marketValueSf,
115
145
  borrowFactorAdjustedMarketValueSf:
@@ -124,7 +154,7 @@ export class ObligationLiquidity {
124
154
  return {
125
155
  borrowReserve: this.borrowReserve,
126
156
  cumulativeBorrowRateBsf: this.cumulativeBorrowRateBsf.toJSON(),
127
- padding: this.padding.toString(),
157
+ firstBorrowedAtTimestamp: this.firstBorrowedAtTimestamp.toString(),
128
158
  borrowedAmountSf: this.borrowedAmountSf.toString(),
129
159
  marketValueSf: this.marketValueSf.toString(),
130
160
  borrowFactorAdjustedMarketValueSf:
@@ -141,7 +171,7 @@ export class ObligationLiquidity {
141
171
  cumulativeBorrowRateBsf: types.BigFractionBytes.fromJSON(
142
172
  obj.cumulativeBorrowRateBsf
143
173
  ),
144
- padding: new BN(obj.padding),
174
+ firstBorrowedAtTimestamp: new BN(obj.firstBorrowedAtTimestamp),
145
175
  borrowedAmountSf: new BN(obj.borrowedAmountSf),
146
176
  marketValueSf: new BN(obj.marketValueSf),
147
177
  borrowFactorAdjustedMarketValueSf: new BN(