Solidity API

VoterRewards

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._

VOTE_REGISTRAR_ROLE

bytes32 VOTE_REGISTRAR_ROLE

The role that can register votes for rewards calculation.

UPGRADER_ROLE

bytes32 UPGRADER_ROLE

The role that can upgrade the contract.

CONTRACTS_ADDRESS_MANAGER_ROLE

bytes32 CONTRACTS_ADDRESS_MANAGER_ROLE

The role that can set the addresses of the contracts used by the VoterRewards contract.

SCALING_FACTOR

uint256 SCALING_FACTOR

The scaling factor for the rewards calculation.

VoterRewardsStorage

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;
}

_getVoterRewardsStorage

function _getVoterRewardsStorage() internal pure returns (struct VoterRewards.VoterRewardsStorage $)

Get the VoterRewardsStorage struct from the specified storage slot specified by the VoterRewardsStorageLocation.

VoteRegistered

event VoteRegistered(uint256 cycle, address voter, uint256 votes, uint256 rewardWeightedVote)

Emitted when a user registers their votes for rewards calculation.

Parameters

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.

RewardClaimed

event RewardClaimed(uint256 cycle, address voter, uint256 reward)

Emitted when a user claims their rewards.

Parameters

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.

GalaxyMemberAddressUpdated

event GalaxyMemberAddressUpdated(address newAddress, address oldAddress)

Emitted when the Galaxy Member contract address is set.

Parameters

Name Type Description
newAddress address - The address of the new Galaxy Member contract.
oldAddress address - The address of the old Galaxy Member contract.

EmissionsAddressUpdated

event EmissionsAddressUpdated(address newAddress, address oldAddress)

Emitted when the Emissions contract address is set.

Parameters

Name Type Description
newAddress address - The address of the new Emissions contract.
oldAddress address - The address of the old Emissions contract.

LevelToMultiplierSet

event LevelToMultiplierSet(uint256 level, uint256 multiplier)

Emitted when the level to multiplier mapping is set.

Parameters

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.

QuadraticRewardingToggled

event QuadraticRewardingToggled(bool disabled)

Emits true if quadratic rewarding is disabled, false otherwise.

Parameters

Name Type Description
disabled bool - The flag to enable or disable quadratic rewarding.

constructor

constructor() public

initialize

function initialize(address admin, address upgrader, address contractsAddressManager, address _emissions, address _galaxyMember, address _b3tr, uint256[] levels, uint256[] multipliers) external

Initialize the VoterRewards contract.

Parameters

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.

_authorizeUpgrade

function _authorizeUpgrade(address newImplementation) internal

Upgrade the implementation of the VoterRewards contract.

Only the address with the UPGRADER_ROLE can call this function.

Parameters

Name Type Description
newImplementation address - The address of the new implementation contract.

registerVote

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.

Parameters

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.

claimReward

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.

Parameters

Name Type Description
cycle uint256 - The cycle in which the rewards are claimed.
voter address - The address of the voter.

getMultiplier

function getMultiplier(uint256 tokenId, uint256 proposalId) public view virtual returns (uint256)

Get the reward multiplier for a user in a specific proposal.

Parameters

Name Type Description
tokenId uint256 Id of the Galaxy Member NFT
proposalId uint256 Id of the proposal

hasNodeVoted

function hasNodeVoted(uint256 nodeId, uint256 proposalId) public view virtual returns (bool)

Check if a Vechain Node has voted in a proposal

Parameters

Name Type Description
nodeId uint256 Id of the Vechain node
proposalId uint256 Id of the proposal

hasTokenVoted

function hasTokenVoted(uint256 tokenId, uint256 proposalId) public view virtual returns (bool)

Check if a Galaxy Member has voted in a proposal

Parameters

Name Type Description
tokenId uint256 Id of the Galaxy Member NFT
proposalId uint256 Id of the proposal

getReward

function getReward(uint256 cycle, address voter) public view virtual returns (uint256)

Get the reward for a user in a specific cycle.

Parameters

Name Type Description
cycle uint256 - The cycle in which the rewards are claimed.
voter address - The address of the voter.

cycleToVoterToTotal

function cycleToVoterToTotal(uint256 cycle, address voter) external view returns (uint256)

Get the total reward-weighted votes for a user in a specific cycle.

Parameters

Name Type Description
cycle uint256 - The cycle in which the rewards are claimed.
voter address - The address of the voter.

cycleToTotal

function cycleToTotal(uint256 cycle) external view returns (uint256)

Get the total reward-weighted votes in a specific cycle.

Parameters

Name Type Description
cycle uint256 - The cycle in which the rewards are claimed.

levelToMultiplier

function levelToMultiplier(uint256 level) external view returns (uint256)

Get the reward multiplier for a specific level of the Galaxy Member NFT.

Parameters

Name Type Description
level uint256 - The level of the Galaxy Member NFT.

galaxyMember

function galaxyMember() external view returns (contract IGalaxyMember)

Get the Galaxy Member contract.

emissions

function emissions() external view returns (contract IEmissions)

Get the Emissions contract.

b3tr

function b3tr() external view returns (contract IB3TR)

Get the B3TR token contract.

isQuadraticRewardingDisabledAtBlock

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.

Parameters

Name Type Description
blockNumber uint48 - The block number to check the quadratic rewarding status.

Return Values

Name Type Description
[0] bool true if quadratic rewarding is disabled, false otherwise.

isQuadraticRewardingDisabledForCurrentCycle

function isQuadraticRewardingDisabledForCurrentCycle() public view returns (bool)

Check if quadratic rewarding is disabled for the current cycle.

Return Values

Name Type Description
[0] bool true if quadratic rewarding is disabled, false otherwise.

setGalaxyMember

function setGalaxyMember(address _galaxyMember) public virtual

Set the Galaxy Member contract.

Parameters

Name Type Description
_galaxyMember address - The address of the Galaxy Member contract.

setLevelToMultiplier

function setLevelToMultiplier(uint256 level, uint256 multiplier) public virtual

Set the Galaxy Member level to multiplier mapping.

Parameters

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.

setEmissions

function setEmissions(address _emissions) public virtual

Set the Emmissions contract.

Parameters

Name Type Description
_emissions address - The address of the emissions contract.

toggleQuadraticRewarding

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.

version

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

Return Values

Name Type Description
[0] string string The version of the contract

clock

function clock() public view virtual returns (uint48)

Clock used for flagging checkpoints.