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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
// This file is part of Basilisk-node.

// Copyright (C) 2020-2022  Intergalactic, Limited (GIB).
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unnecessary_wraps)]

mod mock;

use pallet_liquidity_mining::{GlobalFarmId, LoyaltyCurve, YieldFarmId};
use pallet_xyk_liquidity_mining::Pallet as XYKLiquidityMining;

use frame_benchmarking::{account, benchmarks};
use frame_system::{Pallet as System, RawOrigin};

use frame_support::dispatch;
use orml_traits::arithmetic::One;
use orml_traits::MultiCurrency;
use primitives::{asset::AssetPair, AssetId, Balance};
use sp_arithmetic::FixedU128;
use sp_arithmetic::Perquintill;
use sp_std::convert::From;

use pallet_xyk as xykpool;

pub const GLOBAL_FARM_ID: GlobalFarmId = 1;
pub const GLOBAL_FARM_ID_2: GlobalFarmId = 3;
pub const YIELD_FARM_ID: YieldFarmId = 2;
pub const YIELD_FARM_ID_2: YieldFarmId = 4;
pub const YIELD_FARM_ID_3: YieldFarmId = 4;
pub const DEPOSIT_ID: u128 = 1;

const SEED: u32 = 0;

const BSX: AssetId = 0;
const KSM: AssetId = 1;
const DOT: AssetId = 2;
const ASSET_PAIR: AssetPair = AssetPair {
	asset_in: BSX,
	asset_out: KSM,
};

const INITIAL_BALANCE: Balance = 100_000_000;
const ONE: Balance = 1_000_000_000_000;

pub trait Config: pallet_xyk_liquidity_mining::Config + pallet_xyk::Config + pallet_asset_registry::Config {}

pub struct Pallet<T: Config>(XYKLiquidityMining<T>);

type MultiCurrencyOf<T> = <T as pallet_xyk_liquidity_mining::Config>::MultiCurrency;

fn create_funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
	let caller: T::AccountId = account(name, index, SEED);

	<T as pallet_xyk_liquidity_mining::Config>::MultiCurrency::deposit(BSX, &caller, INITIAL_BALANCE * ONE).unwrap();

	<T as pallet_xyk_liquidity_mining::Config>::MultiCurrency::deposit(KSM, &caller, INITIAL_BALANCE * ONE).unwrap();

	<T as pallet_xyk_liquidity_mining::Config>::MultiCurrency::deposit(DOT, &caller, INITIAL_BALANCE * ONE).unwrap();

	let next_available_asset_id = pallet_asset_registry::Pallet::<T>::next_asset_id().unwrap();
	<T as pallet_xyk_liquidity_mining::Config>::MultiCurrency::deposit(
		next_available_asset_id.try_into().ok().unwrap(),
		&caller,
		INITIAL_BALANCE * ONE,
	)
	.unwrap();

	<T as pallet_xyk_liquidity_mining::Config>::MultiCurrency::deposit(
		TryInto::<u32>::try_into(next_available_asset_id)
			.ok()
			.unwrap()
			.checked_add(1)
			.unwrap(),
		&caller,
		INITIAL_BALANCE * ONE,
	)
	.unwrap();

	<T as pallet_xyk_liquidity_mining::Config>::MultiCurrency::deposit(
		TryInto::<u32>::try_into(next_available_asset_id)
			.ok()
			.unwrap()
			.checked_add(2)
			.unwrap(),
		&caller,
		INITIAL_BALANCE * ONE,
	)
	.unwrap();

	caller
}

fn initialize_pool<T: Config>(
	caller: T::AccountId,
	asset_a: AssetId,
	asset_b: AssetId,
	amount_a: Balance,
	amount_b: Balance,
) -> dispatch::DispatchResult {
	xykpool::Pallet::<T>::create_pool(RawOrigin::Signed(caller).into(), asset_a, amount_a, asset_b, amount_b)
}

