From 04a67d3df0bbc95c24e882255fff2c5c93c5ec54 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 15 Sep 2020 18:49:53 +0200 Subject: [PATCH] updated stabledebttoken --- contracts/tokenization/StableDebtToken.sol | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 85277ddc..7ba4ad31 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -81,10 +81,11 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { } struct MintLocalVars { - uint256 supplyAfterMint; - uint256 supplyBeforeMint; + uint256 currentPrincipalSupply; + uint256 nextSupply; uint256 amountInRay; uint256 newStableRate; + uint256 currentAvgStableRate; } /** @@ -108,8 +109,9 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { uint256 balanceIncrease ) = _calculateBalanceIncrease(user); - vars.supplyBeforeMint = totalSupply().add(balanceIncrease); - vars.supplyAfterMint = vars.supplyBeforeMint.add(amount); + vars.currentPrincipalSupply = totalSupply(); + vars.currentAvgStableRate = _avgStableRate; + vars.nextSupply = _totalSupply = _calcTotalSupply(vars.currentAvgStableRate).add(amount); vars.amountInRay = amount.wadToRay(); @@ -126,10 +128,10 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { _totalSupplyTimestamp = _timestamps[user] = uint40(block.timestamp); //calculates the updated average stable rate - _avgStableRate = _avgStableRate - .rayMul(vars.supplyBeforeMint.wadToRay()) + _avgStableRate = vars.currentAvgStableRate + .rayMul(vars.currentPrincipalSupply.wadToRay()) .add(rate.rayMul(vars.amountInRay)) - .rayDiv(vars.supplyAfterMint.wadToRay()); + .rayDiv(vars.nextSupply.wadToRay()); _mint(user, amount.add(balanceIncrease)); @@ -237,6 +239,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { function getTotalSupplyLastUpdated() public override view returns(uint40) { return _totalSupplyTimestamp; } + /** * @dev Returns the principal debt balance of the user from * @return The debt balance of the user since the last burn/mint action