Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Oct 29, 2023
1 parent 2ac7a33 commit 0b8c3ec
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 41 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down
102 changes: 69 additions & 33 deletions pallets/parachain-staking/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config + orml_tokens::Config + pallet_xyk::Config>(
// n: u32,
// ) {
// let dummy_user: T::AccountId = account("dummy", 0u32, 0u32);
// let collators: Vec<<T as frame_system::Config>::AccountId> =
// RoundCollatorRewardInfo::<T>::iter_key_prefix(n).collect();
// for collator in collators.iter() {
// Pallet::<T>::payout_collator_rewards(
// RawOrigin::Signed(dummy_user.clone()).into(),
// n.try_into().unwrap(),
// collator.clone(),
// <<T as Config>::MaxDelegatorsPerCandidate as Get<u32>>::get(),
// );
// }
// }

/// Mint v liquidity tokens of token set x to funding account
fn create_non_staking_liquidity_for_funding<T: Config + orml_tokens::Config>(
Expand Down Expand Up @@ -124,6 +109,33 @@ fn create_staking_liquidity_for_funding<T: Config + orml_tokens::Config>(
Ok(x + 1u32)
}

fn create_3rdparty_reward_token_for_funding<T: Config + orml_tokens::Config>(
v: Option<Balance>,
) -> Result<TokenId, DispatchError> {
let funding_account: T::AccountId = account("funding", 0u32, 0u32);
let v = v.unwrap_or(1_000_000_000_000_000_000 * DOLLAR);

<orml_tokens::MultiTokenCurrencyAdapter<T> as MultiTokenCurrencyExtended<T::AccountId>>::mint(
MGA_TOKEN_ID.into(),
&funding_account,
v.into(),
)?;

let token = <orml_tokens::MultiTokenCurrencyAdapter<T> as MultiTokenCurrencyExtended<T::AccountId>>::create(&funding_account, (v + 1u128).into())?;

assert!(<T::Xyk as XykFunctionsTrait<_>>::create_pool(
funding_account.clone(),
MGA_TOKEN_ID.into(),
v.into(),
token.into(),
(v + 1).into()
)
.is_ok());

// assert_eq!(<orml_tokens::MultiTokenCurrencyAdapter<T> as MultiTokenCurrency<T::AccountId>>::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)
Expand Down Expand Up @@ -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 (<<T as Config>::MinSelectedCandidates as Get<u32>>::get() + 1u32)..(<<T as Config>::MaxCollatorCandidates as Get<u32>>::get() - 2u32); // to account for the two candidates we start with
// let y in (<<T as Config>::MinSelectedCandidates as Get<u32>>::get() + 1u32)..(<<T as Config>::MaxCollatorCandidates as Get<u32>>::get() - 2u32); // to account for the two candidates we start with
// MaxDelegatorsPerCandidate
let z in 3..<<T as Config>::MaxDelegatorsPerCandidate as Get<u32>>::get();

// // Since now an aggregator can have multiple collators each of whose rewards will be written to the storage individually
// // Total selected
let w = <<T as Config>::MinSelectedCandidates as Get<u32>>::get() + 1u32;

// // liquidity tokens
// let x = 100;
// // candidate_count
// let y = 190;
// let z in 3..<<T as Config>::MaxDelegatorsPerCandidate as Get<u32>>::get();
// Since now an aggregator can have multiple collators each of whose rewards will be written to the storage individually
// Total selected
// let w = <<T as Config>::MinSelectedCandidates as Get<u32>>::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 = (<<T as Config>::MaxCollatorCandidates as Get<u32>>::get() - 2u32);
// // MaxDelegatorsPerCandidate
// let z = 200;
// // Total selected
// let w = 190;
let z = <<T as Config>::MaxDelegatorsPerCandidate as Get<u32>>::get();
// // Total selected candidates
let w = <<T as Config>::MinSelectedCandidates as Get<u32>>::get() + 1u32;
//
// number of 3rdparty schedules
let c = 200;

assert_ok!(<pallet_issuance::Pallet<T>>::finalize_tge(RawOrigin::Root.into()));
assert_ok!(<pallet_issuance::Pallet<T>>::init_issuance_config(RawOrigin::Root.into()));
Expand All @@ -1719,20 +1736,39 @@ benchmarks! {

let start_liquidity_token = Pallet::<T>::staking_liquidity_tokens();
let start_liquidity_token_count: u32 = start_liquidity_token.len().try_into().unwrap();

for (token,_) in start_liquidity_token {
// <pallet_issuance::Pallet<T> as PoolPromoteApi>::update_pool_promotion(token, Some(1));
<T::RewardsApi as ProofOfStakeRewardsApi<_>>::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::<T>(Some(T::MinCandidateStk::get())).unwrap();
Pallet::<T>::add_staking_liquidity_token(RawOrigin::Root.into(), PairedOrLiquidityToken::Liquidity(created_liquidity_token), i).unwrap();
// <pallet_issuance::Pallet<T> as PoolPromoteApi>::update_pool_promotion(created_liquidity_token, Some(1));
<T::RewardsApi as ProofOfStakeRewardsApi<_>>::enable(created_liquidity_token, 1);
}

for id in 0..c {
let liquidity_amount = 100_000;
let liquidity_token = create_non_staking_liquidity_for_funding::<T>(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::<T>(Some(reward_amount)).unwrap();
log::info!("rewards_token: {:?}", reward_token);

let (user, _, _) = create_funded_user::<T>("3rdparty_reward", id as u32, liquidity_token, Some(liquidity_amount));
let (user, _, _) = create_funded_user::<T>("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::<T>(Some( ((z*(y+1)) as u128 *100*DOLLAR)+ T::MinCandidateStk::get()*DOLLAR)).unwrap();
assert_ok!(Pallet::<T>::add_staking_liquidity_token(RawOrigin::Root.into(), PairedOrLiquidityToken::Liquidity(created_liquidity_token), x));
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> = StorageValue<_, RoundInfo<T::BlockNumber>, ValueQuery>;
pub type Round<T: Config> = StorageValue<_, RoundInfo<T::BlockNumber>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn delegator_state)]
Expand Down

0 comments on commit 0b8c3ec

Please sign in to comment.