Skip to content

Commit

Permalink
state not _state (yes, because of line length. so what? wanna fight a…
Browse files Browse the repository at this point in the history
…bout it?)
  • Loading branch information
pmckelvy1 committed Nov 29, 2023
1 parent d0eb11a commit 70645bf
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions contracts/plugins/assets/morpho-aave/MorphoTokenisedDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract contract MorphoTokenisedDeposit is RewardableERC4626Vault {
address public immutable poolToken;
address public immutable underlying;

MorphoTokenisedDepositRewardsAccountingState private _state;
MorphoTokenisedDepositRewardsAccountingState private state;

constructor(MorphoTokenisedDepositConfig memory config)
RewardableERC4626Vault(
Expand All @@ -44,7 +44,7 @@ abstract contract MorphoTokenisedDeposit is RewardableERC4626Vault {
morphoController = config.morphoController;
poolToken = address(config.poolToken);
rewardsDistributor = config.rewardsDistributor;
_state.lastSync = uint48(block.timestamp);
state.lastSync = uint48(block.timestamp);
}

function sync() external {
Expand All @@ -53,35 +53,33 @@ abstract contract MorphoTokenisedDeposit is RewardableERC4626Vault {

function _claimAssetRewards() internal override {
// First pay out any pendingBalances, over a 7200 block period
uint256 timeDelta = block.timestamp - _state.lastSync;
uint256 timeDelta = block.timestamp - state.lastSync;
if (timeDelta == 0) {
return;
}
if (timeDelta > PAYOUT_PERIOD) {
timeDelta = PAYOUT_PERIOD;
}
uint256 amtToPayOut = (_state.pendingBalance * ((timeDelta * 1e18) / PAYOUT_PERIOD)) / 1e18;
_state.pendingBalance -= amtToPayOut;
_state.availableBalance += amtToPayOut;
uint256 amtToPayOut = (state.pendingBalance * ((timeDelta * 1e18) / PAYOUT_PERIOD)) / 1e18;
state.pendingBalance -= amtToPayOut;
state.availableBalance += amtToPayOut;

// If we detect any new balances add it to pending and reset payout period
uint256 totalAccumulated = _state.totalPaidOutBalance + rewardToken.balanceOf(address(this));
uint256 newlyAccumulated = totalAccumulated - _state.totalAccumulatedBalance;
_state.totalAccumulatedBalance = totalAccumulated;
_state.pendingBalance += newlyAccumulated;
uint256 totalAccumulated = state.totalPaidOutBalance + rewardToken.balanceOf(address(this));
uint256 newlyAccumulated = totalAccumulated - state.totalAccumulatedBalance;
state.totalAccumulatedBalance = totalAccumulated;
state.pendingBalance += newlyAccumulated;

_state.lastSync = block.timestamp;
state.lastSync = block.timestamp;
}

function _rewardTokenBalance() internal view override returns (uint256) {
return _state.availableBalance;
return state.availableBalance;
}

function _distributeReward(address account, uint256 amt) internal override {
MorphoTokenisedDepositRewardsAccountingState memory state = _state;
state.totalPaidOutBalance += uint256(amt);
state.availableBalance -= uint256(amt);
_state = state;
SafeERC20.safeTransfer(rewardToken, account, amt);
}

Expand Down

0 comments on commit 70645bf

Please sign in to comment.