@morpho-org/midnight-sdk 1.7.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.
Files changed (103) hide show
  1. package/MIGRATION-v1-to-v2.md +6 -0
  2. package/README.md +63 -61
  3. package/lib/cjs/abis.d.ts +1962 -759
  4. package/lib/cjs/abis.js +2021 -995
  5. package/lib/cjs/api/helpers.d.ts +1 -17
  6. package/lib/cjs/api/helpers.js +0 -4
  7. package/lib/cjs/api/types.d.ts +5 -4
  8. package/lib/cjs/api/version.generated.d.ts +1 -1
  9. package/lib/cjs/api/version.generated.js +2 -2
  10. package/lib/cjs/bundlesV2.d.ts +15 -0
  11. package/lib/cjs/bundlesV2.js +2 -0
  12. package/lib/cjs/constants.d.ts +34 -0
  13. package/lib/cjs/constants.js +35 -1
  14. package/lib/cjs/errors.d.ts +107 -0
  15. package/lib/cjs/errors.js +139 -1
  16. package/lib/cjs/fetch/Ratifier.d.ts +4 -3
  17. package/lib/cjs/fetch/Ratifier.js +6 -4
  18. package/lib/cjs/index.d.ts +8 -0
  19. package/lib/cjs/index.js +16 -1
  20. package/lib/cjs/offers/Offer.d.ts +10 -0
  21. package/lib/cjs/offers/Offer.js +15 -1
  22. package/lib/cjs/offers/OfferUtils.d.ts +3 -0
  23. package/lib/cjs/offers/OfferUtils.js +3 -0
  24. package/lib/cjs/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  25. package/lib/cjs/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  26. package/lib/cjs/signatures/GroupUtils.d.ts +55 -2
  27. package/lib/cjs/signatures/GroupUtils.js +64 -5
  28. package/lib/cjs/signatures/Payload.d.ts +3 -3
  29. package/lib/cjs/signatures/PriceRatifierV1.d.ts +472 -0
  30. package/lib/cjs/signatures/PriceRatifierV1.js +521 -0
  31. package/lib/cjs/signatures/RateRatifierV1.d.ts +581 -0
  32. package/lib/cjs/signatures/RateRatifierV1.js +696 -0
  33. package/lib/{esm/signatures/RatifierUtils.d.ts → cjs/signatures/Ratifier.d.ts} +14 -12
  34. package/lib/cjs/signatures/{RatifierUtils.js → Ratifier.js} +29 -29
  35. package/lib/cjs/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  36. package/lib/cjs/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  37. package/lib/cjs/signatures/Tree.d.ts +94 -17
  38. package/lib/cjs/signatures/Tree.js +146 -111
  39. package/lib/cjs/signatures/TreeUtils.d.ts +191 -21
  40. package/lib/cjs/signatures/TreeUtils.js +320 -134
  41. package/lib/cjs/signatures/index.d.ts +7 -3
  42. package/lib/cjs/signatures/index.js +5 -3
  43. package/lib/cjs/signatures/ratifierRequests.d.ts +55 -0
  44. package/lib/cjs/signatures/ratifierRequests.js +2 -0
  45. package/lib/cjs/signatures/ratifierV1Internal.d.ts +57 -0
  46. package/lib/cjs/signatures/ratifierV1Internal.js +183 -0
  47. package/lib/cjs/signatures/standardRatifierInternal.d.ts +4 -0
  48. package/lib/cjs/signatures/standardRatifierInternal.js +12 -0
  49. package/lib/cjs/signatures/treeMathInternal.d.ts +4 -0
  50. package/lib/cjs/signatures/treeMathInternal.js +12 -0
  51. package/lib/cjs/signatures/treeTypes.d.ts +109 -0
  52. package/lib/cjs/signatures/treeTypes.js +2 -0
  53. package/lib/esm/abis.d.ts +1962 -759
  54. package/lib/esm/abis.js +2020 -994
  55. package/lib/esm/api/helpers.d.ts +1 -17
  56. package/lib/esm/api/helpers.js +4 -4
  57. package/lib/esm/api/types.d.ts +5 -4
  58. package/lib/esm/api/version.generated.d.ts +1 -1
  59. package/lib/esm/api/version.generated.js +2 -2
  60. package/lib/esm/bundlesV2.d.ts +15 -0
  61. package/lib/esm/bundlesV2.js +1 -0
  62. package/lib/esm/constants.d.ts +34 -0
  63. package/lib/esm/constants.js +34 -0
  64. package/lib/esm/errors.d.ts +107 -0
  65. package/lib/esm/errors.js +132 -0
  66. package/lib/esm/fetch/Ratifier.d.ts +4 -3
  67. package/lib/esm/fetch/Ratifier.js +6 -4
  68. package/lib/esm/index.d.ts +8 -0
  69. package/lib/esm/index.js +5 -0
  70. package/lib/esm/offers/Offer.d.ts +10 -0
  71. package/lib/esm/offers/Offer.js +15 -1
  72. package/lib/esm/offers/OfferUtils.d.ts +3 -0
  73. package/lib/esm/offers/OfferUtils.js +3 -0
  74. package/lib/esm/signatures/{EcrecoverRatifierUtils.d.ts → EcrecoverRatifier.d.ts} +118 -2
  75. package/lib/esm/signatures/{EcrecoverRatifierUtils.js → EcrecoverRatifier.js} +146 -9
  76. package/lib/esm/signatures/GroupUtils.d.ts +55 -2
  77. package/lib/esm/signatures/GroupUtils.js +64 -5
  78. package/lib/esm/signatures/Payload.d.ts +3 -3
  79. package/lib/esm/signatures/PriceRatifierV1.d.ts +472 -0
  80. package/lib/esm/signatures/PriceRatifierV1.js +520 -0
  81. package/lib/esm/signatures/RateRatifierV1.d.ts +581 -0
  82. package/lib/esm/signatures/RateRatifierV1.js +695 -0
  83. package/lib/{cjs/signatures/RatifierUtils.d.ts → esm/signatures/Ratifier.d.ts} +14 -12
  84. package/lib/esm/signatures/{RatifierUtils.js → Ratifier.js} +31 -29
  85. package/lib/esm/signatures/{SetterRatifierUtils.d.ts → SetterRatifier.d.ts} +50 -3
  86. package/lib/esm/signatures/{SetterRatifierUtils.js → SetterRatifier.js} +65 -7
  87. package/lib/esm/signatures/Tree.d.ts +94 -17
  88. package/lib/esm/signatures/Tree.js +147 -112
  89. package/lib/esm/signatures/TreeUtils.d.ts +191 -21
  90. package/lib/esm/signatures/TreeUtils.js +318 -132
  91. package/lib/esm/signatures/index.d.ts +7 -3
  92. package/lib/esm/signatures/index.js +5 -3
  93. package/lib/esm/signatures/ratifierRequests.d.ts +55 -0
  94. package/lib/esm/signatures/ratifierRequests.js +1 -0
  95. package/lib/esm/signatures/ratifierV1Internal.d.ts +57 -0
  96. package/lib/esm/signatures/ratifierV1Internal.js +176 -0
  97. package/lib/esm/signatures/standardRatifierInternal.d.ts +4 -0
  98. package/lib/esm/signatures/standardRatifierInternal.js +9 -0
  99. package/lib/esm/signatures/treeMathInternal.d.ts +4 -0
  100. package/lib/esm/signatures/treeMathInternal.js +8 -0
  101. package/lib/esm/signatures/treeTypes.d.ts +109 -0
  102. package/lib/esm/signatures/treeTypes.js +1 -0
  103. package/package.json +9 -8
