Skip to content

Commit

Permalink
Merge pull request #2 from ThenafiBNB/C-01
Browse files Browse the repository at this point in the history
C-01
  • Loading branch information
PrometeoThena committed Jun 11, 2023
2 parents 2bb84cf + f2c6688 commit d9962ba
Showing 1 changed file with 3 additions and 46 deletions.
49 changes: 3 additions & 46 deletions contracts/VoterV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ contract VoterV3 is IVoter, OwnableUpgradeable, ReentrancyGuardUpgradeable {
uint256 _votes = votes[_tokenId][_pool];

if (_votes != 0) {
_updateFor(gauges[_pool]);

// if user last vote is < than epochTimestamp then votes are 0! IF not underflow occur
if(lastVoted[_tokenId] > _epochTimestamp()) weightsPerEpoch[_time][_pool] -= _votes;
Expand Down Expand Up @@ -436,7 +435,6 @@ contract VoterV3 is IVoter, OwnableUpgradeable, ReentrancyGuardUpgradeable {
uint256 _poolWeight = _weights[i] * _weight / _totalVoteWeight;
require(votes[_tokenId][_pool] == 0);
require(_poolWeight != 0);
_updateFor(_gauge);

poolVote[_tokenId].push(_pool);
weightsPerEpoch[_time][_pool] += _poolWeight;
Expand Down Expand Up @@ -611,7 +609,7 @@ contract VoterV3 is IVoter, OwnableUpgradeable, ReentrancyGuardUpgradeable {
pools.push(_pool);

// update index
_updateFor(_gauge);
supplyIndex[_gauge] = index; // new gauges are set to the default global state

emit GaugeCreated(_gauge, msg.sender, _internal_bribe, _external_bribe, _pool);
}
Expand Down Expand Up @@ -785,49 +783,8 @@ contract VoterV3 is IVoter, OwnableUpgradeable, ReentrancyGuardUpgradeable {
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------------------------------------- */

/// @notice update info for given gauges
function updateFor(address[] memory _gauges) external {
for (uint i = 0; i < _gauges.length; i++) {
_updateFor(_gauges[i]);
}
}

/// @notice update gauge info from start to end
function updateForRange(uint start, uint end) public {
for (uint i = start; i < end; i++) {
_updateFor(gauges[pools[i]]);
}
}

/// @notice update info for ALL gauges
function updateAll() external {
updateForRange(0, pools.length);
}

/// @notice update info for gauges
/// @dev this function track the gauge index to emit the correct $the amount
function _updateFor(address _gauge) internal {
address _pool = poolForGauge[_gauge];
uint256 _time = _epochTimestamp();
uint256 _supplied = weightsPerEpoch[_time][_pool];

if (_supplied > 0) {
uint _supplyIndex = supplyIndex[_gauge];
uint _index = index; // get global index0 for accumulated distro
supplyIndex[_gauge] = _index; // update _gauge current position to global position
uint _delta = _index - _supplyIndex; // see if there is any difference that need to be accrued
if (_delta > 0) {
uint _share = uint(_supplied) * _delta / 1e18; // add accrued difference for each supplied token
if (isAlive[_gauge]) {
claimable[_gauge] += _share;
}
}
} else {
supplyIndex[_gauge] = index; // new users are set to the default global state
}
}



/// @notice update info for gauges
/// @dev this function track the gauge index to emit the correct $the amount after the distribution
function _updateForAfterDistribution(address _gauge) private {
Expand Down

0 comments on commit d9962ba

Please sign in to comment.