fn xyk_add_liquidity<T: Config>(
	caller: T::AccountId,
	assets: AssetPair,
	amount_a: Balance,
	amount_b_max: Balance,
) -> dispatch::DispatchResult {
	xykpool::Pallet::<T>::add_liquidity(
		RawOrigin::Signed(caller).into(),
		assets.asset_in,
		assets.asset_out,
		amount_a,
		amount_b_max,
	)
}

fn lm_create_global_farm<T: Config>(
	total_rewards: Balance,
	owner: T::AccountId,
	yield_per_period: Perquintill,
) -> dispatch::DispatchResult {
	XYKLiquidityMining::<T>::create_global_farm(
		RawOrigin::Root.into(),
		total_rewards,
		T::BlockNumber::from(1_000_000_u32),
		T::BlockNumber::from(1_u32),
		BSX,
		BSX,
		owner,
		yield_per_period,
		1_000,
		One::one(),
	)
}

fn lm_deposit_shares<T: Config>(caller: T::AccountId, assets: AssetPair, amount: Balance) -> dispatch::DispatchResult {
	XYKLiquidityMining::<T>::deposit_shares(
		RawOrigin::Signed(caller).into(),
		GLOBAL_FARM_ID,
		YIELD_FARM_ID,
		assets,
		amount,
	)
}

fn lm_create_yield_farm<T: Config>(
	caller: T::AccountId,
	farm_id: GlobalFarmId,
	assets: AssetPair,
	multiplier: FixedU128,
) -> dispatch::DispatchResult {
	XYKLiquidityMining::<T>::create_yield_farm(
		RawOrigin::Signed(caller).into(),
		farm_id,
		assets,
		multiplier,
		Some(LoyaltyCurve::default()),
	)
}

fn set_period<T: Config>(block: u32) {
	//NOTE: predefined global farm has period size = 1 block.
	System::<T>::set_block_number(block.into());
}

