@morpho-org/midnight-sdk 0.1.0 → 1.0.0
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/LICENSE +21 -0
- package/README.md +56 -46
- package/lib/cjs/abis.d.ts +1185 -996
- package/lib/cjs/abis.js +1445 -1211
- package/lib/cjs/api/MidnightApi.d.ts +22 -16
- package/lib/cjs/api/MidnightApi.js +22 -16
- package/lib/cjs/api/helpers.js +6 -3
- package/lib/cjs/api/types.d.ts +35 -9
- package/lib/cjs/constants.d.ts +12 -11
- package/lib/cjs/constants.js +14 -12
- package/lib/cjs/errors.d.ts +74 -1
- package/lib/cjs/errors.js +94 -3
- package/lib/cjs/fetch/Market.js +0 -1
- package/lib/cjs/fetch/index.d.ts +0 -1
- package/lib/cjs/fetch/index.js +0 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +2 -23
- package/lib/cjs/market/Market.d.ts +99 -33
- package/lib/cjs/market/Market.js +137 -28
- package/lib/cjs/market/MarketUtils.d.ts +61 -41
- package/lib/cjs/market/MarketUtils.js +108 -48
- package/lib/cjs/market/Position.d.ts +16 -11
- package/lib/cjs/market/Position.js +18 -12
- package/lib/cjs/market/PositionUtils.d.ts +6 -4
- package/lib/cjs/market/PositionUtils.js +9 -6
- package/lib/cjs/math/TickLib.d.ts +22 -0
- package/lib/cjs/math/TickLib.js +30 -0
- package/lib/cjs/math/index.d.ts +0 -1
- package/lib/cjs/math/index.js +0 -1
- package/lib/cjs/offers/Offer.d.ts +217 -11
- package/lib/cjs/offers/Offer.js +215 -7
- package/lib/cjs/offers/OfferUtils.d.ts +245 -139
- package/lib/cjs/offers/OfferUtils.js +304 -36
- package/lib/cjs/queries/GetPosition.d.ts +1 -1
- package/lib/cjs/queries/GetPosition.js +1 -1
- package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +66 -38
- package/lib/cjs/signatures/EcrecoverRatifierUtils.js +147 -79
- package/lib/cjs/signatures/Group.d.ts +12 -4
- package/lib/cjs/signatures/Group.js +12 -4
- package/lib/cjs/signatures/GroupUtils.d.ts +12 -4
- package/lib/cjs/signatures/GroupUtils.js +6 -2
- package/lib/cjs/signatures/Payload.d.ts +277 -277
- package/lib/cjs/signatures/Payload.js +517 -534
- package/lib/cjs/signatures/RatifierUtils.d.ts +57 -0
- package/lib/cjs/signatures/RatifierUtils.js +94 -0
- package/lib/cjs/signatures/SetterRatifierUtils.d.ts +21 -13
- package/lib/cjs/signatures/SetterRatifierUtils.js +25 -20
- package/lib/cjs/signatures/Tree.d.ts +28 -16
- package/lib/cjs/signatures/Tree.js +25 -13
- package/lib/cjs/signatures/TreeUtils.d.ts +181 -62
- package/lib/cjs/signatures/TreeUtils.js +73 -76
- package/lib/cjs/signatures/index.d.ts +1 -0
- package/lib/cjs/signatures/index.js +3 -0
- package/lib/cjs/signatures/offerStructInternal.d.ts +14 -0
- package/lib/cjs/signatures/offerStructInternal.js +72 -0
- package/lib/esm/abis.d.ts +1185 -996
- package/lib/esm/abis.js +1445 -1211
- package/lib/esm/api/MidnightApi.d.ts +22 -16
- package/lib/esm/api/MidnightApi.js +23 -17
- package/lib/esm/api/helpers.js +6 -3
- package/lib/esm/api/types.d.ts +35 -9
- package/lib/esm/constants.d.ts +12 -11
- package/lib/esm/constants.js +13 -11
- package/lib/esm/errors.d.ts +74 -1
- package/lib/esm/errors.js +89 -2
- package/lib/esm/fetch/Market.js +0 -1
- package/lib/esm/fetch/index.d.ts +0 -1
- package/lib/esm/fetch/index.js +0 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/market/Market.d.ts +99 -33
- package/lib/esm/market/Market.js +137 -28
- package/lib/esm/market/MarketUtils.d.ts +61 -41
- package/lib/esm/market/MarketUtils.js +109 -49
- package/lib/esm/market/Position.d.ts +16 -11
- package/lib/esm/market/Position.js +19 -13
- package/lib/esm/market/PositionUtils.d.ts +6 -4
- package/lib/esm/market/PositionUtils.js +9 -6
- package/lib/esm/math/TickLib.d.ts +22 -0
- package/lib/esm/math/TickLib.js +31 -1
- package/lib/esm/math/index.d.ts +0 -1
- package/lib/esm/math/index.js +0 -1
- package/lib/esm/offers/Offer.d.ts +217 -11
- package/lib/esm/offers/Offer.js +216 -8
- package/lib/esm/offers/OfferUtils.d.ts +245 -139
- package/lib/esm/offers/OfferUtils.js +306 -38
- package/lib/esm/queries/GetPosition.d.ts +1 -1
- package/lib/esm/queries/GetPosition.js +1 -1
- package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +66 -38
- package/lib/esm/signatures/EcrecoverRatifierUtils.js +149 -81
- package/lib/esm/signatures/Group.d.ts +12 -4
- package/lib/esm/signatures/Group.js +12 -4
- package/lib/esm/signatures/GroupUtils.d.ts +12 -4
- package/lib/esm/signatures/GroupUtils.js +6 -2
- package/lib/esm/signatures/Payload.d.ts +277 -277
- package/lib/esm/signatures/Payload.js +517 -531
- package/lib/esm/signatures/RatifierUtils.d.ts +57 -0
- package/lib/esm/signatures/RatifierUtils.js +94 -0
- package/lib/esm/signatures/SetterRatifierUtils.d.ts +21 -13
- package/lib/esm/signatures/SetterRatifierUtils.js +25 -20
- package/lib/esm/signatures/Tree.d.ts +28 -16
- package/lib/esm/signatures/Tree.js +25 -13
- package/lib/esm/signatures/TreeUtils.d.ts +181 -62
- package/lib/esm/signatures/TreeUtils.js +75 -78
- package/lib/esm/signatures/index.d.ts +1 -0
- package/lib/esm/signatures/index.js +1 -0
- package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
- package/lib/esm/signatures/offerStructInternal.js +67 -0
- package/package.json +28 -32
- package/src/index.ts +1 -1
- package/lib/cjs/fetch/Offer.d.ts +0 -74
- package/lib/cjs/fetch/Offer.js +0 -119
- package/lib/cjs/math/ConsumableUnitsLib.d.ts +0 -57
- package/lib/cjs/math/ConsumableUnitsLib.js +0 -77
- package/lib/esm/fetch/Offer.d.ts +0 -74
- package/lib/esm/fetch/Offer.js +0 -116
- package/lib/esm/math/ConsumableUnitsLib.d.ts +0 -57
- package/lib/esm/math/ConsumableUnitsLib.js +0 -74
package/lib/esm/market/Market.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertNonNegative, MathLib, } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { MAX_COLLATERALS } from "../constants.js";
|
|
2
3
|
import { InvalidMarketParameterError } from "../errors.js";
|
|
3
4
|
import { MarketUtils } from "./MarketUtils.js";
|
|
4
5
|
/**
|
|
@@ -9,12 +10,14 @@ import { MarketUtils } from "./MarketUtils.js";
|
|
|
9
10
|
* import { MarketParams } from "@morpho-org/midnight-sdk";
|
|
10
11
|
*
|
|
11
12
|
* const params = new MarketParams({
|
|
13
|
+
* chainId: 8453,
|
|
14
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
12
15
|
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
13
16
|
* collateralParams: [
|
|
14
17
|
* {
|
|
15
18
|
* token: "0x0000000000000000000000000000000000000002",
|
|
16
19
|
* lltv: 770000000000000000n,
|
|
17
|
-
*
|
|
20
|
+
* liquidationCursor: 250000000000000000n,
|
|
18
21
|
* oracle: "0x0000000000000000000000000000000000000003",
|
|
19
22
|
* },
|
|
20
23
|
* ],
|
|
@@ -27,6 +30,10 @@ import { MarketUtils } from "./MarketUtils.js";
|
|
|
27
30
|
* ```
|
|
28
31
|
*/
|
|
29
32
|
export class MarketParams {
|
|
33
|
+
/** EIP-155 chain id captured in the market struct. */
|
|
34
|
+
chainId;
|
|
35
|
+
/** Core Midnight contract address captured in the market struct. */
|
|
36
|
+
midnight;
|
|
30
37
|
/** Loan token address. */
|
|
31
38
|
loanToken;
|
|
32
39
|
/** Collateral definitions sorted by token. */
|
|
@@ -43,11 +50,30 @@ export class MarketParams {
|
|
|
43
50
|
* Creates normalized market params.
|
|
44
51
|
*
|
|
45
52
|
* @param params - Market params to normalize.
|
|
46
|
-
* @throws {InvalidMarketParameterError} when the collateral list is empty, contains duplicate tokens,
|
|
53
|
+
* @throws {InvalidMarketParameterError} when the chain id is malformed or negative, or when the collateral list is empty, exceeds {@link MAX_COLLATERALS}, contains duplicate tokens, has LLTV outside `[0, WAD]`, has liquidation cursor outside `[0, WAD)`, or computes an invalid maximum liquidation incentive factor.
|
|
47
54
|
*/
|
|
48
55
|
constructor(params) {
|
|
56
|
+
try {
|
|
57
|
+
this.chainId = BigInt(params.chainId);
|
|
58
|
+
}
|
|
59
|
+
catch (cause) {
|
|
60
|
+
throw new InvalidMarketParameterError({
|
|
61
|
+
parameter: "chainId",
|
|
62
|
+
value: params.chainId,
|
|
63
|
+
instruction: "Provide a bigint-compatible EIP-155 chain id.",
|
|
64
|
+
cause,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
this.midnight = params.midnight;
|
|
49
68
|
this.loanToken = params.loanToken;
|
|
50
69
|
const collateralParams = params.collateralParams.map(MarketUtils.toCollateralParams);
|
|
70
|
+
if (this.chainId < 0n) {
|
|
71
|
+
throw new InvalidMarketParameterError({
|
|
72
|
+
parameter: "chainId",
|
|
73
|
+
value: this.chainId,
|
|
74
|
+
instruction: "Use a non-negative EIP-155 chain id.",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
51
77
|
if (collateralParams.length === 0) {
|
|
52
78
|
throw new InvalidMarketParameterError({
|
|
53
79
|
parameter: "collateralParams",
|
|
@@ -55,6 +81,13 @@ export class MarketParams {
|
|
|
55
81
|
instruction: "Provide at least one collateral.",
|
|
56
82
|
});
|
|
57
83
|
}
|
|
84
|
+
if (collateralParams.length > Number(MAX_COLLATERALS)) {
|
|
85
|
+
throw new InvalidMarketParameterError({
|
|
86
|
+
parameter: "collateralParams",
|
|
87
|
+
value: collateralParams.length,
|
|
88
|
+
instruction: `Provide at most ${MAX_COLLATERALS} collaterals.`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
58
91
|
const seenCollateralTokens = new Set();
|
|
59
92
|
for (const collateral of collateralParams) {
|
|
60
93
|
if (collateral.lltv < 0n || collateral.lltv > MathLib.WAD) {
|
|
@@ -64,6 +97,31 @@ export class MarketParams {
|
|
|
64
97
|
instruction: "Use an LLTV between 0 and WAD.",
|
|
65
98
|
});
|
|
66
99
|
}
|
|
100
|
+
if (collateral.liquidationCursor < 0n ||
|
|
101
|
+
collateral.liquidationCursor >= MathLib.WAD) {
|
|
102
|
+
throw new InvalidMarketParameterError({
|
|
103
|
+
parameter: "collateralParams.liquidationCursor",
|
|
104
|
+
value: collateral.liquidationCursor,
|
|
105
|
+
instruction: "Use a liquidation cursor between 0 and WAD, exclusive of WAD.",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const maxLif = MathLib.mulDivDown(MathLib.WAD, MathLib.WAD, MathLib.WAD -
|
|
109
|
+
MathLib.mulDivDown(collateral.liquidationCursor, MathLib.WAD - collateral.lltv, MathLib.WAD));
|
|
110
|
+
if (maxLif > 2n * MathLib.WAD) {
|
|
111
|
+
throw new InvalidMarketParameterError({
|
|
112
|
+
parameter: "collateralParams.liquidationCursor",
|
|
113
|
+
value: collateral.liquidationCursor,
|
|
114
|
+
instruction: "Use a liquidation cursor whose computed maximum LIF is at most 2 WAD.",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (collateral.lltv !== MathLib.WAD &&
|
|
118
|
+
collateral.lltv * maxLif > 999000000000000000n * MathLib.WAD) {
|
|
119
|
+
throw new InvalidMarketParameterError({
|
|
120
|
+
parameter: "collateralParams.liquidationCursor",
|
|
121
|
+
value: collateral.liquidationCursor,
|
|
122
|
+
instruction: "Use an LLTV and liquidation cursor whose computed maximum LIF product satisfies the protocol bound.",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
67
125
|
const token = collateral.token.toLowerCase();
|
|
68
126
|
if (seenCollateralTokens.has(token)) {
|
|
69
127
|
throw new InvalidMarketParameterError({
|
|
@@ -93,12 +151,14 @@ export class MarketParams {
|
|
|
93
151
|
* import { MarketParams } from "@morpho-org/midnight-sdk";
|
|
94
152
|
*
|
|
95
153
|
* const params = MarketParams.from({
|
|
154
|
+
* chainId: 8453,
|
|
155
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
96
156
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
97
157
|
* collateralParams: [
|
|
98
158
|
* {
|
|
99
159
|
* token: "0x0000000000000000000000000000000000007000",
|
|
100
160
|
* lltv: 770000000000000000n,
|
|
101
|
-
*
|
|
161
|
+
* liquidationCursor: 250000000000000000n,
|
|
102
162
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
103
163
|
* },
|
|
104
164
|
* ],
|
|
@@ -139,14 +199,15 @@ export class MarketParams {
|
|
|
139
199
|
* });
|
|
140
200
|
*
|
|
141
201
|
* const market = new Market({
|
|
142
|
-
* chainId: 31337,
|
|
143
202
|
* params: {
|
|
203
|
+
* chainId: 31337,
|
|
204
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
144
205
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
145
206
|
* collateralParams: [
|
|
146
207
|
* {
|
|
147
208
|
* token: "0x0000000000000000000000000000000000007000",
|
|
148
209
|
* lltv: 770000000000000000n,
|
|
149
|
-
*
|
|
210
|
+
* liquidationCursor: 250000000000000000n,
|
|
150
211
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
151
212
|
* },
|
|
152
213
|
* ],
|
|
@@ -169,7 +230,7 @@ export class MarketParams {
|
|
|
169
230
|
export class Market {
|
|
170
231
|
/** Market id. */
|
|
171
232
|
id;
|
|
172
|
-
/** EIP-155 chain id
|
|
233
|
+
/** EIP-155 chain id captured in the market struct. */
|
|
173
234
|
chainId;
|
|
174
235
|
/** Immutable market configuration. */
|
|
175
236
|
params;
|
|
@@ -188,9 +249,9 @@ export class Market {
|
|
|
188
249
|
/** Market tick spacing. */
|
|
189
250
|
tickSpacing;
|
|
190
251
|
constructor(market) {
|
|
191
|
-
this.chainId = BigInt(market.chainId);
|
|
192
252
|
this.params = MarketParams.from(market.params);
|
|
193
|
-
this.
|
|
253
|
+
this.chainId = this.params.chainId;
|
|
254
|
+
this.id = MarketUtils.toId(this.params);
|
|
194
255
|
this.totalUnits = BigInt(market.totalUnits);
|
|
195
256
|
this.lossFactor = BigInt(market.lossFactor);
|
|
196
257
|
this.withdrawable = BigInt(market.withdrawable);
|
|
@@ -199,6 +260,52 @@ export class Market {
|
|
|
199
260
|
this.continuousFee = market.continuousFee;
|
|
200
261
|
this.tickSpacing = market.tickSpacing;
|
|
201
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Returns a hydrated market instance from class or plain input.
|
|
265
|
+
*
|
|
266
|
+
* Existing `Market` instances are returned as-is. Plain hydrated market objects
|
|
267
|
+
* are normalized through the constructor so nested params and bigint fields use
|
|
268
|
+
* the SDK's canonical shapes.
|
|
269
|
+
*
|
|
270
|
+
* @param market - Hydrated market class or plain market input.
|
|
271
|
+
* @returns Hydrated market instance.
|
|
272
|
+
* @throws {InvalidMarketParameterError} when nested market params are invalid.
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* import { Market } from "@morpho-org/midnight-sdk";
|
|
276
|
+
*
|
|
277
|
+
* const market = Market.from({
|
|
278
|
+
* params: {
|
|
279
|
+
* chainId: 8453,
|
|
280
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
281
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
282
|
+
* collateralParams: [
|
|
283
|
+
* {
|
|
284
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
285
|
+
* lltv: 770000000000000000n,
|
|
286
|
+
* liquidationCursor: 250000000000000000n,
|
|
287
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
288
|
+
* },
|
|
289
|
+
* ],
|
|
290
|
+
* maturity: 54_000n,
|
|
291
|
+
* rcfThreshold: 0n,
|
|
292
|
+
* enterGate: "0x0000000000000000000000000000000000000000",
|
|
293
|
+
* liquidatorGate: "0x0000000000000000000000000000000000000000",
|
|
294
|
+
* },
|
|
295
|
+
* totalUnits: 1_000n,
|
|
296
|
+
* lossFactor: 0n,
|
|
297
|
+
* withdrawable: 500n,
|
|
298
|
+
* continuousFeeCredit: 0n,
|
|
299
|
+
* settlementFeeCbps: [1, 2, 3, 4, 5, 6, 7],
|
|
300
|
+
* continuousFee: 10,
|
|
301
|
+
* tickSpacing: 4,
|
|
302
|
+
* });
|
|
303
|
+
* console.log(market.id);
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
static from(market) {
|
|
307
|
+
return market instanceof Market ? market : new Market(market);
|
|
308
|
+
}
|
|
202
309
|
/**
|
|
203
310
|
* Returns the non-negative time remaining before maturity.
|
|
204
311
|
*
|
|
@@ -225,14 +332,15 @@ export class Market {
|
|
|
225
332
|
* });
|
|
226
333
|
*
|
|
227
334
|
* const market = new Market({
|
|
228
|
-
* chainId: 31337,
|
|
229
335
|
* params: {
|
|
336
|
+
* chainId: 31337,
|
|
337
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
230
338
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
231
339
|
* collateralParams: [
|
|
232
340
|
* {
|
|
233
341
|
* token: "0x0000000000000000000000000000000000007000",
|
|
234
342
|
* lltv: 770000000000000000n,
|
|
235
|
-
*
|
|
343
|
+
* liquidationCursor: 250000000000000000n,
|
|
236
344
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
237
345
|
* },
|
|
238
346
|
* ],
|
|
@@ -285,14 +393,15 @@ export class Market {
|
|
|
285
393
|
* });
|
|
286
394
|
*
|
|
287
395
|
* const market = new Market({
|
|
288
|
-
* chainId: 31337,
|
|
289
396
|
* params: {
|
|
397
|
+
* chainId: 31337,
|
|
398
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
290
399
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
291
400
|
* collateralParams: [
|
|
292
401
|
* {
|
|
293
402
|
* token: "0x0000000000000000000000000000000000007000",
|
|
294
403
|
* lltv: 770000000000000000n,
|
|
295
|
-
*
|
|
404
|
+
* liquidationCursor: 250000000000000000n,
|
|
296
405
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
297
406
|
* },
|
|
298
407
|
* ],
|
|
@@ -319,10 +428,11 @@ export class Market {
|
|
|
319
428
|
});
|
|
320
429
|
}
|
|
321
430
|
/**
|
|
322
|
-
* Returns collateral
|
|
431
|
+
* Returns collateral by numeric index.
|
|
323
432
|
*
|
|
324
433
|
* @param index - Collateral index.
|
|
325
|
-
* @returns Collateral
|
|
434
|
+
* @returns Collateral entry for the configured index.
|
|
435
|
+
* @throws {UnknownCollateralIndexError} when the index is not configured.
|
|
326
436
|
* @example
|
|
327
437
|
* ```ts
|
|
328
438
|
* import { registerCustomAddresses } from "@morpho-org/morpho-ts";
|
|
@@ -343,14 +453,15 @@ export class Market {
|
|
|
343
453
|
* });
|
|
344
454
|
*
|
|
345
455
|
* const market = new Market({
|
|
346
|
-
* chainId: 31337,
|
|
347
456
|
* params: {
|
|
457
|
+
* chainId: 31337,
|
|
458
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
348
459
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
349
460
|
* collateralParams: [
|
|
350
461
|
* {
|
|
351
462
|
* token: "0x0000000000000000000000000000000000007000",
|
|
352
463
|
* lltv: 770000000000000000n,
|
|
353
|
-
*
|
|
464
|
+
* liquidationCursor: 250000000000000000n,
|
|
354
465
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
355
466
|
* },
|
|
356
467
|
* ],
|
|
@@ -367,16 +478,12 @@ export class Market {
|
|
|
367
478
|
* continuousFee: 10,
|
|
368
479
|
* tickSpacing: 4,
|
|
369
480
|
* });
|
|
370
|
-
* const
|
|
371
|
-
* console.log(
|
|
481
|
+
* const collateral = market.getCollateralByIndex(0);
|
|
482
|
+
* console.log(collateral.token);
|
|
372
483
|
* ```
|
|
373
484
|
*/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (normalizedIndex < 0n ||
|
|
377
|
-
normalizedIndex > BigInt(Number.MAX_SAFE_INTEGER))
|
|
378
|
-
return undefined;
|
|
379
|
-
return this.params.collateralParams[Number(normalizedIndex)];
|
|
485
|
+
getCollateralByIndex(index) {
|
|
486
|
+
return MarketUtils.getCollateralByIndex(this, index);
|
|
380
487
|
}
|
|
381
488
|
/**
|
|
382
489
|
* Returns the configured collateral index for a token.
|
|
@@ -404,14 +511,15 @@ export class Market {
|
|
|
404
511
|
*
|
|
405
512
|
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
406
513
|
* const market = new Market({
|
|
407
|
-
* chainId: 31337,
|
|
408
514
|
* params: {
|
|
515
|
+
* chainId: 31337,
|
|
516
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
409
517
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
410
518
|
* collateralParams: [
|
|
411
519
|
* {
|
|
412
520
|
* token: collateralToken,
|
|
413
521
|
* lltv: 770000000000000000n,
|
|
414
|
-
*
|
|
522
|
+
* liquidationCursor: 250000000000000000n,
|
|
415
523
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
416
524
|
* },
|
|
417
525
|
* ],
|
|
@@ -463,14 +571,15 @@ export class Market {
|
|
|
463
571
|
*
|
|
464
572
|
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
465
573
|
* const market = new Market({
|
|
466
|
-
* chainId: 31337,
|
|
467
574
|
* params: {
|
|
575
|
+
* chainId: 31337,
|
|
576
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
468
577
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
469
578
|
* collateralParams: [
|
|
470
579
|
* {
|
|
471
580
|
* token: collateralToken,
|
|
472
581
|
* lltv: 770000000000000000n,
|
|
473
|
-
*
|
|
582
|
+
* liquidationCursor: 250000000000000000n,
|
|
474
583
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
475
584
|
* },
|
|
476
585
|
* ],
|
|
@@ -17,7 +17,7 @@ export declare namespace MarketUtils {
|
|
|
17
17
|
*
|
|
18
18
|
* @param params.token - Collateral token address.
|
|
19
19
|
* @param params.lltv - WAD-scaled liquidation loan-to-value.
|
|
20
|
-
* @param params.
|
|
20
|
+
* @param params.liquidationCursor - WAD-scaled liquidation cursor.
|
|
21
21
|
* @param params.oracle - Oracle address used to price this collateral.
|
|
22
22
|
* @returns Collateral params with bigint fields.
|
|
23
23
|
* @example
|
|
@@ -27,10 +27,10 @@ export declare namespace MarketUtils {
|
|
|
27
27
|
* const collateral = MarketUtils.toCollateralParams({
|
|
28
28
|
* token: "0x0000000000000000000000000000000000000001",
|
|
29
29
|
* lltv: 770000000000000000n,
|
|
30
|
-
*
|
|
30
|
+
* liquidationCursor: 250000000000000000n,
|
|
31
31
|
* oracle: "0x0000000000000000000000000000000000000002",
|
|
32
32
|
* });
|
|
33
|
-
* console.log(collateral.
|
|
33
|
+
* console.log(collateral.liquidationCursor);
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
function toCollateralParams(params: CollateralParamsInput): CollateralParams;
|
|
@@ -44,12 +44,14 @@ export declare namespace MarketUtils {
|
|
|
44
44
|
* import { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
45
45
|
*
|
|
46
46
|
* const struct = MarketUtils.toStruct({
|
|
47
|
+
* chainId: 8453,
|
|
48
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
47
49
|
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
48
50
|
* collateralParams: [
|
|
49
51
|
* {
|
|
50
52
|
* token: "0x0000000000000000000000000000000000007000",
|
|
51
53
|
* lltv: 770000000000000000n,
|
|
52
|
-
*
|
|
54
|
+
* liquidationCursor: 250000000000000000n,
|
|
53
55
|
* oracle: "0x0000000000000000000000000000000000008000",
|
|
54
56
|
* },
|
|
55
57
|
* ],
|
|
@@ -62,19 +64,51 @@ export declare namespace MarketUtils {
|
|
|
62
64
|
* ```
|
|
63
65
|
*/
|
|
64
66
|
function toStruct(market: MarketInput): MarketParams;
|
|
67
|
+
/**
|
|
68
|
+
* Returns configured collateral by index.
|
|
69
|
+
*
|
|
70
|
+
* @param market - Market params or hydrated market.
|
|
71
|
+
* @param index - Collateral index to look up.
|
|
72
|
+
* @returns Collateral entry for the configured index.
|
|
73
|
+
* @throws {UnknownCollateralIndexError} when the index is not configured.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
77
|
+
*
|
|
78
|
+
* const collateral = MarketUtils.getCollateralByIndex({
|
|
79
|
+
* chainId: 8453,
|
|
80
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
81
|
+
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
82
|
+
* collateralParams: [
|
|
83
|
+
* {
|
|
84
|
+
* token: "0x0000000000000000000000000000000000000002",
|
|
85
|
+
* lltv: 770000000000000000n,
|
|
86
|
+
* liquidationCursor: 250000000000000000n,
|
|
87
|
+
* oracle: "0x0000000000000000000000000000000000000003",
|
|
88
|
+
* },
|
|
89
|
+
* ],
|
|
90
|
+
* maturity: 1n,
|
|
91
|
+
* rcfThreshold: 0n,
|
|
92
|
+
* enterGate: "0x0000000000000000000000000000000000000000",
|
|
93
|
+
* liquidatorGate: "0x0000000000000000000000000000000000000000",
|
|
94
|
+
* }, 0n);
|
|
95
|
+
* console.log(collateral.token);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
function getCollateralByIndex(market: MarketInput, index: BigIntish): CollateralParams;
|
|
65
99
|
/**
|
|
66
100
|
* Returns the liquidation incentive factor for an LLTV and liquidation cursor.
|
|
67
101
|
*
|
|
68
102
|
* @param input - WAD-scaled LLTV or collateral params carrying an LLTV.
|
|
69
|
-
* @param cursor - WAD-scaled liquidation cursor
|
|
103
|
+
* @param cursor - WAD-scaled liquidation cursor.
|
|
70
104
|
* @returns WAD-scaled liquidation incentive factor.
|
|
71
105
|
* @example
|
|
72
106
|
* ```ts
|
|
73
|
-
* import {
|
|
107
|
+
* import { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
74
108
|
*
|
|
75
109
|
* const liquidationIncentiveFactor = MarketUtils.getLiquidationIncentiveFactor(
|
|
76
110
|
* 770000000000000000n,
|
|
77
|
-
*
|
|
111
|
+
* 250000000000000000n,
|
|
78
112
|
* );
|
|
79
113
|
* console.log(liquidationIncentiveFactor);
|
|
80
114
|
* ```
|
|
@@ -121,12 +155,14 @@ export declare namespace MarketUtils {
|
|
|
121
155
|
* import { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
122
156
|
*
|
|
123
157
|
* const hash = MarketUtils.hash({
|
|
158
|
+
* chainId: 8453,
|
|
159
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
124
160
|
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
125
161
|
* collateralParams: [
|
|
126
162
|
* {
|
|
127
163
|
* token: "0x0000000000000000000000000000000000000002",
|
|
128
164
|
* lltv: 770000000000000000n,
|
|
129
|
-
*
|
|
165
|
+
* liquidationCursor: 250000000000000000n,
|
|
130
166
|
* oracle: "0x0000000000000000000000000000000000000003",
|
|
131
167
|
* },
|
|
132
168
|
* ],
|
|
@@ -142,48 +178,32 @@ export declare namespace MarketUtils {
|
|
|
142
178
|
/**
|
|
143
179
|
* Computes the Midnight id for a market using `IdLib.toId`.
|
|
144
180
|
*
|
|
145
|
-
* @param
|
|
146
|
-
* @param params.chainId - EIP-155 chain id used to resolve the core Midnight address from the registry.
|
|
181
|
+
* @param market - Market to hash.
|
|
147
182
|
* @returns Market id.
|
|
148
|
-
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
149
|
-
* @throws {UnknownAddressError} when the registry has no Midnight address for `chainId`.
|
|
150
183
|
* @example
|
|
151
184
|
* ```ts
|
|
152
|
-
* import { ChainId, registerCustomAddresses } from "@morpho-org/morpho-ts";
|
|
153
185
|
* import { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
154
186
|
*
|
|
155
|
-
* registerCustomAddresses({
|
|
156
|
-
* addresses: {
|
|
157
|
-
* [ChainId.BaseMainnet]: {
|
|
158
|
-
* midnight: "0x0000000000000000000000000000000000000001",
|
|
159
|
-
* },
|
|
160
|
-
* },
|
|
161
|
-
* });
|
|
162
|
-
*
|
|
163
187
|
* const id = MarketUtils.toId({
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* chainId: ChainId.BaseMainnet,
|
|
188
|
+
* chainId: 8453,
|
|
189
|
+
* midnight: "0x0000000000000000000000000000000000001000",
|
|
190
|
+
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
191
|
+
* collateralParams: [
|
|
192
|
+
* {
|
|
193
|
+
* token: "0x0000000000000000000000000000000000000002",
|
|
194
|
+
* lltv: 770000000000000000n,
|
|
195
|
+
* liquidationCursor: 250000000000000000n,
|
|
196
|
+
* oracle: "0x0000000000000000000000000000000000000003",
|
|
197
|
+
* },
|
|
198
|
+
* ],
|
|
199
|
+
* maturity: 1n,
|
|
200
|
+
* rcfThreshold: 0n,
|
|
201
|
+
* enterGate: "0x0000000000000000000000000000000000000000",
|
|
202
|
+
* liquidatorGate: "0x0000000000000000000000000000000000000000",
|
|
180
203
|
* });
|
|
181
204
|
* console.log(id);
|
|
182
205
|
* ```
|
|
183
206
|
*/
|
|
184
|
-
function toId(
|
|
185
|
-
readonly market: MarketInput;
|
|
186
|
-
readonly chainId: BigIntish;
|
|
187
|
-
}): `0x${string}`;
|
|
207
|
+
function toId(market: MarketInput): `0x${string}`;
|
|
188
208
|
}
|
|
189
209
|
export {};
|