Skip to content

Commit

Permalink
feat: Slashing Queue (#793)
Browse files Browse the repository at this point in the history
* feat: Slashing Queue

* feat: Per Service restaking percentage exposure

* test: add more tests for the unapplied slash
  • Loading branch information
shekohex authored Oct 16, 2024
1 parent bee0039 commit 6477d74
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 501 deletions.
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pallets/multi-asset-delegation/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use super::*;
use crate::types::{BalanceOf, OperatorStatus};
use sp_runtime::traits::Zero;
use sp_std::prelude::*;
use tangle_primitives::{traits::MultiAssetDelegationInfo, RoundIndex};

impl<T: crate::Config> MultiAssetDelegationInfo<T::AccountId, BalanceOf<T>> for crate::Pallet<T> {
Expand Down Expand Up @@ -50,4 +51,16 @@ impl<T: crate::Config> MultiAssetDelegationInfo<T::AccountId, BalanceOf<T>> for
.fold(Zero::zero(), |acc, stake| acc + stake.amount)
})
}

fn get_delegators_for_operator(
operator: &T::AccountId,
) -> Vec<(T::AccountId, BalanceOf<T>, Self::AssetId)> {
Operators::<T>::get(operator).map_or(Vec::new(), |metadata| {
metadata
.delegations
.iter()
.map(|stake| (stake.delegator.clone(), stake.amount, stake.asset_id))
.collect()
})
}
}
26 changes: 2 additions & 24 deletions pallets/services/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ fn mock_account_id<T: Config>(id: u8) -> T::AccountId {
}

fn operator_preferences<T: Config>() -> OperatorPreferences {
OperatorPreferences {
key: zero_key(),
approval: ApprovalPreference::default(),
price_targets: Default::default(),
}
OperatorPreferences { key: zero_key(), price_targets: Default::default() }
}

fn cggmp21_blueprint<T: Config>() -> ServiceBlueprint<T::Constraints> {
Expand Down Expand Up @@ -92,20 +88,6 @@ benchmarks! {

}: _(RawOrigin::Signed(bob.clone()), 0)


update_approval_preference {
let alice: T::AccountId = mock_account_id::<T>(1u8);
let blueprint = cggmp21_blueprint::<T>();
let _= Pallet::<T>::create_blueprint(RawOrigin::Signed(alice.clone()).into(), blueprint);

let bob: T::AccountId = mock_account_id::<T>(2u8);
let operator_preference = operator_preferences::<T>();

let _= Pallet::<T>::register(RawOrigin::Signed(bob.clone()).into(), 0, operator_preference, Default::default());

}: _(RawOrigin::Signed(bob.clone()), 0, ApprovalPreference::Required)


update_price_targets {
let alice: T::AccountId = mock_account_id::<T>(1u8);
let blueprint = cggmp21_blueprint::<T>();
Expand Down Expand Up @@ -162,8 +144,6 @@ benchmarks! {
Default::default()
);

let operator_preference = OperatorPreferences { approval: ApprovalPreference::Required, ..operator_preference };

let charlie: T::AccountId = mock_account_id::<T>(3u8);
let _= Pallet::<T>::register(RawOrigin::Signed(charlie.clone()).into(), 0, operator_preference, Default::default());

Expand All @@ -180,7 +160,7 @@ benchmarks! {
Default::default()
);

}: _(RawOrigin::Signed(charlie.clone()), 0)
}: _(RawOrigin::Signed(charlie.clone()), 0, Percent::from_percent(25))


reject {
Expand All @@ -197,8 +177,6 @@ benchmarks! {
Default::default()
);

let operator_preference = OperatorPreferences { approval: ApprovalPreference::Required, ..operator_preference };

let charlie: T::AccountId = mock_account_id::<T>(3u8);
let _= Pallet::<T>::register(RawOrigin::Signed(charlie.clone()).into(), 0, operator_preference, Default::default());

Expand Down
Loading

0 comments on commit 6477d74

Please sign in to comment.