Skip to content

Commit

Permalink
limit voting power with initial amount
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Mar 20, 2023
1 parent c2b532c commit 4dc0e78
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
15 changes: 9 additions & 6 deletions contracts/VestedVotingPower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity 0.8.19;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./interfaces/IStepVesting.sol";
import "./interfaces/ISt1inch.sol";
Expand Down Expand Up @@ -38,14 +39,16 @@ contract VestedVotingPower is Ownable, VotingPowerCalculator {
uint256 started = vesting.started();
uint256 cliffDuration = vesting.cliffDuration();
uint256 stepDuration = vesting.stepDuration();
if (block.timestamp < started + cliffDuration) {
votingPower += _votingPowerAt(_balanceAt(vesting.cliffAmount() / _VOTING_POWER_DIVIDER, started + cliffDuration), block.timestamp);
}
uint256 cliffAmount = vesting.cliffAmount();
uint256 numOfSteps = vesting.numOfSteps();
uint256 stepAmount = vesting.stepAmount();
uint256 claimed = vesting.claimed();
if (claimed < cliffAmount) {
votingPower += Math.min(cliffAmount, _votingPowerAt(_balanceAt(cliffAmount / _VOTING_POWER_DIVIDER, started + cliffDuration), block.timestamp));
}
for (uint256 j = 0; j < numOfSteps; j++) {
uint256 stepUnlockTimestamp = started + cliffDuration + stepDuration * (j + 1);
if (block.timestamp < stepUnlockTimestamp) {
votingPower += _votingPowerAt(_balanceAt(vesting.stepAmount() / _VOTING_POWER_DIVIDER, stepUnlockTimestamp), block.timestamp);
if (claimed < cliffAmount + stepAmount * (j + 1)) {
votingPower += Math.min(stepAmount, _votingPowerAt(_balanceAt(stepAmount / _VOTING_POWER_DIVIDER, started + cliffDuration + stepDuration * (j + 1)), block.timestamp));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IStepVesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface IStepVesting {
function stepDuration() external view returns (uint256);
function stepAmount() external view returns (uint256);
function numOfSteps() external view returns (uint256);
function claimed() external view returns (uint256);
}
62 changes: 31 additions & 31 deletions deployments/mainnet/VestedVotingPower.json

Large diffs are not rendered by default.

0 comments on commit 4dc0e78

Please sign in to comment.