@@ -0,0 +1,57 @@
1
+ import { type Address, type Hash } from "viem";
2
+ import { type IOffer, Offer, type OfferStruct } from "../offers/index.js";
3
+ import type { TreeData } from "./treeTypes.js";
4
+ /** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
5
+ export declare function assignRatifierV1Groups<TLeaf extends {
6
+ readonly offer: Offer;
7
+ }>(leaves: readonly TLeaf[], groupId: (leaves: readonly TLeaf[]) => Hash): Offer[];
8
+ /** @internal Padded V1 ratifier leaf descriptor shared by the V1 ratifier utils. */
9
+ export type RatifierV1Descriptor<TStruct> = Omit<TreeData<TStruct>, "offers">;
10
+ /**
11
+ * @internal Pads, hash-checks, and roots a V1 ratifier leaf list.
12
+ *
13
+ * All non-padding entries must share one ratifier address and produce distinct
14
+ * leaf hashes. Non-power-of-two lists are padded with `padding` at the highest
15
+ * leaf indices, matching `TreeUtils.buildDescriptor` semantics.
16
+ */
17
+ export declare function buildRatifierV1Descriptor<TStruct>(params: {
18
+ readonly entries: readonly TStruct[];
19
+ readonly padding: TStruct;
20
+ readonly hashLeaf: (entry: TStruct) => Hash;
21
+ readonly ratifierOf: (entry: TStruct) => Address;
22
+ readonly label: string;
23
+ }): RatifierV1Descriptor<TStruct>;
24
+ /**
25
+ * @internal Resolves a V1 ratifier tree input into a materialized descriptor.
26
+ *
27
+ * Caller-provided descriptors are fully re-validated: height, lengths, leaf
28
+ * hashes, visible-offer correspondence, padding placement, and the Merkle
29
+ * root must all agree, mirroring `Ratifier.normalizeTree`. An optional
30
+ * `validateEntry` hook runs ratifier-specific checks on each visible
31
+ * (non-padding) entry before leaf hashes are recomputed, so descriptor input
32
+ * is held to the same bounds as `buildDescriptor`.
33
+ */
34
+ export declare function resolveRatifierV1Tree<TStruct extends {
35
+ readonly offer: OfferStruct;
36
+ }, TLeaf, TDescriptor extends RatifierV1Descriptor<TStruct> & {
37
+ readonly offers: readonly IOffer[];
38
+ }>(tree: TDescriptor | readonly TLeaf[], helpers: {
39
+ readonly buildDescriptor: (leaves: readonly TLeaf[]) => TDescriptor;
40
+ readonly hashLeaf: (entry: TStruct) => Hash;
41
+ readonly isPadding: (entry: TStruct) => boolean;
42
+ readonly ratifierOf: (entry: TStruct) => Address;
43
+ readonly validateEntry?: (entry: TStruct) => void;
44
+ readonly label: string;
45
+ readonly type: "priceV1" | "rateV1";
46
+ }): TDescriptor;
47
+ /**
48
+ * @internal Asserts a V1 ratifier address is deployed (non-zero).
49
+ */
50
+ export declare function assertRatifierV1Address(ratifier: Address): void;
51
+ /**
52
+ * @internal Asserts a take-side taker matches the leaf's allowed taker.
53
+ */
54
+ export declare function assertRatifierV1Taker(params: {
55
+ readonly taker: Address | undefined;
56
+ readonly allowedTaker: Address;
57
+ }): void;
@@ -0,0 +1,176 @@
1
+ import { isAddressEqual, zeroAddress } from "viem";
2
+ import { MAX_TREE_HEIGHT } from "../constants.js";
3
+ import { InvalidRatifierV1AddressError, InvalidTreeError, InvalidTreeHeightError, RatifierV1TakerNotAllowedError, } from "../errors.js";
4
+ import { Offer, OfferUtils, } from "../offers/index.js";
5
+ import { GroupUtils } from "./GroupUtils.js";
6
+ import { isZeroAddress } from "./offerStructInternal.js";
7
+ import { TreeUtils } from "./TreeUtils.js";
8
+ import { isPowerOfTwo, nextPowerOfTwo } from "./treeMathInternal.js";
9
+ /** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
10
+ export function assignRatifierV1Groups(leaves, groupId) {
11
+ const offers = leaves.map((leaf) => leaf.offer.hasExplicitGroup
12
+ ? leaf.offer
13
+ : Offer.from({ ...leaf.offer, group: groupId([leaf]) }));
14
+ const buckets = new Map();
15
+ for (const [index, leaf] of leaves.entries()) {
16
+ if (!leaf.offer.hasExplicitGroup)
17
+ continue;
18
+ const label = leaf.offer.group.toLowerCase();
19
+ const bucket = buckets.get(label);
20
+ if (bucket)
21
+ bucket.push(index);
22
+ else
23
+ buckets.set(label, [index]);
24
+ }
25
+ for (const [label, indices] of buckets) {
26
+ const bucketLeaves = indices.map((index) => leaves[index]);
27
+ if (GroupUtils.hash(bucketLeaves.map((leaf) => leaf.offer)).toLowerCase() !==
28
+ label) {
29
+ continue;
30
+ }
31
+ const group = groupId(bucketLeaves);
32
+ for (const index of indices) {
33
+ offers[index] = Offer.from({ ...leaves[index].offer, group });
34
+ }
35
+ }
36
+ return offers;
37
+ }
38
+ /**
39
+ * @internal Pads, hash-checks, and roots a V1 ratifier leaf list.
40
+ *
41
+ * All non-padding entries must share one ratifier address and produce distinct
42
+ * leaf hashes. Non-power-of-two lists are padded with `padding` at the highest
43
+ * leaf indices, matching `TreeUtils.buildDescriptor` semantics.
44
+ */
45
+ export function buildRatifierV1Descriptor(params) {
46
+ const { entries, padding, hashLeaf, ratifierOf, label } = params;
47
+ const first = entries[0];
48
+ if (first == null) {
49
+ throw new InvalidTreeError("Tree must not be empty.");
50
+ }
51
+ const ratifier = ratifierOf(first);
52
+ for (const entry of entries.slice(1)) {
53
+ const other = ratifierOf(entry);
54
+ if (!isAddressEqual(other, ratifier)) {
55
+ throw new InvalidTreeError(`All offers in a ${label} tree must use one ratifier; expected "${ratifier}", got "${other}". Build separate trees per ratifier.`);
56
+ }
57
+ }
58
+ const entryHashes = entries.map(hashLeaf);
59
+ const seen = new Set();
60
+ for (const leafHash of entryHashes) {
61
+ if (seen.has(leafHash)) {
62
+ throw new InvalidTreeError(`Duplicate leaf hash "${leafHash}" in tree.`);
63
+ }
64
+ seen.add(leafHash);
65
+ }
66
+ const paddingCount = isPowerOfTwo(entries.length)
67
+ ? 0
68
+ : nextPowerOfTwo(entries.length) - entries.length;
69
+ const paddedEntries = [
70
+ ...entries,
71
+ ...Array.from({ length: paddingCount }, () => padding),
72
+ ];
73
+ const paddingHash = paddingCount === 0 ? undefined : hashLeaf(padding);
74
+ const leaves = [
75
+ ...entryHashes,
76
+ ...Array.from({ length: paddingCount }, () => paddingHash),
77
+ ];
78
+ const { root, height } = TreeUtils.buildRootFromLeaves(leaves);
79
+ return { entries: paddedEntries, leaves, root, height };
80
+ }
81
+ /**
82
+ * @internal Resolves a V1 ratifier tree input into a materialized descriptor.
83
+ *
84
+ * Caller-provided descriptors are fully re-validated: height, lengths, leaf
85
+ * hashes, visible-offer correspondence, padding placement, and the Merkle
86
+ * root must all agree, mirroring `Ratifier.normalizeTree`. An optional
87
+ * `validateEntry` hook runs ratifier-specific checks on each visible
88
+ * (non-padding) entry before leaf hashes are recomputed, so descriptor input
89
+ * is held to the same bounds as `buildDescriptor`.
90
+ */
91
+ export function resolveRatifierV1Tree(tree, helpers) {
92
+ const { buildDescriptor, hashLeaf, isPadding, ratifierOf, label } = helpers;
93
+ if (Array.isArray(tree))
94
+ return buildDescriptor(tree);
95
+ const descriptor = tree;
96
+ if ("type" in descriptor &&
97
+ descriptor.type != null &&
98
+ descriptor.type !== helpers.type) {
99
+ throw new InvalidTreeError("Ratifier route does not match the tree route.");
100
+ }
101
+ if (!Number.isInteger(descriptor.height) ||
102
+ descriptor.height < 0 ||
103
+ descriptor.height > MAX_TREE_HEIGHT) {
104
+ throw new InvalidTreeHeightError(descriptor.height);
105
+ }
106
+ if (descriptor.offers.length === 0) {
107
+ throw new InvalidTreeError("Tree must not be empty.");
108
+ }
109
+ const expectedLength = 2 ** descriptor.height;
110
+ if (descriptor.entries.length !== expectedLength ||
111
+ descriptor.leaves.length !== expectedLength ||
112
+ expectedLength !== nextPowerOfTwo(descriptor.offers.length)) {
113
+ throw new InvalidTreeError("Tree entries, leaves, offers, and height describe different trees.");
114
+ }
115
+ const visibleEntries = descriptor.entries.slice(0, descriptor.offers.length);
116
+ const ratifier = ratifierOf(visibleEntries[0]);
117
+ for (const entry of visibleEntries.slice(1)) {
118
+ const other = ratifierOf(entry);
119
+ if (!isAddressEqual(other, ratifier)) {
120
+ throw new InvalidTreeError(`All offers in a ${label} tree must use one ratifier; expected "${ratifier}", got "${other}". Build separate trees per ratifier.`);
121
+ }
122
+ }
123
+ // Ratifier-specific entry gates run before any leaf hashing.
124
+ for (const entry of visibleEntries) {
125
+ if (isPadding(entry)) {
126
+ throw new InvalidTreeError("Visible offers must not contain tree padding.");
127
+ }
128
+ helpers.validateEntry?.(entry);
129
+ }
130
+ const computedLeaves = descriptor.entries.map((entry) => hashLeaf(entry));
131
+ const seen = new Set();
132
+ for (const [index, offer] of descriptor.offers.entries()) {
133
+ const entry = descriptor.entries[index];
134
+ if (OfferUtils.hashStruct(OfferUtils.toStruct({ offer: Offer.from(offer) })).toLowerCase() !== OfferUtils.hashStruct(entry.offer).toLowerCase()) {
135
+ throw new InvalidTreeError("Visible offers do not match the tree entries.");
136
+ }
137
+ const leafHash = computedLeaves[index].toLowerCase();
138
+ if (seen.has(leafHash)) {
139
+ throw new InvalidTreeError(`Duplicate leaf hash "${leafHash}" in tree.`);
140
+ }
141
+ seen.add(leafHash);
142
+ }
143
+ if (descriptor.entries
144
+ .slice(descriptor.offers.length)
145
+ .some((entry) => !isPadding(entry))) {
146
+ throw new InvalidTreeError("Tree padding contains entries hidden from the visible offer list.");
147
+ }
148
+ if (computedLeaves.some((leaf, index) => leaf.toLowerCase() !== descriptor.leaves[index].toLowerCase())) {
149
+ throw new InvalidTreeError("Tree leaves do not match its entries.");
150
+ }
151
+ if (TreeUtils.buildRootFromLeaves(descriptor.leaves).root.toLowerCase() !==
152
+ descriptor.root.toLowerCase()) {
153
+ throw new InvalidTreeError("Tree root does not match its leaves.");
154
+ }
155
+ return descriptor;
156
+ }
157
+ /**
158
+ * @internal Asserts a V1 ratifier address is deployed (non-zero).
159
+ */
160
+ export function assertRatifierV1Address(ratifier) {
161
+ if (isZeroAddress(ratifier)) {
162
+ throw new InvalidRatifierV1AddressError(ratifier);
163
+ }
164
+ }
165
+ /**
166
+ * @internal Asserts a take-side taker matches the leaf's allowed taker.
167
+ */
168
+ export function assertRatifierV1Taker(params) {
169
+ const { taker, allowedTaker } = params;
170
+ if (taker == null ||
171
+ isAddressEqual(allowedTaker, zeroAddress) ||
172
+ isAddressEqual(taker, allowedTaker)) {
173
+ return;
174
+ }
175
+ throw new RatifierV1TakerNotAllowedError({ taker, allowedTaker });
176
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from "./Tree.js";
2
+ import type { TreeSnapshot } from "./treeTypes.js";
3
+ /** @internal Parses tagged standard-ratifier inputs and rejects legacy or mismatched routes. */
4
+ export declare function parseStandardRatifierTree(tree: TreeSnapshot<"ecrecover"> | TreeSnapshot<"setter">, expected: "ecrecover" | "setter"): Tree<"ecrecover"> | Tree<"setter">;
@@ -0,0 +1,9 @@
1
+ import { InvalidTreeError } from "../errors.js";
2
+ import { Tree } from "./Tree.js";
3
+ /** @internal Parses tagged standard-ratifier inputs and rejects legacy or mismatched routes. */
4
+ export function parseStandardRatifierTree(tree, expected) {
5
+ if (tree.type !== expected) {
6
+ throw new InvalidTreeError(`Expected a "${expected}" tree. Create a tree with an explicit matching ratifier type.`);
7
+ }
8
+ return Tree.fromDescriptor(tree);
9
+ }
@@ -0,0 +1,4 @@
1
+ /** @internal Returns whether `value` is a positive power of two. */
2
+ export declare function isPowerOfTwo(value: number): boolean;
3
+ /** @internal Returns the smallest power of two greater than or equal to `value`. */
4
+ export declare function nextPowerOfTwo(value: number): number;
@@ -0,0 +1,8 @@
1
+ /** @internal Returns whether `value` is a positive power of two. */
2
+ export function isPowerOfTwo(value) {
3
+ return value > 0 && (value & (value - 1)) === 0;
4
+ }
5
+ /** @internal Returns the smallest power of two greater than or equal to `value`. */
6
+ export function nextPowerOfTwo(value) {
7
+ return 2 ** Math.ceil(Math.log2(value));
8
+ }
@@ -0,0 +1,109 @@
1
+ import type { Hash } from "viem";
2
+ import type { IOffer, OfferStruct } from "../offers/index.js";
3
+ import type { GroupInput } from "./GroupUtils.js";
4
+ import type { PriceRatifierV1Leaf, PriceRatifierV1LeafStruct } from "./PriceRatifierV1.js";
5
+ import type { RateRatifierV1Leaf, RateRatifierV1LeafStruct } from "./RateRatifierV1.js";
6
+ import type { Tree } from "./Tree.js";
7
+ import type { RatifierTreeInput, TreeLike, TreeMempoolValidateParams, TreeMempoolValidateRatification } from "./TreeUtils.js";
8
+ /** Creation request for an Ecrecover tree; its root is authorized by signature. */
9
+ export interface EcrecoverTreeCreateRequest {
10
+ /** Selects standard offer hashing and Ecrecover authorization. */
11
+ readonly type: "ecrecover";
12
+ /** Groups or standalone offers in leaf order. */
13
+ readonly entries: readonly GroupInput[];
14
+ }
15
+ /** Creation request for a Setter tree; its root is approved onchain. */
16
+ export interface SetterTreeCreateRequest {
17
+ /** Selects standard offer hashing and Setter authorization. */
18
+ readonly type: "setter";
19
+ /** Groups or standalone offers in leaf order. */
20
+ readonly entries: readonly GroupInput[];
21
+ }
22
+ /** Creation request for a Price V1 tree with per-leaf taker restrictions. */
23
+ export interface PriceRatifierV1TreeCreateRequest {
24
+ /** Selects Price V1 leaf commitments. */
25
+ readonly type: "priceV1";
26
+ /** Price-bounded offer leaves in leaf order. */
27
+ readonly entries: readonly PriceRatifierV1Leaf[];
28
+ }
29
+ /** Creation request for a Rate V1 tree with per-leaf rate and taker restrictions. */
30
+ export interface RateRatifierV1TreeCreateRequest {
31
+ /** Selects Rate V1 leaf commitments. */
32
+ readonly type: "rateV1";
33
+ /** Rate-bounded offer leaves in leaf order. */
34
+ readonly entries: readonly RateRatifierV1Leaf[];
35
+ }
36
+ /** Tagged construction API; each variant keeps its route and entries together. */
37
+ export type TreeCreateRequest = EcrecoverTreeCreateRequest | SetterTreeCreateRequest | PriceRatifierV1TreeCreateRequest | RateRatifierV1TreeCreateRequest;
38
+ /** Associates each ratifier route with its construction input and committed leaf. */
39
+ export type RatifierTypes = {
40
+ /** Ecrecover signs standard offer trees. */
41
+ readonly ecrecover: {
42
+ readonly input: EcrecoverTreeCreateRequest["entries"];
43
+ readonly entry: OfferStruct;
44
+ };
45
+ /** Setter approves standard offer trees onchain. */
46
+ readonly setter: {
47
+ readonly input: SetterTreeCreateRequest["entries"];
48
+ readonly entry: OfferStruct;
49
+ };
50
+ /** Price V1 commits to price and taker restrictions. */
51
+ readonly priceV1: {
52
+ readonly input: PriceRatifierV1TreeCreateRequest["entries"];
53
+ readonly entry: PriceRatifierV1LeafStruct;
54
+ };
55
+ /** Rate V1 commits to rate and taker restrictions. */
56
+ readonly rateV1: {
57
+ readonly input: RateRatifierV1TreeCreateRequest["entries"];
58
+ readonly entry: RateRatifierV1LeafStruct;
59
+ };
60
+ };
61
+ /** Explicit ratifier routes supported by a typed tree. */
62
+ export type RatifierKind = keyof RatifierTypes;
63
+ /** Normalized entry for a route; undefined retains the legacy standard format. */
64
+ export type TreeEntry<K extends RatifierKind | undefined> = K extends RatifierKind ? RatifierTypes[K]["entry"] : OfferStruct;
65
+ /** Shared materialized leaf data, independent of ratifier authorization. */
66
+ export interface TreeData<E> {
67
+ /** Padded normalized entries in leaf order. */
68
+ readonly entries: readonly E[];
69
+ /** Non-padding offers in leaf order. */
70
+ readonly offers: readonly IOffer[];
71
+ /** Hashes of all padded entries. */
72
+ readonly leaves: readonly Hash[];
73
+ /** Merkle root. */
74
+ readonly root: Hash;
75
+ /** Merkle height. */
76
+ readonly height: number;
77
+ }
78
+ /** Portable descriptor; callers must validate it before trusting its hashes. */
79
+ export interface TreeSnapshot<K extends RatifierKind | undefined> extends TreeData<TreeEntry<K>> {
80
+ /** Route selecting normalization, hashing and authorization. */
81
+ readonly type: K;
82
+ }
83
+ /** Union preserving the relationship between a descriptor's route and entries. */
84
+ export type AnyTreeSnapshot = {
85
+ [K in RatifierKind]: TreeSnapshot<K>;
86
+ }[RatifierKind];
87
+ /** Union that narrows entries when its route tag is narrowed. */
88
+ export type AnyTree = {
89
+ [K in RatifierKind]: Tree<K>;
90
+ }[RatifierKind];
91
+ /** API validation options restricted to a tree's authorization route. */
92
+ export type TypedTreeMempoolValidateParams<K extends RatifierKind | undefined> = Omit<TreeMempoolValidateParams, "ratification"> & {
93
+ readonly ratification?: K extends "priceV1" | "rateV1" ? {
94
+ readonly type: K;
95
+ } : K extends "ecrecover" | "setter" ? Extract<TreeMempoolValidateRatification, {
96
+ readonly type: K;
97
+ }> : TreeMempoolValidateRatification;
98
+ };
99
+ /**
100
+ * Compatibility input accepting the original untagged contract or a matching tagged tree.
101
+ * @deprecated Use TreeSnapshot with the required route for the new ratifier APIs.
102
+ * Deliberately widening a tagged tree to a legacy type erases static route information;
103
+ * ratifier utilities still validate any runtime tag before use.
104
+ */
105
+ export type TypedRatifierTreeInput<K extends "ecrecover" | "setter"> = (RatifierTreeInput & {
106
+ readonly type?: undefined;
107
+ }) | (TreeLike & {
108
+ readonly type: K;
109
+ });
@@ -0,0 +1 @@
1
+ export {};
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.7.0",
4
+ "version": "2.0.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -37,27 +37,28 @@
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.0.0",
52
- "@morpho-org/test": "^2.10.0"
53
+ "vitest": "^4.1.11"
53
54
  },
54
55
  "scripts": {
55
56
  "prepublish": "pnpm build",
56
- "compile": "node ../../scripts/compile-solidity.js midnight-sdk",
57
+ "compile": "node ../../scripts/compile-solidity.ts midnight-sdk",
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.mjs",
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"