Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Add initial setup of the XCM emulator #222

Closed
wants to merge 8 commits into from
Closed
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ members = [
"primitives/xcm",
]
exclude = [
"contracts",
"xcm-simulator"
"contracts",
"xcm-simulator",
"xcm-emulator"
]

[profile.release]
Expand Down
10 changes: 10 additions & 0 deletions runtime/trappist/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ pub mod fee {
}]
}
}

pub fn base_tx_fee() -> Balance {
CENTS / 10
}

pub fn default_fee_per_second() -> u128 {
let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time());
let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight;
base_tx_per_second * base_tx_fee()
}
}
5 changes: 3 additions & 2 deletions runtime/trappist/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ impl<Call> XcmWeightInfo<Call> for TrappistXcmWeight<Call> {
fn withdraw_asset(assets: &MultiAssets) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
}
// Currently there is no trusted reserve
// Hacked value to make the tests passing. This should be overwritten by the benchmarking
// pallet.
fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight {
u64::MAX
10_000u64.into()
}
fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
Expand Down
38 changes: 30 additions & 8 deletions runtime/trappist/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{impls::ToAuthor, weights::TrappistDropAssetsWeigher};
use crate::{
constants::fee::default_fee_per_second, impls::ToAuthor, weights::TrappistDropAssetsWeigher,
};

use super::{
AccountId, AssetRegistry, Assets, Balance, Balances, ParachainInfo, ParachainSystem,
Expand All @@ -40,14 +42,16 @@ use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use polkadot_parachain::primitives::Sibling;
use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation};

pub use xcm_executor::traits::Convert;

use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex,
ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete,
LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WeightInfoBounds,
ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible,
FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
};
use xcm_executor::XcmExecutor;

Expand Down Expand Up @@ -171,6 +175,7 @@ pub type XcmOriginToTransactDispatchOrigin = (

parameter_types! {
pub const MaxInstructions: u32 = 100;
pub UnitWeightCost: u64 = 1_000_000_000;
}

match_types! {
Expand Down Expand Up @@ -211,6 +216,14 @@ parameter_types! {
// Rockmine's Assets pallet index
pub RockmineAssetsPalletLocation: MultiLocation =
MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50)));

pub RUsdPerSecond: (xcm::v1::AssetId, u128) = (
MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))).into(),
default_fee_per_second() * 10
);
/// Roc = 7 RUSD
pub RocPerSecond: (xcm::v1::AssetId, u128) = (MultiLocation::parent().into(), default_fee_per_second() * 70);

}

//- From PR https://github.com/paritytech/cumulus/pull/936
Expand All @@ -223,6 +236,7 @@ fn matches_prefix(prefix: &MultiLocation, loc: &MultiLocation) -> bool {
.zip(loc.interior().iter())
.all(|(prefix_junction, junction)| prefix_junction == junction)
}

pub struct ReserveAssetsFrom<T>(PhantomData<T>);
impl<T: Get<MultiLocation>> FilterAssetLocation for ReserveAssetsFrom<T> {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
Expand All @@ -237,7 +251,14 @@ impl<T: Get<MultiLocation>> FilterAssetLocation for ReserveAssetsFrom<T> {
}
}

//--
pub type Traders = (
// RUSD
FixedRateOfFungible<RUsdPerSecond, ()>,
// Roc
FixedRateOfFungible<RocPerSecond, ()>,
// Everything else
UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>,
);

pub type Reserves = (NativeAsset, ReserveAssetsFrom<RockmineLocation>);

Expand All @@ -256,7 +277,7 @@ impl xcm_executor::Config for XcmConfig {
RuntimeCall,
MaxInstructions,
>;
type Trader = UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>;
type Trader = Traders;
type ResponseHandler = PolkadotXcm;
type AssetTrap = TrappistDropAssets<
AssetId,
Expand Down Expand Up @@ -293,6 +314,7 @@ impl pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
/* type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>; */
type Weigher = WeightInfoBounds<
crate::weights::xcm::TrappistXcmWeight<RuntimeCall>,
RuntimeCall,
Expand Down
Loading