Skip to content

Commit

Permalink
Merge pull request #41 from nutsfinance/fix-redeem-fee
Browse files Browse the repository at this point in the history
Fix amount in YieldCollected
  • Loading branch information
zjb0807 authored Nov 27, 2023
2 parents 5de7fc3 + 3bb0d9d commit 9858361
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 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,7 +797,7 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
totalSupply = D - _amount;
// After reducing the redeem fee, the remaining pool tokens are burned!
poolToken.burnSharesFrom(msg.sender, _amount);
collectFeeOrYield(true);
feeAmount = collectFeeOrYield(true);
emit Redeemed(msg.sender, _amount, amounts, feeAmount);
return amounts;
}
Expand Down Expand Up @@ -902,7 +898,7 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
IERC20Upgradeable(tokens[_i]).safeTransfer(msg.sender, transferAmount);
totalSupply = D - _amount;
poolToken.burnSharesFrom(msg.sender, _amount);
collectFeeOrYield(true);
feeAmount = collectFeeOrYield(true);
emit Redeemed(msg.sender, _amount, amounts, feeAmount);
return transferAmount;
}
Expand Down Expand Up @@ -1003,7 +999,7 @@ contract StableAsset is Initializable, ReentrancyGuardUpgradeable {
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 @@ -1088,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 9858361

Please sign in to comment.