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
Changes from 1 commit
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
10 changes: 8 additions & 2 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 @@ -365,6 +365,9 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

/// @inheritdoc IMetaMorphoBase
function reallocate(MarketAllocation[] calldata allocations) external onlyAllocatorRole {
// Accrue fee to avoid taking a fee on withdrawn donations.
_accrueFee();

uint256 totalSupplied;
uint256 totalWithdrawn;
for (uint256 i; i < allocations.length; ++i) {
Expand Down Expand Up @@ -413,6 +416,9 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
}

if (totalWithdrawn != totalSupplied) revert ErrorsLib.InconsistentReallocation();

// Update `lastTotalAssets` to avoid taking a fee on withdrawn donations.
_updateLastTotalAssets(totalAssets());
}

/* REVOKE FUNCTIONS */
Expand Down