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

feat: review jean #127

Merged
merged 4 commits into from
Oct 2, 2023
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
19 changes: 13 additions & 6 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ 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
/// duplicate.
/// @dev Always contain all non-zero cap markets as well as all markets on which the vault supplies liquidity,
/// without duplicate.
Id[] public withdrawQueue;

PendingUint192 public pendingFee;
Expand Down Expand Up @@ -121,12 +121,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 @@ -147,6 +151,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 @@ -246,6 +252,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.
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
function sortWithdrawQueue(uint256[] calldata indexes) external onlyAllocator {
uint256 newLength = indexes.length;
uint256 currLength = withdrawQueue.length;
Expand Down Expand Up @@ -273,7 +281,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);
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

delete config[id].withdrawRank;
}
Expand Down Expand Up @@ -652,10 +660,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
10 changes: 10 additions & 0 deletions test/forge/UrdTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ contract UrdTest is BaseTest {
}

function testSetRewardsDistributor(address newRewardsDistributor) public {
vm.assume(newRewardsDistributor != vault.rewardsDistributor());
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

vm.prank(OWNER);
vault.setRewardsDistributor(newRewardsDistributor);
assertEq(vault.rewardsDistributor(), newRewardsDistributor);
}

function testAlreadySetRewardsDistributor() public {
address currentRewardsDistributor = vault.rewardsDistributor();

vm.prank(OWNER);
vm.expectRevert(bytes(ErrorsLib.ALREADY_SET));
vault.setRewardsDistributor(currentRewardsDistributor);
}

function testSetRewardsDistributorNotOwner() public {
vm.expectRevert("Ownable: caller is not the owner");
vault.setRewardsDistributor(address(0));
Expand Down
Loading