From eb524c55c9b2c68c50a2769d35a764b560267af5 Mon Sep 17 00:00:00 2001 From: RonTuretzky <74178515+RonTuretzky@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:36:52 +0300 Subject: [PATCH] Derive cycle length from actual distribution blocks (#102) * chore: adding more accurate cycle length derivation * chore: renaming for clarity --- src/YieldDistributor.sol | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/YieldDistributor.sol b/src/YieldDistributor.sol index 34a88b9..40daa6d 100644 --- a/src/YieldDistributor.sol +++ b/src/YieldDistributor.sol @@ -51,6 +51,8 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable { uint256 public yieldFixedSplitDivisor; /// @notice The address of the `ButteredBread` token contract ERC20VotesUpgradeable public BUTTERED_BREAD; + /// @notice The block number before the last yield distribution + uint256 public previousCycleStartingBlock; /// @custom:oz-upgrades-unsafe-allow constructor constructor() { @@ -108,12 +110,8 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable { * @return uint256 The voting power of the user */ function getCurrentVotingPower(address _account) public view returns (uint256) { - return this.getVotingPowerForPeriod( - BREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account - ) - + this.getVotingPowerForPeriod( - BUTTERED_BREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account - ); + return this.getVotingPowerForPeriod(BREAD, previousCycleStartingBlock, lastClaimedBlockNumber, _account) + + this.getVotingPowerForPeriod(BUTTERED_BREAD, previousCycleStartingBlock, lastClaimedBlockNumber, _account); } /// @notice Get the current accumulated voting power for a user @@ -197,6 +195,7 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable { if (!_resolved) revert YieldNotResolved(); BREAD.claimYield(BREAD.yieldAccrued(), address(this)); + previousCycleStartingBlock = lastClaimedBlockNumber; lastClaimedBlockNumber = block.number; uint256 balance = BREAD.balanceOf(address(this)); uint256 _fixedYield = balance / yieldFixedSplitDivisor;