referrerpolicy=no-referrer-when-downgrade

assets_common/
benchmarks.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use core::{fmt::Debug, marker::PhantomData};
17use cumulus_primitives_core::ParaId;
18use sp_runtime::traits::Get;
19use xcm::latest::prelude::*;
20
21/// Creates asset pairs for liquidity pools with `Target` always being the first asset.
22pub struct AssetPairFactory<Target, SelfParaId, PalletId, L = Location>(
23	PhantomData<(Target, SelfParaId, PalletId, L)>,
24);
25impl<Target: Get<L>, SelfParaId: Get<ParaId>, PalletId: Get<u32>, L: TryFrom<Location> + Debug>
26	pallet_asset_conversion::BenchmarkHelper<L> for AssetPairFactory<Target, SelfParaId, PalletId, L>
27where
28	<L as TryFrom<Location>>::Error: Debug,
29{
30	fn create_pair(seed1: u32, seed2: u32) -> (L, L) {
31		let with_id = Location::new(
32			1,
33			[
34				Parachain(SelfParaId::get().into()),
35				PalletInstance(PalletId::get() as u8),
36				GeneralIndex(seed2.into()),
37			],
38		);
39		if seed1 % 2 == 0 {
40			(
41				with_id
42					.try_into()
43					.map_err(|error| {
44						tracing::error!(
45							target: "xcm",
46							?error,
47							"Failed to create asset pairs when seed1 is even",
48						);
49						"Something went wrong"
50					})
51					.unwrap(),
52				Target::get(),
53			)
54		} else {
55			(
56				Target::get(),
57				with_id
58					.try_into()
59					.map_err(|error| {
60						tracing::error!(target: "xcm", ?error, "Failed to create asset pairs");
61						"Something went wrong"
62					})
63					.unwrap(),
64			)
65		}
66	}
67}