MidnightAdapterBase
Git Source - Generated with forge doc
Inherits: CoreAdapter, IMidnightAdapter
Title: MidnightAdapterBase
Base adapter for Morpho Midnight operations via Bundler3.
Inherit this in any adapter that needs Morpho Midnight support.
Constants
MORPHO_MIDNIGHT
The Morpho Midnight contract.
IMidnight public immutable MORPHO_MIDNIGHT
Functions
constructor
constructor(address morphoMidnight) ;
Parameters
| Name | Type | Description |
|---|---|---|
morphoMidnight | address | The Morpho Midnight contract address. |
midnightRepay
Repays debt on Morpho Midnight on behalf of the initiator.
Strictly uses tokens already on the adapter (does not pull from initiator).
function midnightRepay(
Market calldata market,
uint256 assets,
uint256 debt,
address callbackAddr,
bytes calldata callbackData
) external onlyBundler3;
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | The market to repay. |
assets | uint256 | The amount of assets to repay. Pass type(uint256).max to use the adapter's full balance. |
debt | uint256 | The amount to repay. Pass type(uint256).max to repay the initiator's entire debt. |
callbackAddr | address | The Midnight.repay callback target, forwarded as-is. Pass address(0) for no callback. MidnightAdapterBase does not implement an onRepay handler. |
callbackData | bytes | Arbitrary data forwarded to callbackAddr.onRepay. Unused when callbackAddr == address(0). |
midnightSupplyCollateral
Supplies collateral to Morpho Midnight on behalf of the initiator.
Strictly uses tokens already on the adapter (does not pull from initiator).
function midnightSupplyCollateral(Market calldata market, uint256 collateralIndex, uint256 assets)
external
onlyBundler3;
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | The market to supply collateral to. |
collateralIndex | uint256 | The index of the collateral in market.collateralParams. |
assets | uint256 | The amount of collateral to supply. Pass type(uint256).max to use the adapter's full balance. |
midnightWithdrawCollateral
Withdraws collateral from Morpho Midnight on behalf of the initiator.
function midnightWithdrawCollateral(
Market calldata market,
uint256 collateralIndex,
uint256 assets,
address receiver
) external onlyBundler3;
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | The market to withdraw collateral from. |
collateralIndex | uint256 | The index of the collateral in market.collateralParams. |
assets | uint256 | The amount of collateral to withdraw. Pass type(uint256).max to withdraw the initiator's full collateral balance. |
receiver | address | The account receiving the withdrawn collateral. |
midnightWithdraw
Withdraws from a market on Morpho Midnight on behalf of the initiator.
function midnightWithdraw(Market calldata market, uint256 units, address receiver) external onlyBundler3;
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | The market to withdraw from. |
units | uint256 | The amount of market units to withdraw. Pass type(uint256).max to withdraw all the initiator's credit after position update (slashing + fee accrual). |
receiver | address | The account receiving the withdrawn assets. |
midnightSetConsumed
Sets the consumed amount for an offer group on Morpho Midnight on behalf of the initiator.
Used for atomic cancel operations (cancel + withdraw, cancel + disable auto-renewal). Passing
type(uint256).max cancels all offers in the group.
function midnightSetConsumed(bytes32 group, uint256 amount) external onlyBundler3;
Parameters
| Name | Type | Description |
|---|---|---|
group | bytes32 | The offer group to set consumed amount for. |
amount | uint256 | The new consumed amount (must be >= current consumed amount). |
midnightFlashLoan
Triggers a flash loan on Morpho Midnight.
The flash-loaned tokens land on this adapter; the reenter actions in data must consume (and repay)
them within the loan, as any balance left on the adapter is skimmable by a later bundle.
function midnightFlashLoan(address[] calldata tokens, uint256[] calldata assets, bytes calldata data)
external
onlyBundler3;
Parameters
| Name | Type | Description |
|---|---|---|
tokens | address[] | The addresses of the tokens to flash loan. |
assets | uint256[] | The amounts of assets to flash loan, paired with tokens by index. |
data | bytes | Arbitrary data forwarded to onFlashLoan (bundler3 reenter payload). |
onFlashLoan
Callback from Morpho Midnight during flash loan.
Allows reentering bundler during Morpho Midnight.flashLoan
caller must be this adapter. Legitimate flash loans originate from midnightFlashLoan
(which calls Midnight.flashLoan as msg.sender = adapter). Rejecting other callers
blocks an external party from forcing the adapter onto a flashLoan payer slot,
where any token with a residual max allowance (set by a prior midnightFlashLoan)
would otherwise let them consume the bundle's reenter slot at no cost.
function onFlashLoan(address caller, address[] memory, uint256[] memory, bytes memory data)
external
returns (bytes32);
Parameters
| Name | Type | Description |
|---|---|---|
caller | address | |
<none> | address[] | |
<none> | uint256[] | |
data | bytes | Bytes containing an abi-encoded Call[] (must be memory per IFlashLoanCallback interface). |
_midnightCallback
Handles callbacks from Morpho Midnight (which use bytes memory).
Sender validation already done in caller.
Manual call needed because CoreAdapter.reenterBundler3 expects calldata, but Morpho Midnight callbacks provide memory
Bundler3 allows at most one reentry per top-level multicall slot; a second Bundler3.reenter inside
the same slot reverts with IncorrectReenterHash. Bundles where more than one inner action triggers
a Midnight callback that reenters here (e.g. multiple Midnight take actions with a reentrant
takerCallback dispatched by TenorRouter) must split those actions across separate top-level
Bundler3.multicall Call entries; each entry gets its own reenterHash.
function _midnightCallback(bytes memory data) internal;