Skip to content

Commit

Permalink
Add asset-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 13, 2024
1 parent b20aca3 commit 324789c
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 16 deletions.
64 changes: 64 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ cumulus-client-collator = "0.7.0"
substrate-wasm-builder = { version = "17.0.0" }
substrate-build-script-utils = "11.0.0"

# Orml
orml-asset-registry = { version = "0.7.0", default-features = false }
orml-traits = { version = "0.7.0", default-features = false }

# Polytope Labs
ismp = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-try-runtime", default-features = false }
pallet-ismp = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-try-runtime", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions runtime/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

sp-core = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
]
18 changes: 18 additions & 0 deletions runtime/primitives/src/assets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

#[derive(
Clone,
Copy,
Default,
PartialOrd,
Ord,
PartialEq,
Eq,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
pub struct CustomMetadata;
2 changes: 2 additions & 0 deletions runtime/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#![cfg_attr(not(feature = "std"), no_std)]

pub mod assets;

use sp_runtime::{
generic,
traits::{BlakeTwo256, IdentifyAccount, Verify},
Expand Down
7 changes: 7 additions & 0 deletions runtime/regionx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ ismp-parachain = { workspace = true, default-features = false }
ismp-runtime-api = { workspace = true, default-features = false }
ismp-parachain-runtime-api = { workspace = true, default-features = false }

# Orml
orml-asset-registry = { workspace = true }
orml-traits = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
Expand Down Expand Up @@ -107,6 +111,7 @@ std = [
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"orml-asset-registry/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down Expand Up @@ -154,6 +159,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"orml-asset-registry/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand All @@ -179,6 +185,7 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"orml-asset-registry/try-runtime",
"pallet-ismp/try-runtime",
"ismp-parachain/try-runtime",
"pallet-assets/try-runtime",
Expand Down
30 changes: 30 additions & 0 deletions runtime/regionx/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::{AssetId, Runtime};
use orml_asset_registry::DefaultAssetMetadata;
use orml_traits::asset_registry::AssetProcessor;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::DispatchError;

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub struct CustomAssetProcessor;

impl AssetProcessor<AssetId, DefaultAssetMetadata<Runtime>> for CustomAssetProcessor {
fn pre_register(
id: Option<AssetId>,
metadata: DefaultAssetMetadata<Runtime>,
) -> Result<(AssetId, DefaultAssetMetadata<Runtime>), DispatchError> {
match id {
Some(id) => Ok((id, metadata)),
None => Err(DispatchError::Other("asset-registry: AssetId is required")),
}
}

fn post_register(
_id: AssetId,
_metadata: DefaultAssetMetadata<Runtime>,
) -> Result<(), DispatchError> {
Ok(())
}
}
52 changes: 36 additions & 16 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ extern crate alloc;
mod weights;
pub mod xcm_config;

mod impls;
mod ismp;

use impls::*;

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::traits::TransformOrigin;
Expand Down Expand Up @@ -93,7 +96,8 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use xcm::latest::prelude::BodyId;

use regionx_primitives::{
AccountId, Address, Balance, BlockNumber, Hash, Header, Nonce, Signature,
assets::CustomMetadata, AccountId, Address, Balance, BlockNumber, Hash, Header, Nonce,
Signature,
};

pub type Block = generic::Block<Header, UncheckedExtrinsic>;
Expand Down Expand Up @@ -228,6 +232,8 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

type AssetId = u32;

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -366,11 +372,11 @@ parameter_types! {
impl pallet_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = u32;
type AssetIdParameter = parity_scale_codec::Compact<u32>;
type AssetId = AssetId;
type AssetIdParameter = parity_scale_codec::Compact<AssetId>;
type Currency = Balances;
// TODO after https://github.com/RegionX-Labs/RegionX-Node/issues/72:
// Allow only TC to create an asset as well.
// Allow only TC to create an asset.
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type AssetDeposit = AssetDeposit;
Expand All @@ -389,6 +395,19 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = ();
}

impl orml_asset_registry::Config for Runtime {
type AssetId = AssetId;
type AssetProcessor = CustomAssetProcessor;
// TODO after https://github.com/RegionX-Labs/RegionX-Node/issues/72:
// Allow TC to register an asset.
type AuthorityOrigin = EnsureRoot<AccountId>;
type Balance = Balance;
type CustomMetadata = CustomMetadata;
type StringLimit = AssetsStringLimit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = 10 * MICROM4X;
Expand Down Expand Up @@ -548,26 +567,27 @@ construct_runtime!(
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
OrmlAssetRegistry: orml_asset_registry = 13,

// Governance
Sudo: pallet_sudo = 15,
Sudo: pallet_sudo = 20,

// Collator support. The order of these 4 are important and shall not change.
Authorship: pallet_authorship = 20,
CollatorSelection: pallet_collator_selection = 21,
Session: pallet_session = 22,
Aura: pallet_aura = 23,
AuraExt: cumulus_pallet_aura_ext = 24,
Authorship: pallet_authorship = 30,
CollatorSelection: pallet_collator_selection = 31,
Session: pallet_session = 32,
Aura: pallet_aura = 33,
AuraExt: cumulus_pallet_aura_ext = 34,

// XCM helpers.
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
MessageQueue: pallet_message_queue = 33,
XcmpQueue: cumulus_pallet_xcmp_queue = 40,
PolkadotXcm: pallet_xcm = 41,
CumulusXcm: cumulus_pallet_xcm = 42,
MessageQueue: pallet_message_queue = 43,

// ISMP
Ismp: pallet_ismp = 40,
IsmpParachain: ismp_parachain = 41,
Ismp: pallet_ismp = 50,
IsmpParachain: ismp_parachain = 51,
}
);

Expand Down

0 comments on commit 324789c

Please sign in to comment.