Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Stermi review #374

Merged
merged 8 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The vault's owner has the choice to distribute back these rewards to vault depos
For more information about this use case, see the [Rewards](#rewards) section.

All actions that may be against users' interests (e.g. enabling a market with a high exposure) are subject to a timelock of minimum 24 hours.
If set, the `guardian` can revoke the action during the timelock.
The `owner`, or the `guardian` if set, can revoke the action during the timelock.
After the timelock, the action can be executed by anyone.

### Roles
Expand Down Expand Up @@ -100,15 +100,16 @@ It can:

In some cases, the vault's curator or allocators may want to keep some funds "idle", to guarantee lenders that some liquidity can be withdrawn from the vault (beyond the liquidity of each of the vault's markets).

To achieve this, it is advised to allocate "idle" funds to any market on Morpho Blue having:
To achieve this, they can deposit in markets with `address(0)` as the oracle or the collateral, ensuring that these funds can't be borrowed.
They are thus guaranteed to be liquid; though they won't generate interest.
It is advised to use these canonical configurations for "idle" markets:

- The vault's asset as loan token.
- No collateral token (`address(0)`).
- An IRM that does not trigger a revert (`address(0)`).
- An arbitrary oracle (`address(0)`).
- An arbitrary LLTV (`0`).
- `loanToken`: The vault's asset to be able to supply/withdraw funds.
- `collateralToken`: `address(0)` (not necessary since no funds will be borrowed on this market)
- `irm`: `address(0)` (Morpho Blue will skip the call to the IRM in this case, thus reducing the gas cost)
- `oracle`: `address(0)` (not necessary since no funds will be borrowed on this market)
- `lltv`: `0` (not necessary since no funds will be borrowed on this market)

Thus, these funds cannot be borrowed on Morpho Blue and are guaranteed to be liquid; though it won't generate interest.

Note that to allocate funds to this idle market, it is first required to enable its cap on MetaMorpho.
Enabling an infinite cap (`type(uint184).max`) will always allow users to deposit on the vault.
Expand Down
5 changes: 4 additions & 1 deletion src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,10 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

uint256 supplyShares = MORPHO.supplyShares(id, address(this));
(uint256 totalSupplyAssets, uint256 totalSupplyShares,,) = MORPHO.expectedMarketBalances(_marketParams(id));
// `supplyAssets` needs to be rounded up for `totalSuppliable` to be rounded down.
uint256 supplyAssets = supplyShares.toAssetsUp(totalSupplyAssets, totalSupplyShares);

totalSuppliable += supplyCap.zeroFloorSub(supplyShares.toAssetsUp(totalSupplyAssets, totalSupplyShares));
totalSuppliable += supplyCap.zeroFloorSub(supplyAssets);
}
}

Expand Down Expand Up @@ -746,6 +748,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

marketConfig.enabled = true;

// Take into account assets of the new market without applying a fee.
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));

emit EventsLib.SetWithdrawQueue(msg.sender, withdrawQueue);
Expand Down
5 changes: 3 additions & 2 deletions src/interfaces/IMetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ interface IMetaMorphoBase {
/// @notice Warning: Anyone can supply on behalf of the vault so the call to `updateWithdrawQueue` that expects a
/// market to be empty can be griefed by a front-run. To circumvent this, the allocator can simply bundle a
/// reallocation that withdraws max from this market with a call to `updateWithdrawQueue`.
/// @dev Warning: Removing a market with supply will decrease the fee accrued until the next deposit/withdrawal.
/// @dev Warning: updateWithdrawQueue is not idempotent. Submitting twice the same tx will change the queue twice.
/// @dev Warning: Removing a market with supply will decrease the fee accrued until one of the functions updating
/// `lastTotalAssets` is triggered (deposit/mint/withdraw/redeem/setFee/setFeeRecipient).
/// @dev Warning: `updateWithdrawQueue` is not idempotent. Submitting twice the same tx will change the queue twice.
/// @param indexes The indexes of each market in the previous withdraw queue, in the new withdraw queue's order.
function updateWithdrawQueue(uint256[] calldata indexes) external;

Expand Down
Loading