Skip to content

Commit

Permalink
added pallet assets
Browse files Browse the repository at this point in the history
  • Loading branch information
asiniscalchi committed Oct 9, 2024
1 parent 8440db1 commit 72f48ba
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
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.

2 changes: 2 additions & 0 deletions xcm-simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ laos-primitives = { workspace = true }
parachain-info = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
assets-common = { workspace = true }
parachains-common = { workspace = true }


[features]
default = ["std"]
std = [
"parachains-common/std",
"cumulus-pallet-xcm/std",
"parachain-info/std",
"laos-primitives/std",
Expand Down
37 changes: 35 additions & 2 deletions xcm-simulator/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
use core::marker::PhantomData;
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing},
traits::{
AsEnsureOriginWithArg, ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything,
EverythingBut, Nothing,
},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use parity_scale_codec::{Decode, Encode};

use frame_system::EnsureRoot;
use frame_system::{EnsureRoot, EnsureSigned};
use sp_core::{ConstU32, H256};
use sp_runtime::{
codec,
traits::{Get, Hash, IdentityLookup},
AccountId32,
};
use sp_std::prelude::*;

use assets_common::{foreign_creators::ForeignCreators, matching::FromSiblingParachain};
use pallet_xcm::XcmPassthrough;
use parachains_common::AssetIdForTrustBackedAssets;
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
use polkadot_parachain_primitives::primitives::{
DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler,
Expand Down Expand Up @@ -464,6 +469,33 @@ pub type ForeignCreatorsSovereignAccountOf = (
GlobalConsensusParachainConvertsFor<UniversalLocation, AccountId>,
);

// Called "Trust Backed" assets because these are generally registered by some account, and users of
// the asset assume it has some claimed backing. The pallet is called `Assets` in
// `construct_runtime` to avoid breaking changes on storage reads.
pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type AssetDeposit = frame_support::traits::ConstU128<1_000>;
type MetadataDepositBase = frame_support::traits::ConstU128<1_000>;
type MetadataDepositPerByte = frame_support::traits::ConstU128<1_000>;
type ApprovalDeposit = ExistentialDeposit;
type StringLimit = frame_support::traits::ConstU32<50>;
type Freezer = ();
type Extra = ();
type WeightInfo = ();
type CallbackHandle = ();
type AssetAccountDeposit = frame_support::traits::ConstU128<1_000>;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

/// Assets managed by some foreign location. Note: we do not declare a `ForeignAssetsCall` type, as
/// this type is used in proxy definitions. We assume that a foreign location would not want to set
/// an individual, local account as a proxy for the issuance of their assets. This issuance should
Expand Down Expand Up @@ -510,6 +542,7 @@ construct_runtime!(
MsgQueue: mock_msg_queue,
PolkadotXcm: pallet_xcm,
ForeignUniques: pallet_uniques,
Assets: pallet_assets::<Instance1> = 50,
ForeignAssets: pallet_assets::<Instance2> = 53,
}
);
8 changes: 4 additions & 4 deletions xcm-simulator/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use xcm_simulator::TestExt;

mod laosish_xcm;

pub type ForeignAssetsCall =
pallet_assets::Call<parachain::Runtime, parachain::ForeignAssetsInstance>;

// Helper function for forming buy execution message
fn buy_execution<C>(fees: impl Into<Asset>) -> Instruction<C> {
BuyExecution { fees: fees.into(), weight_limit: Unlimited }
Expand Down Expand Up @@ -582,10 +585,7 @@ fn xcmp_create_asset() {
let para_a_native_asset_location =
xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(PARA_A_ID)]);

let create_asset = parachain::RuntimeCall::ForeignAssets(pallet_assets::Call::<
parachain::Runtime,
parachain::ForeignAssetsInstance,
>::create {
let create_asset = parachain::RuntimeCall::ForeignAssets(ForeignAssetsCall::create {
id: para_a_native_asset_location,
admin: ALICE,
min_balance: 1000,
Expand Down

0 comments on commit 72f48ba

Please sign in to comment.