Skip to main content

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

NameTypeDescription
morphoMidnightaddress

_initiator​

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

Returns

NameTypeDescription
<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

NameTypeDescription
paramsExecuteParams
actionsAction[]

Returns

NameTypeDescription
<none>uint256The total buyer-side asset flow (post-fee).
<none>uint256The total seller-side asset flow (post-fee).
<none>uint256The total market units filled.

_execute​

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

Parameters

NameTypeDescription
paramsExecuteParams
actionsAction[]

Returns

NameTypeDescription
totalsuint256[3]
rawTotalsuint256[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

NameTypeDescription
paramsExecuteParams
actionsAction[]
maxFilluint256
minFilluint256

Returns

NameTypeDescription
totalsuint256[3]
rawTotalsuint256[3]

_dispatchMidnightTake​

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

Parameters

NameTypeDescription
actionAction
initiatoraddress
fillIndexuint8
remaininguint256

Returns

NameTypeDescription
<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

NameTypeDescription
actionAction
_address

Returns

NameTypeDescription
<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

NameTypeDescription
actionsAction[]
initiatoraddress

Returns

NameTypeDescription
<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

NameTypeDescription
fillAxisFillAxis
actionsAction[]
initiatoraddress

Returns

NameTypeDescription
<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

NameTypeDescription
marketMarket
idbytes32
useraddress

Returns

NameTypeDescription
<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 &lt;= maxFill &lt;= 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

NameTypeDescription
actionAction
takeUnitsuint256
fillIndexuint8
remaininguint256
marketIdbytes32

Returns

NameTypeDescription
<none>uint256