Skip to content

Commit

Permalink
Derive cycle length from actual distribution blocks (#102)
Browse files Browse the repository at this point in the history
* chore: adding more accurate cycle length derivation

* chore: renaming for clarity
  • Loading branch information
RonTuretzky authored Oct 24, 2024
1 parent c05d3f9 commit eb524c5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/YieldDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb524c5

Please sign in to comment.