@morpho-org/midnight-sdk 1.2.0 → 1.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/helpers.js +2 -4
- package/lib/cjs/api/version.generated.d.ts +2 -0
- package/lib/cjs/api/version.generated.js +6 -0
- package/lib/cjs/offers/Offer.d.ts +14 -10
- package/lib/cjs/offers/Offer.js +11 -7
- package/lib/cjs/signatures/RatifierUtils.js +2 -4
- package/lib/cjs/signatures/Tree.d.ts +3 -2
- package/lib/cjs/signatures/Tree.js +4 -3
- package/lib/cjs/signatures/TreeUtils.d.ts +2 -5
- package/lib/cjs/signatures/TreeUtils.js +5 -8
- package/lib/esm/api/helpers.js +1 -3
- package/lib/esm/api/version.generated.d.ts +2 -0
- package/lib/esm/api/version.generated.js +3 -0
- package/lib/esm/offers/Offer.d.ts +14 -10
- package/lib/esm/offers/Offer.js +12 -8
- package/lib/esm/signatures/RatifierUtils.js +3 -5
- package/lib/esm/signatures/Tree.d.ts +3 -2
- package/lib/esm/signatures/Tree.js +5 -4
- package/lib/esm/signatures/TreeUtils.d.ts +2 -5
- package/lib/esm/signatures/TreeUtils.js +5 -8
- package/package.json +3 -2
package/lib/cjs/api/helpers.js
CHANGED
|
@@ -12,10 +12,8 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
12
12
|
const viem_1 = require("viem");
|
|
13
13
|
const errors_js_1 = require("../errors.js");
|
|
14
14
|
const index_js_1 = require("../market/index.js");
|
|
15
|
+
const version_generated_js_1 = require("./version.generated.js");
|
|
15
16
|
const DEFAULT_MIDNIGHT_API_URL = new URL("/v0/midnight", morpho_ts_1.BLUE_API_BASE_URL);
|
|
16
|
-
// Keep this literal in source so the browser ESM build does not import package.json
|
|
17
|
-
// through Node-only createRequire/module shims.
|
|
18
|
-
const MIDNIGHT_SDK_VERSION = "1.0.1";
|
|
19
17
|
/** @internal Sends one Midnight API request and maps non-2xx responses to SDK errors. */
|
|
20
18
|
async function requestMidnightApi(params) {
|
|
21
19
|
const baseUrl = new URL(params.baseUrl ?? DEFAULT_MIDNIGHT_API_URL);
|
|
@@ -46,7 +44,7 @@ async function requestMidnightApi(params) {
|
|
|
46
44
|
const headers = new Headers(params.request?.headers);
|
|
47
45
|
if (params.body !== undefined)
|
|
48
46
|
headers.set("Content-Type", "application/json");
|
|
49
|
-
headers.set("sdk-version", MIDNIGHT_SDK_VERSION);
|
|
47
|
+
headers.set("sdk-version", version_generated_js_1.MIDNIGHT_SDK_VERSION);
|
|
50
48
|
const init = {
|
|
51
49
|
...params.request,
|
|
52
50
|
method: params.method,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Generated by scripts/release/generate-midnight-package-version.mjs. Do not edit.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.MIDNIGHT_SDK_VERSION = void 0;
|
|
5
|
+
/** @internal Installed Midnight SDK package version. */
|
|
6
|
+
exports.MIDNIGHT_SDK_VERSION = "1.2.1";
|
|
@@ -9,9 +9,9 @@ import { type IMarket, type IMarketParams, Market, MarketParams } from "../marke
|
|
|
9
9
|
* take-side conversion helpers. Use {@link Offer.create} instead for new maker
|
|
10
10
|
* offers so deterministic fields are validated before grouping or signing.
|
|
11
11
|
* The `group` field is optional. When omitted, {@link Offer.group} lazily
|
|
12
|
-
* derives the
|
|
13
|
-
* zero
|
|
14
|
-
* this field on the copies it owns.
|
|
12
|
+
* derives the content-addressed singleton group id from this offer's
|
|
13
|
+
* zero-group hash. `Group.create` copies offers into a shared group and
|
|
14
|
+
* overrides this field on the copies it owns.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
@@ -64,7 +64,7 @@ export interface IOffer {
|
|
|
64
64
|
readonly expiry: BigIntish;
|
|
65
65
|
/** Midnight tick. */
|
|
66
66
|
readonly tick: BigIntish;
|
|
67
|
-
/** Consumption group id; defaults to the
|
|
67
|
+
/** Consumption group id; defaults to the content-addressed singleton group id. */
|
|
68
68
|
readonly group?: Hash;
|
|
69
69
|
/** Optional maker callback. */
|
|
70
70
|
readonly callback: Address;
|
|
@@ -90,10 +90,11 @@ export interface IOffer {
|
|
|
90
90
|
* `Group.create` for shared-consumption ladders or directly to `Tree.create`
|
|
91
91
|
* for standalone offers. API/take-side code can convert a plain `IOffer`
|
|
92
92
|
* into this class before ABI encoding. The class resolves the onchain `group`
|
|
93
|
-
* field lazily. Standalone offers derive their
|
|
94
|
-
*
|
|
95
|
-
* on those copies when several offers share one
|
|
96
|
-
* hydrated from API or decoded data may also carry
|
|
93
|
+
* field lazily. Standalone offers derive their content-addressed singleton
|
|
94
|
+
* group id from the offer's zero-group hash; `Group.create` copies offers and
|
|
95
|
+
* overrides the group on those copies when several offers share one
|
|
96
|
+
* consumption bucket. Offers hydrated from API or decoded data may also carry
|
|
97
|
+
* a known group id.
|
|
97
98
|
*
|
|
98
99
|
* @example
|
|
99
100
|
* ```ts
|
|
@@ -220,8 +221,11 @@ export declare class Offer {
|
|
|
220
221
|
* Consumption group id encoded into this offer.
|
|
221
222
|
*
|
|
222
223
|
* When no group id was provided, the value is computed on first access by
|
|
223
|
-
* hashing this offer with the protocol zero group id
|
|
224
|
-
*
|
|
224
|
+
* hashing this offer with the protocol zero group id, then hashing that
|
|
225
|
+
* result as a singleton group. The computed value is cached because offer
|
|
226
|
+
* hashing is resource-intensive. This is equivalent to
|
|
227
|
+
* `GroupUtils.hash([offer])`, but is computed directly to keep the offers
|
|
228
|
+
* layer from importing signature helpers and creating a circular dependency.
|
|
225
229
|
*
|
|
226
230
|
* @returns Consumption group id.
|
|
227
231
|
* @example
|
package/lib/cjs/offers/Offer.js
CHANGED
|
@@ -11,10 +11,11 @@ const OfferUtils_js_1 = require("./OfferUtils.js");
|
|
|
11
11
|
* `Group.create` for shared-consumption ladders or directly to `Tree.create`
|
|
12
12
|
* for standalone offers. API/take-side code can convert a plain `IOffer`
|
|
13
13
|
* into this class before ABI encoding. The class resolves the onchain `group`
|
|
14
|
-
* field lazily. Standalone offers derive their
|
|
15
|
-
*
|
|
16
|
-
* on those copies when several offers share one
|
|
17
|
-
* hydrated from API or decoded data may also carry
|
|
14
|
+
* field lazily. Standalone offers derive their content-addressed singleton
|
|
15
|
+
* group id from the offer's zero-group hash; `Group.create` copies offers and
|
|
16
|
+
* overrides the group on those copies when several offers share one
|
|
17
|
+
* consumption bucket. Offers hydrated from API or decoded data may also carry
|
|
18
|
+
* a known group id.
|
|
18
19
|
*
|
|
19
20
|
* @example
|
|
20
21
|
* ```ts
|
|
@@ -162,8 +163,11 @@ class Offer {
|
|
|
162
163
|
* Consumption group id encoded into this offer.
|
|
163
164
|
*
|
|
164
165
|
* When no group id was provided, the value is computed on first access by
|
|
165
|
-
* hashing this offer with the protocol zero group id
|
|
166
|
-
*
|
|
166
|
+
* hashing this offer with the protocol zero group id, then hashing that
|
|
167
|
+
* result as a singleton group. The computed value is cached because offer
|
|
168
|
+
* hashing is resource-intensive. This is equivalent to
|
|
169
|
+
* `GroupUtils.hash([offer])`, but is computed directly to keep the offers
|
|
170
|
+
* layer from importing signature helpers and creating a circular dependency.
|
|
167
171
|
*
|
|
168
172
|
* @returns Consumption group id.
|
|
169
173
|
* @example
|
|
@@ -208,7 +212,7 @@ class Offer {
|
|
|
208
212
|
* ```
|
|
209
213
|
*/
|
|
210
214
|
get group() {
|
|
211
|
-
this.cachedGroup ??= OfferUtils_js_1.OfferUtils.groupHash(this);
|
|
215
|
+
this.cachedGroup ??= (0, viem_1.keccak256)(OfferUtils_js_1.OfferUtils.groupHash(this));
|
|
212
216
|
return this.cachedGroup;
|
|
213
217
|
}
|
|
214
218
|
/**
|
|
@@ -24,12 +24,10 @@ function normalizeTree(tree) {
|
|
|
24
24
|
: [
|
|
25
25
|
new index_js_1.Offer({
|
|
26
26
|
...index_js_1.Offer.from(entry),
|
|
27
|
-
group:
|
|
27
|
+
group: GroupUtils_js_1.GroupUtils.hash([entry]),
|
|
28
28
|
}),
|
|
29
29
|
]);
|
|
30
|
-
const descriptor = TreeUtils_js_1.TreeUtils.buildDescriptor(
|
|
31
|
-
preserveStandaloneGroups: true,
|
|
32
|
-
});
|
|
30
|
+
const descriptor = TreeUtils_js_1.TreeUtils.buildDescriptor(entries);
|
|
33
31
|
return {
|
|
34
32
|
offers,
|
|
35
33
|
paddedOffers: descriptor.offers,
|
|
@@ -108,8 +108,9 @@ export declare class Tree {
|
|
|
108
108
|
*
|
|
109
109
|
* Use after `Offer.create` and optional `Group.create`, before
|
|
110
110
|
* `Tree.mempoolValidate`, `EcrecoverRatifierUtils.ratify`, or
|
|
111
|
-
* `SetterRatifierUtils.ratify`. Groups are flattened
|
|
112
|
-
* offer
|
|
111
|
+
* `SetterRatifierUtils.ratify`. Groups are flattened, and every standalone
|
|
112
|
+
* offer is normalized as a singleton group using the router-compatible group
|
|
113
|
+
* id algorithm.
|
|
113
114
|
*
|
|
114
115
|
* @param params - Groups or standalone offers in leaf order.
|
|
115
116
|
* @returns Tree instance.
|
|
@@ -63,7 +63,7 @@ class Tree {
|
|
|
63
63
|
: [
|
|
64
64
|
new index_js_1.Offer({
|
|
65
65
|
...index_js_1.Offer.from(entry),
|
|
66
|
-
group:
|
|
66
|
+
group: GroupUtils_js_1.GroupUtils.hash([entry]),
|
|
67
67
|
}),
|
|
68
68
|
]);
|
|
69
69
|
const descriptor = TreeUtils_js_1.TreeUtils.buildDescriptor(params);
|
|
@@ -127,8 +127,9 @@ class Tree {
|
|
|
127
127
|
*
|
|
128
128
|
* Use after `Offer.create` and optional `Group.create`, before
|
|
129
129
|
* `Tree.mempoolValidate`, `EcrecoverRatifierUtils.ratify`, or
|
|
130
|
-
* `SetterRatifierUtils.ratify`. Groups are flattened
|
|
131
|
-
* offer
|
|
130
|
+
* `SetterRatifierUtils.ratify`. Groups are flattened, and every standalone
|
|
131
|
+
* offer is normalized as a singleton group using the router-compatible group
|
|
132
|
+
* id algorithm.
|
|
132
133
|
*
|
|
133
134
|
* @param params - Groups or standalone offers in leaf order.
|
|
134
135
|
* @returns Tree instance.
|
|
@@ -489,12 +489,11 @@ export declare namespace TreeUtils {
|
|
|
489
489
|
* Use after `Group.create` or standalone `Offer.create` when you need the
|
|
490
490
|
* padded leaves for custom signing, root approval, or proof construction.
|
|
491
491
|
* Groups are encoded with their derived shared group id, and standalone
|
|
492
|
-
* offers are encoded with
|
|
492
|
+
* offers are encoded as singleton groups with the same algorithm.
|
|
493
493
|
* `Tree.create` calls this internally and is the simpler API for most
|
|
494
494
|
* make-side code.
|
|
495
495
|
*
|
|
496
496
|
* @param entries - Groups or standalone offers in leaf order.
|
|
497
|
-
* @param options.preserveStandaloneGroups - Whether standalone offer group ids should be preserved instead of normalized.
|
|
498
497
|
* @returns Tree descriptor.
|
|
499
498
|
* @throws {InvalidTreeError} when the offer count is empty, all padding, or duplicated.
|
|
500
499
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
@@ -532,9 +531,7 @@ export declare namespace TreeUtils {
|
|
|
532
531
|
* console.log(tree.root);
|
|
533
532
|
* ```
|
|
534
533
|
*/
|
|
535
|
-
function buildDescriptor(entries: TreeCreateParams
|
|
536
|
-
readonly preserveStandaloneGroups?: boolean;
|
|
537
|
-
}): TreeDescriptor;
|
|
534
|
+
function buildDescriptor(entries: TreeCreateParams): TreeDescriptor;
|
|
538
535
|
/**
|
|
539
536
|
* Builds only the tree root.
|
|
540
537
|
*
|
|
@@ -137,10 +137,10 @@ var TreeUtils;
|
|
|
137
137
|
: [
|
|
138
138
|
new index_js_1.Offer({
|
|
139
139
|
...index_js_1.Offer.from(entry),
|
|
140
|
-
group:
|
|
140
|
+
group: GroupUtils_js_1.GroupUtils.hash([entry]),
|
|
141
141
|
}),
|
|
142
142
|
]);
|
|
143
|
-
buildDescriptor(
|
|
143
|
+
buildDescriptor(entries);
|
|
144
144
|
items = offers.map((offer) => ({
|
|
145
145
|
offer,
|
|
146
146
|
ratifierData: "0x",
|
|
@@ -209,12 +209,11 @@ var TreeUtils;
|
|
|
209
209
|
* Use after `Group.create` or standalone `Offer.create` when you need the
|
|
210
210
|
* padded leaves for custom signing, root approval, or proof construction.
|
|
211
211
|
* Groups are encoded with their derived shared group id, and standalone
|
|
212
|
-
* offers are encoded with
|
|
212
|
+
* offers are encoded as singleton groups with the same algorithm.
|
|
213
213
|
* `Tree.create` calls this internally and is the simpler API for most
|
|
214
214
|
* make-side code.
|
|
215
215
|
*
|
|
216
216
|
* @param entries - Groups or standalone offers in leaf order.
|
|
217
|
-
* @param options.preserveStandaloneGroups - Whether standalone offer group ids should be preserved instead of normalized.
|
|
218
217
|
* @returns Tree descriptor.
|
|
219
218
|
* @throws {InvalidTreeError} when the offer count is empty, all padding, or duplicated.
|
|
220
219
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
@@ -252,15 +251,13 @@ var TreeUtils;
|
|
|
252
251
|
* console.log(tree.root);
|
|
253
252
|
* ```
|
|
254
253
|
*/
|
|
255
|
-
function buildDescriptor(entries
|
|
254
|
+
function buildDescriptor(entries) {
|
|
256
255
|
const structs = entries.flatMap((entry) => GroupUtils_js_1.GroupUtils.isGroupInput(entry)
|
|
257
256
|
? GroupUtils_js_1.GroupUtils.toStructs(entry)
|
|
258
257
|
: [
|
|
259
258
|
index_js_1.OfferUtils.toStruct({
|
|
260
259
|
offer: entry,
|
|
261
|
-
group:
|
|
262
|
-
? undefined
|
|
263
|
-
: index_js_1.OfferUtils.groupHash(entry),
|
|
260
|
+
group: GroupUtils_js_1.GroupUtils.hash([entry]),
|
|
264
261
|
}),
|
|
265
262
|
]);
|
|
266
263
|
if (structs.length === 0) {
|
package/lib/esm/api/helpers.js
CHANGED
|
@@ -2,10 +2,8 @@ import { BLUE_API_BASE_URL, isHexEqual } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { isAddressEqual } from "viem";
|
|
3
3
|
import { InvalidMidnightApiResponseError, MidnightApiError, } from "../errors.js";
|
|
4
4
|
import { MarketUtils } from "../market/index.js";
|
|
5
|
+
import { MIDNIGHT_SDK_VERSION } from "./version.generated.js";
|
|
5
6
|
const DEFAULT_MIDNIGHT_API_URL = new URL("/v0/midnight", BLUE_API_BASE_URL);
|
|
6
|
-
// Keep this literal in source so the browser ESM build does not import package.json
|
|
7
|
-
// through Node-only createRequire/module shims.
|
|
8
|
-
const MIDNIGHT_SDK_VERSION = "1.0.1";
|
|
9
7
|
/** @internal Sends one Midnight API request and maps non-2xx responses to SDK errors. */
|
|
10
8
|
export async function requestMidnightApi(params) {
|
|
11
9
|
const baseUrl = new URL(params.baseUrl ?? DEFAULT_MIDNIGHT_API_URL);
|
|
@@ -9,9 +9,9 @@ import { type IMarket, type IMarketParams, Market, MarketParams } from "../marke
|
|
|
9
9
|
* take-side conversion helpers. Use {@link Offer.create} instead for new maker
|
|
10
10
|
* offers so deterministic fields are validated before grouping or signing.
|
|
11
11
|
* The `group` field is optional. When omitted, {@link Offer.group} lazily
|
|
12
|
-
* derives the
|
|
13
|
-
* zero
|
|
14
|
-
* this field on the copies it owns.
|
|
12
|
+
* derives the content-addressed singleton group id from this offer's
|
|
13
|
+
* zero-group hash. `Group.create` copies offers into a shared group and
|
|
14
|
+
* overrides this field on the copies it owns.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
@@ -64,7 +64,7 @@ export interface IOffer {
|
|
|
64
64
|
readonly expiry: BigIntish;
|
|
65
65
|
/** Midnight tick. */
|
|
66
66
|
readonly tick: BigIntish;
|
|
67
|
-
/** Consumption group id; defaults to the
|
|
67
|
+
/** Consumption group id; defaults to the content-addressed singleton group id. */
|
|
68
68
|
readonly group?: Hash;
|
|
69
69
|
/** Optional maker callback. */
|
|
70
70
|
readonly callback: Address;
|
|
@@ -90,10 +90,11 @@ export interface IOffer {
|
|
|
90
90
|
* `Group.create` for shared-consumption ladders or directly to `Tree.create`
|
|
91
91
|
* for standalone offers. API/take-side code can convert a plain `IOffer`
|
|
92
92
|
* into this class before ABI encoding. The class resolves the onchain `group`
|
|
93
|
-
* field lazily. Standalone offers derive their
|
|
94
|
-
*
|
|
95
|
-
* on those copies when several offers share one
|
|
96
|
-
* hydrated from API or decoded data may also carry
|
|
93
|
+
* field lazily. Standalone offers derive their content-addressed singleton
|
|
94
|
+
* group id from the offer's zero-group hash; `Group.create` copies offers and
|
|
95
|
+
* overrides the group on those copies when several offers share one
|
|
96
|
+
* consumption bucket. Offers hydrated from API or decoded data may also carry
|
|
97
|
+
* a known group id.
|
|
97
98
|
*
|
|
98
99
|
* @example
|
|
99
100
|
* ```ts
|
|
@@ -220,8 +221,11 @@ export declare class Offer {
|
|
|
220
221
|
* Consumption group id encoded into this offer.
|
|
221
222
|
*
|
|
222
223
|
* When no group id was provided, the value is computed on first access by
|
|
223
|
-
* hashing this offer with the protocol zero group id
|
|
224
|
-
*
|
|
224
|
+
* hashing this offer with the protocol zero group id, then hashing that
|
|
225
|
+
* result as a singleton group. The computed value is cached because offer
|
|
226
|
+
* hashing is resource-intensive. This is equivalent to
|
|
227
|
+
* `GroupUtils.hash([offer])`, but is computed directly to keep the offers
|
|
228
|
+
* layer from importing signature helpers and creating a circular dependency.
|
|
225
229
|
*
|
|
226
230
|
* @returns Consumption group id.
|
|
227
231
|
* @example
|
package/lib/esm/offers/Offer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { zeroAddress } from "viem";
|
|
1
|
+
import { keccak256, zeroAddress } from "viem";
|
|
2
2
|
import { Market, MarketParams, } from "../market/index.js";
|
|
3
3
|
import { OfferUtils } from "./OfferUtils.js";
|
|
4
4
|
/**
|
|
@@ -8,10 +8,11 @@ import { OfferUtils } from "./OfferUtils.js";
|
|
|
8
8
|
* `Group.create` for shared-consumption ladders or directly to `Tree.create`
|
|
9
9
|
* for standalone offers. API/take-side code can convert a plain `IOffer`
|
|
10
10
|
* into this class before ABI encoding. The class resolves the onchain `group`
|
|
11
|
-
* field lazily. Standalone offers derive their
|
|
12
|
-
*
|
|
13
|
-
* on those copies when several offers share one
|
|
14
|
-
* hydrated from API or decoded data may also carry
|
|
11
|
+
* field lazily. Standalone offers derive their content-addressed singleton
|
|
12
|
+
* group id from the offer's zero-group hash; `Group.create` copies offers and
|
|
13
|
+
* overrides the group on those copies when several offers share one
|
|
14
|
+
* consumption bucket. Offers hydrated from API or decoded data may also carry
|
|
15
|
+
* a known group id.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```ts
|
|
@@ -159,8 +160,11 @@ export class Offer {
|
|
|
159
160
|
* Consumption group id encoded into this offer.
|
|
160
161
|
*
|
|
161
162
|
* When no group id was provided, the value is computed on first access by
|
|
162
|
-
* hashing this offer with the protocol zero group id
|
|
163
|
-
*
|
|
163
|
+
* hashing this offer with the protocol zero group id, then hashing that
|
|
164
|
+
* result as a singleton group. The computed value is cached because offer
|
|
165
|
+
* hashing is resource-intensive. This is equivalent to
|
|
166
|
+
* `GroupUtils.hash([offer])`, but is computed directly to keep the offers
|
|
167
|
+
* layer from importing signature helpers and creating a circular dependency.
|
|
164
168
|
*
|
|
165
169
|
* @returns Consumption group id.
|
|
166
170
|
* @example
|
|
@@ -205,7 +209,7 @@ export class Offer {
|
|
|
205
209
|
* ```
|
|
206
210
|
*/
|
|
207
211
|
get group() {
|
|
208
|
-
this.cachedGroup ??= OfferUtils.groupHash(this);
|
|
212
|
+
this.cachedGroup ??= keccak256(OfferUtils.groupHash(this));
|
|
209
213
|
return this.cachedGroup;
|
|
210
214
|
}
|
|
211
215
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InvalidTreeError } from "../errors.js";
|
|
2
|
-
import { Offer
|
|
2
|
+
import { Offer } from "../offers/index.js";
|
|
3
3
|
import { Group } from "./Group.js";
|
|
4
4
|
import { GroupUtils } from "./GroupUtils.js";
|
|
5
5
|
import { TreeUtils } from "./TreeUtils.js";
|
|
@@ -21,12 +21,10 @@ function normalizeTree(tree) {
|
|
|
21
21
|
: [
|
|
22
22
|
new Offer({
|
|
23
23
|
...Offer.from(entry),
|
|
24
|
-
group:
|
|
24
|
+
group: GroupUtils.hash([entry]),
|
|
25
25
|
}),
|
|
26
26
|
]);
|
|
27
|
-
const descriptor = TreeUtils.buildDescriptor(
|
|
28
|
-
preserveStandaloneGroups: true,
|
|
29
|
-
});
|
|
27
|
+
const descriptor = TreeUtils.buildDescriptor(entries);
|
|
30
28
|
return {
|
|
31
29
|
offers,
|
|
32
30
|
paddedOffers: descriptor.offers,
|
|
@@ -108,8 +108,9 @@ export declare class Tree {
|
|
|
108
108
|
*
|
|
109
109
|
* Use after `Offer.create` and optional `Group.create`, before
|
|
110
110
|
* `Tree.mempoolValidate`, `EcrecoverRatifierUtils.ratify`, or
|
|
111
|
-
* `SetterRatifierUtils.ratify`. Groups are flattened
|
|
112
|
-
* offer
|
|
111
|
+
* `SetterRatifierUtils.ratify`. Groups are flattened, and every standalone
|
|
112
|
+
* offer is normalized as a singleton group using the router-compatible group
|
|
113
|
+
* id algorithm.
|
|
113
114
|
*
|
|
114
115
|
* @param params - Groups or standalone offers in leaf order.
|
|
115
116
|
* @returns Tree instance.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Offer
|
|
1
|
+
import { Offer } from "../offers/index.js";
|
|
2
2
|
import { Group } from "./Group.js";
|
|
3
3
|
import { GroupUtils } from "./GroupUtils.js";
|
|
4
4
|
import { TreeUtils, } from "./TreeUtils.js";
|
|
@@ -60,7 +60,7 @@ export class Tree {
|
|
|
60
60
|
: [
|
|
61
61
|
new Offer({
|
|
62
62
|
...Offer.from(entry),
|
|
63
|
-
group:
|
|
63
|
+
group: GroupUtils.hash([entry]),
|
|
64
64
|
}),
|
|
65
65
|
]);
|
|
66
66
|
const descriptor = TreeUtils.buildDescriptor(params);
|
|
@@ -124,8 +124,9 @@ export class Tree {
|
|
|
124
124
|
*
|
|
125
125
|
* Use after `Offer.create` and optional `Group.create`, before
|
|
126
126
|
* `Tree.mempoolValidate`, `EcrecoverRatifierUtils.ratify`, or
|
|
127
|
-
* `SetterRatifierUtils.ratify`. Groups are flattened
|
|
128
|
-
* offer
|
|
127
|
+
* `SetterRatifierUtils.ratify`. Groups are flattened, and every standalone
|
|
128
|
+
* offer is normalized as a singleton group using the router-compatible group
|
|
129
|
+
* id algorithm.
|
|
129
130
|
*
|
|
130
131
|
* @param params - Groups or standalone offers in leaf order.
|
|
131
132
|
* @returns Tree instance.
|
|
@@ -489,12 +489,11 @@ export declare namespace TreeUtils {
|
|
|
489
489
|
* Use after `Group.create` or standalone `Offer.create` when you need the
|
|
490
490
|
* padded leaves for custom signing, root approval, or proof construction.
|
|
491
491
|
* Groups are encoded with their derived shared group id, and standalone
|
|
492
|
-
* offers are encoded with
|
|
492
|
+
* offers are encoded as singleton groups with the same algorithm.
|
|
493
493
|
* `Tree.create` calls this internally and is the simpler API for most
|
|
494
494
|
* make-side code.
|
|
495
495
|
*
|
|
496
496
|
* @param entries - Groups or standalone offers in leaf order.
|
|
497
|
-
* @param options.preserveStandaloneGroups - Whether standalone offer group ids should be preserved instead of normalized.
|
|
498
497
|
* @returns Tree descriptor.
|
|
499
498
|
* @throws {InvalidTreeError} when the offer count is empty, all padding, or duplicated.
|
|
500
499
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
@@ -532,9 +531,7 @@ export declare namespace TreeUtils {
|
|
|
532
531
|
* console.log(tree.root);
|
|
533
532
|
* ```
|
|
534
533
|
*/
|
|
535
|
-
function buildDescriptor(entries: TreeCreateParams
|
|
536
|
-
readonly preserveStandaloneGroups?: boolean;
|
|
537
|
-
}): TreeDescriptor;
|
|
534
|
+
function buildDescriptor(entries: TreeCreateParams): TreeDescriptor;
|
|
538
535
|
/**
|
|
539
536
|
* Builds only the tree root.
|
|
540
537
|
*
|
|
@@ -134,10 +134,10 @@ export var TreeUtils;
|
|
|
134
134
|
: [
|
|
135
135
|
new Offer({
|
|
136
136
|
...Offer.from(entry),
|
|
137
|
-
group:
|
|
137
|
+
group: GroupUtils.hash([entry]),
|
|
138
138
|
}),
|
|
139
139
|
]);
|
|
140
|
-
buildDescriptor(
|
|
140
|
+
buildDescriptor(entries);
|
|
141
141
|
items = offers.map((offer) => ({
|
|
142
142
|
offer,
|
|
143
143
|
ratifierData: "0x",
|
|
@@ -206,12 +206,11 @@ export var TreeUtils;
|
|
|
206
206
|
* Use after `Group.create` or standalone `Offer.create` when you need the
|
|
207
207
|
* padded leaves for custom signing, root approval, or proof construction.
|
|
208
208
|
* Groups are encoded with their derived shared group id, and standalone
|
|
209
|
-
* offers are encoded with
|
|
209
|
+
* offers are encoded as singleton groups with the same algorithm.
|
|
210
210
|
* `Tree.create` calls this internally and is the simpler API for most
|
|
211
211
|
* make-side code.
|
|
212
212
|
*
|
|
213
213
|
* @param entries - Groups or standalone offers in leaf order.
|
|
214
|
-
* @param options.preserveStandaloneGroups - Whether standalone offer group ids should be preserved instead of normalized.
|
|
215
214
|
* @returns Tree descriptor.
|
|
216
215
|
* @throws {InvalidTreeError} when the offer count is empty, all padding, or duplicated.
|
|
217
216
|
* @throws {InvalidTreeHeightError} when the padded tree exceeds supported ratifier typehashes.
|
|
@@ -249,15 +248,13 @@ export var TreeUtils;
|
|
|
249
248
|
* console.log(tree.root);
|
|
250
249
|
* ```
|
|
251
250
|
*/
|
|
252
|
-
function buildDescriptor(entries
|
|
251
|
+
function buildDescriptor(entries) {
|
|
253
252
|
const structs = entries.flatMap((entry) => GroupUtils.isGroupInput(entry)
|
|
254
253
|
? GroupUtils.toStructs(entry)
|
|
255
254
|
: [
|
|
256
255
|
OfferUtils.toStruct({
|
|
257
256
|
offer: entry,
|
|
258
|
-
group:
|
|
259
|
-
? undefined
|
|
260
|
-
: OfferUtils.groupHash(entry),
|
|
257
|
+
group: GroupUtils.hash([entry]),
|
|
261
258
|
}),
|
|
262
259
|
]);
|
|
263
260
|
if (structs.length === 0) {
|
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.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -57,9 +57,10 @@
|
|
|
57
57
|
"scripts": {
|
|
58
58
|
"prepublish": "$npm_execpath build",
|
|
59
59
|
"compile": "node ../../scripts/compile-solidity.js midnight-sdk",
|
|
60
|
-
"build": "tsc --noEmit && $npm_execpath build:cjs && $npm_execpath build:esm",
|
|
60
|
+
"build": "$npm_execpath generate:version && tsc --noEmit && $npm_execpath build:cjs && $npm_execpath build:esm",
|
|
61
61
|
"build:cjs": "tsc --build tsconfig.build.cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
|
|
62
62
|
"build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
|
|
63
|
+
"generate:version": "node ../../scripts/release/generate-midnight-package-version.mjs",
|
|
63
64
|
"test": "vitest --root ../.. --project midnight-sdk"
|
|
64
65
|
},
|
|
65
66
|
"types": "./lib/esm/index.d.ts"
|