From bcdef6fa7e39e7dd6fa2111dbf8ba89c00faca6d Mon Sep 17 00:00:00 2001 From: The3D Date: Wed, 16 Sep 2020 20:00:13 +0200 Subject: [PATCH] Added change to the stabledebttoken --- contracts/tokenization/StableDebtToken.sol | 11 +++++++---- .../tokenization/interfaces/IStableDebtToken.sol | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 5b286e93..610b2ae8 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -110,7 +110,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { uint256 balanceIncrease ) = _calculateBalanceIncrease(user); - vars.currentSupply = totalSupply(); + //accrueing the interest accumulation to the stored total supply and caching it + vars.currentSupply = _totalSupply = totalSupply(); vars.currentAvgStableRate = _avgStableRate; vars.nextSupply = vars.currentSupply.add(amount); @@ -125,12 +126,13 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { require(vars.newStableRate < (1 << 128), 'Debt token: stable rate overflow'); _usersData[user] = vars.newStableRate; + //updating the user and supply timestamp //solium-disable-next-line _totalSupplyTimestamp = _timestamps[user] = uint40(block.timestamp); //calculates the updated average stable rate _avgStableRate = vars.currentAvgStableRate - .rayMul(vars.currentPrincipalSupply.wadToRay()) + .rayMul(vars.currentSupply.wadToRay()) .add(rate.rayMul(vars.amountInRay)) .rayDiv(vars.nextSupply.wadToRay()); @@ -224,8 +226,9 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { ); } - function getPrincipalSupplyAndAvgRate() public override view returns (uint256, uint256) { - return (super.totalSupply(), _avgStableRate); + function getSupplyData() public override view returns (uint256, uint256, uint256) { + uint256 avgRate = _avgStableRate; + return (super.totalSupply(), _calcTotalSupply(avgRate), avgRate); } function getTotalSupplyAndAvgRate() public override view returns (uint256, uint256) { diff --git a/contracts/tokenization/interfaces/IStableDebtToken.sol b/contracts/tokenization/interfaces/IStableDebtToken.sol index 46324e88..0e75bae4 100644 --- a/contracts/tokenization/interfaces/IStableDebtToken.sol +++ b/contracts/tokenization/interfaces/IStableDebtToken.sol @@ -86,9 +86,9 @@ interface IStableDebtToken { function getUserLastUpdated(address user) external view returns (uint40); /** - * @dev returns the principal total supply and the average stable rate + * @dev returns the principal, the total supply and the average stable rate **/ - function getPrincipalSupplyAndAvgRate() external view returns (uint256, uint256); + function getSupplyData() external view returns (uint256, uint256, uint256); /** * @dev returns the timestamp of the last update of the total supply