Skip to content

Commit

Permalink
Replace pallet_assets with orml_tokens & orml_currency (#91)
Browse files Browse the repository at this point in the history
* Replace pallet_assets with orml_tokens

* add currencies

* update proxy
  • Loading branch information
Szegoo authored Apr 20, 2024
1 parent 0277476 commit f9c4003
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 54 deletions.
39 changes: 38 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ 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 Expand Up @@ -133,6 +132,8 @@ substrate-build-script-utils = "11.0.0"

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

# Polytope Labs
Expand Down
11 changes: 10 additions & 1 deletion runtime/primitives/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::Balance;
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

/// Asset identifier.
pub type AssetId = u32;

#[derive(
Clone,
Copy,
Expand All @@ -15,4 +19,9 @@ use scale_info::TypeInfo;
TypeInfo,
MaxEncodedLen,
)]
pub struct CustomMetadata;
pub struct CustomMetadata {
pub existential_deposit: Balance,
}

pub const REGX_ASSET_ID: AssetId = 0;
pub const RELAY_CHAIN_ASSET_ID: AssetId = 1;
3 changes: 3 additions & 0 deletions runtime/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
/// Balance of an account.
pub type Balance = u128;

/// Signed version of Balance
pub type Amount = i128;

/// Index of a transaction in the chain.
pub type Nonce = u32;

Expand Down
12 changes: 8 additions & 4 deletions runtime/regionx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ ismp-parachain-runtime-api = { workspace = true, default-features = false }

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

# Substrate
Expand All @@ -41,7 +43,6 @@ 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 @@ -115,7 +116,9 @@ std = [
"frame-try-runtime?/std",
"log/std",
"orml-asset-registry/std",
"pallet-assets/std",
"orml-currencies/std",
"orml-tokens/std",
"orml-traits/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
Expand Down Expand Up @@ -166,7 +169,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"hex-literal",
"orml-asset-registry/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"orml-tokens/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
Expand Down Expand Up @@ -195,9 +198,10 @@ try-runtime = [
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"orml-asset-registry/try-runtime",
"orml-currencies/try-runtime",
"orml-tokens/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 Down
24 changes: 20 additions & 4 deletions runtime/regionx/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{AssetId, Runtime, RuntimeCall};
use crate::{AssetId, Balance, OrmlAssetRegistry, Runtime, RuntimeCall};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::traits::InstanceFilter;
use orml_asset_registry::DefaultAssetMetadata;
use orml_traits::asset_registry::AssetProcessor;
use orml_traits::{asset_registry::AssetProcessor, GetByKey};
use scale_info::TypeInfo;
use sp_runtime::{DispatchError, RuntimeDebug};

Expand Down Expand Up @@ -64,10 +64,26 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer =>
!matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. }),
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances { .. } |
RuntimeCall::Tokens { .. } |
RuntimeCall::Currencies { .. }
),
ProxyType::CancelProxy =>
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })),
}
}
}

pub struct ExistentialDeposits;
impl GetByKey<AssetId, Balance> for ExistentialDeposits {
fn get(asset: &AssetId) -> Balance {
if let Some(metadata) = OrmlAssetRegistry::metadata(asset) {
metadata.existential_deposit
} else {
// As restrictive as we can be. The asset must have associated metadata.
Balance::MAX
}
}
}
85 changes: 42 additions & 43 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything,
},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
Expand All @@ -71,8 +69,9 @@ use frame_support::{
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned, Phase,
EnsureRoot, Phase,
};
use orml_currencies::BasicCurrencyAdapter;
use pallet_ismp::{
mmr::primitives::{Leaf, LeafIndex},
primitives::Proof,
Expand All @@ -96,8 +95,8 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use xcm::latest::prelude::BodyId;

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

pub type Block = generic::Block<Header, UncheckedExtrinsic>;
Expand Down Expand Up @@ -148,9 +147,9 @@ pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 MILLIM4X:
// in our template, we map to 1/10 of that, or 1/10 MILLIM4X
let p = MILLIM4X / 10;
// in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 MILLIREGX:
// in our template, we map to 1/10 of that, or 1/10 MILLIREGX
let p = MILLIREGX / 10;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
smallvec![WeightToFeeCoefficient {
degree: 1,
Expand Down Expand Up @@ -197,13 +196,13 @@ pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

// Unit = the base number of indivisible units for balances
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 REGX: Balance = 1_000_000_000_000;
pub const MILLIREGX: Balance = 1_000_000_000;
pub const MICROREGX: 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
items as Balance * REGX + (bytes as Balance) * MILLIREGX
}

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
Expand All @@ -216,7 +215,7 @@ const BLOCK_PROCESSING_VELOCITY: u32 = 1;
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;

/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIM4X;
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIREGX;

/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
Expand All @@ -232,8 +231,6 @@ 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 @@ -338,10 +335,12 @@ impl pallet_authorship::Config for Runtime {

parameter_types! {
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Runtime {
type MaxLocks = ConstU32<50>;
type MaxLocks = MaxLocks;
type MaxHolds = ConstU32<1>;
/// The type for recording an account's balance.
type Balance = Balance;
Expand All @@ -351,7 +350,7 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type MaxReserves = ConstU32<50>;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
Expand All @@ -369,30 +368,30 @@ parameter_types! {
pub const MetadataDepositPerByte: Balance = deposit(0, 1);
}

impl pallet_assets::Config for Runtime {
impl orml_tokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetId;
type AssetIdParameter = codec::Compact<AssetId>;
type Currency = Balances;
// TODO after https://github.com/RegionX-Labs/RegionX-Node/issues/72:
// Allow only TC to create an asset.
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 Amount = Amount;
type CurrencyId = AssetId;
type WeightInfo = ();
/// Tokens are registered through the orml asset registry.
type ExistentialDeposits = ExistentialDeposits;
type CurrencyHooks = ();
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type DustRemovalWhitelist = ();
}

parameter_types! {
pub const NativeAssetId: AssetId = REGX_ASSET_ID;
}

impl orml_currencies::Config for Runtime {
type MultiCurrency = Tokens;
type NativeCurrency = BasicCurrencyAdapter<Runtime, Balances, Amount, BlockNumber>;
type GetNativeCurrencyId = NativeAssetId;
type WeightInfo = ();
type CallbackHandle = ();
type AssetAccountDeposit = AssetAccountDeposit;
type RemoveItemsLimit = sp_core::ConstU32<1000>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl orml_asset_registry::Config for Runtime {
Expand All @@ -410,7 +409,7 @@ impl orml_asset_registry::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = 10 * MICROM4X;
pub const TransactionByteFee: Balance = 10 * MICROREGX;
}

impl pallet_transaction_payment::Config for Runtime {
Expand Down Expand Up @@ -618,8 +617,9 @@ construct_runtime!(
// Monetary stuff.
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
OrmlAssetRegistry: orml_asset_registry = 13,
OrmlAssetRegistry: orml_asset_registry = 12,
Tokens: orml_tokens = 13,
Currencies: orml_currencies = 14,

// Governance
Sudo: pallet_sudo = 20,
Expand Down Expand Up @@ -652,7 +652,6 @@ construct_runtime!(
mod benches {
frame_benchmarking::define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_assets, Assets]
[pallet_balances, Balances]
[pallet_session, SessionBench::<Runtime>]
[pallet_multisig, Multisig]
Expand Down

0 comments on commit f9c4003

Please sign in to comment.