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

Add pallet-assets #73

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 5 additions & 1 deletion runtime/regionx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -193,4 +197,4 @@ try-runtime = [
"sp-runtime/try-runtime",
]

experimental = ["pallet-aura/experimental"]
experimental = ["pallet-aura/experimental"]
49 changes: 47 additions & 2 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = u32;
type AssetIdParameter = parity_scale_codec::Compact<u32>;
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<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -531,6 +575,7 @@ construct_runtime!(
mod benches {
frame_benchmarking::define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_assets, Assets]
[pallet_balances, Balances]
[pallet_session, SessionBench::<Runtime>]
[pallet_timestamp, Timestamp]
Expand Down
Loading