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 last total assets #201

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 6 additions & 8 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,6 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

shares = _convertToSharesWithFeeAccrued(assets, totalSupply(), newTotalAssets, Math.Rounding.Floor);
_deposit(_msgSender(), receiver, assets, shares);

_updateLastTotalAssets(newTotalAssets + assets);
}

/// @inheritdoc IERC4626
Expand All @@ -491,8 +489,6 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

assets = _convertToAssetsWithFeeAccrued(shares, totalSupply(), newTotalAssets, Math.Rounding.Ceil);
_deposit(_msgSender(), receiver, assets, shares);

_updateLastTotalAssets(newTotalAssets + assets);
}

/// @inheritdoc IERC4626
Expand All @@ -507,8 +503,6 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

shares = _convertToSharesWithFeeAccrued(assets, totalSupply(), newTotalAssets, Math.Rounding.Ceil);
_withdraw(_msgSender(), receiver, owner, assets, shares);

_updateLastTotalAssets(newTotalAssets - assets);
}

/// @inheritdoc IERC4626
Expand All @@ -523,8 +517,6 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

assets = _convertToAssetsWithFeeAccrued(shares, totalSupply(), newTotalAssets, Math.Rounding.Floor);
_withdraw(_msgSender(), receiver, owner, assets, shares);

_updateLastTotalAssets(newTotalAssets - assets);
}

/// @inheritdoc IERC4626
Expand Down Expand Up @@ -607,6 +599,9 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
super._deposit(caller, owner, assets, shares);

_supplyMorpho(assets);

// `newTotalAssets + assets` cannot be used as input because of rounding errors so we must use `totalAssets`.
_updateLastTotalAssets(totalAssets());
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
}

/// @inheritdoc ERC4626
Expand All @@ -624,6 +619,9 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
if (_withdrawMorpho(assets) != 0) revert ErrorsLib.WithdrawMorphoFailed();

super._withdraw(caller, receiver, owner, assets, shares);

// `newTotalAssets - assets` cannot be used as input because of rounding errors so we must use `totalAssets`.
_updateLastTotalAssets(totalAssets());
}

/* INTERNAL */
Expand Down
2 changes: 1 addition & 1 deletion test/forge/FeeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract FeeTest is BaseTest {
vm.prank(SUPPLIER);
vault.deposit(deposited, ONBEHALF);

assertApproxEqAbs(vault.lastTotalAssets(), vault.totalAssets(), 1, "lastTotalAssets");
assertEq(vault.lastTotalAssets(), vault.totalAssets(), "lastTotalAssets");
}

function testAccrueFeeWithinABlock(uint256 deposited, uint256 withdrawn) public {
Expand Down
Loading