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 userIsBuyer flag and the maturities provided by the ratifier.
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 (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
MAX_POINTS
uint256 internal constant MAX_POINTS = 8
State Variables
curves
mapping(address user => mapping(bytes32 tenorMarketId => CurvePoint[])) public curves
Functions
constructor
constructor(address morphoMidnight) ;
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;
clearCurve
Deletes the curve of onBehalf for tenorMarketId.
function clearCurve(address onBehalf, bytes32 tenorMarketId) external;
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,
uint256 sourceMaturity,
uint256 targetMaturity,
bool userIsBuyer
) public view virtual returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
sourceTenorMarketId | bytes32 | The id of the source side of the renewal (the position being closed). |
targetTenorMarketId | bytes32 | The id of the target side of the renewal (the position being entered). |
<none> | uint256 | |
user | address | The position owner being renewed (the offer maker in the make-on-behalf flow). |
sourceMaturity | uint256 | The source market maturity (0 for Blue to Midnight migrations). |
targetMaturity | uint256 | The target market maturity (0 for Midnight to Blue exits). |
userIsBuyer | bool | The renewed user's side in the trade, derived from the migration direction. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | rate The 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);