mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
fix: Refactor, simplifying _beforeTokenTransfer
This commit is contained in:
parent
c1ce8475de
commit
e36a2f0e21
|
@ -426,14 +426,11 @@ contract StaticATokenLM is ERC20 {
|
||||||
address to,
|
address to,
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) internal override {
|
) internal override {
|
||||||
// Only enter when not minting or burning.
|
|
||||||
if (from != address(0)) {
|
if (from != address(0)) {
|
||||||
_updateUnclaimedRewards(from);
|
_updateUser(from);
|
||||||
_updateUserIndex(from);
|
|
||||||
}
|
}
|
||||||
if (to != address(0)) {
|
if (to != address(0)) {
|
||||||
_updateUnclaimedRewards(to);
|
_updateUser(to);
|
||||||
_updateUserIndex(to);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +454,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
||||||
|
|
||||||
rewardIndex = rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
rewardIndex = rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
||||||
|
|
||||||
lifeTimeRewards = externalLifetimeRewards;
|
lifeTimeRewards = externalLifetimeRewards;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,15 +519,16 @@ contract StaticATokenLM is ERC20 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Adding the pending rewards to the unclaimed for specific user
|
* @dev Adding the pending rewards to the unclaimed for specific user and updating user index
|
||||||
* @param user The address of the user to update
|
* @param user The address of the user to update
|
||||||
*/
|
*/
|
||||||
function _updateUnclaimedRewards(address user) internal {
|
function _updateUser(address user) internal {
|
||||||
uint256 balance = balanceOf(user);
|
uint256 balance = balanceOf(user);
|
||||||
if (balance > 0) {
|
if (balance > 0) {
|
||||||
uint256 pending = _getPendingRewards(user, balance, false);
|
uint256 pending = _getPendingRewards(user, balance, false);
|
||||||
_unclaimedRewards[user] = _unclaimedRewards[user].add(pending);
|
_unclaimedRewards[user] = _unclaimedRewards[user].add(pending);
|
||||||
}
|
}
|
||||||
|
_updateUserIndex(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -568,8 +565,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
_rewardIndex = _rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
_rewardIndex = _rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 _reward = rayBalance.rayMulNoRounding(_rewardIndex.sub(_userIndex[user]));
|
return rayBalance.rayMulNoRounding(_rewardIndex.sub(_userIndex[user]));
|
||||||
return _reward;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user