From c1e4ca51d4fb8ac9ae04f63ce823cf06c04c234f Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Thu, 14 Dec 2023 11:25:35 +0100 Subject: [PATCH] fix PoS benchmarks --- pallets/proof-of-stake/src/benchmarking.rs | 58 ++++++++++++---------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/pallets/proof-of-stake/src/benchmarking.rs b/pallets/proof-of-stake/src/benchmarking.rs index c23fe5170c..0799069448 100644 --- a/pallets/proof-of-stake/src/benchmarking.rs +++ b/pallets/proof-of-stake/src/benchmarking.rs @@ -247,15 +247,16 @@ benchmarks! { } let REWARDS_AMOUNT: u128 = ::Min3rdPartyRewardValutationPerSession::get() * 10u128; - let native_asset_amount: u128 = REWARDS_AMOUNT * Into::::into(schedules_limit + 1); + let POOL_VOLUME: u128 = ::Min3rdPartyRewardVolume::get() * 1_000_000u128; + + let native_asset_amount: u128 = POOL_VOLUME * Into::::into(schedules_limit + 1); TokensOf::::mint(native_asset_id.into(), &caller, native_asset_amount.to_balance::()).unwrap(); for _ in 0 .. schedules_limit - 2 { - let token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), token_id, REWARDS_AMOUNT.to_balance::()).unwrap(); + let token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), token_id, POOL_VOLUME.to_balance::()).unwrap(); let reward_token = token_id + One::one(); let balance:u128 = TokensOf::::free_balance(reward_token.into(), &caller).into(); - assert_eq!(balance, REWARDS_AMOUNT); PoS::::reward_pool( RawOrigin::Signed(caller.clone().into()).into(), @@ -266,8 +267,8 @@ benchmarks! { ).unwrap(); } - let token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + let token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let reward_token = token_id + One::one(); PoS::::reward_pool( RawOrigin::Signed(caller.clone().into()).into(), @@ -281,8 +282,8 @@ benchmarks! { forward_to_next_session::(); forward_to_next_session::(); - let token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + let token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let reward_token = token_id + One::one(); assert_eq!( @@ -311,6 +312,7 @@ benchmarks! { let caller: ::AccountId = whitelisted_caller(); let native_asset_id = ::NativeCurrencyId::get(); let REWARDS_AMOUNT: u128 = ::Min3rdPartyRewardValutationPerSession::get() * (schedules_limit as u128); + let POOL_VOLUME: u128 = ::Min3rdPartyRewardVolume::get() * 1_000_000u128; loop { let token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); @@ -319,15 +321,15 @@ benchmarks! { } } - let native_asset_amount: u128 = REWARDS_AMOUNT * Into::::into(schedules_limit); + let native_asset_amount: u128 = POOL_VOLUME * Into::::into(schedules_limit); TokensOf::::mint(native_asset_id.into(), &caller, native_asset_amount.to_balance::()).unwrap(); - let first_token_id= TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id, REWARDS_AMOUNT.to_balance::(), first_token_id, REWARDS_AMOUNT.to_balance::()).unwrap(); + let first_token_id= TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id, POOL_VOLUME.to_balance::(), first_token_id, POOL_VOLUME.to_balance::()).unwrap(); let liquidity_asset_id = first_token_id + One::one(); - let second_token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), second_token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + let second_token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), second_token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let reward_token_id = second_token_id + One::one(); @@ -361,6 +363,7 @@ benchmarks! { let caller: ::AccountId = whitelisted_caller(); let native_asset_id = ::NativeCurrencyId::get(); let REWARDS_AMOUNT: u128 = 2u128 * ::Min3rdPartyRewardValutationPerSession::get(); + let POOL_VOLUME: u128 = ::Min3rdPartyRewardVolume::get() * 1_000_000u128; loop { let token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); @@ -369,15 +372,15 @@ benchmarks! { } } - let native_asset_amount: u128 = REWARDS_AMOUNT * Into::::into(schedules_limit); - TokensOf::::mint(native_asset_id.into(), &caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - let first_token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), first_token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + let native_asset_amount: u128 = POOL_VOLUME * Into::::into(schedules_limit); + TokensOf::::mint(native_asset_id.into(), &caller, POOL_VOLUME.to_balance::()).unwrap(); + let first_token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), first_token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let liquidity_asset_id = first_token_id + One::one(); - TokensOf::::mint(native_asset_id.into(), &caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - let second_token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), second_token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + TokensOf::::mint(native_asset_id.into(), &caller, POOL_VOLUME.to_balance::()).unwrap(); + let second_token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), second_token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let reward_token_id = second_token_id + One::one(); PoS::::reward_pool( @@ -408,7 +411,7 @@ benchmarks! { TokensOf::::ensure_can_withdraw( liquidity_asset_id.into(), &caller, - REWARDS_AMOUNT.to_balance::(), + POOL_VOLUME.to_balance::(), WithdrawReasons::all(), Default::default(), ).is_err() @@ -421,7 +424,7 @@ benchmarks! { assert!(TokensOf::::ensure_can_withdraw( liquidity_asset_id.into(), &caller, - REWARDS_AMOUNT.to_balance::(), + POOL_VOLUME.to_balance::(), WithdrawReasons::all(), Default::default(), ).is_ok()); @@ -441,6 +444,7 @@ benchmarks! { let caller: ::AccountId = whitelisted_caller(); let native_asset_id = ::NativeCurrencyId::get(); let REWARDS_AMOUNT: u128 = 2u128 * ::Min3rdPartyRewardValutationPerSession::get(); + let POOL_VOLUME: u128 = ::Min3rdPartyRewardVolume::get() * 1_000_000u128; loop { let token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); @@ -449,15 +453,15 @@ benchmarks! { } } - let native_asset_amount: u128 = REWARDS_AMOUNT * Into::::into(schedules_limit); + let native_asset_amount: u128 = POOL_VOLUME * Into::::into(schedules_limit); TokensOf::::mint(native_asset_id.into(), &caller, native_asset_amount.to_balance::()).unwrap(); - let first_token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), first_token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + let first_token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), first_token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let liquidity_asset_id = first_token_id + One::one(); - let second_token_id = TokensOf::::create(&caller, REWARDS_AMOUNT.to_balance::()).unwrap(); - XykOf::::create_pool(caller.clone(), native_asset_id.into(), REWARDS_AMOUNT.to_balance::(), second_token_id.into(), REWARDS_AMOUNT.to_balance::()).unwrap(); + let second_token_id = TokensOf::::create(&caller, POOL_VOLUME.to_balance::()).unwrap(); + XykOf::::create_pool(caller.clone(), native_asset_id.into(), POOL_VOLUME.to_balance::(), second_token_id.into(), POOL_VOLUME.to_balance::()).unwrap(); let reward_token_id = second_token_id + One::one(); PoS::::reward_pool(