Skip to main content

MarketMakingPolicy

Git Source - Generated with forge doc

Inherits: IMarketMakingPolicy

Title: MarketMakingPolicy

Singleton IInterestRatePolicy where each user writes one curve per Tenor market.

Each point carries (ttm, sellRate, buyRate) on a shared TTM grid with sellRate <= buyRate enforced point-wise. getRate returns the side selected by userIsBuyer (true when buying credit on Midnight); the rate gap is the spread.

Rates are capped at type(uint112).max: within 192 seconds of maturity, even the max rate gives price = WAD^2 / (WAD + rate * ttm) >= 1 after flooring, so a quote of exactly 0 is not expressible there.

The policy does not verify which callback is in use; it trusts the ratifier's userIsBuyer flag and maturities.

getRate reverts on Midnight to Midnight renewals (both source and target maturities nonzero); not supported.

Lend-only: only lend entry and exit flows are supported (vault -> Midnight and Midnight -> vault).

setCurve/clearCurve use the Midnight contract as authorization authority: the caller must be onBehalf or authorized by it on Midnight; each maker's curve is stored per (onBehalf, tenorMarketId).

Constants​

MORPHO_MIDNIGHT​

The Morpho Midnight protocol used for authorization checks.

IMidnight public immutable MORPHO_MIDNIGHT;

Returns

NameTypeDescription
<none>address

MAX_POINTS​

uint256 internal constant MAX_POINTS = 8;

State Variables​

curves​

Returns the i-th point of the curve of user on tenorMarketId.

mapping(address user => mapping(bytes32 tenorMarketId => CurvePoint[])) public curves;

Parameters

NameTypeDescription
useraddress
tenorMarketIdbytes32
<none>uint256

Returns

NameTypeDescription
ttmuint32
sellRateuint112
buyRateuint112

Functions​

constructor​

constructor(address morphoMidnight);

Parameters

NameTypeDescription
morphoMidnightaddress

setCurve​

Overwrites the curve of onBehalf for tenorMarketId.

Enforces 1 to MAX_POINTS points, strictly increasing ttm, and sellRate <= buyRate at every point.

function setCurve(address onBehalf, bytes32 tenorMarketId, CurvePoint[] calldata points) external;

Parameters

NameTypeDescription
onBehalfaddress
tenorMarketIdbytes32
pointsCurvePoint[]

clearCurve​

Deletes the curve of onBehalf for tenorMarketId.

function clearCurve(address onBehalf, bytes32 tenorMarketId) external;

Parameters

NameTypeDescription
onBehalfaddress
tenorMarketIdbytes32

getRate​

Returns the interest rate for the given renewal context.

Midnight to Midnight renewals are rejected. A buy quotes the target market's buyRate, a sell the source market's sellRate. The ttm is floored at zero so past-maturity markets clamp instead of underflowing.

function getRate(
bytes32 sourceTenorMarketId,
bytes32 targetTenorMarketId,
uint256, /* renewalPeriodStart */
address user,
address, /* taker */
uint256 sourceMaturity,
uint256 targetMaturity,
bool userIsBuyer
) public view virtual returns (uint256);

Parameters

NameTypeDescription
sourceTenorMarketIdbytes32The id of the source side of the renewal (the position being closed).
targetTenorMarketIdbytes32The id of the target side of the renewal (the position being entered).
_uint256The renewal period start timestamp (the policy computes the elapsed time internally).
useraddressThe position owner being renewed (the offer maker in the make-on-behalf flow).
_addressThe Midnight.take taker, forwarded from isRatified.
sourceMaturityuint256The source market maturity (0 for Blue to Midnight migrations).
targetMaturityuint256The target market maturity (0 for Midnight to Blue exits).
userIsBuyerboolThe renewed user's side in the trade, derived from the migration direction.

Returns

NameTypeDescription
<none>uint256The interpolated rate per second in WAD at the given elapsed time.

_loadCurve​

Materializes the requested side of curve into parallel (knots, values) arrays.

function _loadCurve(CurvePoint[] storage curve, bool buySide)
private
view
returns (uint256[] memory knots, uint256[] memory values);

Parameters

NameTypeDescription
curveCurvePoint[]
buySidebool

Returns

NameTypeDescription
knotsuint256[]
valuesuint256[]