1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.

pub use pallet::*;

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
#[cfg(test)]
mod mock;

#[frame_support::pallet]
pub mod pallet {
	use frame_benchmarking::BenchmarkError;
	use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::Encode};
	use sp_runtime::traits::Dispatchable;
	use xcm::latest::{Asset, Assets, InteriorLocation, Junction, Location, NetworkId, Response};

	#[pallet::config]
	pub trait Config<I: 'static = ()>: frame_system::Config + crate::Config {
		type RuntimeCall: Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
			+ GetDispatchInfo
			+ From<frame_system::Call<Self>>
			+ Encode;

		/// The type of `fungible` that is being used under the hood.
		///
		/// This is useful for testing and checking.
		type TransactAsset: frame_support::traits::fungible::Mutate<Self::AccountId>;

		///	The response which causes the most runtime weight.
		fn worst_case_response() -> (u64, Response);

		/// The pair of asset collections which causes the most runtime weight if demanded to be
		/// exchanged.
		///
		/// The first element in the returned tuple represents the assets that are being exchanged
		/// from, whereas the second element represents the assets that are being exchanged to.
		///
		/// If set to `Err`, benchmarks which rely on an `exchange_asset` will be skipped.
		fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError>;

		/// A `(Location, Junction)` that is one of the `UniversalAliases` configured by the
		/// XCM executor.
		///
		/// If set to `Err`, benchmarks which rely on a universal alias will be skipped.
		fn universal_alias() -> Result<(Location, Junction), BenchmarkError>;

		/// The `Location` and `RuntimeCall` used for successful transaction XCMs.
		///
		/// If set to `Err`, benchmarks which rely on a `transact_origin_and_runtime_call` will be
		/// skipped.
		fn transact_origin_and_runtime_call(
		) -> Result<(Location, <Self as crate::generic::Config<I>>::RuntimeCall), BenchmarkError>;

		/// A valid `Location` we can successfully subscribe to.
		///
		/// If set to `Err`, benchmarks which rely on a `subscribe_origin` will be skipped.
		fn subscribe_origin() -> Result<Location, BenchmarkError>;

		/// Return an origin, ticket, and assets that can be trapped and claimed.
		fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError>;

		/// Asset used to pay for fees. Used to buy weight in benchmarks, for example in
		/// `refund_surplus`.
		fn fee_asset() -> Result<Asset, BenchmarkError>;

		/// Return an unlocker, owner and assets that can be locked and unlocked.
		fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError>;

		/// A `(Location, NetworkId, InteriorLocation)` we can successfully export message
		/// to.
		///
		/// If set to `Err`, benchmarks which rely on `export_message` will be skipped.
		fn export_message_origin_and_destination(
		) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError>;

		/// A `(Location, Location)` that is one of the `Aliasers` configured by the XCM
		/// executor.
		///
		/// If set to `Err`, benchmarks which rely on a universal alias will be skipped.
		fn alias_origin() -> Result<(Location, Location), BenchmarkError>;

		/// Returns a valid pallet info for `ExpectPallet` or `QueryPallet` benchmark.
		///
		/// By default returns `frame_system::Pallet` info with expected pallet index `0`.
		fn valid_pallet() -> frame_support::traits::PalletInfoData {
			frame_support::traits::PalletInfoData {
				index: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::index(),
				name: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::name(),
				module_name: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::module_name(),
				crate_version: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::crate_version(),
			}
		}
	}

	#[pallet::pallet]
	pub struct Pallet<T, I = ()>(_);
}