Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
XCM v3: ExchangeAsset and Remote-locking (#4945)
Browse files Browse the repository at this point in the history
* Asset Exchange and Locks

* Make sure XCM typers impl MaxEncodedLen

* Basic implementation for locks

* Bump Substrate

* Missing files

* Use new API

* Introduce  instruction

* Big refactor

* Docs

* Remove deprecated struct

* Remove deprecated struct

* Repot XCM builder tests

* ExchangeAsset test

* Exchange tests

* Locking tests

* Locking tests

* Fixes and tests

* Fixes

* Formatting

* Spelling
  • Loading branch information
gavofyork authored Feb 20, 2022
1 parent 841bdb9 commit 768535f
Show file tree
Hide file tree
Showing 67 changed files with 4,784 additions and 2,698 deletions.
327 changes: 164 additions & 163 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions bridges/bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ impl Config for XcmConfig {
type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, ()>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
}
Expand Down
7 changes: 7 additions & 0 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ impl xcm_executor::Config for XcmConfig {
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
Expand Down Expand Up @@ -195,4 +197,9 @@ impl pallet_xcm::Config for Runtime {
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = SovereignAccountOf;
type MaxLockers = frame_support::traits::ConstU32<8>;
}
7 changes: 7 additions & 0 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl xcm_executor::Config for XcmConfig {
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
Expand Down Expand Up @@ -187,4 +189,9 @@ impl pallet_xcm::Config for Runtime {
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = SovereignAccountOf;
type MaxLockers = frame_support::traits::ConstU32<8>;
}
13 changes: 10 additions & 3 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ parameter_types! {
pub CheckAccount: AccountId = XcmPallet::check_account();
}

pub type SovereignAccountOf =
pub type LocationConverter =
(ChildParachainConvertsVia<ParaId, AccountId>, AccountId32Aliases<ThisNetwork, AccountId>);

pub type LocalAssetTransactor = XcmCurrencyAdapter<
Expand All @@ -52,15 +52,15 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter<
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<TokenLocation>,
// We can convert the MultiLocations with our converter above:
SovereignAccountOf,
LocationConverter,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// It's a native asset so we keep track of the teleports to maintain total issuance.
CheckAccount,
>;

type LocalOriginConverter = (
SovereignSignedViaLocation<SovereignAccountOf, Origin>,
SovereignSignedViaLocation<LocationConverter, Origin>,
ChildParachainAsNative<parachains_origin::Origin, Origin>,
SignedAccountId32AsNative<ThisNetwork, Origin>,
ChildSystemParachainAsSuperuser<ParaId, Origin>,
Expand Down Expand Up @@ -135,6 +135,8 @@ impl xcm_executor::Config for XcmConfig {
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
Expand Down Expand Up @@ -175,4 +177,9 @@ impl pallet_xcm::Config for Runtime {
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = IsConcrete<TokenLocation>;
type TrustedLockers = ();
type SovereignAccountOf = LocationConverter;
type MaxLockers = frame_support::traits::ConstU32<8>;
}
5 changes: 5 additions & 0 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ impl pallet_xcm::Config for Runtime {
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = frame_support::traits::ConstU32<8>;
}

impl parachains_hrmp::Config for Runtime {
Expand Down
2 changes: 2 additions & 0 deletions runtime/test-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ impl xcm_executor::Config for XcmConfig {
type Trader = DummyWeightTrader;
type ResponseHandler = super::Xcm;
type AssetTrap = super::Xcm;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = super::Xcm;
type SubscriptionService = super::Xcm;
type PalletInstancesInfo = ();
Expand Down
21 changes: 18 additions & 3 deletions runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<Call> XcmWeightInfo<Call> for WestendXcmWeight<Call> {
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight {
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
Weight::MAX // todo fix
}
fn initiate_reserve_withdraw(
Expand Down Expand Up @@ -218,9 +218,24 @@ impl<Call> XcmWeightInfo<Call> for WestendXcmWeight<Call> {
XcmGeneric::<Runtime>::clear_transact_status()
}
fn universal_origin(_: &Junction) -> Weight {
10_000_000_000
Weight::MAX // todo fix
}
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
10_000_000_000
Weight::MAX // todo fix
}
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
Weight::MAX // todo fix
}
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
Weight::MAX // todo fix
}
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
Weight::MAX // todo fix
}
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
Weight::MAX // todo fix
}
fn set_fees_mode(_: &bool) -> Weight {
Weight::MAX // todo fix
}
}
7 changes: 7 additions & 0 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ impl xcm_executor::Config for XcmConfig {
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
Expand Down Expand Up @@ -147,4 +149,9 @@ impl pallet_xcm::Config for Runtime {
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = IsConcrete<TokenLocation>;
type TrustedLockers = ();
type SovereignAccountOf = LocationConverter;
type MaxLockers = frame_support::traits::ConstU32<8>;
}
2 changes: 1 addition & 1 deletion xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
impl-trait-for-tuples = "0.2.2"
parity-scale-codec = { version = "2.3.1", default-features = false, features = [ "derive" ] }
parity-scale-codec = { version = "2.3.1", default-features = false, features = [ "derive", "max-encoded-len" ] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
derivative = {version = "2.2.0", default-features = false, features = [ "use_core" ] }
log = { version = "0.4.14", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions xcm/pallet-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ frame-support = { default-features = false, branch = "master", git = "https://gi
frame-system = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" }
sp-runtime = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" }
sp-std = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" }
sp-io = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" }
xcm-executor = { path = "../xcm-executor", default-features = false, features = ["runtime-benchmarks"] }
frame-benchmarking = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" }
xcm = { path = "..", default-features = false, features = ["runtime-benchmarks"] }
Expand Down
12 changes: 6 additions & 6 deletions xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ benchmarks_instance_pallet! {
assert!(!T::TransactAsset::balance(&sender_account).is_zero());

let mut executor = new_executor::<T>(sender_location);
executor.holding = worst_case_holding.into();
executor.set_holding(worst_case_holding.into());
let instruction = Instruction::<XcmCallOf<T>>::WithdrawAsset(vec![asset.clone()].into());
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
// check one of the assets of origin.
assert!(T::TransactAsset::balance(&sender_account).is_zero());
assert!(executor.holding.ensure_contains(&vec![asset].into()).is_ok());
assert!(executor.holding().ensure_contains(&vec![asset].into()).is_ok());
}

transfer_asset {
Expand Down Expand Up @@ -135,7 +135,7 @@ benchmarks_instance_pallet! {
)
})?;
} verify {
assert!(executor.holding.ensure_contains(&assets).is_ok());
assert!(executor.holding().ensure_contains(&assets).is_ok());
}

deposit_asset {
Expand All @@ -151,7 +151,7 @@ benchmarks_instance_pallet! {
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding.into();
executor.set_holding(holding.into());
let instruction = Instruction::<XcmCallOf<T>>::DepositAsset {
assets: asset.into(),
beneficiary: dest_location,
Expand All @@ -177,7 +177,7 @@ benchmarks_instance_pallet! {
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding.into();
executor.set_holding(holding.into());
let instruction = Instruction::<XcmCallOf<T>>::DepositReserveAsset {
assets: asset.into(),
dest: dest_location,
Expand All @@ -202,7 +202,7 @@ benchmarks_instance_pallet! {
assert!(T::CheckedAccount::get().map_or(true, |c| T::TransactAsset::balance(&c).is_zero()));

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding.into();
executor.set_holding(holding.into());
let instruction = Instruction::<XcmCallOf<T>>::InitiateTeleport {
assets: asset.into(),
dest: T::valid_destination()?,
Expand Down
2 changes: 2 additions & 0 deletions xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl xcm_executor::Config for XcmConfig {
type Trader = xcm_builder::FixedRateOfFungible<WeightPrice, ()>;
type ResponseHandler = DevNull;
type AssetTrap = ();
type AssetLocker = ();
type AssetExchanger = ();
type AssetClaims = ();
type SubscriptionService = ();
type PalletInstancesInfo = AllPalletsWithSystem;
Expand Down
Loading

0 comments on commit 768535f

Please sign in to comment.