difftreelog
fix IsReserve
in: master
6 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5692,6 +5692,7 @@
"orml-tokens",
"orml-traits",
"orml-vesting",
+ "orml-xcm-support",
"orml-xtokens",
"pallet-app-promotion",
"pallet-aura",
@@ -9142,6 +9143,7 @@
"orml-tokens",
"orml-traits",
"orml-vesting",
+ "orml-xcm-support",
"orml-xtokens",
"pallet-app-promotion",
"pallet-aura",
@@ -13418,6 +13420,7 @@
"orml-tokens",
"orml-traits",
"orml-vesting",
+ "orml-xcm-support",
"orml-xtokens",
"pallet-app-promotion",
"pallet-aura",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -181,6 +181,7 @@
orml-traits = { default-features = false , git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39" }
orml-vesting = { default-features = false , git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39" }
orml-xtokens = { default-features = false , git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39" }
+orml-xcm-support = { default-features = false , git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39" }
# Other
derivative = { version = "2.2.0", features = ["use_core"] }
runtime/common/config/xcm/foreignassets.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{traits::Get, parameter_types};18use sp_runtime::traits::Convert;19use xcm::latest::{prelude::*, MultiAsset, MultiLocation};20use xcm_builder::{FungiblesAdapter, NoChecking, ConvertedConcreteId};21use xcm_executor::traits::{TransactAsset, Convert as ConvertXcm, JustTry};22use pallet_foreign_assets::{23 AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, NativeCurrency, FreeForAll, TryAsForeign,24 ForeignAssetId, CurrencyId,25};26use sp_std::{borrow::Borrow, marker::PhantomData};27use orml_traits::location::AbsoluteReserveProvider;28use orml_xcm_support::MultiNativeAsset;29use crate::{Runtime, Balances, ParachainInfo, PolkadotXcm, ForeignAssets};3031use super::{LocationToAccountId, RelayLocation};3233use up_common::types::{AccountId, Balance};3435parameter_types! {36 pub CheckingAccount: AccountId = PolkadotXcm::check_account();37}3839pub struct AsInnerId<AssetId, ConvertAssetId>(PhantomData<(AssetId, ConvertAssetId)>);40impl<AssetId: Clone + PartialEq, ConvertAssetId: ConvertXcm<AssetId, AssetId>>41 ConvertXcm<MultiLocation, AssetId> for AsInnerId<AssetId, ConvertAssetId>42where43 AssetId: Borrow<AssetId>,44 AssetId: TryAsForeign<AssetId, ForeignAssetId>,45 AssetIds: Borrow<AssetId>,46{47 fn convert_ref(id: impl Borrow<MultiLocation>) -> Result<AssetId, ()> {48 let id = id.borrow();4950 log::trace!(51 target: "xcm::AsInnerId::Convert",52 "AsInnerId {:?}",53 id54 );5556 let parent = MultiLocation::parent();57 let here = MultiLocation::here();58 let self_location = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));5960 if *id == parent {61 return ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Parent));62 }6364 if *id == here || *id == self_location {65 return ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Here));66 }6768 match XcmForeignAssetIdMapping::<Runtime>::get_currency_id(id.clone()) {69 Some(AssetIds::ForeignAssetId(foreign_asset_id)) => {70 ConvertAssetId::convert_ref(AssetIds::ForeignAssetId(foreign_asset_id))71 }72 _ => Err(()),73 }74 }7576 fn reverse_ref(what: impl Borrow<AssetId>) -> Result<MultiLocation, ()> {77 log::trace!(78 target: "xcm::AsInnerId::Reverse",79 "AsInnerId",80 );8182 let asset_id = what.borrow();8384 let parent_id =85 ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Parent)).unwrap();86 let here_id =87 ConvertAssetId::convert_ref(AssetIds::NativeAssetId(NativeCurrency::Here)).unwrap();8889 if asset_id.clone() == parent_id {90 return Ok(MultiLocation::parent());91 }9293 if asset_id.clone() == here_id {94 return Ok(MultiLocation::new(95 1,96 X1(Parachain(ParachainInfo::get().into())),97 ));98 }99100 match <AssetId as TryAsForeign<AssetId, ForeignAssetId>>::try_as_foreign(asset_id.clone()) {101 Some(fid) => match XcmForeignAssetIdMapping::<Runtime>::get_multi_location(fid) {102 Some(location) => Ok(location),103 None => Err(()),104 },105 None => Err(()),106 }107 }108}109110/// Means for transacting assets besides the native currency on this chain.111pub type FungiblesTransactor = FungiblesAdapter<112 // Use this fungibles implementation:113 ForeignAssets,114 // Use this currency when it is a fungible asset matching the given location or name:115 ConvertedConcreteId<AssetIds, Balance, AsInnerId<AssetIds, JustTry>, JustTry>,116 // Convert an XCM MultiLocation into a local account id:117 LocationToAccountId,118 // Our chain's account ID type (we can't get away without mentioning it explicitly):119 AccountId,120 // No Checking for teleported assets since we disallow teleports at all.121 NoChecking,122 // The account to use for tracking teleports.123 CheckingAccount,124>;125126/// Means for transacting assets on this chain.127pub struct AssetTransactor;128impl TransactAsset for AssetTransactor {129 fn can_check_in(130 _origin: &MultiLocation,131 _what: &MultiAsset,132 _context: &XcmContext,133 ) -> XcmResult {134 Err(XcmError::Unimplemented)135 }136137 fn check_in(_origin: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {}138139 fn can_check_out(140 _dest: &MultiLocation,141 _what: &MultiAsset,142 _context: &XcmContext,143 ) -> XcmResult {144 Err(XcmError::Unimplemented)145 }146147 fn check_out(_dest: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {}148149 fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult {150 FungiblesTransactor::deposit_asset(what, who, context)151 }152153 fn withdraw_asset(154 what: &MultiAsset,155 who: &MultiLocation,156 maybe_context: Option<&XcmContext>,157 ) -> Result<xcm_executor::Assets, XcmError> {158 FungiblesTransactor::withdraw_asset(what, who, maybe_context)159 }160161 fn internal_transfer_asset(162 what: &MultiAsset,163 from: &MultiLocation,164 to: &MultiLocation,165 context: &XcmContext,166 ) -> Result<xcm_executor::Assets, XcmError> {167 FungiblesTransactor::internal_transfer_asset(what, from, to, context)168 }169}170171pub type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;172173pub type Trader<T> = FreeForAll<174 pallet_configuration::WeightToFee<T, Balance>,175 RelayLocation,176 AccountId,177 Balances,178 (),179>;180181pub struct CurrencyIdConvert;182impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {183 fn convert(id: AssetIds) -> Option<MultiLocation> {184 match id {185 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(186 1,187 X1(Parachain(ParachainInfo::get().into())),188 )),189 AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),190 AssetIds::ForeignAssetId(foreign_asset_id) => {191 XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)192 }193 }194 }195}196197impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {198 fn convert(location: MultiLocation) -> Option<CurrencyId> {199 if location == MultiLocation::here()200 || location == MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())))201 {202 return Some(AssetIds::NativeAssetId(NativeCurrency::Here));203 }204205 if location == MultiLocation::parent() {206 return Some(AssetIds::NativeAssetId(NativeCurrency::Parent));207 }208209 if let Some(currency_id) =210 XcmForeignAssetIdMapping::<Runtime>::get_currency_id(location.clone())211 {212 return Some(currency_id);213 }214215 None216 }217}runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -130,6 +130,7 @@
"orml-traits/std",
"orml-vesting/std",
"orml-xtokens/std",
+ "orml-xcm-support/std",
"pallet-foreign-assets/std",
'pallet-maintenance/std',
@@ -217,6 +218,7 @@
orml-traits = { workspace = true }
orml-vesting = { workspace = true }
orml-xtokens = { workspace = true }
+orml-xcm-support = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -129,6 +129,7 @@
"orml-traits/std",
"orml-vesting/std",
"orml-xtokens/std",
+ "orml-xcm-support/std",
"pallet-foreign-assets/std",
"pallet-maintenance/std",
]
@@ -209,6 +210,7 @@
orml-traits = { workspace = true }
orml-vesting = { workspace = true }
orml-xtokens = { workspace = true }
+orml-xcm-support = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -126,6 +126,7 @@
"orml-traits/std",
"orml-vesting/std",
"orml-xtokens/std",
+ "orml-xcm-support/std",
"pallet-foreign-assets/std",
"pallet-maintenance/std",
]
@@ -208,6 +209,7 @@
orml-traits = { workspace = true }
orml-vesting = { workspace = true }
orml-xtokens = { workspace = true }
+orml-xcm-support = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }