Sub3.0模板进化4添加官方治理模块--by Skyh

官方治理模块涉及collective, membership, elections,治理与国库treasury相关

1. 添加collective与membership

runtime 的Cargo.toml 添加:

pallet-collective = { version = "3.0.0", default-features = false }
pallet-membership = { version = "3.0.0", default-features = false }
pallet-elections-phragmen = { version = "3.0.0", default-features = false }

添加议会的collective

parameter_types! {
    pub const CouncilMotionDuration: BlockNumber = 3 * DAYS;
    pub const CouncilMaxProposals: u32 = 100;
    pub const CouncilMaxMembers: u32 = 100;
}

type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Config for Runtime {
    type Origin = Origin;
    type Proposal = Call;
    type Event = Event;
    type MotionDuration = CouncilMotionDuration;
    type MaxProposals = CouncilMaxProposals;
    type MaxMembers = CouncilMaxMembers;
    type DefaultVote = pallet_collective::PrimeDefaultVote;
    type WeightInfo = ();
}

添加技术委员会

parameter_types! {
    pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS;
    pub const TechnicalMaxProposals: u32 = 100;
    pub const TechnicalMaxMembers: u32 = 100;
}

type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Config for Runtime {
    type Origin = Origin;
    type Proposal = Call;
    type Event = Event;
    type MotionDuration = TechnicalMotionDuration;
    type MaxProposals = TechnicalMaxProposals;
    type MaxMembers = TechnicalMaxMembers;
    type DefaultVote = pallet_collective::PrimeDefaultVote;
    type WeightInfo = ();
}

添加membership:

type MoreThanHalfCouncil = EnsureOneOf<
    AccountId,
    EnsureRoot,
    pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>
>;

impl pallet_membership::Config for Runtime {
    type Event = Event;
    type AddOrigin = MoreThanHalfCouncil;
    type RemoveOrigin = MoreThanHalfCouncil;
    type SwapOrigin = MoreThanHalfCouncil;
    type ResetOrigin = MoreThanHalfCouncil;
    type PrimeOrigin = MoreThanHalfCouncil;
    type MembershipInitialized = TechnicalCommittee;
    type MembershipChanged = TechnicalCommittee;
}

2. 添加elections_phragmen, treasury

parameter_types! {
    pub const CandidacyBond: Balance = 1 * DOLLARS;
    // 1 storage item created, key size is 32 bytes, value size is 16+16.
    pub const VotingBondBase: Balance = deposit(1, 64);
    // additional data per vote is 32 bytes (account id).
    pub const VotingBondFactor: Balance = deposit(0, 32);
    /// Daily council elections
    pub const TermDuration: BlockNumber = 24 * HOURS;
    pub const DesiredMembers: u32 = 19;
    pub const DesiredRunnersUp: u32 = 19;

    pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
}

// Make sure that there are no more than MaxMembers members elected via phragmen.
const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());

impl pallet_elections_phragmen::Config for Runtime {
    type Event = Event;
    type Currency = Balances;
    type ChangeMembers = Council;
    type InitializeMembers = Council;

    type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
    type CandidacyBond = CandidacyBond;
    type VotingBondBase = VotingBondBase;
    type VotingBondFactor = VotingBondFactor;

    type LoserCandidate = Treasury;
    type KickedMember = Treasury;
    type DesiredMembers = DesiredMembers;
    type DesiredRunnersUp = DesiredRunnersUp;
    type TermDuration = TermDuration;

    type ModuleId = ElectionsPhragmenModuleId;
    type WeightInfo = ();
}

添加treasury

type ApproveOrigin = EnsureOneOf<
    AccountId,
    EnsureRoot,
    pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>
>;

parameter_types! {
    pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
    pub const ProposalBond: Permill = Permill::from_percent(5);
    pub const ProposalBondMinimum: Balance = DOLLARS;
    pub const SpendPeriod: BlockNumber = DAYS;
    pub const Burn: Permill = Permill::from_percent(0);

    pub const BountyDepositBase: Balance = DOLLARS;
    pub const BountyDepositPayoutDelay: BlockNumber = DAYS;
    pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;
    pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
    pub const BountyValueMinimum: Balance = 5 * DOLLARS;

    pub const TipCountdown: BlockNumber = DAYS;
    pub const TipFindersFee: Percent = Percent::from_percent(10);
    pub const TipReportDepositBase: Balance = DOLLARS;
    pub const DataDepositPerByte: Balance = CENTS;
    pub const MaximumReasonLength: u32 = 16384;
}

impl pallet_treasury::Config for Runtime {
    type Event = Event;
    type Currency = Balances;
    type ModuleId = TreasuryModuleId;
    type ApproveOrigin = ApproveOrigin;
    type RejectOrigin = MoreThanHalfCouncil;


    type ProposalBond = ProposalBond;
    type ProposalBondMinimum = ProposalBondMinimum;
    type SpendFunds = (); // Bounties;
    type SpendPeriod = SpendPeriod;
    type Burn = Burn;
    type OnSlash = Treasury;
    type BurnDestination = ();
    type WeightInfo = ();
}

添加bounty和tips

impl pallet_bounties::Config for Runtime {
    type Event = Event;
    type BountyDepositBase = BountyDepositBase;
    type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
    type BountyUpdatePeriod = BountyUpdatePeriod;
    type BountyCuratorDeposit = BountyCuratorDeposit;
    type BountyValueMinimum = BountyValueMinimum;
    type DataDepositPerByte = DataDepositPerByte;
    type MaximumReasonLength = MaximumReasonLength;
    type WeightInfo = ();

}
impl pallet_tips::Config for Runtime {
    type Event = Event;
    type DataDepositPerByte = DataDepositPerByte;
    type MaximumReasonLength = MaximumReasonLength;
    type Tippers = ElectionsPhragmen; // Kusama
    type TipCountdown = TipCountdown;
    type TipFindersFee = TipFindersFee;
    type TipReportDepositBase = TipReportDepositBase;
    type WeightInfo = ();
}

3 在runtime里加上

Council: pallet_collective::::{Module, Call, Storage, Origin, Event, Config},
        TechnicalCommittee: pallet_collective::::{Module, Call, Storage, Origin, Event, Config},
        TechnicalMembership: pallet_membership::::{Module, Call, Storage, Event, Config},
        ElectionsPhragmen: pallet_elections_phragmen::{Module, Call, Storage, Event, Config},
        Treasury: pallet_treasury::{Module, Call, Storage, Config, Event},
        Bounties: pallet_bounties::{Module, Call, Storage, Event},
        Tips: pallet_tips::{Module, Call, Storage, Event},

4. 修bug,编译之后就可以出现浏览器的治理页面

image.png

更新在
https://github.com/skyh24/node-template3/commit/f61143028d7b8d4934e834774d807823998bfbb4

https://github.com/skyh24/node-template3/commit/40018a7a7da41b3e2b84bd0cd1b4fb27a524953f

你可能感兴趣的:(Sub3.0模板进化4添加官方治理模块--by Skyh)