Skip to content

Commit

Permalink
Fix yield amount
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Nov 19, 2023
1 parent b741816 commit 77bdc1a
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions contracts/StableAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,9 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
_amounts[i]
);
}
totalSupply = newD;
totalSupply = oldD + mintAmount;
poolToken.mintShares(msg.sender, mintAmount);
if (feeAmount > 0) {
poolToken.setTotalSupply(feeAmount);
}

collectFeeOrYield(true);
feeAmount = collectFeeOrYield(true);
emit Minted(msg.sender, mintAmount, _amounts, feeAmount);
return mintAmount;
}
Expand Down Expand Up @@ -801,13 +797,7 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
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);
feeAmount = collectFeeOrYield(true);
emit Redeemed(msg.sender, _amount, amounts, feeAmount);
return amounts;
}
Expand Down Expand Up @@ -908,13 +898,7 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
IERC20Upgradeable(tokens[_i]).safeTransfer(msg.sender, transferAmount);
totalSupply = D - redeemAmount;
poolToken.burnSharesFrom(msg.sender, _amount);

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

collectFeeOrYield(true);
feeAmount = collectFeeOrYield(true);
emit Redeemed(msg.sender, _amount, amounts, feeAmount);
return transferAmount;
}
Expand Down Expand Up @@ -1010,18 +994,12 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
balances = _balances;
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;
IERC20Upgradeable(tokens[i]).safeTransfer(msg.sender, _amounts[i]);
}
collectFeeOrYield(true);
feeAmount = collectFeeOrYield(true);
emit Redeemed(msg.sender, redeemAmount, amounts, feeAmount);
return amounts;
}
Expand Down Expand Up @@ -1106,7 +1084,14 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
} else {
uint256[] memory amounts = new uint256[](_balances.length);
for (uint256 i = 0; i < _balances.length; i++) {
amounts[i] = _balances[i] - oldBalances[i];
uint256 amount = _balances[i] - oldBalances[i];
if (i == exchangeRateTokenIndex) {
amount =
(amount *
(10 ** exchangeRateProvider.exchangeRateDecimals())) /
exchangeRateProvider.exchangeRate();
}
amounts[i] = amount;
}
emit YieldCollected(amounts, feeAmount, totalSupply);
}
Expand Down

0 comments on commit 77bdc1a

Please sign in to comment.