benchmarks! {
	create_global_farm {
		let total_rewards = 1_000_000 * ONE;
		let caller = create_funded_account::<T>("caller", 0);
		let planned_yielding_periods = T::BlockNumber::from(1_000_000_u32);
		let yield_per_period = Perquintill::from_percent(20);
		let blocks_per_period = T::BlockNumber::from(1_u32);
	}: {
		XYKLiquidityMining::<T>::create_global_farm(RawOrigin::Root.into(), total_rewards, planned_yielding_periods, blocks_per_period, BSX, BSX, caller.clone(), yield_per_period, 1_000, One::one())?
	}

	update_global_farm {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		lm_deposit_shares::<T>(liq_provider, ASSET_PAIR, 10 * ONE)?;
		set_period::<T>(200_000);
	}: {
		XYKLiquidityMining::<T>::update_global_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, FixedU128::from_inner(234_456_677_000_000_000_u128))?
	}

	terminate_global_farm {
		let total_rewards = 1_000_000 * ONE;
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		lm_deposit_shares::<T>(liq_provider, ASSET_PAIR, 10 * ONE)?;
		set_period::<T>(100_000);

		XYKLiquidityMining::<T>::stop_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, ASSET_PAIR)?;
		XYKLiquidityMining::<T>::terminate_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, YIELD_FARM_ID, ASSET_PAIR)?;
		set_period::<T>(200_000);
	}: {
		XYKLiquidityMining::<T>::terminate_global_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID)?
	}

	create_yield_farm {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);
		let bsx_dot = AssetPair {
			asset_in:  BSX,
			asset_out: DOT
		};

		initialize_pool::<T>(xyk_caller.clone(), ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		lm_deposit_shares::<T>(liq_provider, ASSET_PAIR, 10 * ONE)?;
		set_period::<T>(100_000);

		initialize_pool::<T>(xyk_caller, bsx_dot.asset_in, bsx_dot.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
	}: {
		XYKLiquidityMining::<T>::create_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, bsx_dot, FixedU128::from(50_000_000_u128), Some(LoyaltyCurve::default()))?
	}

	update_yield_farm {
		let new_multiplier = FixedU128::one();
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::from_inner(500_000_000_000_000_000_u128))?;

		lm_deposit_shares::<T>(liq_provider, ASSET_PAIR, 10 * ONE)?;
		set_period::<T>(100_000);
	}: {
		XYKLiquidityMining::<T>::update_yield_farm(RawOrigin::Signed(caller.clone()).into(), 1, ASSET_PAIR, new_multiplier)?
	}

	stop_yield_farm {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		lm_deposit_shares::<T>(liq_provider, ASSET_PAIR, 10 * ONE)?;
		set_period::<T>(100_000);
	}: {
		XYKLiquidityMining::<T>::stop_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, ASSET_PAIR)?
	}

	terminate_yield_farm {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		lm_deposit_shares::<T>(liq_provider, ASSET_PAIR, 10 * ONE)?;
		set_period::<T>(100_000);

		XYKLiquidityMining::<T>::stop_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, ASSET_PAIR)?;
	}: {
		XYKLiquidityMining::<T>::terminate_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID,YIELD_FARM_ID, ASSET_PAIR)?
	}

	deposit_shares {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		let xyk_id = xykpool::Pallet::<T>::pair_account_from_assets(ASSET_PAIR.asset_in, ASSET_PAIR.asset_out);
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		lm_create_global_farm::<T>(1_000_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller, GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		lm_deposit_shares::<T>(liq_provider.clone(), ASSET_PAIR, 5 * ONE)?;
		set_period::<T>(100_000);
	}: {
		XYKLiquidityMining::<T>::deposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID, YIELD_FARM_ID, ASSET_PAIR, 5 * ONE)?
	}

	redeposit_shares {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);
		let shares_amount = 10 * ONE;

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		//global id: 1, yield id: 2
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		//global id: 3, yield id: 4
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID_2, ASSET_PAIR, FixedU128::one())?;

		//global id: 5, yield id:6
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), 5, ASSET_PAIR, FixedU128::one())?;

		//global id: 7, yield id:8
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), 7, ASSET_PAIR, FixedU128::one())?;

		//global id: 9, yield id:10
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller, 9, ASSET_PAIR, FixedU128::one())?;

		set_period::<T>(200_000);

		XYKLiquidityMining::<T>::deposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID, YIELD_FARM_ID, ASSET_PAIR, shares_amount)?;
		//NOTE: with this redeposits it's like 0.5 µs slower(on my machine) because adding yield
		//farm entry into the deposit is doing search on BoundedVec<YieldFarmEntry, ...>
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID_2, YIELD_FARM_ID_2, ASSET_PAIR, DEPOSIT_ID)?;
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), 5, 6, ASSET_PAIR, DEPOSIT_ID)?;
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), 7, 8, ASSET_PAIR, DEPOSIT_ID)?;
	}: {
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), 9, 10, ASSET_PAIR, DEPOSIT_ID)?
	}

	claim_rewards {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);
		let shares_amount = 10 * ONE;

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		//global id: 1, yield id: 2
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(),GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		//global id: 3, yield id: 4
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID_2, ASSET_PAIR, FixedU128::one())?;

		//global id: 5, yield id:6
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), 5, ASSET_PAIR, FixedU128::one())?;

		//global id: 7, yield id:8
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller.clone(), 7, ASSET_PAIR, FixedU128::one())?;

		//global id: 9, yield id:10
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller, 9, ASSET_PAIR, FixedU128::one())?;

		set_period::<T>(200_000);

		XYKLiquidityMining::<T>::deposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID, YIELD_FARM_ID, ASSET_PAIR, shares_amount)?;
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID_2, YIELD_FARM_ID_2, ASSET_PAIR, DEPOSIT_ID)?;
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), 5, 6, ASSET_PAIR, DEPOSIT_ID)?;
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), 7, 8, ASSET_PAIR, DEPOSIT_ID)?;
		XYKLiquidityMining::<T>::redeposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), 9, 10, ASSET_PAIR, DEPOSIT_ID)?;

		set_period::<T>(400_000);
		let liq_provider_bsx_balance = MultiCurrencyOf::<T>::free_balance(BSX, &liq_provider);
	}: {
		XYKLiquidityMining::<T>::claim_rewards(RawOrigin::Signed(liq_provider.clone()).into(), DEPOSIT_ID, 10)?
	} verify {
		assert!(MultiCurrencyOf::<T>::free_balance(BSX, &liq_provider).gt(&liq_provider_bsx_balance));
	}

	//This benchmark has higher weights than:
	//  * withdraw_shares with farms removal from storage
	//  * withdraw_shares without deposit removal from storage
	withdraw_shares {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);
		let shares_amount = 10 * ONE;

		initialize_pool::<T>(xyk_caller, ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		xyk_add_liquidity::<T>(liq_provider.clone(), ASSET_PAIR, 10 * ONE, 1_000 * ONE)?;

		//global id: 1, yield id: 2
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		lm_create_yield_farm::<T>(caller, GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;

		set_period::<T>(200_000);

		XYKLiquidityMining::<T>::deposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID, YIELD_FARM_ID, ASSET_PAIR, shares_amount)?;

		set_period::<T>(400_000);

		let liq_provider_bsx_balance = MultiCurrencyOf::<T>::free_balance(BSX, &liq_provider);
	}: {
		XYKLiquidityMining::<T>::withdraw_shares(RawOrigin::Signed(liq_provider.clone()).into(), DEPOSIT_ID, YIELD_FARM_ID, ASSET_PAIR)?
	} verify {
		assert!(MultiCurrencyOf::<T>::free_balance(BSX, &liq_provider).gt(&liq_provider_bsx_balance));
	}

	resume_yield_farm {
		let caller = create_funded_account::<T>("caller", 0);
		let xyk_caller = create_funded_account::<T>("xyk_caller", 1);
		let liq_provider = create_funded_account::<T>("liq_provider", 2);
		let shares_amount = 10 * ONE;
		let bsx_dot = AssetPair {
			asset_in:  BSX,
			asset_out: DOT
		};

		initialize_pool::<T>(xyk_caller.clone(), ASSET_PAIR.asset_in, ASSET_PAIR.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		initialize_pool::<T>(xyk_caller, bsx_dot.asset_in, bsx_dot.asset_out, 1_000_000 * ONE, 10_000_000 * ONE)?;
		xyk_add_liquidity::<T>(liq_provider.clone(), bsx_dot, 10 * ONE, 1_000 * ONE)?;

		//global id: 1
		lm_create_global_farm::<T>(100_000 * ONE, caller.clone(), Perquintill::from_percent(20))?;
		//yield id: 2
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, ASSET_PAIR, FixedU128::one())?;
		//yield id: 3
		lm_create_yield_farm::<T>(caller.clone(), GLOBAL_FARM_ID, bsx_dot, FixedU128::one())?;

		XYKLiquidityMining::<T>::stop_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, ASSET_PAIR)?;

		set_period::<T>(200_000);

		XYKLiquidityMining::<T>::deposit_shares(RawOrigin::Signed(liq_provider.clone()).into(), GLOBAL_FARM_ID, 3, bsx_dot, shares_amount)?;

		set_period::<T>(400_000);
		let liq_provider_bsx_balance = MultiCurrencyOf::<T>::free_balance(BSX, &liq_provider);
	}: {
		XYKLiquidityMining::<T>::resume_yield_farm(RawOrigin::Signed(caller.clone()).into(), GLOBAL_FARM_ID, YIELD_FARM_ID, ASSET_PAIR, FixedU128::from(12_452))?
	}
}

#[cfg(test)]
mod tests {
	use super::Pallet;
	use frame_benchmarking::impl_benchmark_test_suite;

	impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}