Skip to content

Commit

Permalink
fix: Consistently use from when burning.
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Jan 21, 2022
1 parent 7ff9858 commit a5fa434
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions contracts/interfaces/IStableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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
* @param avgStableRate The next average stable rate after the burning
* @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,
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IVariableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions contracts/protocol/tokenization/StableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions contracts/protocol/tokenization/VariableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit a5fa434

Please sign in to comment.