Skip to content

Commit 10d911c

Browse files
SaraSara
Sara
authored and
Sara
committed
what if the voting streak was managed in yielddistributor
1 parent 0ee81a2 commit 10d911c

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/VotingMultipliers.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ contract VotingMultipliers is Ownable2StepUpgradeable, IVotingMultipliers {
6969

7070
/// @notice Calculates the total multiplier for a given user using specific multiplier indexes
7171
/// @param _user The address of the user
72+
/// @param _baseMultiplier A base multiplier provided by the function caller
7273
/// @param _multiplierIndexes Array of multiplier indexes to use
7374
/// @return The total multiplier value for the user
74-
function getTotalMultipliers(address _user, uint256[] calldata _multiplierIndexes) public view returns (uint256) {
75-
uint256 _totalMultiplier = 0;
75+
function getTotalMultipliers(address _user, uint256 baseMultiplier, uint256[] calldata _multiplierIndexes)
76+
public
77+
view
78+
returns (uint256)
79+
{
80+
uint256 _totalMultiplier = baseMultiplier;
7681

7782
for (uint256 i = 0; i < _multiplierIndexes.length; i++) {
7883
uint256 index = _multiplierIndexes[i];

src/YieldDistributor.sol

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ contract YieldDistributor is IYieldDistributor, Ownable2StepUpgradeable, VotingM
5656
ERC20VotesUpgradeable public BUTTERED_BREAD;
5757
/// @notice The block number before the last yield distribution
5858
uint256 public previousCycleStartingBlock;
59-
/// @notice The interface for the `VotingStreakMultiplier` contract
60-
IVotingStreakMultiplier public votingStreakMultiplier;
59+
/// @notice Mapping of user addresses to their current multiplier factor
60+
mapping(address => uint256) public userToMultiplier;
61+
/// @notice Mapping of user addresses to their multiplier validity period
62+
mapping(address => uint256) public userToValidity;
63+
/// @notice The maximum multiplier incrementation
64+
uint256 public maxVotingStreakMultiplier;
65+
/// @notice The increment value for the multiplier
66+
uint256 public votingStreakMultiplierIncrement;
6167

6268
/// @custom:oz-upgrades-unsafe-allow constructor
6369
constructor(address _votingStreakMultiplier) {
@@ -233,14 +239,26 @@ contract YieldDistributor is IYieldDistributor, Ownable2StepUpgradeable, VotingM
233239
_castVote(msg.sender, _points, _currentVotingPower);
234240
}
235241

242+
/// @notice Calculate and return the voting streak multiplier for a user
243+
/// @param _account Address of the user to calculate the multiplier for
244+
/// @return uint256 The calculated voting streak multiplier
245+
function votingStreakMultiplier(address _account) public view returns (uint256) {
246+
uint256 validity = userToValidity[_account];
247+
if (block.number > validity) {
248+
return 0; // No active multiplier
249+
}
250+
return userToMultiplier[_account]; // Return the current multiplier
251+
}
252+
236253
/**
237254
* @notice Cast votes for the distribution of $BREAD yield with multipliers
238255
* @param _points List of points as integers for each project
239256
* @param _multiplierIndices List of indices of multipliers to use for each project
240257
*/
241258
function castVoteWithMultipliers(uint256[] calldata _points, uint256[] calldata _multiplierIndices) public {
242259
uint256 _currentVotingPower = getCurrentVotingPower(msg.sender);
243-
uint256 multiplier = getTotalMultipliers(msg.sender, _multiplierIndices);
260+
uint256 baseMultiplier = votingStreakMultiplier(msg.sender);
261+
uint256 multiplier = getTotalMultipliers(msg.sender, baseMultiplier, _multiplierIndices);
244262
_currentVotingPower = multiplier == 0 ? _currentVotingPower : (_currentVotingPower * multiplier) / PRECISION;
245263
if (_currentVotingPower < minRequiredVotingPower) revert BelowMinRequiredVotingPower();
246264
_castVote(msg.sender, _points, _currentVotingPower);
@@ -410,4 +428,16 @@ contract YieldDistributor is IYieldDistributor, Ownable2StepUpgradeable, VotingM
410428
function setButteredBread(address _butteredBread) public onlyOwner {
411429
BUTTERED_BREAD = ERC20VotesUpgradeable(_butteredBread);
412430
}
431+
432+
/// @notice Sets the multiplier increment value
433+
/// @param _multiplierIncrement The new multiplier increment value
434+
function setVotingStreakMultiplierIncrement(uint256 _votingStreakMultiplierIncrement) external onlyOwner {
435+
votingStreakMultiplierIncrement = _votingStreakMultiplierIncrement;
436+
}
437+
438+
/// @notice Sets the maximum multiplier value
439+
/// @param _maxMultiplier The new maximum multiplier value
440+
function setMaxVotingStreakMultiplier(uint256 _maxVotingStreakMultiplier) external onlyOwner {
441+
maxVotingStreakMultiplier = _maxVotingStreakMultiplier;
442+
}
413443
}

0 commit comments

Comments
 (0)