Skip to content

Commit

Permalink
Pallet grouping macros (#300)
Browse files Browse the repository at this point in the history
* init using relative paths for now

* not working

* cannot define same types with alias names in 2 places relalias todo

* node compiles using impl oz system to abstract over frame system

* clean

* timestamp

* parachain info

* preimage and scheduler

* proxy and balances

* utility and parachain system

* use construct openzeppelin runtime

* generic runtime apis

* pause construct runtime until other macros validated by cross template usage

* hold runtime construction until inner macros validated

* evm template impl openzeppelin system

* revert back to generic construct runtime minimal wrapper for now

* use the trivial versions for the construct runtime and impl runtime api macros for now

* fix system grouping macro name

* consensus wrapper in generic template

* include ExistentialDeposit as explicit system parameter and add asset grouping for generic

* wip governance

* wip governnace for generic

* rm placeholders for runtime api and construct runtime until implemented

* fix evm template after latest changes to system grouping

* whitelist

* custom origins and referenda to finish governance grouping in generic template

* init xcm grouping for generic template queue pallets first

* more xcm

* replace direct paths with git url and branch for the macro dep

* update cargo locks and template fuzzer paths used for constants

* use consensus macro for evm template

* fix path in generic templates constant tests

* fix more test imports for the generic template

* fix template fuzzer build for generic template

* evm template governance and clean generic governance config as well

* impl xcm for evm template compiles w unused imports

* clean evm template commented out code and init assets impl for evm template

* progress on using impl assets for evm template

* error persists despite moving from impls into scope of macro expansion

* fix imports to fix errors for assets impl for evm template

* init evm works

* generic runtime compiles with most recent changeset

* update to latest macro changes

* move asset manager config into macro expansion as much as possible

* fix and clean

* update package name use git url and rename marker struct to OpenZeppelinRuntime

* compiles

* batch merge comment suggestions

* expose ProxyType and move defn from macro expansion to types file for each runtime

* generic single file config and minimal type aliases

* single file evm config need to clean imports and minimize type aliasing next

* clean evm template

* evm compilation post macro updates

* clean evm runtimes

* clean generic

* toml sort

* fix

* fmt fixes, supported the last changes

---------

Co-authored-by: Nikita Khateev <[email protected]>
  • Loading branch information
4meta5 and KitHat authored Nov 4, 2024
1 parent 2515d4e commit 8e0feec
Show file tree
Hide file tree
Showing 20 changed files with 561 additions and 1,856 deletions.
13 changes: 13 additions & 0 deletions evm-template/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions evm-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ serde_derive = { version = "1.0.121", default-features = false }
serde_json = "1.0.121"
smallvec = "1.11.0"

openzeppelin-polkadot-wrappers = { git = "http://github.com/openzeppelin/polkadot-runtime-wrappers", default-features = false, tag = "v0.1-rc1" }

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
Expand Down
3 changes: 3 additions & 0 deletions evm-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ parity-scale-codec = { workspace = true, features = [ "derive" ] }
scale-info = { workspace = true, features = [ "derive" ] }
smallvec = { workspace = true }

openzeppelin-polkadot-wrappers = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
Expand Down Expand Up @@ -141,6 +143,7 @@ std = [
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"openzeppelin-polkadot-wrappers/std",
"orml-xtokens/std",
"pallet-asset-manager/std",
"pallet-assets/std",
Expand Down
73 changes: 11 additions & 62 deletions evm-template/runtime/src/configs/asset_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use frame_support::{
dispatch::GetDispatchInfo, parameter_types, traits::AsEnsureOriginWithArg, weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSigned};
use parity_scale_codec::{Compact, Decode, Encode};
use frame_support::{dispatch::GetDispatchInfo, weights::Weight};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_core::{H160, H256};
use sp_runtime::traits::Hash as THash;
Expand All @@ -13,21 +10,10 @@ use sp_std::{
use xcm::latest::Location;

use crate::{
constants::currency::{deposit, CENTS, MILLICENTS},
types::{AccountId, AssetId, Balance},
weights, AssetManager, Assets, Balances, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
AssetManager, Assets, Runtime, RuntimeCall, RuntimeOrigin,
};

parameter_types! {
pub const AssetDeposit: Balance = 10 * CENTS;
pub const AssetAccountDeposit: Balance = deposit(1, 16);
pub const ApprovalDeposit: Balance = MILLICENTS;
pub const StringLimit: u32 = 50;
pub const MetadataDepositBase: Balance = deposit(1, 68);
pub const MetadataDepositPerByte: Balance = deposit(0, 1);
pub const RemoveItemsLimit: u32 = 1000;
}

// Required for runtime benchmarks
pallet_assets::runtime_benchmarks_enabled! {
pub struct BenchmarkHelper;
Expand All @@ -41,31 +27,6 @@ pallet_assets::runtime_benchmarks_enabled! {
}
}

// Foreign assets
impl pallet_assets::Config for Runtime {
type ApprovalDeposit = ApprovalDeposit;
type AssetAccountDeposit = AssetAccountDeposit;
type AssetDeposit = AssetDeposit;
type AssetId = AssetId;
type AssetIdParameter = Compact<AssetId>;
type Balance = Balance;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper;
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<AccountId>;
type Freezer = ();
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type RemoveItemsLimit = RemoveItemsLimit;
type RuntimeEvent = RuntimeEvent;
type StringLimit = StringLimit;
/// Rerun benchmarks if you are making changes to runtime configuration.
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
}

// Our AssetType. For now we only handle Xcm Assets
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub enum AssetType {
Expand Down Expand Up @@ -114,6 +75,14 @@ impl From<AssetType> for AssetId {
}
}

#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub struct AssetRegistrarMetadata {
pub name: Vec<u8>,
pub symbol: Vec<u8>,
pub decimals: u8,
pub is_frozen: bool,
}

// We instruct how to register the Assets
// In this case, we tell it to Create an Asset in pallet-assets
pub struct AssetRegistrar;
Expand Down Expand Up @@ -165,26 +134,6 @@ impl pallet_asset_manager::AssetRegistrar<Runtime> for AssetRegistrar {
}
}

#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub struct AssetRegistrarMetadata {
pub name: Vec<u8>,
pub symbol: Vec<u8>,
pub decimals: u8,
pub is_frozen: bool,
}

