Skip to content

Commit

Permalink
Merge pull request #756 from multiversx/governance-v2-merkle-proof
Browse files Browse the repository at this point in the history
Governance v2 merkle proof
  • Loading branch information
dragos-rebegea authored Aug 7, 2023
2 parents d49b05d + 1a9a40a commit 3a1e7a8
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 476 deletions.
14 changes: 0 additions & 14 deletions energy-integration/governance-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ publish = false

[lib]
path = "src/lib.rs"
[dependencies.energy-query]
path = "../common-modules/energy-query"

[dependencies.multiversx-sc]
version = "=0.39.4"
Expand All @@ -19,15 +17,3 @@ num-bigint = "0.4.2"

[dev-dependencies.multiversx-sc-scenario]
version = "=0.39.4"

[dev-dependencies.energy-factory-mock]
path = "../energy-factory-mock"

[dependencies.permissions_module]
path = "../../common/modules/permissions_module"

[dependencies.fees-collector]
path = "../fees-collector"

[dependencies.weekly-rewards-splitting]
path = "../common-modules/weekly-rewards-splitting"
33 changes: 7 additions & 26 deletions energy-integration/governance-v2/src/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ multiversx_sc::imports!();
/// - voting/downvoting a certain proposal
/// - after a voting period, either putting the action in a queue (if it reached quorum), or canceling
///
/// Voting is done through energy.
/// Voting is done through tokens ownership.
///
/// The module provides the following configurable parameters:
/// - `minEnergyForPropose` - the minimum energy required for submitting a proposal
/// - `quorum` - the minimum number of (`votes` minus `downvotes`) at the end of voting period
/// - `maxActionsPerProposal` - Maximum number of actions (transfers and/or smart contract calls) that a proposal may have
/// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal
Expand All @@ -36,33 +35,25 @@ const MIN_VOTING_PERIOD: u64 = 14_400; // 24 Hours
const MAX_VOTING_PERIOD: u64 = 201_600; // 2 Weeks
const MIN_QUORUM: u64 = 1_000; // 10%
const MAX_QUORUM: u64 = 6_000; // 60%
const MIN_MIN_FEE_FOR_PROPOSE: u64 = 2_000_000;
const MIN_MIN_FEE_FOR_PROPOSE: u64 = 1;
const MAX_MIN_FEE_FOR_PROPOSE: u64 = 200_000_000_000;
const DECIMALS_CONST: u64 = 1_000_000_000_000_000_000;

#[multiversx_sc::module]
pub trait ConfigurablePropertiesModule:
energy_query::EnergyQueryModule + permissions_module::PermissionsModule
{
pub trait ConfigurablePropertiesModule {
// endpoints - these can only be called by the SC itself.
// i.e. only by proposing and executing an action with the SC as dest and the respective func name

#[only_owner]
#[endpoint(changeMinEnergyForProposal)]
fn change_min_energy_for_propose(&self, new_value: BigUint) {
self.try_change_min_energy_for_propose(new_value);
}

#[only_owner]
#[endpoint(changeMinFeeForProposal)]
fn change_min_fee_for_propose(&self, new_value: BigUint) {
self.try_change_min_fee_for_propose(new_value);
}

#[only_owner]
#[endpoint(changeQuorum)]
fn change_quorum(&self, new_value: BigUint) {
self.try_change_quorum(new_value);
#[endpoint(changeQuorumPercentage)]
fn change_quorum_percentage(&self, new_value: BigUint) {
self.try_change_quorum_percentage(new_value);
}

#[only_owner]
Expand All @@ -77,12 +68,6 @@ pub trait ConfigurablePropertiesModule:
self.try_change_voting_period_in_blocks(new_value);
}

fn try_change_min_energy_for_propose(&self, new_value: BigUint) {
require!(new_value != 0, "Min energy for proposal can't be set to 0");

self.min_energy_for_propose().set(&new_value);
}

fn try_change_min_fee_for_propose(&self, new_value: BigUint) {
let minimum_min_fee =
BigUint::from(MIN_MIN_FEE_FOR_PROPOSE) * BigUint::from(DECIMALS_CONST);
Expand All @@ -96,7 +81,7 @@ pub trait ConfigurablePropertiesModule:
self.min_fee_for_propose().set(&new_value);
}

fn try_change_quorum(&self, new_value: BigUint) {
fn try_change_quorum_percentage(&self, new_value: BigUint) {
require!(
new_value > MIN_QUORUM && new_value < MAX_QUORUM,
"Not valid value for Quorum!"
Expand Down Expand Up @@ -137,10 +122,6 @@ pub trait ConfigurablePropertiesModule:
self.fee_token_id().set_if_empty(&fee_token_id);
}

#[view(getMinEnergyForPropose)]
#[storage_mapper("minEnergyForPropose")]
fn min_energy_for_propose(&self) -> SingleValueMapper<BigUint>;

#[view(getMinFeeForPropose)]
#[storage_mapper("minFeeForPropose")]
fn min_fee_for_propose(&self) -> SingleValueMapper<BigUint>;
Expand Down
10 changes: 9 additions & 1 deletion energy-integration/governance-v2/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
pub const WRONG_TOKEN_ID: &[u8] = b"Wrong payment token id for fee";
pub const NOT_ENOUGH_FEE: &[u8] = b"Minimum fee required not reached";
pub const NOT_ENOUGH_ENERGY: &[u8] = b"Not enough energy for propose";
pub const TOO_MUCH_GAS: &[u8] = b"Actions require too much gas to be executed";
pub const PROPOSAL_NOT_ACTIVE: &[u8] = b"Proposal is not active";
pub const ERROR_NOT_AN_ESDT: &[u8] = b"Not a valid esdt id";
pub const ALREADY_VOTED_ERR_MSG: &[u8] = b"Already voted for this proposal";
pub const INVALID_ROOT_HASH: &[u8] = b"Invalid root hash provided";
pub const PROPOSAL_NO_ACTION: &[u8] = b"Proposal has no actions";
pub const EXEEDED_MAX_ACTIONS: &[u8] = b"Exceeded max actions per proposal";
pub const ONLY_PROPOSER_CANCEL: &[u8] = b"Only original proposer may cancel a pending proposal";
pub const ONLY_PROPOSER_WITHDRAW: &[u8] = b"Only original proposer may withdraw a pending proposal";
pub const NO_PROPOSAL: &[u8] = b"Proposal does not exist";
pub const WITHDRAW_NOT_ALLOWED: &[u8] = b"You may not withdraw funds from this proposal!";
pub const INVALID_MERKLE_PROOF: &[u8] = b"Invalid merkle proof provided";
Loading

0 comments on commit 3a1e7a8

Please sign in to comment.