@@ -25,13 +25,15 @@ library MorphoLib {
2525 /// @notice Settles accrued interest on the given market into Morpho's stored state.
2626 /// @dev Must be called in the same tx before any read that depends on up-to-the-block debt (e.g. `debt`,
2727 /// `healthFactor`, `maxBorrowAtHealthFactor`). Without this, reads reflect the last-touched block's state.
28+ /// @param morpho The Morpho Blue singleton.
2829 /// @param market Morpho market parameters identifying the position.
2930 function accrueInterest (IMorpho morpho , MarketParams memory market ) internal {
3031 morpho.accrueInterest (market);
3132 }
3233
3334 /// @notice Supplies `assets` of collateral token from this contract to the market on behalf of itself.
3435 /// @dev Assumes the caller has already approved the Morpho singleton for `assets` of the collateral token.
36+ /// @param morpho The Morpho Blue singleton.
3537 /// @param market Morpho market parameters identifying the position.
3638 /// @param assets Amount of collateral to supply, in token units.
3739 function supplyCollateral (IMorpho morpho , MarketParams memory market , uint256 assets ) internal {
@@ -41,6 +43,7 @@ library MorphoLib {
4143 /// @notice Borrows `assets` of loan token against this contract's collateral, with the loan tokens sent to itself.
4244 /// @dev Passes `shares = 0` so Morpho interprets the call as an asset-denominated borrow. Reverts inside Morpho if
4345 /// the resulting position would exceed LLTV.
46+ /// @param morpho The Morpho Blue singleton.
4447 /// @param market Morpho market parameters identifying the position.
4548 /// @param assets Amount of loan token to borrow, in token units.
4649 function borrow (IMorpho morpho , MarketParams memory market , uint256 assets ) internal {
@@ -51,6 +54,7 @@ library MorphoLib {
5154 /// @notice Repay `assets` units of the loan token to Morpho, reducing this contract's debt on the market.
5255 /// @dev `onBehalf = address(this)` repays this contract's own position; the trailing `""` is Morpho's callback
5356 /// data, unused.
57+ /// @param morpho The Morpho Blue singleton.
5458 /// @param market Morpho market parameters identifying the position.
5559 /// @param assets Amount of loan token to repay, in token units.
5660 /// @return assetsRepaid Mirrors `assets` (Morpho's return convention).
@@ -68,8 +72,9 @@ library MorphoLib {
6872 /// an asset amount back to shares either over-shoots (repaying `debt()` over-burns -> revert) or under-shoots
6973 /// (leaving dust borrow shares that block a full-collateral withdrawal). Repaying by shares clears it precisely.
7074 /// Morpho pulls the required loan token from this contract's balance, so the caller must pre-fund it.
71- /// @return assetsRepaid Loan token consumed to clear the position .
75+ /// @param morpho The Morpho Blue singleton .
7276 /// @param market Morpho market parameters identifying the position.
77+ /// @return assetsRepaid Loan token consumed to clear the position.
7378 function repayAll (IMorpho morpho , MarketParams memory market ) internal returns (uint256 assetsRepaid ) {
7479 uint256 borrowShares = uint256 (morpho.position (market.id (), address (this )).borrowShares);
7580 if (borrowShares == 0 ) return 0 ;
@@ -83,13 +88,15 @@ library MorphoLib {
8388 ///
8489 /// Both the `onBehalf` and `receiver` arguments to Morpho are `address(this)`: the collateral belongs to
8590 /// this contract.
91+ /// @param morpho The Morpho Blue singleton.
8692 /// @param market Morpho market parameters identifying the position.
8793 /// @param assets Amount of collateral to withdraw, in token units.
8894 function withdrawCollateral (IMorpho morpho , MarketParams memory market , uint256 assets ) internal {
8995 morpho.withdrawCollateral (market, assets, address (this ), address (this ));
9096 }
9197
9298 /// @notice Returns this contract's collateral balance in the given market, in raw collateral-token units.
99+ /// @param morpho The Morpho Blue singleton.
93100 /// @param market Morpho market parameters identifying the position.
94101 function collateral (IMorpho morpho , MarketParams memory market ) internal view returns (uint256 ) {
95102 return uint256 (morpho.position (market.id (), address (this )).collateral);
@@ -107,6 +114,7 @@ library MorphoLib {
107114 /// so the first borrower cannot manipulate it. They must be included in every conversion to match Morpho's internal
108115 /// accounting.
109116 /// CAUTION: Call `accrueInterest(market)` first if an up-to-the-block value is required.
117+ /// @param morpho The Morpho Blue singleton.
110118 /// @param market Morpho market parameters identifying the position.
111119 function debt (IMorpho morpho , MarketParams memory market ) internal view returns (uint256 ) {
112120 Position memory pos = morpho.position (market.id (), address (this ));
@@ -162,6 +170,7 @@ library MorphoLib {
162170
163171 /// @notice Returns the maximum loan-token amount borrowable against this contract's current collateral balance.
164172 /// @dev Convenience wrapper over `maxBorrowFor(collateral(market))`.
173+ /// @param morpho The Morpho Blue singleton.
165174 /// @param market Morpho market parameters identifying the position.
166175 function maxBorrow (IMorpho morpho , MarketParams memory market ) internal view returns (uint256 ) {
167176 return maxBorrowFor (market, collateral (morpho, market));
@@ -174,6 +183,7 @@ library MorphoLib {
174183 /// an unborrowed position cannot be liquidated.
175184 /// CAUTION: Call `accrueInterest(market)` first if an up-to-the-block value is required, since `debt` reads stored
176185 /// state and does not include unaccrued interest.
186+ /// @param morpho The Morpho Blue singleton.
177187 /// @param market Morpho market parameters identifying the position.
178188 function healthFactor (IMorpho morpho , MarketParams memory market ) internal view returns (uint256 ) {
179189 uint256 debtAmount = debt (morpho, market);
@@ -186,6 +196,7 @@ library MorphoLib {
186196 /// implies a health factor at or below the target (i.e. borrowing more would push the position deeper toward
187197 /// liquidation than requested).
188198 /// CAUTION: Call `accrueInterest(market)` first if an up-to-the-block value is required.
199+ /// @param morpho The Morpho Blue singleton.
189200 /// @param market Morpho market parameters identifying the position.
190201 /// @param targetHealthFactor WAD-scaled target health factor (WAD = liquidation threshold).
191202 function maxBorrowAtHealthFactor (IMorpho morpho , MarketParams memory market , uint256 targetHealthFactor )
0 commit comments