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

difftreelog

source

runtime/common/config/xcm/nativeassets.rs3.9 KiBsourcehistory
1// 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::{18	traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},19	weights::{Weight, WeightToFeePolynomial},20};21use sp_runtime::traits::{CheckedConversion, Zero};22use xcm::v1::{Junction::*, MultiLocation, Junctions::*};23use xcm::latest::{24	AssetId::{Concrete},25	Fungibility::Fungible as XcmFungible,26	MultiAsset, Error as XcmError,27};28use xcm_builder::{CurrencyAdapter, NativeAsset};29use xcm_executor::{30	Assets,31	traits::{MatchesFungible, WeightTrader},32};33use sp_std::marker::PhantomData;34use crate::{Balances, ParachainInfo};35use super::{LocationToAccountId, RelayLocation};3637use up_common::types::{AccountId, Balance};3839pub struct OnlySelfCurrency;40impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {41	fn matches_fungible(a: &MultiAsset) -> Option<B> {42		let paraid = Parachain(ParachainInfo::parachain_id().into());43		match (&a.id, &a.fun) {44			(45				Concrete(MultiLocation {46					parents: 1,47					interior: X1(loc),48				}),49				XcmFungible(ref amount),50			) if paraid == *loc => CheckedConversion::checked_from(*amount),51			(52				Concrete(MultiLocation {53					parents: 0,54					interior: Here,55				}),56				XcmFungible(ref amount),57			) => CheckedConversion::checked_from(*amount),58			_ => None,59		}60	}61}6263/// Means for transacting assets on this chain.64pub type LocalAssetTransactor = CurrencyAdapter<65	// Use this currency:66	Balances,67	// Use this currency when it is a fungible asset matching the given location or name:68	OnlySelfCurrency,69	// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:70	LocationToAccountId,71	// Our chain's account ID type (we can't get away without mentioning it explicitly):72	AccountId,73	// We don't track any teleports.74	(),75>;7677pub type AssetTransactors = LocalAssetTransactor;7879pub type IsReserve = NativeAsset;8081pub struct UsingOnlySelfCurrencyComponents<82	WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,83	AssetId: Get<MultiLocation>,84	AccountId,85	Currency: CurrencyT<AccountId>,86	OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,87>(88	Weight,89	Currency::Balance,90	PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,91);92impl<93		WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,94		AssetId: Get<MultiLocation>,95		AccountId,96		Currency: CurrencyT<AccountId>,97		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,98	> WeightTrader99	for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>100{101	fn new() -> Self {102		Self(0, Zero::zero(), PhantomData)103	}104105	fn buy_weight(&mut self, _weight: Weight, payment: Assets) -> Result<Assets, XcmError> {106		Ok(payment)107	}108}109impl<110		WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,111		AssetId: Get<MultiLocation>,112		AccountId,113		Currency: CurrencyT<AccountId>,114		OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,115	> Drop116	for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>117{118	fn drop(&mut self) {119		OnUnbalanced::on_unbalanced(Currency::issue(self.1));120	}121}122123pub type Trader<T> = UsingOnlySelfCurrencyComponents<124	pallet_configuration::WeightToFee<T, Balance>,125	RelayLocation,126	AccountId,127	Balances,128	(),129>;