@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.
73 lines (72 loc) • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EMPTY_OFFER_STRUCT = void 0;
exports.isZeroAddress = isZeroAddress;
exports.isEmptyOfferStruct = isEmptyOfferStruct;
const viem_1 = require("viem");
const index_js_1 = require("../offers/index.js");
/** @internal Empty protocol offer struct used for Merkle padding. */
exports.EMPTY_OFFER_STRUCT = {
market: {
chainId: 0n,
midnight: viem_1.zeroAddress,
loanToken: viem_1.zeroAddress,
collateralParams: [],
maturity: 0n,
rcfThreshold: 0n,
enterGate: viem_1.zeroAddress,
liquidatorGate: viem_1.zeroAddress,
},
buy: false,
maker: viem_1.zeroAddress,
start: 0n,
expiry: 0n,
tick: 0n,
group: viem_1.zeroHash,
callback: viem_1.zeroAddress,
callbackData: "0x",
receiverIfMakerIsSeller: viem_1.zeroAddress,
ratifier: viem_1.zeroAddress,
reduceOnly: false,
maxUnits: 0n,
maxAssets: 0n,
continuousFeeCap: 0n,
};
const EMPTY_OFFER_DEFAULT_GROUP = (0, viem_1.keccak256)(index_js_1.OfferUtils.hashStruct(exports.EMPTY_OFFER_STRUCT));
/** @internal Returns whether an address value is the zero address. */
function isZeroAddress(value) {
return value.toLowerCase() === viem_1.zeroAddress;
}
/**
* @internal Returns whether an offer struct is the protocol empty offer.
*
* Tree padding may carry the empty offer's derived default group, while payload
* decoding only treats the canonical zero-group empty struct as padding.
*/
function isEmptyOfferStruct(offer, options = {}) {
const group = offer.group.toLowerCase();
const hasEmptyGroup = group === viem_1.zeroHash ||
(options.allowDefaultGroup === true && group === EMPTY_OFFER_DEFAULT_GROUP);
return (offer.market.chainId === 0n &&
isZeroAddress(offer.market.midnight) &&
isZeroAddress(offer.market.loanToken) &&
offer.market.collateralParams.length === 0 &&
offer.market.maturity === 0n &&
offer.market.rcfThreshold === 0n &&
isZeroAddress(offer.market.enterGate) &&
isZeroAddress(offer.market.liquidatorGate) &&
offer.buy === false &&
isZeroAddress(offer.maker) &&
offer.start === 0n &&
offer.expiry === 0n &&
offer.tick === 0n &&
hasEmptyGroup &&
isZeroAddress(offer.callback) &&
offer.callbackData === "0x" &&
isZeroAddress(offer.receiverIfMakerIsSeller) &&
isZeroAddress(offer.ratifier) &&
offer.reduceOnly === false &&
offer.maxUnits === 0n &&
offer.maxAssets === 0n &&
offer.continuousFeeCap === 0n);
}