Skip to content

Commit

Permalink
feat: review jean
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Oct 2, 2023
1 parent 4d15a2a commit 5237181
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
Id[] public supplyQueue;

/// @dev Stores the order of markets from which liquidity is withdrawn upon withdrawal.
/// @dev Always contain all non-zero cap markets or markets on which the vault supplies liquidity, without
/// @dev Always contain all non-zero cap markets and markets on which the vault supplies liquidity, without
/// duplicate.
Id[] public withdrawQueue;

Expand Down Expand Up @@ -116,12 +116,16 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
/* ONLY OWNER FUNCTIONS */

function setRiskManager(address newRiskManager) external onlyOwner {
require(newRiskManager != riskManager, ErrorsLib.ALREADY_SET);

riskManager = newRiskManager;

emit EventsLib.SetRiskManager(newRiskManager);
}

function setIsAllocator(address newAllocator, bool newIsAllocator) external onlyOwner {
require(_isAllocator[newAllocator] != newIsAllocator, ErrorsLib.ALREADY_SET);

_isAllocator[newAllocator] = newIsAllocator;

emit EventsLib.SetIsAllocator(newAllocator, newIsAllocator);
Expand All @@ -142,6 +146,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
}

function setRewardsDistributor(address newRewardsDistributor) external onlyOwner {
require(newRewardsDistributor != rewardsDistributor, ErrorsLib.ALREADY_SET);

rewardsDistributor = newRewardsDistributor;

emit EventsLib.SetRewardsDistributor(newRewardsDistributor);
Expand Down Expand Up @@ -241,6 +247,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
emit EventsLib.SetSupplyQueue(msg.sender, newSupplyQueue);
}

/// @dev Sets the withdraw queue as a permutation of the previous one, although markets with zero cap and zero
/// vault's supply can be removed.
function sortWithdrawQueue(uint256[] calldata indexes) external onlyAllocator {
uint256 newLength = indexes.length;
uint256 currLength = withdrawQueue.length;
Expand Down Expand Up @@ -268,7 +276,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
if (!seen[i]) {
Id id = withdrawQueue[i];

require(MORPHO.supplyShares(id, address(this)) == 0, ErrorsLib.MISSING_MARKET);
require(MORPHO.supplyShares(id, address(this)) == 0 && config[id].cap == 0, ErrorsLib.MISSING_MARKET);

delete config[id].withdrawRank;
}
Expand Down Expand Up @@ -647,10 +655,9 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
uint256 supplyShares = MORPHO.supplyShares(id, address(this));
(uint256 totalSupplyAssets, uint256 totalSupplyShares, uint256 totalBorrowAssets,) =
MORPHO.expectedMarketBalances(marketParams);
uint256 availableLiquidity = totalSupplyAssets - totalBorrowAssets;

return UtilsLib.min(
supplyShares.toAssetsDown(totalSupplyAssets, totalSupplyShares), totalSupplyAssets - totalBorrowAssets
);
return UtilsLib.min(supplyShares.toAssetsDown(totalSupplyAssets, totalSupplyShares), availableLiquidity);
}

/* FEE MANAGEMENT */
Expand Down

0 comments on commit 5237181

Please sign in to comment.