From c336b88ea19ad222050a297e6ceec894a9543e80 Mon Sep 17 00:00:00 2001 From: devwckd Date: Wed, 8 Jan 2025 02:46:27 -0300 Subject: [PATCH] feat: add governance config fields to global params proposal --- pallets/governance/src/benchmarks.rs | 1 + pallets/governance/src/lib.rs | 12 ++++-- pallets/governance/src/proposal.rs | 63 ++++++++++++++++++++++++++-- runtime/src/configs.rs | 4 +- test-utils/src/lib.rs | 4 +- 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/pallets/governance/src/benchmarks.rs b/pallets/governance/src/benchmarks.rs index 8b4a000..45dad33 100644 --- a/pallets/governance/src/benchmarks.rs +++ b/pallets/governance/src/benchmarks.rs @@ -129,6 +129,7 @@ benchmarks! { min_staking_fee: 1, dividends_participation_weight: Percent::zero(), proposal_cost: 0, + ..Default::default() }; let data = vec![0]; diff --git a/pallets/governance/src/lib.rs b/pallets/governance/src/lib.rs index 53ef2d3..382e757 100644 --- a/pallets/governance/src/lib.rs +++ b/pallets/governance/src/lib.rs @@ -99,10 +99,6 @@ pub mod pallet { #[pallet::constant] type MaxApplicationDataLength: Get; - #[pallet::constant] - #[pallet::no_default_bounds] - type ApplicationExpiration: Get>; - #[pallet::constant] type MaxPenaltyPercentage: Get; @@ -136,6 +132,10 @@ pub mod pallet { #[pallet::no_default_bounds] type DefaultProposalRewardInterval: Get>; + #[pallet::constant] + #[pallet::no_default_bounds] + type EmissionProposalMinimumTime: Get>; + #[pallet::no_default_bounds] type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -492,6 +492,10 @@ pub mod pallet { InvalidMinStakingFee, /// Invalid params given to Emission proposal InvalidEmissionProposalData, + /// Invalid proposal reward interval given to global params proposal + InvalidProposalRewardInterval, + /// Invalid agent application cost given to global params proposal + InvalidAgentApplicationCost, } } diff --git a/pallets/governance/src/proposal.rs b/pallets/governance/src/proposal.rs index 49ef2ae..9cda551 100644 --- a/pallets/governance/src/proposal.rs +++ b/pallets/governance/src/proposal.rs @@ -1,13 +1,14 @@ +use crate::config::GovernanceConfiguration; use crate::frame::traits::ExistenceRequirement; use crate::BoundedBTreeSet; use crate::BoundedVec; use crate::DebugNoBound; +use crate::NotDelegatingVotingPower; use crate::TypeInfo; use crate::{ AccountIdOf, BalanceOf, DaoTreasuryAddress, Error, GlobalGovernanceConfig, Proposals, UnrewardedProposals, }; -use crate::{GovernanceConfiguration, NotDelegatingVotingPower}; use codec::{Decode, Encode, MaxEncodedLen}; use polkadot_sdk::frame_election_provider_support::Get; use polkadot_sdk::frame_support::traits::Currency; @@ -98,6 +99,12 @@ impl Proposal { min_staking_fee, dividends_participation_weight, proposal_cost, + proposal_expiration, + agent_application_cost, + agent_application_expiration, + proposal_reward_treasury_allocation, + max_proposal_reward_treasury_allocation, + proposal_reward_interval, } = data; pallet_torus0::MinNameLength::::set(min_name_length); @@ -113,8 +120,15 @@ impl Proposal { }); pallet_emission0::MaxAllowedWeights::::set(max_allowed_weights); pallet_emission0::MinStakePerWeight::::set(min_stake_per_weight); - crate::GlobalGovernanceConfig::::mutate(|config| { - config.proposal_cost = proposal_cost; + + crate::GlobalGovernanceConfig::::set(GovernanceConfiguration:: { + proposal_cost, + proposal_expiration, + agent_application_cost, + agent_application_expiration, + proposal_reward_treasury_allocation, + max_proposal_reward_treasury_allocation, + proposal_reward_interval, }); } ProposalData::TransferDaoTreasury { account, amount } => { @@ -205,6 +219,12 @@ pub struct GlobalParamsData { pub min_staking_fee: u8, pub dividends_participation_weight: Percent, pub proposal_cost: BalanceOf, + pub proposal_expiration: BlockNumberFor, + pub agent_application_cost: BalanceOf, + pub agent_application_expiration: BlockNumberFor, + pub proposal_reward_treasury_allocation: Percent, + pub max_proposal_reward_treasury_allocation: BalanceOf, + pub proposal_reward_interval: BlockNumberFor, } impl Default for GlobalParamsData { @@ -220,6 +240,13 @@ impl Default for GlobalParamsData { dividends_participation_weight: ::DefaultDividendsParticipationWeight::get(), proposal_cost: T::DefaultProposalCost::get(), + proposal_expiration: T::DefaultProposalExpiration::get(), + agent_application_cost: T::DefaultAgentApplicationCost::get(), + agent_application_expiration: T::DefaultAgentApplicationExpiration::get(), + proposal_reward_treasury_allocation: T::DefaultProposalRewardTreasuryAllocation::get(), + max_proposal_reward_treasury_allocation: + T::DefaultMaxProposalRewardTreasuryAllocation::get(), + proposal_reward_interval: T::DefaultProposalRewardInterval::get(), } } } @@ -261,6 +288,28 @@ impl GlobalParamsData { crate::Error::::InvalidProposalCost ); + let proposal_expiration_num: u64 = self + .proposal_expiration + .try_into() + .map_err(|_| crate::Error::::InvalidProposalExpiration)?; + + ensure!( + (5_400..u64::MAX).contains(&proposal_expiration_num), + crate::Error::::InvalidProposalExpiration + ); + + ensure!( + self.agent_application_cost <= 100_000_000_000_000_000_000_000, + crate::Error::::InvalidAgentApplicationCost + ); + + ensure!( + self.proposal_reward_interval + <= BlockNumberFor::::try_from(U256::from(100_000)) + .map_err(|_| crate::Error::::InvalidProposalRewardInterval)?, + crate::Error::::InvalidProposalRewardInterval + ); + Ok(()) } } @@ -385,10 +434,16 @@ fn add_proposal( let current_block = >::block_number(); + let expiration_block = match &data { + ProposalData::Emission { .. } => (current_block + T::EmissionProposalMinimumTime::get()) + .max(current_block + config.proposal_expiration), + _ => current_block + config.proposal_expiration, + }; + let proposal = Proposal:: { id: proposal_id, proposer, - expiration_block: current_block + config.proposal_expiration, + expiration_block, data, status: ProposalStatus::Open { votes_for: BoundedBTreeSet::new(), diff --git a/runtime/src/configs.rs b/runtime/src/configs.rs index 43e8f67..d5758e4 100644 --- a/runtime/src/configs.rs +++ b/runtime/src/configs.rs @@ -372,8 +372,6 @@ impl pallet_governance::Config for Runtime { type MaxApplicationDataLength = ConstU32<256>; - type ApplicationExpiration = ConstU64<2000>; - type MaxPenaltyPercentage = MaxPenaltyPercentage; type DefaultTreasuryEmissionFee = DefaultTreasuryEmissionFee; @@ -392,6 +390,8 @@ impl pallet_governance::Config for Runtime { type DefaultProposalRewardInterval = ConstU64<75_600>; + type EmissionProposalMinimumTime = ConstU64<21_600>; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index 8d28708..2f52fd0 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -184,8 +184,6 @@ impl pallet_governance::Config for Test { type MaxApplicationDataLength = ConstU32<256>; - type ApplicationExpiration = ConstU64<2000>; - type MaxPenaltyPercentage = MaxPenaltyPercentage; type DefaultTreasuryEmissionFee = DefaultTreasuryEmissionFee; @@ -204,6 +202,8 @@ impl pallet_governance::Config for Test { type DefaultProposalRewardInterval = ConstU64<75_600>; + type EmissionProposalMinimumTime = ConstU64<21_600>; + type RuntimeEvent = RuntimeEvent; type Currency = Balances;