mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
fixed events in the token contract
This commit is contained in:
parent
cb6603f8a7
commit
3439198ec3
|
@ -131,7 +131,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
_totalSupplyTimestamp = _timestamps[user] = uint40(block.timestamp);
|
_totalSupplyTimestamp = _timestamps[user] = uint40(block.timestamp);
|
||||||
|
|
||||||
//calculates the updated average stable rate
|
//calculates the updated average stable rate
|
||||||
_avgStableRate = vars.currentAvgStableRate
|
_avgStableRate = vars
|
||||||
|
.currentAvgStableRate
|
||||||
.rayMul(vars.previousSupply.wadToRay())
|
.rayMul(vars.previousSupply.wadToRay())
|
||||||
.add(rate.rayMul(vars.amountInRay))
|
.add(rate.rayMul(vars.amountInRay))
|
||||||
.rayDiv(vars.nextSupply.wadToRay());
|
.rayDiv(vars.nextSupply.wadToRay());
|
||||||
|
@ -141,14 +142,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
// transfer event to track balances
|
// transfer event to track balances
|
||||||
emit Transfer(address(0), user, amount);
|
emit Transfer(address(0), user, amount);
|
||||||
|
|
||||||
emit MintDebt(
|
emit Mint(user, amount, previousBalance, currentBalance, balanceIncrease, vars.newStableRate);
|
||||||
user,
|
|
||||||
amount,
|
|
||||||
previousBalance,
|
|
||||||
currentBalance,
|
|
||||||
balanceIncrease,
|
|
||||||
vars.newStableRate
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +157,6 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
uint256 balanceIncrease
|
uint256 balanceIncrease
|
||||||
) = _calculateBalanceIncrease(user);
|
) = _calculateBalanceIncrease(user);
|
||||||
|
|
||||||
|
|
||||||
uint256 previousSupply = totalSupply();
|
uint256 previousSupply = totalSupply();
|
||||||
|
|
||||||
//since the total supply and each single user debt accrue separately,
|
//since the total supply and each single user debt accrue separately,
|
||||||
|
@ -174,7 +167,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
_avgStableRate = 0;
|
_avgStableRate = 0;
|
||||||
_totalSupply = 0;
|
_totalSupply = 0;
|
||||||
} else {
|
} else {
|
||||||
uint256 nextSupply = _totalSupply = previousSupply.sub(amount);
|
uint256 nextSupply = _totalSupply = previousSupply.sub(amount);
|
||||||
_avgStableRate = _avgStableRate
|
_avgStableRate = _avgStableRate
|
||||||
.rayMul(previousSupply.wadToRay())
|
.rayMul(previousSupply.wadToRay())
|
||||||
.sub(_usersData[user].rayMul(amount.wadToRay()))
|
.sub(_usersData[user].rayMul(amount.wadToRay()))
|
||||||
|
@ -184,7 +177,6 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
if (amount == currentBalance) {
|
if (amount == currentBalance) {
|
||||||
_usersData[user] = 0;
|
_usersData[user] = 0;
|
||||||
_timestamps[user] = 0;
|
_timestamps[user] = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//solium-disable-next-line
|
//solium-disable-next-line
|
||||||
_timestamps[user] = uint40(block.timestamp);
|
_timestamps[user] = uint40(block.timestamp);
|
||||||
|
@ -201,7 +193,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
// transfer event to track balances
|
// transfer event to track balances
|
||||||
emit Transfer(user, address(0), amount);
|
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
|
* @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;
|
uint256 avgRate = _avgStableRate;
|
||||||
return (super.totalSupply(), _calcTotalSupply(avgRate), avgRate, _totalSupplyTimestamp);
|
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
|
* @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;
|
return _totalSupplyTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,13 +276,12 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
return super.balanceOf(user);
|
return super.balanceOf(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev calculates the total supply
|
* @dev calculates the total supply
|
||||||
* @param avgRate the average rate at which calculate 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
|
* @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();
|
uint256 principalSupply = super.totalSupply();
|
||||||
|
|
||||||
if (principalSupply == 0) {
|
if (principalSupply == 0) {
|
||||||
|
@ -295,14 +296,17 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
return principalSupply.rayMul(cumulatedInterest);
|
return principalSupply.rayMul(cumulatedInterest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev mints stable debt tokens to an user
|
* @dev mints stable debt tokens to an user
|
||||||
* @param account the account receiving the debt tokens
|
* @param account the account receiving the debt tokens
|
||||||
* @param amount the amount being minted
|
* @param amount the amount being minted
|
||||||
* @param oldTotalSupply the total supply before the minting event
|
* @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];
|
uint256 oldAccountBalance = _balances[account];
|
||||||
_balances[account] = oldAccountBalance.add(amount);
|
_balances[account] = oldAccountBalance.add(amount);
|
||||||
|
|
||||||
|
@ -311,14 +315,17 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev burns stable debt tokens of an user
|
* @dev burns stable debt tokens of an user
|
||||||
* @param account the user getting his debt burned
|
* @param account the user getting his debt burned
|
||||||
* @param amount the amount being burned
|
* @param amount the amount being burned
|
||||||
* @param oldTotalSupply the total supply before the burning event
|
* @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];
|
uint256 oldAccountBalance = _balances[account];
|
||||||
_balances[account] = oldAccountBalance.sub(amount, 'ERC20: burn amount exceeds balance');
|
_balances[account] = oldAccountBalance.sub(amount, 'ERC20: burn amount exceeds balance');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user