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

Update lastTotalAsset in updateWithdrawQueue #2

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 17 additions & 1 deletion src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {MorphoLib} from "../lib/morpho-blue/src/libraries/periphery/MorphoLib.so
import {MarketParamsLib} from "../lib/morpho-blue/src/libraries/MarketParamsLib.sol";
import {IERC20Metadata} from "../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {MorphoBalancesLib} from "../lib/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol";
import {MorphoStorageLib} from "../lib/morpho-blue/src/libraries/periphery/MorphoStorageLib.sol";

import {Multicall} from "../lib/openzeppelin-contracts/contracts/utils/Multicall.sol";
import {Ownable2Step, Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol";
Expand All @@ -48,6 +49,7 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
using MorphoLib for IMorpho;
using SharesMathLib for uint256;
using MorphoBalancesLib for IMorpho;
using MorphoStorageLib for Id;
using MarketParamsLib for MarketParams;
using PendingLib for MarketConfig;
using PendingLib for PendingUint192;
Expand Down Expand Up @@ -350,6 +352,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
bool[] memory seen = new bool[](currLength);
Id[] memory newWithdrawQueue = new Id[](newLength);

uint256 lostSupply;
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

for (uint256 i; i < newLength; ++i) {
uint256 prevIndex = indexes[i];

Expand All @@ -367,12 +371,20 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

if (config[id].cap != 0) revert ErrorsLib.InvalidMarketRemovalNonZeroCap(id);

if (MORPHO.supplyShares(id, address(this)) != 0) {
uint256 supplyShares = MORPHO.supplyShares(id, address(this));

if (supplyShares != 0) {
if (config[id].removableAt == 0) revert ErrorsLib.InvalidMarketRemovalNonZeroSupply(id);

if (block.timestamp < config[id].removableAt) {
revert ErrorsLib.InvalidMarketRemovalTimelockNotElapsed(id);
}

bytes32[] memory slot = new bytes32[](1);
slot[0] = id.marketTotalSupplyAssetsAndSharesSlot();
bytes32[] memory res = MORPHO.extSloads(slot);

lostSupply += supplyShares.toAssetsDown(uint128(uint256(res[0])), uint256(res[0] >> 128));
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved
}

delete config[id];
Expand All @@ -381,6 +393,10 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

withdrawQueue = newWithdrawQueue;

// Accrue interests on all the enabled markets except the removed ones.
_updateLastTotalAssets(lastTotalAssets.zeroFloorSub(lostSupply));
_updateLastTotalAssets(_accrueFee());
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved

emit EventsLib.SetWithdrawQueue(_msgSender(), newWithdrawQueue);
}

Expand Down
Loading