From a5fa43426764ec4348c15169d1479283d5c55e1d Mon Sep 17 00:00:00 2001 From: Lasse Herskind Date: Fri, 21 Jan 2022 15:21:27 +0000 Subject: [PATCH] fix: Consistently use `from` when burning. --- contracts/interfaces/IStableDebtToken.sol | 8 +++--- contracts/interfaces/IVariableDebtToken.sol | 4 +-- .../protocol/tokenization/StableDebtToken.sol | 26 +++++++++---------- .../tokenization/VariableDebtToken.sol | 4 +-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/contracts/interfaces/IStableDebtToken.sol b/contracts/interfaces/IStableDebtToken.sol index 7b38479aa..ad5cdb45f 100644 --- a/contracts/interfaces/IStableDebtToken.sol +++ b/contracts/interfaces/IStableDebtToken.sol @@ -34,7 +34,7 @@ interface IStableDebtToken is IInitializableDebtToken { /** * @dev Emitted when new stable debt is burned - * @param user The address of the user + * @param from The address from which the debt will be burned * @param amount The amount being burned (user entered amount - balance increase from interest) * @param currentBalance The current balance of the user * @param balanceIncrease The the increase in balance since the last action of the user @@ -42,7 +42,7 @@ interface IStableDebtToken is IInitializableDebtToken { * @param newTotalSupply The next total supply of the stable debt token after the action **/ event Burn( - address indexed user, + address indexed from, uint256 amount, uint256 currentBalance, uint256 balanceIncrease, @@ -82,12 +82,12 @@ interface IStableDebtToken is IInitializableDebtToken { * and the rate of the previous debt * @dev In some instances, a burn transaction will emit a mint event * if the amount to burn is less than the interest the user earned - * @param user The address of the user getting his debt burned + * @param from The address from which the debt will be burned * @param amount The amount of debt tokens getting burned * @return The total stable debt * @return The average stable borrow rate **/ - function burn(address user, uint256 amount) external returns (uint256, uint256); + function burn(address from, uint256 amount) external returns (uint256, uint256); /** * @notice Returns the average rate of all the stable rate loans. diff --git a/contracts/interfaces/IVariableDebtToken.sol b/contracts/interfaces/IVariableDebtToken.sol index 72cbc4194..59facb7be 100644 --- a/contracts/interfaces/IVariableDebtToken.sol +++ b/contracts/interfaces/IVariableDebtToken.sol @@ -31,13 +31,13 @@ interface IVariableDebtToken is IScaledBalanceToken, IInitializableDebtToken { * @notice Burns user variable debt * @dev In some instances, a burn transaction will emit a mint event * if the amount to burn is less than the interest that the user accrued - * @param user The user which debt is burnt + * @param from The address from which the debt will be burned * @param amount The amount getting burned * @param index The variable debt index of the reserve * @return The scaled total debt of the reserve **/ function burn( - address user, + address from, uint256 amount, uint256 index ) external returns (uint256); diff --git a/contracts/protocol/tokenization/StableDebtToken.sol b/contracts/protocol/tokenization/StableDebtToken.sol index 125923d8e..428038afb 100644 --- a/contracts/protocol/tokenization/StableDebtToken.sol +++ b/contracts/protocol/tokenization/StableDebtToken.sol @@ -183,18 +183,18 @@ contract StableDebtToken is DebtTokenBase, IncentivizedERC20, IStableDebtToken { } /// @inheritdoc IStableDebtToken - function burn(address user, uint256 amount) + function burn(address from, uint256 amount) external override onlyPool returns (uint256, uint256) { - (, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(user); + (, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from); uint256 previousSupply = totalSupply(); uint256 nextAvgStableRate = 0; uint256 nextSupply = 0; - uint256 userStableRate = _userState[user].additionalData; + uint256 userStableRate = _userState[from].additionalData; // Since the total supply and each single user debt accrue separately, // there might be accumulation errors so that the last borrower repaying @@ -221,22 +221,22 @@ contract StableDebtToken is DebtTokenBase, IncentivizedERC20, IStableDebtToken { } if (amount == currentBalance) { - _userState[user].additionalData = 0; - _timestamps[user] = 0; + _userState[from].additionalData = 0; + _timestamps[from] = 0; } else { //solium-disable-next-line - _timestamps[user] = uint40(block.timestamp); + _timestamps[from] = uint40(block.timestamp); } //solium-disable-next-line _totalSupplyTimestamp = uint40(block.timestamp); if (balanceIncrease > amount) { uint256 amountToMint = balanceIncrease - amount; - _mint(user, amountToMint, previousSupply); - emit Transfer(address(0), user, amountToMint); + _mint(from, amountToMint, previousSupply); + emit Transfer(address(0), from, amountToMint); emit Mint( - user, - user, + from, + from, amountToMint, currentBalance, balanceIncrease, @@ -246,9 +246,9 @@ contract StableDebtToken is DebtTokenBase, IncentivizedERC20, IStableDebtToken { ); } else { uint256 amountToBurn = amount - balanceIncrease; - _burn(user, amountToBurn, previousSupply); - emit Transfer(user, address(0), amountToBurn); - emit Burn(user, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply); + _burn(from, amountToBurn, previousSupply); + emit Transfer(from, address(0), amountToBurn); + emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply); } return (nextSupply, nextAvgStableRate); diff --git a/contracts/protocol/tokenization/VariableDebtToken.sol b/contracts/protocol/tokenization/VariableDebtToken.sol index 4423da25c..b3face423 100644 --- a/contracts/protocol/tokenization/VariableDebtToken.sol +++ b/contracts/protocol/tokenization/VariableDebtToken.sol @@ -98,11 +98,11 @@ contract VariableDebtToken is DebtTokenBase, ScaledBalanceTokenBase, IVariableDe /// @inheritdoc IVariableDebtToken function burn( - address user, + address from, uint256 amount, uint256 index ) external override onlyPool returns (uint256) { - _burnScaled(user, address(0), amount, index); + _burnScaled(from, address(0), amount, index); return scaledTotalSupply(); }