@morpho-org/midnight-sdk 1.8.0 → 2.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.
@@ -1,5 +1,5 @@
1
1
  import { type Address, type Hash } from "viem";
2
- import { type ApiBookMarketResponse, type ApiCollateralResponse, type ApiPriceLevelResponse, type ApiRequestParams, type ApiTakeableOfferResponse, type MempoolPayloadValidationResult, type MidnightApiBookMarket, type MidnightApiBookSide, type MidnightApiCollateral, type MidnightApiPriceLevel, type MidnightApiTake } from "./types.js";
2
+ import { type ApiBookMarketResponse, type ApiPriceLevelResponse, type ApiRequestParams, type ApiTakeableOfferResponse, type MempoolPayloadValidationResult, type MidnightApiBookMarket, type MidnightApiBookSide, type MidnightApiPriceLevel, type MidnightApiTake } from "./types.js";
3
3
  /** @internal Sends one Midnight API request and maps non-2xx responses to SDK errors. */
4
4
  export declare function requestMidnightApi<Response = unknown>(params: ApiRequestParams): Promise<Response>;
5
5
  /** @internal Builds a book endpoint path with encoded path segments. */
@@ -8,16 +8,6 @@ export declare function buildBookPath(params: {
8
8
  readonly side?: MidnightApiBookSide;
9
9
  readonly suffix?: "quote" | "takeable-offers";
10
10
  }): string;
11
- /**
12
- * @internal Maps a book market API payload to the SDK response shape, rejecting any
13
- * response whose advertised `market_id` cannot be derived from — or does not match —
14
- * its own market params. Recomputing the id with `MarketUtils.toId` (mirroring the
15
- * takeable-offers path) stops a hostile API from pairing a trusted id with foreign
16
- * metadata; every book flows through here, so both bound paths reject the same substitution.
17
- * Collaterals are returned in the protocol's canonical order so their array index matches
18
- * the onchain `collateralIndex`.
19
- */
20
- export declare function mapBookMarket(book: ApiBookMarketResponse): MidnightApiBookMarket;
21
11
  /** @internal Maps a book market, binding its verified id to the requested market. */
22
12
  export declare function mapBoundBookMarket(book: ApiBookMarketResponse, requestedMarketId: Hash): MidnightApiBookMarket;
23
13
  /** @internal Requested `fetchBooks` filters that every returned book must satisfy. */
@@ -30,14 +20,8 @@ export interface BookFilterContext {
30
20
  }
31
21
  /** @internal Maps listed book markets, binding each verified id to requested filters when present. */
32
22
  export declare function mapBoundBooks(books: readonly ApiBookMarketResponse[], context?: BookFilterContext): MidnightApiBookMarket[];
33
- /** @internal Maps a collateral API payload to the SDK response shape. */
34
- export declare function mapCollateral(collateral: ApiCollateralResponse): MidnightApiCollateral;
35
- /** @internal Maps a price-level API payload to the SDK response shape. */
36
- export declare function mapPriceLevel(level: ApiPriceLevelResponse): MidnightApiPriceLevel;
37
23
  /** @internal Maps API price levels and sorts them best first: asks by ascending tick, bids by descending tick. */
38
24
  export declare function mapPriceLevels(levels: readonly ApiPriceLevelResponse[], side: MidnightApiBookSide): MidnightApiPriceLevel[];
39
- /** @internal Maps a takeable-offer API payload to the SDK response shape. */
40
- export declare function mapTakeableOffer(takeableOffer: ApiTakeableOfferResponse): MidnightApiTake;
41
25
  /** @internal API response context required for a takeable offer to be executable for the caller's request. */
