Skip to content

Commit

Permalink
Fix redeem totalSupply
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Nov 19, 2023
1 parent 5de7fc3 commit b741816
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions contracts/StableAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,15 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
);
}

totalSupply = D - _amount;
totalSupply = D - redeemAmount;
// After reducing the redeem fee, the remaining pool tokens are burned!
poolToken.burnSharesFrom(msg.sender, _amount);

// Add fee to totalSupply after burning _amount
if (feeAmount > 0) {
poolToken.setTotalSupply(feeAmount);
}

collectFeeOrYield(true);
emit Redeemed(msg.sender, _amount, amounts, feeAmount);
return amounts;
Expand Down Expand Up @@ -900,8 +906,14 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
}
amounts[_i] = transferAmount;
IERC20Upgradeable(tokens[_i]).safeTransfer(msg.sender, transferAmount);
totalSupply = D - _amount;
totalSupply = D - redeemAmount;
poolToken.burnSharesFrom(msg.sender, _amount);

// Add fee to totalSupply after burning _amount
if (feeAmount > 0) {
poolToken.setTotalSupply(feeAmount);
}

collectFeeOrYield(true);
emit Redeemed(msg.sender, _amount, amounts, feeAmount);
return transferAmount;
Expand Down Expand Up @@ -996,8 +1008,14 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {

// Updates token balances in storage.
balances = _balances;
totalSupply = oldD - redeemAmount;
totalSupply = oldD - (redeemAmount - feeAmount);
poolToken.burnSharesFrom(msg.sender, redeemAmount);

// Add fee to totalSupply after burning _amount
if (feeAmount > 0) {
poolToken.setTotalSupply(feeAmount);
}

uint256[] memory amounts = _amounts;
for (i = 0; i < _balances.length; i++) {
if (_amounts[i] == 0) continue;
Expand Down

0 comments on commit b741816

Please sign in to comment.