TenorRouter
Git Source - Generated with forge doc
Inherits: ITenorRouter
Title: TenorRouter
Executes batches of Midnight takes with per-batch fill, price, continuous-fee 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 reverts implicitly.
Without a feeAdjuster, maxFill, minFill and the price band bound raw Midnight amounts, not net-taker amounts.
Takes from nested callbacks are invisible to the batch's maxFill/minFill accounting and BatchExecuted totals.
Maker-supplied policies, resolvers and clamps are untrusted code; quoting and dispatch may revert or burn gas.
Continuous-fee protection assumes the continuous fee does not change mid-execution.
Constants
_MORPHO_MIDNIGHT
IMidnight internal immutable _MORPHO_MIDNIGHT;
Functions
constructor
constructor(address morphoMidnight);
Parameters
| Name | Type | Description |
|---|---|---|
morphoMidnight | address |
_initiator
function _initiator() internal view virtual returns (address);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address |
execute
Executes a batch of direct midnight.take actions, accumulating buyer/seller/units totals and
enforcing per-batch fill bounds and price slippage. The initiator is the Midnight taker for every action.
All actions must share actions[0]'s market (offer.market).
All actions must share actions[0]'s side (_initiatorIsBuyer(action, initiator)).
fillAxis == ASSETS resolves to the batch side; slippage uses the same axis.
function execute(ExecuteParams calldata params, Action[] calldata actions)
external
virtual
override
returns (uint256, uint256, uint256);
Parameters
| Name | Type | Description |
|---|---|---|
params | ExecuteParams | |
actions | Action[] |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total buyer-side asset flow (post-fee). |
<none> | uint256 | The total seller-side asset flow (post-fee). |
<none> | uint256 | The total market units filled. |
_execute
function _execute(ExecuteParams calldata params, Action[] calldata actions)
internal
returns (uint256[3] memory totals, uint256[3] memory rawTotals);
Parameters
| Name | Type | Description |
|---|---|---|
params | ExecuteParams | |
actions | Action[] |
Returns
| Name | Type | Description |
|---|---|---|
totals | uint256[3] | |
rawTotals | uint256[3] |
_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 that Midnight already counts under consumed[initiator][group]: resting
offers filled during the batch, e.g. via reentrancy.
To reconcile the initiator's consumption, add rawTotals to consumed[initiator][group]: the two never
overlap, so the sum does not double-count.
function _execute(ExecuteParams calldata params, Action[] calldata actions, uint256 maxFill, uint256 minFill)
internal
returns (uint256[3] memory totals, uint256[3] memory rawTotals);
Parameters
| Name | Type | Description |
|---|---|---|
params | ExecuteParams | |
actions | Action[] | |
maxFill | uint256 | |
minFill | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
totals | uint256[3] | |
rawTotals | uint256[3] |
_dispatchMidnightTake
function _dispatchMidnightTake(Action calldata action, address initiator, uint8 fillIndex, uint256 remaining)
internal
returns (bool, uint256, uint256, uint256, bytes32, bytes memory);
Parameters
| Name | Type | Description |
|---|---|---|
action | Action | |
initiator | address | |
fillIndex | uint8 | |
remaining | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | |
<none> | uint256 | |
<none> | uint256 | |
<none> | uint256 | |
<none> | bytes32 | |
<none> | bytes |
_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);
Parameters
| Name | Type | Description |
|---|---|---|
action | Action | |
_ | address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | 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);
Parameters
| Name | Type | Description |
|---|---|---|
actions | Action[] | |
initiator | address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | 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);
Parameters
| Name | Type | Description |
|---|---|---|
fillAxis | FillAxis | |
actions | Action[] | |
initiator | address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | 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);
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | |
id | bytes32 | |
user | address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | 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.
remaining <= maxFill <= type(uint128).max, so adjuster/inversion WAD math cannot overflow.
function _capTakeUnits(
Action calldata action,
uint256 takeUnits,
uint8 fillIndex,
uint256 remaining,
bytes32 marketId
) internal view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
action | Action | |
takeUnits | uint256 | |
fillIndex | uint8 | |
remaining | uint256 | |
marketId | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 |