@morpho-org/midnight-sdk 0.1.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/README.md +252 -0
- package/lib/cjs/abis.d.ts +3170 -0
- package/lib/cjs/abis.js +4073 -0
- package/lib/cjs/api/MidnightApi.d.ts +532 -0
- package/lib/cjs/api/MidnightApi.js +713 -0
- package/lib/cjs/api/helpers.d.ts +20 -0
- package/lib/cjs/api/helpers.js +189 -0
- package/lib/cjs/api/index.d.ts +2 -0
- package/lib/cjs/api/index.js +21 -0
- package/lib/cjs/api/types.d.ts +453 -0
- package/lib/cjs/api/types.js +2 -0
- package/lib/cjs/constants.d.ts +168 -0
- package/lib/cjs/constants.js +187 -0
- package/lib/cjs/errors.d.ts +253 -0
- package/lib/cjs/errors.js +309 -0
- package/lib/cjs/fetch/Market.d.ts +65 -0
- package/lib/cjs/fetch/Market.js +117 -0
- package/lib/cjs/fetch/Offer.d.ts +74 -0
- package/lib/cjs/fetch/Offer.js +119 -0
- package/lib/cjs/fetch/Position.d.ts +85 -0
- package/lib/cjs/fetch/Position.js +148 -0
- package/lib/cjs/fetch/Ratifier.d.ts +38 -0
- package/lib/cjs/fetch/Ratifier.js +57 -0
- package/lib/cjs/fetch/index.d.ts +5 -0
- package/lib/cjs/fetch/index.js +21 -0
- package/lib/cjs/fetch/types.d.ts +57 -0
- package/lib/cjs/fetch/types.js +2 -0
- package/lib/cjs/fetch/utils.d.ts +8 -0
- package/lib/cjs/fetch/utils.js +18 -0
- package/lib/cjs/index.d.ts +18 -0
- package/lib/cjs/index.js +57 -0
- package/lib/cjs/market/Market.d.ts +613 -0
- package/lib/cjs/market/Market.js +503 -0
- package/lib/cjs/market/MarketUtils.d.ts +189 -0
- package/lib/cjs/market/MarketUtils.js +303 -0
- package/lib/cjs/market/Position.d.ts +424 -0
- package/lib/cjs/market/Position.js +425 -0
- package/lib/cjs/market/PositionUtils.d.ts +115 -0
- package/lib/cjs/market/PositionUtils.js +194 -0
- package/lib/cjs/market/index.d.ts +4 -0
- package/lib/cjs/market/index.js +20 -0
- package/lib/cjs/math/ConsumableUnitsLib.d.ts +57 -0
- package/lib/cjs/math/ConsumableUnitsLib.js +77 -0
- package/lib/cjs/math/TakeAmountsLib.d.ts +175 -0
- package/lib/cjs/math/TakeAmountsLib.js +199 -0
- package/lib/cjs/math/TickLib.d.ts +200 -0
- package/lib/cjs/math/TickLib.js +272 -0
- package/lib/cjs/math/index.d.ts +3 -0
- package/lib/cjs/math/index.js +19 -0
- package/lib/cjs/offers/Offer.d.ts +534 -0
- package/lib/cjs/offers/Offer.js +343 -0
- package/lib/cjs/offers/OfferUtils.d.ts +565 -0
- package/lib/cjs/offers/OfferUtils.js +659 -0
- package/lib/cjs/offers/index.d.ts +2 -0
- package/lib/cjs/offers/index.js +18 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/queries/GetPosition.d.ts +55 -0
- package/lib/cjs/queries/GetPosition.js +74 -0
- package/lib/cjs/queries/index.d.ts +1 -0
- package/lib/cjs/queries/index.js +37 -0
- package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +733 -0
- package/lib/cjs/signatures/EcrecoverRatifierUtils.js +618 -0
- package/lib/cjs/signatures/Group.d.ts +178 -0
- package/lib/cjs/signatures/Group.js +193 -0
- package/lib/cjs/signatures/GroupUtils.d.ts +191 -0
- package/lib/cjs/signatures/GroupUtils.js +127 -0
- package/lib/cjs/signatures/Payload.d.ts +283 -0
- package/lib/cjs/signatures/Payload.js +570 -0
- package/lib/cjs/signatures/RatifierUtils.d.ts +109 -0
- package/lib/cjs/signatures/RatifierUtils.js +76 -0
- package/lib/cjs/signatures/SetterRatifierUtils.d.ts +243 -0
- package/lib/cjs/signatures/SetterRatifierUtils.js +217 -0
- package/lib/cjs/signatures/Tree.d.ts +241 -0
- package/lib/cjs/signatures/Tree.js +263 -0
- package/lib/cjs/signatures/TreeUtils.d.ts +573 -0
- package/lib/cjs/signatures/TreeUtils.js +461 -0
- package/lib/cjs/signatures/index.d.ts +7 -0
- package/lib/cjs/signatures/index.js +23 -0
- package/lib/esm/abis.d.ts +3170 -0
- package/lib/esm/abis.js +4070 -0
- package/lib/esm/api/MidnightApi.d.ts +532 -0
- package/lib/esm/api/MidnightApi.js +709 -0
- package/lib/esm/api/helpers.d.ts +20 -0
- package/lib/esm/api/helpers.js +180 -0
- package/lib/esm/api/index.d.ts +2 -0
- package/lib/esm/api/index.js +2 -0
- package/lib/esm/api/types.d.ts +453 -0
- package/lib/esm/api/types.js +1 -0
- package/lib/esm/constants.d.ts +168 -0
- package/lib/esm/constants.js +184 -0
- package/lib/esm/errors.d.ts +253 -0
- package/lib/esm/errors.js +291 -0
- package/lib/esm/fetch/Market.d.ts +65 -0
- package/lib/esm/fetch/Market.js +113 -0
- package/lib/esm/fetch/Offer.d.ts +74 -0
- package/lib/esm/fetch/Offer.js +116 -0
- package/lib/esm/fetch/Position.d.ts +85 -0
- package/lib/esm/fetch/Position.js +144 -0
- package/lib/esm/fetch/Ratifier.d.ts +38 -0
- package/lib/esm/fetch/Ratifier.js +54 -0
- package/lib/esm/fetch/index.d.ts +5 -0
- package/lib/esm/fetch/index.js +5 -0
- package/lib/esm/fetch/types.d.ts +57 -0
- package/lib/esm/fetch/types.js +1 -0
- package/lib/esm/fetch/utils.d.ts +8 -0
- package/lib/esm/fetch/utils.js +12 -0
- package/lib/esm/index.d.ts +18 -0
- package/lib/esm/index.js +18 -0
- package/lib/esm/market/Market.d.ts +613 -0
- package/lib/esm/market/Market.js +498 -0
- package/lib/esm/market/MarketUtils.d.ts +189 -0
- package/lib/esm/market/MarketUtils.js +300 -0
- package/lib/esm/market/Position.d.ts +424 -0
- package/lib/esm/market/Position.js +420 -0
- package/lib/esm/market/PositionUtils.d.ts +115 -0
- package/lib/esm/market/PositionUtils.js +191 -0
- package/lib/esm/market/index.d.ts +4 -0
- package/lib/esm/market/index.js +4 -0
- package/lib/esm/math/ConsumableUnitsLib.d.ts +57 -0
- package/lib/esm/math/ConsumableUnitsLib.js +74 -0
- package/lib/esm/math/TakeAmountsLib.d.ts +175 -0
- package/lib/esm/math/TakeAmountsLib.js +196 -0
- package/lib/esm/math/TickLib.d.ts +200 -0
- package/lib/esm/math/TickLib.js +269 -0
- package/lib/esm/math/index.d.ts +3 -0
- package/lib/esm/math/index.js +3 -0
- package/lib/esm/offers/Offer.d.ts +534 -0
- package/lib/esm/offers/Offer.js +339 -0
- package/lib/esm/offers/OfferUtils.d.ts +565 -0
- package/lib/esm/offers/OfferUtils.js +656 -0
- package/lib/esm/offers/index.d.ts +2 -0
- package/lib/esm/offers/index.js +2 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/queries/GetPosition.d.ts +55 -0
- package/lib/esm/queries/GetPosition.js +71 -0
- package/lib/esm/queries/index.d.ts +1 -0
- package/lib/esm/queries/index.js +1 -0
- package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +733 -0
- package/lib/esm/signatures/EcrecoverRatifierUtils.js +615 -0
- package/lib/esm/signatures/Group.d.ts +178 -0
- package/lib/esm/signatures/Group.js +189 -0
- package/lib/esm/signatures/GroupUtils.d.ts +191 -0
- package/lib/esm/signatures/GroupUtils.js +124 -0
- package/lib/esm/signatures/Payload.d.ts +283 -0
- package/lib/esm/signatures/Payload.js +564 -0
- package/lib/esm/signatures/RatifierUtils.d.ts +109 -0
- package/lib/esm/signatures/RatifierUtils.js +73 -0
- package/lib/esm/signatures/SetterRatifierUtils.d.ts +243 -0
- package/lib/esm/signatures/SetterRatifierUtils.js +214 -0
- package/lib/esm/signatures/Tree.d.ts +241 -0
- package/lib/esm/signatures/Tree.js +259 -0
- package/lib/esm/signatures/TreeUtils.d.ts +573 -0
- package/lib/esm/signatures/TreeUtils.js +458 -0
- package/lib/esm/signatures/index.d.ts +7 -0
- package/lib/esm/signatures/index.js +7 -0
- package/package.json +69 -0
- package/src/index.ts +19 -0
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import { encode as encodePayload } from "../signatures/Payload.js";
|
|
2
|
+
import { buildBookPath, mapBookMarket, mapPriceLevel, mapTakeableOffer, parseValidationResponse, requestMidnightApi, } from "./helpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Midnight API client and stateless helper surface for books and mempool data.
|
|
5
|
+
*
|
|
6
|
+
* Static methods use `https://api.morpho.org/v1/midnight` by default and accept
|
|
7
|
+
* per-call configuration. Instances keep shared `baseUrl`, `fetch`, and request
|
|
8
|
+
* options for integrations that make repeated calls.
|
|
9
|
+
* Caller input and successful JSON output shapes are trusted at runtime;
|
|
10
|
+
* returned TypeScript types model the API contract.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
15
|
+
*
|
|
16
|
+
* const direct = await MidnightApi.validateMempoolPayload({
|
|
17
|
+
* chainId: 8453,
|
|
18
|
+
* payload: "0x0100000000",
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const api = new MidnightApi("https://api.morpho.org/v1/midnight");
|
|
22
|
+
* const configured = await api.validateMempoolPayload({
|
|
23
|
+
* chainId: 8453,
|
|
24
|
+
* payload: "0x0100000000",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* console.log(direct.valid && configured.valid);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class MidnightApi {
|
|
31
|
+
config;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a Midnight API client with shared request configuration.
|
|
34
|
+
*
|
|
35
|
+
* @param config - API base URL or full request configuration.
|
|
36
|
+
* @param config.baseUrl - Optional Midnight API base URL.
|
|
37
|
+
* @param config.fetch - Optional fetch implementation used for all instance calls.
|
|
38
|
+
* @param config.request - Optional fetch options forwarded to all instance calls.
|
|
39
|
+
* @returns Configured Midnight API client.
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
43
|
+
*
|
|
44
|
+
* const api = new MidnightApi({
|
|
45
|
+
* baseUrl: "https://api.morpho.org/v1/midnight",
|
|
46
|
+
* });
|
|
47
|
+
* console.log(api);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
constructor(config = {}) {
|
|
51
|
+
this.config =
|
|
52
|
+
typeof config === "string" || config instanceof URL
|
|
53
|
+
? { baseUrl: config }
|
|
54
|
+
: { ...config };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetches active Midnight books with market metadata and top price levels.
|
|
58
|
+
*
|
|
59
|
+
* Reads `GET /books` from the Midnight API. Does not read onchain RPC state.
|
|
60
|
+
*
|
|
61
|
+
* @param params.sort - Optional book sort terms.
|
|
62
|
+
* @param params.maturities - Optional exact maturity timestamp filters in unix seconds.
|
|
63
|
+
* @param params.collateralTokens - Optional collateral token address filters.
|
|
64
|
+
* @param params.loanTokens - Optional loan token address filters.
|
|
65
|
+
* @param params.chainIds - Optional chain id filters.
|
|
66
|
+
* @param params.marketIds - Optional market id filters.
|
|
67
|
+
* @param params.limit - Optional maximum number of books to return.
|
|
68
|
+
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
69
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
70
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
71
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
72
|
+
* @returns Paginated books mapped to SDK camelCase fields.
|
|
73
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
74
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
78
|
+
*
|
|
79
|
+
* const books = await MidnightApi.fetchBooks({
|
|
80
|
+
* chainIds: [8453],
|
|
81
|
+
* limit: 10,
|
|
82
|
+
* });
|
|
83
|
+
* console.log(books.data.length);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
static async fetchBooks(params = {}) {
|
|
87
|
+
const input = params;
|
|
88
|
+
const response = await requestMidnightApi({
|
|
89
|
+
...input,
|
|
90
|
+
method: "GET",
|
|
91
|
+
path: "books",
|
|
92
|
+
query: {
|
|
93
|
+
sort: input.sort,
|
|
94
|
+
maturities: input.maturities,
|
|
95
|
+
collateral_tokens: input.collateralTokens,
|
|
96
|
+
loan_tokens: input.loanTokens,
|
|
97
|
+
chain_ids: input.chainIds,
|
|
98
|
+
ids: input.marketIds,
|
|
99
|
+
limit: input.limit,
|
|
100
|
+
cursor: input.cursor,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
cursor: response.cursor,
|
|
105
|
+
data: response.data.map(mapBookMarket),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Fetches one Midnight book with market metadata and both sides.
|
|
110
|
+
*
|
|
111
|
+
* Reads `GET /books/{marketId}` from the Midnight API. Does not read onchain RPC state.
|
|
112
|
+
*
|
|
113
|
+
* @param params.marketId - Market id whose book to read.
|
|
114
|
+
* @param params.depth - Optional maximum levels returned per side.
|
|
115
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
116
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
117
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
118
|
+
* @returns Book snapshot mapped to SDK camelCase fields.
|
|
119
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
120
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
124
|
+
*
|
|
125
|
+
* const book = await MidnightApi.fetchBook({
|
|
126
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
127
|
+
* });
|
|
128
|
+
* console.log(book.data.marketId);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
static async fetchBook(params) {
|
|
132
|
+
const input = params;
|
|
133
|
+
const response = await requestMidnightApi({
|
|
134
|
+
...input,
|
|
135
|
+
method: "GET",
|
|
136
|
+
path: buildBookPath({ marketId: input.marketId }),
|
|
137
|
+
query: {
|
|
138
|
+
depth: input.depth,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
data: mapBookMarket(response.data),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Fetches one side of a Midnight book grouped by price level.
|
|
147
|
+
*
|
|
148
|
+
* Reads `GET /books/{marketId}/{side}` from the Midnight API. Does not read onchain RPC state.
|
|
149
|
+
*
|
|
150
|
+
* @param params.marketId - Market id whose book side to read.
|
|
151
|
+
* @param params.side - Book side to query.
|
|
152
|
+
* @param params.depth - Optional maximum levels returned.
|
|
153
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
154
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
155
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
156
|
+
* @returns Price levels mapped to SDK camelCase fields.
|
|
157
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
158
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
162
|
+
*
|
|
163
|
+
* const levels = await MidnightApi.fetchBookPriceLevels({
|
|
164
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
165
|
+
* side: "asks",
|
|
166
|
+
* });
|
|
167
|
+
* console.log(levels.data.length);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
static async fetchBookPriceLevels(params) {
|
|
171
|
+
const input = params;
|
|
172
|
+
const response = await requestMidnightApi({
|
|
173
|
+
...input,
|
|
174
|
+
method: "GET",
|
|
175
|
+
path: buildBookPath({ marketId: input.marketId, side: input.side }),
|
|
176
|
+
query: {
|
|
177
|
+
depth: input.depth,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
data: response.data.map(mapPriceLevel),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Fetches executable offers for one side of a Midnight book.
|
|
186
|
+
*
|
|
187
|
+
* Reads `GET /books/{marketId}/{side}/takeable-offers` from the Midnight API. Does not read onchain RPC state.
|
|
188
|
+
*
|
|
189
|
+
* @param params.marketId - Market id whose book side to read.
|
|
190
|
+
* @param params.side - Book side to query.
|
|
191
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
192
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
193
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
194
|
+
* @returns ABI-ready take objects mapped from the API response.
|
|
195
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
196
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
200
|
+
*
|
|
201
|
+
* const offers = await MidnightApi.fetchBookTakeableOffers({
|
|
202
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
203
|
+
* side: "bids",
|
|
204
|
+
* });
|
|
205
|
+
* console.log(offers.data.length);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
static async fetchBookTakeableOffers(params) {
|
|
209
|
+
const input = params;
|
|
210
|
+
const response = await requestMidnightApi({
|
|
211
|
+
...input,
|
|
212
|
+
method: "GET",
|
|
213
|
+
path: buildBookPath({
|
|
214
|
+
marketId: input.marketId,
|
|
215
|
+
side: input.side,
|
|
216
|
+
suffix: "takeable-offers",
|
|
217
|
+
}),
|
|
218
|
+
});
|
|
219
|
+
return {
|
|
220
|
+
data: response.data.map(mapTakeableOffer),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Fetches a bundle-ready quote for one side of a Midnight book.
|
|
225
|
+
*
|
|
226
|
+
* Reads `GET /books/{marketId}/{side}/quote` from the Midnight API. Does not read onchain RPC state.
|
|
227
|
+
*
|
|
228
|
+
* @param params.marketId - Market id whose book side to quote.
|
|
229
|
+
* @param params.side - Book side to quote.
|
|
230
|
+
* @param params.assets - Optional maker-side target assets amount. Mutually exclusive with `params.units`.
|
|
231
|
+
* @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
|
|
232
|
+
* @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
|
|
233
|
+
* @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
|
|
234
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
235
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
236
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
237
|
+
* @returns Quote and signed ABI-ready take caps mapped from the API response.
|
|
238
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
239
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
243
|
+
*
|
|
244
|
+
* const quote = await MidnightApi.fetchBookQuote({
|
|
245
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
246
|
+
* side: "asks",
|
|
247
|
+
* assets: 1000000000000000000n,
|
|
248
|
+
* slippage: "0.5",
|
|
249
|
+
* });
|
|
250
|
+
* console.log(quote.data.averageBestPrice);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
static async fetchBookQuote(params) {
|
|
254
|
+
const input = params;
|
|
255
|
+
const response = await requestMidnightApi({
|
|
256
|
+
...input,
|
|
257
|
+
method: "GET",
|
|
258
|
+
path: buildBookPath({
|
|
259
|
+
marketId: input.marketId,
|
|
260
|
+
side: input.side,
|
|
261
|
+
suffix: "quote",
|
|
262
|
+
}),
|
|
263
|
+
query: {
|
|
264
|
+
average_worst_price: input.averageWorstPrice,
|
|
265
|
+
slippage: input.slippage,
|
|
266
|
+
units: input.units,
|
|
267
|
+
assets: input.assets,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
const takeableOffers = response.data.takeable_offers.map(mapTakeableOffer);
|
|
271
|
+
return {
|
|
272
|
+
data: {
|
|
273
|
+
averageBestPrice: response.data.average_best_price,
|
|
274
|
+
averageWorstPrice: response.data.average_worst_price,
|
|
275
|
+
availableAssets: response.data.available_assets,
|
|
276
|
+
availableUnits: response.data.available_units,
|
|
277
|
+
takeableOffers,
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Fetches one maker's unexpired, unmatured takeable offers.
|
|
283
|
+
*
|
|
284
|
+
* Reads `GET /takeable-offers` from the Midnight API. Does not read onchain RPC state.
|
|
285
|
+
*
|
|
286
|
+
* @param params.maker - Maker EVM address.
|
|
287
|
+
* @param params.marketIds - Optional market id filters.
|
|
288
|
+
* @param params.groups - Optional group id filters.
|
|
289
|
+
* @param params.limit - Optional maximum number of offers to return.
|
|
290
|
+
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
291
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
292
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
293
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
294
|
+
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
295
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
296
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
300
|
+
*
|
|
301
|
+
* const offers = await MidnightApi.fetchTakeableOffers({
|
|
302
|
+
* maker: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
|
|
303
|
+
* });
|
|
304
|
+
* console.log(offers.data.length);
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
static async fetchTakeableOffers(params) {
|
|
308
|
+
const input = params;
|
|
309
|
+
const response = await requestMidnightApi({
|
|
310
|
+
...input,
|
|
311
|
+
method: "GET",
|
|
312
|
+
path: "takeable-offers",
|
|
313
|
+
query: {
|
|
314
|
+
maker: input.maker,
|
|
315
|
+
market_ids: input.marketIds,
|
|
316
|
+
groups: input.groups,
|
|
317
|
+
limit: input.limit,
|
|
318
|
+
cursor: input.cursor,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
cursor: response.cursor,
|
|
323
|
+
data: response.data.map(mapTakeableOffer),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Validates an encoded Midnight mempool payload against API policy.
|
|
328
|
+
*
|
|
329
|
+
* Use when an integration already has encoded payload bytes and wants API
|
|
330
|
+
* feedback before publishing those bytes onchain. Normal SDK maker flows
|
|
331
|
+
* should call `Tree.mempoolValidate` before ratification instead of
|
|
332
|
+
* validating again after `Payload.encode`.
|
|
333
|
+
*
|
|
334
|
+
* Sends `POST /mempool/validate` to the Midnight API. Does not read onchain RPC state.
|
|
335
|
+
*
|
|
336
|
+
* @param params.chainId - Chain id whose API policy should validate the payload.
|
|
337
|
+
* @param params.payload - Encoded Midnight mempool payload bytes.
|
|
338
|
+
* @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
339
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
340
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
341
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
342
|
+
* @returns API issues and `valid` summary.
|
|
343
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
344
|
+
* @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
348
|
+
*
|
|
349
|
+
* const validation = await MidnightApi.validateMempoolPayload({
|
|
350
|
+
* chainId: 8453,
|
|
351
|
+
* payload: "0x0100000000",
|
|
352
|
+
* });
|
|
353
|
+
* console.log(validation.valid);
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
static async validateMempoolPayload(params) {
|
|
357
|
+
const input = params;
|
|
358
|
+
const response = await requestMidnightApi({
|
|
359
|
+
...input,
|
|
360
|
+
method: "POST",
|
|
361
|
+
path: "mempool/validate",
|
|
362
|
+
query: {
|
|
363
|
+
timestamp: input.timestamp,
|
|
364
|
+
},
|
|
365
|
+
body: {
|
|
366
|
+
chain_id: input.chainId,
|
|
367
|
+
payload: input.payload,
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
return parseValidationResponse(response);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Encodes SDK-native payload items and validates them against API policy.
|
|
374
|
+
*
|
|
375
|
+
* Use when an integration already has payload-ready items but not encoded
|
|
376
|
+
* payload bytes. Normal SDK maker flows should call `Tree.mempoolValidate`
|
|
377
|
+
* before ratification. This helper owns the temporary payload encoding for
|
|
378
|
+
* validation only.
|
|
379
|
+
*
|
|
380
|
+
* Encodes `params.items`, then sends `POST /mempool/validate` to the Midnight API. Does not read onchain RPC state.
|
|
381
|
+
*
|
|
382
|
+
* @param params.chainId - Chain id whose API policy should validate the payload.
|
|
383
|
+
* @param params.items - SDK-native payload items to encode before API validation.
|
|
384
|
+
* @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
385
|
+
* @param params.baseUrl - Optional Midnight API base URL override.
|
|
386
|
+
* @param params.fetch - Optional fetch implementation override.
|
|
387
|
+
* @param params.request - Optional fetch options forwarded to this request.
|
|
388
|
+
* @returns API issues and `valid` summary.
|
|
389
|
+
* @throws {Payload.DecodeError} when item encoding fails.
|
|
390
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
391
|
+
* @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
395
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
396
|
+
* import { zeroAddress } from "viem";
|
|
397
|
+
*
|
|
398
|
+
* const offer = Offer.create({
|
|
399
|
+
* market: {
|
|
400
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
401
|
+
* collateralParams: [
|
|
402
|
+
* {
|
|
403
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
404
|
+
* lltv: 770000000000000000n,
|
|
405
|
+
* maxLif: 1061007957559681697n,
|
|
406
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
407
|
+
* },
|
|
408
|
+
* ],
|
|
409
|
+
* maturity: 54_000n,
|
|
410
|
+
* rcfThreshold: 0n,
|
|
411
|
+
* enterGate: zeroAddress,
|
|
412
|
+
* liquidatorGate: zeroAddress,
|
|
413
|
+
* },
|
|
414
|
+
* buy: true,
|
|
415
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
416
|
+
* tick: 5_000n,
|
|
417
|
+
* expiry: 3_600n,
|
|
418
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
419
|
+
* maxUnits: 100n,
|
|
420
|
+
* });
|
|
421
|
+
*
|
|
422
|
+
* const validation = await MidnightApi.validateMempoolItems({
|
|
423
|
+
* chainId: 8453,
|
|
424
|
+
* items: [{ offer, ratifierData: "0x" }],
|
|
425
|
+
* });
|
|
426
|
+
* console.log(validation.valid);
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
static async validateMempoolItems(params) {
|
|
430
|
+
const input = params;
|
|
431
|
+
const payload = await encodePayload(input.items);
|
|
432
|
+
return MidnightApi.validateMempoolPayload({
|
|
433
|
+
baseUrl: input.baseUrl,
|
|
434
|
+
fetch: input.fetch,
|
|
435
|
+
request: input.request,
|
|
436
|
+
chainId: input.chainId,
|
|
437
|
+
timestamp: input.timestamp,
|
|
438
|
+
payload,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Fetches active Midnight books with this client's configuration.
|
|
443
|
+
*
|
|
444
|
+
* Reads `GET /books` from the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
445
|
+
*
|
|
446
|
+
* @param params.sort - Optional book sort terms.
|
|
447
|
+
* @param params.maturities - Optional exact maturity timestamp filters in unix seconds.
|
|
448
|
+
* @param params.collateralTokens - Optional collateral token address filters.
|
|
449
|
+
* @param params.loanTokens - Optional loan token address filters.
|
|
450
|
+
* @param params.chainIds - Optional chain id filters.
|
|
451
|
+
* @param params.marketIds - Optional market id filters.
|
|
452
|
+
* @param params.limit - Optional maximum number of books to return.
|
|
453
|
+
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
454
|
+
* @returns Paginated books mapped to SDK camelCase fields.
|
|
455
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
456
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
460
|
+
*
|
|
461
|
+
* const api = new MidnightApi();
|
|
462
|
+
* const books = await api.fetchBooks({ chainIds: [8453], limit: 10 });
|
|
463
|
+
* console.log(books.data.length);
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
fetchBooks(params = {}) {
|
|
467
|
+
return MidnightApi.fetchBooks({
|
|
468
|
+
...this.config,
|
|
469
|
+
...params,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Fetches one Midnight book with this client's configuration.
|
|
474
|
+
*
|
|
475
|
+
* Reads `GET /books/{marketId}` from the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
476
|
+
*
|
|
477
|
+
* @param params.marketId - Market id whose book to read.
|
|
478
|
+
* @param params.depth - Optional maximum levels returned per side.
|
|
479
|
+
* @returns Book snapshot mapped to SDK camelCase fields.
|
|
480
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
481
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
482
|
+
* @example
|
|
483
|
+
* ```ts
|
|
484
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
485
|
+
*
|
|
486
|
+
* const api = new MidnightApi();
|
|
487
|
+
* const book = await api.fetchBook({
|
|
488
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
489
|
+
* });
|
|
490
|
+
* console.log(book.data.marketId);
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
fetchBook(params) {
|
|
494
|
+
return MidnightApi.fetchBook({
|
|
495
|
+
...this.config,
|
|
496
|
+
...params,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Fetches one side of a Midnight book with this client's configuration.
|
|
501
|
+
*
|
|
502
|
+
* Reads `GET /books/{marketId}/{side}` from the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
503
|
+
*
|
|
504
|
+
* @param params.marketId - Market id whose book side to read.
|
|
505
|
+
* @param params.side - Book side to query.
|
|
506
|
+
* @param params.depth - Optional maximum levels returned.
|
|
507
|
+
* @returns Price levels mapped to SDK camelCase fields.
|
|
508
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
509
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
513
|
+
*
|
|
514
|
+
* const api = new MidnightApi();
|
|
515
|
+
* const levels = await api.fetchBookPriceLevels({
|
|
516
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
517
|
+
* side: "asks",
|
|
518
|
+
* });
|
|
519
|
+
* console.log(levels.data.length);
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
fetchBookPriceLevels(params) {
|
|
523
|
+
return MidnightApi.fetchBookPriceLevels({
|
|
524
|
+
...this.config,
|
|
525
|
+
...params,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Fetches executable offers for one book side with this client's configuration.
|
|
530
|
+
*
|
|
531
|
+
* Reads `GET /books/{marketId}/{side}/takeable-offers` from the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
532
|
+
*
|
|
533
|
+
* @param params.marketId - Market id whose book side to read.
|
|
534
|
+
* @param params.side - Book side to query.
|
|
535
|
+
* @returns ABI-ready take objects mapped from the API response.
|
|
536
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
537
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
538
|
+
* @example
|
|
539
|
+
* ```ts
|
|
540
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
541
|
+
*
|
|
542
|
+
* const api = new MidnightApi();
|
|
543
|
+
* const offers = await api.fetchBookTakeableOffers({
|
|
544
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
545
|
+
* side: "bids",
|
|
546
|
+
* });
|
|
547
|
+
* console.log(offers.data.length);
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
fetchBookTakeableOffers(params) {
|
|
551
|
+
return MidnightApi.fetchBookTakeableOffers({
|
|
552
|
+
...this.config,
|
|
553
|
+
...params,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Fetches a bundle-ready quote with this client's configuration.
|
|
558
|
+
*
|
|
559
|
+
* Reads `GET /books/{marketId}/{side}/quote` from the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
560
|
+
*
|
|
561
|
+
* @param params.marketId - Market id whose book side to quote.
|
|
562
|
+
* @param params.side - Book side to quote.
|
|
563
|
+
* @param params.assets - Optional maker-side target assets amount. Mutually exclusive with `params.units`.
|
|
564
|
+
* @param params.units - Optional target unit amount. Mutually exclusive with `params.assets`.
|
|
565
|
+
* @param params.averageWorstPrice - Optional WAD-scaled average worst price guard. Mutually exclusive with `params.slippage`.
|
|
566
|
+
* @param params.slippage - Optional slippage percentage used to derive the guard. Mutually exclusive with `params.averageWorstPrice`.
|
|
567
|
+
* @returns Quote and signed ABI-ready take caps mapped from the API response.
|
|
568
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
569
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
573
|
+
*
|
|
574
|
+
* const api = new MidnightApi();
|
|
575
|
+
* const quote = await api.fetchBookQuote({
|
|
576
|
+
* marketId: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
577
|
+
* side: "asks",
|
|
578
|
+
* units: "1000000000000000000",
|
|
579
|
+
* });
|
|
580
|
+
* console.log(quote.data.takeableOffers.length);
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
fetchBookQuote(params) {
|
|
584
|
+
return MidnightApi.fetchBookQuote({
|
|
585
|
+
...this.config,
|
|
586
|
+
...params,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Fetches one maker's takeable offers with this client's configuration.
|
|
591
|
+
*
|
|
592
|
+
* Reads `GET /takeable-offers` from the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
593
|
+
*
|
|
594
|
+
* @param params.maker - Maker EVM address.
|
|
595
|
+
* @param params.marketIds - Optional market id filters.
|
|
596
|
+
* @param params.groups - Optional group id filters.
|
|
597
|
+
* @param params.limit - Optional maximum number of offers to return.
|
|
598
|
+
* @param params.cursor - Optional opaque pagination cursor from a previous response.
|
|
599
|
+
* @returns Paginated ABI-ready take objects mapped from the API response.
|
|
600
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
601
|
+
* @throws {InvalidMidnightApiResponseError} when the API success response is not JSON.
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
605
|
+
*
|
|
606
|
+
* const api = new MidnightApi();
|
|
607
|
+
* const offers = await api.fetchTakeableOffers({
|
|
608
|
+
* maker: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
|
|
609
|
+
* });
|
|
610
|
+
* console.log(offers.data.length);
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
fetchTakeableOffers(params) {
|
|
614
|
+
return MidnightApi.fetchTakeableOffers({
|
|
615
|
+
...this.config,
|
|
616
|
+
...params,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Validates an encoded Midnight mempool payload with this client's configuration.
|
|
621
|
+
*
|
|
622
|
+
* Use when an integration already has encoded payload bytes and wants API
|
|
623
|
+
* feedback before publishing those bytes onchain. Normal SDK maker flows
|
|
624
|
+
* should call `Tree.mempoolValidate` before ratification instead of
|
|
625
|
+
* validating again after `Payload.encode`.
|
|
626
|
+
*
|
|
627
|
+
* Sends `POST /mempool/validate` to the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
628
|
+
*
|
|
629
|
+
* @param params.chainId - Chain id whose API policy should validate the payload.
|
|
630
|
+
* @param params.payload - Encoded Midnight mempool payload bytes.
|
|
631
|
+
* @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
632
|
+
* @returns API validation result.
|
|
633
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
634
|
+
* @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
|
|
635
|
+
* @example
|
|
636
|
+
* ```ts
|
|
637
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
638
|
+
*
|
|
639
|
+
* const api = new MidnightApi();
|
|
640
|
+
* const validation = await api.validateMempoolPayload({ chainId: 8453, payload: "0x0100000000" });
|
|
641
|
+
* console.log(validation.valid);
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
validateMempoolPayload(params) {
|
|
645
|
+
return MidnightApi.validateMempoolPayload({
|
|
646
|
+
...this.config,
|
|
647
|
+
...params,
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Validates payload-ready items with this client's configuration.
|
|
652
|
+
*
|
|
653
|
+
* Use when an integration already has payload-ready items but not encoded
|
|
654
|
+
* payload bytes. Normal SDK maker flows should call `Tree.mempoolValidate`
|
|
655
|
+
* before ratification.
|
|
656
|
+
*
|
|
657
|
+
* Encodes `params.items`, then sends `POST /mempool/validate` to the Midnight API using this client's configuration. Does not read onchain RPC state.
|
|
658
|
+
*
|
|
659
|
+
* @param params.chainId - Chain id whose API policy should validate the payload.
|
|
660
|
+
* @param params.items - SDK-native payload items to encode before API validation.
|
|
661
|
+
* @param params.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
662
|
+
* @returns API validation result.
|
|
663
|
+
* @throws {Payload.DecodeError} when item encoding fails.
|
|
664
|
+
* @throws {MidnightApiError} when the API returns a non-2xx response.
|
|
665
|
+
* @throws {InvalidMidnightApiResponseError} when the API returns malformed success JSON.
|
|
666
|
+
* @example
|
|
667
|
+
* ```ts
|
|
668
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
669
|
+
* import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
670
|
+
* import { zeroAddress } from "viem";
|
|
671
|
+
*
|
|
672
|
+
* const api = new MidnightApi();
|
|
673
|
+
* const offer = Offer.create({
|
|
674
|
+
* market: {
|
|
675
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
676
|
+
* collateralParams: [
|
|
677
|
+
* {
|
|
678
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
679
|
+
* lltv: 770000000000000000n,
|
|
680
|
+
* maxLif: 1061007957559681697n,
|
|
681
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
682
|
+
* },
|
|
683
|
+
* ],
|
|
684
|
+
* maturity: 54_000n,
|
|
685
|
+
* rcfThreshold: 0n,
|
|
686
|
+
* enterGate: zeroAddress,
|
|
687
|
+
* liquidatorGate: zeroAddress,
|
|
688
|
+
* },
|
|
689
|
+
* buy: true,
|
|
690
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
691
|
+
* tick: 5_000n,
|
|
692
|
+
* expiry: 3_600n,
|
|
693
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
694
|
+
* maxUnits: 100n,
|
|
695
|
+
* });
|
|
696
|
+
* const validation = await api.validateMempoolItems({
|
|
697
|
+
* chainId: 8453,
|
|
698
|
+
* items: [{ offer, ratifierData: "0x" }],
|
|
699
|
+
* });
|
|
700
|
+
* console.log(validation.valid);
|
|
701
|
+
* ```
|
|
702
|
+
*/
|
|
703
|
+
validateMempoolItems(params) {
|
|
704
|
+
return MidnightApi.validateMempoolItems({
|
|
705
|
+
...this.config,
|
|
706
|
+
...params,
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|