mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
fix: Minor refactor, variable renaming and cleanup
This commit is contained in:
parent
d1ff677045
commit
fd38f1f4d8
|
@ -53,7 +53,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
|
|
||||||
mapping(address => uint256) public _nonces;
|
mapping(address => uint256) public _nonces;
|
||||||
|
|
||||||
uint256 public accRewardstokenPerShare;
|
uint256 public rewardIndex;
|
||||||
uint256 public lifeTimeRewardsClaimed;
|
uint256 public lifeTimeRewardsClaimed;
|
||||||
uint256 public lifeTimeRewards;
|
uint256 public lifeTimeRewards;
|
||||||
uint256 public lastRewardBlock;
|
uint256 public lastRewardBlock;
|
||||||
|
@ -363,7 +363,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
) internal returns (uint256) {
|
) internal returns (uint256) {
|
||||||
require(recipient != address(0), 'INVALID_RECIPIENT');
|
require(recipient != address(0), 'INVALID_RECIPIENT');
|
||||||
_updateRewards();
|
_updateRewards();
|
||||||
_updateUnclaimedRewards(recipient);
|
|
||||||
|
|
||||||
if (fromUnderlying) {
|
if (fromUnderlying) {
|
||||||
ASSET.safeTransferFrom(depositor, address(this), amount);
|
ASSET.safeTransferFrom(depositor, address(this), amount);
|
||||||
|
@ -374,8 +373,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 amountToMint = _dynamicToStaticAmount(amount, rate());
|
uint256 amountToMint = _dynamicToStaticAmount(amount, rate());
|
||||||
_mint(recipient, amountToMint);
|
_mint(recipient, amountToMint);
|
||||||
|
|
||||||
_updateRewardDebt(recipient, balanceOf(recipient));
|
|
||||||
|
|
||||||
return amountToMint;
|
return amountToMint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +386,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
require(recipient != address(0), 'INVALID_RECIPIENT');
|
require(recipient != address(0), 'INVALID_RECIPIENT');
|
||||||
require(staticAmount == 0 || dynamicAmount == 0, 'ONLY_ONE_AMOUNT_FORMAT_ALLOWED');
|
require(staticAmount == 0 || dynamicAmount == 0, 'ONLY_ONE_AMOUNT_FORMAT_ALLOWED');
|
||||||
_updateRewards();
|
_updateRewards();
|
||||||
_updateUnclaimedRewards(owner);
|
|
||||||
|
|
||||||
uint256 userBalance = balanceOf(owner);
|
uint256 userBalance = balanceOf(owner);
|
||||||
|
|
||||||
|
@ -416,7 +412,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
ATOKEN.safeTransfer(recipient, amountToWithdraw);
|
ATOKEN.safeTransfer(recipient, amountToWithdraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateRewardDebt(owner, balanceOf(owner));
|
|
||||||
return (amountToBurn, amountToWithdraw);
|
return (amountToBurn, amountToWithdraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,15 +427,11 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) internal override {
|
) internal override {
|
||||||
// Only enter when not minting or burning.
|
// Only enter when not minting or burning.
|
||||||
if (from != address(0) && to != address(0)) {
|
if (from != address(0)) {
|
||||||
// The rewards not claimed to the contract yet is transferrred to the buyer as well.
|
|
||||||
// Often the recent rewards < gas, so only needed for whales to run updateClaim before it
|
|
||||||
|
|
||||||
// Pay out rewards (from)
|
|
||||||
_updateUnclaimedRewards(from);
|
_updateUnclaimedRewards(from);
|
||||||
_updateRewardDebt(from, balanceOf(from).sub(amount));
|
_updateRewardDebt(from, balanceOf(from).sub(amount));
|
||||||
|
}
|
||||||
// Pay out rewards (to)
|
if (to != address(0)) {
|
||||||
_updateUnclaimedRewards(to);
|
_updateUnclaimedRewards(to);
|
||||||
_updateRewardDebt(to, balanceOf(to).add(amount));
|
_updateRewardDebt(to, balanceOf(to).add(amount));
|
||||||
}
|
}
|
||||||
|
@ -450,7 +441,6 @@ contract StaticATokenLM is ERC20 {
|
||||||
* @dev Updates virtual internal accounting of rewards.
|
* @dev Updates virtual internal accounting of rewards.
|
||||||
*/
|
*/
|
||||||
function _updateRewards() internal {
|
function _updateRewards() internal {
|
||||||
// Update the virtual rewards without actually claiming.
|
|
||||||
if (block.number > lastRewardBlock) {
|
if (block.number > lastRewardBlock) {
|
||||||
lastRewardBlock = block.number;
|
lastRewardBlock = block.number;
|
||||||
uint256 _supply = totalSupply();
|
uint256 _supply = totalSupply();
|
||||||
|
@ -466,9 +456,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 externalLifetimeRewards = lifeTimeRewardsClaimed.add(freshRewards);
|
uint256 externalLifetimeRewards = lifeTimeRewardsClaimed.add(freshRewards);
|
||||||
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
||||||
|
|
||||||
accRewardstokenPerShare = accRewardstokenPerShare.add(
|
rewardIndex = rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
||||||
(diff).rayDivNoRounding(_supply.wadToRay())
|
|
||||||
);
|
|
||||||
|
|
||||||
lifeTimeRewards = externalLifetimeRewards;
|
lifeTimeRewards = externalLifetimeRewards;
|
||||||
}
|
}
|
||||||
|
@ -491,9 +479,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
||||||
|
|
||||||
if (_supply > 0 && diff > 0) {
|
if (_supply > 0 && diff > 0) {
|
||||||
accRewardstokenPerShare = accRewardstokenPerShare.add(
|
rewardIndex = rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
||||||
(diff).rayDivNoRounding(_supply.wadToRay())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
|
@ -536,7 +522,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
function _updateRewardDebt(address user, uint256 balance) internal {
|
function _updateRewardDebt(address user, uint256 balance) internal {
|
||||||
// If we round down here, we could underestimate the debt, thereby paying out too much. Better to overestimate.
|
// If we round down here, we could underestimate the debt, thereby paying out too much. Better to overestimate.
|
||||||
uint256 rayBalance = balance.wadToRay();
|
uint256 rayBalance = balance.wadToRay();
|
||||||
rewardDebts[user] = rayBalance.rayMul(accRewardstokenPerShare);
|
rewardDebts[user] = rayBalance.rayMul(rewardIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -572,7 +558,7 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 rayBalance = balance.wadToRay();
|
uint256 rayBalance = balance.wadToRay();
|
||||||
|
|
||||||
uint256 _supply = totalSupply();
|
uint256 _supply = totalSupply();
|
||||||
uint256 _accRewardstokenPerShare = accRewardstokenPerShare;
|
uint256 _rewardIndex = rewardIndex;
|
||||||
|
|
||||||
if (_supply != 0 && fresh) {
|
if (_supply != 0 && fresh) {
|
||||||
// Done purely virtually, this is used for retrieving up to date rewards for the ui
|
// Done purely virtually, this is used for retrieving up to date rewards for the ui
|
||||||
|
@ -582,13 +568,10 @@ contract StaticATokenLM is ERC20 {
|
||||||
uint256 freshReward = _incentivesController.getRewardsBalance(assets, address(this));
|
uint256 freshReward = _incentivesController.getRewardsBalance(assets, address(this));
|
||||||
uint256 externalLifetimeRewards = lifeTimeRewardsClaimed.add(freshReward);
|
uint256 externalLifetimeRewards = lifeTimeRewardsClaimed.add(freshReward);
|
||||||
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
uint256 diff = externalLifetimeRewards.sub(lifeTimeRewards).wadToRay();
|
||||||
|
_rewardIndex = _rewardIndex.add((diff).rayDivNoRounding(_supply.wadToRay()));
|
||||||
_accRewardstokenPerShare = _accRewardstokenPerShare.add(
|
|
||||||
(diff).rayDivNoRounding(_supply.wadToRay())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 _reward = rayBalance.rayMulNoRounding(_accRewardstokenPerShare);
|
uint256 _reward = rayBalance.rayMulNoRounding(_rewardIndex);
|
||||||
uint256 _debt = rewardDebts[user];
|
uint256 _debt = rewardDebts[user];
|
||||||
if (_reward > _debt) {
|
if (_reward > _debt) {
|
||||||
// Safe because line above
|
// Safe because line above
|
||||||
|
|
Loading…
Reference in New Issue
Block a user