@morpho-org/midnight-sdk 2.2.0-next.0 → 2.2.1
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/lib/cjs/api/MidnightApi.d.ts +18 -8
- package/lib/cjs/api/MidnightApi.js +18 -8
- package/lib/cjs/api/helpers.js +11 -2
- package/lib/cjs/api/version.generated.d.ts +1 -1
- package/lib/cjs/api/version.generated.js +1 -1
- package/lib/cjs/errors.d.ts +27 -13
- package/lib/cjs/errors.js +39 -8
- package/lib/cjs/position/PositionUtils.js +35 -11
- package/lib/cjs/signatures/PriceRatifierV1.d.ts +6 -1
- package/lib/cjs/signatures/PriceRatifierV1.js +6 -1
- package/lib/cjs/signatures/RateRatifierV1.d.ts +6 -1
- package/lib/cjs/signatures/RateRatifierV1.js +6 -1
- package/lib/cjs/signatures/Tree.d.ts +2 -0
- package/lib/cjs/signatures/TreeUtils.d.ts +1 -0
- package/lib/cjs/signatures/ratifierV1Internal.d.ts +1 -1
- package/lib/cjs/signatures/ratifierV1Internal.js +24 -1
- package/lib/esm/api/MidnightApi.d.ts +18 -8
- package/lib/esm/api/MidnightApi.js +18 -8
- package/lib/esm/api/helpers.js +12 -3
- package/lib/esm/api/version.generated.d.ts +1 -1
- package/lib/esm/api/version.generated.js +1 -1
- package/lib/esm/errors.d.ts +27 -13
- package/lib/esm/errors.js +36 -8
- package/lib/esm/position/PositionUtils.js +36 -12
- package/lib/esm/signatures/PriceRatifierV1.d.ts +6 -1
- package/lib/esm/signatures/PriceRatifierV1.js +6 -1
- package/lib/esm/signatures/RateRatifierV1.d.ts +6 -1
- package/lib/esm/signatures/RateRatifierV1.js +6 -1
- package/lib/esm/signatures/Tree.d.ts +2 -0
- package/lib/esm/signatures/TreeUtils.d.ts +1 -0
- package/lib/esm/signatures/ratifierV1Internal.d.ts +1 -1
- package/lib/esm/signatures/ratifierV1Internal.js +24 -1
- package/package.json +5 -5
|
@@ -74,6 +74,7 @@ export declare class Tree<K extends RatifierKind | undefined = undefined> {
|
|
|
74
74
|
* @returns Tree instance.
|
|
75
75
|
* @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
|
|
76
76
|
* @throws {InvalidTreeHeightError} when the resulting height is unsupported.
|
|
77
|
+
* @throws {InvalidOfferGroupError} for priceV1/rateV1 entries whose explicit groups break `OfferUtils.validateOfferGroup` rules.
|
|
77
78
|
* @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
|
|
78
79
|
* @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
|
|
79
80
|
* @example
|
|
@@ -141,6 +142,7 @@ export declare class Tree<K extends RatifierKind | undefined = undefined> {
|
|
|
141
142
|
* @returns A tree whose entries and validation options are inferred from the route.
|
|
142
143
|
* @throws {InvalidTreeError} when the tree is empty, all padding, or duplicated.
|
|
143
144
|
* @throws {InvalidTreeHeightError} when the resulting height is unsupported.
|
|
145
|
+
* @throws {InvalidOfferGroupError} for priceV1/rateV1 entries whose explicit groups break `OfferUtils.validateOfferGroup` rules.
|
|
144
146
|
* @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
|
|
145
147
|
* @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
|
|
146
148
|
* @example
|
|
@@ -535,6 +535,7 @@ export declare namespace TreeUtils {
|
|
|
535
535
|
* @returns Tree descriptor.
|
|
536
536
|
* @throws {InvalidTreeError} when the offer count is empty, all padding, or duplicated.
|
|
537
537
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
538
|
+
* @throws {InvalidOfferGroupError} for priceV1/rateV1 entries whose explicit groups break `OfferUtils.validateOfferGroup` rules.
|
|
538
539
|
* @throws {InvalidRateRatifierV1RateError} when a Rate leaf has a negative rate.
|
|
539
540
|
* @throws {InvalidRateRatifierV1TickError} when a Rate leaf offer tick is below `RateRatifierV1.MIN_TICK`.
|
|
540
541
|
* @example
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Address, type Hash } from "viem";
|
|
2
2
|
import { type IOffer, Offer, type OfferStruct } from "../offers/index.js";
|
|
3
3
|
import type { TreeData } from "./treeTypes.js";
|
|
4
|
-
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
|
|
4
|
+
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids and validates explicit groups. */
|
|
5
5
|
export declare function assignRatifierV1Groups<TLeaf extends {
|
|
6
6
|
readonly offer: Offer;
|
|
7
7
|
}>(leaves: readonly TLeaf[], groupId: (leaves: readonly TLeaf[]) => Hash): Offer[];
|
|
@@ -6,7 +6,7 @@ import { GroupUtils } from "./GroupUtils.js";
|
|
|
6
6
|
import { isZeroAddress } from "./offerStructInternal.js";
|
|
7
7
|
import { TreeUtils } from "./TreeUtils.js";
|
|
8
8
|
import { isPowerOfTwo, nextPowerOfTwo } from "./treeMathInternal.js";
|
|
9
|
-
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids. */
|
|
9
|
+
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids and validates explicit groups. */
|
|
10
10
|
export function assignRatifierV1Groups(leaves, groupId) {
|
|
11
11
|
const offers = leaves.map((leaf) => leaf.offer.hasExplicitGroup
|
|
12
12
|
? leaf.offer
|
|
@@ -24,6 +24,10 @@ export function assignRatifierV1Groups(leaves, groupId) {
|
|
|
24
24
|
}
|
|
25
25
|
for (const [label, indices] of buckets) {
|
|
26
26
|
const bucketLeaves = indices.map((index) => leaves[index]);
|
|
27
|
+
// Called only to throw on incompatible group members.
|
|
28
|
+
OfferUtils.validateOfferGroup({
|
|
29
|
+
offers: bucketLeaves.map((leaf) => leaf.offer),
|
|
30
|
+
});
|
|
27
31
|
if (GroupUtils.hash(bucketLeaves.map((leaf) => leaf.offer)).toLowerCase() !==
|
|
28
32
|
label) {
|
|
29
33
|
continue;
|
|
@@ -33,6 +37,25 @@ export function assignRatifierV1Groups(leaves, groupId) {
|
|
|
33
37
|
offers[index] = Offer.from({ ...leaves[index].offer, group });
|
|
34
38
|
}
|
|
35
39
|
}
|
|
40
|
+
const finalGroups = new Map();
|
|
41
|
+
for (const [index, offer] of offers.entries()) {
|
|
42
|
+
const label = offer.group.toLowerCase();
|
|
43
|
+
const hasExplicitGroup = leaves[index].offer.hasExplicitGroup;
|
|
44
|
+
const bucket = finalGroups.get(label);
|
|
45
|
+
if (bucket) {
|
|
46
|
+
bucket.offers.push(offer);
|
|
47
|
+
bucket.hasExplicitGroup ||= hasExplicitGroup;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
finalGroups.set(label, { offers: [offer], hasExplicitGroup });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const { offers: groupOffers, hasExplicitGroup, } of finalGroups.values()) {
|
|
54
|
+
if (!hasExplicitGroup)
|
|
55
|
+
continue;
|
|
56
|
+
// Catches explicit groups that collide with a defaulted or re-derived id.
|
|
57
|
+
OfferUtils.validateOfferGroup({ offers: groupOffers });
|
|
58
|
+
}
|
|
36
59
|
return offers;
|
|
37
60
|
}
|
|
38
61
|
/**
|
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": "2.2.
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -41,16 +41,16 @@
|
|
|
41
41
|
"MIGRATION-v1-to-v2.md"
|
|
42
42
|
],
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@morpho-org/morpho-ts": "^4.
|
|
44
|
+
"@morpho-org/morpho-ts": "^2.8.0 || ^3.0.0 || ^4.0.0",
|
|
45
45
|
"viem": "^2.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@morpho-org/morpho-ts": "^4.1.0
|
|
49
|
-
"@morpho-org/test": "^2.
|
|
48
|
+
"@morpho-org/morpho-ts": "^4.1.0",
|
|
49
|
+
"@morpho-org/test": "^2.11.0",
|
|
50
50
|
"fast-check": "^4.9.0",
|
|
51
51
|
"typescript": "7.0.2",
|
|
52
52
|
"viem": "^2.55.10",
|
|
53
|
-
"vitest": "^4.1.
|
|
53
|
+
"vitest": "^4.1.12"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"prepublish": "pnpm build",
|