Skip to content

Commit

Permalink
Merge branch 'governance-campaign-total-quorum-check'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/release.yml
#	Cargo.lock
#	dex/farm-with-locked-rewards/meta/Cargo.toml
#	dex/farm/meta/Cargo.toml
#	dex/governance/meta/Cargo.toml
#	dex/pair-mock/meta/Cargo.toml
#	dex/pair-mock/wasm/src/lib.rs
#	dex/pair/meta/Cargo.toml
#	dex/price-discovery/meta/Cargo.toml
#	dex/proxy-deployer/meta/Cargo.toml
#	dex/router/meta/Cargo.toml
#	energy-integration/energy-factory-mock/meta/Cargo.toml
#	energy-integration/energy-update/meta/Cargo.toml
#	energy-integration/fees-collector/meta/Cargo.toml
#	energy-integration/governance-v2/Cargo.toml
#	energy-integration/governance-v2/meta/Cargo.toml
#	energy-integration/governance-v2/src/configurable.rs
#	energy-integration/governance-v2/src/errors.rs
#	energy-integration/governance-v2/src/lib.rs
#	energy-integration/governance-v2/src/views.rs
#	energy-integration/governance-v2/tests/gov_rust_test.rs
#	energy-integration/governance-v2/tests/gov_test_setup/mod.rs
#	energy-integration/governance-v2/wasm/Cargo.lock
#	energy-integration/governance-v2/wasm/src/lib.rs
#	farm-staking/farm-staking-proxy/meta/Cargo.toml
#	farm-staking/farm-staking/meta/Cargo.toml
#	farm-staking/metabonding-staking/meta/Cargo.toml
#	locked-asset/distribution/meta/Cargo.toml
#	locked-asset/energy-factory/meta/Cargo.toml
#	locked-asset/factory/meta/Cargo.toml
#	locked-asset/lkmex-transfer/meta/Cargo.toml
#	locked-asset/locked-token-wrapper/meta/Cargo.toml
#	locked-asset/proxy_dex/meta/Cargo.toml
#	locked-asset/simple-lock-whitelist/meta/Cargo.toml
#	locked-asset/simple-lock/meta/Cargo.toml
#	locked-asset/token-unstake/meta/Cargo.toml
#	pause-all/meta/Cargo.toml
  • Loading branch information
dragos-rebegea committed Apr 17, 2024
2 parents c2a2d27 + 5c3900f commit 20ce465
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 208 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/on_pull_request_build_contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: On pull request, build contracts

on:
pull_request:

permissions:
contents: write

jobs:
build:
uses: multiversx/mx-sc-actions/.github/workflows/[email protected]
with:
image_tag: v4.2.1
package_whole_project_src: true
12 changes: 5 additions & 7 deletions dex/pair-mock/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated by the multiversx-sc build system. DO NOT EDIT.
// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
Expand All @@ -10,19 +10,17 @@
// Total number of exported functions: 4

#![no_std]
#![allow(internal_features)]
#![feature(lang_items)]
#![feature(alloc_error_handler, lang_items)]

multiversx_sc_wasm_adapter::allocator!();
multiversx_sc_wasm_adapter::panic_handler!();

multiversx_sc_wasm_adapter::endpoints! {
pair_mock
(
init => init
addInitialLiquidity => add_initial_liquidity
getTokensForGivenPositionWithSafePrice => get_tokens_for_given_position_with_safe_price
addInitialLiquidity
getTokensForGivenPositionWithSafePrice
)
}

