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.

20 lines (19 loc) • 868 B
import { getChainId } from "viem/actions"; import { ChainIdMismatchError } from "../errors.js"; /** @internal Extracts viem call parameters from Midnight fetch inputs. */ export const callParameters = (params) => ({ account: params.account, blockNumber: params.blockNumber, blockTag: params.blockTag, stateOverride: params.stateOverride, }); /** @internal Returns the configured deployless mode, defaulting to enabled. */ export const shouldUseDeployless = (params) => params.deployless ?? true; /** @internal Returns the RPC chain id and rejects configured-chain drift. */ export const resolveChainId = async (client) => { const rpcChainId = await getChainId(client); if (client.chain?.id != null && client.chain.id !== rpcChainId) { throw new ChainIdMismatchError(client.chain.id, BigInt(rpcChainId)); } return rpcChainId; };