diff --git a/contracts/BackedAutoFeeTokenImplementation.sol b/contracts/BackedAutoFeeTokenImplementation.sol index 25b5738..de487bd 100644 --- a/contracts/BackedAutoFeeTokenImplementation.sol +++ b/contracts/BackedAutoFeeTokenImplementation.sol @@ -77,6 +77,8 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { uint256 internal _totalShares; + uint256 public multiplierNonce; + // Events: /** @@ -104,10 +106,10 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { // Modifiers: modifier updateMultiplier() { - (uint256 newMultiplier, uint256 periodsPassed) = getCurrentMultiplier(); + (uint256 newMultiplier, uint256 periodsPassed, uint256 newMultiplierNonce) = getCurrentMultiplier(); lastTimeFeeApplied = lastTimeFeeApplied + periodLength * periodsPassed; if (multiplier != newMultiplier) { - _updateMultiplier(newMultiplier); + _updateMultiplier(newMultiplier, newMultiplierNonce); } _; } @@ -155,6 +157,7 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { require(_lastTimeFeeApplied != 0, "Invalid last time fee applied"); multiplier = 1e18; + multiplierNonce = 0; periodLength = _periodLength; lastTimeFeeApplied = _lastTimeFeeApplied; feePerPeriod = _feePerPeriod; @@ -164,7 +167,7 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { - (uint256 newMultiplier, ) = getCurrentMultiplier(); + (uint256 newMultiplier, ,) = getCurrentMultiplier(); return _getUnderlyingAmountByShares(_totalShares, newMultiplier); } @@ -174,7 +177,7 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { function balanceOf( address account ) public view virtual override returns (uint256) { - (uint256 newMultiplier, ) = getCurrentMultiplier(); + (uint256 newMultiplier, ,) = getCurrentMultiplier(); return _getUnderlyingAmountByShares(sharesOf(account), newMultiplier); } @@ -186,13 +189,15 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { public view virtual - returns (uint256 newMultiplier, uint256 periodsPassed) + returns (uint256 newMultiplier, uint256 periodsPassed, uint256 newMultiplierNonce) { periodsPassed = (block.timestamp - lastTimeFeeApplied) / periodLength; newMultiplier = multiplier; + newMultiplierNonce = multiplierNonce; if (feePerPeriod > 0) { for (uint256 index = 0; index < periodsPassed; index++) { newMultiplier = (newMultiplier * (1e18 - feePerPeriod)) / 1e18; + newMultiplierNonce += 1; } } } @@ -210,7 +215,7 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { function getSharesByUnderlyingAmount( uint256 _underlyingAmount ) external view returns (uint256) { - (uint256 newMultiplier, ) = getCurrentMultiplier(); + (uint256 newMultiplier, ,) = getCurrentMultiplier(); return _getSharesByUnderlyingAmount(_underlyingAmount, newMultiplier); } @@ -220,7 +225,7 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { function getUnderlyingAmountByShares( uint256 _sharesAmount ) external view returns (uint256) { - (uint256 newMultiplier, ) = getCurrentMultiplier(); + (uint256 newMultiplier, ,) = getCurrentMultiplier(); return _getUnderlyingAmountByShares(_sharesAmount, newMultiplier); } @@ -337,7 +342,7 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { multiplier == oldMultiplier, "BackedToken: Multiplier changed in the meantime" ); - _updateMultiplier(newMultiplier); + _updateMultiplier(newMultiplier, multiplierNonce + 1); } /** @@ -469,8 +474,9 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation { * * Emit an {MultiplierUpdated} event. */ - function _updateMultiplier(uint256 newMultiplier) internal virtual { + function _updateMultiplier(uint256 newMultiplier, uint256 newMultiplierNonce) internal virtual { multiplier = newMultiplier; + multiplierNonce = newMultiplierNonce; emit MultiplierUpdated(newMultiplier); } diff --git a/contracts/BackedTokenImplementation.sol b/contracts/BackedTokenImplementation.sol index c397420..d36a2ee 100644 --- a/contracts/BackedTokenImplementation.sol +++ b/contracts/BackedTokenImplementation.sol @@ -323,5 +323,5 @@ contract BackedTokenImplementation is OwnableUpgradeable, ERC20PermitDelegateTra * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ - uint256[49] private __gap; + uint256[48] private __gap; }