CollateralTransferLib
Git Source - Generated with forge doc
Title: CollateralTransferLib
Shared Midnight to Midnight collateral transfer logic for callback contracts.
The calling callback must be authorized on Morpho Midnight by the borrower for both collateral withdrawal (source market) and collateral supply (target market).
Functions
transferCollaterals
Transfers collateral from the source to the target market, pro-rata to the repaid debt, rounded down (all on the final fill, to avoid dust).
The final fill is detected by exact equality repaidUnits == sourceDebtBefore; with a nonzero fee, fills sized to the remaining offer capacity may never satisfy it, leaving residual debt and collateral on the source market until an exact-repayment fill occurs.
Only transfers tokens listed in both markets; source-only tokens are silently skipped (left on source).
function transferCollaterals(
IMidnight morphoMidnight,
Market memory sourceMarket,
Market memory targetMarket,
address borrower,
bytes32 sourceMarketId,
uint256 sourceDebtBefore,
uint256 repaidUnits
) internal returns (address[] memory collateralTokens, uint256[] memory collateralAmounts);
Returns
| Name | Type | Description |
|---|---|---|
collateralTokens | address[] | Token addresses, mirroring sourceMarket.collateralParams order. |
collateralAmounts | uint256[] | Amount transferred per token; 0 if the token was skipped, the source had no balance, or the pro-rata amount rounded down to zero. |