Skip to content

Commit ac37316

Browse files
authored
Support DOT reseve on AH and Snowfork bridged assets (#2858)
* Support DOT reseve on AH and Snowfork bridged assets * allow transfer assets from pallet xcm * indent
1 parent c9d49d7 commit ac37316

File tree

6 files changed

+76
-15
lines changed

6 files changed

+76
-15
lines changed

runtime/acala/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ impl Contains<RuntimeCall> for BaseCallFilter {
226226
| pallet_xcm::Call::teleport_assets { .. }
227227
| pallet_xcm::Call::reserve_transfer_assets { .. }
228228
| pallet_xcm::Call::limited_reserve_transfer_assets { .. }
229-
| pallet_xcm::Call::limited_teleport_assets { .. }
230-
| pallet_xcm::Call::transfer_assets { .. }
231-
| pallet_xcm::Call::transfer_assets_using_type_and_then { .. } => {
229+
| pallet_xcm::Call::limited_teleport_assets { .. } => {
232230
return false;
233231
}
234232
// user xcm calls
235-
pallet_xcm::Call::claim_assets { .. } => {
233+
pallet_xcm::Call::claim_assets { .. }
234+
| pallet_xcm::Call::transfer_assets { .. }
235+
| pallet_xcm::Call::transfer_assets_using_type_and_then { .. } => {
236236
return true;
237237
}
238238
// xcm operations call

runtime/acala/src/xcm_config.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ use parity_scale_codec::{Decode, Encode};
4040
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
4141
use primitives::evm::is_system_contract;
4242
use runtime_common::{
43-
local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
43+
local_currency_location, native_currency_location, xcm_config::RelayLocationFilter,
44+
xcm_impl::IsBridgedConcreteAssetFrom, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
4445
EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RuntimeBlockWeights,
4546
};
4647
use sp_runtime::Perbill;
4748
use xcm::{prelude::*, v3::Weight as XcmWeight};
4849
use xcm_builder::{
49-
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
50+
Case, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
5051
};
5152

5253
parameter_types! {
@@ -94,8 +95,24 @@ parameter_types! {
9495
0
9596
);
9697
pub BaseRate: u128 = aca_per_second();
98+
99+
/// Location of Asset Hub
100+
pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
101+
pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
102+
RelayLocationFilter::get(),
103+
AssetHubLocation::get()
104+
);
97105
}
98106

107+
type Reserves = (
108+
// Assets bridged from different consensus systems held in reserve on Asset Hub.
109+
IsBridgedConcreteAssetFrom<AssetHubLocation>,
110+
// Relaychain (DOT) from Asset Hub
111+
Case<RelayChainNativeAssetFromAssetHub>,
112+
// Assets which the reserve is the same as the origin.
113+
MultiNativeAsset<AbsoluteReserveProvider>,
114+
);
115+
99116
pub type Trader = (
100117
FixedRateOfAsset<BaseRate, ToTreasury, BuyWeightRateOfTransactionFeePool<Runtime, CurrencyIdConvert>>,
101118
FixedRateOfFungible<AcaPerSecond, ToTreasury>,
@@ -115,7 +132,7 @@ impl xcm_executor::Config for XcmConfig {
115132
// How to withdraw and deposit an asset.
116133
type AssetTransactor = LocalAssetTransactor;
117134
type OriginConverter = XcmOriginToCallOrigin;
118-
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
135+
type IsReserve = Reserves;
119136
type IsTeleporter = runtime_common::xcm_config::TrustedTeleporters;
120137
type UniversalLocation = UniversalLocation;
121138
type Barrier = Barrier;

runtime/common/src/xcm_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ impl Convert<AccountId, Location> for AccountIdToLocation {
127127

128128
parameter_types! {
129129
pub const RelayLocation: Location = Location::parent();
130+
pub RelayLocationFilter: AssetFilter = Wild(AllOf {
131+
fun: WildFungible,
132+
id: xcm::prelude::AssetId(RelayLocation::get()),
133+
});
130134
}
131135

132136
// define assets that can be trusted to teleport by remotes

runtime/common/src/xcm_impl.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
//! Common xcm implementation
2020
21-
use frame_support::{traits::Get, weights::constants::WEIGHT_REF_TIME_PER_SECOND};
21+
use frame_support::{
22+
traits::{ContainsPair, Get},
23+
weights::constants::WEIGHT_REF_TIME_PER_SECOND,
24+
};
2225
use module_support::BuyWeightRate;
2326
use orml_traits::GetByKey;
2427
use parity_scale_codec::Encode;
@@ -295,6 +298,26 @@ where
295298
}
296299
}
297300

301+
/// Matches foreign assets from a given origin.
302+
/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1.
303+
pub struct IsBridgedConcreteAssetFrom<Origin>(PhantomData<Origin>);
304+
impl<Origin> ContainsPair<Asset, Location> for IsBridgedConcreteAssetFrom<Origin>
305+
where
306+
Origin: Get<Location>,
307+
{
308+
fn contains(asset: &Asset, origin: &Location) -> bool {
309+
let loc = Origin::get();
310+
&loc == origin
311+
&& matches!(
312+
asset,
313+
Asset {
314+
id: AssetId(Location { parents: 2, .. }),
315+
fun: Fungibility::Fungible(_)
316+
},
317+
)
318+
}
319+
}
320+
298321
#[cfg(test)]
299322
mod tests {
300323
use super::*;

runtime/karura/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ impl Contains<RuntimeCall> for BaseCallFilter {
233233
| pallet_xcm::Call::teleport_assets { .. }
234234
| pallet_xcm::Call::reserve_transfer_assets { .. }
235235
| pallet_xcm::Call::limited_reserve_transfer_assets { .. }
236-
| pallet_xcm::Call::limited_teleport_assets { .. }
237-
| pallet_xcm::Call::transfer_assets { .. }
238-
| pallet_xcm::Call::transfer_assets_using_type_and_then { .. } => {
236+
| pallet_xcm::Call::limited_teleport_assets { .. } => {
239237
return false;
240238
}
241239
// user xcm calls
242-
pallet_xcm::Call::claim_assets { .. } => {
240+
pallet_xcm::Call::claim_assets { .. }
241+
| pallet_xcm::Call::transfer_assets { .. }
242+
| pallet_xcm::Call::transfer_assets_using_type_and_then { .. } => {
243243
return true;
244244
}
245245
// xcm operations call

runtime/karura/src/xcm_config.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ use parity_scale_codec::{Decode, Encode};
3838
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
3939
use primitives::evm::is_system_contract;
4040
use runtime_common::{
41-
local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
41+
local_currency_location, native_currency_location, xcm_config::RelayLocationFilter,
42+
xcm_impl::IsBridgedConcreteAssetFrom, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
4243
EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RuntimeBlockWeights,
4344
};
4445
use sp_runtime::Perbill;
4546
use xcm::{prelude::*, v3::Weight as XcmWeight};
4647
use xcm_builder::{
47-
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
48+
Case, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
4849
};
4950

5051
parameter_types! {
@@ -136,8 +137,24 @@ parameter_types! {
136137
);
137138

138139
pub BaseRate: u128 = kar_per_second();
140+
141+
/// Location of Asset Hub
142+
pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
143+
pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
144+
RelayLocationFilter::get(),
145+
AssetHubLocation::get()
146+
);
139147
}
140148

149+
type Reserves = (
150+
// Assets bridged from different consensus systems held in reserve on Asset Hub.
151+
IsBridgedConcreteAssetFrom<AssetHubLocation>,
152+
// Relaychain (DOT) from Asset Hub
153+
Case<RelayChainNativeAssetFromAssetHub>,
154+
// Assets which the reserve is the same as the origin.
155+
MultiNativeAsset<AbsoluteReserveProvider>,
156+
);
157+
141158
pub type Trader = (
142159
FixedRateOfAsset<BaseRate, ToTreasury, BuyWeightRateOfTransactionFeePool<Runtime, CurrencyIdConvert>>,
143160
FixedRateOfFungible<KarPerSecond, ToTreasury>,
@@ -162,7 +179,7 @@ impl xcm_executor::Config for XcmConfig {
162179
// How to withdraw and deposit an asset.
163180
type AssetTransactor = LocalAssetTransactor;
164181
type OriginConverter = XcmOriginToCallOrigin;
165-
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
182+
type IsReserve = Reserves;
166183
type IsTeleporter = runtime_common::xcm_config::TrustedTeleporters;
167184
type UniversalLocation = UniversalLocation;
168185
type Barrier = Barrier;

0 commit comments

Comments
 (0)