Browse Source

Add create_set_council_mint_capacity_proposal() extrinsic

Shamil Gadelshin 5 years ago
parent
commit
6667cd3ac4

+ 5 - 5
runtime-modules/proposals/codex/Cargo.toml

@@ -96,6 +96,11 @@ default_features = false
 package = 'substrate-governance-module'
 package = 'substrate-governance-module'
 path = '../../governance'
 path = '../../governance'
 
 
+[dependencies.mint]
+default_features = false
+package = 'substrate-token-mint-module'
+path = '../../token-minting'
+
 [dependencies.proposal_engine]
 [dependencies.proposal_engine]
 default_features = false
 default_features = false
 package = 'substrate-proposals-engine-module'
 package = 'substrate-proposals-engine-module'
@@ -116,8 +121,3 @@ default_features = false
 git = 'https://github.com/paritytech/substrate.git'
 git = 'https://github.com/paritytech/substrate.git'
 package = 'sr-io'
 package = 'sr-io'
 rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
 rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dev-dependencies.mint]
-default_features = false
-package = 'substrate-token-mint-module'
-path = '../../token-minting'

+ 51 - 0
runtime-modules/proposals/codex/src/lib.rs

@@ -66,6 +66,10 @@ pub type BalanceOfGovernanceCurrency<T> =
         <T as system::Trait>::AccountId,
         <T as system::Trait>::AccountId,
     >>::Balance;
     >>::Balance;
 
 
+/// Balance alias for token mint balance from token mint module. TODO: replace with BalanceOf
+pub type BalanceOfMint<T> =
+    <<T as mint::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
+
 /// Balance alias for staking
 /// Balance alias for staking
 pub type NegativeImbalance<T> =
 pub type NegativeImbalance<T> =
     <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
     <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
@@ -282,6 +286,53 @@ decl_module! {
              <ThreadIdByProposalId<T>>::insert(proposal_id, discussion_thread_id);
              <ThreadIdByProposalId<T>>::insert(proposal_id, discussion_thread_id);
         }
         }
 
 
+
+        /// Create 'Set council mint capacity' proposal type. This proposal uses set_mint_capacity()
+        /// extrinsic from the governance::council module.
+        pub fn create_set_council_mint_capacity_proposal(
+            origin,
+            member_id: MemberId<T>,
+            title: Vec<u8>,
+            description: Vec<u8>,
+            stake_balance: Option<BalanceOf<T>>,
+            mint_balance: BalanceOfMint<T>,
+        ) {
+            let account_id = T::MembershipOriginValidator::ensure_actor_origin(origin, member_id.clone())?;
+
+            let parameters = proposal_types::parameters::set_council_mint_capacity_proposal::<T>();
+
+            <proposal_engine::Module<T>>::ensure_create_proposal_parameters_are_valid(
+                &parameters,
+                &title,
+                &description,
+                stake_balance,
+            )?;
+
+            <proposal_discussion::Module<T>>::ensure_can_create_thread(
+                &title,
+                member_id.clone(),
+            )?;
+
+            let proposal_code = <governance::council::Call<T>>::set_council_mint_capacity(mint_balance);
+
+            let discussion_thread_id = <proposal_discussion::Module<T>>::create_thread(
+                member_id,
+                title.clone(),
+            )?;
+
+            let proposal_id = <proposal_engine::Module<T>>::create_proposal(
+                account_id,
+                member_id,
+                parameters,
+                title,
+                description,
+                stake_balance,
+                proposal_code.encode(),
+            )?;
+
+             <ThreadIdByProposalId<T>>::insert(proposal_id, discussion_thread_id);
+        }
+
 // *************** Extrinsic to execute
 // *************** Extrinsic to execute
 
 
         /// Text proposal extrinsic. Should be used as callable object to pass to the engine module.
         /// Text proposal extrinsic. Should be used as callable object to pass to the engine module.

+ 16 - 2
runtime-modules/proposals/codex/src/proposal_types/mod.rs

@@ -24,7 +24,7 @@ pub(crate) mod parameters {
             approval_quorum_percentage: 40,
             approval_quorum_percentage: 40,
             approval_threshold_percentage: 51,
             approval_threshold_percentage: 51,
             slashing_quorum_percentage: 80,
             slashing_quorum_percentage: 80,
-            slashing_threshold_percentage: 80,
+            slashing_threshold_percentage: 82,
             required_stake: Some(<BalanceOf<T>>::from(500u32)),
             required_stake: Some(<BalanceOf<T>>::from(500u32)),
         }
         }
     }
     }
@@ -37,7 +37,21 @@ pub(crate) mod parameters {
             grace_period: T::BlockNumber::from(10000u32),
             grace_period: T::BlockNumber::from(10000u32),
             approval_quorum_percentage: 40,
             approval_quorum_percentage: 40,
             approval_threshold_percentage: 51,
             approval_threshold_percentage: 51,
-            slashing_quorum_percentage: 80,
+            slashing_quorum_percentage: 81,
+            slashing_threshold_percentage: 80,
+            required_stake: Some(<BalanceOf<T>>::from(500u32)),
+        }
+    }
+
+    // Proposal parameters for the 'Set council mint capacity' proposal
+    pub(crate) fn set_council_mint_capacity_proposal<T: crate::Trait>(
+    ) -> ProposalParameters<T::BlockNumber, BalanceOf<T>> {
+        ProposalParameters {
+            voting_period: T::BlockNumber::from(50000u32),
+            grace_period: T::BlockNumber::from(10000u32),
+            approval_quorum_percentage: 40,
+            approval_threshold_percentage: 51,
+            slashing_quorum_percentage: 81,
             slashing_threshold_percentage: 80,
             slashing_threshold_percentage: 80,
             required_stake: Some(<BalanceOf<T>>::from(500u32)),
             required_stake: Some(<BalanceOf<T>>::from(500u32)),
         }
         }