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

[NES-294] [Fix] Slowmist remediations update #122

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion nest/src/AggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder {
uint256 assets,
address receiver,
address controller
) public override(ComponentToken, IComponentToken, ERC4626Upgradeable) returns (uint256 shares) {
) public override(ComponentToken, IComponentToken) returns (uint256 shares) {
if (_getAggregateTokenStorage().paused) {
revert DepositPaused();
}
Expand Down
33 changes: 26 additions & 7 deletions nest/src/ComponentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,22 @@ abstract contract ComponentToken is
if ($.sharesDepositRequest[controller] < shares) {
revert InsufficientRequestBalance(controller, shares, 1);
}
// Use the pre-calculated assets amount from when deposit was notified

// Get the pre-calculated values
uint256 claimableShares = $.sharesDepositRequest[controller];
assets = $.claimableDepositRequest[controller];

// Verify shares match exactly
if (shares != claimableShares) {
ungaro marked this conversation as resolved.
Show resolved Hide resolved
revert InvalidDepositAmount(shares, claimableShares);
}

// Reset state atomically
$.claimableDepositRequest[controller] = 0;
$.sharesDepositRequest[controller] = 0;
} else {
assets = previewMint(shares);
_deposit(msg.sender, receiver, assets, shares);
SafeERC20.safeTransferFrom(IERC20(asset()), controller, address(this), assets);
}
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
Expand Down Expand Up @@ -547,7 +556,7 @@ abstract contract ComponentToken is
address receiver,
address controller
) public virtual override(ERC4626Upgradeable, IERC7540) nonReentrant returns (uint256 shares) {
if (shares == 0) {
if (assets == 0) {
revert ZeroAmount();
}
if (msg.sender != controller) {
Expand All @@ -556,19 +565,29 @@ abstract contract ComponentToken is

ComponentTokenStorage storage $ = _getComponentTokenStorage();
if ($.asyncRedeem) {
// Use the pre-calculated assets amount from when redeem was notified
if ($.assetsRedeemRequest[controller] < assets) {
revert InsufficientRequestBalance(controller, assets, 3);
}
// Get the pre-calculated values
uint256 claimableAssets = $.assetsRedeemRequest[controller];
shares = $.claimableRedeemRequest[controller];

// Verify assets match exactly
if (assets != claimableAssets) {
revert InvalidRedeemAmount(assets, claimableAssets);
}

// Reset state atomically
$.claimableRedeemRequest[controller] = 0;
$.assetsRedeemRequest[controller] = 0;

// No _burn needed here as shares were already burned in requestRedeem
SafeERC20.safeTransfer(IERC20(asset()), receiver, assets);
emit Withdraw(controller, receiver, controller, assets, shares);
} else {
shares = previewWithdraw(assets);
_withdraw(msg.sender, receiver, msg.sender, assets, shares);
_withdraw(controller, receiver, controller, assets, shares);
}
_burn(msg.sender, shares);
emit Withdraw(msg.sender, receiver, msg.sender, assets, shares);
return shares;
}

Expand Down
Loading