Skip to content

Commit

Permalink
Test Aragon DAO whitelist origin on Koi
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lau <x@acg.box>
  • Loading branch information
AurevoirXavier committed Nov 6, 2024
1 parent cdede29 commit 86b44f8
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 130 deletions.
26 changes: 25 additions & 1 deletion runtime/common/src/gov_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pub use frame_support::traits::{EitherOf, EitherOfDiverse};
pub use frame_support::{
dispatch::RawOrigin,
traits::{EitherOf, EitherOfDiverse, EnsureOrigin, Get},
};

// core
use core::marker::PhantomData;
// darwinia
use dc_primitives::AccountId;
// frontier
Expand Down Expand Up @@ -56,3 +61,22 @@ pub const ROOT: AccountId20 =
pub const KTON_ADMIN: AccountId20 = AccountId20([
70, 39, 93, 41, 17, 63, 6, 92, 42, 172, 38, 47, 52, 199, 163, 216, 168, 183, 55, 125,
]);

/// Ensure the origin is RingDAO.
pub struct RingDao<RingDaoAccount>(PhantomData<RingDaoAccount>)
where
RingDaoAccount: Get<AccountId20>;
impl<O, RingDaoAccount> EnsureOrigin<O> for RingDao<RingDaoAccount>
where
O: Into<Result<RawOrigin<AccountId20>, O>> + From<RawOrigin<AccountId20>>,
RingDaoAccount: Get<AccountId20>,
{
type Success = ();

fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Signed(who) if who == RingDaoAccount::get() => Ok(()),
r => Err(O::from(r)),
})
}
}
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl pallet_asset_manager::Config for Runtime {
type AssetRegistrar = AssetRegistrar;
type AssetRegistrarMetadata = xcm_config::AssetRegistrarMetadata;
type Balance = Balance;
type ForeignAssetModifierOrigin = RootOr<GeneralAdmin>;
type ForeignAssetModifierOrigin = Root;
type ForeignAssetType = AssetType;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_asset_manager::WeightInfo<Self>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl pallet_assets::Config for Runtime {
>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = RootOr<GeneralAdmin>;
type ForceOrigin = Root;
type Freezer = ();
type MetadataDepositBase = ();
type MetadataDepositPerByte = ();
Expand Down
24 changes: 15 additions & 9 deletions runtime/koi/src/pallets/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

mod origin;
pub use origin::custom_origins;
use origin::*;
pub use origin::{custom_origins, GeneralAdmin};

mod track;
use track::*;
Expand All @@ -42,7 +42,7 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SetMembersOrigin = RootOr<GeneralAdmin>;
type SetMembersOrigin = Root;
type WeightInfo = weights::pallet_collective::WeightInfo<Self>;
}

Expand Down Expand Up @@ -80,6 +80,11 @@ impl pallet_referenda::Config for Runtime {

impl custom_origins::Config for Runtime {}

frame_support::parameter_types! {
// 0x005493b5658e6201F06FE2adF492610635505F4C.
pub RingDaoAccount: AccountId = [0, 84, 147, 181, 101, 142, 98, 1, 240, 111, 226, 173, 244, 146, 97, 6, 53, 80, 95, 76].into();
}

// The purpose of this pallet is to queue calls to be dispatched as by root later => the Dispatch
// origin corresponds to the Gov2 Whitelist track.
impl pallet_whitelist::Config for Runtime {
Expand All @@ -88,15 +93,18 @@ impl pallet_whitelist::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_whitelist::WeightInfo<Self>;
type WhitelistOrigin = RootOrAtLeastFourFifth<TechnicalCollective>;
type WhitelistOrigin = frame_support::traits::EitherOf<
RingDao<RingDaoAccount>,
AtLeastFourFifth<TechnicalCollective>,
>;
}

frame_support::parameter_types! {
pub const ProposalBond: sp_runtime::Permill = sp_runtime::Permill::from_percent(5);
}

impl pallet_treasury::Config for Runtime {
type ApproveOrigin = RootOr<GeneralAdmin>;
type ApproveOrigin = Root;
type AssetKind = ();
type BalanceConverter = frame_support::traits::tokens::UnityAssetBalanceConversion;
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -115,13 +123,11 @@ impl pallet_treasury::Config for Runtime {
type ProposalBond = ProposalBond;
type ProposalBondMaximum = ();
type ProposalBondMinimum = ConstU128<DARWINIA_PROPOSAL_REQUIREMENT>;
type RejectOrigin = RootOr<GeneralAdmin>;
type RejectOrigin = Root;
type RuntimeEvent = RuntimeEvent;
type SpendFunds = ();
type SpendOrigin = EitherOf<
frame_system::EnsureRootWithSuccess<Self::AccountId, pallet_config::MaxBalance>,
Spender,
>;
type SpendOrigin =
frame_system::EnsureRootWithSuccess<Self::AccountId, pallet_config::MaxBalance>;
type SpendPeriod = Time1;
type WeightInfo = weights::pallet_treasury::WeightInfo<Self>;
}
80 changes: 33 additions & 47 deletions runtime/koi/src/pallets/governance/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
pub mod custom_origins {
// crates.io
use strum::EnumString;
// darwinia
use dc_primitives::{Balance, UNIT};
// polkadot-sdk
use frame_support::pallet_prelude::*;
use sp_runtime::RuntimeDebug;
Expand All @@ -40,16 +38,10 @@ pub mod custom_origins {
pub enum Origin {
/// Origin able to dispatch a whitelisted call.
WhitelistedCaller,
/// General admin
GeneralAdmin,
/// Origin able to cancel referenda.
ReferendumCanceller,
/// Origin able to kill referenda.
ReferendumKiller,
/// Origin able to spend up to 4M KRING from the treasury at once.
MediumSpender,
/// Origin able to spend up to 20M KRING from the treasury at once.
BigSpender,
}

macro_rules! decl_unit_ensures {
Expand Down Expand Up @@ -82,45 +74,39 @@ pub mod custom_origins {
};
() => {}
}
decl_unit_ensures!(ReferendumCanceller, ReferendumKiller, WhitelistedCaller, GeneralAdmin);
decl_unit_ensures!(ReferendumCanceller, ReferendumKiller, WhitelistedCaller);

macro_rules! decl_ensure {
(
$vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
$( $item:ident = $success:expr, )*
}
) => {
$vis struct $name;
impl<O: Into<Result<Origin, O>> + From<Origin>>
EnsureOrigin<O> for $name
{
type Success = $success_type;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
$(
Origin::$item => Ok($success),
)*
r => Err(O::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
// By convention the more privileged origins go later, so for greatest chance
// of success, we want the last one.
let _result: Result<O, ()> = Err(());
$(
let _result: Result<O, ()> = Ok(O::from(Origin::$item));
)*
_result
}
}
}
}
decl_ensure! {
pub type Spender: EnsureOrigin<Success = Balance> {
MediumSpender = 4_000_000 * UNIT,
BigSpender = 20_000_000 * UNIT,
}
}
// macro_rules! decl_ensure {
// (
// $vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
// $( $item:ident = $success:expr, )*
// }
// ) => {
// $vis struct $name;
// impl<O: Into<Result<Origin, O>> + From<Origin>>
// EnsureOrigin<O> for $name
// {
// type Success = $success_type;
// fn try_origin(o: O) -> Result<Self::Success, O> {
// o.into().and_then(|o| match o {
// $(
// Origin::$item => Ok($success),
// )*
// r => Err(O::from(r)),
// })
// }
// #[cfg(feature = "runtime-benchmarks")]
// fn try_successful_origin() -> Result<O, ()> {
// // By convention the more privileged origins go later, so for greatest chance
// // of success, we want the last one.
// let _result: Result<O, ()> = Err(());
// $(
// let _result: Result<O, ()> = Ok(O::from(Origin::$item));
// )*
// _result
// }
// }
// }
// }
}
pub use custom_origins::*;
71 changes: 4 additions & 67 deletions runtime/koi/src/pallets/governance/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::str::FromStr;
// darwinia
use super::*;

const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 7] = [
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 4] = [
(
0,
pallet_referenda::TrackInfo {
Expand Down Expand Up @@ -80,32 +80,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 7]
),
},
),
(
2,
pallet_referenda::TrackInfo {
name: "general_admin",
max_deciding: 10,
decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT,
prepare_period: TIME_1,
decision_period: TIME_1,
confirm_period: TIME_1,
min_enactment_period: TIME_1,
min_approval: pallet_referenda::Curve::make_reciprocal(
1,
2,
percent(80),
percent(50),
percent(100),
),
min_support: pallet_referenda::Curve::make_reciprocal(
1,
2,
percent(10),
percent(0),
percent(50),
),
},
),
// 2 for deprecated general admin.
(
3,
pallet_referenda::TrackInfo {
Expand Down Expand Up @@ -158,46 +133,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 7]
),
},
),
(
5,
pallet_referenda::TrackInfo {
name: "medium_spender",
max_deciding: 50,
decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT,
prepare_period: TIME_1,
decision_period: TIME_1,
confirm_period: TIME_1,
min_enactment_period: TIME_1,
min_approval: pallet_referenda::Curve::make_linear(1, 2, percent(50), percent(100)),
min_support: pallet_referenda::Curve::make_reciprocal(
1,
2,
percent(1),
percent(0),
percent(50),
),
},
),
(
6,
pallet_referenda::TrackInfo {
name: "big_spender",
max_deciding: 50,
decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT,
prepare_period: TIME_1,
decision_period: TIME_1,
confirm_period: TIME_1,
min_enactment_period: TIME_1,
min_approval: pallet_referenda::Curve::make_linear(1, 2, percent(50), percent(100)),
min_support: pallet_referenda::Curve::make_reciprocal(
1,
2,
percent(1),
percent(0),
percent(50),
),
},
),
// 5 for deprecated medium spender.
// 6 for deprecated big spender.
];

pub struct TracksInfo;
Expand Down
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl xcm_executor::Config for XcmExecutorConfig {
}

impl pallet_xcm::Config for Runtime {
type AdminOrigin = RootOr<GeneralAdmin>;
type AdminOrigin = Root;
// ^ Override for AdvertisedXcmVersion default
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
Expand Down
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/preimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl pallet_preimage::Config for Runtime {
>,
>;
type Currency = Balances;
type ManagerOrigin = RootOr<GeneralAdmin>;
type ManagerOrigin = Root;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_preimage::WeightInfo<Self>;
}
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ impl pallet_scheduler::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type ScheduleOrigin = RootOr<GeneralAdmin>;
type ScheduleOrigin = Root;
type WeightInfo = weights::pallet_scheduler::WeightInfo<Self>;
}
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/xcmp_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::*;

impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ChannelInfo = ParachainSystem;
type ControllerOrigin = RootOr<GeneralAdmin>;
type ControllerOrigin = Root;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type MaxInboundSuspended = sp_core::ConstU32<1_000>;
type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery<
Expand Down

0 comments on commit 86b44f8

Please sign in to comment.