Vote power strategies
Vote power strategies are used to calculate the voting power of a user. You can add any strategy you want to the Governance Tool. Once you add a new strategy, you can select it for a proposal.
How to add a new vote power strategy
To add a new vote power strategy, you need to extend the votes.get_available_vote_power_calculation_strategies
function.
Here’s an example of how to add a new vote power strategy:
function derive_max_vote_power_from_native_stake_balance(citizen: citizens.citizen, proposals.proposal?): big_integer {
val native_stake_balance = icmf.get_native_stake_balance(citizen.account.id);
return big_integer(native_stake_balance);
}
@extend(votes.get_available_vote_power_calculation_strategies)
function icmf_get_available_vote_power_calculation_strategies(): map<text, votes.my_vote_power_calculation_strategy> {
val strategies = map<text, votes.my_vote_power_calculation_strategy>();
strategies.put(
"TOTAL_CHR_STAKE", // Name of the strategy, which needs to be unique
votes.my_vote_power_calculation_strategy(
name = "TOTAL_CHR_STAKE", // Unique name of the strategy
description = "Derives voting power based on the user's total balance of CHR stake across all EVM and Chromia chains.",
derive_max_voting_power = derive_max_vote_power_from_native_stake_balance(*),
base_vote_power = 10L.pow(6)
)
);
return strategies;
}
The idea is to use extendable functions to return a map of vote power strategies. The results of every extended function will be merged together into one map at execution time. For more information, check how extendable functions work in Rell.
struct my_vote_power_calculation_strategy {
name: text;
description: text;
derive_max_voting_power: (citizens.citizen, proposals.proposal?) -> big_integer;
base_vote_power: big_integer; // This is the voting power added to the total vote power of the option, serving as the base vote power for users who do not utilize any vote power on a vote.
}
For each vote power strategy, you need to define the following properties:
Name
A unique identifier for the strategy, which will be displayed in the UI. This helps users distinguish between different voting strategies. Warning: If you use the same name for different strategies, you will encounter an error whenever you attempt to use or retrieve vote power strategies.
Description
A detailed explanation of how the strategy works and its functionality. This helps users grasp the purpose and behavior of the strategy while viewing it in the UI.
Derive max voting power
The core function that calculates a user's voting power. This function takes a citizen and an optional proposal as input and returns the calculated voting power as a big integer.
Example:
function derive_max_vote_power_from_native_stake_balance(citizen: citizens.citizen, proposals.proposal?): big_integer {
val native_stake_balance = icmf.get_native_stake_balance(citizen.account.id);
return big_integer(native_stake_balance);
}
Base vote power
The baseline voting power value used in calculations. For instance, if you're using a token with 6 decimal places for voting power, you would set this to 10^6. This ensures proper scaling of voting power values.