git.delta.rocks / unique-network / refs/commits / 25b276d53c18

difftreelog

fix(xcm) get rid of xcm warns, fix quartz CurrencyIdConvert

Daniel Shiposha2022-09-06parent: #ecb82c0.patch.diff
in: master

19 files changed

modifiedpallets/foreing-assets/src/lib.rsdiffbeforeafterboth
5454
55// NOTE:v1::MultiLocation is used in storages, we would need to do migration if upgrade the55// NOTE:v1::MultiLocation is used in storages, we would need to do migration if upgrade the
56// MultiLocation in the future.56// MultiLocation in the future.
57use xcm::opaque::latest::{prelude::XcmError, MultiAsset};57use xcm::opaque::latest::prelude::XcmError;
58use xcm::{v1::MultiLocation, VersionedMultiLocation};58use xcm::{v1::MultiLocation, VersionedMultiLocation};
59use xcm_executor::{traits::WeightTrader, Assets};59use xcm_executor::{traits::WeightTrader, Assets};
6060
445 }445 }
446}446}
447447
448use sp_runtime::SaturatedConversion;
449use sp_runtime::traits::Saturating;
450pub use frame_support::{448pub use frame_support::{
451 traits::{449 traits::{
452 fungibles::{Balanced, CreditOf},450 fungibles::{Balanced, CreditOf},
456 weights::{WeightToFeePolynomial, WeightToFee},454 weights::{WeightToFeePolynomial, WeightToFee},
457};455};
458
459use xcm::latest::{Fungibility::Fungible as XcmFungible};
460456
461pub struct FreeForAll<457pub struct FreeForAll<
462 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,458 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
deletedruntime/common/config/xcm.rsdiffbeforeafterboth

no changes

addedruntime/common/config/xcm/foreignassets.rsdiffbeforeafterboth

no changes

addedruntime/common/config/xcm/mod.rsdiffbeforeafterboth

no changes

addedruntime/common/config/xcm/nativeassets.rsdiffbeforeafterboth

no changes

modifiedruntime/common/tests/mod.rsdiffbeforeafterboth

no syntactic changes

modifiedruntime/common/tests/xcm.rsdiffbeforeafterboth
92 let fun = Fungibility::Fungible(42);84 let fun = Fungibility::Fungible(42);
93 let multiasset = MultiAsset {85 let multiasset = MultiAsset { id, fun };
94 id,
95 fun,
96 };
9786
98 multiasset.into()87 multiasset.into()
143 self_para_id: u32,132 self_para_id: u32,
144) -> Result<(), String>133) -> Result<(), String>
145where134where
146 B: ShouldExecute135 B: ShouldExecute,
147{136{
148 const UNKNOWN_PARACHAIN_ID: u32 = 4057;137 const UNKNOWN_PARACHAIN_ID: u32 = 4057;
149138
modifiedruntime/opal/src/tests/logcapture.rsdiffbeforeafterboth

no syntactic changes

modifiedruntime/opal/src/tests/mod.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17mod xcm;17mod logcapture;
18mod logcapture;18mod xcm;
1919
modifiedruntime/opal/src/tests/xcm.rsdiffbeforeafterboth
17use logtest::Logger;17use logtest::Logger;
18use crate::{18use crate::{runtime_common::tests::xcm::*, xcm_config::Barrier};
19 runtime_common::tests::xcm::*,
20 xcm_config::Barrier,
21};
2219
23const OPAL_PARA_ID: u32 = 2095; // Same as Quartz20const OPAL_PARA_ID: u32 = 2095; // Same as Quartz
modifiedruntime/opal/src/xcm_config.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17use cumulus_pallet_xcm;
18use frame_support::{17use frame_support::{
19 {match_types, parameter_types, weights::Weight},18 {match_types, parameter_types, weights::Weight},
20 pallet_prelude::Get,19 pallet_prelude::Get,
21 traits::{Contains, Everything, fungibles},20 traits::{Contains, Everything},
22};21};
23use frame_system::EnsureRoot;
24use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};22use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
25use pallet_xcm::XcmPassthrough;
26use polkadot_parachain::primitives::Sibling;
27use sp_runtime::traits::{AccountIdConversion, CheckedConversion, Convert, Zero};23use sp_runtime::traits::{AccountIdConversion, Convert};
28use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};24use sp_std::{vec, vec::Vec};
29use xcm::{25use xcm::{
30 latest::{MultiAsset, Xcm},26 latest::Xcm,
31 prelude::{Concrete, Fungible as XcmFungible},
32 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},27 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
33};28};
34use xcm_builder::{29use xcm_builder::{
35 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin,30 AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter,
36 FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentAsSuperuser, ParentIsPreset,
37 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
38 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,31 TakeWeightCredit,
39 ConvertedConcreteAssetId,
40};32};
41use xcm_executor::{33use xcm_executor::{XcmExecutor, traits::ShouldExecute};
42 {Config, XcmExecutor},
43 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible, ShouldExecute},
44};
4534
46use up_common::{35use up_common::types::{AccountId, Balance};
47 constants::{MAXIMUM_BLOCK_WEIGHT, UNIQUE},
48 types::{AccountId, Balance},
49};
50
51use crate::{
52 Balances, Call, DmpQueue, Event, ForeingAssets, Origin, ParachainInfo, ParachainSystem,
53 PolkadotXcm, Runtime, XcmpQueue,
54};
55use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};36use crate::{
56use crate::runtime_common::config::pallets::TreasuryAccountId;37 Call, Event, ParachainInfo, Runtime,
57use crate::runtime_common::config::xcm::*;38 runtime_common::config::{
58use crate::*;39 substrate::{TreasuryModuleId, MaxLocks, MaxReserves},
40 pallets::TreasuryAccountId,
41 xcm::*,
42 },
43};
5944
60use pallet_foreing_assets::{45use pallet_foreing_assets::{
61 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency, FreeForAll,46 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
62 TryAsForeing, ForeignAssetId,
63};47};
6448
65// Signed version of balance49// Signed version of balance
66pub type Amount = i128;50pub type Amount = i128;
67
68parameter_types! {
69 pub const RelayLocation: MultiLocation = MultiLocation::parent();
70 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
71 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
72 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
73 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
74}
75
76/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
77/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
78/// biases the kind of local `Origin` it will become.
79pub type XcmOriginToTransactDispatchOrigin = (
80 // Sovereign account converter; this attempts to derive an `AccountId` from the origin location
81 // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
82 // foreign chains who want to have a local sovereign account on this chain which they control.
83 SovereignSignedViaLocation<LocationToAccountId, Origin>,
84 // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
85 // recognised.
86 RelayChainAsNative<RelayOrigin, Origin>,
87 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
88 // recognised.
89 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,
90 // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
91 // transaction from the Root origin.
92 ParentAsSuperuser<Origin>,
93 // Native signed account converter; this just converts an `AccountId32` origin into a normal
94 // `Origin::Signed` origin of the same 32-byte value.
95 SignedAccountId32AsNative<RelayNetwork, Origin>,
96 // Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
97 XcmPassthrough<Origin>,
98);
99
100parameter_types! {
101 // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.
102 pub UnitWeightCost: Weight = 1_000_000;
103 // 1200 UNIQUEs buy 1 second of weight.
104 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);
105 pub const MaxInstructions: u32 = 100;
106 pub const MaxAuthorities: u32 = 100_000;
107}
10851
109match_types! {52match_types! {
110 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {53 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {
123 fn should_execute<Call>(66 fn should_execute<Call>(
124 _origin: &MultiLocation,67 _origin: &MultiLocation,
125 _message: &mut Xcm<Call>,68 _message: &mut Xcm<Call>,
126 max_weight: Weight,69 _max_weight: Weight,
127 weight_credit: &mut Weight,70 _weight_credit: &mut Weight,
128 ) -> Result<(), ()> {71 ) -> Result<(), ()> {
129 Ok(())72 Ok(())
130 }73 }
138 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,81 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
139 // ^^^ Parent & its unit plurality gets free execution82 // ^^^ Parent & its unit plurality gets free execution
140 AllowAllDebug,83 AllowAllDebug,
141 )84 ),
142>;85>;
14386
144pub struct AllAsset;
145impl FilterAssetLocation for AllAsset {
146 fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
147 true
148 }
149}
150
151pub struct CurrencyIdConvert;
152impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
153 fn convert(id: AssetIds) -> Option<MultiLocation> {
154 match id {
155 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
156 1,
157 X1(Parachain(ParachainInfo::get().into())),
158 )),
159 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),
160 AssetIds::ForeignAssetId(foreign_asset_id) => {
161 XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)
162 }
163 }
164 }
165}
166impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {87impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
167 fn convert(location: MultiLocation) -> Option<CurrencyId> {88 fn convert(location: MultiLocation) -> Option<CurrencyId> {
168 if location == MultiLocation::here()89 if location == MultiLocation::here()
185 }106 }
186}107}
187108
109impl orml_tokens::Config for Runtime {
110 type Event = Event;
111 type Balance = Balance;
112 type Amount = Amount;
113 type CurrencyId = CurrencyId;
188pub fn get_all_module_accounts() -> Vec<AccountId> {114 type WeightInfo = ();
115 type ExistentialDeposits = ExistentialDeposits;
116 type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;
117 type MaxLocks = MaxLocks;
118 type MaxReserves = MaxReserves;
119 // TODO: Add all module accounts
120 type DustRemovalWhitelist = DustRemovalWhitelist;
121 /// The id type for named reserves.
122 type ReserveIdentifier = ();
123 type OnNewTokenAccount = ();
124 type OnKilledTokenAccount = ();
125}
126
127impl orml_xtokens::Config for Runtime {
128 type Event = Event;
129 type Balance = Balance;
130 type CurrencyId = CurrencyId;
131 type CurrencyIdConvert = CurrencyIdConvert;
132 type AccountIdToMultiLocation = AccountIdToMultiLocation;
133 type SelfLocation = SelfLocation;
134 type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
135 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
136 type BaseXcmWeight = BaseXcmWeight;
137 type LocationInverter = LocationInverter<Ancestry>;
138 type MaxAssetsForTransfer = MaxAssetsForTransfer;
139 type MinXcmFee = ParachainMinFee;
140 type MultiLocationsFilter = Everything;
141 type ReserveProvider = AbsoluteReserveProvider;
142}
143
189 vec![TreasuryModuleId::get().into_account_truncating()]144parameter_type_with_key! {
190}145 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
146 match currency_id {
147 CurrencyId::NativeAssetId(symbol) => match symbol {
148 NativeCurrency::Here => 0,
149 NativeCurrency::Parent=> 0,
150 },
151 _ => 100_000
152 }
153 };
154}
191155
192pub struct DustRemovalWhitelist;156pub struct DustRemovalWhitelist;
193impl Contains<AccountId> for DustRemovalWhitelist {157impl Contains<AccountId> for DustRemovalWhitelist {
196 }160 }
197}161}
198162
199parameter_type_with_key! {
200 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {163pub struct CurrencyIdConvert;
201 match currency_id {
202 CurrencyId::NativeAssetId(symbol) => match symbol {
203 NativeCurrency::Here => 0,
204 NativeCurrency::Parent=> 0,
205 },
206 _ => 100_000
207 }
208 };
209}
210
211impl orml_tokens::Config for Runtime {164impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
212 type Event = Event;165 fn convert(id: AssetIds) -> Option<MultiLocation> {
213 type Balance = Balance;166 match id {
214 type Amount = Amount;167 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
215 type CurrencyId = CurrencyId;168 1,
216 type WeightInfo = ();
217 type ExistentialDeposits = ExistentialDeposits;
218 type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccountId>;169 X1(Parachain(ParachainInfo::get().into())),
219 type MaxLocks = MaxLocks;170 )),
220 type MaxReserves = MaxReserves;
221 // TODO: Add all module accounts
222 type DustRemovalWhitelist = DustRemovalWhitelist;
223 /// The id type for named reserves.
224 type ReserveIdentifier = ();171 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),
225 type OnNewTokenAccount = ();172 AssetIds::ForeignAssetId(foreign_asset_id) => {
226 type OnKilledTokenAccount = ();173 XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)
174 }
175 }
176 }
227}177}
228178
229parameter_types! {179parameter_types! {
230 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this180 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
231 pub const MaxAssetsForTransfer: usize = 2;181 pub const MaxAssetsForTransfer: usize = 2;
182
183 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
184 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
232}185}
233186
234parameter_type_with_key! {187parameter_type_with_key! {
237 };190 };
238}191}
239192
193pub fn get_all_module_accounts() -> Vec<AccountId> {
194 vec![TreasuryModuleId::get().into_account_truncating()]
195}
240pub struct AccountIdToMultiLocation;196pub struct AccountIdToMultiLocation;
241impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {197impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
242 fn convert(account: AccountId) -> MultiLocation {198 fn convert(account: AccountId) -> MultiLocation {
248 }204 }
249}205}
250
251impl orml_xtokens::Config for Runtime {
252 type Event = Event;
253 type Balance = Balance;
254 type CurrencyId = CurrencyId;
255 type CurrencyIdConvert = CurrencyIdConvert;
256 type AccountIdToMultiLocation = AccountIdToMultiLocation;
257 type SelfLocation = SelfLocation;
258 type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
259 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
260 type BaseXcmWeight = BaseXcmWeight;
261 type LocationInverter = LocationInverter<Ancestry>;
262 type MaxAssetsForTransfer = MaxAssetsForTransfer;
263 type MinXcmFee = ParachainMinFee;
264 type MultiLocationsFilter = Everything;
265 type ReserveProvider = AbsoluteReserveProvider;
266}
267206
modifiedruntime/quartz/src/tests/logcapture.rsdiffbeforeafterboth

