RouterLib
Git Source - Generated with forge doc
Title: RouterLib
Fill-sizing helpers shared by TenorRouter and ICallbackFeeAdjuster implementations.
budgetToUnits inverts a remaining fill budget in a given dimension to the maximum market units; it is used by the router's no-adjuster path and by CallbackFeeAdjuster for dimensions the fee does not land on.
netBuyerPrice and netSellerPrice compose Midnight's forward price with Tenor's effective price to get the per-unit price the taker actually pays (buyer) or receives (seller) after both onchain fees; they are used by CallbackFeeAdjuster to invert remainingBudget to maxUnits conservatively under the interest fee formula.
Constants
FILL_BUYER_ASSETS
uint8 internal constant FILL_BUYER_ASSETS = 0
FILL_SELLER_ASSETS
uint8 internal constant FILL_SELLER_ASSETS = 1
FILL_UNITS
uint8 internal constant FILL_UNITS = 2
Functions
budgetToUnits
Returns the maximum market units for a remaining fill budget in a given dimension such that the budget is not overshot when run through Midnight's forward rounding.
function budgetToUnits(
IMidnight morphoMidnight,
bytes32 marketId,
Offer calldata offer,
uint8 fillIndex,
uint256 remainingBudget
) internal view returns (uint256);
netBuyerPrice
Returns the net per-unit price the buyer-as-taker pays onchain, used to invert remainingBudget to maxUnits under the interest fee formula.
Returns the max of Midnight's price (offerPrice + settlementFee) and buyerEffectivePrice. The callback fee is zero-floored against Midnight's fee (see CallbackLib), so the max is the price the buyer actually pays and dividing remainingBudget by it cannot overshoot the budget.
function netBuyerPrice(uint256 offerPrice, uint256 settlementFee, uint256 feeRate) internal pure returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
offerPrice | uint256 | The offer price (TickLib.tickToPrice(offer.tick)). |
settlementFee | uint256 | Midnight's per-market settlement fee for the time-to-maturity. |
feeRate | uint256 | The callback fee rate, in WAD (0 = no fee, returns Midnight's price alone). |
netSellerPrice
Returns the net per-unit price the seller-as-taker receives onchain, used to invert remainingBudget to maxUnits under the interest fee formula.
Returns the min of Midnight's price (offerPrice - settlementFee, zero-floored) and sellerEffectivePrice. The callback fee is zero-floored against Midnight's fee (see CallbackLib), so the min is the price the seller actually receives and any larger units count would push the receipt past remainingBudget.
function netSellerPrice(uint256 offerPrice, uint256 settlementFee, uint256 feeRate)
internal
pure
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
offerPrice | uint256 | The offer price (TickLib.tickToPrice(offer.tick)). |
settlementFee | uint256 | Midnight's per-market settlement fee for the time-to-maturity. |
feeRate | uint256 | The callback fee rate, in WAD (0 = no fee, returns Midnight's price alone). |