impl pallet_asset_manager::Config for Runtime {
type AssetId = AssetId;
type AssetRegistrar = AssetRegistrar;
type AssetRegistrarMetadata = AssetRegistrarMetadata;
type Balance = Balance;
type ForeignAssetModifierOrigin = EnsureRoot<AccountId>;
type ForeignAssetType = AssetType;
type RuntimeEvent = RuntimeEvent;
/// Rerun benchmarks if you are making changes to runtime configuration.
type WeightInfo = weights::pallet_asset_manager::WeightInfo<Runtime>;
}

/// This trait ensure we can convert AccountIds to AssetIds.
pub trait AccountIdAssetIdConversion<Account, AssetId> {
// Get assetId and prefix from account
Expand Down
78 changes: 4 additions & 74 deletions evm-template/runtime/src/configs/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,10 @@
pub mod origins;
pub use origins::{Spender, WhitelistedCaller};
mod tracks;

use frame_support::{
parameter_types,
traits::{ConstU32, EitherOf},
};
use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned};
pub mod tracks;

use crate::{
constants::{
currency::{CENTS, GRAND},
DAYS,
},
types::{AccountId, Balance, BlockNumber},
weights, Balances, Preimage, Referenda, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
Scheduler, Treasury,
constants::currency::{CENTS, GRAND},
types::{Balance, BlockNumber},
RuntimeOrigin,
};

parameter_types! {
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
}

impl pallet_conviction_voting::Config for Runtime {
type Currency = Balances;
type MaxTurnout =
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
type MaxVotes = ConstU32<512>;
type Polls = Referenda;
type RuntimeEvent = RuntimeEvent;
type VoteLockingPeriod = VoteLockingPeriod;
/// Rerun benchmarks if you are making changes to runtime configuration.
type WeightInfo = weights::pallet_conviction_voting::WeightInfo<Runtime>;
}

parameter_types! {
pub const MaxBalance: Balance = Balance::MAX;
}
pub type TreasurySpender = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, Spender>;

impl origins::pallet_custom_origins::Config for Runtime {}

impl pallet_whitelist::Config for Runtime {
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
type Preimages = Preimage;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
/// Rerun benchmarks if you are making changes to runtime configuration.
type WeightInfo = weights::pallet_whitelist::WeightInfo<Runtime>;
type WhitelistOrigin = EnsureRoot<Self::AccountId>;
}

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 3 * CENTS;
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
}

impl pallet_referenda::Config for Runtime {
type AlarmInterval = AlarmInterval;
type CancelOrigin = EnsureRoot<AccountId>;
type Currency = Balances;
type KillOrigin = EnsureRoot<AccountId>;
type MaxQueued = ConstU32<20>;
type Preimages = Preimage;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Slash = Treasury;
type SubmissionDeposit = SubmissionDeposit;
type SubmitOrigin = EnsureSigned<AccountId>;
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
type Tracks = tracks::TracksInfo;
type UndecidingTimeout = UndecidingTimeout;
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
/// Rerun benchmarks if you are making changes to runtime configuration.
type WeightInfo = weights::pallet_referenda::WeightInfo<Runtime>;
}
Loading

0 comments on commit 8e0feec

Please sign in to comment.