@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,129 @@
|
|
|
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 ObligationCollateralFields {
|
|
8
|
+
/** Reserve collateral is deposited to */
|
|
9
|
+
depositReserve: Address
|
|
10
|
+
/** Amount of collateral deposited */
|
|
11
|
+
depositedAmount: BN
|
|
12
|
+
/** Collateral market value in quote currency (scaled fraction) */
|
|
13
|
+
marketValueSf: BN
|
|
14
|
+
/**
|
|
15
|
+
* Debt amount (lamport) taken against this collateral.
|
|
16
|
+
* (only meaningful if this obligation is part of an elevation group, otherwise 0)
|
|
17
|
+
* This is only indicative of the debt computed on the last refresh obligation.
|
|
18
|
+
* If the obligation have multiple collateral this value is the same for all of them.
|
|
19
|
+
*/
|
|
20
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: BN
|
|
21
|
+
padding: Array<BN>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ObligationCollateralJSON {
|
|
25
|
+
/** Reserve collateral is deposited to */
|
|
26
|
+
depositReserve: string
|
|
27
|
+
/** Amount of collateral deposited */
|
|
28
|
+
depositedAmount: string
|
|
29
|
+
/** Collateral market value in quote currency (scaled fraction) */
|
|
30
|
+
marketValueSf: string
|
|
31
|
+
/**
|
|
32
|
+
* Debt amount (lamport) taken against this collateral.
|
|
33
|
+
* (only meaningful if this obligation is part of an elevation group, otherwise 0)
|
|
34
|
+
* This is only indicative of the debt computed on the last refresh obligation.
|
|
35
|
+
* If the obligation have multiple collateral this value is the same for all of them.
|
|
36
|
+
*/
|
|
37
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: string
|
|
38
|
+
padding: Array<string>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Obligation collateral state */
|
|
42
|
+
export class ObligationCollateral {
|
|
43
|
+
/** Reserve collateral is deposited to */
|
|
44
|
+
readonly depositReserve: Address
|
|
45
|
+
/** Amount of collateral deposited */
|
|
46
|
+
readonly depositedAmount: BN
|
|
47
|
+
/** Collateral market value in quote currency (scaled fraction) */
|
|
48
|
+
readonly marketValueSf: BN
|
|
49
|
+
/**
|
|
50
|
+
* Debt amount (lamport) taken against this collateral.
|
|
51
|
+
* (only meaningful if this obligation is part of an elevation group, otherwise 0)
|
|
52
|
+
* This is only indicative of the debt computed on the last refresh obligation.
|
|
53
|
+
* If the obligation have multiple collateral this value is the same for all of them.
|
|
54
|
+
*/
|
|
55
|
+
readonly borrowedAmountAgainstThisCollateralInElevationGroup: BN
|
|
56
|
+
readonly padding: Array<BN>
|
|
57
|
+
|
|
58
|
+
constructor(fields: ObligationCollateralFields) {
|
|
59
|
+
this.depositReserve = fields.depositReserve
|
|
60
|
+
this.depositedAmount = fields.depositedAmount
|
|
61
|
+
this.marketValueSf = fields.marketValueSf
|
|
62
|
+
this.borrowedAmountAgainstThisCollateralInElevationGroup =
|
|
63
|
+
fields.borrowedAmountAgainstThisCollateralInElevationGroup
|
|
64
|
+
this.padding = fields.padding
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static layout(property?: string) {
|
|
68
|
+
return borsh.struct(
|
|
69
|
+
[
|
|
70
|
+
borshAddress("depositReserve"),
|
|
71
|
+
borsh.u64("depositedAmount"),
|
|
72
|
+
borsh.u128("marketValueSf"),
|
|
73
|
+
borsh.u64("borrowedAmountAgainstThisCollateralInElevationGroup"),
|
|
74
|
+
borsh.array(borsh.u64(), 9, "padding"),
|
|
75
|
+
],
|
|
76
|
+
property
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
static fromDecoded(obj: any) {
|
|
82
|
+
return new ObligationCollateral({
|
|
83
|
+
depositReserve: obj.depositReserve,
|
|
84
|
+
depositedAmount: obj.depositedAmount,
|
|
85
|
+
marketValueSf: obj.marketValueSf,
|
|
86
|
+
borrowedAmountAgainstThisCollateralInElevationGroup:
|
|
87
|
+
obj.borrowedAmountAgainstThisCollateralInElevationGroup,
|
|
88
|
+
padding: obj.padding,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static toEncodable(fields: ObligationCollateralFields) {
|
|
93
|
+
return {
|
|
94
|
+
depositReserve: fields.depositReserve,
|
|
95
|
+
depositedAmount: fields.depositedAmount,
|
|
96
|
+
marketValueSf: fields.marketValueSf,
|
|
97
|
+
borrowedAmountAgainstThisCollateralInElevationGroup:
|
|
98
|
+
fields.borrowedAmountAgainstThisCollateralInElevationGroup,
|
|
99
|
+
padding: fields.padding,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
toJSON(): ObligationCollateralJSON {
|
|
104
|
+
return {
|
|
105
|
+
depositReserve: this.depositReserve,
|
|
106
|
+
depositedAmount: this.depositedAmount.toString(),
|
|
107
|
+
marketValueSf: this.marketValueSf.toString(),
|
|
108
|
+
borrowedAmountAgainstThisCollateralInElevationGroup:
|
|
109
|
+
this.borrowedAmountAgainstThisCollateralInElevationGroup.toString(),
|
|
110
|
+
padding: this.padding.map((item) => item.toString()),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static fromJSON(obj: ObligationCollateralJSON): ObligationCollateral {
|
|
115
|
+
return new ObligationCollateral({
|
|
116
|
+
depositReserve: address(obj.depositReserve),
|
|
117
|
+
depositedAmount: new BN(obj.depositedAmount),
|
|
118
|
+
marketValueSf: new BN(obj.marketValueSf),
|
|
119
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: new BN(
|
|
120
|
+
obj.borrowedAmountAgainstThisCollateralInElevationGroup
|
|
121
|
+
),
|
|
122
|
+
padding: obj.padding.map((item) => new BN(item)),
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
toEncodable() {
|
|
127
|
+
return ObligationCollateral.toEncodable(this)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
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 ObligationLiquidityFields {
|
|
8
|
+
/** Reserve liquidity is borrowed from */
|
|
9
|
+
borrowReserve: Address
|
|
10
|
+
/** Borrow rate used for calculating interest (big scaled fraction) */
|
|
11
|
+
cumulativeBorrowRateBsf: types.BigFractionBytesFields
|
|
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
|
|
23
|
+
/** Amount of liquidity borrowed plus interest (scaled fraction) */
|
|
24
|
+
borrowedAmountSf: BN
|
|
25
|
+
/** Liquidity market value in quote currency (scaled fraction) */
|
|
26
|
+
marketValueSf: BN
|
|
27
|
+
/** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */
|
|
28
|
+
borrowFactorAdjustedMarketValueSf: BN
|
|
29
|
+
/** Amount of liquidity borrowed outside of an elevation group */
|
|
30
|
+
borrowedAmountOutsideElevationGroups: BN
|
|
31
|
+
/**
|
|
32
|
+
* The user's auto-rollover opt-ins - only effective when this borrow is fixed-term (i.e. its
|
|
33
|
+
* reserve has a non-zero [ReserveConfig::debt_term_seconds]).
|
|
34
|
+
*/
|
|
35
|
+
fixedTermBorrowRolloverConfig: types.FixedTermBorrowRolloverConfigFields
|
|
36
|
+
padding2: Array<BN>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ObligationLiquidityJSON {
|
|
40
|
+
/** Reserve liquidity is borrowed from */
|
|
41
|
+
borrowReserve: string
|
|
42
|
+
/** Borrow rate used for calculating interest (big scaled fraction) */
|
|
43
|
+
cumulativeBorrowRateBsf: types.BigFractionBytesJSON
|
|
44
|
+
/**
|
|
45
|
+
* The timestamp at which this debt was taken.
|
|
46
|
+
* More specifically: when the *first* borrow operation from this reserve happened.
|
|
47
|
+
* This means that:
|
|
48
|
+
* - adding debt of the same reserve does *not* change this timestamp,
|
|
49
|
+
* - repaying the entire debt of this reserve *does* reset this timestamp.
|
|
50
|
+
*
|
|
51
|
+
* Note: this field is *not* only metadata: it is used in the logic, e.g. for enforcing the
|
|
52
|
+
* fixed-term borrows (i.e. those induced by [ReserveConfig::debt_term_seconds]).
|
|
53
|
+
*/
|
|
54
|
+
firstBorrowedAtTimestamp: string
|
|
55
|
+
/** Amount of liquidity borrowed plus interest (scaled fraction) */
|
|
56
|
+
borrowedAmountSf: string
|
|
57
|
+
/** Liquidity market value in quote currency (scaled fraction) */
|
|
58
|
+
marketValueSf: string
|
|
59
|
+
/** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */
|
|
60
|
+
borrowFactorAdjustedMarketValueSf: string
|
|
61
|
+
/** Amount of liquidity borrowed outside of an elevation group */
|
|
62
|
+
borrowedAmountOutsideElevationGroups: string
|
|
63
|
+
/**
|
|
64
|
+
* The user's auto-rollover opt-ins - only effective when this borrow is fixed-term (i.e. its
|
|
65
|
+
* reserve has a non-zero [ReserveConfig::debt_term_seconds]).
|
|
66
|
+
*/
|
|
67
|
+
fixedTermBorrowRolloverConfig: types.FixedTermBorrowRolloverConfigJSON
|
|
68
|
+
padding2: Array<string>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Obligation liquidity state */
|
|
72
|
+
export class ObligationLiquidity {
|
|
73
|
+
/** Reserve liquidity is borrowed from */
|
|
74
|
+
readonly borrowReserve: Address
|
|
75
|
+
/** Borrow rate used for calculating interest (big scaled fraction) */
|
|
76
|
+
readonly cumulativeBorrowRateBsf: types.BigFractionBytes
|
|
77
|
+
/**
|
|
78
|
+
* The timestamp at which this debt was taken.
|
|
79
|
+
* More specifically: when the *first* borrow operation from this reserve happened.
|
|
80
|
+
* This means that:
|
|
81
|
+
* - adding debt of the same reserve does *not* change this timestamp,
|
|
82
|
+
* - repaying the entire debt of this reserve *does* reset this timestamp.
|
|
83
|
+
*
|
|
84
|
+
* Note: this field is *not* only metadata: it is used in the logic, e.g. for enforcing the
|
|
85
|
+
* fixed-term borrows (i.e. those induced by [ReserveConfig::debt_term_seconds]).
|
|
86
|
+
*/
|
|
87
|
+
readonly firstBorrowedAtTimestamp: BN
|
|
88
|
+
/** Amount of liquidity borrowed plus interest (scaled fraction) */
|
|
89
|
+
readonly borrowedAmountSf: BN
|
|
90
|
+
/** Liquidity market value in quote currency (scaled fraction) */
|
|
91
|
+
readonly marketValueSf: BN
|
|
92
|
+
/** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */
|
|
93
|
+
readonly borrowFactorAdjustedMarketValueSf: BN
|
|
94
|
+
/** Amount of liquidity borrowed outside of an elevation group */
|
|
95
|
+
readonly borrowedAmountOutsideElevationGroups: BN
|
|
96
|
+
/**
|
|
97
|
+
* The user's auto-rollover opt-ins - only effective when this borrow is fixed-term (i.e. its
|
|
98
|
+
* reserve has a non-zero [ReserveConfig::debt_term_seconds]).
|
|
99
|
+
*/
|
|
100
|
+
readonly fixedTermBorrowRolloverConfig: types.FixedTermBorrowRolloverConfig
|
|
101
|
+
readonly padding2: Array<BN>
|
|
102
|
+
|
|
103
|
+
constructor(fields: ObligationLiquidityFields) {
|
|
104
|
+
this.borrowReserve = fields.borrowReserve
|
|
105
|
+
this.cumulativeBorrowRateBsf = new types.BigFractionBytes({
|
|
106
|
+
...fields.cumulativeBorrowRateBsf,
|
|
107
|
+
})
|
|
108
|
+
this.firstBorrowedAtTimestamp = fields.firstBorrowedAtTimestamp
|
|
109
|
+
this.borrowedAmountSf = fields.borrowedAmountSf
|
|
110
|
+
this.marketValueSf = fields.marketValueSf
|
|
111
|
+
this.borrowFactorAdjustedMarketValueSf =
|
|
112
|
+
fields.borrowFactorAdjustedMarketValueSf
|
|
113
|
+
this.borrowedAmountOutsideElevationGroups =
|
|
114
|
+
fields.borrowedAmountOutsideElevationGroups
|
|
115
|
+
this.fixedTermBorrowRolloverConfig =
|
|
116
|
+
new types.FixedTermBorrowRolloverConfig({
|
|
117
|
+
...fields.fixedTermBorrowRolloverConfig,
|
|
118
|
+
})
|
|
119
|
+
this.padding2 = fields.padding2
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static layout(property?: string) {
|
|
123
|
+
return borsh.struct(
|
|
124
|
+
[
|
|
125
|
+
borshAddress("borrowReserve"),
|
|
126
|
+
types.BigFractionBytes.layout("cumulativeBorrowRateBsf"),
|
|
127
|
+
borsh.u64("firstBorrowedAtTimestamp"),
|
|
128
|
+
borsh.u128("borrowedAmountSf"),
|
|
129
|
+
borsh.u128("marketValueSf"),
|
|
130
|
+
borsh.u128("borrowFactorAdjustedMarketValueSf"),
|
|
131
|
+
borsh.u64("borrowedAmountOutsideElevationGroups"),
|
|
132
|
+
types.FixedTermBorrowRolloverConfig.layout(
|
|
133
|
+
"fixedTermBorrowRolloverConfig"
|
|
134
|
+
),
|
|
135
|
+
borsh.array(borsh.u64(), 5, "padding2"),
|
|
136
|
+
],
|
|
137
|
+
property
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
|
+
static fromDecoded(obj: any) {
|
|
143
|
+
return new ObligationLiquidity({
|
|
144
|
+
borrowReserve: obj.borrowReserve,
|
|
145
|
+
cumulativeBorrowRateBsf: types.BigFractionBytes.fromDecoded(
|
|
146
|
+
obj.cumulativeBorrowRateBsf
|
|
147
|
+
),
|
|
148
|
+
firstBorrowedAtTimestamp: obj.firstBorrowedAtTimestamp,
|
|
149
|
+
borrowedAmountSf: obj.borrowedAmountSf,
|
|
150
|
+
marketValueSf: obj.marketValueSf,
|
|
151
|
+
borrowFactorAdjustedMarketValueSf: obj.borrowFactorAdjustedMarketValueSf,
|
|
152
|
+
borrowedAmountOutsideElevationGroups:
|
|
153
|
+
obj.borrowedAmountOutsideElevationGroups,
|
|
154
|
+
fixedTermBorrowRolloverConfig:
|
|
155
|
+
types.FixedTermBorrowRolloverConfig.fromDecoded(
|
|
156
|
+
obj.fixedTermBorrowRolloverConfig
|
|
157
|
+
),
|
|
158
|
+
padding2: obj.padding2,
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static toEncodable(fields: ObligationLiquidityFields) {
|
|
163
|
+
return {
|
|
164
|
+
borrowReserve: fields.borrowReserve,
|
|
165
|
+
cumulativeBorrowRateBsf: types.BigFractionBytes.toEncodable(
|
|
166
|
+
fields.cumulativeBorrowRateBsf
|
|
167
|
+
),
|
|
168
|
+
firstBorrowedAtTimestamp: fields.firstBorrowedAtTimestamp,
|
|
169
|
+
borrowedAmountSf: fields.borrowedAmountSf,
|
|
170
|
+
marketValueSf: fields.marketValueSf,
|
|
171
|
+
borrowFactorAdjustedMarketValueSf:
|
|
172
|
+
fields.borrowFactorAdjustedMarketValueSf,
|
|
173
|
+
borrowedAmountOutsideElevationGroups:
|
|
174
|
+
fields.borrowedAmountOutsideElevationGroups,
|
|
175
|
+
fixedTermBorrowRolloverConfig:
|
|
176
|
+
types.FixedTermBorrowRolloverConfig.toEncodable(
|
|
177
|
+
fields.fixedTermBorrowRolloverConfig
|
|
178
|
+
),
|
|
179
|
+
padding2: fields.padding2,
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
toJSON(): ObligationLiquidityJSON {
|
|
184
|
+
return {
|
|
185
|
+
borrowReserve: this.borrowReserve,
|
|
186
|
+
cumulativeBorrowRateBsf: this.cumulativeBorrowRateBsf.toJSON(),
|
|
187
|
+
firstBorrowedAtTimestamp: this.firstBorrowedAtTimestamp.toString(),
|
|
188
|
+
borrowedAmountSf: this.borrowedAmountSf.toString(),
|
|
189
|
+
marketValueSf: this.marketValueSf.toString(),
|
|
190
|
+
borrowFactorAdjustedMarketValueSf:
|
|
191
|
+
this.borrowFactorAdjustedMarketValueSf.toString(),
|
|
192
|
+
borrowedAmountOutsideElevationGroups:
|
|
193
|
+
this.borrowedAmountOutsideElevationGroups.toString(),
|
|
194
|
+
fixedTermBorrowRolloverConfig:
|
|
195
|
+
this.fixedTermBorrowRolloverConfig.toJSON(),
|
|
196
|
+
padding2: this.padding2.map((item) => item.toString()),
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static fromJSON(obj: ObligationLiquidityJSON): ObligationLiquidity {
|
|
201
|
+
return new ObligationLiquidity({
|
|
202
|
+
borrowReserve: address(obj.borrowReserve),
|
|
203
|
+
cumulativeBorrowRateBsf: types.BigFractionBytes.fromJSON(
|
|
204
|
+
obj.cumulativeBorrowRateBsf
|
|
205
|
+
),
|
|
206
|
+
firstBorrowedAtTimestamp: new BN(obj.firstBorrowedAtTimestamp),
|
|
207
|
+
borrowedAmountSf: new BN(obj.borrowedAmountSf),
|
|
208
|
+
marketValueSf: new BN(obj.marketValueSf),
|
|
209
|
+
borrowFactorAdjustedMarketValueSf: new BN(
|
|
210
|
+
obj.borrowFactorAdjustedMarketValueSf
|
|
211
|
+
),
|
|
212
|
+
borrowedAmountOutsideElevationGroups: new BN(
|
|
213
|
+
obj.borrowedAmountOutsideElevationGroups
|
|
214
|
+
),
|
|
215
|
+
fixedTermBorrowRolloverConfig:
|
|
216
|
+
types.FixedTermBorrowRolloverConfig.fromJSON(
|
|
217
|
+
obj.fixedTermBorrowRolloverConfig
|
|
218
|
+
),
|
|
219
|
+
padding2: obj.padding2.map((item) => new BN(item)),
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
toEncodable() {
|
|
224
|
+
return ObligationLiquidity.toEncodable(this)
|
|
225
|
+
}
|
|
226
|
+
}
|