Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: small corrections #134

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ module.exports = {
"bridges/test/WormholeL1Receiver.sol",
"bridges/test/WormholeL1Sender.sol",
"bridges/test/WormholeL2ReceiverL1Sender.sol",
"multisigs/test/DelegatecallExploit.sol",
"multisigs/test/MockTimelockCM.sol",
"multisigs/test/MockTreasury.sol",
"test/BridgeSetup.sol",
"test/BrokenERC20.sol",
"test/EchidnaVoteWeightingAssert.sol",
"test/SafeSetup.sol",
"multisigs/test/MockTimelockCM.sol",
"multisigs/test/MockTreasury.sol",
"test/VoteWeightingFuzzing.sol"
]
};
};
53 changes: 23 additions & 30 deletions contracts/VoteWeighting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
// Maximum chain Id as per EVM specs
uint256 public constant MAX_EVM_CHAIN_ID = type(uint64).max / 2 - 36;
// veOLAS contract address
address public immutable ve;

Check warning on line 141 in contracts/VoteWeighting.sol

View workflow job for this annotation

GitHub Actions / build

Immutable variables name are set to be in capitalized SNAKE_CASE
// Contract owner address
address public owner;
// Dispenser contract
Expand Down Expand Up @@ -190,7 +190,8 @@
owner = msg.sender;
ve = _ve;
timeSum = block.timestamp / WEEK * WEEK;
setNominees.push(Nominee(bytes32(0), 0));
// Push empty element to the zero-th index
setNominees.push(Nominee(0, 0));
}

/// @dev Fill sum of nominee weights for the same type week-over-week for missed checkins and return the sum for the future week.
Expand Down Expand Up @@ -367,24 +368,23 @@
dispenser = newDispenser;
}

/// @dev Checkpoint to fill data common for all nominees.
/// @dev Checkpoints to fill data common for all nominees.
function checkpoint() external {
_getSum();
}

/// @dev Checkpoint to fill data for both a specific nominee and common for all nominees.
/// @dev Checkpoints to fill data for both a specific nominee and common for all nominees.
/// @param account Address of the nominee.
/// @param chainId Chain Id.
function checkpointNominee(bytes32 account, uint256 chainId) external {
_getWeight(account, chainId);
_getSum();
}

/// @dev Get Nominee relative weight (not more than 1.0) normalized to 1e18 (e.g. 1.0 == 1e18) and a sum of weights.
/// Inflation which will be received by it is inflation_rate * relativeWeight / 1e18.
/// @dev Gets Nominee relative weight (not more than 1.0) normalized to 1e18 (e.g. 1.0 == 1e18) and a sum of weights.
/// @param account Address of the nominee in byte32 standard.
/// @param chainId Chain Id.
/// @param time Relative weight at the specified timestamp in the past or present.
/// @param time Timestamp in the past or present.
/// @return weight Value of relative weight normalized to 1e18.
/// @return totalSum Sum of nominee weights.
function _nomineeRelativeWeight(
Expand All @@ -404,12 +404,10 @@
}
}

/// @dev Get Nominee relative weight (not more than 1.0) normalized to 1e18 and the sum of weights.
/// (e.g. 1.0 == 1e18). Inflation which will be received by it is
/// inflation_rate * relativeWeight / 1e18.
/// @dev Gets Nominee relative weight (not more than 1.0) normalized to 1e18 (e.g. 1.0 == 1e18) and a sum of weights.
/// @param account Address of the nominee in bytes32 form.
/// @param chainId Chain Id.
/// @param time Relative weight at the specified timestamp in the past or present.
/// @param time Timestamp in the past or present.
/// @return weight Value of relative weight normalized to 1e18.
/// @return totalSum Sum of nominee weights.
function nomineeRelativeWeight(
Expand All @@ -420,12 +418,11 @@
(weight, totalSum) = _nomineeRelativeWeight(account, chainId, time);
}

