@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.
26 lines (25 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveChainId = exports.shouldUseDeployless = exports.callParameters = void 0;
const actions_1 = require("viem/actions");
const errors_js_1 = require("../errors.js");
/** @internal Extracts viem call parameters from Midnight fetch inputs. */
const callParameters = (params) => ({
account: params.account,
blockNumber: params.blockNumber,
blockTag: params.blockTag,
stateOverride: params.stateOverride,
});
exports.callParameters = callParameters;
/** @internal Returns the configured deployless mode, defaulting to enabled. */
const shouldUseDeployless = (params) => params.deployless ?? true;
exports.shouldUseDeployless = shouldUseDeployless;
/** @internal Returns the RPC chain id and rejects configured-chain drift. */
const resolveChainId = async (client) => {
const rpcChainId = await (0, actions_1.getChainId)(client);
if (client.chain?.id != null && client.chain.id !== rpcChainId) {
throw new errors_js_1.ChainIdMismatchError(client.chain.id, BigInt(rpcChainId));
}
return rpcChainId;
};
exports.resolveChainId = resolveChainId;