Skip to content

Commit

Permalink
Revert "use calculated amounts between async deposit and redeem"
Browse files Browse the repository at this point in the history
This reverts commit e94addd.
  • Loading branch information
ungaro committed Dec 9, 2024
1 parent e94addd commit 138a1d8
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions nest/src/ComponentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,23 @@ abstract contract ComponentToken is
}

ComponentTokenStorage storage $ = _getComponentTokenStorage();
assets = convertToAssets(shares);

if ($.asyncDeposit) {
// For async mints, use pre-calculated values
if ($.sharesDepositRequest[controller] < shares) {
revert InsufficientRequestBalance(controller, shares, 1);
if ($.claimableDepositRequest[controller] < assets) {
revert InsufficientRequestBalance(controller, assets, 1);
}
assets = $.claimableDepositRequest[controller];
$.claimableDepositRequest[controller] = 0;
$.sharesDepositRequest[controller] = 0;
$.claimableDepositRequest[controller] -= assets;
$.sharesDepositRequest[controller] -= shares;
} else {
// For sync mints, calculate and transfer in same transaction
assets = convertToAssets(shares);
if (!IERC20(asset()).transferFrom(controller, address(this), assets)) {
revert InsufficientBalance(IERC20(asset()), controller, assets);
}
}

_mint(receiver, shares);

emit Deposit(controller, receiver, assets, shares);
return assets;
}

/// @inheritdoc IComponentToken
Expand Down Expand Up @@ -567,15 +564,23 @@ abstract contract ComponentToken is
ComponentTokenStorage storage $ = _getComponentTokenStorage();

if ($.asyncRedeem) {
// For async withdraws, use pre-calculated values
if ($.assetsRedeemRequest[controller] < assets) {
revert InsufficientRequestBalance(controller, assets, 3);
// For async redemptions, we must use the full claimable amount
uint256 claimableShares = $.claimableRedeemRequest[controller];
uint256 claimableAssets = $.assetsRedeemRequest[controller];

if (claimableShares == 0 || claimableAssets == 0) {
revert NoClaimableRedeem();
}
if (assets != claimableAssets) {
revert InvalidRedeemAmount(convertToShares(assets), claimableShares);
}
shares = $.claimableRedeemRequest[controller];

shares = claimableShares;

// Reset state atomically
$.claimableRedeemRequest[controller] = 0;
$.assetsRedeemRequest[controller] = 0;
} else {
// For sync withdraws, calculate and burn in same transaction
shares = convertToShares(assets);
_burn(controller, shares);
}
Expand Down

0 comments on commit 138a1d8

Please sign in to comment.