Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Community] Implement Governance #303

Closed
3 of 10 tasks
Tracked by #125
pandres95 opened this issue Sep 29, 2023 · 0 comments · Fixed by #313
Closed
3 of 10 tasks
Tracked by #125

[Community] Implement Governance #303

pandres95 opened this issue Sep 29, 2023 · 0 comments · Fixed by #313
Assignees

Comments

@pandres95
Copy link
Member

pandres95 commented Sep 29, 2023

Description

This issue aims to enable communities to handle their own settings and treasury based on two governance systems: authoritative decisions (a.k.a. Voice), or voting mechanisms via polls (Members or Fraction).

Types

Origins

/// The origin of the comnunity governance, as well as the origin
/// sent to emit on behalf of the pallet
#[derive(TypeInfo, Encode, Decode, MaxEncodedLen, Clone, Eq, PartialEq, Debug)]
#[scale_info(skip_type_params(T))]
pub struct RawOrigin<T: Config> {
	/// The community id. Used to get the account of the
	/// community for certain origin conversions
	pub community_id: T::CommunityId,
	/// The governance strategy. This defines how to behave
	/// when ensuring privileged calls and deciding executing
	/// calls
	pub governance_strategy: CommunityGovernanceStrategy<AccountIdOf<T>, AssetIdOf<T>>,
}

Structures

/// This structure holds a governance strategy. This defines how to behave
/// when ensuring privileged calls and deciding executing
/// calls
#[derive(TypeInfo, Encode, Decode, MaxEncodedLen, Clone, Eq, PartialEq, Debug)]
#[scale_info(skip_type_params(AccountId, AssetId))]
pub enum CommunityGovernanceStrategy<AccountId, AssetId> {
    /// The community governance lies in the shoulders of the admin of it.
    ///
    /// This is equivalent to `RawOrigin::Member` on collectives-pallet, or
    /// `BodyPart::Voice` on XCM.
    AdminBased(AccountId),
    /// The community governance relies on a member count-based (one member,
    /// one vote) poll.
    ///
    /// This is equivalent to `RawOrigin::Members` on collectives-pallet, or
    /// `BodyPart::Members` on XCM.
    MemberCountPoll {
        count: u32,
    },
    /// The community governance relies on an asset-weighed (one token,
    /// one vote) poll.
    ///
    /// This is equivalent to `RawOrigin::Members` on collectives-pallet, or
    /// `BodyPart::Fraction` on XCM.
    AssetWeighedPoll {
        asset_id: AssetId,
        #[codec(compact)]
        num: u32,
        #[codec(compact)]
        denum: u32,
    },
    /// The community governance relies on an ranked-weighed (one member vote,
    /// the number of votes corresponding to the rank of member) poll,
    ///
    /// This is equivalent to `RawOrigin::Members` on collectives-pallet, or
    /// `BodyPart::Fraction` on XCM.
    RankedWeighedPoll {
        #[codec(compact)]
        num: u32,
        #[codec(compact)]
        denum: u32,
    },
}

/// This structure holds the basic definition of a proposal.
/// It includes the information about the proposer,
/// the hash of the call to be executed if approved,
/// and the information of the
#[derive(TypeInfo, Encode, Decode, MaxEncodedLen, Clone, PartialEq, Eq)]
#[scale_info(skip_type_params(T))]
pub struct CommunityProposal<T: Config> {
    pub(crate) proposer: AccountIdOf<T>,
    pub(crate) call_hash: Hash,
}

/// This structure holds a poll and the methods to increase/decrease
/// votes
#[derive(TypeInfo, Encode, Decode, MaxEncodedLen, Clone)]
pub struct CommunityPoll {
    #[codec(compact)]
    pub(crate) ayes: VotesCount,
    #[codec(compact)]
    pub(crate) nays: VotesCount,
}

Storage

/// Stores the governance strategy for the community.
#[pallet::storage]
#[pallet::getter(fn governance_strategy)]
pub(super) type GovernanceStrategy<T> = StorageMap<
    _,
    Blake2_128Concat,
    CommunityIdOf<T>,
    CommunityGovernanceStrategy<AccountIdOf<T>, AssetIdOf<T>>
>;

/// Stores a queue of the proposals.
#[pallet::storage]
#[pallet::getter(fn proposals)]
pub(super) type Proposals<T> = StorageMap<
    _,
    Blake2_128Concat,
    CommunityIdOf<T>,
    BoundedVec<CommunityProposal<T>, <T as Config>::MaxProposals>
>;

/// Stores a poll representing the current proposal.
#[pallet::storage]
#[pallet::getter(fn poll)]
pub(super) type Poll<T> = StorageMap<_, Blake2_128Concat, CommunityIdOf<T>, CommunityPoll>;

/// Stores the list of votes for a community.
#[pallet::storage]
pub(super) type VoteOf<T> = StorageDoubleMap<
    _,
    Blake2_128Concat,
    CommunityIdOf<T>,
    Blake2_128Concat,
    AccountIdOf<T>,
    ()
>;

Implementation

Permissioned Calls

  • open_proposal: Creates a proposal to execute a call on behalf of either the community origin or the community account.
  • vote_proposal: Creates a proposal to execute a call on behalf of either the community origin or the community account.
  • close_proposal: Closes a proposal, executing a call (to be dispatched by the runtime scheduler).

Privileged Calls

  • execute_call: Creates a proposal, and immediately closes a poll, effectively executing a call (to be dispatched by the runtime scheduler). Called by the community admin when the current governance strategy for the community is AdminBased.

Private methods

  • do_create_proposal: Enqueues a proposal with its corresponding (preimaged) BoundedCall. Is called by open_proposal.
  • ensure_poll_closed: Ensures whether a proposal is able to be closed. Is called by close_proposal.
  • get_poll_approval: Decides whether a proposal is approved. Is called by close_proposal.
  • do_clear_poll: Clears a poll once it's closed. Is called by close_proposal.
  • do_call_execute: Schedules a enqueued on behalf of the treasury. Is called by close_proposal or execute_call.

Deprecations

  • Remove assets_transfer and balances_transfer, as they should be dispatched by the governance mechanisms.
@pandres95 pandres95 self-assigned this Oct 3, 2023
@pandres95 pandres95 moved this to Backlog in Virto MVP Oct 3, 2023
@pandres95 pandres95 changed the title Running proposals to enable community governance. [Community] Implement Governance Oct 5, 2023
@pandres95 pandres95 linked a pull request Oct 5, 2023 that will close this issue
@pandres95 pandres95 moved this from Backlog to In Progress in Virto MVP Oct 10, 2023
@pandres95 pandres95 moved this from In Progress to Under Review in Virto MVP Nov 17, 2023
@pandres95 pandres95 moved this from Under Review to Done in Virto MVP Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants