@exponent-labs/kamino-reserve-deserializer 0.1.3 → 0.1.6
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/build/index.d.ts +6 -3
- package/build/index.js +13 -9
- package/build/index.js.map +1 -1
- package/build/types/Obligation.d.ts +2 -0
- package/package.json +1 -1
- package/src/index.ts +13 -7
- package/src/types/Obligation.ts +400 -0
- package/src/types/ObligationCollateral.ts +126 -0
- package/src/types/ObligationLiquidity.ts +143 -0
- package/src/types/ObligationOrder.ts +347 -0
package/build/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import {
|
|
3
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
4
|
import BN from "bn.js";
|
|
5
|
+
import Decimal from "decimal.js";
|
|
5
6
|
import { LastUpdate, LastUpdateFields, LastUpdateJSON } from "./types";
|
|
6
|
-
import {
|
|
7
|
+
import { Obligation } from "./types/Obligation";
|
|
7
8
|
import { ReserveCollateral, ReserveCollateralFields, ReserveCollateralJSON } from "./types/ReserveCollateral";
|
|
8
9
|
import { ReserveConfig, ReserveConfigFields, ReserveConfigJSON } from "./types/ReserveConfig";
|
|
9
|
-
import
|
|
10
|
+
import { ReserveLiquidity, ReserveLiquidityFields, ReserveLiquidityJSON } from "./types/ReserveLiquidity";
|
|
11
|
+
export { Obligation };
|
|
12
|
+
export declare const PROGRAM_ID: PublicKey;
|
|
10
13
|
export interface ReserveFields {
|
|
11
14
|
/** Version of the reserve */
|
|
12
15
|
version: BN;
|
package/build/index.js
CHANGED
|
@@ -26,17 +26,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Reserve = void 0;
|
|
29
|
+
exports.Reserve = exports.PROGRAM_ID = exports.Obligation = void 0;
|
|
30
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
31
|
+
const borsh = __importStar(require("@coral-xyz/borsh"));
|
|
30
32
|
const web3_js_1 = require("@solana/web3.js");
|
|
31
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
32
|
-
const
|
|
33
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
34
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
35
|
+
const fraction_1 = require("./fraction");
|
|
36
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
33
37
|
const types_1 = require("./types");
|
|
34
|
-
const
|
|
38
|
+
const Obligation_1 = require("./types/Obligation");
|
|
39
|
+
Object.defineProperty(exports, "Obligation", { enumerable: true, get: function () { return Obligation_1.Obligation; } });
|
|
35
40
|
const ReserveCollateral_1 = require("./types/ReserveCollateral");
|
|
36
41
|
const ReserveConfig_1 = require("./types/ReserveConfig");
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const PROGRAM_ID = new web3_js_1.PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD");
|
|
42
|
+
const ReserveLiquidity_1 = require("./types/ReserveLiquidity");
|
|
43
|
+
exports.PROGRAM_ID = new web3_js_1.PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD");
|
|
40
44
|
class Reserve {
|
|
41
45
|
/** Version of the reserve */
|
|
42
46
|
version;
|
|
@@ -95,7 +99,7 @@ class Reserve {
|
|
|
95
99
|
this.borrowedAmountsAgainstThisReserveInElevationGroups = fields.borrowedAmountsAgainstThisReserveInElevationGroups;
|
|
96
100
|
this.padding = fields.padding;
|
|
97
101
|
}
|
|
98
|
-
static async fetch(c, address, programId = PROGRAM_ID) {
|
|
102
|
+
static async fetch(c, address, programId = exports.PROGRAM_ID) {
|
|
99
103
|
const info = await c.getAccountInfo(address);
|
|
100
104
|
if (info === null) {
|
|
101
105
|
return null;
|
|
@@ -105,7 +109,7 @@ class Reserve {
|
|
|
105
109
|
}
|
|
106
110
|
return this.decode(info.data);
|
|
107
111
|
}
|
|
108
|
-
static async fetchMultiple(c, addresses, programId = PROGRAM_ID) {
|
|
112
|
+
static async fetchMultiple(c, addresses, programId = exports.PROGRAM_ID) {
|
|
109
113
|
const infos = await c.getMultipleAccountsInfo(addresses);
|
|
110
114
|
return infos.map((info) => {
|
|
111
115
|
if (info === null) {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAuD;AACvD,kDAAsB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAwD;AACxD,wDAAyC;AACzC,6CAAuD;AACvD,kDAAsB;AACtB,4DAAgC;AAEhC,yCAAqC;AACrC,wDAAwD;AACxD,mCAAsE;AACtE,mDAA+C;AAKtC,2FALA,uBAAU,OAKA;AAJnB,iEAA6G;AAC7G,yDAA6F;AAC7F,+DAAyG;AAI5F,QAAA,UAAU,GAAG,IAAI,mBAAS,CAAC,6CAA6C,CAAC,CAAA;AAwDtF,MAAa,OAAO;IAClB,6BAA6B;IACpB,OAAO,CAAI;IACpB,8CAA8C;IACrC,UAAU,CAAY;IAC/B,6BAA6B;IACpB,aAAa,CAAW;IACxB,cAAc,CAAW;IACzB,QAAQ,CAAW;IAC5B,wBAAwB;IACf,SAAS,CAAkB;IAC3B,uBAAuB,CAAW;IAC3C,yBAAyB;IAChB,UAAU,CAAmB;IAC7B,wBAAwB,CAAW;IAC5C,mCAAmC;IAC1B,MAAM,CAAe;IACrB,aAAa,CAAW;IACxB,mCAAmC,CAAI;IAChD;;;OAGG;IACM,kDAAkD,CAAW;IAC7D,OAAO,CAAW;IAE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AS,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,SAAS,EAAE,CAAA;IAClE,CAAC;IAED,0BAA0B;QACxB,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC,SAAS,EAAE,CAAA;IAC3E,CAAC;IAED,0BAA0B;QACxB,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC,SAAS,EAAE,CAAA;IAC3E,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC,SAAS,EAAE,CAAA;IACvE,CAAC;;AAzMH,0BA0MC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import * as borsh from "@coral-xyz/borsh"
|
|
3
|
+
import { Connection, PublicKey } from "@solana/web3.js"
|
|
4
|
+
import BN from "bn.js"
|
|
5
|
+
import Decimal from "decimal.js"
|
|
6
|
+
|
|
7
|
+
import { Fraction } from "./fraction"
|
|
8
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4
9
|
import { LastUpdate, LastUpdateFields, LastUpdateJSON } from "./types"
|
|
5
|
-
import {
|
|
10
|
+
import { Obligation } from "./types/Obligation"
|
|
6
11
|
import { ReserveCollateral, ReserveCollateralFields, ReserveCollateralJSON } from "./types/ReserveCollateral"
|
|
7
12
|
import { ReserveConfig, ReserveConfigFields, ReserveConfigJSON } from "./types/ReserveConfig"
|
|
8
|
-
import
|
|
9
|
-
|
|
13
|
+
import { ReserveLiquidity, ReserveLiquidityFields, ReserveLiquidityJSON } from "./types/ReserveLiquidity"
|
|
14
|
+
|
|
15
|
+
export { Obligation }
|
|
10
16
|
|
|
11
|
-
const PROGRAM_ID = new PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD")
|
|
17
|
+
export const PROGRAM_ID = new PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD")
|
|
12
18
|
|
|
13
19
|
export interface ReserveFields {
|
|
14
20
|
/** Version of the reserve */
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { PublicKey, Connection } from "@solana/web3.js"
|
|
2
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
3
|
+
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4
|
+
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
import { PROGRAM_ID } from "../index"
|
|
6
|
+
import { ObligationOrder, ObligationOrderFields, ObligationOrderJSON } from "./ObligationOrder"
|
|
7
|
+
import { ObligationCollateral, ObligationCollateralFields, ObligationCollateralJSON } from "./ObligationCollateral"
|
|
8
|
+
import { ObligationLiquidity, ObligationLiquidityFields, ObligationLiquidityJSON } from "./ObligationLiquidity"
|
|
9
|
+
|
|
10
|
+
export interface ObligationFields {
|
|
11
|
+
/** Version of the struct */
|
|
12
|
+
tag: BN
|
|
13
|
+
/** Last update to collateral, liquidity, or their market values */
|
|
14
|
+
lastUpdate: types.LastUpdateFields
|
|
15
|
+
/** Lending market address */
|
|
16
|
+
lendingMarket: PublicKey
|
|
17
|
+
/** Owner authority which can borrow liquidity */
|
|
18
|
+
owner: PublicKey
|
|
19
|
+
/** Deposited collateral for the obligation, unique by deposit reserve address */
|
|
20
|
+
deposits: Array<ObligationCollateralFields>
|
|
21
|
+
/** Worst LTV for the collaterals backing the loan, represented as a percentage */
|
|
22
|
+
lowestReserveDepositLiquidationLtv: BN
|
|
23
|
+
/** Market value of deposits (scaled fraction) */
|
|
24
|
+
depositedValueSf: BN
|
|
25
|
+
/** Borrowed liquidity for the obligation, unique by borrow reserve address */
|
|
26
|
+
borrows: Array<ObligationLiquidityFields>
|
|
27
|
+
/** Risk adjusted market value of borrows/debt (sum of price * borrowed_amount * borrow_factor) (scaled fraction) */
|
|
28
|
+
borrowFactorAdjustedDebtValueSf: BN
|
|
29
|
+
/** Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) */
|
|
30
|
+
borrowedAssetsMarketValueSf: BN
|
|
31
|
+
/** The maximum borrow value at the weighted average loan to value ratio (scaled fraction) */
|
|
32
|
+
allowedBorrowValueSf: BN
|
|
33
|
+
/** The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) */
|
|
34
|
+
unhealthyBorrowValueSf: BN
|
|
35
|
+
/** The asset tier of the deposits */
|
|
36
|
+
depositsAssetTiers: Array<number>
|
|
37
|
+
/** The asset tier of the borrows */
|
|
38
|
+
borrowsAssetTiers: Array<number>
|
|
39
|
+
/** The elevation group id the obligation opted into. */
|
|
40
|
+
elevationGroup: number
|
|
41
|
+
/** The number of obsolete reserves the obligation has a deposit in */
|
|
42
|
+
numOfObsoleteDepositReserves: number
|
|
43
|
+
/** Marked = 1 if borrows array is not empty, 0 = borrows empty */
|
|
44
|
+
hasDebt: number
|
|
45
|
+
/** Wallet address of the referrer */
|
|
46
|
+
referrer: PublicKey
|
|
47
|
+
/** Marked = 1 if borrowing disabled, 0 = borrowing enabled */
|
|
48
|
+
borrowingDisabled: number
|
|
49
|
+
/**
|
|
50
|
+
* A target LTV set by the risk council when marking this obligation for deleveraging.
|
|
51
|
+
* Only effective when `deleveraging_margin_call_started_slot != 0`.
|
|
52
|
+
*/
|
|
53
|
+
autodeleverageTargetLtvPct: number
|
|
54
|
+
/** The lowest max LTV found amongst the collateral deposits */
|
|
55
|
+
lowestReserveDepositMaxLtvPct: number
|
|
56
|
+
/** The number of obsolete reserves the obligation has a borrow in */
|
|
57
|
+
numOfObsoleteBorrowReserves: number
|
|
58
|
+
reserved: Array<number>
|
|
59
|
+
highestBorrowFactorPct: BN
|
|
60
|
+
/**
|
|
61
|
+
* A timestamp at which the risk council most-recently marked this obligation for deleveraging.
|
|
62
|
+
* Zero if not currently subject to deleveraging.
|
|
63
|
+
*/
|
|
64
|
+
autodeleverageMarginCallStartedTimestamp: BN
|
|
65
|
+
/**
|
|
66
|
+
* Owner-defined, liquidator-executed orders applicable to this obligation.
|
|
67
|
+
* Typical use-cases would be a stop-loss and a take-profit (possibly co-existing).
|
|
68
|
+
*/
|
|
69
|
+
orders: Array<ObligationOrderFields>
|
|
70
|
+
padding3: Array<BN>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ObligationJSON {
|
|
74
|
+
/** Version of the struct */
|
|
75
|
+
tag: string
|
|
76
|
+
/** Last update to collateral, liquidity, or their market values */
|
|
77
|
+
lastUpdate: types.LastUpdateJSON
|
|
78
|
+
/** Lending market address */
|
|
79
|
+
lendingMarket: string
|
|
80
|
+
/** Owner authority which can borrow liquidity */
|
|
81
|
+
owner: string
|
|
82
|
+
/** Deposited collateral for the obligation, unique by deposit reserve address */
|
|
83
|
+
deposits: Array<ObligationCollateralJSON>
|
|
84
|
+
/** Worst LTV for the collaterals backing the loan, represented as a percentage */
|
|
85
|
+
lowestReserveDepositLiquidationLtv: string
|
|
86
|
+
/** Market value of deposits (scaled fraction) */
|
|
87
|
+
depositedValueSf: string
|
|
88
|
+
/** Borrowed liquidity for the obligation, unique by borrow reserve address */
|
|
89
|
+
borrows: Array<ObligationLiquidityJSON>
|
|
90
|
+
/** Risk adjusted market value of borrows/debt (sum of price * borrowed_amount * borrow_factor) (scaled fraction) */
|
|
91
|
+
borrowFactorAdjustedDebtValueSf: string
|
|
92
|
+
/** Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) */
|
|
93
|
+
borrowedAssetsMarketValueSf: string
|
|
94
|
+
/** The maximum borrow value at the weighted average loan to value ratio (scaled fraction) */
|
|
95
|
+
allowedBorrowValueSf: string
|
|
96
|
+
/** The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) */
|
|
97
|
+
unhealthyBorrowValueSf: string
|
|
98
|
+
/** The asset tier of the deposits */
|
|
99
|
+
depositsAssetTiers: Array<number>
|
|
100
|
+
/** The asset tier of the borrows */
|
|
101
|
+
borrowsAssetTiers: Array<number>
|
|
102
|
+
/** The elevation group id the obligation opted into. */
|
|
103
|
+
elevationGroup: number
|
|
104
|
+
/** The number of obsolete reserves the obligation has a deposit in */
|
|
105
|
+
numOfObsoleteDepositReserves: number
|
|
106
|
+
/** Marked = 1 if borrows array is not empty, 0 = borrows empty */
|
|
107
|
+
hasDebt: number
|
|
108
|
+
/** Wallet address of the referrer */
|
|
109
|
+
referrer: string
|
|
110
|
+
/** Marked = 1 if borrowing disabled, 0 = borrowing enabled */
|
|
111
|
+
borrowingDisabled: number
|
|
112
|
+
/**
|
|
113
|
+
* A target LTV set by the risk council when marking this obligation for deleveraging.
|
|
114
|
+
* Only effective when `deleveraging_margin_call_started_slot != 0`.
|
|
115
|
+
*/
|
|
116
|
+
autodeleverageTargetLtvPct: number
|
|
117
|
+
/** The lowest max LTV found amongst the collateral deposits */
|
|
118
|
+
lowestReserveDepositMaxLtvPct: number
|
|
119
|
+
/** The number of obsolete reserves the obligation has a borrow in */
|
|
120
|
+
numOfObsoleteBorrowReserves: number
|
|
121
|
+
reserved: Array<number>
|
|
122
|
+
highestBorrowFactorPct: string
|
|
123
|
+
/**
|
|
124
|
+
* A timestamp at which the risk council most-recently marked this obligation for deleveraging.
|
|
125
|
+
* Zero if not currently subject to deleveraging.
|
|
126
|
+
*/
|
|
127
|
+
autodeleverageMarginCallStartedTimestamp: string
|
|
128
|
+
/**
|
|
129
|
+
* Owner-defined, liquidator-executed orders applicable to this obligation.
|
|
130
|
+
* Typical use-cases would be a stop-loss and a take-profit (possibly co-existing).
|
|
131
|
+
*/
|
|
132
|
+
orders: Array<ObligationOrderJSON>
|
|
133
|
+
padding3: Array<string>
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Lending market obligation state */
|
|
137
|
+
export class Obligation {
|
|
138
|
+
/** Version of the struct */
|
|
139
|
+
readonly tag: BN
|
|
140
|
+
/** Last update to collateral, liquidity, or their market values */
|
|
141
|
+
readonly lastUpdate: types.LastUpdate
|
|
142
|
+
/** Lending market address */
|
|
143
|
+
readonly lendingMarket: PublicKey
|
|
144
|
+
/** Owner authority which can borrow liquidity */
|
|
145
|
+
readonly owner: PublicKey
|
|
146
|
+
/** Deposited collateral for the obligation, unique by deposit reserve address */
|
|
147
|
+
readonly deposits: Array<ObligationCollateral>
|
|
148
|
+
/** Worst LTV for the collaterals backing the loan, represented as a percentage */
|
|
149
|
+
readonly lowestReserveDepositLiquidationLtv: BN
|
|
150
|
+
/** Market value of deposits (scaled fraction) */
|
|
151
|
+
readonly depositedValueSf: BN
|
|
152
|
+
/** Borrowed liquidity for the obligation, unique by borrow reserve address */
|
|
153
|
+
readonly borrows: Array<ObligationLiquidity>
|
|
154
|
+
/** Risk adjusted market value of borrows/debt (sum of price * borrowed_amount * borrow_factor) (scaled fraction) */
|
|
155
|
+
readonly borrowFactorAdjustedDebtValueSf: BN
|
|
156
|
+
/** Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) */
|
|
157
|
+
readonly borrowedAssetsMarketValueSf: BN
|
|
158
|
+
/** The maximum borrow value at the weighted average loan to value ratio (scaled fraction) */
|
|
159
|
+
readonly allowedBorrowValueSf: BN
|
|
160
|
+
/** The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) */
|
|
161
|
+
readonly unhealthyBorrowValueSf: BN
|
|
162
|
+
/** The asset tier of the deposits */
|
|
163
|
+
readonly depositsAssetTiers: Array<number>
|
|
164
|
+
/** The asset tier of the borrows */
|
|
165
|
+
readonly borrowsAssetTiers: Array<number>
|
|
166
|
+
/** The elevation group id the obligation opted into. */
|
|
167
|
+
readonly elevationGroup: number
|
|
168
|
+
/** The number of obsolete reserves the obligation has a deposit in */
|
|
169
|
+
readonly numOfObsoleteDepositReserves: number
|
|
170
|
+
/** Marked = 1 if borrows array is not empty, 0 = borrows empty */
|
|
171
|
+
readonly hasDebt: number
|
|
172
|
+
/** Wallet address of the referrer */
|
|
173
|
+
readonly referrer: PublicKey
|
|
174
|
+
/** Marked = 1 if borrowing disabled, 0 = borrowing enabled */
|
|
175
|
+
readonly borrowingDisabled: number
|
|
176
|
+
/**
|
|
177
|
+
* A target LTV set by the risk council when marking this obligation for deleveraging.
|
|
178
|
+
* Only effective when `deleveraging_margin_call_started_slot != 0`.
|
|
179
|
+
*/
|
|
180
|
+
readonly autodeleverageTargetLtvPct: number
|
|
181
|
+
/** The lowest max LTV found amongst the collateral deposits */
|
|
182
|
+
readonly lowestReserveDepositMaxLtvPct: number
|
|
183
|
+
/** The number of obsolete reserves the obligation has a borrow in */
|
|
184
|
+
readonly numOfObsoleteBorrowReserves: number
|
|
185
|
+
readonly reserved: Array<number>
|
|
186
|
+
readonly highestBorrowFactorPct: BN
|
|
187
|
+
/**
|
|
188
|
+
* A timestamp at which the risk council most-recently marked this obligation for deleveraging.
|
|
189
|
+
* Zero if not currently subject to deleveraging.
|
|
190
|
+
*/
|
|
191
|
+
readonly autodeleverageMarginCallStartedTimestamp: BN
|
|
192
|
+
/**
|
|
193
|
+
* Owner-defined, liquidator-executed orders applicable to this obligation.
|
|
194
|
+
* Typical use-cases would be a stop-loss and a take-profit (possibly co-existing).
|
|
195
|
+
*/
|
|
196
|
+
readonly orders: Array<ObligationOrder>
|
|
197
|
+
readonly padding3: Array<BN>
|
|
198
|
+
|
|
199
|
+
static readonly discriminator = Buffer.from([168, 206, 141, 106, 88, 76, 172, 167])
|
|
200
|
+
|
|
201
|
+
static readonly layout = borsh.struct([
|
|
202
|
+
borsh.u64("tag"),
|
|
203
|
+
types.LastUpdate.layout("lastUpdate"),
|
|
204
|
+
borsh.publicKey("lendingMarket"),
|
|
205
|
+
borsh.publicKey("owner"),
|
|
206
|
+
borsh.array(ObligationCollateral.layout(), 8, "deposits"),
|
|
207
|
+
borsh.u64("lowestReserveDepositLiquidationLtv"),
|
|
208
|
+
borsh.u128("depositedValueSf"),
|
|
209
|
+
borsh.array(ObligationLiquidity.layout(), 5, "borrows"),
|
|
210
|
+
borsh.u128("borrowFactorAdjustedDebtValueSf"),
|
|
211
|
+
borsh.u128("borrowedAssetsMarketValueSf"),
|
|
212
|
+
borsh.u128("allowedBorrowValueSf"),
|
|
213
|
+
borsh.u128("unhealthyBorrowValueSf"),
|
|
214
|
+
borsh.array(borsh.u8(), 8, "depositsAssetTiers"),
|
|
215
|
+
borsh.array(borsh.u8(), 5, "borrowsAssetTiers"),
|
|
216
|
+
borsh.u8("elevationGroup"),
|
|
217
|
+
borsh.u8("numOfObsoleteDepositReserves"),
|
|
218
|
+
borsh.u8("hasDebt"),
|
|
219
|
+
borsh.publicKey("referrer"),
|
|
220
|
+
borsh.u8("borrowingDisabled"),
|
|
221
|
+
borsh.u8("autodeleverageTargetLtvPct"),
|
|
222
|
+
borsh.u8("lowestReserveDepositMaxLtvPct"),
|
|
223
|
+
borsh.u8("numOfObsoleteBorrowReserves"),
|
|
224
|
+
borsh.array(borsh.u8(), 4, "reserved"),
|
|
225
|
+
borsh.u64("highestBorrowFactorPct"),
|
|
226
|
+
borsh.u64("autodeleverageMarginCallStartedTimestamp"),
|
|
227
|
+
borsh.array(ObligationOrder.layout(), 2, "orders"),
|
|
228
|
+
borsh.array(borsh.u64(), 93, "padding3"),
|
|
229
|
+
])
|
|
230
|
+
|
|
231
|
+
constructor(fields: ObligationFields) {
|
|
232
|
+
this.tag = fields.tag
|
|
233
|
+
this.lastUpdate = new types.LastUpdate({ ...fields.lastUpdate })
|
|
234
|
+
this.lendingMarket = fields.lendingMarket
|
|
235
|
+
this.owner = fields.owner
|
|
236
|
+
this.deposits = fields.deposits.map((item) => new ObligationCollateral({ ...item }))
|
|
237
|
+
this.lowestReserveDepositLiquidationLtv = fields.lowestReserveDepositLiquidationLtv
|
|
238
|
+
this.depositedValueSf = fields.depositedValueSf
|
|
239
|
+
this.borrows = fields.borrows.map((item) => new ObligationLiquidity({ ...item }))
|
|
240
|
+
this.borrowFactorAdjustedDebtValueSf = fields.borrowFactorAdjustedDebtValueSf
|
|
241
|
+
this.borrowedAssetsMarketValueSf = fields.borrowedAssetsMarketValueSf
|
|
242
|
+
this.allowedBorrowValueSf = fields.allowedBorrowValueSf
|
|
243
|
+
this.unhealthyBorrowValueSf = fields.unhealthyBorrowValueSf
|
|
244
|
+
this.depositsAssetTiers = fields.depositsAssetTiers
|
|
245
|
+
this.borrowsAssetTiers = fields.borrowsAssetTiers
|
|
246
|
+
this.elevationGroup = fields.elevationGroup
|
|
247
|
+
this.numOfObsoleteDepositReserves = fields.numOfObsoleteDepositReserves
|
|
248
|
+
this.hasDebt = fields.hasDebt
|
|
249
|
+
this.referrer = fields.referrer
|
|
250
|
+
this.borrowingDisabled = fields.borrowingDisabled
|
|
251
|
+
this.autodeleverageTargetLtvPct = fields.autodeleverageTargetLtvPct
|
|
252
|
+
this.lowestReserveDepositMaxLtvPct = fields.lowestReserveDepositMaxLtvPct
|
|
253
|
+
this.numOfObsoleteBorrowReserves = fields.numOfObsoleteBorrowReserves
|
|
254
|
+
this.reserved = fields.reserved
|
|
255
|
+
this.highestBorrowFactorPct = fields.highestBorrowFactorPct
|
|
256
|
+
this.autodeleverageMarginCallStartedTimestamp = fields.autodeleverageMarginCallStartedTimestamp
|
|
257
|
+
this.orders = fields.orders.map((item) => new ObligationOrder({ ...item }))
|
|
258
|
+
this.padding3 = fields.padding3
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
static async fetch(c: Connection, address: PublicKey, programId: PublicKey = PROGRAM_ID): Promise<Obligation | null> {
|
|
262
|
+
const info = await c.getAccountInfo(address)
|
|
263
|
+
|
|
264
|
+
if (info === null) {
|
|
265
|
+
return null
|
|
266
|
+
}
|
|
267
|
+
if (!info.owner.equals(programId)) {
|
|
268
|
+
throw new Error("account doesn't belong to this program")
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return this.decode(info.data)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static async fetchMultiple(
|
|
275
|
+
c: Connection,
|
|
276
|
+
addresses: PublicKey[],
|
|
277
|
+
programId: PublicKey = PROGRAM_ID,
|
|
278
|
+
): Promise<Array<Obligation | null>> {
|
|
279
|
+
const infos = await c.getMultipleAccountsInfo(addresses)
|
|
280
|
+
|
|
281
|
+
return infos.map((info) => {
|
|
282
|
+
if (info === null) {
|
|
283
|
+
return null
|
|
284
|
+
}
|
|
285
|
+
if (!info.owner.equals(programId)) {
|
|
286
|
+
throw new Error("account doesn't belong to this program")
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return this.decode(info.data)
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
static decode(data: Buffer): Obligation {
|
|
294
|
+
if (!data.slice(0, 8).equals(Obligation.discriminator)) {
|
|
295
|
+
throw new Error("invalid account discriminator")
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const dec = Obligation.layout.decode(data.slice(8))
|
|
299
|
+
|
|
300
|
+
return new Obligation({
|
|
301
|
+
tag: dec.tag,
|
|
302
|
+
lastUpdate: types.LastUpdate.fromDecoded(dec.lastUpdate),
|
|
303
|
+
lendingMarket: dec.lendingMarket,
|
|
304
|
+
owner: dec.owner,
|
|
305
|
+
deposits: dec.deposits.map((item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) =>
|
|
306
|
+
ObligationCollateral.fromDecoded(item),
|
|
307
|
+
),
|
|
308
|
+
lowestReserveDepositLiquidationLtv: dec.lowestReserveDepositLiquidationLtv,
|
|
309
|
+
depositedValueSf: dec.depositedValueSf,
|
|
310
|
+
borrows: dec.borrows.map((item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) =>
|
|
311
|
+
ObligationLiquidity.fromDecoded(item),
|
|
312
|
+
),
|
|
313
|
+
borrowFactorAdjustedDebtValueSf: dec.borrowFactorAdjustedDebtValueSf,
|
|
314
|
+
borrowedAssetsMarketValueSf: dec.borrowedAssetsMarketValueSf,
|
|
315
|
+
allowedBorrowValueSf: dec.allowedBorrowValueSf,
|
|
316
|
+
unhealthyBorrowValueSf: dec.unhealthyBorrowValueSf,
|
|
317
|
+
depositsAssetTiers: dec.depositsAssetTiers,
|
|
318
|
+
borrowsAssetTiers: dec.borrowsAssetTiers,
|
|
319
|
+
elevationGroup: dec.elevationGroup,
|
|
320
|
+
numOfObsoleteDepositReserves: dec.numOfObsoleteDepositReserves,
|
|
321
|
+
hasDebt: dec.hasDebt,
|
|
322
|
+
referrer: dec.referrer,
|
|
323
|
+
borrowingDisabled: dec.borrowingDisabled,
|
|
324
|
+
autodeleverageTargetLtvPct: dec.autodeleverageTargetLtvPct,
|
|
325
|
+
lowestReserveDepositMaxLtvPct: dec.lowestReserveDepositMaxLtvPct,
|
|
326
|
+
numOfObsoleteBorrowReserves: dec.numOfObsoleteBorrowReserves,
|
|
327
|
+
reserved: dec.reserved,
|
|
328
|
+
highestBorrowFactorPct: dec.highestBorrowFactorPct,
|
|
329
|
+
autodeleverageMarginCallStartedTimestamp: dec.autodeleverageMarginCallStartedTimestamp,
|
|
330
|
+
orders: dec.orders.map((item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) =>
|
|
331
|
+
ObligationOrder.fromDecoded(item),
|
|
332
|
+
),
|
|
333
|
+
padding3: dec.padding3,
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
toJSON(): ObligationJSON {
|
|
338
|
+
return {
|
|
339
|
+
tag: this.tag.toString(),
|
|
340
|
+
lastUpdate: this.lastUpdate.toJSON(),
|
|
341
|
+
lendingMarket: this.lendingMarket.toString(),
|
|
342
|
+
owner: this.owner.toString(),
|
|
343
|
+
deposits: this.deposits.map((item) => item.toJSON()),
|
|
344
|
+
lowestReserveDepositLiquidationLtv: this.lowestReserveDepositLiquidationLtv.toString(),
|
|
345
|
+
depositedValueSf: this.depositedValueSf.toString(),
|
|
346
|
+
borrows: this.borrows.map((item) => item.toJSON()),
|
|
347
|
+
borrowFactorAdjustedDebtValueSf: this.borrowFactorAdjustedDebtValueSf.toString(),
|
|
348
|
+
borrowedAssetsMarketValueSf: this.borrowedAssetsMarketValueSf.toString(),
|
|
349
|
+
allowedBorrowValueSf: this.allowedBorrowValueSf.toString(),
|
|
350
|
+
unhealthyBorrowValueSf: this.unhealthyBorrowValueSf.toString(),
|
|
351
|
+
depositsAssetTiers: this.depositsAssetTiers,
|
|
352
|
+
borrowsAssetTiers: this.borrowsAssetTiers,
|
|
353
|
+
elevationGroup: this.elevationGroup,
|
|
354
|
+
numOfObsoleteDepositReserves: this.numOfObsoleteDepositReserves,
|
|
355
|
+
hasDebt: this.hasDebt,
|
|
356
|
+
referrer: this.referrer.toString(),
|
|
357
|
+
borrowingDisabled: this.borrowingDisabled,
|
|
358
|
+
autodeleverageTargetLtvPct: this.autodeleverageTargetLtvPct,
|
|
359
|
+
lowestReserveDepositMaxLtvPct: this.lowestReserveDepositMaxLtvPct,
|
|
360
|
+
numOfObsoleteBorrowReserves: this.numOfObsoleteBorrowReserves,
|
|
361
|
+
reserved: this.reserved,
|
|
362
|
+
highestBorrowFactorPct: this.highestBorrowFactorPct.toString(),
|
|
363
|
+
autodeleverageMarginCallStartedTimestamp: this.autodeleverageMarginCallStartedTimestamp.toString(),
|
|
364
|
+
orders: this.orders.map((item) => item.toJSON()),
|
|
365
|
+
padding3: this.padding3.map((item) => item.toString()),
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
static fromJSON(obj: ObligationJSON): Obligation {
|
|
370
|
+
return new Obligation({
|
|
371
|
+
tag: new BN(obj.tag),
|
|
372
|
+
lastUpdate: types.LastUpdate.fromJSON(obj.lastUpdate),
|
|
373
|
+
lendingMarket: new PublicKey(obj.lendingMarket),
|
|
374
|
+
owner: new PublicKey(obj.owner),
|
|
375
|
+
deposits: obj.deposits.map((item) => ObligationCollateral.fromJSON(item)),
|
|
376
|
+
lowestReserveDepositLiquidationLtv: new BN(obj.lowestReserveDepositLiquidationLtv),
|
|
377
|
+
depositedValueSf: new BN(obj.depositedValueSf),
|
|
378
|
+
borrows: obj.borrows.map((item) => ObligationLiquidity.fromJSON(item)),
|
|
379
|
+
borrowFactorAdjustedDebtValueSf: new BN(obj.borrowFactorAdjustedDebtValueSf),
|
|
380
|
+
borrowedAssetsMarketValueSf: new BN(obj.borrowedAssetsMarketValueSf),
|
|
381
|
+
allowedBorrowValueSf: new BN(obj.allowedBorrowValueSf),
|
|
382
|
+
unhealthyBorrowValueSf: new BN(obj.unhealthyBorrowValueSf),
|
|
383
|
+
depositsAssetTiers: obj.depositsAssetTiers,
|
|
384
|
+
borrowsAssetTiers: obj.borrowsAssetTiers,
|
|
385
|
+
elevationGroup: obj.elevationGroup,
|
|
386
|
+
numOfObsoleteDepositReserves: obj.numOfObsoleteDepositReserves,
|
|
387
|
+
hasDebt: obj.hasDebt,
|
|
388
|
+
referrer: new PublicKey(obj.referrer),
|
|
389
|
+
borrowingDisabled: obj.borrowingDisabled,
|
|
390
|
+
autodeleverageTargetLtvPct: obj.autodeleverageTargetLtvPct,
|
|
391
|
+
lowestReserveDepositMaxLtvPct: obj.lowestReserveDepositMaxLtvPct,
|
|
392
|
+
numOfObsoleteBorrowReserves: obj.numOfObsoleteBorrowReserves,
|
|
393
|
+
reserved: obj.reserved,
|
|
394
|
+
highestBorrowFactorPct: new BN(obj.highestBorrowFactorPct),
|
|
395
|
+
autodeleverageMarginCallStartedTimestamp: new BN(obj.autodeleverageMarginCallStartedTimestamp),
|
|
396
|
+
orders: obj.orders.map((item) => ObligationOrder.fromJSON(item)),
|
|
397
|
+
padding3: obj.padding3.map((item) => new BN(item)),
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js" // 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
|
+
|
|
6
|
+
export interface ObligationCollateralFields {
|
|
7
|
+
/** Reserve collateral is deposited to */
|
|
8
|
+
depositReserve: PublicKey
|
|
9
|
+
/** Amount of collateral deposited */
|
|
10
|
+
depositedAmount: BN
|
|
11
|
+
/** Collateral market value in quote currency (scaled fraction) */
|
|
12
|
+
marketValueSf: BN
|
|
13
|
+
/**
|
|
14
|
+
* Debt amount (lamport) taken against this collateral.
|
|
15
|
+
* (only meaningful if this obligation is part of an elevation group, otherwise 0)
|
|
16
|
+
* This is only indicative of the debt computed on the last refresh obligation.
|
|
17
|
+
* If the obligation have multiple collateral this value is the same for all of them.
|
|
18
|
+
*/
|
|
19
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: BN
|
|
20
|
+
padding: Array<BN>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ObligationCollateralJSON {
|
|
24
|
+
/** Reserve collateral is deposited to */
|
|
25
|
+
depositReserve: string
|
|
26
|
+
/** Amount of collateral deposited */
|
|
27
|
+
depositedAmount: string
|
|
28
|
+
/** Collateral market value in quote currency (scaled fraction) */
|
|
29
|
+
marketValueSf: string
|
|
30
|
+
/**
|
|
31
|
+
* Debt amount (lamport) taken against this collateral.
|
|
32
|
+
* (only meaningful if this obligation is part of an elevation group, otherwise 0)
|
|
33
|
+
* This is only indicative of the debt computed on the last refresh obligation.
|
|
34
|
+
* If the obligation have multiple collateral this value is the same for all of them.
|
|
35
|
+
*/
|
|
36
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: string
|
|
37
|
+
padding: Array<string>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Obligation collateral state */
|
|
41
|
+
export class ObligationCollateral {
|
|
42
|
+
/** Reserve collateral is deposited to */
|
|
43
|
+
readonly depositReserve: PublicKey
|
|
44
|
+
/** Amount of collateral deposited */
|
|
45
|
+
readonly depositedAmount: BN
|
|
46
|
+
/** Collateral market value in quote currency (scaled fraction) */
|
|
47
|
+
readonly marketValueSf: BN
|
|
48
|
+
/**
|
|
49
|
+
* Debt amount (lamport) taken against this collateral.
|
|
50
|
+
* (only meaningful if this obligation is part of an elevation group, otherwise 0)
|
|
51
|
+
* This is only indicative of the debt computed on the last refresh obligation.
|
|
52
|
+
* If the obligation have multiple collateral this value is the same for all of them.
|
|
53
|
+
*/
|
|
54
|
+
readonly borrowedAmountAgainstThisCollateralInElevationGroup: BN
|
|
55
|
+
readonly padding: Array<BN>
|
|
56
|
+
|
|
57
|
+
constructor(fields: ObligationCollateralFields) {
|
|
58
|
+
this.depositReserve = fields.depositReserve
|
|
59
|
+
this.depositedAmount = fields.depositedAmount
|
|
60
|
+
this.marketValueSf = fields.marketValueSf
|
|
61
|
+
this.borrowedAmountAgainstThisCollateralInElevationGroup =
|
|
62
|
+
fields.borrowedAmountAgainstThisCollateralInElevationGroup
|
|
63
|
+
this.padding = fields.padding
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static layout(property?: string) {
|
|
67
|
+
return borsh.struct(
|
|
68
|
+
[
|
|
69
|
+
borsh.publicKey("depositReserve"),
|
|
70
|
+
borsh.u64("depositedAmount"),
|
|
71
|
+
borsh.u128("marketValueSf"),
|
|
72
|
+
borsh.u64("borrowedAmountAgainstThisCollateralInElevationGroup"),
|
|
73
|
+
borsh.array(borsh.u64(), 9, "padding"),
|
|
74
|
+
],
|
|
75
|
+
property,
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
static fromDecoded(obj: any) {
|
|
81
|
+
return new ObligationCollateral({
|
|
82
|
+
depositReserve: obj.depositReserve,
|
|
83
|
+
depositedAmount: obj.depositedAmount,
|
|
84
|
+
marketValueSf: obj.marketValueSf,
|
|
85
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: obj.borrowedAmountAgainstThisCollateralInElevationGroup,
|
|
86
|
+
padding: obj.padding,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static toEncodable(fields: ObligationCollateralFields) {
|
|
91
|
+
return {
|
|
92
|
+
depositReserve: fields.depositReserve,
|
|
93
|
+
depositedAmount: fields.depositedAmount,
|
|
94
|
+
marketValueSf: fields.marketValueSf,
|
|
95
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: fields.borrowedAmountAgainstThisCollateralInElevationGroup,
|
|
96
|
+
padding: fields.padding,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
toJSON(): ObligationCollateralJSON {
|
|
101
|
+
return {
|
|
102
|
+
depositReserve: this.depositReserve.toString(),
|
|
103
|
+
depositedAmount: this.depositedAmount.toString(),
|
|
104
|
+
marketValueSf: this.marketValueSf.toString(),
|
|
105
|
+
borrowedAmountAgainstThisCollateralInElevationGroup:
|
|
106
|
+
this.borrowedAmountAgainstThisCollateralInElevationGroup.toString(),
|
|
107
|
+
padding: this.padding.map((item) => item.toString()),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static fromJSON(obj: ObligationCollateralJSON): ObligationCollateral {
|
|
112
|
+
return new ObligationCollateral({
|
|
113
|
+
depositReserve: new PublicKey(obj.depositReserve),
|
|
114
|
+
depositedAmount: new BN(obj.depositedAmount),
|
|
115
|
+
marketValueSf: new BN(obj.marketValueSf),
|
|
116
|
+
borrowedAmountAgainstThisCollateralInElevationGroup: new BN(
|
|
117
|
+
obj.borrowedAmountAgainstThisCollateralInElevationGroup,
|
|
118
|
+
),
|
|
119
|
+
padding: obj.padding.map((item) => new BN(item)),
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
toEncodable() {
|
|
124
|
+
return ObligationCollateral.toEncodable(this)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js" // 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 { BigFractionBytes, BigFractionBytesFields, BigFractionBytesJSON } from "./BigFractionBytes"
|
|
6
|
+
|
|
7
|
+
export interface ObligationLiquidityFields {
|
|
8
|
+
/** Reserve liquidity is borrowed from */
|
|
9
|
+
borrowReserve: PublicKey
|
|
10
|
+
/** Borrow rate used for calculating interest (big scaled fraction) */
|
|
11
|
+
cumulativeBorrowRateBsf: BigFractionBytesFields
|
|
12
|
+
padding: BN
|
|
13
|
+
/** Amount of liquidity borrowed plus interest (scaled fraction) */
|
|
14
|
+
borrowedAmountSf: BN
|
|
15
|
+
/** Liquidity market value in quote currency (scaled fraction) */
|
|
16
|
+
marketValueSf: BN
|
|
17
|
+
/** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */
|
|
18
|
+
borrowFactorAdjustedMarketValueSf: BN
|
|
19
|
+
/** Amount of liquidity borrowed outside of an elevation group */
|
|
20
|
+
borrowedAmountOutsideElevationGroups: BN
|
|
21
|
+
padding2: Array<BN>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ObligationLiquidityJSON {
|
|
25
|
+
/** Reserve liquidity is borrowed from */
|
|
26
|
+
borrowReserve: string
|
|
27
|
+
/** Borrow rate used for calculating interest (big scaled fraction) */
|
|
28
|
+
cumulativeBorrowRateBsf: BigFractionBytesJSON
|
|
29
|
+
padding: string
|
|
30
|
+
/** Amount of liquidity borrowed plus interest (scaled fraction) */
|
|
31
|
+
borrowedAmountSf: string
|
|
32
|
+
/** Liquidity market value in quote currency (scaled fraction) */
|
|
33
|
+
marketValueSf: string
|
|
34
|
+
/** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */
|
|
35
|
+
borrowFactorAdjustedMarketValueSf: string
|
|
36
|
+
/** Amount of liquidity borrowed outside of an elevation group */
|
|
37
|
+
borrowedAmountOutsideElevationGroups: string
|
|
38
|
+
padding2: Array<string>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Obligation liquidity state */
|
|
42
|
+
export class ObligationLiquidity {
|
|
43
|
+
/** Reserve liquidity is borrowed from */
|
|
44
|
+
readonly borrowReserve: PublicKey
|
|
45
|
+
/** Borrow rate used for calculating interest (big scaled fraction) */
|
|
46
|
+
readonly cumulativeBorrowRateBsf: BigFractionBytes
|
|
47
|
+
readonly padding: BN
|
|
48
|
+
/** Amount of liquidity borrowed plus interest (scaled fraction) */
|
|
49
|
+
readonly borrowedAmountSf: BN
|
|
50
|
+
/** Liquidity market value in quote currency (scaled fraction) */
|
|
51
|
+
readonly marketValueSf: BN
|
|
52
|
+
/** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */
|
|
53
|
+
readonly borrowFactorAdjustedMarketValueSf: BN
|
|
54
|
+
/** Amount of liquidity borrowed outside of an elevation group */
|
|
55
|
+
readonly borrowedAmountOutsideElevationGroups: BN
|
|
56
|
+
readonly padding2: Array<BN>
|
|
57
|
+
|
|
58
|
+
constructor(fields: ObligationLiquidityFields) {
|
|
59
|
+
this.borrowReserve = fields.borrowReserve
|
|
60
|
+
this.cumulativeBorrowRateBsf = new BigFractionBytes({
|
|
61
|
+
...fields.cumulativeBorrowRateBsf,
|
|
62
|
+
})
|
|
63
|
+
this.padding = fields.padding
|
|
64
|
+
this.borrowedAmountSf = fields.borrowedAmountSf
|
|
65
|
+
this.marketValueSf = fields.marketValueSf
|
|
66
|
+
this.borrowFactorAdjustedMarketValueSf = fields.borrowFactorAdjustedMarketValueSf
|
|
67
|
+
this.borrowedAmountOutsideElevationGroups = fields.borrowedAmountOutsideElevationGroups
|
|
68
|
+
this.padding2 = fields.padding2
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static layout(property?: string) {
|
|
72
|
+
return borsh.struct(
|
|
73
|
+
[
|
|
74
|
+
borsh.publicKey("borrowReserve"),
|
|
75
|
+
BigFractionBytes.layout("cumulativeBorrowRateBsf"),
|
|
76
|
+
borsh.u64("padding"),
|
|
77
|
+
borsh.u128("borrowedAmountSf"),
|
|
78
|
+
borsh.u128("marketValueSf"),
|
|
79
|
+
borsh.u128("borrowFactorAdjustedMarketValueSf"),
|
|
80
|
+
borsh.u64("borrowedAmountOutsideElevationGroups"),
|
|
81
|
+
borsh.array(borsh.u64(), 7, "padding2"),
|
|
82
|
+
],
|
|
83
|
+
property,
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
static fromDecoded(obj: any) {
|
|
89
|
+
return new ObligationLiquidity({
|
|
90
|
+
borrowReserve: obj.borrowReserve,
|
|
91
|
+
cumulativeBorrowRateBsf: BigFractionBytes.fromDecoded(obj.cumulativeBorrowRateBsf),
|
|
92
|
+
padding: obj.padding,
|
|
93
|
+
borrowedAmountSf: obj.borrowedAmountSf,
|
|
94
|
+
marketValueSf: obj.marketValueSf,
|
|
95
|
+
borrowFactorAdjustedMarketValueSf: obj.borrowFactorAdjustedMarketValueSf,
|
|
96
|
+
borrowedAmountOutsideElevationGroups: obj.borrowedAmountOutsideElevationGroups,
|
|
97
|
+
padding2: obj.padding2,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static toEncodable(fields: ObligationLiquidityFields) {
|
|
102
|
+
return {
|
|
103
|
+
borrowReserve: fields.borrowReserve,
|
|
104
|
+
cumulativeBorrowRateBsf: BigFractionBytes.toEncodable(fields.cumulativeBorrowRateBsf),
|
|
105
|
+
padding: fields.padding,
|
|
106
|
+
borrowedAmountSf: fields.borrowedAmountSf,
|
|
107
|
+
marketValueSf: fields.marketValueSf,
|
|
108
|
+
borrowFactorAdjustedMarketValueSf: fields.borrowFactorAdjustedMarketValueSf,
|
|
109
|
+
borrowedAmountOutsideElevationGroups: fields.borrowedAmountOutsideElevationGroups,
|
|
110
|
+
padding2: fields.padding2,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
toJSON(): ObligationLiquidityJSON {
|
|
115
|
+
return {
|
|
116
|
+
borrowReserve: this.borrowReserve.toString(),
|
|
117
|
+
cumulativeBorrowRateBsf: this.cumulativeBorrowRateBsf.toJSON(),
|
|
118
|
+
padding: this.padding.toString(),
|
|
119
|
+
borrowedAmountSf: this.borrowedAmountSf.toString(),
|
|
120
|
+
marketValueSf: this.marketValueSf.toString(),
|
|
121
|
+
borrowFactorAdjustedMarketValueSf: this.borrowFactorAdjustedMarketValueSf.toString(),
|
|
122
|
+
borrowedAmountOutsideElevationGroups: this.borrowedAmountOutsideElevationGroups.toString(),
|
|
123
|
+
padding2: this.padding2.map((item) => item.toString()),
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static fromJSON(obj: ObligationLiquidityJSON): ObligationLiquidity {
|
|
128
|
+
return new ObligationLiquidity({
|
|
129
|
+
borrowReserve: new PublicKey(obj.borrowReserve),
|
|
130
|
+
cumulativeBorrowRateBsf: BigFractionBytes.fromJSON(obj.cumulativeBorrowRateBsf),
|
|
131
|
+
padding: new BN(obj.padding),
|
|
132
|
+
borrowedAmountSf: new BN(obj.borrowedAmountSf),
|
|
133
|
+
marketValueSf: new BN(obj.marketValueSf),
|
|
134
|
+
borrowFactorAdjustedMarketValueSf: new BN(obj.borrowFactorAdjustedMarketValueSf),
|
|
135
|
+
borrowedAmountOutsideElevationGroups: new BN(obj.borrowedAmountOutsideElevationGroups),
|
|
136
|
+
padding2: obj.padding2.map((item) => new BN(item)),
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
toEncodable() {
|
|
141
|
+
return ObligationLiquidity.toEncodable(this)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js" // 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
|
+
|
|
6
|
+
export interface ObligationOrderFields {
|
|
7
|
+
/**
|
|
8
|
+
* A threshold value used by the condition (scaled [Fraction]).
|
|
9
|
+
* The exact meaning depends on the specific [Self::condition_type].
|
|
10
|
+
*
|
|
11
|
+
* Examples:
|
|
12
|
+
* - when `condition_type == 2 (UserLtvBelow)`:
|
|
13
|
+
* then a value of `0.455` here means that the order is active only when the obligation's
|
|
14
|
+
* user LTV is less than `0.455` (i.e. < 45.5%).
|
|
15
|
+
* - when `condition_type == 3 (DebtCollPriceRatioAbove)`:
|
|
16
|
+
* assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here
|
|
17
|
+
* means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e.
|
|
18
|
+
* > 491.3 SOL per BTC).
|
|
19
|
+
*/
|
|
20
|
+
conditionThresholdSf: BN
|
|
21
|
+
/**
|
|
22
|
+
* A configuration parameter used by the opportunity (scaled [Fraction]).
|
|
23
|
+
* The exact meaning depends on the specific [Self::opportunity_type].
|
|
24
|
+
*
|
|
25
|
+
* Examples:
|
|
26
|
+
* - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`:
|
|
27
|
+
* Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000`
|
|
28
|
+
* here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this
|
|
29
|
+
* obligation.
|
|
30
|
+
* Note: the special value of [Fraction::MAX] is *not* allowed in this case.
|
|
31
|
+
* - when `opportunity_type == 1 (DeleverageAllDebtAmount)`:
|
|
32
|
+
* The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt
|
|
33
|
+
* should be repaid).
|
|
34
|
+
*/
|
|
35
|
+
opportunityParameterSf: BN
|
|
36
|
+
/**
|
|
37
|
+
* A *minimum* additional fraction of collateral transferred to the liquidator, in bps.
|
|
38
|
+
*
|
|
39
|
+
* The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and
|
|
40
|
+
* grows linearly towards the [Self::max_execution_bonus_bps].
|
|
41
|
+
*
|
|
42
|
+
* Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when
|
|
43
|
+
* executed precisely at the moment LTV exceeds 65%.
|
|
44
|
+
*/
|
|
45
|
+
minExecutionBonusBps: number
|
|
46
|
+
/**
|
|
47
|
+
* A *maximum* additional fraction of collateral transferred to the liquidator, in bps.
|
|
48
|
+
*
|
|
49
|
+
* The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.:
|
|
50
|
+
* - for a stop-loss condition, it is a point at which the obligation becomes liquidatable;
|
|
51
|
+
* - for a take-profit condition, it is a point at which obligation has 0% LTV.
|
|
52
|
+
*
|
|
53
|
+
* In non-extreme states, the actual bonus value is interpolated linearly, starting from
|
|
54
|
+
* [Self::min_execution_bonus_bps] (at the point specified by the order's condition).
|
|
55
|
+
*
|
|
56
|
+
* Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140"
|
|
57
|
+
* order, when executed at a higher price = 200, at which the obligation's LTV happens to
|
|
58
|
+
* be equal to its liquidation LTV.
|
|
59
|
+
*/
|
|
60
|
+
maxExecutionBonusBps: number
|
|
61
|
+
/**
|
|
62
|
+
* Serialized [ConditionType].
|
|
63
|
+
* The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]).
|
|
64
|
+
*
|
|
65
|
+
* Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to
|
|
66
|
+
* interpret this condition, we also need to take the [Self::condition_threshold_sf] into
|
|
67
|
+
* account.
|
|
68
|
+
*/
|
|
69
|
+
conditionType: number
|
|
70
|
+
/**
|
|
71
|
+
* Serialized [OpportunityType].
|
|
72
|
+
*
|
|
73
|
+
* Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to
|
|
74
|
+
* interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into
|
|
75
|
+
* account.
|
|
76
|
+
*/
|
|
77
|
+
opportunityType: number
|
|
78
|
+
/**
|
|
79
|
+
* Internal padding.
|
|
80
|
+
* The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to
|
|
81
|
+
* align with `u128`s.
|
|
82
|
+
*/
|
|
83
|
+
padding1: Array<number>
|
|
84
|
+
/**
|
|
85
|
+
* End padding.
|
|
86
|
+
* The total size of a single instance is 8*u128 = 128 bytes.
|
|
87
|
+
*/
|
|
88
|
+
padding2: Array<BN>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ObligationOrderJSON {
|
|
92
|
+
/**
|
|
93
|
+
* A threshold value used by the condition (scaled [Fraction]).
|
|
94
|
+
* The exact meaning depends on the specific [Self::condition_type].
|
|
95
|
+
*
|
|
96
|
+
* Examples:
|
|
97
|
+
* - when `condition_type == 2 (UserLtvBelow)`:
|
|
98
|
+
* then a value of `0.455` here means that the order is active only when the obligation's
|
|
99
|
+
* user LTV is less than `0.455` (i.e. < 45.5%).
|
|
100
|
+
* - when `condition_type == 3 (DebtCollPriceRatioAbove)`:
|
|
101
|
+
* assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here
|
|
102
|
+
* means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e.
|
|
103
|
+
* > 491.3 SOL per BTC).
|
|
104
|
+
*/
|
|
105
|
+
conditionThresholdSf: string
|
|
106
|
+
/**
|
|
107
|
+
* A configuration parameter used by the opportunity (scaled [Fraction]).
|
|
108
|
+
* The exact meaning depends on the specific [Self::opportunity_type].
|
|
109
|
+
*
|
|
110
|
+
* Examples:
|
|
111
|
+
* - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`:
|
|
112
|
+
* Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000`
|
|
113
|
+
* here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this
|
|
114
|
+
* obligation.
|
|
115
|
+
* Note: the special value of [Fraction::MAX] is *not* allowed in this case.
|
|
116
|
+
* - when `opportunity_type == 1 (DeleverageAllDebtAmount)`:
|
|
117
|
+
* The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt
|
|
118
|
+
* should be repaid).
|
|
119
|
+
*/
|
|
120
|
+
opportunityParameterSf: string
|
|
121
|
+
/**
|
|
122
|
+
* A *minimum* additional fraction of collateral transferred to the liquidator, in bps.
|
|
123
|
+
*
|
|
124
|
+
* The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and
|
|
125
|
+
* grows linearly towards the [Self::max_execution_bonus_bps].
|
|
126
|
+
*
|
|
127
|
+
* Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when
|
|
128
|
+
* executed precisely at the moment LTV exceeds 65%.
|
|
129
|
+
*/
|
|
130
|
+
minExecutionBonusBps: number
|
|
131
|
+
/**
|
|
132
|
+
* A *maximum* additional fraction of collateral transferred to the liquidator, in bps.
|
|
133
|
+
*
|
|
134
|
+
* The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.:
|
|
135
|
+
* - for a stop-loss condition, it is a point at which the obligation becomes liquidatable;
|
|
136
|
+
* - for a take-profit condition, it is a point at which obligation has 0% LTV.
|
|
137
|
+
*
|
|
138
|
+
* In non-extreme states, the actual bonus value is interpolated linearly, starting from
|
|
139
|
+
* [Self::min_execution_bonus_bps] (at the point specified by the order's condition).
|
|
140
|
+
*
|
|
141
|
+
* Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140"
|
|
142
|
+
* order, when executed at a higher price = 200, at which the obligation's LTV happens to
|
|
143
|
+
* be equal to its liquidation LTV.
|
|
144
|
+
*/
|
|
145
|
+
maxExecutionBonusBps: number
|
|
146
|
+
/**
|
|
147
|
+
* Serialized [ConditionType].
|
|
148
|
+
* The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]).
|
|
149
|
+
*
|
|
150
|
+
* Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to
|
|
151
|
+
* interpret this condition, we also need to take the [Self::condition_threshold_sf] into
|
|
152
|
+
* account.
|
|
153
|
+
*/
|
|
154
|
+
conditionType: number
|
|
155
|
+
/**
|
|
156
|
+
* Serialized [OpportunityType].
|
|
157
|
+
*
|
|
158
|
+
* Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to
|
|
159
|
+
* interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into
|
|
160
|
+
* account.
|
|
161
|
+
*/
|
|
162
|
+
opportunityType: number
|
|
163
|
+
/**
|
|
164
|
+
* Internal padding.
|
|
165
|
+
* The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to
|
|
166
|
+
* align with `u128`s.
|
|
167
|
+
*/
|
|
168
|
+
padding1: Array<number>
|
|
169
|
+
/**
|
|
170
|
+
* End padding.
|
|
171
|
+
* The total size of a single instance is 8*u128 = 128 bytes.
|
|
172
|
+
*/
|
|
173
|
+
padding2: Array<string>
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A single obligation order.
|
|
178
|
+
* See [Obligation::orders].
|
|
179
|
+
*/
|
|
180
|
+
export class ObligationOrder {
|
|
181
|
+
/**
|
|
182
|
+
* A threshold value used by the condition (scaled [Fraction]).
|
|
183
|
+
* The exact meaning depends on the specific [Self::condition_type].
|
|
184
|
+
*
|
|
185
|
+
* Examples:
|
|
186
|
+
* - when `condition_type == 2 (UserLtvBelow)`:
|
|
187
|
+
* then a value of `0.455` here means that the order is active only when the obligation's
|
|
188
|
+
* user LTV is less than `0.455` (i.e. < 45.5%).
|
|
189
|
+
* - when `condition_type == 3 (DebtCollPriceRatioAbove)`:
|
|
190
|
+
* assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here
|
|
191
|
+
* means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e.
|
|
192
|
+
* > 491.3 SOL per BTC).
|
|
193
|
+
*/
|
|
194
|
+
readonly conditionThresholdSf: BN
|
|
195
|
+
/**
|
|
196
|
+
* A configuration parameter used by the opportunity (scaled [Fraction]).
|
|
197
|
+
* The exact meaning depends on the specific [Self::opportunity_type].
|
|
198
|
+
*
|
|
199
|
+
* Examples:
|
|
200
|
+
* - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`:
|
|
201
|
+
* Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000`
|
|
202
|
+
* here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this
|
|
203
|
+
* obligation.
|
|
204
|
+
* Note: the special value of [Fraction::MAX] is *not* allowed in this case.
|
|
205
|
+
* - when `opportunity_type == 1 (DeleverageAllDebtAmount)`:
|
|
206
|
+
* The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt
|
|
207
|
+
* should be repaid).
|
|
208
|
+
*/
|
|
209
|
+
readonly opportunityParameterSf: BN
|
|
210
|
+
/**
|
|
211
|
+
* A *minimum* additional fraction of collateral transferred to the liquidator, in bps.
|
|
212
|
+
*
|
|
213
|
+
* The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and
|
|
214
|
+
* grows linearly towards the [Self::max_execution_bonus_bps].
|
|
215
|
+
*
|
|
216
|
+
* Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when
|
|
217
|
+
* executed precisely at the moment LTV exceeds 65%.
|
|
218
|
+
*/
|
|
219
|
+
readonly minExecutionBonusBps: number
|
|
220
|
+
/**
|
|
221
|
+
* A *maximum* additional fraction of collateral transferred to the liquidator, in bps.
|
|
222
|
+
*
|
|
223
|
+
* The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.:
|
|
224
|
+
* - for a stop-loss condition, it is a point at which the obligation becomes liquidatable;
|
|
225
|
+
* - for a take-profit condition, it is a point at which obligation has 0% LTV.
|
|
226
|
+
*
|
|
227
|
+
* In non-extreme states, the actual bonus value is interpolated linearly, starting from
|
|
228
|
+
* [Self::min_execution_bonus_bps] (at the point specified by the order's condition).
|
|
229
|
+
*
|
|
230
|
+
* Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140"
|
|
231
|
+
* order, when executed at a higher price = 200, at which the obligation's LTV happens to
|
|
232
|
+
* be equal to its liquidation LTV.
|
|
233
|
+
*/
|
|
234
|
+
readonly maxExecutionBonusBps: number
|
|
235
|
+
/**
|
|
236
|
+
* Serialized [ConditionType].
|
|
237
|
+
* The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]).
|
|
238
|
+
*
|
|
239
|
+
* Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to
|
|
240
|
+
* interpret this condition, we also need to take the [Self::condition_threshold_sf] into
|
|
241
|
+
* account.
|
|
242
|
+
*/
|
|
243
|
+
readonly conditionType: number
|
|
244
|
+
/**
|
|
245
|
+
* Serialized [OpportunityType].
|
|
246
|
+
*
|
|
247
|
+
* Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to
|
|
248
|
+
* interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into
|
|
249
|
+
* account.
|
|
250
|
+
*/
|
|
251
|
+
readonly opportunityType: number
|
|
252
|
+
/**
|
|
253
|
+
* Internal padding.
|
|
254
|
+
* The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to
|
|
255
|
+
* align with `u128`s.
|
|
256
|
+
*/
|
|
257
|
+
readonly padding1: Array<number>
|
|
258
|
+
/**
|
|
259
|
+
* End padding.
|
|
260
|
+
* The total size of a single instance is 8*u128 = 128 bytes.
|
|
261
|
+
*/
|
|
262
|
+
readonly padding2: Array<BN>
|
|
263
|
+
|
|
264
|
+
constructor(fields: ObligationOrderFields) {
|
|
265
|
+
this.conditionThresholdSf = fields.conditionThresholdSf
|
|
266
|
+
this.opportunityParameterSf = fields.opportunityParameterSf
|
|
267
|
+
this.minExecutionBonusBps = fields.minExecutionBonusBps
|
|
268
|
+
this.maxExecutionBonusBps = fields.maxExecutionBonusBps
|
|
269
|
+
this.conditionType = fields.conditionType
|
|
270
|
+
this.opportunityType = fields.opportunityType
|
|
271
|
+
this.padding1 = fields.padding1
|
|
272
|
+
this.padding2 = fields.padding2
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
static layout(property?: string) {
|
|
276
|
+
return borsh.struct(
|
|
277
|
+
[
|
|
278
|
+
borsh.u128("conditionThresholdSf"),
|
|
279
|
+
borsh.u128("opportunityParameterSf"),
|
|
280
|
+
borsh.u16("minExecutionBonusBps"),
|
|
281
|
+
borsh.u16("maxExecutionBonusBps"),
|
|
282
|
+
borsh.u8("conditionType"),
|
|
283
|
+
borsh.u8("opportunityType"),
|
|
284
|
+
borsh.array(borsh.u8(), 10, "padding1"),
|
|
285
|
+
borsh.array(borsh.u128(), 5, "padding2"),
|
|
286
|
+
],
|
|
287
|
+
property,
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
|
+
static fromDecoded(obj: any) {
|
|
293
|
+
return new ObligationOrder({
|
|
294
|
+
conditionThresholdSf: obj.conditionThresholdSf,
|
|
295
|
+
opportunityParameterSf: obj.opportunityParameterSf,
|
|
296
|
+
minExecutionBonusBps: obj.minExecutionBonusBps,
|
|
297
|
+
maxExecutionBonusBps: obj.maxExecutionBonusBps,
|
|
298
|
+
conditionType: obj.conditionType,
|
|
299
|
+
opportunityType: obj.opportunityType,
|
|
300
|
+
padding1: obj.padding1,
|
|
301
|
+
padding2: obj.padding2,
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
static toEncodable(fields: ObligationOrderFields) {
|
|
306
|
+
return {
|
|
307
|
+
conditionThresholdSf: fields.conditionThresholdSf,
|
|
308
|
+
opportunityParameterSf: fields.opportunityParameterSf,
|
|
309
|
+
minExecutionBonusBps: fields.minExecutionBonusBps,
|
|
310
|
+
maxExecutionBonusBps: fields.maxExecutionBonusBps,
|
|
311
|
+
conditionType: fields.conditionType,
|
|
312
|
+
opportunityType: fields.opportunityType,
|
|
313
|
+
padding1: fields.padding1,
|
|
314
|
+
padding2: fields.padding2,
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
toJSON(): ObligationOrderJSON {
|
|
319
|
+
return {
|
|
320
|
+
conditionThresholdSf: this.conditionThresholdSf.toString(),
|
|
321
|
+
opportunityParameterSf: this.opportunityParameterSf.toString(),
|
|
322
|
+
minExecutionBonusBps: this.minExecutionBonusBps,
|
|
323
|
+
maxExecutionBonusBps: this.maxExecutionBonusBps,
|
|
324
|
+
conditionType: this.conditionType,
|
|
325
|
+
opportunityType: this.opportunityType,
|
|
326
|
+
padding1: this.padding1,
|
|
327
|
+
padding2: this.padding2.map((item) => item.toString()),
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
static fromJSON(obj: ObligationOrderJSON): ObligationOrder {
|
|
332
|
+
return new ObligationOrder({
|
|
333
|
+
conditionThresholdSf: new BN(obj.conditionThresholdSf),
|
|
334
|
+
opportunityParameterSf: new BN(obj.opportunityParameterSf),
|
|
335
|
+
minExecutionBonusBps: obj.minExecutionBonusBps,
|
|
336
|
+
maxExecutionBonusBps: obj.maxExecutionBonusBps,
|
|
337
|
+
conditionType: obj.conditionType,
|
|
338
|
+
opportunityType: obj.opportunityType,
|
|
339
|
+
padding1: obj.padding1,
|
|
340
|
+
padding2: obj.padding2.map((item) => new BN(item)),
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
toEncodable() {
|
|
345
|
+
return ObligationOrder.toEncodable(this)
|
|
346
|
+
}
|
|
347
|
+
}
|