/// @dev Get nominee weight normalized to 1e18 and also fill all the unfilled values for type and nominee records.
/// Also, get the total sum of all the nominee weights.
/// @notice Any address can call, however nothing is recorded if the values are filled already.
/// @dev Gets nominee weight normalized to 1e18 and also gets the total sum of all the nominee weights.
/// @notice Nothing is recorded if the values are already filled.
/// @param account Address of the nominee in bytes32 form.
/// @param chainId Chain Id.
/// @param time Relative weight at the specified timestamp in the past or present.
/// @param time Timestamp in the past or present.
/// @return weight Value of relative weight normalized to 1e18.
/// @return totalSum Sum of nominee weights.
function nomineeRelativeWeightWrite(
Expand All @@ -438,7 +435,7 @@
(weight, totalSum) = _nomineeRelativeWeight(account, chainId, time);
}

/// @dev Allocate voting power for changing pool weights.
/// @dev Allocates voting power for changing pool weights.
/// @param account Address of the nominee the `msg.sender` votes for in bytes32 form.
/// @param chainId Chain Id.
/// @param weight Weight for a nominee in bps (units of 0.01%). Minimal is 0.01%. Ignored if 0.
Expand Down Expand Up @@ -523,7 +520,7 @@
emit VoteForNominee(msg.sender, account, chainId, weight);
}

/// @dev Allocate voting power for changing pool weights in batch.
/// @dev Allocates voting power for changing pool weights in a batch set.
/// @param accounts Set of nominee addresses in bytes32 form the `msg.sender` votes for.
/// @param chainIds Set of corresponding chain Ids.
/// @param weights Weights for a nominees in bps (units of 0.01%). Minimal is 0.01%. Ignored if 0.
Expand Down Expand Up @@ -658,28 +655,28 @@

/// @dev Gets a full set of nominees.
/// @notice The returned set includes the zero-th empty nominee instance.
/// @return nominees Set of all the nominees in the contract.
function getAllNominees() external view returns (Nominee[] memory nominees) {
nominees = setNominees;
/// @return Set of all the nominees in the contract.
function getAllNominees() external view returns (Nominee[] memory) {
return setNominees;
}

/// @dev Gets the nominee Id in the global nominees set.
/// @param account Nominee address in bytes32 form.
/// @param chainId Chain Id.
/// @return id Nominee Id in the global set of Nominee struct values.
function getNomineeId(bytes32 account, uint256 chainId) external view returns (uint256 id) {
/// @return Nominee Id in the global set of Nominee struct values.
function getNomineeId(bytes32 account, uint256 chainId) external view returns (uint256) {
// Get the nominee struct and hash
Nominee memory nominee = Nominee(account, chainId);
bytes32 nomineeHash = keccak256(abi.encode(nominee));

id = mapNomineeIds[nomineeHash];
return mapNomineeIds[nomineeHash];
}

/// @dev Get the nominee address and its corresponding chain Id.
/// @notice The zero-th default nominee Id with id == 0 does not count.
/// @param id Nominee Id in the global set of Nominee struct values.
/// @return nominee Nominee address in bytes32 form and chain Id.
function getNominee(uint256 id) external view returns (Nominee memory nominee) {
/// @return Nominee address in bytes32 form and chain Id.
function getNominee(uint256 id) external view returns (Nominee memory) {
// Get the total number of nominees in the contract
uint256 totalNumNominees = setNominees.length - 1;
// Check for the zero id or the overflow
Expand All @@ -689,19 +686,15 @@
revert Overflow(id, totalNumNominees);
}

nominee = setNominees[id];
return setNominees[id];
}

/// @dev Get the set of nominee addresses and corresponding chain Ids.
/// @notice The zero-th default nominee Id with id == 0 does not count.
/// @param startId Start Id of the nominee in the global set of Nominee struct values.
/// @param numNominees Number of nominees to get.
/// @return nominees Set of nominee accounts in bytes32 form and chain Ids.
function getNominees(
uint256 startId,
uint256 numNominees
) external view returns (Nominee[] memory nominees)
{
function getNominees(uint256 startId, uint256 numNominees) external view returns (Nominee[] memory nominees) {
// Check for the zero id or the overflow
if (startId == 0 || numNominees == 0) {
revert ZeroValue();
Expand Down
2 changes: 1 addition & 1 deletion test/VoteWeighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { expect } = require("chai");
const { ethers } = require("hardhat");
const helpers = require("@nomicfoundation/hardhat-network-helpers");

describe("Voting Escrow OLAS", function () {
describe("Vote Weighting veOLAS", function () {
let olas;
let ve;
let vw;
Expand Down
Loading