mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add claim_deallocation to the staking pallet
This commit is contained in:
@@ -13,12 +13,13 @@ pub mod pallet {
|
|||||||
|
|
||||||
use serai_primitives::{NetworkId, Amount, PublicKey};
|
use serai_primitives::{NetworkId, Amount, PublicKey};
|
||||||
|
|
||||||
use validator_sets_pallet::{Config as VsConfig, Pallet as VsPallet};
|
use validator_sets_pallet::{primitives::Session, Config as VsConfig, Pallet as VsPallet};
|
||||||
use pallet_session::{Config as SessionConfig, SessionManager};
|
use pallet_session::{Config as SessionConfig, SessionManager};
|
||||||
|
|
||||||
#[pallet::error]
|
#[pallet::error]
|
||||||
pub enum Error<T> {
|
pub enum Error<T> {
|
||||||
StakeUnavilable,
|
StakeUnavilable,
|
||||||
|
NoDeallocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Event
|
// TODO: Event
|
||||||
@@ -76,7 +77,6 @@ pub mod pallet {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)] // TODO
|
|
||||||
fn deallocate_internal(account: &T::AccountId, amount: u64) -> Result<(), Error<T>> {
|
fn deallocate_internal(account: &T::AccountId, amount: u64) -> Result<(), Error<T>> {
|
||||||
Allocated::<T>::try_mutate(account, |allocated| {
|
Allocated::<T>::try_mutate(account, |allocated| {
|
||||||
if *allocated < amount {
|
if *allocated < amount {
|
||||||
@@ -150,7 +150,20 @@ pub mod pallet {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a function to reclaim deallocated funds
|
#[pallet::call_index(4)]
|
||||||
|
#[pallet::weight((0, DispatchClass::Operational))] // TODO
|
||||||
|
pub fn claim_deallocation(
|
||||||
|
origin: OriginFor<T>,
|
||||||
|
network: NetworkId,
|
||||||
|
session: Session,
|
||||||
|
) -> DispatchResult {
|
||||||
|
let account = ensure_signed(origin)?;
|
||||||
|
let Some(amount) = VsPallet::<T>::take_deallocatable_amount(network, session, account) else {
|
||||||
|
Err(Error::<T>::NoDeallocation)?
|
||||||
|
};
|
||||||
|
Self::deallocate_internal(&account, amount.0)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call order is end_session(i - 1) -> start_session(i) -> new_session(i + 1)
|
// Call order is end_session(i - 1) -> start_session(i) -> new_session(i + 1)
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ pub mod pallet {
|
|||||||
#[pallet::getter(fn keys)]
|
#[pallet::getter(fn keys)]
|
||||||
pub type Keys<T: Config> = StorageMap<_, Twox64Concat, ValidatorSet, KeyPair, OptionQuery>;
|
pub type Keys<T: Config> = StorageMap<_, Twox64Concat, ValidatorSet, KeyPair, OptionQuery>;
|
||||||
|
|
||||||
|
// TODO: Expand
|
||||||
#[pallet::event]
|
#[pallet::event]
|
||||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||||
pub enum Event<T: Config> {
|
pub enum Event<T: Config> {
|
||||||
|
|||||||
Reference in New Issue
Block a user