diff --git a/Cargo.toml b/Cargo.toml index ec3df6fb88..821b454933 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -170,8 +170,8 @@ sp-timestamp = { git = "https://github.com/mangata-finance//substrate", branch = sp-runtime = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-io = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-mmr-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +# pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +# pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } mangata-support = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } # patch generated by ./scripts/dev-0.9.29_manifest.sh @@ -327,8 +327,8 @@ sp-timestamp = { git = "https://github.com/mangata-finance//substrate", branch = sp-runtime = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-io = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-mmr-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +# pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +# pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } mangata-support = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } # patch generated by ./scripts/dev-v0.9.31-0.9.29_manifest.sh @@ -483,8 +483,8 @@ sp-timestamp = { git = "https://github.com/mangata-finance//substrate", branch = sp-runtime = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-io = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } sp-mmr-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } -pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +# pallet-vesting-mangata-rpc-runtime-api = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } +# pallet-vesting-mangata-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } mangata-support = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" } # # patch generated by ./scripts/dev_manifest.sh diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index 9d809111c5..a0703d6127 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -29,7 +29,7 @@ sp-staking = { git = "https://github.com/mangata-finance/substrate", branch = "m pallet-collective-mangata = { git = "https://github.com/mangata-finance/substrate", branch = "mangata-dev", default-features = false } mangata-support = { git = "https://github.com/mangata-finance/substrate", branch = "mangata-dev", default-features = false } -pallet-issuance = { git = "https://github.com/mangata-finance/mangata-node", branch = "develop-v0.9.40", default-features = false, optional = true} +pallet-issuance = { git = "https://github.com/mangata-finance/mangata-node", branch = "develop", default-features = false, optional = true} mangata-types = { git = "https://github.com/mangata-finance/substrate", branch = "mangata-dev", default-features = false } orml-tokens = { default-features = false, version = '0.4.1-dev', git = "https://github.com/mangata-finance/open-runtime-module-library", branch = "mangata-dev" } itertools = {version ="0.10.3", default-features=false, features=["use_alloc"]} diff --git a/pallets/parachain-staking/src/benchmarks.rs b/pallets/parachain-staking/src/benchmarks.rs index 09f7f6a2aa..2a998022c0 100644 --- a/pallets/parachain-staking/src/benchmarks.rs +++ b/pallets/parachain-staking/src/benchmarks.rs @@ -52,21 +52,6 @@ const MGA_TOKEN_ID: TokenId = 0u32; /// Any set of tokens x, x0=0, will have token_id, (3x+5, 3x+6) <=> 3x+7 /// Since we are creating new tokens every time we can simply just use (v, v+1) as the pooled token amounts, to mint v liquidity tokens -// pub(crate) fn payout_collator_for_round( -// n: u32, -// ) { -// let dummy_user: T::AccountId = account("dummy", 0u32, 0u32); -// let collators: Vec<::AccountId> = -// RoundCollatorRewardInfo::::iter_key_prefix(n).collect(); -// for collator in collators.iter() { -// Pallet::::payout_collator_rewards( -// RawOrigin::Signed(dummy_user.clone()).into(), -// n.try_into().unwrap(), -// collator.clone(), -// <::MaxDelegatorsPerCandidate as Get>::get(), -// ); -// } -// } /// Mint v liquidity tokens of token set x to funding account fn create_non_staking_liquidity_for_funding( @@ -124,6 +109,33 @@ fn create_staking_liquidity_for_funding( Ok(x + 1u32) } +fn create_3rdparty_reward_token_for_funding( + v: Option, +) -> Result { + let funding_account: T::AccountId = account("funding", 0u32, 0u32); + let v = v.unwrap_or(1_000_000_000_000_000_000 * DOLLAR); + + as MultiTokenCurrencyExtended>::mint( + MGA_TOKEN_ID.into(), + &funding_account, + v.into(), + )?; + + let token = as MultiTokenCurrencyExtended>::create(&funding_account, (v + 1u128).into())?; + + assert!(>::create_pool( + funding_account.clone(), + MGA_TOKEN_ID.into(), + v.into(), + token.into(), + (v + 1).into() + ) + .is_ok()); + + // assert_eq!( as MultiTokenCurrency>::total_balance((token + 1u32).into(), &funding_account), v.into()); + Ok((token + 1u32.into()).into()) +} + /// Create a funded user. /// Extra + min_candidate_stk is total minted funds /// Returns tuple (id, balance) @@ -1689,25 +1701,30 @@ benchmarks! { active_session_change { - // liquidity tokens - let x in 3..100; + + // number of 3rdparty rewards schedules running + // let c in 3..150; + // number of native rewrds (promoted pools) + // let x in 3..100; // candidate_count - let y in (<::MinSelectedCandidates as Get>::get() + 1u32)..(<::MaxCollatorCandidates as Get>::get() - 2u32); // to account for the two candidates we start with + // let y in (<::MinSelectedCandidates as Get>::get() + 1u32)..(<::MaxCollatorCandidates as Get>::get() - 2u32); // to account for the two candidates we start with // MaxDelegatorsPerCandidate - let z in 3..<::MaxDelegatorsPerCandidate as Get>::get(); - - // // Since now an aggregator can have multiple collators each of whose rewards will be written to the storage individually - // // Total selected - let w = <::MinSelectedCandidates as Get>::get() + 1u32; - - // // liquidity tokens - // let x = 100; - // // candidate_count - // let y = 190; + // let z in 3..<::MaxDelegatorsPerCandidate as Get>::get(); + // Since now an aggregator can have multiple collators each of whose rewards will be written to the storage individually + // Total selected + // let w = <::MinSelectedCandidates as Get>::get() + 1u32; + + // // liquidity tokens - (Pos::distribute_rewards) calculate things per liq token + let x = 200; + // // candidate_count - total number of all candidates (needs to calculate bonds in each session) + let y = (<::MaxCollatorCandidates as Get>::get() - 2u32); // // MaxDelegatorsPerCandidate - // let z = 200; - // // Total selected - // let w = 190; + let z = <::MaxDelegatorsPerCandidate as Get>::get(); + // // Total selected candidates + let w = <::MinSelectedCandidates as Get>::get() + 1u32; + // + // number of 3rdparty schedules + let c = 200; assert_ok!(>::finalize_tge(RawOrigin::Root.into())); assert_ok!(>::init_issuance_config(RawOrigin::Root.into())); @@ -1719,20 +1736,39 @@ benchmarks! { let start_liquidity_token = Pallet::::staking_liquidity_tokens(); let start_liquidity_token_count: u32 = start_liquidity_token.len().try_into().unwrap(); + for (token,_) in start_liquidity_token { - // as PoolPromoteApi>::update_pool_promotion(token, Some(1)); >::enable(token, 1); } + assert!(x > start_liquidity_token_count); // create X - 1 Tokens now and then remaining one for i in start_liquidity_token_count..(x-1){ let created_liquidity_token = create_staking_liquidity_for_funding::(Some(T::MinCandidateStk::get())).unwrap(); Pallet::::add_staking_liquidity_token(RawOrigin::Root.into(), PairedOrLiquidityToken::Liquidity(created_liquidity_token), i).unwrap(); - // as PoolPromoteApi>::update_pool_promotion(created_liquidity_token, Some(1)); >::enable(created_liquidity_token, 1); } + for id in 0..c { + let liquidity_amount = 100_000; + let liquidity_token = create_non_staking_liquidity_for_funding::(Some(liquidity_amount)).unwrap(); + + let pool = (liquidity_token - 2, liquidity_token - 1); + + log::info!("3rdparty_liq_token: {:?} : {:?}", liquidity_token, pool); + + let reward_amount = 100_000_000*DOLLAR; + let reward_token = create_3rdparty_reward_token_for_funding::(Some(reward_amount)).unwrap(); + log::info!("rewards_token: {:?}", reward_token); + + let (user, _, _) = create_funded_user::("3rdparty_reward", id as u32, liquidity_token, Some(liquidity_amount)); + let (user, _, _) = create_funded_user::("3rdparty_reward", id as u32, reward_token, Some(reward_amount)); + + T::RewardsApi::enable_3rdparty_rewards(user.clone(), pool, reward_token, 10, reward_amount); + T::RewardsApi::activate_liquidity_for_3rdparty_rewards(user, liquidity_token, liquidity_amount, reward_token); + } + // Now to prepare the liquidity token we will use for collator and delegators let created_liquidity_token = create_staking_liquidity_for_funding::(Some( ((z*(y+1)) as u128 *100*DOLLAR)+ T::MinCandidateStk::get()*DOLLAR)).unwrap(); assert_ok!(Pallet::::add_staking_liquidity_token(RawOrigin::Root.into(), PairedOrLiquidityToken::Liquidity(created_liquidity_token), x)); diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index b681333220..a6b136c69a 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -1693,7 +1693,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn round)] /// Current round index and next round scheduled transition - pub(crate) type Round = StorageValue<_, RoundInfo, ValueQuery>; + pub type Round = StorageValue<_, RoundInfo, ValueQuery>; #[pallet::storage] #[pallet::getter(fn delegator_state)]