@kamino-finance/klend-sdk 7.4.0-beta.0 → 7.4.0-beta.2
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.
- package/dist/@codegen/kvault/accounts/LendingMarket.d.ts +480 -0
- package/dist/@codegen/kvault/accounts/LendingMarket.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/LendingMarket.js +480 -0
- package/dist/@codegen/kvault/accounts/LendingMarket.js.map +1 -0
- package/dist/@codegen/kvault/accounts/Obligation.d.ts +208 -0
- package/dist/@codegen/kvault/accounts/Obligation.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/Obligation.js +298 -0
- package/dist/@codegen/kvault/accounts/Obligation.js.map +1 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.d.ts +51 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.js +137 -0
- package/dist/@codegen/kvault/accounts/ReferrerTokenState.js.map +1 -0
- package/dist/@codegen/kvault/accounts/Reserve.d.ts +6 -0
- package/dist/@codegen/kvault/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/Reserve.js +9 -2
- package/dist/@codegen/kvault/accounts/Reserve.js.map +1 -1
- package/dist/@codegen/kvault/accounts/VaultState.d.ts +45 -3
- package/dist/@codegen/kvault/accounts/VaultState.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/VaultState.js +28 -4
- package/dist/@codegen/kvault/accounts/VaultState.js.map +1 -1
- package/dist/@codegen/kvault/accounts/WithdrawTicket.d.ts +144 -0
- package/dist/@codegen/kvault/accounts/WithdrawTicket.d.ts.map +1 -0
- package/dist/@codegen/kvault/accounts/WithdrawTicket.js +205 -0
- package/dist/@codegen/kvault/accounts/WithdrawTicket.js.map +1 -0
- package/dist/@codegen/kvault/accounts/index.d.ts +8 -0
- package/dist/@codegen/kvault/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/accounts/index.js +9 -1
- package/dist/@codegen/kvault/accounts/index.js.map +1 -1
- package/dist/@codegen/kvault/errors/custom.d.ts +81 -1
- package/dist/@codegen/kvault/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/kvault/errors/custom.js +141 -1
- package/dist/@codegen/kvault/errors/custom.js.map +1 -1
- package/dist/@codegen/kvault/instructions/index.d.ts +4 -0
- package/dist/@codegen/kvault/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/index.js +5 -1
- package/dist/@codegen/kvault/instructions/index.js.map +1 -1
- package/dist/@codegen/kvault/instructions/invest.d.ts +9 -0
- package/dist/@codegen/kvault/instructions/invest.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/invest.js +7 -0
- package/dist/@codegen/kvault/instructions/invest.js.map +1 -1
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.d.ts +51 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.js +154 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.js.map +1 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.d.ts +54 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.js +166 -0
- package/dist/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.d.ts +1 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.d.ts.map +1 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.js +72 -0
- package/dist/@codegen/kvault/instructions/updateKlendQueueAccounting.js.map +1 -0
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts +3 -1
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.js +3 -0
- package/dist/@codegen/kvault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/@codegen/kvault/types/BorrowOrder.d.ts +192 -0
- package/dist/@codegen/kvault/types/BorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/BorrowOrder.js +194 -0
- package/dist/@codegen/kvault/types/BorrowOrder.js.map +1 -0
- package/dist/@codegen/kvault/types/ElevationGroup.d.ts +67 -0
- package/dist/@codegen/kvault/types/ElevationGroup.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ElevationGroup.js +137 -0
- package/dist/@codegen/kvault/types/ElevationGroup.js.map +1 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.d.ts +145 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.js +144 -0
- package/dist/@codegen/kvault/types/FixedTermBorrowRolloverConfig.js.map +1 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.d.ts +72 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.js +119 -0
- package/dist/@codegen/kvault/types/ObligationCollateral.js.map +1 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.d.ts +143 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.js +165 -0
- package/dist/@codegen/kvault/types/ObligationLiquidity.js.map +1 -0
- package/dist/@codegen/kvault/types/ObligationOrder.d.ts +284 -0
- package/dist/@codegen/kvault/types/ObligationOrder.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ObligationOrder.js +205 -0
- package/dist/@codegen/kvault/types/ObligationOrder.js.map +1 -0
- package/dist/@codegen/kvault/types/ReserveConfig.d.ts +60 -5
- package/dist/@codegen/kvault/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/ReserveConfig.js +36 -7
- package/dist/@codegen/kvault/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/kvault/types/ReserveLiquidity.d.ts +26 -8
- package/dist/@codegen/kvault/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/ReserveLiquidity.js +14 -8
- package/dist/@codegen/kvault/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/kvault/types/ReserveType.d.ts +32 -0
- package/dist/@codegen/kvault/types/ReserveType.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/ReserveType.js +108 -0
- package/dist/@codegen/kvault/types/ReserveType.js.map +1 -0
- package/dist/@codegen/kvault/types/VaultAllocation.d.ts +60 -0
- package/dist/@codegen/kvault/types/VaultAllocation.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/VaultAllocation.js +38 -2
- package/dist/@codegen/kvault/types/VaultAllocation.js.map +1 -1
- package/dist/@codegen/kvault/types/WithdrawQueue.d.ts +64 -0
- package/dist/@codegen/kvault/types/WithdrawQueue.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/WithdrawQueue.js +104 -0
- package/dist/@codegen/kvault/types/WithdrawQueue.js.map +1 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.d.ts +19 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.d.ts.map +1 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.js +82 -0
- package/dist/@codegen/kvault/types/WithdrawTicketProgressEvent.js.map +1 -0
- package/dist/@codegen/kvault/types/index.d.ts +34 -0
- package/dist/@codegen/kvault/types/index.d.ts.map +1 -1
- package/dist/@codegen/kvault/types/index.js +19 -1
- package/dist/@codegen/kvault/types/index.js.map +1 -1
- package/dist/classes/action.d.ts +21 -91
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +141 -119
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +310 -0
- package/dist/classes/actionTypes.d.ts.map +1 -0
- package/dist/classes/actionTypes.js +3 -0
- package/dist/classes/actionTypes.js.map +1 -0
- package/dist/classes/market.d.ts +109 -15
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +186 -26
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +11 -11
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +56 -56
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +6 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.d.ts +9 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +20 -0
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +1 -0
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/utils.d.ts +2 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +12 -1
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +4 -2
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +12 -2
- package/dist/classes/vault.js.map +1 -1
- package/dist/client/commands/borrow.d.ts +1 -1
- package/dist/client/commands/borrow.d.ts.map +1 -1
- package/dist/client/commands/borrow.js +11 -2
- package/dist/client/commands/borrow.js.map +1 -1
- package/dist/client/commands/deposit.d.ts +1 -1
- package/dist/client/commands/deposit.d.ts.map +1 -1
- package/dist/client/commands/deposit.js +11 -2
- package/dist/client/commands/deposit.js.map +1 -1
- package/dist/client/commands/printReserve.d.ts +1 -1
- package/dist/client/commands/printReserve.d.ts.map +1 -1
- package/dist/client/commands/printReserve.js +2 -4
- package/dist/client/commands/printReserve.js.map +1 -1
- package/dist/client/commands/repay.d.ts +1 -1
- package/dist/client/commands/repay.d.ts.map +1 -1
- package/dist/client/commands/repay.js +12 -2
- package/dist/client/commands/repay.js.map +1 -1
- package/dist/client/commands/withdraw.d.ts +1 -1
- package/dist/client/commands/withdraw.d.ts.map +1 -1
- package/dist/client/commands/withdraw.js +11 -2
- package/dist/client/commands/withdraw.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +40 -21
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +6 -6
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +167 -52
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +2 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/manager/client_kamino_manager.js +0 -2
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/obligation_orders/price_based.js +5 -3
- package/dist/obligation_orders/price_based.js.map +1 -1
- package/dist/utils/ObligationType.d.ts +33 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js +81 -2
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/ReserveKind.d.ts +57 -0
- package/dist/utils/ReserveKind.d.ts.map +1 -0
- package/dist/utils/ReserveKind.js +76 -0
- package/dist/utils/ReserveKind.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +2 -2
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +49 -25
- package/dist/utils/userMetadata.js.map +1 -1
- package/dist/utils/validations.d.ts +1 -0
- package/dist/utils/validations.d.ts.map +1 -1
- package/dist/utils/validations.js +5 -0
- package/dist/utils/validations.js.map +1 -1
- package/dist/utils/vault.d.ts.map +1 -1
- package/dist/utils/vault.js +2 -0
- package/dist/utils/vault.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/kvault/accounts/LendingMarket.ts +837 -0
- package/src/@codegen/kvault/accounts/Obligation.ts +459 -0
- package/src/@codegen/kvault/accounts/ReferrerTokenState.ts +160 -0
- package/src/@codegen/kvault/accounts/Reserve.ts +13 -2
- package/src/@codegen/kvault/accounts/VaultState.ts +59 -7
- package/src/@codegen/kvault/accounts/WithdrawTicket.ts +280 -0
- package/src/@codegen/kvault/accounts/index.ts +11 -0
- package/src/@codegen/kvault/errors/custom.ts +152 -0
- package/src/@codegen/kvault/instructions/index.ts +10 -0
- package/src/@codegen/kvault/instructions/invest.ts +16 -0
- package/src/@codegen/kvault/instructions/investInVirtualReserveAndFillOrder.ts +189 -0
- package/src/@codegen/kvault/instructions/investInVirtualReserveAndFillWithdrawalTicket.ts +205 -0
- package/src/@codegen/kvault/instructions/updateKlendQueueAccounting.ts +76 -0
- package/src/@codegen/kvault/instructions/updateReserveAllocation.ts +4 -1
- package/src/@codegen/kvault/types/BorrowOrder.ts +267 -0
- package/src/@codegen/kvault/types/ElevationGroup.ts +134 -0
- package/src/@codegen/kvault/types/FixedTermBorrowRolloverConfig.ts +199 -0
- package/src/@codegen/kvault/types/ObligationCollateral.ts +129 -0
- package/src/@codegen/kvault/types/ObligationLiquidity.ts +226 -0
- package/src/@codegen/kvault/types/ObligationOrder.ts +348 -0
- package/src/@codegen/kvault/types/ReserveConfig.ts +72 -9
- package/src/@codegen/kvault/types/ReserveLiquidity.ts +30 -12
- package/src/@codegen/kvault/types/ReserveType.ts +89 -0
- package/src/@codegen/kvault/types/VaultAllocation.ts +74 -2
- package/src/@codegen/kvault/types/WithdrawQueue.ts +117 -0
- package/src/@codegen/kvault/types/WithdrawTicketProgressEvent.ts +59 -0
- package/src/@codegen/kvault/types/index.ts +52 -0
- package/src/classes/action.ts +321 -347
- package/src/classes/actionTypes.ts +295 -0
- package/src/classes/manager.ts +1 -1
- package/src/classes/market.ts +232 -30
- package/src/classes/obligation.ts +62 -59
- package/src/classes/obligationOrder.ts +6 -3
- package/src/classes/reserve.ts +24 -0
- package/src/classes/shared.ts +2 -0
- package/src/classes/utils.ts +8 -0
- package/src/classes/vault.ts +35 -4
- package/src/client/client.ts +17 -18
- package/src/client/commands/borrow.ts +10 -9
- package/src/client/commands/deposit.ts +10 -9
- package/src/client/commands/printReserve.ts +2 -4
- package/src/client/commands/repay.ts +11 -10
- package/src/client/commands/withdraw.ts +15 -9
- package/src/idl/kvault.json +2336 -299
- package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
- package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
- package/src/lending_operations/swap_collateral_operations.ts +47 -41
- package/src/leverage/operations.ts +168 -129
- package/src/leverage/types.ts +2 -2
- package/src/manager/client_kamino_manager.ts +0 -2
- package/src/obligation_orders/price_based.ts +7 -5
- package/src/utils/ObligationType.ts +92 -1
- package/src/utils/ReserveKind.ts +94 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/userMetadata.ts +64 -30
- package/src/utils/validations.ts +5 -0
- package/src/utils/vault.ts +2 -0
|
@@ -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 open-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 open-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 open-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,134 @@
|
|
|
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 ElevationGroupFields {
|
|
8
|
+
maxLiquidationBonusBps: number
|
|
9
|
+
id: number
|
|
10
|
+
ltvPct: number
|
|
11
|
+
liquidationThresholdPct: number
|
|
12
|
+
allowNewLoans: number
|
|
13
|
+
maxReservesAsCollateral: number
|
|
14
|
+
padding0: number
|
|
15
|
+
/** Mandatory debt reserve for this elevation group */
|
|
16
|
+
debtReserve: Address
|
|
17
|
+
padding1: Array<BN>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ElevationGroupJSON {
|
|
21
|
+
maxLiquidationBonusBps: number
|
|
22
|
+
id: number
|
|
23
|
+
ltvPct: number
|
|
24
|
+
liquidationThresholdPct: number
|
|
25
|
+
allowNewLoans: number
|
|
26
|
+
maxReservesAsCollateral: number
|
|
27
|
+
padding0: number
|
|
28
|
+
/** Mandatory debt reserve for this elevation group */
|
|
29
|
+
debtReserve: string
|
|
30
|
+
padding1: Array<string>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class ElevationGroup {
|
|
34
|
+
readonly maxLiquidationBonusBps: number
|
|
35
|
+
readonly id: number
|
|
36
|
+
readonly ltvPct: number
|
|
37
|
+
readonly liquidationThresholdPct: number
|
|
38
|
+
readonly allowNewLoans: number
|
|
39
|
+
readonly maxReservesAsCollateral: number
|
|
40
|
+
readonly padding0: number
|
|
41
|
+
/** Mandatory debt reserve for this elevation group */
|
|
42
|
+
readonly debtReserve: Address
|
|
43
|
+
readonly padding1: Array<BN>
|
|
44
|
+
|
|
45
|
+
constructor(fields: ElevationGroupFields) {
|
|
46
|
+
this.maxLiquidationBonusBps = fields.maxLiquidationBonusBps
|
|
47
|
+
this.id = fields.id
|
|
48
|
+
this.ltvPct = fields.ltvPct
|
|
49
|
+
this.liquidationThresholdPct = fields.liquidationThresholdPct
|
|
50
|
+
this.allowNewLoans = fields.allowNewLoans
|
|
51
|
+
this.maxReservesAsCollateral = fields.maxReservesAsCollateral
|
|
52
|
+
this.padding0 = fields.padding0
|
|
53
|
+
this.debtReserve = fields.debtReserve
|
|
54
|
+
this.padding1 = fields.padding1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static layout(property?: string) {
|
|
58
|
+
return borsh.struct(
|
|
59
|
+
[
|
|
60
|
+
borsh.u16("maxLiquidationBonusBps"),
|
|
61
|
+
borsh.u8("id"),
|
|
62
|
+
borsh.u8("ltvPct"),
|
|
63
|
+
borsh.u8("liquidationThresholdPct"),
|
|
64
|
+
borsh.u8("allowNewLoans"),
|
|
65
|
+
borsh.u8("maxReservesAsCollateral"),
|
|
66
|
+
borsh.u8("padding0"),
|
|
67
|
+
borshAddress("debtReserve"),
|
|
68
|
+
borsh.array(borsh.u64(), 4, "padding1"),
|
|
69
|
+
],
|
|
70
|
+
property
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
static fromDecoded(obj: any) {
|
|
76
|
+
return new ElevationGroup({
|
|
77
|
+
maxLiquidationBonusBps: obj.maxLiquidationBonusBps,
|
|
78
|
+
id: obj.id,
|
|
79
|
+
ltvPct: obj.ltvPct,
|
|
80
|
+
liquidationThresholdPct: obj.liquidationThresholdPct,
|
|
81
|
+
allowNewLoans: obj.allowNewLoans,
|
|
82
|
+
maxReservesAsCollateral: obj.maxReservesAsCollateral,
|
|
83
|
+
padding0: obj.padding0,
|
|
84
|
+
debtReserve: obj.debtReserve,
|
|
85
|
+
padding1: obj.padding1,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static toEncodable(fields: ElevationGroupFields) {
|
|
90
|
+
return {
|
|
91
|
+
maxLiquidationBonusBps: fields.maxLiquidationBonusBps,
|
|
92
|
+
id: fields.id,
|
|
93
|
+
ltvPct: fields.ltvPct,
|
|
94
|
+
liquidationThresholdPct: fields.liquidationThresholdPct,
|
|
95
|
+
allowNewLoans: fields.allowNewLoans,
|
|
96
|
+
maxReservesAsCollateral: fields.maxReservesAsCollateral,
|
|
97
|
+
padding0: fields.padding0,
|
|
98
|
+
debtReserve: fields.debtReserve,
|
|
99
|
+
padding1: fields.padding1,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
toJSON(): ElevationGroupJSON {
|
|
104
|
+
return {
|
|
105
|
+
maxLiquidationBonusBps: this.maxLiquidationBonusBps,
|
|
106
|
+
id: this.id,
|
|
107
|
+
ltvPct: this.ltvPct,
|
|
108
|
+
liquidationThresholdPct: this.liquidationThresholdPct,
|
|
109
|
+
allowNewLoans: this.allowNewLoans,
|
|
110
|
+
maxReservesAsCollateral: this.maxReservesAsCollateral,
|
|
111
|
+
padding0: this.padding0,
|
|
112
|
+
debtReserve: this.debtReserve,
|
|
113
|
+
padding1: this.padding1.map((item) => item.toString()),
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static fromJSON(obj: ElevationGroupJSON): ElevationGroup {
|
|
118
|
+
return new ElevationGroup({
|
|
119
|
+
maxLiquidationBonusBps: obj.maxLiquidationBonusBps,
|
|
120
|
+
id: obj.id,
|
|
121
|
+
ltvPct: obj.ltvPct,
|
|
122
|
+
liquidationThresholdPct: obj.liquidationThresholdPct,
|
|
123
|
+
allowNewLoans: obj.allowNewLoans,
|
|
124
|
+
maxReservesAsCollateral: obj.maxReservesAsCollateral,
|
|
125
|
+
padding0: obj.padding0,
|
|
126
|
+
debtReserve: address(obj.debtReserve),
|
|
127
|
+
padding1: obj.padding1.map((item) => new BN(item)),
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
toEncodable() {
|
|
132
|
+
return ElevationGroup.toEncodable(this)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 FixedTermBorrowRolloverConfigFields {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the borrow can be permissionlessly prolonged under the following *joint* conditions:
|
|
10
|
+
*
|
|
11
|
+
* The reserve used to re-borrow the liquidity must have:
|
|
12
|
+
* A) the exact same maximum borrow rate as the current one,
|
|
13
|
+
* B) the exact same debt term as the current one,
|
|
14
|
+
* C) sufficient available liquidity (including no withdraw tickets waiting in its queue).
|
|
15
|
+
*
|
|
16
|
+
* The time left until the current debt term expires must be:
|
|
17
|
+
* D) less than [LendingMarket::fixed_rollover_window_duration_seconds].
|
|
18
|
+
*
|
|
19
|
+
* Note: the other settings are only effective when this one is `1`.
|
|
20
|
+
*/
|
|
21
|
+
autoRolloverEnabled: number
|
|
22
|
+
/**
|
|
23
|
+
* When `1`, partially lifts the condition *B* from [Self::auto_rollover_enabled]: additionally
|
|
24
|
+
* allows to use a variable (indefinite) debt term if less than
|
|
25
|
+
* [LendingMarket::variable_rollover_window_duration_seconds] is left until expiration.
|
|
26
|
+
*
|
|
27
|
+
* Note: typically this flag should be used together with [Self::max_borrow_rate_bps] set to
|
|
28
|
+
* `u32::MAX` (to denote a variable-rate reserve).
|
|
29
|
+
*/
|
|
30
|
+
openTermAllowed: number
|
|
31
|
+
/** Internal alignment padding (free to reuse). */
|
|
32
|
+
alignmentPadding: Array<number>
|
|
33
|
+
/**
|
|
34
|
+
* A customization setting that can lift the condition *A* from [Self::auto_rollover_enabled]:
|
|
35
|
+
* when not zeroed, the rollover may use a reserve with a maximum borrow rate equal or lower
|
|
36
|
+
* than the given one.
|
|
37
|
+
*/
|
|
38
|
+
maxBorrowRateBps: number
|
|
39
|
+
/**
|
|
40
|
+
* A customization setting that can lift the condition *B* from [Self::auto_rollover_enabled]:
|
|
41
|
+
* when not zeroed, the rollover may use a reserve with a *fixed* debt term equal or longer
|
|
42
|
+
* than the given one.
|
|
43
|
+
*/
|
|
44
|
+
minDebtTermSeconds: BN
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface FixedTermBorrowRolloverConfigJSON {
|
|
48
|
+
/**
|
|
49
|
+
* Whether the borrow can be permissionlessly prolonged under the following *joint* conditions:
|
|
50
|
+
*
|
|
51
|
+
* The reserve used to re-borrow the liquidity must have:
|
|
52
|
+
* A) the exact same maximum borrow rate as the current one,
|
|
53
|
+
* B) the exact same debt term as the current one,
|
|
54
|
+
* C) sufficient available liquidity (including no withdraw tickets waiting in its queue).
|
|
55
|
+
*
|
|
56
|
+
* The time left until the current debt term expires must be:
|
|
57
|
+
* D) less than [LendingMarket::fixed_rollover_window_duration_seconds].
|
|
58
|
+
*
|
|
59
|
+
* Note: the other settings are only effective when this one is `1`.
|
|
60
|
+
*/
|
|
61
|
+
autoRolloverEnabled: number
|
|
62
|
+
/**
|
|
63
|
+
* When `1`, partially lifts the condition *B* from [Self::auto_rollover_enabled]: additionally
|
|
64
|
+
* allows to use a variable (indefinite) debt term if less than
|
|
65
|
+
* [LendingMarket::variable_rollover_window_duration_seconds] is left until expiration.
|
|
66
|
+
*
|
|
67
|
+
* Note: typically this flag should be used together with [Self::max_borrow_rate_bps] set to
|
|
68
|
+
* `u32::MAX` (to denote a variable-rate reserve).
|
|
69
|
+
*/
|
|
70
|
+
openTermAllowed: number
|
|
71
|
+
/** Internal alignment padding (free to reuse). */
|
|
72
|
+
alignmentPadding: Array<number>
|
|
73
|
+
/**
|
|
74
|
+
* A customization setting that can lift the condition *A* from [Self::auto_rollover_enabled]:
|
|
75
|
+
* when not zeroed, the rollover may use a reserve with a maximum borrow rate equal or lower
|
|
76
|
+
* than the given one.
|
|
77
|
+
*/
|
|
78
|
+
maxBorrowRateBps: number
|
|
79
|
+
/**
|
|
80
|
+
* A customization setting that can lift the condition *B* from [Self::auto_rollover_enabled]:
|
|
81
|
+
* when not zeroed, the rollover may use a reserve with a *fixed* debt term equal or longer
|
|
82
|
+
* than the given one.
|
|
83
|
+
*/
|
|
84
|
+
minDebtTermSeconds: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Settings driving the auto-rollover of an [ObligationLiquidity] that uses a fixed-term [Reserve]
|
|
89
|
+
* and approaches the end of its [ReserveConfig::debt_term_seconds].
|
|
90
|
+
*
|
|
91
|
+
* By its nature (not a special case), the zeroed struct mean "no auto-rollover".
|
|
92
|
+
*/
|
|
93
|
+
export class FixedTermBorrowRolloverConfig {
|
|
94
|
+
/**
|
|
95
|
+
* Whether the borrow can be permissionlessly prolonged under the following *joint* conditions:
|
|
96
|
+
*
|
|
97
|
+
* The reserve used to re-borrow the liquidity must have:
|
|
98
|
+
* A) the exact same maximum borrow rate as the current one,
|
|
99
|
+
* B) the exact same debt term as the current one,
|
|
100
|
+
* C) sufficient available liquidity (including no withdraw tickets waiting in its queue).
|
|
101
|
+
*
|
|
102
|
+
* The time left until the current debt term expires must be:
|
|
103
|
+
* D) less than [LendingMarket::fixed_rollover_window_duration_seconds].
|
|
104
|
+
*
|
|
105
|
+
* Note: the other settings are only effective when this one is `1`.
|
|
106
|
+
*/
|
|
107
|
+
readonly autoRolloverEnabled: number
|
|
108
|
+
/**
|
|
109
|
+
* When `1`, partially lifts the condition *B* from [Self::auto_rollover_enabled]: additionally
|
|
110
|
+
* allows to use a variable (indefinite) debt term if less than
|
|
111
|
+
* [LendingMarket::variable_rollover_window_duration_seconds] is left until expiration.
|
|
112
|
+
*
|
|
113
|
+
* Note: typically this flag should be used together with [Self::max_borrow_rate_bps] set to
|
|
114
|
+
* `u32::MAX` (to denote a variable-rate reserve).
|
|
115
|
+
*/
|
|
116
|
+
readonly openTermAllowed: number
|
|
117
|
+
/** Internal alignment padding (free to reuse). */
|
|
118
|
+
readonly alignmentPadding: Array<number>
|
|
119
|
+
/**
|
|
120
|
+
* A customization setting that can lift the condition *A* from [Self::auto_rollover_enabled]:
|
|
121
|
+
* when not zeroed, the rollover may use a reserve with a maximum borrow rate equal or lower
|
|
122
|
+
* than the given one.
|
|
123
|
+
*/
|
|
124
|
+
readonly maxBorrowRateBps: number
|
|
125
|
+
/**
|
|
126
|
+
* A customization setting that can lift the condition *B* from [Self::auto_rollover_enabled]:
|
|
127
|
+
* when not zeroed, the rollover may use a reserve with a *fixed* debt term equal or longer
|
|
128
|
+
* than the given one.
|
|
129
|
+
*/
|
|
130
|
+
readonly minDebtTermSeconds: BN
|
|
131
|
+
|
|
132
|
+
constructor(fields: FixedTermBorrowRolloverConfigFields) {
|
|
133
|
+
this.autoRolloverEnabled = fields.autoRolloverEnabled
|
|
134
|
+
this.openTermAllowed = fields.openTermAllowed
|
|
135
|
+
this.alignmentPadding = fields.alignmentPadding
|
|
136
|
+
this.maxBorrowRateBps = fields.maxBorrowRateBps
|
|
137
|
+
this.minDebtTermSeconds = fields.minDebtTermSeconds
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static layout(property?: string) {
|
|
141
|
+
return borsh.struct(
|
|
142
|
+
[
|
|
143
|
+
borsh.u8("autoRolloverEnabled"),
|
|
144
|
+
borsh.u8("openTermAllowed"),
|
|
145
|
+
borsh.array(borsh.u8(), 2, "alignmentPadding"),
|
|
146
|
+
borsh.u32("maxBorrowRateBps"),
|
|
147
|
+
borsh.u64("minDebtTermSeconds"),
|
|
148
|
+
],
|
|
149
|
+
property
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
+
static fromDecoded(obj: any) {
|
|
155
|
+
return new FixedTermBorrowRolloverConfig({
|
|
156
|
+
autoRolloverEnabled: obj.autoRolloverEnabled,
|
|
157
|
+
openTermAllowed: obj.openTermAllowed,
|
|
158
|
+
alignmentPadding: obj.alignmentPadding,
|
|
159
|
+
maxBorrowRateBps: obj.maxBorrowRateBps,
|
|
160
|
+
minDebtTermSeconds: obj.minDebtTermSeconds,
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
static toEncodable(fields: FixedTermBorrowRolloverConfigFields) {
|
|
165
|
+
return {
|
|
166
|
+
autoRolloverEnabled: fields.autoRolloverEnabled,
|
|
167
|
+
openTermAllowed: fields.openTermAllowed,
|
|
168
|
+
alignmentPadding: fields.alignmentPadding,
|
|
169
|
+
maxBorrowRateBps: fields.maxBorrowRateBps,
|
|
170
|
+
minDebtTermSeconds: fields.minDebtTermSeconds,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
toJSON(): FixedTermBorrowRolloverConfigJSON {
|
|
175
|
+
return {
|
|
176
|
+
autoRolloverEnabled: this.autoRolloverEnabled,
|
|
177
|
+
openTermAllowed: this.openTermAllowed,
|
|
178
|
+
alignmentPadding: this.alignmentPadding,
|
|
179
|
+
maxBorrowRateBps: this.maxBorrowRateBps,
|
|
180
|
+
minDebtTermSeconds: this.minDebtTermSeconds.toString(),
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
static fromJSON(
|
|
185
|
+
obj: FixedTermBorrowRolloverConfigJSON
|
|
186
|
+
): FixedTermBorrowRolloverConfig {
|
|
187
|
+
return new FixedTermBorrowRolloverConfig({
|
|
188
|
+
autoRolloverEnabled: obj.autoRolloverEnabled,
|
|
189
|
+
openTermAllowed: obj.openTermAllowed,
|
|
190
|
+
alignmentPadding: obj.alignmentPadding,
|
|
191
|
+
maxBorrowRateBps: obj.maxBorrowRateBps,
|
|
192
|
+
minDebtTermSeconds: new BN(obj.minDebtTermSeconds),
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
toEncodable() {
|
|
197
|
+
return FixedTermBorrowRolloverConfig.toEncodable(this)
|
|
198
|
+
}
|
|
199
|
+
}
|