Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update slashing across all active assets on a service #886

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d71d019
feat: update slashing across all active assets on a service
drewstone Jan 16, 2025
b80ecec
chore: get building, migrate large functions into separate files
drewstone Jan 19, 2025
aca7c3d
feat: add membership model to blueprint and services
drewstone Jan 21, 2025
4f8adef
chore: add service id to slash operator for proper processing
drewstone Jan 21, 2025
96163f1
feat: merge main, update build, add SlashManager trait
drewstone Jan 28, 2025
84af14d
feat: update slashing from services, process slashes on_initialize, p…
drewstone Jan 31, 2025
b363388
Merge branch 'main' into drew/slashing-updates
drewstone Jan 31, 2025
06f835b
feat: add native delegation / native restaking
drewstone Feb 1, 2025
47ae054
chore: gitignore fix
drewstone Feb 1, 2025
3a624f5
chore: fmt
drewstone Feb 1, 2025
1a64861
chore: move service tests to directory and into different files
drewstone Feb 1, 2025
2cdf62d
chore: fix more test errors/lints, still bit to go
drewstone Feb 1, 2025
51cf4e4
chore: get tests building and running
drewstone Feb 3, 2025
bdebe6b
chore: fix up some errors, trigger more
drewstone Feb 3, 2025
3669cab
chore: fix warnings
drewstone Feb 4, 2025
42c59fb
chore: merge main
drewstone Feb 4, 2025
a0df81f
fix: update tests and bytecode
shekohex Feb 4, 2025
e3a0e14
fix: services pallet tests
shekohex Feb 4, 2025
e7d0329
fix: more tests that is related to services
shekohex Feb 4, 2025
7dfbf12
feat: add native restaking test
shekohex Feb 5, 2025
6507229
chore: setup native restaking tests
drewstone Feb 5, 2025
2e69ed3
feat: add more native restaking test
shekohex Feb 5, 2025
af02b0b
Merge branch 'drew/slashing-updates' into drew/slashing-updates-temp
drewstone Feb 5, 2025
c0390a5
chore: fix slashing, add more test coverage for native and normal del…
drewstone Feb 6, 2025
e3f046c
chore: remove fn
drewstone Feb 7, 2025
c462597
feat: add SignedExtension to check if the caller can unbond
shekohex Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

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

89 changes: 89 additions & 0 deletions pallets/multi-asset-delegation/src/extra.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use mock::{AccountId, Runtime, RuntimeCall};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::traits::{DispatchInfoOf, SignedExtension};
use types::BalanceOf;

use super::*;

#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct CheckNominatedRestaked<T>(core::marker::PhantomData<T>);

impl<T> sp_std::fmt::Debug for CheckNominatedRestaked<T> {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
write!(f, "CheckNominatedRestaked")
}

#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
Ok(())
}
}

impl<T> CheckNominatedRestaked<T> {
pub fn new() -> Self {
CheckNominatedRestaked(core::marker::PhantomData)
}
}

impl<T: Config> CheckNominatedRestaked<T> {
/// See [`crate::Pallet::can_unbound`]
pub fn can_unbound(who: &T::AccountId, amount: BalanceOf<T>) -> bool {
crate::Pallet::<T>::can_unbound(who, amount)
}
}

impl<T> Default for CheckNominatedRestaked<T> {
fn default() -> Self {
CheckNominatedRestaked(core::marker::PhantomData)
}
}

impl SignedExtension for CheckNominatedRestaked<Runtime> {
const IDENTIFIER: &'static str = "CheckNominatedRestaked";

type AccountId = AccountId;

type Call = RuntimeCallFor<Runtime>;

type AdditionalSigned = ();

type Pre = ();

fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}

fn validate(
&self,
who: &Self::AccountId,
call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
match call {
RuntimeCall::Staking(pallet_staking::Call::unbond { value }) => {
if Self::can_unbound(who, *value) {
Ok(ValidTransaction::default())
} else {
Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(1)))
}
},
_ => Ok(ValidTransaction::default()),
}
}

fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
self.validate(who, call, info, len).map(|_| ())
}
}
Loading