42
26
  export interface TakeableOfferContext {
43
27
  readonly marketId?: Hash;
@@ -90,7 +90,7 @@ export function buildBookPath(params) {
90
90
  * Collaterals are returned in the protocol's canonical order so their array index matches
91
91
  * the onchain `collateralIndex`.
92
92
  */
93
- export function mapBookMarket(book) {
93
+ function mapBookMarket(book) {
94
94
  let derivedMarketId;
95
95
  let matchesAdvertisedId;
96
96
  try {
@@ -177,7 +177,7 @@ export function mapBoundBooks(books, context = {}) {
177
177
  });
178
178
  }
179
179
  /** @internal Maps a collateral API payload to the SDK response shape. */
180
- export function mapCollateral(collateral) {
180
+ function mapCollateral(collateral) {
181
181
  return {
182
182
  token: collateral.token,
183
183
  lltv: collateral.lltv,
@@ -186,7 +186,7 @@ export function mapCollateral(collateral) {
186
186
  };
187
187
  }
188
188
  /** @internal Maps a price-level API payload to the SDK response shape. */
189
- export function mapPriceLevel(level) {
189
+ function mapPriceLevel(level) {
190
190
  return {
191
191
  tick: level.tick,
192
192
  price: level.price,
@@ -202,7 +202,7 @@ export function mapPriceLevels(levels, side) {
202
202
  .sort((a, b) => (side === "asks" ? a.tick - b.tick : b.tick - a.tick));
203
203
  }
204
204
  /** @internal Maps a takeable-offer API payload to the SDK response shape. */
205
- export function mapTakeableOffer(takeableOffer) {
205
+ function mapTakeableOffer(takeableOffer) {
206
206
  const offer = takeableOffer.offer;
207
207
  return {
208
208
  marketId: takeableOffer.market_id,
@@ -440,9 +440,9 @@ export interface MidnightApiTakeableOffersResult {
440
440
  readonly data: readonly MidnightApiTake[];
441
441
  }
442
442
  /** @internal HTTP method owned by Midnight API helpers. */
443
- export type ApiMethod = "GET" | "POST";
443
+ type ApiMethod = "GET" | "POST";
444
444
  /** @internal Query values serializable by Midnight API helpers. */
445
- export type QueryValue = string | number | bigint | boolean | Date | readonly string[] | readonly number[] | undefined;
445
+ type QueryValue = string | number | bigint | boolean | Date | readonly string[] | readonly number[] | undefined;
446
446
  /** @internal Request descriptor consumed by the Midnight API HTTP helper. */
447
447
  export type ApiRequestParams = MidnightApiConfig & {
448
448
  readonly method: ApiMethod;
@@ -493,7 +493,7 @@ export type ApiPriceLevelsResponse = {
493
493
  readonly data: readonly ApiPriceLevelResponse[];
494
494
  };
495
495
  /** @internal Offer market response shape returned by the API. */
496
- export type ApiOfferMarketResponse = {
496
+ type ApiOfferMarketResponse = {
497
497
  readonly chain_id: number;
498
498
  readonly midnight: Address;
499
499
  readonly loan_token: Address;
@@ -504,7 +504,7 @@ export type ApiOfferMarketResponse = {
504
504
  readonly liquidator_gate: Address;
505
505
  };
506
506
  /** @internal Inline offer response shape returned by the API. */
507
- export type ApiOfferResponse = {
507
+ type ApiOfferResponse = {
508
508
  readonly market: ApiOfferMarketResponse;
509
509
  readonly buy: boolean;
510
510
  readonly maker: Address;
@@ -547,3 +547,4 @@ export type ApiTakeableOffersResponse = {
547
547
  readonly cursor: string | null;
548
548
  readonly data: readonly ApiTakeableOfferResponse[];
549
549
  };
550
+ export {};
@@ -1,2 +1,2 @@
1
1
  /** @internal Installed Midnight SDK package version. */
2
- export declare const MIDNIGHT_SDK_VERSION = "1.8.0";
2
+ export declare const MIDNIGHT_SDK_VERSION = "2.0.0";
@@ -1,3 +1,3 @@
1
- // Generated by scripts/release/generate-midnight-package-version.ts. Do not edit.
1
+ // Generated by scripts/generate-midnight-package-version.ts. Do not edit.
2
2
  /** @internal Installed Midnight SDK package version. */
3
- export const MIDNIGHT_SDK_VERSION = "1.8.0";
3
+ export const MIDNIGHT_SDK_VERSION = "2.0.0";
@@ -0,0 +1,15 @@
1
+ import type { Hex } from "viem";
2
+ /** `MidnightBundlesV2` group cancellation: marks `group` fully consumed if its consumption is at most `maxConsumed`. */
3
+ export interface GroupCancellation {
4
+ /** Offer group id. */
5
+ readonly group: Hex;
6
+ /** Largest current group consumption accepted (uint128); the whole call reverts above it. */
7
+ readonly maxConsumed: bigint;
8
+ }
9
+ /** `MidnightBundlesV2` collateral transfer: `assets` of the market collateral at `collateralIndex`. */
10
+ export interface CollateralTransfer {
11
+ /** Index of the collateral in the market's `collateralParams`. */
12
+ readonly collateralIndex: bigint;
13
+ /** Collateral assets. */
14
+ readonly assets: bigint;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -39,6 +39,7 @@ export async function fetchRatifierInfo(client, params) {
39
39
  const chainId = await resolveChainId(client);
40
40
  const ecrecoverRatifier = getChainAddress(chainId, "ecrecoverRatifier");
41
41
  const setterRatifier = getChainAddress(chainId, "setterRatifier");
42
+ // eth_getCode is trusted; the returned ratifier is a suggestion the caller commits to on Offer.create. See THREAT_MODEL.md, RPC.
42
43
  const bytecode = await getBytecode(client, {
43
44
  ...(params.blockNumber != null
44
45
  ? { blockNumber: params.blockNumber }
@@ -1,4 +1,5 @@
1
1
  export * from "./abis.js";
2
+ export type { CollateralTransfer, GroupCancellation } from "./bundlesV2.js";
2
3
  export * from "./constants.js";
3
4
  export * from "./errors.js";
4
5
  export * from "./fetch/index.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/midnight-sdk",
3
3
  "description": "Viem-based package for Morpho Midnight that exports protocol utilities, fetch helpers, and Midnight API utilities under a dedicated API subpath.",
4
- "version": "1.8.0",
4
+ "version": "2.0.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -37,19 +37,20 @@
37
37
  },
38
38
  "sideEffects": false,
39
39
  "files": [
40
- "lib"
40
+ "lib",
41
+ "MIGRATION-v1-to-v2.md"
41
42
  ],
42
43
  "peerDependencies": {
43
- "@morpho-org/morpho-ts": "^2.8.0 || ^3.0.0",
44
+ "@morpho-org/morpho-ts": "^2.8.0 || ^3.0.0 || ^4.0.0",
44
45
  "viem": "^2.0.0"
45
46
  },
46
47
  "devDependencies": {
48
+ "@morpho-org/morpho-ts": "^4.0.0",
49
+ "@morpho-org/test": "^2.10.1",
47
50
  "fast-check": "^4.9.0",
48
51
  "typescript": "7.0.2",
49
52
  "viem": "^2.55.10",
50
- "vitest": "^4.1.11",
51
- "@morpho-org/morpho-ts": "^3.1.0",
52
- "@morpho-org/test": "^2.10.0"
53
+ "vitest": "^4.1.11"
53
54
  },
54
55
  "scripts": {
55
56
  "prepublish": "pnpm build",
@@ -57,7 +58,7 @@
57
58
  "build": "pnpm generate:version && tsc --noEmit && pnpm build:cjs && pnpm build:esm",
58
59
  "build:cjs": "tsc --build tsconfig.build.cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
59
60
  "build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
60
- "generate:version": "node ../../scripts/release/generate-midnight-package-version.ts",
61
+ "generate:version": "node ../../scripts/generate-midnight-package-version.ts",
61
62
  "test": "vitest --root ../.. --project midnight-sdk --project midnight-sdk-fork"
62
63
  },
63
64
  "types": "./lib/esm/index.d.ts"