From aba38a800fc0bcbf6d035faa231f2356960fd770 Mon Sep 17 00:00:00 2001 From: emilio Date: Tue, 27 Oct 2020 10:36:02 +0100 Subject: [PATCH] Fixed event for the avg stable rate --- contracts/tokenization/StableDebtToken.sol | 19 ++++++++++++++----- .../interfaces/IStableDebtToken.sol | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 5d38c464..346d9719 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -128,7 +128,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { _totalSupplyTimestamp = _timestamps[user] = uint40(block.timestamp); //calculates the updated average stable rate - _avgStableRate = vars + vars.currentAvgStableRate = _avgStableRate = vars .currentAvgStableRate .rayMul(vars.previousSupply.wadToRay()) .add(rate.rayMul(vars.amountInRay)) @@ -139,7 +139,15 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { // transfer event to track balances emit Transfer(address(0), user, amount); - emit Mint(user, amount, previousBalance, currentBalance, balanceIncrease, vars.newStableRate); + emit Mint( + user, + amount, + previousBalance, + currentBalance, + balanceIncrease, + vars.newStableRate, + vars.currentAvgStableRate + ); } /** @@ -155,17 +163,18 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { ) = _calculateBalanceIncrease(user); uint256 previousSupply = totalSupply(); + uint256 newStableRate = 0; //since the total supply and each single user debt accrue separately, //there might be accumulation errors so that the last borrower repaying //might actually try to repay more than the available debt supply. //in this case we simply set the total supply and the avg stable rate to 0 if (previousSupply <= amount) { - _avgStableRate = 0; + newStableRate = _avgStableRate = 0; _totalSupply = 0; } else { uint256 nextSupply = _totalSupply = previousSupply.sub(amount); - _avgStableRate = _avgStableRate + newStableRate = _avgStableRate = _avgStableRate .rayMul(previousSupply.wadToRay()) .sub(_usersData[user].rayMul(amount.wadToRay())) .rayDiv(nextSupply.wadToRay()); @@ -190,7 +199,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { // transfer event to track balances emit Transfer(user, address(0), amount); - emit Burn(user, amount, previousBalance, currentBalance, balanceIncrease); + emit Burn(user, amount, previousBalance, currentBalance, balanceIncrease, newStableRate); } /** diff --git a/contracts/tokenization/interfaces/IStableDebtToken.sol b/contracts/tokenization/interfaces/IStableDebtToken.sol index 8862c30d..4c0d5940 100644 --- a/contracts/tokenization/interfaces/IStableDebtToken.sol +++ b/contracts/tokenization/interfaces/IStableDebtToken.sol @@ -21,6 +21,7 @@ interface IStableDebtToken { * @param currentBalance the current balance of the user * @param balanceIncrease the debt increase since the last update * @param newRate the rate of the debt after the minting + * @param avgStableRate the new average stable rate after the minting **/ event Mint( address indexed user, @@ -28,7 +29,8 @@ interface IStableDebtToken { uint256 previousBalance, uint256 currentBalance, uint256 balanceIncrease, - uint256 newRate + uint256 newRate, + uint256 avgStableRate ); /** @@ -38,13 +40,15 @@ interface IStableDebtToken { * @param previousBalance the previous balance of the user * @param currentBalance the current balance of the user * @param balanceIncrease the debt increase since the last update + * @param avgStableRate the new average stable rate after the minting **/ event Burn( address indexed user, uint256 amount, uint256 previousBalance, uint256 currentBalance, - uint256 balanceIncrease + uint256 balanceIncrease, + uint256 avgStableRate ); /**