multiversx_sc_wasm_adapter::async_callback_empty! {}
multiversx_sc_wasm_adapter::empty_callback! {}
64 changes: 18 additions & 46 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
/// The module provides the following configurable parameters:
/// - `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,25 +35,17 @@ 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;
pub const MAX_GAS_LIMIT_PER_BLOCK: u64 = 600_000_000;
pub const FULL_PERCENTAGE: u64 = 10_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) {
Expand All @@ -63,16 +54,10 @@ pub trait ConfigurablePropertiesModule:

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

#[only_owner]
#[endpoint(changeWithdrawPercentage)]
fn change_withdraw_percentage(&self, new_value: u64) {
self.try_change_withdraw_percentage_defeated(new_value);
}

#[only_owner]
#[endpoint(changeVotingDelayInBlocks)]
fn change_voting_delay_in_blocks(&self, new_value: u64) {
Expand All @@ -85,10 +70,6 @@ pub trait ConfigurablePropertiesModule:
self.try_change_voting_period_in_blocks(new_value);
}

fn try_change_min_energy_for_propose(&self, new_value: BigUint) {
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 @@ -102,63 +83,54 @@ pub trait ConfigurablePropertiesModule:
self.min_fee_for_propose().set(&new_value);
}

fn try_change_quorum_percentage(&self, new_quorum_percentage: u64) {
fn try_change_quorum_percentage(&self, new_value: BigUint) {
require!(
(MIN_QUORUM..MAX_QUORUM).contains(&new_quorum_percentage),
new_value > MIN_QUORUM && new_value < MAX_QUORUM,
"Not valid value for Quorum!"
);

self.quorum_percentage().set(new_quorum_percentage);
self.quorum_percentage().set(&new_value);
}

fn try_change_voting_delay_in_blocks(&self, new_voting_delay: u64) {
fn try_change_voting_delay_in_blocks(&self, new_value: u64) {
require!(
(MIN_VOTING_DELAY..MAX_VOTING_DELAY).contains(&new_voting_delay),
new_value > MIN_VOTING_DELAY && new_value < MAX_VOTING_DELAY,
"Not valid value for voting delay!"
);

self.voting_delay_in_blocks().set(new_voting_delay);
self.voting_delay_in_blocks().set(new_value);
}

fn try_change_voting_period_in_blocks(&self, new_voting_period: u64) {
fn try_change_voting_period_in_blocks(&self, new_value: u64) {
require!(
(MIN_VOTING_PERIOD..MAX_VOTING_PERIOD).contains(&new_voting_period),
new_value > MIN_VOTING_PERIOD && new_value < MAX_VOTING_PERIOD,
"Not valid value for voting period!"
);

self.voting_period_in_blocks().set(new_voting_period);
self.voting_period_in_blocks().set(new_value);
}

fn try_change_withdraw_percentage_defeated(&self, new_withdraw_percentage: u64) {
fn try_change_withdraw_percentage_defeated(&self, new_value: u64) {
require!(
new_withdraw_percentage <= FULL_PERCENTAGE,
new_value > 0 && new_value < FULL_PERCENTAGE,
"Not valid value for withdraw percentage if defeated!"
);

self.withdraw_percentage_defeated()
.set(new_withdraw_percentage);
self.withdraw_percentage_defeated().set(new_value);
}

fn try_change_fee_token_id(&self, fee_token_id: TokenIdentifier) {
require!(fee_token_id.is_valid_esdt_identifier(), ERROR_NOT_AN_ESDT);
self.fee_token_id().set_if_empty(&fee_token_id);
}

fn smoothing_function(&self, input: &BigUint) -> BigUint {
input.sqrt()
}

#[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>;

#[view(getQuorum)]
#[storage_mapper("quorumPercentage")]
fn quorum_percentage(&self) -> SingleValueMapper<u64>;
fn quorum_percentage(&self) -> SingleValueMapper<BigUint>;

#[view(getVotingDelayInBlocks)]
#[storage_mapper("votingDelayInBlocks")]
Expand Down
6 changes: 3 additions & 3 deletions energy-integration/governance-v2/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,14 +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 FEE_ALREADY_WITHDRAWN: &[u8] = b"Fee already withdrawn!";
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 PROPOSAL_NOT_ALLOWED_FOR_SC: &[u8] = b"Smart Contracts are not allowed to propose!";
pub const INVALID_MERKLE_PROOF: &[u8] = b"Invalid merkle proof provided";
Loading

0 comments on commit 20ce465

Please sign in to comment.