@morpho-org/midnight-sdk
Version:
Viem-based package for Morpho Midnight that exports protocol utilities, fetch helpers, and Midnight API utilities under a dedicated API subpath.
58 lines (57 loc) • 2.75 kB
TypeScript
import { type Address, type Hash } from "viem";
import { type IOffer, Offer, type OfferStruct } from "../offers/index.js";
import type { TreeData } from "./treeTypes.js";
/** @internal Resolves V1 leaf groups mirroring the router's group_identity content ids and validates explicit groups. */
export declare function assignRatifierV1Groups<TLeaf extends {
readonly offer: Offer;
}>(leaves: readonly TLeaf[], groupId: (leaves: readonly TLeaf[]) => Hash): Offer[];
/** @internal Padded V1 ratifier leaf descriptor shared by the V1 ratifier utils. */
export type RatifierV1Descriptor<TStruct> = Omit<TreeData<TStruct>, "offers">;
/**
* @internal Pads, hash-checks, and roots a V1 ratifier leaf list.
*
* All non-padding entries must share one ratifier address and produce distinct
* leaf hashes. Non-power-of-two lists are padded with `padding` at the highest
* leaf indices, matching `TreeUtils.buildDescriptor` semantics.
*/
export declare function buildRatifierV1Descriptor<TStruct>(params: {
readonly entries: readonly TStruct[];
readonly padding: TStruct;
readonly hashLeaf: (entry: TStruct) => Hash;
readonly ratifierOf: (entry: TStruct) => Address;
readonly label: string;
}): RatifierV1Descriptor<TStruct>;
/**
* @internal Resolves a V1 ratifier tree input into a materialized descriptor.
*
* Caller-provided descriptors are fully re-validated: height, lengths, leaf
* hashes, visible-offer correspondence, padding placement, and the Merkle
* root must all agree, mirroring `Ratifier.normalizeTree`. An optional
* `validateEntry` hook runs ratifier-specific checks on each visible
* (non-padding) entry before leaf hashes are recomputed, so descriptor input
* is held to the same bounds as `buildDescriptor`.
*/
export declare function resolveRatifierV1Tree<TStruct extends {
readonly offer: OfferStruct;
}, TLeaf, TDescriptor extends RatifierV1Descriptor<TStruct> & {
readonly offers: readonly IOffer[];
}>(tree: TDescriptor | readonly TLeaf[], helpers: {
readonly buildDescriptor: (leaves: readonly TLeaf[]) => TDescriptor;
readonly hashLeaf: (entry: TStruct) => Hash;
readonly isPadding: (entry: TStruct) => boolean;
readonly ratifierOf: (entry: TStruct) => Address;
readonly validateEntry?: (entry: TStruct) => void;
readonly label: string;
readonly type: "priceV1" | "rateV1";
}): TDescriptor;
/**
* @internal Asserts a V1 ratifier address is deployed (non-zero).
*/
export declare function assertRatifierV1Address(ratifier: Address): void;
/**
* @internal Asserts a take-side taker matches the leaf's allowed taker.
*/
export declare function assertRatifierV1Taker(params: {
readonly taker: Address | undefined;
readonly allowedTaker: Address;
}): void;