no syntactic changes

modifiedruntime/quartz/src/tests/mod.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17mod xcm;17mod logcapture;
18mod logcapture;18mod xcm;
1919
modifiedruntime/quartz/src/tests/xcm.rsdiffbeforeafterboth
17use logtest::Logger;17use logtest::Logger;
18use crate::{18use crate::{runtime_common::tests::xcm::*, xcm_config::Barrier};
19 runtime_common::tests::xcm::*,
20 xcm_config::Barrier,
21};
2219
23const QUARTZ_PARA_ID: u32 = 2095;20const QUARTZ_PARA_ID: u32 = 2095;
modifiedruntime/quartz/src/xcm_config.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17use cumulus_pallet_xcm;
18use frame_support::{17use frame_support::{
19 {match_types, parameter_types, weights::Weight},18 {match_types, parameter_types, weights::Weight},
20 pallet_prelude::Get,19 pallet_prelude::Get,
21 traits::{Contains, Everything, fungibles},20 traits::{Contains, Everything},
22};21};
23use frame_system::EnsureRoot;
24use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};22use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
25use pallet_xcm::XcmPassthrough;
26use polkadot_parachain::primitives::Sibling;
27use sp_runtime::traits::{AccountIdConversion, CheckedConversion, Convert, Zero};23use sp_runtime::traits::{AccountIdConversion, Convert};
28use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};24use sp_std::{vec, vec::Vec};
29use xcm::{25use xcm::{
30 latest::{MultiAsset, Xcm},26 latest::Xcm,
31 prelude::{Concrete, Fungible as XcmFungible},
32 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},27 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
33};28};
34use xcm_builder::{29use xcm_builder::{
35 AllowKnownQueryResponses, AllowSubscriptionsFrom,30 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
36 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,31 AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, TakeWeightCredit,
37 EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentAsSuperuser,
38 ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
39 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
40 ConvertedConcreteAssetId,
41};32};
42use xcm_executor::{33use xcm_executor::XcmExecutor;
43 {Config, XcmExecutor},
44 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible},
45};
4634
47use up_common::{35use up_common::types::{AccountId, Balance};
48 constants::{MAXIMUM_BLOCK_WEIGHT, UNIQUE},
49 types::{AccountId, Balance},
50};
51use pallet_foreing_assets::{36use pallet_foreing_assets::{AssetIds, CurrencyId, NativeCurrency};
52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
53 FreeForAll, TryAsForeing, ForeignAssetId,
54};
55use crate::{37use crate::{Call, Event, ParachainInfo, PolkadotXcm, Runtime};
56 Balances, Call, DmpQueue, Event, Origin, ParachainInfo,
57 ParachainSystem, PolkadotXcm, Runtime, XcmpQueue,
58};
59use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};38use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};
60use crate::runtime_common::config::pallets::TreasuryAccountId;39use crate::runtime_common::config::pallets::TreasuryAccountId;
61use crate::runtime_common::config::xcm::*;40use crate::runtime_common::config::xcm::*;
62use crate::*;
63use xcm::opaque::latest::prelude::{ DepositReserveAsset, DepositAsset, TransferAsset, TransferReserveAsset };41use xcm::opaque::latest::prelude::{DepositReserveAsset, TransferReserveAsset};
6442
65// Signed version of balance43// Signed version of balance
66pub type Amount = i128;44pub type Amount = i128;
76 };54 };
77}55}
56
57pub type Barrier = DenyThenTry<
58 (DenyTransact, DenyExchangeWithUnknownLocation),
59 (
60 TakeWeightCredit,
61 AllowTopLevelPaidExecutionFrom<Everything>,
62 // Parent and its exec plurality get free execution
63 AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
64 // Expected responses are OK.
65 AllowKnownQueryResponses<PolkadotXcm>,
66 // Subscriptions for version tracking are OK.
67 AllowSubscriptionsFrom<ParentOrSiblings>,
68 ),
69>;
7870
79pub fn get_allowed_locations() -> Vec<MultiLocation> {71pub fn get_allowed_locations() -> Vec<MultiLocation> {
80 vec![72 vec![
102 // Check if deposit or transfer belongs to allowed parachains105 // Check if deposit or transfer belongs to allowed parachains
103 let mut allowed = get_allowed_locations().contains(origin);106 let mut allowed = get_allowed_locations().contains(origin);
104107
105 message.0.iter().for_each(|inst| {108 message.0.iter().for_each(|inst| match inst {
106 match inst {
107 DepositReserveAsset { dest: dst, .. } => { allowed |= get_allowed_locations().contains(dst); }109 DepositReserveAsset { dest: dst, .. } => {
110 allowed |= get_allowed_locations().contains(dst);
111 }
108 TransferReserveAsset { dest: dst, .. } => { allowed |= get_allowed_locations().contains(dst); }112 TransferReserveAsset { dest: dst, .. } => {
113 allowed |= get_allowed_locations().contains(dst);
114 }
109 _ => {}115 _ => {}
110 }116 });
111 });
112117
113 if allowed {118 if allowed {
114 return Ok(());119 return Ok(());
123 }128 }
124}129}
125
126pub type Barrier = DenyThenTry<
127 (
128 DenyTransact,
129 DenyExchangeWithUnknownLocation,
130 ),
131 (
132 TakeWeightCredit,
133 AllowTopLevelPaidExecutionFrom<Everything>,
134 // Parent and its exec plurality get free execution
135 AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
136 // Expected responses are OK.
137 AllowKnownQueryResponses<PolkadotXcm>,
138 // Subscriptions for version tracking are OK.
139 AllowSubscriptionsFrom<ParentOrSiblings>,
140 ),
141>;
142130
143impl orml_tokens::Config for Runtime {131impl orml_tokens::Config for Runtime {
144 type Event = Event;132 type Event = Event;
202 1,190 1,
203 X1(Parachain(ParachainInfo::get().into())),191 X1(Parachain(ParachainInfo::get().into())),
204 )),192 )),
205 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),
206 AssetIds::ForeignAssetId(_) => None,193 _ => None,
207 }194 }
208 }195 }
209}196}
210197
211parameter_types! {198parameter_types! {
212 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this199 pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
213 pub const MaxAssetsForTransfer: usize = 2;200 pub const MaxAssetsForTransfer: usize = 2;
214}201
215
216parameter_types! {
217 pub const RelayLocation: MultiLocation = MultiLocation::parent();
218 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
219 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
220 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();202 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
221 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));203 pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
222}204}
223205
224parameter_type_with_key! {206parameter_type_with_key! {
225 pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {207 pub ParachainMinFee: |_location: MultiLocation| -> Option<u128> {
modifiedruntime/unique/src/tests/logcapture.rsdiffbeforeafterboth

no syntactic changes

modifiedruntime/unique/src/tests/mod.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17mod xcm;17mod logcapture;
18mod logcapture;18mod xcm;
1919
modifiedruntime/unique/src/tests/xcm.rsdiffbeforeafterboth
17use logtest::Logger;17use logtest::Logger;
18use crate::{18use crate::{runtime_common::tests::xcm::*, xcm_config::Barrier};
19 runtime_common::tests::xcm::*,
20 xcm_config::Barrier,
21};
2219
23const UNIQUE_PARA_ID: u32 = 2037;20const UNIQUE_PARA_ID: u32 = 2037;
modifiedruntime/unique/src/xcm_config.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17use cumulus_pallet_xcm;
18use frame_support::{17use frame_support::{
19 {match_types, parameter_types, weights::Weight},18 {match_types, parameter_types, weights::Weight},
20 pallet_prelude::Get,19 pallet_prelude::Get,
21 traits::{Contains, Everything, fungibles},20 traits::{Contains, Everything},
22};21};
23use frame_system::EnsureRoot;
24use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};22use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
25use pallet_xcm::XcmPassthrough;
26use polkadot_parachain::primitives::Sibling;
27use sp_runtime::traits::{AccountIdConversion, CheckedConversion, Convert, Zero};23use sp_runtime::traits::{AccountIdConversion, Convert};
28use sp_std::{borrow::Borrow, marker::PhantomData, vec, vec::Vec};24use sp_std::{vec, vec::Vec};
29use xcm::{25use xcm::{
30 latest::{MultiAsset, Xcm},26 latest::Xcm,
31 prelude::{Concrete, Fungible as XcmFungible},
32 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},27 v1::{BodyId, Junction::*, Junctions::*, MultiLocation, NetworkId},
33};28};
34use xcm_builder::{29use xcm_builder::{
35 AllowKnownQueryResponses, AllowSubscriptionsFrom,30 AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
36 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,31 AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, TakeWeightCredit,
37 EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentAsSuperuser,
38 ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
39 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
40 ConvertedConcreteAssetId,
41};32};
42use xcm_executor::{33use xcm_executor::XcmExecutor;
43 {Config, XcmExecutor},
44 traits::{Convert as ConvertXcm, FilterAssetLocation, JustTry, MatchesFungible},
45};
4634
47use up_common::{35use up_common::types::{AccountId, Balance};
48 constants::{MAXIMUM_BLOCK_WEIGHT, UNIQUE},
49 types::{AccountId, Balance},
50};
51use pallet_foreing_assets::{36use pallet_foreing_assets::{AssetIds, CurrencyId, NativeCurrency};
52 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, CurrencyId, NativeCurrency,
53 FreeForAll, TryAsForeing, ForeignAssetId,
54};
55use crate::{37use crate::{Call, Event, ParachainInfo, PolkadotXcm, Runtime};
56 Balances, Call, DmpQueue, Event, Origin, ParachainInfo,
57 ParachainSystem, PolkadotXcm, Runtime, XcmpQueue,
58};
59use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};38use crate::runtime_common::config::substrate::{TreasuryModuleId, MaxLocks, MaxReserves};
60use crate::runtime_common::config::pallets::TreasuryAccountId;39use crate::runtime_common::config::pallets::TreasuryAccountId;
61use crate::runtime_common::config::xcm::*;40use crate::runtime_common::config::xcm::*;
62use crate::*;
63use xcm::opaque::latest::prelude::{ DepositReserveAsset, DepositAsset, TransferAsset, TransferReserveAsset };41use xcm::opaque::latest::prelude::{DepositReserveAsset, TransferReserveAsset};
6442
65// Signed version of balance43// Signed version of balance
66pub type Amount = i128;44pub type Amount = i128;
6745
46match_types! {
47 pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
48 MultiLocation { parents: 1, interior: Here } |
49 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
50 };
51 pub type ParentOrSiblings: impl Contains<MultiLocation> = {
52 MultiLocation { parents: 1, interior: Here } |
53 MultiLocation { parents: 1, interior: X1(_) }
54 };
55}
6856
69pub type Barrier = DenyThenTry<57pub type Barrier = DenyThenTry<
70 (58 (DenyTransact, DenyExchangeWithUnknownLocation),
71 DenyTransact,
72 DenyExchangeWithUnknownLocation,
73 ),
74 (59 (
75 TakeWeightCredit,60 TakeWeightCredit,
109 // Check if deposit or transfer belongs to allowed parachains105 // Check if deposit or transfer belongs to allowed parachains
110 let mut allowed = get_allowed_locations().contains(origin);106 let mut allowed = get_allowed_locations().contains(origin);
111107
112 message.0.iter().for_each(|inst| {108 message.0.iter().for_each(|inst| match inst {
113 match inst {
114 DepositReserveAsset { dest: dst, .. } => { allowed |= get_allowed_locations().contains(dst); }109 DepositReserveAsset { dest: dst, .. } => {
110 allowed |= get_allowed_locations().contains(dst);
111 }
115 TransferReserveAsset { dest: dst, .. } => { allowed |= get_allowed_locations().contains(dst); }112 TransferReserveAsset { dest: dst, .. } => {
113 allowed |= get_allowed_locations().contains(dst);
114 }
116 _ => {}115 _ => {}
117 }116 });
118 });
119117
120 if allowed {118 if allowed {
121 return Ok(());119 return Ok(());
131}129}
132
133
134match_types! {
135 pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
136 MultiLocation { parents: 1, interior: Here } |
137 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
138 };
139 pub type ParentOrSiblings: impl Contains<MultiLocation> = {
140 MultiLocation { parents: 1, interior: Here } |
141 MultiLocation { parents: 1, interior: X1(_) }
142 };
143}
144
145pub fn get_all_module_accounts() -> Vec<AccountId> {
146 vec![TreasuryModuleId::get().into_account_truncating()]
147}
148
149pub struct DustRemovalWhitelist;
150impl Contains<AccountId> for DustRemovalWhitelist {
151 fn contains(a: &AccountId) -> bool {
152 get_all_module_accounts().contains(a)
153 }
154}
155
156parameter_type_with_key! {
157 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
158 match currency_id {
159 CurrencyId::NativeAssetId(symbol) => match symbol {
160 NativeCurrency::Here => 0,
161 NativeCurrency::Parent=> 0,
162 },
163 _ => 100_000
164 }
165 };
166}
167130
168impl orml_tokens::Config for Runtime {131impl orml_tokens::Config for Runtime {
169 type Event = Event;132 type Event = Event;
200 type ReserveProvider = AbsoluteReserveProvider;163 type ReserveProvider = AbsoluteReserveProvider;
201}164}
165
166parameter_type_with_key! {
167 pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
168 match currency_id {
169 CurrencyId::NativeAssetId(symbol) => match symbol {
170 NativeCurrency::Here => 0,
171 NativeCurrency::Parent=> 0,
172 },
173 _ => 100_000
174 }
175 };
176}
177
178pub struct DustRemovalWhitelist;
179impl Contains<AccountId> for DustRemovalWhitelist {
180 fn contains(a: &AccountId) -> bool {
181 get_all_module_accounts().contains(a)
182 }
183}
202184
203pub struct CurrencyIdConvert;185pub struct CurrencyIdConvert;
204impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {186impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
227 };209 };
228}210}
229211
212pub fn get_all_module_accounts() -> Vec<AccountId> {
213 vec![TreasuryModuleId::get().into_account_truncating()]
214}
230215
231pub struct AccountIdToMultiLocation;216pub struct AccountIdToMultiLocation;
232impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {217impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {