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

Revert when submitting cap and a removal has been submitted #355

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
Id id = marketParams.id();
if (marketParams.loanToken != asset()) revert ErrorsLib.InconsistentAsset(id);
if (MORPHO.lastUpdate(id) == 0) revert ErrorsLib.MarketNotCreated();
if (config[id].removableAt != 0) revert ErrorsLib.RemovalSubmitted();
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

uint256 supplyCap = config[id].cap;
if (newSupplyCap == supplyCap) revert ErrorsLib.AlreadySet();
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ library ErrorsLib {
/// asset.
error InconsistentAsset(Id id);

/// @notice Thrown when submitting a cap for a market `id` which removal has been submitted.
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved
error RemovalSubmitted();
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

/// @notice Thrown when the supply cap has been exceeded on market `id` during a reallocation of funds.
error SupplyCapExceeded(Id id);

Expand Down
16 changes: 13 additions & 3 deletions test/forge/MarketTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ contract MarketTest is IntegrationTest {
vault.submitCap(allMarkets[0], CAP);
}

function testSubmitCapRemovalSubmitted(uint256 cap) public {
cap = bound(cap, MIN_TEST_ASSETS, MAX_TEST_ASSETS);

_setCap(allMarkets[0], 0);
vm.startPrank(CURATOR);
vault.submitMarketRemoval(allMarkets[0].id());

vm.expectRevert(ErrorsLib.RemovalSubmitted.selector);
vault.submitCap(allMarkets[0], cap);
vm.stopPrank();
}

function testSetSupplyQueue() public {
Id[] memory supplyQueue = new Id[](2);
supplyQueue[0] = allMarkets[1].id();
Expand Down Expand Up @@ -155,10 +167,8 @@ contract MarketTest is IntegrationTest {
function testUpdateWithdrawQueueRemovingDisabledMarket() public {
_setCap(allMarkets[2], 0);

vm.startPrank(CURATOR);
vm.prank(CURATOR);
vault.submitMarketRemoval(allMarkets[2].id());
vault.submitCap(allMarkets[2], CAP + 1);
vm.stopPrank();

vm.warp(block.timestamp + TIMELOCK);

Expand Down