Skip to main content

TenorRouter

Git Source - Generated with forge doc

Inherits: ITenorRouter

Title: TenorRouter

Executes batches of Midnight takes with the initiator as the Midnight taker, with per-batch fill, price and crossing protections.

The initiator (msg.sender here, Bundler3.initiator() in the adapter) drives the batch and is always the Midnight taker; offer.maker is the counterparty providing liquidity for a given action.

Self-take is not explicitly rejected: offer.maker == initiator makes maker and taker the same account, so the dispatch to Midnight reverts implicitly.

Migrations on behalf of a user run by the user (as offer maker) authorizing a migration ratifier on Midnight, whose isRatified the take then runs. This router is unaware of migrations; it only takes.

Without a feeAdjuster, maxFill, minFill and the price band bound raw Midnight amounts, not net-taker amounts.

Takes triggered by nested callbacks within an action are invisible to the batch's maxFill/minFill accounting and BatchExecuted totals.

Maker-supplied policies, resolvers and clamps are untrusted code; keepers must treat quoting and dispatch as potentially reverting or gas-expensive.

Constants

_MORPHO_MIDNIGHT

Midnight internal immutable _MORPHO_MIDNIGHT

Functions

constructor

constructor(address morphoMidnight) ;

_initiator

function _initiator() internal view virtual returns (address);

execute

function execute(ExecuteParams calldata params, Action[] calldata actions)
external
virtual
override
returns (uint256, uint256, uint256);

_execute

function _execute(ExecuteParams calldata params, Action[] calldata actions)
internal
returns (uint256[3] memory totals, uint256[3] memory rawTotals);

_execute

totals holds the initiator-facing amounts after feeAdjuster.afterDispatch() has tilted them in the initiator-worsening direction, across all fills.

rawTotals holds the amounts Midnight actually matched onchain (pre-adjustment), accumulated unconditionally. The initiator is always the taker here, so these are exclusively its taker-side fills, disjoint from its maker-side fills (resting offers filled during the batch, e.g. via reentrancy) that Midnight already counts under consumed[initiator][group].

To reconcile the initiator's consumption, add rawTotals to consumed[initiator][group]: the two never overlap, so the sum does not double-count. Reconcile against rawTotals, not the fee-adjusted totals.

function _execute(ExecuteParams calldata params, Action[] calldata actions, uint256 maxFill, uint256 minFill)
internal
returns (uint256[3] memory totals, uint256[3] memory rawTotals);

_dispatchMidnightTake

function _dispatchMidnightTake(Action calldata action, address initiator, uint8 fillIndex, uint256 remaining)
internal
returns (bool, uint256, uint256, uint256, bytes32, bytes memory);

_initiatorIsBuyer

Anchors the same-side check and the slippage denominator.

The initiator is always the Midnight taker, so the result is !offer.buy.

function _initiatorIsBuyer(Action calldata action, address) internal pure returns (bool);

_sideAssetsIndex

Maps the batch's side to its loan-token axis.

Single source of truth for the FillAxis.ASSETS to BUYER_ASSETS/SELLER_ASSETS resolution shared between _execute and TenorRouterAdapterBase (sentinel and consume paths).

Callers must ensure actions.length > 0; both _execute and the adapter reject empty batches with EmptyActions before reaching this helper.

function _sideAssetsIndex(Action[] calldata actions, address initiator) internal pure returns (uint8);

_fillIndex

Resolves a FillAxis to its uint8 fill index: UNITS maps to FILL_UNITS, and ASSETS maps to the batch side via _sideAssetsIndex.

function _fillIndex(FillAxis fillAxis, Action[] calldata actions, address initiator) internal pure returns (uint8);

_updatedCredit

Returns user's up-to-date credit via updatePositionView, the value Midnight.take will internally see and mutate.

credit is not used because it does not include pending continuous-fee accrual or slashing.

function _updatedCredit(Market calldata market, bytes32 id, address user) internal view returns (uint256);

_capTakeUnits

Returns takeUnits capped by the remaining fill budget (remaining, denominated in assets or units depending on fillIndex), the offer's remaining capacity, and the optional clamp.

function _capTakeUnits(
Action calldata action,
uint256 takeUnits,
uint8 fillIndex,
uint256 remaining,
bytes32 marketId
) internal view returns (uint256);