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

fix(reallocate): prevent withdrawing from market not enabled #358

Merged
merged 4 commits into from
Dec 27, 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
8 changes: 4 additions & 4 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
if (newFee > ConstantsLib.MAX_FEE) revert ErrorsLib.MaxFeeExceeded();
if (newFee != 0 && feeRecipient == address(0)) revert ErrorsLib.ZeroFeeRecipient();

// Accrue interest using the previous fee set before changing it.
// Accrue fee using the previous fee set before changing it.
_updateLastTotalAssets(_accrueFee());

// Safe "unchecked" cast because newFee <= MAX_FEE.
Expand All @@ -243,7 +243,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
if (newFeeRecipient == feeRecipient) revert ErrorsLib.AlreadySet();
if (newFeeRecipient == address(0) && fee != 0) revert ErrorsLib.ZeroFeeRecipient();

// Accrue interest to the previous fee recipient set before changing it.
// Accrue fee to the previous fee recipient set before changing it.
_updateLastTotalAssets(_accrueFee());

feeRecipient = newFeeRecipient;
Expand Down Expand Up @@ -294,7 +294,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
/// @inheritdoc IMetaMorphoBase
function submitMarketRemoval(Id id) external onlyCuratorRole {
if (config[id].removableAt != 0) revert ErrorsLib.AlreadySet();
if (!config[id].enabled) revert ErrorsLib.MarketNotEnabled();
if (!config[id].enabled) revert ErrorsLib.MarketNotEnabled(id);

_setCap(id, 0);

Expand Down Expand Up @@ -375,7 +375,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
uint256 withdrawn = supplyAssets.zeroFloorSub(allocation.assets);

if (withdrawn > 0) {
if (allocation.marketParams.loanToken != asset()) revert ErrorsLib.InconsistentAsset(id);
if (!config[id].enabled) revert ErrorsLib.MarketNotEnabled(id);
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved

// Guarantees that unknown frontrunning donations can be withdrawn, in order to disable a market.
uint256 shares;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ library ErrorsLib {
/// @notice Thrown when submitting a cap for a market which does not exist.
error MarketNotCreated();

/// @notice Thrown when submitting a non previously enabled market for removal.
error MarketNotEnabled();
/// @notice Thrown when interacting with a non previously enabled market `id`.
error MarketNotEnabled(Id id);
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved

/// @notice Thrown when the submitted timelock is above the max timelock.
error AboveMaxTimelock();
Expand Down
4 changes: 2 additions & 2 deletions test/forge/ReallocateWithdrawTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract ReallocateWithdrawTest is IntegrationTest {
assertEq(_idle(), INITIAL_DEPOSIT, "idle");
}

function testReallocateWithdrawInconsistentAsset() public {
function testReallocateWithdrawMarketNotEnabled() public {
ERC20Mock loanToken2 = new ERC20Mock("loan2", "B2");
allMarkets[0].loanToken = address(loanToken2);
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -75,7 +75,7 @@ contract ReallocateWithdrawTest is IntegrationTest {
allocations.push(MarketAllocation(allMarkets[0], 0));

vm.prank(ALLOCATOR);
vm.expectRevert(abi.encodeWithSelector(ErrorsLib.InconsistentAsset.selector, allMarkets[0].id()));
vm.expectRevert(abi.encodeWithSelector(ErrorsLib.MarketNotEnabled.selector, allMarkets[0].id()));
vault.reallocate(allocations);
}

Expand Down
2 changes: 1 addition & 1 deletion test/forge/TimelockTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ contract TimelockTest is IntegrationTest {
}

function testSubmitMarketRemovalMarketNotEnabled() public {
vm.expectRevert(ErrorsLib.MarketNotEnabled.selector);
vm.expectRevert(abi.encodeWithSelector(ErrorsLib.MarketNotEnabled.selector, allMarkets[1].id()));
vm.prank(CURATOR);
vault.submitMarketRemoval(allMarkets[1].id());
}
Expand Down
Loading