This contract handles the rewards for voters in the VeBetterDAO ecosystem. It calculates the rewards for voters based on their voting power and the level of their Galaxy Member NFT.
_The contract is - upgradeable using UUPSUpgradeable. - using AccessControl to handle the admin and upgrader roles. - using ReentrancyGuard to prevent reentrancy attacks. - following the ERC-7201 standard for storage layout.
Roles: - DEFAULT_ADMIN_ROLE: The role that can add new admins and upgraders. It is also the role that can set scaling factor and the Galaxy Member level to multiplier mapping. - UPGRADER_ROLE: The role that can upgrade the contract. - VOTE_REGISTRAR_ROLE: The role that can register votes for rewards calculation. - CONTRACTS_ADDRESS_MANAGER_ROLE: The role that can set the addresses of the contracts used by the VoterRewards contract.
—————— Version 2 Changes —————— - Added quadratic rewarding disabled checkpoints to disable quadratic rewarding for a specific cycle. - Added the clock function to get the current block number. - Added functions to check if quadratic rewarding is disabled at a specific block number or for the current cycle. - Added function to disable quadratic rewarding or re-enable it.
—————— Version 3 Changes —————— - Added the ability to track if a Galaxy Member NFT has voted in a proposal. - Added the ability to track if a Vechain node attached to a Galaxy Member NFT has voted in a proposal. - Proposal Id is now required when registering votes instead of proposal snapshot. - Core logic functions are now virtual allowing to be overridden through inheritance.
—————— Version 4 Changes —————— - Update the contract to use new Galaxy Member interface._
bytes32 VOTE_REGISTRAR_ROLE
The role that can register votes for rewards calculation.
bytes32 UPGRADER_ROLE
The role that can upgrade the contract.
bytes32 CONTRACTS_ADDRESS_MANAGER_ROLE
The role that can set the addresses of the contracts used by the VoterRewards contract.
uint256 SCALING_FACTOR
The scaling factor for the rewards calculation.
struct VoterRewardsStorage {
contract IGalaxyMember galaxyMember;
contract IB3TR b3tr;
contract IEmissions emissions;
mapping(uint256 => uint256) levelToMultiplier;
mapping(uint256 => uint256) cycleToTotal;
mapping(uint256 => mapping(address => uint256)) cycleToVoterToTotal;
struct Checkpoints.Trace208 quadraticRewardingDisabled;
mapping(uint256 => mapping(uint256 => bool)) proposalToGalaxyMemberToHasVoted;
mapping(uint256 => mapping(uint256 => bool)) proposalToNodeToHasVoted;
}
function _getVoterRewardsStorage() internal pure returns (struct VoterRewards.VoterRewardsStorage $)
Get the VoterRewardsStorage struct from the specified storage slot specified by the VoterRewardsStorageLocation.
event VoteRegistered(uint256 cycle, address voter, uint256 votes, uint256 rewardWeightedVote)
Emitted when a user registers their votes for rewards calculation.
Name | Type | Description |
---|---|---|
cycle | uint256 | - The cycle in which the votes were registered. |
voter | address | |
votes | uint256 | - The number of votes cast by the voter. |
rewardWeightedVote | uint256 | - The reward-weighted vote power for the voter based on their voting power and GM NFT level. |
event RewardClaimed(uint256 cycle, address voter, uint256 reward)
Emitted when a user claims their rewards.
Name | Type | Description |
---|---|---|
cycle | uint256 | - The cycle in which the rewards were claimed. |
voter | address | - The address of the voter. |
reward | uint256 | - The amount of B3TR reward claimed by the voter. |
event GalaxyMemberAddressUpdated(address newAddress, address oldAddress)
Emitted when the Galaxy Member contract address is set.
Name | Type | Description |
---|---|---|
newAddress | address | - The address of the new Galaxy Member contract. |
oldAddress | address | - The address of the old Galaxy Member contract. |
event EmissionsAddressUpdated(address newAddress, address oldAddress)
Emitted when the Emissions contract address is set.
Name | Type | Description |
---|---|---|
newAddress | address | - The address of the new Emissions contract. |
oldAddress | address | - The address of the old Emissions contract. |
event LevelToMultiplierSet(uint256 level, uint256 multiplier)
Emitted when the level to multiplier mapping is set.
Name | Type | Description |
---|---|---|
level | uint256 | - The level of the Galaxy Member NFT. |
multiplier | uint256 | - The percentage multiplier for the level of the Galaxy Member NFT. |
event QuadraticRewardingToggled(bool disabled)
Emits true if quadratic rewarding is disabled, false otherwise.
Name | Type | Description |
---|---|---|
disabled | bool | - The flag to enable or disable quadratic rewarding. |
constructor() public
function initialize(address admin, address upgrader, address contractsAddressManager, address _emissions, address _galaxyMember, address _b3tr, uint256[] levels, uint256[] multipliers) external
Initialize the VoterRewards contract.
Name | Type | Description |
---|---|---|
admin | address | - The address of the admin. |
upgrader | address | - The address of the upgrader. |
contractsAddressManager | address | - The address of the contract address manager. |
_emissions | address | - The address of the emissions contract. |
_galaxyMember | address | - The address of the Galaxy Member contract. |
_b3tr | address | - The address of the B3TR token contract. |
levels | uint256[] | - The levels of the Galaxy Member NFTs. |
multipliers | uint256[] | - The multipliers for the levels of the Galaxy Member NFTs. |
function _authorizeUpgrade(address newImplementation) internal
Upgrade the implementation of the VoterRewards contract.
Only the address with the UPGRADER_ROLE can call this function.
Name | Type | Description |
---|---|---|
newImplementation | address | - The address of the new implementation contract. |
function registerVote(uint256 proposalId, address voter, uint256 votes, uint256 votePower) public virtual
Register the votes of a user for rewards calculation.
Quadratic rewarding is used to reward users with quadratic-weight based on their voting power and the level of their Galaxy Member NFT.
Name | Type | Description |
---|---|---|
proposalId | uint256 | - The ID of the proposal. |
voter | address | - The address of the voter. |
votes | uint256 | - The number of votes cast by the voter. |
votePower | uint256 | - The square root of the total votes cast by the voter. |
function claimReward(uint256 cycle, address voter) public virtual
Claim the rewards for a user in a specific cycle.
The rewards are claimed based on the reward-weighted votes of the user in the cycle.
Name | Type | Description |
---|---|---|
cycle | uint256 | - The cycle in which the rewards are claimed. |
voter | address | - The address of the voter. |
function getMultiplier(uint256 tokenId, uint256 proposalId) public view virtual returns (uint256)
Get the reward multiplier for a user in a specific proposal.
Name | Type | Description |
---|---|---|
tokenId | uint256 | Id of the Galaxy Member NFT |
proposalId | uint256 | Id of the proposal |
function hasNodeVoted(uint256 nodeId, uint256 proposalId) public view virtual returns (bool)
Check if a Vechain Node has voted in a proposal
Name | Type | Description |
---|---|---|
nodeId | uint256 | Id of the Vechain node |
proposalId | uint256 | Id of the proposal |
function hasTokenVoted(uint256 tokenId, uint256 proposalId) public view virtual returns (bool)
Check if a Galaxy Member has voted in a proposal
Name | Type | Description |
---|---|---|
tokenId | uint256 | Id of the Galaxy Member NFT |
proposalId | uint256 | Id of the proposal |
function getReward(uint256 cycle, address voter) public view virtual returns (uint256)
Get the reward for a user in a specific cycle.
Name | Type | Description |
---|---|---|
cycle | uint256 | - The cycle in which the rewards are claimed. |
voter | address | - The address of the voter. |
function cycleToVoterToTotal(uint256 cycle, address voter) external view returns (uint256)
Get the total reward-weighted votes for a user in a specific cycle.
Name | Type | Description |
---|---|---|
cycle | uint256 | - The cycle in which the rewards are claimed. |
voter | address | - The address of the voter. |
function cycleToTotal(uint256 cycle) external view returns (uint256)
Get the total reward-weighted votes in a specific cycle.
Name | Type | Description |
---|---|---|
cycle | uint256 | - The cycle in which the rewards are claimed. |
function levelToMultiplier(uint256 level) external view returns (uint256)
Get the reward multiplier for a specific level of the Galaxy Member NFT.
Name | Type | Description |
---|---|---|
level | uint256 | - The level of the Galaxy Member NFT. |
function galaxyMember() external view returns (contract IGalaxyMember)
Get the Galaxy Member contract.
function emissions() external view returns (contract IEmissions)
Get the Emissions contract.
function b3tr() external view returns (contract IB3TR)
Get the B3TR token contract.
function isQuadraticRewardingDisabledAtBlock(uint48 blockNumber) public view returns (bool)
Check if quadratic rewarding is disabled at a specific block number.
To check if quadratic rewarding was disabled for a cycle, use the block number the cycle started.
Name | Type | Description |
---|---|---|
blockNumber | uint48 | - The block number to check the quadratic rewarding status. |
Name | Type | Description |
---|---|---|
[0] | bool | true if quadratic rewarding is disabled, false otherwise. |
function isQuadraticRewardingDisabledForCurrentCycle() public view returns (bool)
Check if quadratic rewarding is disabled for the current cycle.
Name | Type | Description |
---|---|---|
[0] | bool | true if quadratic rewarding is disabled, false otherwise. |
function setGalaxyMember(address _galaxyMember) public virtual
Set the Galaxy Member contract.
Name | Type | Description |
---|---|---|
_galaxyMember | address | - The address of the Galaxy Member contract. |
function setLevelToMultiplier(uint256 level, uint256 multiplier) public virtual
Set the Galaxy Member level to multiplier mapping.
Name | Type | Description |
---|---|---|
level | uint256 | - The level of the Galaxy Member NFT. |
multiplier | uint256 | - The percentage multiplier for the level of the Galaxy Member NFT. |
function setEmissions(address _emissions) public virtual
Set the Emmissions contract.
Name | Type | Description |
---|---|---|
_emissions | address | - The address of the emissions contract. |
function toggleQuadraticRewarding() external
Toggle quadratic rewarding for a specific cycle.
This function toggles the state of quadratic rewarding for a specific cycle. The state will flip between enabled and disabled each time the function is called.
function version() external pure virtual returns (string)
Returns the version of the contract
This should be updated every time a new version of implementation is deployed
Name | Type | Description |
---|---|---|
[0] | string | string The version of the contract |
function clock() public view virtual returns (uint48)
Clock used for flagging checkpoints.