mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/61' into 'master'
Resolve "Fix stable rate token events" Closes #61 See merge request aave-tech/protocol-v2!69
This commit is contained in:
commit
a7861f8cba
|
@ -131,7 +131,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
_totalSupplyTimestamp = _timestamps[user] = uint40(block.timestamp);
|
||||
|
||||
//calculates the updated average stable rate
|
||||
_avgStableRate = vars.currentAvgStableRate
|
||||
_avgStableRate = vars
|
||||
.currentAvgStableRate
|
||||
.rayMul(vars.previousSupply.wadToRay())
|
||||
.add(rate.rayMul(vars.amountInRay))
|
||||
.rayDiv(vars.nextSupply.wadToRay());
|
||||
|
@ -141,14 +142,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
// transfer event to track balances
|
||||
emit Transfer(address(0), user, amount);
|
||||
|
||||
emit MintDebt(
|
||||
user,
|
||||
amount,
|
||||
previousBalance,
|
||||
currentBalance,
|
||||
balanceIncrease,
|
||||
vars.newStableRate
|
||||
);
|
||||
emit Mint(user, amount, previousBalance, currentBalance, balanceIncrease, vars.newStableRate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +157,6 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
uint256 balanceIncrease
|
||||
) = _calculateBalanceIncrease(user);
|
||||
|
||||
|
||||
uint256 previousSupply = totalSupply();
|
||||
|
||||
//since the total supply and each single user debt accrue separately,
|
||||
|
@ -184,7 +177,6 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
if (amount == currentBalance) {
|
||||
_usersData[user] = 0;
|
||||
_timestamps[user] = 0;
|
||||
|
||||
} else {
|
||||
//solium-disable-next-line
|
||||
_timestamps[user] = uint40(block.timestamp);
|
||||
|
@ -201,7 +193,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
// transfer event to track balances
|
||||
emit Transfer(user, address(0), amount);
|
||||
|
||||
emit BurnDebt(user, amount, previousBalance, currentBalance, balanceIncrease);
|
||||
emit Burn(user, amount, previousBalance, currentBalance, balanceIncrease);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,7 +230,17 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
/**
|
||||
* @dev returns the principal and total supply, the average borrow rate and the last supply update timestamp
|
||||
**/
|
||||
function getSupplyData() public override view returns (uint256, uint256, uint256,uint40) {
|
||||
function getSupplyData()
|
||||
public
|
||||
override
|
||||
view
|
||||
returns (
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint40
|
||||
)
|
||||
{
|
||||
uint256 avgRate = _avgStableRate;
|
||||
return (super.totalSupply(), _calcTotalSupply(avgRate), avgRate, _totalSupplyTimestamp);
|
||||
}
|
||||
|
@ -261,7 +263,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
/**
|
||||
* @dev returns the timestamp at which the total supply was updated
|
||||
**/
|
||||
function getTotalSupplyLastUpdated() public override view returns(uint40) {
|
||||
function getTotalSupplyLastUpdated() public override view returns (uint40) {
|
||||
return _totalSupplyTimestamp;
|
||||
}
|
||||
|
||||
|
@ -274,13 +276,12 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
return super.balanceOf(user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dev calculates the total supply
|
||||
* @param avgRate the average rate at which calculate the total supply
|
||||
* @return The debt balance of the user since the last burn/mint action
|
||||
**/
|
||||
function _calcTotalSupply(uint256 avgRate) internal view returns(uint256) {
|
||||
function _calcTotalSupply(uint256 avgRate) internal view returns (uint256) {
|
||||
uint256 principalSupply = super.totalSupply();
|
||||
|
||||
if (principalSupply == 0) {
|
||||
|
@ -301,8 +302,11 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
* @param amount the amount being minted
|
||||
* @param oldTotalSupply the total supply before the minting event
|
||||
**/
|
||||
function _mint(address account, uint256 amount, uint256 oldTotalSupply) internal {
|
||||
|
||||
function _mint(
|
||||
address account,
|
||||
uint256 amount,
|
||||
uint256 oldTotalSupply
|
||||
) internal {
|
||||
uint256 oldAccountBalance = _balances[account];
|
||||
_balances[account] = oldAccountBalance.add(amount);
|
||||
|
||||
|
@ -317,8 +321,11 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
* @param amount the amount being burned
|
||||
* @param oldTotalSupply the total supply before the burning event
|
||||
**/
|
||||
function _burn(address account, uint256 amount, uint256 oldTotalSupply) internal {
|
||||
|
||||
function _burn(
|
||||
address account,
|
||||
uint256 amount,
|
||||
uint256 oldTotalSupply
|
||||
) internal {
|
||||
uint256 oldAccountBalance = _balances[account];
|
||||
_balances[account] = oldAccountBalance.sub(amount, 'ERC20: burn amount exceeds balance');
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ interface IStableDebtToken {
|
|||
* @param balanceIncrease the debt increase since the last update
|
||||
* @param newRate the rate of the debt after the minting
|
||||
**/
|
||||
event MintDebt(
|
||||
address user,
|
||||
event Mint(
|
||||
address indexed user,
|
||||
uint256 amount,
|
||||
uint256 previousBalance,
|
||||
uint256 currentBalance,
|
||||
|
@ -39,8 +39,8 @@ interface IStableDebtToken {
|
|||
* @param currentBalance the current balance of the user
|
||||
* @param balanceIncrease the debt increase since the last update
|
||||
**/
|
||||
event BurnDebt(
|
||||
address user,
|
||||
event Burn(
|
||||
address indexed user,
|
||||
uint256 amount,
|
||||
uint256 previousBalance,
|
||||
uint256 currentBalance,
|
||||
|
@ -88,7 +88,15 @@ interface IStableDebtToken {
|
|||
/**
|
||||
* @dev returns the principal, the total supply and the average stable rate
|
||||
**/
|
||||
function getSupplyData() external view returns (uint256, uint256, uint256, uint40);
|
||||
function getSupplyData()
|
||||
external
|
||||
view
|
||||
returns (
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint40
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev returns the timestamp of the last update of the total supply
|
||||
|
|
Loading…
Reference in New Issue
Block a user