UNPKG

@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.

40 lines (39 loc) • 2.01 kB
import type { Address, Client } from "viem"; import { type RatifierInfo } from "../signatures/Ratifier.js"; import type { MidnightCallParameters } from "./types.js"; /** * Fetches maker bytecode and classifies the ratifier route for new offers. * * The `bytecode` read is the result of `eth_getCode` for `params.maker` at the * requested block. It is not returned to callers; it only tells the SDK whether * the maker is an EOA or EIP-7702 account that can use Ecrecover signatures, or * a deployed-code account that should use Setter root approval. Put the returned * `ratifier` address on `Offer.create`, then use the returned `type` to choose * `EcrecoverRatifier.ratify` or `SetterRatifier.ratify` after the tree * has been built. * * Reads `eth_chainId` only when the viem client has no configured chain id, * then reads `eth_getCode` for `params.maker`. * * @param client - Viem client used for the bytecode read. * @param params.maker - Maker address whose bytecode determines the ratifier route. * @param params.blockNumber - Optional block number used for the bytecode read. * @param params.blockTag - Optional block tag used for the bytecode read. * @returns Ratifier information. * @throws {UnsupportedChainIdError} when no address registry exists for the client chain id. * @throws {UnknownAddressError} when the registry has no configured ratifier address for the client chain id. * @example * ```ts * import { fetchRatifierInfo } from "@morpho-org/midnight-sdk"; * * const maker = "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"; * const info = await fetchRatifierInfo(client, { maker }); * // Pass info.ratifier to Offer.create(...), then use info.type after * // Tree.create({ type: info.type, entries: [...] }) to choose the Ecrecover * // or Setter ratifier flow. * console.log(info.type, info.ratifier); * ``` */ export declare function fetchRatifierInfo(client: Client, params: { readonly maker: Address; } & MidnightCallParameters): Promise<RatifierInfo>;