From c28ee2770b5a4515d965e6c681434d9f8d6ad371 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 12 Apr 2024 15:58:33 +0200 Subject: [PATCH] Add pallet-assets --- Cargo.lock | 1 + Cargo.toml | 1 + runtime/regionx/Cargo.toml | 6 ++++- runtime/regionx/src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48e70f4a..bf6aa5c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9265,6 +9265,7 @@ dependencies = [ "ismp-parachain-runtime-api", "ismp-runtime-api", "log", + "pallet-assets", "pallet-aura", "pallet-authorship", "pallet-balances", diff --git a/Cargo.toml b/Cargo.toml index 015dc8bf..64fbfa1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ frame-system-rpc-runtime-api = { version = "26.0.0", default-features = false } frame-try-runtime = { version = "0.34.0", default-features = false } pallet-aura = { version = "27.0.0", default-features = false } pallet-authorship = { version = "28.0.0", default-features = false } +pallet-assets = { version = "29.0.0", default-features = false } pallet-balances = { version = "28.0.0", default-features = false } pallet-session = { version = "28.0.0", default-features = false } pallet-sudo = { version = "28.0.0", default-features = false } diff --git a/runtime/regionx/Cargo.toml b/runtime/regionx/Cargo.toml index 0b92e06d..b9d2bdc3 100644 --- a/runtime/regionx/Cargo.toml +++ b/runtime/regionx/Cargo.toml @@ -37,6 +37,7 @@ frame-system = { workspace = true } frame-system-benchmarking = { workspace = true, optional = true } frame-system-rpc-runtime-api = { workspace = true } frame-try-runtime = { workspace = true, optional = true } +pallet-assets = { workspace = true } pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } @@ -106,6 +107,7 @@ std = [ "frame-system/std", "frame-try-runtime?/std", "log/std", + "pallet-assets/std", "pallet-aura/std", "pallet-authorship/std", "pallet-balances/std", @@ -152,6 +154,7 @@ runtime-benchmarks = [ "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "hex-literal", + "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", @@ -178,6 +181,7 @@ try-runtime = [ "frame-try-runtime/try-runtime", "pallet-ismp/try-runtime", "ismp-parachain/try-runtime", + "pallet-assets/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", @@ -193,4 +197,4 @@ try-runtime = [ "sp-runtime/try-runtime", ] -experimental = ["pallet-aura/experimental"] \ No newline at end of file +experimental = ["pallet-aura/experimental"] diff --git a/runtime/regionx/src/lib.rs b/runtime/regionx/src/lib.rs index 0f6286c7..c2836acd 100644 --- a/runtime/regionx/src/lib.rs +++ b/runtime/regionx/src/lib.rs @@ -57,7 +57,9 @@ use frame_support::{ dispatch::DispatchClass, genesis_builder_helper::{build_config, create_default_config}, parameter_types, - traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything}, + traits::{ + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, + }, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, @@ -66,7 +68,7 @@ use frame_support::{ }; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureRoot, Phase, + EnsureRoot, EnsureSigned, Phase, }; use pallet_ismp::{ mmr_primitives::{Leaf, LeafIndex}, @@ -195,6 +197,11 @@ pub const M4X: Balance = 1_000_000_000_000; pub const MILLIM4X: Balance = 1_000_000_000; pub const MICROM4X: Balance = 1_000_000; +pub const fn deposit(items: u32, bytes: u32) -> Balance { + // TODO: ensure this is a sensible value. + items as Balance * M4X + (bytes as Balance) * MILLIM4X +} + /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included /// into the relay chain. const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; @@ -346,6 +353,42 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = ConstU32<0>; } +parameter_types! { + pub const AssetDeposit: Balance = deposit(1, 190); + pub const AssetAccountDeposit: Balance = deposit(1, 16); + pub const AssetsStringLimit: u32 = 50; + /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) + // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 + pub const MetadataDepositBase: Balance = deposit(1, 68); + pub const MetadataDepositPerByte: Balance = deposit(0, 1); +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = u64; + type AssetIdParameter = parity_scale_codec::Compact; + type Currency = Balances; + // TODO after https://github.com/RegionX-Labs/RegionX-Node/issues/72: + // Allow only TC to create an asset as well. + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ExistentialDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + // TODO: accurate weight. + type WeightInfo = (); + type CallbackHandle = (); + type AssetAccountDeposit = AssetAccountDeposit; + type RemoveItemsLimit = sp_core::ConstU32<1000>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = (); +} + parameter_types! { /// Relay Chain `TransactionByteFee` / 10 pub const TransactionByteFee: Balance = 10 * MICROM4X; @@ -504,6 +547,7 @@ construct_runtime!( // Monetary stuff. Balances: pallet_balances = 10, TransactionPayment: pallet_transaction_payment = 11, + Assets: pallet_assets = 12, // Governance Sudo: pallet_sudo = 15, @@ -531,6 +575,7 @@ construct_runtime!( mod benches { frame_benchmarking::define_benchmarks!( [frame_system, SystemBench::] + [pallet_assets, Assets] [pallet_balances, Balances] [pallet_session, SessionBench::] [pallet_timestamp, Timestamp]