Skip to content

Commit

Permalink
refactor: minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Feb 17, 2024
1 parent 6335a15 commit 941e53c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
14 changes: 8 additions & 6 deletions src/PublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,26 @@ contract PublicAllocator is IPublicAllocatorStaticTyping {

MORPHO.accrueInterest(withdrawals[i].marketParams);
uint256 assets = MORPHO.expectedSupplyAssets(withdrawals[i].marketParams, address(VAULT));

uint128 withdrawnAssets = withdrawals[i].amount;
totalWithdrawn += withdrawnAssets;
flowCap[id].maxIn += withdrawnAssets;

if (flowCap[id].maxOut < withdrawnAssets) revert ErrorsLib.MaxOutflowExceeded(id);

flowCap[id].maxIn += withdrawnAssets;
flowCap[id].maxOut -= withdrawnAssets;
if (assets < withdrawnAssets) revert ErrorsLib.NotEnoughSupply(id);
allocations[i].assets = assets - withdrawnAssets;
allocations[i].marketParams = withdrawals[i].marketParams;

totalWithdrawn += withdrawnAssets;

emit EventsLib.PublicWithdrawal(id, withdrawnAssets);
}

allocations[withdrawals.length].marketParams = supplyMarketParams;
allocations[withdrawals.length].assets = type(uint256).max;
if (flowCap[supplyMarketId].maxIn < totalWithdrawn) revert ErrorsLib.MaxInflowExceeded(supplyMarketId);

flowCap[supplyMarketId].maxIn -= totalWithdrawn;
flowCap[supplyMarketId].maxOut += totalWithdrawn;
allocations[withdrawals.length].marketParams = supplyMarketParams;
allocations[withdrawals.length].assets = type(uint256).max;

VAULT.reallocate(allocations);

Expand Down
3 changes: 0 additions & 3 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ library ErrorsLib {
/// @notice Thrown when the PublicAllocatorFactory is called with a vault not made by the MetaMorphoFactory.
error NotMetaMorpho();

/// @notice Thrown when attempting to withdraw more than the available supply of a market.
error NotEnoughSupply(Id id);

/// @notice Thrown when attempting to withdraw more than the max outflow of a market.
error MaxOutflowExceeded(Id id);

Expand Down
18 changes: 0 additions & 18 deletions test/PublicAllocatorTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -485,24 +485,6 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setFlowCaps(flowCaps);
}

function testNotEnoughSupply() public {
uint128 flow = 1e18;
// Set flow limits with withdraw market's maxIn to max
flowCaps.push(FlowConfig(idleParams.id(), FlowCap(MAX_SETTABLE_FLOW_CAP, MAX_SETTABLE_FLOW_CAP)));
flowCaps.push(FlowConfig(allMarkets[0].id(), FlowCap(MAX_SETTABLE_FLOW_CAP, MAX_SETTABLE_FLOW_CAP)));
vm.prank(OWNER);
publicAllocator.setFlowCaps(flowCaps);

withdrawals.push(Withdrawal(idleParams, flow));
publicAllocator.reallocateTo(withdrawals, allMarkets[0]);

delete withdrawals;

withdrawals.push(Withdrawal(allMarkets[0],flow+1));
vm.expectRevert(abi.encodeWithSelector(ErrorsLib.NotEnoughSupply.selector,allMarkets[0].id()));
publicAllocator.reallocateTo(withdrawals,idleParams);
}

function testMaxOutflowExceeded() public {
uint128 cap = 1e18;
// Set flow limits with withdraw market's maxIn to max
Expand Down

0 comments on commit 941e53c

Please sign in to comment.