-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "pallet-governance0" | ||
description = "The chain's governance pallet." | ||
version = "0.1.0" | ||
license = "MIT-0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["codec/std", "polkadot-sdk/std", "scale-info/std"] | ||
|
||
[dependencies] | ||
codec = { workspace = true, features = ["derive"] } | ||
pallet-torus0 = { workspace = true } | ||
polkadot-sdk = { workspace = true, features = ["experimental", "runtime"] } | ||
scale-info = { workspace = true, features = ["derive"] } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use pallet_torus0::Config; | ||
use polkadot_sdk::frame_support::dispatch::DispatchResult; | ||
use polkadot_sdk::frame_support::DebugNoBound; | ||
use polkadot_sdk::polkadot_sdk_frame::prelude::OriginFor; | ||
use polkadot_sdk::sp_core::ConstU32; | ||
use polkadot_sdk::sp_runtime::BoundedVec; | ||
use polkadot_sdk::sp_std::vec::Vec; | ||
use scale_info::TypeInfo; | ||
|
||
#[derive(DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub struct AgentApplication<T: Config> { | ||
pub id: u32, | ||
pub payer_key: T::AccountId, | ||
pub agent_key: T::AccountId, | ||
pub data: BoundedVec<u8, ConstU32<256>>, | ||
pub cost: u64, | ||
pub expires_at: u64, | ||
} | ||
|
||
pub fn submit_application<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_agent_key: T::AccountId, | ||
_data: Vec<u8>, | ||
) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn accept_application<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_application_id: u32, | ||
) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn deny_application<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_application_id: u32, | ||
) -> DispatchResult { | ||
todo!() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use polkadot_sdk::{ | ||
frame_support::dispatch::DispatchResult, polkadot_sdk_frame::prelude::OriginFor, | ||
}; | ||
|
||
pub fn add_curator<T: crate::Config>(_origin: OriginFor<T>, _key: T::AccountId) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn remove_curator<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_key: T::AccountId, | ||
) -> DispatchResult { | ||
todo!() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
mod application; | ||
mod curator; | ||
mod proposal; | ||
mod voting; | ||
mod whitelist; | ||
|
||
use frame::testing_prelude::{DispatchResult, OriginFor}; | ||
pub use pallet::*; | ||
use polkadot_sdk::polkadot_sdk_frame as frame; | ||
use polkadot_sdk::sp_std::vec::Vec; | ||
|
||
#[frame::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: polkadot_sdk::frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(0)] | ||
Check failure on line 27 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 27 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn add_curator_extrinsic(origin: OriginFor<T>, key: T::AccountId) -> DispatchResult { | ||
curator::add_curator::<T>(origin, key) | ||
} | ||
|
||
#[pallet::call_index(1)] | ||
#[pallet::weight(0)] | ||
Check failure on line 33 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 33 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_1::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn remove_curator_extrinsic(origin: OriginFor<T>, key: T::AccountId) -> DispatchResult { | ||
curator::remove_curator::<T>(origin, key) | ||
} | ||
|
||
#[pallet::call_index(2)] | ||
#[pallet::weight(0)] | ||
Check failure on line 39 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 39 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_2::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn add_to_whitelist_extrinsic( | ||
origin: OriginFor<T>, | ||
key: T::AccountId, | ||
) -> DispatchResult { | ||
whitelist::add_to_whitelist::<T>(origin, key) | ||
} | ||
|
||
#[pallet::call_index(3)] | ||
#[pallet::weight(0)] | ||
Check failure on line 48 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 48 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_3::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn remove_from_whitelist_extrinsic( | ||
origin: OriginFor<T>, | ||
key: T::AccountId, | ||
) -> DispatchResult { | ||
whitelist::remove_from_whitelist::<T>(origin, key) | ||
} | ||
|
||
#[pallet::call_index(4)] | ||
#[pallet::weight(0)] | ||
Check failure on line 57 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 57 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_4::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn submit_application_extrinsic( | ||
origin: OriginFor<T>, | ||
agent_key: T::AccountId, | ||
data: Vec<u8>, | ||
) -> DispatchResult { | ||
application::submit_application::<T>(origin, agent_key, data) | ||
} | ||
|
||
#[pallet::call_index(5)] | ||
#[pallet::weight(0)] | ||
Check failure on line 67 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 67 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_5::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn accept_application_extrinsic( | ||
origin: OriginFor<T>, | ||
application_id: u32, | ||
) -> DispatchResult { | ||
application::accept_application::<T>(origin, application_id) | ||
} | ||
|
||
#[pallet::call_index(6)] | ||
#[pallet::weight(0)] | ||
Check failure on line 76 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 76 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_6::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn deny_application_extrinsic( | ||
origin: OriginFor<T>, | ||
application_id: u32, | ||
) -> DispatchResult { | ||
application::deny_application::<T>(origin, application_id) | ||
} | ||
|
||
#[pallet::call_index(7)] | ||
#[pallet::weight(0)] | ||
Check failure on line 85 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 85 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_7::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn add_global_custom_proposal_extrinsic( | ||
origin: OriginFor<T>, | ||
data: Vec<u8>, | ||
) -> DispatchResult { | ||
proposal::add_global_custom_proposal::<T>(origin, data) | ||
} | ||
|
||
#[pallet::call_index(8)] | ||
#[pallet::weight(0)] | ||
Check failure on line 94 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 94 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_8::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn add_dao_treasury_transfer_proposal_extrinsic( | ||
origin: OriginFor<T>, | ||
value: u64, | ||
destination_key: T::AccountId, | ||
data: Vec<u8>, | ||
) -> DispatchResult { | ||
proposal::add_dao_treasury_transfer_proposal::<T>(origin, value, destination_key, data) | ||
} | ||
|
||
#[pallet::call_index(9)] | ||
#[pallet::weight(0)] | ||
Check failure on line 105 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 105 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_9::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn vote_proposal_extrinsic( | ||
origin: OriginFor<T>, | ||
proposal_id: u64, | ||
agree: bool, | ||
) -> DispatchResult { | ||
voting::add_vote::<T>(origin, proposal_id, agree) | ||
} | ||
|
||
#[pallet::call_index(10)] | ||
#[pallet::weight(0)] | ||
Check failure on line 115 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 115 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_10::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn remove_vote_proposal_extrinsic( | ||
origin: OriginFor<T>, | ||
proposal_id: u64, | ||
) -> DispatchResult { | ||
voting::remove_vote::<T>(origin, proposal_id) | ||
} | ||
|
||
#[pallet::call_index(11)] | ||
#[pallet::weight(0)] | ||
Check failure on line 124 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 124 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_11::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn enable_vote_delegation_extrinsic(origin: OriginFor<T>) -> DispatchResult { | ||
voting::enable_delegation::<T>(origin) | ||
} | ||
|
||
#[pallet::call_index(12)] | ||
#[pallet::weight(0)] | ||
Check failure on line 130 in pallets/governance0/src/lib.rs GitHub Actions / clippythis let-binding has unit value
Check failure on line 130 in pallets/governance0/src/lib.rs GitHub Actions / clippyuse of deprecated constant `pallet::warnings::ConstantWeight_12::_w`: It is deprecated to use hard-coded constant as call weight. Please instead benchmark all calls or put the pallet into `dev` mode. For more info see: <https://github.com/paritytech/substrate/pull/13798>
|
||
pub fn disable_vote_delegation_extrinsic(origin: OriginFor<T>) -> DispatchResult { | ||
voting::disable_delegation::<T>(origin) | ||
} | ||
} | ||
|
||
#[pallet::error] | ||
pub enum Error<T> { | ||
/// The proposal is already finished. Do not retry. | ||
ProposalIsFinished, | ||
/// Invalid parameters were provided to the finalization process. | ||
InvalidProposalFinalizationParameters, | ||
/// Invalid parameters were provided to the voting process. | ||
InvalidProposalVotingParameters, | ||
/// Negative proposal cost when setting global or subnet governance configuration. | ||
InvalidProposalCost, | ||
/// Negative expiration when setting global or subnet governance configuration. | ||
InvalidProposalExpiration, | ||
/// Key doesn't have enough tokens to create a proposal. | ||
NotEnoughBalanceToPropose, | ||
/// Proposal data is empty. | ||
ProposalDataTooSmall, | ||
/// Proposal data is bigger than 256 characters. | ||
ProposalDataTooLarge, | ||
/// The staked module is already delegating for 2 ^ 32 keys. | ||
ModuleDelegatingForMaxStakers, | ||
/// Proposal with given id doesn't exist. | ||
ProposalNotFound, | ||
/// Proposal was either accepted, refused or expired and cannot accept votes. | ||
ProposalClosed, | ||
/// Proposal data isn't composed by valid UTF-8 characters. | ||
InvalidProposalData, | ||
/// Invalid value given when transforming a u64 into T::Currency. | ||
InvalidCurrencyConversionValue, | ||
/// Dao Treasury doesn't have enough funds to be transferred. | ||
InsufficientDaoTreasuryFunds, | ||
/// Key has already voted on given Proposal. | ||
AlreadyVoted, | ||
/// Key hasn't voted on given Proposal. | ||
NotVoted, | ||
/// Key doesn't have enough stake to vote. | ||
InsufficientStake, | ||
/// The voter is delegating its voting power to their staked modules. Disable voting power | ||
/// delegation. | ||
VoterIsDelegatingVotingPower, | ||
/// The network vote mode must be authority for changes to be imposed. | ||
VoteModeIsNotAuthority, | ||
/// An internal error occurred, probably relating to the size of the bounded sets. | ||
InternalError, | ||
/// The application data is too small or empty. | ||
ApplicationTooSmall, | ||
/// The application data is too large, exceeding the maximum allowed size. | ||
InvalidApplicationSize, | ||
/// The application is not in a pending state. | ||
ApplicationNotPending, | ||
/// The application key is already used in another application. | ||
ApplicationKeyAlreadyUsed, | ||
/// The application data is invalid or malformed. | ||
InvalidApplication, | ||
/// The account doesn't have enough balance to submit an application. | ||
NotEnoughBalanceToApply, | ||
/// The operation can only be performed by the curator. | ||
NotCurator, | ||
/// The application with the given ID was not found. | ||
ApplicationNotFound, | ||
/// The account is already whitelisted and cannot be added again. | ||
AlreadyWhitelisted, | ||
/// The account is not whitelisted and cannot be removed from the whitelist. | ||
NotWhitelisted, | ||
/// Failed to convert the given value to a balance. | ||
CouldNotConvertToBalance, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use polkadot_sdk::{ | ||
frame_support::{dispatch::DispatchResult, DebugNoBound}, | ||
polkadot_sdk_frame::prelude::OriginFor, | ||
sp_core::ConstU32, | ||
sp_runtime::{BoundedBTreeSet, BoundedVec}, | ||
sp_std::vec::Vec, | ||
}; | ||
use scale_info::TypeInfo; | ||
|
||
pub type ProposalId = u64; | ||
|
||
#[derive(DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub struct Proposal<T: crate::Config> { | ||
pub id: ProposalId, | ||
pub proposer: T::AccountId, | ||
pub expiration_block: u64, | ||
pub data: ProposalData<T>, | ||
pub status: ProposalStatus<T>, | ||
pub metadata: BoundedVec<u8, ConstU32<256>>, | ||
pub proposal_cost: u64, | ||
pub creation_block: u64, | ||
} | ||
|
||
#[derive(Clone, DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen, PartialEq, Eq)] | ||
#[scale_info(skip_type_params(T))] | ||
pub enum ProposalStatus<T: crate::Config> { | ||
Open { | ||
votes_for: BoundedBTreeSet<T::AccountId, ConstU32<{ u32::MAX }>>, | ||
votes_against: BoundedBTreeSet<T::AccountId, ConstU32<{ u32::MAX }>>, | ||
stake_for: u64, | ||
stake_against: u64, | ||
}, | ||
Accepted { | ||
block: u64, | ||
stake_for: u64, | ||
stake_against: u64, | ||
}, | ||
Refused { | ||
block: u64, | ||
stake_for: u64, | ||
stake_against: u64, | ||
}, | ||
Expired, | ||
} | ||
|
||
#[derive(DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen, PartialEq, Eq)] | ||
#[scale_info(skip_type_params(T))] | ||
pub enum ProposalData<T: crate::Config> { | ||
GlobalCustom, | ||
TransferDaoTreasury { account: T::AccountId, amount: u64 }, | ||
} | ||
|
||
pub fn add_global_custom_proposal<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_data: Vec<u8>, | ||
) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn add_dao_treasury_transfer_proposal<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_value: u64, | ||
_destination_key: T::AccountId, | ||
_data: Vec<u8>, | ||
) -> DispatchResult { | ||
todo!() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use polkadot_sdk::{ | ||
frame_support::dispatch::DispatchResult, polkadot_sdk_frame::prelude::OriginFor, | ||
}; | ||
|
||
pub fn add_vote<T: crate::Config>( | ||
_origin: OriginFor<T>, | ||
_proposal_id: u64, | ||
_agree: bool, | ||
) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn remove_vote<T: crate::Config>(_origin: OriginFor<T>, _proposal_id: u64) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn enable_delegation<T: crate::Config>(_origin: OriginFor<T>) -> DispatchResult { | ||
todo!() | ||
} | ||
|
||
pub fn disable_delegation<T: crate::Config>(_origin: OriginFor<T>) -> DispatchResult { | ||
todo!() | ||
} |