@kamino-finance/klend-sdk 7.4.0-beta.5 → 7.4.0-beta.7
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/klend/accounts/LendingMarket.d.ts +18 -18
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +18 -18
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +73 -1
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +127 -1
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +4 -0
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +6 -2
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.d.ts +36 -0
- package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.js +62 -0
- package/dist/@codegen/klend/instructions/rolloverFixedTermBorrow.js.map +1 -0
- package/dist/@codegen/klend/instructions/updateObligationConfig.d.ts +30 -0
- package/dist/@codegen/klend/instructions/updateObligationConfig.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/updateObligationConfig.js +70 -0
- package/dist/@codegen/klend/instructions/updateObligationConfig.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts +62 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -1
- package/dist/@codegen/klend/types/BorrowOrder.js +28 -1
- package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -1
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +5 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -1
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +8 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -1
- package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.d.ts +6 -6
- package/dist/@codegen/klend/types/FixedTermBorrowRolloverConfig.js +2 -2
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +14 -14
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +23 -23
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateObligationConfigMode.d.ts +58 -0
- package/dist/@codegen/klend/types/UpdateObligationConfigMode.d.ts.map +1 -0
- package/dist/@codegen/klend/types/UpdateObligationConfigMode.js +156 -0
- package/dist/@codegen/klend/types/UpdateObligationConfigMode.js.map +1 -0
- package/dist/@codegen/klend/types/index.d.ts +16 -2
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +3 -1
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/classes/action.d.ts +5 -2
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +99 -3
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +25 -0
- package/dist/classes/actionTypes.d.ts.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +2 -2
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/reserve.d.ts +6 -4
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +26 -5
- package/dist/classes/reserve.js.map +1 -1
- package/dist/idl/klend.json +309 -12
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +5 -1
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/klend/accounts/LendingMarket.ts +36 -36
- package/src/@codegen/klend/errors/custom.ts +147 -0
- package/src/@codegen/klend/instructions/index.ts +7 -0
- package/src/@codegen/klend/instructions/rolloverFixedTermBorrow.ts +109 -0
- package/src/@codegen/klend/instructions/updateObligationConfig.ts +84 -0
- package/src/@codegen/klend/types/BorrowOrder.ts +69 -1
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +11 -0
- package/src/@codegen/klend/types/FixedTermBorrowRolloverConfig.ts +6 -6
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +26 -26
- package/src/@codegen/klend/types/UpdateObligationConfigMode.ts +151 -0
- package/src/@codegen/klend/types/index.ts +28 -4
- package/src/classes/action.ts +192 -5
- package/src/classes/actionTypes.ts +23 -0
- package/src/classes/manager.ts +6 -4
- package/src/classes/market.ts +4 -1
- package/src/classes/reserve.ts +32 -5
- package/src/idl/klend.json +309 -12
- package/src/utils/seeds.ts +5 -1
|
@@ -153,6 +153,15 @@ export type CustomError =
|
|
|
153
153
|
| WithdrawTicketInvalid
|
|
154
154
|
| InvalidWithdrawTicketProgressCallbackConfig
|
|
155
155
|
| WithdrawTicketProgressCallbackAccountsMissing
|
|
156
|
+
| BorrowRolloverConfigurationDisabled
|
|
157
|
+
| InvalidObligationConfigUpdateSubject
|
|
158
|
+
| BorrowRolloverLiquidityMintMismatch
|
|
159
|
+
| ObligationBorrowRolloverNotApplicable
|
|
160
|
+
| ObligationBorrowOutsideRolloverWindow
|
|
161
|
+
| ObligationBorrowRolloverNotEnabledByOwner
|
|
162
|
+
| ObligationBorrowRolloverTargetReserveMismatch
|
|
163
|
+
| BorrowRolloverExecutionDisabled
|
|
164
|
+
| ObligationAccountingMismatch
|
|
156
165
|
|
|
157
166
|
export class InvalidMarketAuthority extends Error {
|
|
158
167
|
static readonly code = 6000
|
|
@@ -1971,6 +1980,126 @@ export class WithdrawTicketProgressCallbackAccountsMissing extends Error {
|
|
|
1971
1980
|
}
|
|
1972
1981
|
}
|
|
1973
1982
|
|
|
1983
|
+
export class BorrowRolloverConfigurationDisabled extends Error {
|
|
1984
|
+
static readonly code = 6154
|
|
1985
|
+
readonly code = 6154
|
|
1986
|
+
readonly name = "BorrowRolloverConfigurationDisabled"
|
|
1987
|
+
readonly msg =
|
|
1988
|
+
"Configuring auto-rollover on loans is disabled by market owner"
|
|
1989
|
+
|
|
1990
|
+
constructor(readonly logs?: string[]) {
|
|
1991
|
+
super(
|
|
1992
|
+
"6154: Configuring auto-rollover on loans is disabled by market owner"
|
|
1993
|
+
)
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
export class InvalidObligationConfigUpdateSubject extends Error {
|
|
1998
|
+
static readonly code = 6155
|
|
1999
|
+
readonly code = 6155
|
|
2000
|
+
readonly name = "InvalidObligationConfigUpdateSubject"
|
|
2001
|
+
readonly msg =
|
|
2002
|
+
"Invalid specification of the Obligation's part to be configured"
|
|
2003
|
+
|
|
2004
|
+
constructor(readonly logs?: string[]) {
|
|
2005
|
+
super(
|
|
2006
|
+
"6155: Invalid specification of the Obligation's part to be configured"
|
|
2007
|
+
)
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
export class BorrowRolloverLiquidityMintMismatch extends Error {
|
|
2012
|
+
static readonly code = 6156
|
|
2013
|
+
readonly code = 6156
|
|
2014
|
+
readonly name = "BorrowRolloverLiquidityMintMismatch"
|
|
2015
|
+
readonly msg = "Auto-rollover must use a target reserve of the same token"
|
|
2016
|
+
|
|
2017
|
+
constructor(readonly logs?: string[]) {
|
|
2018
|
+
super("6156: Auto-rollover must use a target reserve of the same token")
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
export class ObligationBorrowRolloverNotApplicable extends Error {
|
|
2023
|
+
static readonly code = 6157
|
|
2024
|
+
readonly code = 6157
|
|
2025
|
+
readonly name = "ObligationBorrowRolloverNotApplicable"
|
|
2026
|
+
readonly msg =
|
|
2027
|
+
"The given borrow is not fixed-term and does not require rolling over"
|
|
2028
|
+
|
|
2029
|
+
constructor(readonly logs?: string[]) {
|
|
2030
|
+
super(
|
|
2031
|
+
"6157: The given borrow is not fixed-term and does not require rolling over"
|
|
2032
|
+
)
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
export class ObligationBorrowOutsideRolloverWindow extends Error {
|
|
2037
|
+
static readonly code = 6158
|
|
2038
|
+
readonly code = 6158
|
|
2039
|
+
readonly name = "ObligationBorrowOutsideRolloverWindow"
|
|
2040
|
+
readonly msg =
|
|
2041
|
+
"The given borrow is outside the corresponding market-configured rollover window"
|
|
2042
|
+
|
|
2043
|
+
constructor(readonly logs?: string[]) {
|
|
2044
|
+
super(
|
|
2045
|
+
"6158: The given borrow is outside the corresponding market-configured rollover window"
|
|
2046
|
+
)
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
export class ObligationBorrowRolloverNotEnabledByOwner extends Error {
|
|
2051
|
+
static readonly code = 6159
|
|
2052
|
+
readonly code = 6159
|
|
2053
|
+
readonly name = "ObligationBorrowRolloverNotEnabledByOwner"
|
|
2054
|
+
readonly msg =
|
|
2055
|
+
"Obligation's owner did not opt-in for auto-rollover of the given borrow"
|
|
2056
|
+
|
|
2057
|
+
constructor(readonly logs?: string[]) {
|
|
2058
|
+
super(
|
|
2059
|
+
"6159: Obligation's owner did not opt-in for auto-rollover of the given borrow"
|
|
2060
|
+
)
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
export class ObligationBorrowRolloverTargetReserveMismatch extends Error {
|
|
2065
|
+
static readonly code = 6160
|
|
2066
|
+
readonly code = 6160
|
|
2067
|
+
readonly name = "ObligationBorrowRolloverTargetReserveMismatch"
|
|
2068
|
+
readonly msg =
|
|
2069
|
+
"Obligation's owner did not allow to roll over into terms offered by the given reserve"
|
|
2070
|
+
|
|
2071
|
+
constructor(readonly logs?: string[]) {
|
|
2072
|
+
super(
|
|
2073
|
+
"6160: Obligation's owner did not allow to roll over into terms offered by the given reserve"
|
|
2074
|
+
)
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
export class BorrowRolloverExecutionDisabled extends Error {
|
|
2079
|
+
static readonly code = 6161
|
|
2080
|
+
readonly code = 6161
|
|
2081
|
+
readonly name = "BorrowRolloverExecutionDisabled"
|
|
2082
|
+
readonly msg = "Executing auto-rollover is disabled by market owner"
|
|
2083
|
+
|
|
2084
|
+
constructor(readonly logs?: string[]) {
|
|
2085
|
+
super("6161: Executing auto-rollover is disabled by market owner")
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
export class ObligationAccountingMismatch extends Error {
|
|
2090
|
+
static readonly code = 6162
|
|
2091
|
+
readonly code = 6162
|
|
2092
|
+
readonly name = "ObligationAccountingMismatch"
|
|
2093
|
+
readonly msg =
|
|
2094
|
+
"Obligation internal state accounting has been unexpectedly modified"
|
|
2095
|
+
|
|
2096
|
+
constructor(readonly logs?: string[]) {
|
|
2097
|
+
super(
|
|
2098
|
+
"6162: Obligation internal state accounting has been unexpectedly modified"
|
|
2099
|
+
)
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
|
|
1974
2103
|
export function fromCode(code: number, logs?: string[]): CustomError | null {
|
|
1975
2104
|
switch (code) {
|
|
1976
2105
|
case 6000:
|
|
@@ -2281,6 +2410,24 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
|
|
|
2281
2410
|
return new InvalidWithdrawTicketProgressCallbackConfig(logs)
|
|
2282
2411
|
case 6153:
|
|
2283
2412
|
return new WithdrawTicketProgressCallbackAccountsMissing(logs)
|
|
2413
|
+
case 6154:
|
|
2414
|
+
return new BorrowRolloverConfigurationDisabled(logs)
|
|
2415
|
+
case 6155:
|
|
2416
|
+
return new InvalidObligationConfigUpdateSubject(logs)
|
|
2417
|
+
case 6156:
|
|
2418
|
+
return new BorrowRolloverLiquidityMintMismatch(logs)
|
|
2419
|
+
case 6157:
|
|
2420
|
+
return new ObligationBorrowRolloverNotApplicable(logs)
|
|
2421
|
+
case 6158:
|
|
2422
|
+
return new ObligationBorrowOutsideRolloverWindow(logs)
|
|
2423
|
+
case 6159:
|
|
2424
|
+
return new ObligationBorrowRolloverNotEnabledByOwner(logs)
|
|
2425
|
+
case 6160:
|
|
2426
|
+
return new ObligationBorrowRolloverTargetReserveMismatch(logs)
|
|
2427
|
+
case 6161:
|
|
2428
|
+
return new BorrowRolloverExecutionDisabled(logs)
|
|
2429
|
+
case 6162:
|
|
2430
|
+
return new ObligationAccountingMismatch(logs)
|
|
2284
2431
|
}
|
|
2285
2432
|
|
|
2286
2433
|
return null
|
|
@@ -195,6 +195,13 @@ export type {
|
|
|
195
195
|
SetBorrowOrderArgs,
|
|
196
196
|
SetBorrowOrderAccounts,
|
|
197
197
|
} from "./setBorrowOrder"
|
|
198
|
+
export { updateObligationConfig } from "./updateObligationConfig"
|
|
199
|
+
export type {
|
|
200
|
+
UpdateObligationConfigArgs,
|
|
201
|
+
UpdateObligationConfigAccounts,
|
|
202
|
+
} from "./updateObligationConfig"
|
|
203
|
+
export { rolloverFixedTermBorrow } from "./rolloverFixedTermBorrow"
|
|
204
|
+
export type { RolloverFixedTermBorrowAccounts } from "./rolloverFixedTermBorrow"
|
|
198
205
|
export { fillBorrowOrder } from "./fillBorrowOrder"
|
|
199
206
|
export type { FillBorrowOrderAccounts } from "./fillBorrowOrder"
|
|
200
207
|
export { enqueueToWithdraw } from "./enqueueToWithdraw"
|
|
@@ -0,0 +1,109 @@
|
|
|
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([85, 30, 155, 225, 224, 186, 141, 148])
|
|
19
|
+
|
|
20
|
+
export interface RolloverFixedTermBorrowAccounts {
|
|
21
|
+
rolloverAccounts: {
|
|
22
|
+
payer: TransactionSigner
|
|
23
|
+
/** The obligation with a fixed-term borrow. */
|
|
24
|
+
obligation: Address
|
|
25
|
+
/** The [Self::obligation]'s market, needed for validations against the market-wide 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 fixed-term reserve used by the existing [Self::obligation]'s borrow that approaches its debt term and needs to rollover from. */
|
|
30
|
+
sourceBorrowReserve: Address
|
|
31
|
+
/** The reserve to rollover the borrow into - possibly (but not necessarily) the same as [Self::source_borrow_reserve]'s (but definitely of the same liquidity mint). */
|
|
32
|
+
targetBorrowReserve: Address
|
|
33
|
+
/** The mint of [Self::source_borrow_reserve] and [Self::target_borrow_reserve], needed to transfer funds between them. */
|
|
34
|
+
liquidityMint: Address
|
|
35
|
+
/** The vault of [Self::source_borrow_reserve], from which the funds are transferred. */
|
|
36
|
+
sourceBorrowReserveLiquidity: Address
|
|
37
|
+
/** The vault of [Self::target_borrow_reserve], from which the funds are transferred. */
|
|
38
|
+
targetBorrowReserveLiquidity: Address
|
|
39
|
+
/** The token program of [Self::liquidity_mint] - needed to execute the transfer. */
|
|
40
|
+
tokenProgram: Address
|
|
41
|
+
}
|
|
42
|
+
sourceFarmsAccounts: {
|
|
43
|
+
obligationFarmUserState: Option<Address>
|
|
44
|
+
reserveFarmState: Option<Address>
|
|
45
|
+
}
|
|
46
|
+
targetFarmsAccounts: {
|
|
47
|
+
obligationFarmUserState: Option<Address>
|
|
48
|
+
reserveFarmState: Option<Address>
|
|
49
|
+
}
|
|
50
|
+
farmsProgram: Address
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function rolloverFixedTermBorrow(
|
|
54
|
+
accounts: RolloverFixedTermBorrowAccounts,
|
|
55
|
+
remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
|
|
56
|
+
programAddress: Address = PROGRAM_ID
|
|
57
|
+
) {
|
|
58
|
+
const keys: Array<AccountMeta | AccountSignerMeta> = [
|
|
59
|
+
{
|
|
60
|
+
address: accounts.rolloverAccounts.payer.address,
|
|
61
|
+
role: 2,
|
|
62
|
+
signer: accounts.rolloverAccounts.payer,
|
|
63
|
+
},
|
|
64
|
+
{ address: accounts.rolloverAccounts.obligation, role: 1 },
|
|
65
|
+
{ address: accounts.rolloverAccounts.lendingMarket, role: 0 },
|
|
66
|
+
{ address: accounts.rolloverAccounts.lendingMarketAuthority, role: 0 },
|
|
67
|
+
{ address: accounts.rolloverAccounts.sourceBorrowReserve, role: 1 },
|
|
68
|
+
{ address: accounts.rolloverAccounts.targetBorrowReserve, role: 1 },
|
|
69
|
+
{ address: accounts.rolloverAccounts.liquidityMint, role: 0 },
|
|
70
|
+
{
|
|
71
|
+
address: accounts.rolloverAccounts.sourceBorrowReserveLiquidity,
|
|
72
|
+
role: 1,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
address: accounts.rolloverAccounts.targetBorrowReserveLiquidity,
|
|
76
|
+
role: 1,
|
|
77
|
+
},
|
|
78
|
+
{ address: accounts.rolloverAccounts.tokenProgram, role: 0 },
|
|
79
|
+
isSome(accounts.sourceFarmsAccounts.obligationFarmUserState)
|
|
80
|
+
? {
|
|
81
|
+
address: accounts.sourceFarmsAccounts.obligationFarmUserState.value,
|
|
82
|
+
role: 1,
|
|
83
|
+
}
|
|
84
|
+
: { address: programAddress, role: 0 },
|
|
85
|
+
isSome(accounts.sourceFarmsAccounts.reserveFarmState)
|
|
86
|
+
? {
|
|
87
|
+
address: accounts.sourceFarmsAccounts.reserveFarmState.value,
|
|
88
|
+
role: 1,
|
|
89
|
+
}
|
|
90
|
+
: { address: programAddress, role: 0 },
|
|
91
|
+
isSome(accounts.targetFarmsAccounts.obligationFarmUserState)
|
|
92
|
+
? {
|
|
93
|
+
address: accounts.targetFarmsAccounts.obligationFarmUserState.value,
|
|
94
|
+
role: 1,
|
|
95
|
+
}
|
|
96
|
+
: { address: programAddress, role: 0 },
|
|
97
|
+
isSome(accounts.targetFarmsAccounts.reserveFarmState)
|
|
98
|
+
? {
|
|
99
|
+
address: accounts.targetFarmsAccounts.reserveFarmState.value,
|
|
100
|
+
role: 1,
|
|
101
|
+
}
|
|
102
|
+
: { address: programAddress, role: 0 },
|
|
103
|
+
{ address: accounts.farmsProgram, role: 0 },
|
|
104
|
+
...remainingAccounts,
|
|
105
|
+
]
|
|
106
|
+
const data = DISCRIMINATOR
|
|
107
|
+
const ix: Instruction = { accounts: keys, programAddress, data }
|
|
108
|
+
return ix
|
|
109
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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([82, 152, 213, 69, 250, 0, 157, 188])
|
|
19
|
+
|
|
20
|
+
export interface UpdateObligationConfigArgs {
|
|
21
|
+
mode: types.UpdateObligationConfigModeKind
|
|
22
|
+
value: Uint8Array
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface UpdateObligationConfigAccounts {
|
|
26
|
+
/** Obligation's owner (signer - only the owner can modify the obligation's configuration). */
|
|
27
|
+
owner: TransactionSigner
|
|
28
|
+
/** The obligation to update. */
|
|
29
|
+
obligation: Address
|
|
30
|
+
/**
|
|
31
|
+
* The reserve of a selected one among the [Obligation::borrows].
|
|
32
|
+
*
|
|
33
|
+
* Required only if the config update affects a single borrow (for validating its new config).
|
|
34
|
+
*/
|
|
35
|
+
borrowReserve: Option<Address>
|
|
36
|
+
/**
|
|
37
|
+
* The reserve of a selected one among the [Obligation::deposits].
|
|
38
|
+
*
|
|
39
|
+
* Required only if the config update affects a single deposit (for validating its new config).
|
|
40
|
+
*/
|
|
41
|
+
depositReserve: Option<Address>
|
|
42
|
+
/** The lending market (for validating the obligation's new config). */
|
|
43
|
+
lendingMarket: Address
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const layout = borsh.struct([
|
|
47
|
+
types.UpdateObligationConfigMode.layout("mode"),
|
|
48
|
+
borsh.vecU8("value"),
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
export function updateObligationConfig(
|
|
52
|
+
args: UpdateObligationConfigArgs,
|
|
53
|
+
accounts: UpdateObligationConfigAccounts,
|
|
54
|
+
remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
|
|
55
|
+
programAddress: Address = PROGRAM_ID
|
|
56
|
+
) {
|
|
57
|
+
const keys: Array<AccountMeta | AccountSignerMeta> = [
|
|
58
|
+
{ address: accounts.owner.address, role: 2, signer: accounts.owner },
|
|
59
|
+
{ address: accounts.obligation, role: 1 },
|
|
60
|
+
isSome(accounts.borrowReserve)
|
|
61
|
+
? { address: accounts.borrowReserve.value, role: 0 }
|
|
62
|
+
: { address: programAddress, role: 0 },
|
|
63
|
+
isSome(accounts.depositReserve)
|
|
64
|
+
? { address: accounts.depositReserve.value, role: 0 }
|
|
65
|
+
: { address: programAddress, role: 0 },
|
|
66
|
+
{ address: accounts.lendingMarket, role: 0 },
|
|
67
|
+
...remainingAccounts,
|
|
68
|
+
]
|
|
69
|
+
const buffer = Buffer.alloc(1000)
|
|
70
|
+
const len = layout.encode(
|
|
71
|
+
{
|
|
72
|
+
mode: args.mode.toEncodable(),
|
|
73
|
+
value: Buffer.from(
|
|
74
|
+
args.value.buffer,
|
|
75
|
+
args.value.byteOffset,
|
|
76
|
+
args.value.length
|
|
77
|
+
),
|
|
78
|
+
},
|
|
79
|
+
buffer
|
|
80
|
+
)
|
|
81
|
+
const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len)
|
|
82
|
+
const ix: Instruction = { accounts: keys, programAddress, data }
|
|
83
|
+
return ix
|
|
84
|
+
}
|
|
@@ -49,6 +49,26 @@ export interface BorrowOrderFields {
|
|
|
49
49
|
* *higher* than this.
|
|
50
50
|
*/
|
|
51
51
|
maxBorrowRateBps: number
|
|
52
|
+
/**
|
|
53
|
+
* When `1`, all [Obligation::borrows] that get filled by this order will have their
|
|
54
|
+
* [FixedTermBorrowRolloverConfig::auto_rollover_enabled] flag set.
|
|
55
|
+
*
|
|
56
|
+
* Additionally, their rollover customizations:
|
|
57
|
+
* - will exactly match this order's constraints regarding [Self::min_debt_term_seconds] and
|
|
58
|
+
* [Self::max_borrow_rate_bps];
|
|
59
|
+
* - will use the [FixedTermBorrowRolloverConfig::open_term_allowed] fallback.
|
|
60
|
+
*
|
|
61
|
+
* See [BorrowOrder::get_rollover_config_for_filled_borrow()].
|
|
62
|
+
*
|
|
63
|
+
* Clarification note: when `0`, this setting has no effect on any borrow (i.e. if an existing
|
|
64
|
+
* borrow was independently marked for auto-rollover, it will *not* be unmarked when filled by
|
|
65
|
+
* this order).
|
|
66
|
+
*
|
|
67
|
+
* Feature flag note: when [LendingMarket::obligation_borrow_rollover_configuration_enabled] is
|
|
68
|
+
* disabled, this setting has no effect on any borrow (i.e. the fill will be successful, but
|
|
69
|
+
* the borrow will not be marked for auto-rollover.
|
|
70
|
+
*/
|
|
71
|
+
enableAutoRolloverOnFilledBorrows: number
|
|
52
72
|
/** Alignment padding. */
|
|
53
73
|
padding1: Array<number>
|
|
54
74
|
/** End padding. */
|
|
@@ -100,6 +120,26 @@ export interface BorrowOrderJSON {
|
|
|
100
120
|
* *higher* than this.
|
|
101
121
|
*/
|
|
102
122
|
maxBorrowRateBps: number
|
|
123
|
+
/**
|
|
124
|
+
* When `1`, all [Obligation::borrows] that get filled by this order will have their
|
|
125
|
+
* [FixedTermBorrowRolloverConfig::auto_rollover_enabled] flag set.
|
|
126
|
+
*
|
|
127
|
+
* Additionally, their rollover customizations:
|
|
128
|
+
* - will exactly match this order's constraints regarding [Self::min_debt_term_seconds] and
|
|
129
|
+
* [Self::max_borrow_rate_bps];
|
|
130
|
+
* - will use the [FixedTermBorrowRolloverConfig::open_term_allowed] fallback.
|
|
131
|
+
*
|
|
132
|
+
* See [BorrowOrder::get_rollover_config_for_filled_borrow()].
|
|
133
|
+
*
|
|
134
|
+
* Clarification note: when `0`, this setting has no effect on any borrow (i.e. if an existing
|
|
135
|
+
* borrow was independently marked for auto-rollover, it will *not* be unmarked when filled by
|
|
136
|
+
* this order).
|
|
137
|
+
*
|
|
138
|
+
* Feature flag note: when [LendingMarket::obligation_borrow_rollover_configuration_enabled] is
|
|
139
|
+
* disabled, this setting has no effect on any borrow (i.e. the fill will be successful, but
|
|
140
|
+
* the borrow will not be marked for auto-rollover.
|
|
141
|
+
*/
|
|
142
|
+
enableAutoRolloverOnFilledBorrows: number
|
|
103
143
|
/** Alignment padding. */
|
|
104
144
|
padding1: Array<number>
|
|
105
145
|
/** End padding. */
|
|
@@ -158,6 +198,26 @@ export class BorrowOrder {
|
|
|
158
198
|
* *higher* than this.
|
|
159
199
|
*/
|
|
160
200
|
readonly maxBorrowRateBps: number
|
|
201
|
+
/**
|
|
202
|
+
* When `1`, all [Obligation::borrows] that get filled by this order will have their
|
|
203
|
+
* [FixedTermBorrowRolloverConfig::auto_rollover_enabled] flag set.
|
|
204
|
+
*
|
|
205
|
+
* Additionally, their rollover customizations:
|
|
206
|
+
* - will exactly match this order's constraints regarding [Self::min_debt_term_seconds] and
|
|
207
|
+
* [Self::max_borrow_rate_bps];
|
|
208
|
+
* - will use the [FixedTermBorrowRolloverConfig::open_term_allowed] fallback.
|
|
209
|
+
*
|
|
210
|
+
* See [BorrowOrder::get_rollover_config_for_filled_borrow()].
|
|
211
|
+
*
|
|
212
|
+
* Clarification note: when `0`, this setting has no effect on any borrow (i.e. if an existing
|
|
213
|
+
* borrow was independently marked for auto-rollover, it will *not* be unmarked when filled by
|
|
214
|
+
* this order).
|
|
215
|
+
*
|
|
216
|
+
* Feature flag note: when [LendingMarket::obligation_borrow_rollover_configuration_enabled] is
|
|
217
|
+
* disabled, this setting has no effect on any borrow (i.e. the fill will be successful, but
|
|
218
|
+
* the borrow will not be marked for auto-rollover.
|
|
219
|
+
*/
|
|
220
|
+
readonly enableAutoRolloverOnFilledBorrows: number
|
|
161
221
|
/** Alignment padding. */
|
|
162
222
|
readonly padding1: Array<number>
|
|
163
223
|
/** End padding. */
|
|
@@ -173,6 +233,8 @@ export class BorrowOrder {
|
|
|
173
233
|
this.lastUpdatedAtTimestamp = fields.lastUpdatedAtTimestamp
|
|
174
234
|
this.requestedDebtAmount = fields.requestedDebtAmount
|
|
175
235
|
this.maxBorrowRateBps = fields.maxBorrowRateBps
|
|
236
|
+
this.enableAutoRolloverOnFilledBorrows =
|
|
237
|
+
fields.enableAutoRolloverOnFilledBorrows
|
|
176
238
|
this.padding1 = fields.padding1
|
|
177
239
|
this.endPadding = fields.endPadding
|
|
178
240
|
}
|
|
@@ -189,7 +251,8 @@ export class BorrowOrder {
|
|
|
189
251
|
borsh.u64("lastUpdatedAtTimestamp"),
|
|
190
252
|
borsh.u64("requestedDebtAmount"),
|
|
191
253
|
borsh.u32("maxBorrowRateBps"),
|
|
192
|
-
borsh.
|
|
254
|
+
borsh.u8("enableAutoRolloverOnFilledBorrows"),
|
|
255
|
+
borsh.array(borsh.u8(), 3, "padding1"),
|
|
193
256
|
borsh.array(borsh.u64(), 5, "endPadding"),
|
|
194
257
|
],
|
|
195
258
|
property
|
|
@@ -208,6 +271,7 @@ export class BorrowOrder {
|
|
|
208
271
|
lastUpdatedAtTimestamp: obj.lastUpdatedAtTimestamp,
|
|
209
272
|
requestedDebtAmount: obj.requestedDebtAmount,
|
|
210
273
|
maxBorrowRateBps: obj.maxBorrowRateBps,
|
|
274
|
+
enableAutoRolloverOnFilledBorrows: obj.enableAutoRolloverOnFilledBorrows,
|
|
211
275
|
padding1: obj.padding1,
|
|
212
276
|
endPadding: obj.endPadding,
|
|
213
277
|
})
|
|
@@ -224,6 +288,8 @@ export class BorrowOrder {
|
|
|
224
288
|
lastUpdatedAtTimestamp: fields.lastUpdatedAtTimestamp,
|
|
225
289
|
requestedDebtAmount: fields.requestedDebtAmount,
|
|
226
290
|
maxBorrowRateBps: fields.maxBorrowRateBps,
|
|
291
|
+
enableAutoRolloverOnFilledBorrows:
|
|
292
|
+
fields.enableAutoRolloverOnFilledBorrows,
|
|
227
293
|
padding1: fields.padding1,
|
|
228
294
|
endPadding: fields.endPadding,
|
|
229
295
|
}
|
|
@@ -240,6 +306,7 @@ export class BorrowOrder {
|
|
|
240
306
|
lastUpdatedAtTimestamp: this.lastUpdatedAtTimestamp.toString(),
|
|
241
307
|
requestedDebtAmount: this.requestedDebtAmount.toString(),
|
|
242
308
|
maxBorrowRateBps: this.maxBorrowRateBps,
|
|
309
|
+
enableAutoRolloverOnFilledBorrows: this.enableAutoRolloverOnFilledBorrows,
|
|
243
310
|
padding1: this.padding1,
|
|
244
311
|
endPadding: this.endPadding.map((item) => item.toString()),
|
|
245
312
|
}
|
|
@@ -256,6 +323,7 @@ export class BorrowOrder {
|
|
|
256
323
|
lastUpdatedAtTimestamp: new BN(obj.lastUpdatedAtTimestamp),
|
|
257
324
|
requestedDebtAmount: new BN(obj.requestedDebtAmount),
|
|
258
325
|
maxBorrowRateBps: obj.maxBorrowRateBps,
|
|
326
|
+
enableAutoRolloverOnFilledBorrows: obj.enableAutoRolloverOnFilledBorrows,
|
|
259
327
|
padding1: obj.padding1,
|
|
260
328
|
endPadding: obj.endPadding.map((item) => new BN(item)),
|
|
261
329
|
})
|
|
@@ -9,6 +9,7 @@ export interface BorrowOrderConfigArgsFields {
|
|
|
9
9
|
maxBorrowRateBps: number
|
|
10
10
|
minDebtTermSeconds: BN
|
|
11
11
|
fillableUntilTimestamp: BN
|
|
12
|
+
enableAutoRolloverOnFilledBorrows: boolean
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export interface BorrowOrderConfigArgsJSON {
|
|
@@ -16,6 +17,7 @@ export interface BorrowOrderConfigArgsJSON {
|
|
|
16
17
|
maxBorrowRateBps: number
|
|
17
18
|
minDebtTermSeconds: string
|
|
18
19
|
fillableUntilTimestamp: string
|
|
20
|
+
enableAutoRolloverOnFilledBorrows: boolean
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/** A subset of [BorrowOrderConfig] excluding the accounts passed via [SetBorrowOrder]. */
|
|
@@ -24,12 +26,15 @@ export class BorrowOrderConfigArgs {
|
|
|
24
26
|
readonly maxBorrowRateBps: number
|
|
25
27
|
readonly minDebtTermSeconds: BN
|
|
26
28
|
readonly fillableUntilTimestamp: BN
|
|
29
|
+
readonly enableAutoRolloverOnFilledBorrows: boolean
|
|
27
30
|
|
|
28
31
|
constructor(fields: BorrowOrderConfigArgsFields) {
|
|
29
32
|
this.remainingDebtAmount = fields.remainingDebtAmount
|
|
30
33
|
this.maxBorrowRateBps = fields.maxBorrowRateBps
|
|
31
34
|
this.minDebtTermSeconds = fields.minDebtTermSeconds
|
|
32
35
|
this.fillableUntilTimestamp = fields.fillableUntilTimestamp
|
|
36
|
+
this.enableAutoRolloverOnFilledBorrows =
|
|
37
|
+
fields.enableAutoRolloverOnFilledBorrows
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
static layout(property?: string) {
|
|
@@ -39,6 +44,7 @@ export class BorrowOrderConfigArgs {
|
|
|
39
44
|
borsh.u32("maxBorrowRateBps"),
|
|
40
45
|
borsh.u64("minDebtTermSeconds"),
|
|
41
46
|
borsh.u64("fillableUntilTimestamp"),
|
|
47
|
+
borsh.bool("enableAutoRolloverOnFilledBorrows"),
|
|
42
48
|
],
|
|
43
49
|
property
|
|
44
50
|
)
|
|
@@ -51,6 +57,7 @@ export class BorrowOrderConfigArgs {
|
|
|
51
57
|
maxBorrowRateBps: obj.maxBorrowRateBps,
|
|
52
58
|
minDebtTermSeconds: obj.minDebtTermSeconds,
|
|
53
59
|
fillableUntilTimestamp: obj.fillableUntilTimestamp,
|
|
60
|
+
enableAutoRolloverOnFilledBorrows: obj.enableAutoRolloverOnFilledBorrows,
|
|
54
61
|
})
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -60,6 +67,8 @@ export class BorrowOrderConfigArgs {
|
|
|
60
67
|
maxBorrowRateBps: fields.maxBorrowRateBps,
|
|
61
68
|
minDebtTermSeconds: fields.minDebtTermSeconds,
|
|
62
69
|
fillableUntilTimestamp: fields.fillableUntilTimestamp,
|
|
70
|
+
enableAutoRolloverOnFilledBorrows:
|
|
71
|
+
fields.enableAutoRolloverOnFilledBorrows,
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
|
|
@@ -69,6 +78,7 @@ export class BorrowOrderConfigArgs {
|
|
|
69
78
|
maxBorrowRateBps: this.maxBorrowRateBps,
|
|
70
79
|
minDebtTermSeconds: this.minDebtTermSeconds.toString(),
|
|
71
80
|
fillableUntilTimestamp: this.fillableUntilTimestamp.toString(),
|
|
81
|
+
enableAutoRolloverOnFilledBorrows: this.enableAutoRolloverOnFilledBorrows,
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
|
|
@@ -78,6 +88,7 @@ export class BorrowOrderConfigArgs {
|
|
|
78
88
|
maxBorrowRateBps: obj.maxBorrowRateBps,
|
|
79
89
|
minDebtTermSeconds: new BN(obj.minDebtTermSeconds),
|
|
80
90
|
fillableUntilTimestamp: new BN(obj.fillableUntilTimestamp),
|
|
91
|
+
enableAutoRolloverOnFilledBorrows: obj.enableAutoRolloverOnFilledBorrows,
|
|
81
92
|
})
|
|
82
93
|
}
|
|
83
94
|
|
|
@@ -14,7 +14,7 @@ export interface FixedTermBorrowRolloverConfigFields {
|
|
|
14
14
|
* C) sufficient available liquidity (including no withdraw tickets waiting in its queue).
|
|
15
15
|
*
|
|
16
16
|
* The time left until the current debt term expires must be:
|
|
17
|
-
* D) less than [LendingMarket::
|
|
17
|
+
* D) less than [LendingMarket::fixed_term_rollover_window_duration_seconds].
|
|
18
18
|
*
|
|
19
19
|
* Note: the other settings are only effective when this one is `1`.
|
|
20
20
|
*/
|
|
@@ -22,7 +22,7 @@ export interface FixedTermBorrowRolloverConfigFields {
|
|
|
22
22
|
/**
|
|
23
23
|
* When `1`, partially lifts the condition *B* from [Self::auto_rollover_enabled]: additionally
|
|
24
24
|
* allows to use a variable (indefinite) debt term if less than
|
|
25
|
-
* [LendingMarket::
|
|
25
|
+
* [LendingMarket::open_term_rollover_window_duration_seconds] is left until expiration.
|
|
26
26
|
*
|
|
27
27
|
* Note: typically this flag should be used together with [Self::max_borrow_rate_bps] set to
|
|
28
28
|
* `u32::MAX` (to denote a variable-rate reserve).
|
|
@@ -54,7 +54,7 @@ export interface FixedTermBorrowRolloverConfigJSON {
|
|
|
54
54
|
* C) sufficient available liquidity (including no withdraw tickets waiting in its queue).
|
|
55
55
|
*
|
|
56
56
|
* The time left until the current debt term expires must be:
|
|
57
|
-
* D) less than [LendingMarket::
|
|
57
|
+
* D) less than [LendingMarket::fixed_term_rollover_window_duration_seconds].
|
|
58
58
|
*
|
|
59
59
|
* Note: the other settings are only effective when this one is `1`.
|
|
60
60
|
*/
|
|
@@ -62,7 +62,7 @@ export interface FixedTermBorrowRolloverConfigJSON {
|
|
|
62
62
|
/**
|
|
63
63
|
* When `1`, partially lifts the condition *B* from [Self::auto_rollover_enabled]: additionally
|
|
64
64
|
* allows to use a variable (indefinite) debt term if less than
|
|
65
|
-
* [LendingMarket::
|
|
65
|
+
* [LendingMarket::open_term_rollover_window_duration_seconds] is left until expiration.
|
|
66
66
|
*
|
|
67
67
|
* Note: typically this flag should be used together with [Self::max_borrow_rate_bps] set to
|
|
68
68
|
* `u32::MAX` (to denote a variable-rate reserve).
|
|
@@ -100,7 +100,7 @@ export class FixedTermBorrowRolloverConfig {
|
|
|
100
100
|
* C) sufficient available liquidity (including no withdraw tickets waiting in its queue).
|
|
101
101
|
*
|
|
102
102
|
* The time left until the current debt term expires must be:
|
|
103
|
-
* D) less than [LendingMarket::
|
|
103
|
+
* D) less than [LendingMarket::fixed_term_rollover_window_duration_seconds].
|
|
104
104
|
*
|
|
105
105
|
* Note: the other settings are only effective when this one is `1`.
|
|
106
106
|
*/
|
|
@@ -108,7 +108,7 @@ export class FixedTermBorrowRolloverConfig {
|
|
|
108
108
|
/**
|
|
109
109
|
* When `1`, partially lifts the condition *B* from [Self::auto_rollover_enabled]: additionally
|
|
110
110
|
* allows to use a variable (indefinite) debt term if less than
|
|
111
|
-
* [LendingMarket::
|
|
111
|
+
* [LendingMarket::open_term_rollover_window_duration_seconds] is left until expiration.
|
|
112
112
|
*
|
|
113
113
|
* Note: typically this flag should be used together with [Self::max_borrow_rate_bps] set to
|
|
114
114
|
* `u32::MAX` (to denote a variable-rate reserve).
|