Skip to content

Commit

Permalink
feat: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 committed Feb 29, 2024
1 parent 7ec2a28 commit ec764ed
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
27 changes: 15 additions & 12 deletions contracts/governance/locking/Locking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
* @notice Initializes the locking contract.
* @dev Sets up the base locking parameters and initializes ownership and context setup
* @param _token Address of the ERC20 that will be locked. (Mento Token)
* @param _startingPointWeek Origin week no for the week-based time system
* @param _startingPointWeek Origin week number for the week-based time system
* @param _minCliffPeriod Minimum cliff period for locks
* @param _minSlopePeriod Minimum slope period for locks
*/
Expand All @@ -37,7 +37,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {

/**
* @notice Stops the locking functionality
* @dev Can only be called by the owner
* @dev Can only be called by the owner while locking is active (meaning not stopped)
*/
function stop() external onlyOwner notStopped {
stopped = true;
Expand All @@ -46,7 +46,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {

/**
* @notice Restarts the locking functionality after it has been stopped
* @dev Can only be called by the owner
* @dev Can only be called by the owner while locking is stopped
*/
function start() external onlyOwner isStopped {
stopped = false;
Expand All @@ -56,7 +56,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
/**
* @notice Begins the migration process to a new contract
* @dev Can only be called by the owner
* @param to Address of the new contract where future operations will be migrated
* @param to Address of the new contract where future operations will be migrated to
*/
function startMigration(address to) external onlyOwner {
// slither-disable-next-line missing-zero-check
Expand All @@ -66,6 +66,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {

/**
* @notice Locks a specified amount of tokens for a given period
* @dev Can not be called when locking is stopped or migration is in progress
* @param account Account for which tokens are being locked
* @param _delegate Address that will receive the voting power from the locked tokens
* If address(0) passed, voting power will be lost
Expand Down Expand Up @@ -100,7 +101,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
}

/**
* @notice Withdraws available tokens for the caller
* @notice Withdraws unlocked tokens for the caller
*/
function withdraw() external {
uint96 value = getAvailableForWithdraw(msg.sender);
Expand Down Expand Up @@ -131,7 +132,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
/**
* @notice Returns the total amount of tokens locked for an account
* @param account The account to check locked amount for
* @return The total locked amount
* @return The locked amount for the account
*/
function locked(address account) external view returns (uint256) {
return accounts[account].amount;
Expand All @@ -141,15 +142,17 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
* @notice Retrieves the account and delegate associated with a given lock ID
* @param id The id of the lock
* @return _account The account that owns the lock
* @return _delegate The account owns the voting power
* @return _delegate The account that owns the voting power
*/
function getAccountAndDelegate(uint256 id) external view returns (address _account, address _delegate) {
_account = locks[id].account;
_delegate = locks[id].delegate;
}

/**
* @notice Returns "current week" of the contract
* @notice Returns "current week" of the contract. The Locking contract works with a week-based time system
* for managing locks and voting power. The current week number is calculated based on the number of weeks passed
* since the starting point week. The starting point is set during the contract initialization.
*/
function getWeek() external view returns (uint256) {
return roundTimestamp(getBlockNumber());
Expand All @@ -176,8 +179,8 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
}

/**
* @notice Current total supply of veMENTO tokens
* @return The total locked supply affecting voting power
* @notice Returns the current total supply of veMENTO tokens
* @return The total supply of veMENTO tokens
*/
function totalSupply() external view returns (uint256) {
if ((totalSupplyLine.initial.bias == 0) || (stopped)) {
Expand All @@ -191,7 +194,7 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {
/**
* @notice Retrieves the veMENTO balance of an account
* @param account The account to check the balance for
* @return The balance of veMENTO tokens affecting voting power
* @return The accounts balance of veMENTO tokens
*/
function balanceOf(address account) external view returns (uint256) {
if ((accounts[account].balance.initial.bias == 0) || (stopped)) {
Expand All @@ -204,8 +207,8 @@ contract Locking is ILocking, LockingBase, LockingRelock, LockingVotes {

/**
* @notice Migrates specified locks to a new contract
* @param id An array of lock IDs to be migrated
* @dev Performs the migration by transferring locked tokens and updating delegations as necessary
* @param id An array of lock IDs to be migrated
*/
function migrate(uint256[] memory id) external {
if (migrateTo == address(0)) {
Expand Down
48 changes: 24 additions & 24 deletions contracts/governance/locking/LockingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import "./libs/LibBrokenLine.sol";
/**
* @title LockingBase
* @dev This abstract contract provides the foundational functionality
* for locking ERC20 tokens to accrue voting power over time.
* for locking ERC20 tokens to accrue voting power.
* @dev It utilizes the Broken Line library to represent the decay of voting power as tokens unlock.
* @notice https://github.com/rarible/locking-contracts/tree/4f189a96b3e85602dedfbaf69d9a1f5056d835eb
*/
abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
using LibBrokenLine for LibBrokenLine.BrokenLine;
/**
* @dev Duration of a week in blocks on the CELO blockchain
* @dev Duration of a week in blocks on the CELO blockchain assuming 5 seconds per block
*/
uint32 public constant WEEK = 120_960;
/**
Expand Down Expand Up @@ -45,7 +45,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
*/
bool public stopped;
/**
* @dev Address to migrate locks to, if any
* @dev Address to migrate locks to. Is zero if not in migration state
*/
address public migrateTo;
/**
Expand All @@ -57,7 +57,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
*/
uint256 public minSlopePeriod;
/**
* @dev Starting point for the locking week-based time system
* @dev Starting point week for the locking week-based time system
*/
uint256 public startingPointWeek;
/**
Expand Down Expand Up @@ -157,7 +157,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
/**
* @dev Initializes the contract with token, starting point week, and minimum cliff and slope periods.
* @param _token ERC20 token to be locked. (Mento Token)
* @param _startingPointWeek Origin week no for the week-based time system.
* @param _startingPointWeek Origin week number for the week-based time system.
* @param _minCliffPeriod Minimum cliff period for locks.
* @param _minSlopePeriod Minimum slope period for locks.
*/
Expand Down Expand Up @@ -212,7 +212,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice updates broken lines for account and delegate, and total supply
* @notice Updates broken lines for account, delegate and total supply
* @param account address of account that locked tokens
* @param _delegate address of delegate that owns the voting power
* @param time week number till which to update lines
Expand All @@ -228,7 +228,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice calculates lockAmount and lockSlope for given lock parameters
* @notice Calculates lockAmount and lockSlope for given lock parameters
* @dev Сalculate and return (lockAmount, lockSlope), using formula:
* P = t * min(c/c_max + s/s_max, 1),
*
Expand Down Expand Up @@ -277,7 +277,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice calculates a divided by b rounded up
* @notice Calculates a divided by b rounded up
* @param a numerator
* @param b denominator
* @return ⌈a/b⌉
Expand All @@ -287,9 +287,9 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice calculates the week number for a given blocknumber
* @notice Calculates the week number for a given blocknumber
* @param ts block number
* @return week number blocknumber belongs to
* @return week number the block number belongs to
*/
function roundTimestamp(uint32 ts) public view returns (uint32) {
if (ts < getEpochShift()) {
Expand All @@ -308,7 +308,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice verifies msg.sender is lock owner
* @notice Verifies msg.sender is lock owner
* @param id lock id to verify
* @return account address of lock owner
*/
Expand All @@ -318,15 +318,15 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice returns the current block number as a uint32
* @notice Returns the current block number as a uint32
* @return current block number
*/
function getBlockNumber() internal view virtual returns (uint32) {
return uint32(block.number);
}

/**
* @notice sets the starting point for the week-based time system
* @notice Sets the starting point for the week-based time system
* @param newStartingPointWeek new starting point
*/
function setStartingPointWeek(uint32 newStartingPointWeek) public notStopped notMigrating onlyOwner {
Expand All @@ -337,7 +337,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice sets the minimum cliff period
* @notice Sets the minimum cliff period
* @param newMinCliffPeriod new minimum cliff period
*/
function setMinCliffPeriod(uint32 newMinCliffPeriod) external notStopped notMigrating onlyOwner {
Expand All @@ -348,7 +348,7 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice sets the minimum slope period
* @notice Sets the minimum slope period
* @param newMinSlopePeriod new minimum slope period
*/
function setMinSlopePeriod(uint32 newMinSlopePeriod) external notStopped notMigrating onlyOwner {
Expand All @@ -375,35 +375,35 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @dev Throws if migrating
* @dev Throws if migration is active
*/
modifier notMigrating() {
require(migrateTo == address(0), "migrating");
_;
}

/**
* @notice updates the broken lines for an account till a given week number
* @notice Updates the broken lines for an account until a given week number
* @param account address of account to update
* @param time week number till which to update lines
* @param time week number until which to update lines
*/
function updateAccountLines(address account, uint32 time) public notStopped notMigrating onlyOwner {
accounts[account].balance.update(time);
accounts[account].locked.update(time);
}

/**
* @notice updates the total supply line till a given week number
* @param time week number till which to update lines
* @notice updates the total supply line until a given week number
* @param time week number until which to update lines
*/
function updateTotalSupplyLine(uint32 time) public notStopped notMigrating onlyOwner {
totalSupplyLine.update(time);
}

/**
* @notice updates the broken lines for an account till a given block number
* @notice updates the broken lines for an account until a given block number
* @param account address of account to update
* @param blockNumber block number till which to update lines
* @param blockNumber block number until which to update lines
*/
function updateAccountLinesBlockNumber(address account, uint32 blockNumber)
external
Expand All @@ -416,8 +416,8 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

/**
* @notice updates the total supply line till a given block number
* @param blockNumber block number till which to update line
* @notice Updates the total supply line until a given block number
* @param blockNumber block number until which to update line
*/
function updateTotalSupplyLineBlockNumber(uint32 blockNumber) external notStopped notMigrating onlyOwner {
uint32 time = roundTimestamp(blockNumber);
Expand Down
6 changes: 3 additions & 3 deletions contracts/governance/locking/LockingRelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract contract LockingRelock is LockingBase {
using LibBrokenLine for LibBrokenLine.BrokenLine;

/**
* @notice relock tokens allows to change lock parameters
* @notice Relocking tokens allows to changing lock parameters
* @param id lock id of lock to relock
* @param newDelegate new delegate address
* @param newAmount new amount to lock
Expand Down Expand Up @@ -88,7 +88,7 @@ abstract contract LockingRelock is LockingBase {
}

/**
* @notice removes a given lock from the lock owner, delegate and total supply
* @notice Removes a given lock from the lock owner, delegate and total supply
* @param id lock id of lock to remove
* @param account address of account that owns the lock
* @param delegate address of delegate that owns the voting power
Expand All @@ -110,7 +110,7 @@ abstract contract LockingRelock is LockingBase {
}

/**
* @notice rebalances additional tokens for the relock
* @notice Rebalances additional tokens for the relock
* @param id lock id of lock to relock
* @param account address of account that owns the old lock
* @param bias bias of the old lock
Expand Down
18 changes: 9 additions & 9 deletions contracts/governance/locking/libs/LibBrokenLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ library LibBrokenLine {
}

/**
* @notice adds a line to a given BrokenLine struct
* @notice Adds a line to a given BrokenLine struct
* @dev Add Line, save data in LineData. Run update BrokenLine, require:
* 1. slope != 0, slope <= bias
* 2. line not exists
Expand Down Expand Up @@ -100,7 +100,7 @@ library LibBrokenLine {
}

/**
* @notice adds a line to a given BrokenLine struct and saves a snapshot
* @notice Adds a line to a given BrokenLine struct and saves a snapshot
* @param brokenLine the BrokenLine struct to add the line to
* @param id the id of the line to add
* @param line the line to add
Expand All @@ -117,7 +117,7 @@ library LibBrokenLine {
}

/**
* @notice removes a line from a given BrokenLine struct
* @notice Removes a line from a given BrokenLine struct
* @param brokenLine the BrokenLine struct to remove the line from
* @param id the id of the line to remove
* @param toTime current week number
Expand Down Expand Up @@ -187,7 +187,7 @@ library LibBrokenLine {
}

/**
* @notice removes a line from a given BrokenLine struct and saves a snapshot
* @notice Removes a line from a given BrokenLine struct and saves a snapshot
* @param brokenLine the BrokenLine struct to remove the line from
* @param id the id of the line to remove
* @param toTime current week number
Expand All @@ -214,7 +214,7 @@ library LibBrokenLine {
}

/**
* @notice updates a given BrokenLine till a given week number
* @notice Updates a given BrokenLine until a given week number
* @param brokenLine the BrokenLine struct to update
* @param toTime the week number to update the BrokenLine to
*/
Expand Down Expand Up @@ -243,7 +243,7 @@ library LibBrokenLine {
}

/**
* @notice returns y value of a given BrokenLine at a given week and block number
* @notice Returns y value of a given BrokenLine at a given week and block number
* @param brokenLine the BrokenLine struct to get the value from
* @param toTime the week number to get the value at
* @param toBlock the block number to get the value at
Expand All @@ -269,9 +269,9 @@ library LibBrokenLine {
}

/**
* @notice calculates and returns the y value of a given BrokenLine for given a week
* @notice Calculates and returns the y value of a given BrokenLine for given a week
* @dev calculates the y value at toTime by applying the slope to the bias starting at the fromTime.
* Per week the slope is updated by the slopeChanges map until the toTime is reached.
* Per week the slope is updated by the slopeChanges map until the toTime is reached.
* @param brokenLine the BrokenLine struct to calculate the value for
* @param fromTime the week number to start the calculation from
* @param toTime the week number to calculate the value at
Expand Down Expand Up @@ -304,7 +304,7 @@ library LibBrokenLine {
}

/**
* @notice finds the closest snapshot to a given block number and calculates the y value based on that.
* @notice Finds the closest snapshot to a given block number and calculates the y value based on that.
* @param brokenLine the BrokenLine struct to calculate the value for
* @param toTime the week number to get the y value at
* @param toBlock the block number to get the y value at
Expand Down

0 comments on commit ec764ed

Please sign in to comment.