Skip to content

Commit

Permalink
Merge pull request #351 from morpho-org/refactor/remove-automatic-sup…
Browse files Browse the repository at this point in the history
…ply-queue-push

Remove automatic supply queue push
  • Loading branch information
MerlinEgalite authored Dec 22, 2023
2 parents d261b27 + 295f621 commit dab10a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -738,17 +738,13 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

if (supplyCap > 0) {
if (!marketConfig.enabled) {
supplyQueue.push(id);
withdrawQueue.push(id);

if (
supplyQueue.length > ConstantsLib.MAX_QUEUE_LENGTH
|| withdrawQueue.length > ConstantsLib.MAX_QUEUE_LENGTH
) {
revert ErrorsLib.MaxQueueLengthExceeded();
}
if (withdrawQueue.length > ConstantsLib.MAX_QUEUE_LENGTH) revert ErrorsLib.MaxQueueLengthExceeded();

marketConfig.enabled = true;

emit EventsLib.SetWithdrawQueue(msg.sender, withdrawQueue);
}

marketConfig.removableAt = 0;
Expand Down
1 change: 1 addition & 0 deletions test/forge/MetaMorphoInternalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ contract MetaMorphoInternalTest is InternalTest {

Id id = allMarkets[0].id();
_setCap(id, CAP);
supplyQueue = [id];

loanToken.setBalance(SUPPLIER, suppliedAmount);
vm.prank(SUPPLIER);
Expand Down
13 changes: 13 additions & 0 deletions test/forge/helpers/IntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ contract IntegrationTest is BaseTest {
function _setCap(MarketParams memory marketParams, uint256 newCap) internal {
Id id = marketParams.id();
uint256 cap = vault.config(id).cap;
bool isEnabled = vault.config(id).enabled;
if (newCap == cap) return;

PendingUint192 memory pendingCap = vault.pendingCap(id);
Expand All @@ -115,6 +116,18 @@ contract IntegrationTest is BaseTest {
vault.acceptCap(id);

assertEq(vault.config(id).cap, newCap, "_setCap");

if (newCap > 0) {
if (!isEnabled) {
Id[] memory newSupplyQueue = new Id[](vault.supplyQueueLength() + 1);
for (uint256 k; k < vault.supplyQueueLength(); k++) {
newSupplyQueue[k] = vault.supplyQueue(k);
}
newSupplyQueue[vault.supplyQueueLength()] = id;
vm.prank(ALLOCATOR);
vault.setSupplyQueue(newSupplyQueue);
}
}
}

function _sortSupplyQueueIdleLast() internal {
Expand Down

0 comments on commit dab10a1

Please sign in to comment.