mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-06-11 09:31:06 +00:00
Add pallet-assets (#94)
* init * add assets to xcm transactor * add empty genesis config for assets for now
This commit is contained in:
+40
-3
@@ -17,7 +17,10 @@ use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
genesis_builder_helper::{build_config, create_default_config},
|
||||
parameter_types,
|
||||
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, InstanceFilter},
|
||||
traits::{
|
||||
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything,
|
||||
InstanceFilter,
|
||||
},
|
||||
weights::{
|
||||
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
|
||||
WeightToFeeCoefficients, WeightToFeePolynomial,
|
||||
@@ -26,7 +29,7 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::{
|
||||
limits::{BlockLength, BlockWeights},
|
||||
EnsureRoot,
|
||||
EnsureRoot, EnsureSigned,
|
||||
};
|
||||
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
|
||||
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
|
||||
@@ -56,7 +59,7 @@ use xcm::latest::prelude::BodyId;
|
||||
use xcm_executor::XcmExecutor;
|
||||
|
||||
use crate::{
|
||||
constants::currency::{deposit, EXISTENTIAL_DEPOSIT, MICROCENTS, MILLICENTS},
|
||||
constants::currency::{deposit, CENTS, EXISTENTIAL_DEPOSIT, MICROCENTS, MILLICENTS},
|
||||
weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
|
||||
xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin},
|
||||
};
|
||||
@@ -427,6 +430,38 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AssetDeposit: Balance = 10 * CENTS;
|
||||
pub const AssetAccountDeposit: Balance = deposit(1, 16);
|
||||
pub const ApprovalDeposit: Balance = EXISTENTIAL_DEPOSIT;
|
||||
pub const StringLimit: u32 = 50;
|
||||
pub const MetadataDepositBase: Balance = deposit(1, 68);
|
||||
pub const MetadataDepositPerByte: Balance = deposit(0, 1);
|
||||
}
|
||||
|
||||
impl pallet_assets::Config for Runtime {
|
||||
type ApprovalDeposit = ApprovalDeposit;
|
||||
type AssetAccountDeposit = AssetAccountDeposit;
|
||||
type AssetDeposit = AssetDeposit;
|
||||
type AssetId = u32;
|
||||
type AssetIdParameter = parity_scale_codec::Compact<u32>;
|
||||
type Balance = Balance;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type 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 = ConstU32<1000>;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type StringLimit = StringLimit;
|
||||
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
/// Relay Chain `TransactionByteFee` / 10
|
||||
pub const TransactionByteFee: Balance = 10 * MICROCENTS;
|
||||
@@ -596,6 +631,7 @@ construct_runtime!(
|
||||
// Monetary stuff.
|
||||
Balances: pallet_balances = 10,
|
||||
TransactionPayment: pallet_transaction_payment = 11,
|
||||
Assets: pallet_assets = 12,
|
||||
|
||||
// Governance
|
||||
Sudo: pallet_sudo = 15,
|
||||
@@ -623,6 +659,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]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
traits::{ConstU32, Everything, Nothing},
|
||||
traits::{ConstU32, Everything, Nothing, PalletInfoAccess},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
@@ -11,25 +11,32 @@ use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
|
||||
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
|
||||
FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative,
|
||||
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
|
||||
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
|
||||
UsingComponents, WithComputedOrigin, WithUniqueTopic,
|
||||
FixedWeightBounds, FungiblesAdapter, IsConcrete, NativeAsset, NoChecking, ParentIsPreset,
|
||||
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
|
||||
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
|
||||
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
|
||||
};
|
||||
use xcm_executor::XcmExecutor;
|
||||
|
||||
use super::{
|
||||
AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
|
||||
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
|
||||
AccountId, AllPalletsWithSystem, Assets, Balance, Balances, ParachainInfo, ParachainSystem,
|
||||
PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const RelayNetwork: Option<NetworkId> = None;
|
||||
pub PlaceholderAccount: AccountId = PolkadotXcm::check_account();
|
||||
pub AssetsPalletLocation: MultiLocation =
|
||||
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
|
||||
}
|
||||
|
||||
/// `AssetId/Balancer` converter for `TrustBackedAssets`
|
||||
pub type TrustBackedAssetsConvertedConcreteId =
|
||||
assets_common::TrustBackedAssetsConvertedConcreteId<AssetsPalletLocation, Balance>;
|
||||
|
||||
/// Type for specifying how a `MultiLocation` can be converted into an
|
||||
/// `AccountId`. This is used when determining ownership of accounts for asset
|
||||
/// transacting and when attempting to use XCM `Transact` in order to determine
|
||||
@@ -57,6 +64,26 @@ pub type LocalAssetTransactor = CurrencyAdapter<
|
||||
(),
|
||||
>;
|
||||
|
||||
/// Means for transacting assets besides the native currency on this chain.
|
||||
pub type LocalFungiblesTransactor = FungiblesAdapter<
|
||||
// Use this fungibles implementation:
|
||||
Assets,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
TrustBackedAssetsConvertedConcreteId,
|
||||
// Convert an XCM MultiLocation into a local account id:
|
||||
LocationToAccountId,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
// We don't track any teleports of `Assets`.
|
||||
NoChecking,
|
||||
// We don't track any teleports of `Assets`, but a placeholder account is provided due to trait
|
||||
// bounds.
|
||||
PlaceholderAccount,
|
||||
>;
|
||||
|
||||
/// Means for transacting assets on this chain.
|
||||
pub type AssetTransactors = (LocalAssetTransactor, LocalFungiblesTransactor);
|
||||
|
||||
/// This is the type we use to convert an (incoming) XCM origin into a local
|
||||
/// `Origin` instance, ready for dispatching a transaction with Xcm's
|
||||
/// `Transact`. There is an `OriginKind` which can biases the kind of local
|
||||
@@ -118,7 +145,7 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type AssetExchanger = ();
|
||||
type AssetLocker = ();
|
||||
// How to withdraw and deposit an asset.
|
||||
type AssetTransactor = LocalAssetTransactor;
|
||||
type AssetTransactor = AssetTransactors;
|
||||
type AssetTrap = PolkadotXcm;
|
||||
type Barrier = Barrier;
|
||||
type CallDispatcher = RuntimeCall;
|
||||
|
||||
Reference in New Issue
Block a user