Skip to main content

StakingManager

Struct StakingManager 

Source
pub struct StakingManager { /* private fields */ }
Expand description

Staking manager

Manages staking for validators and service providers.

Implementations§

Source§

impl StakingManager

Source

pub fn new() -> Self

Creates a new staking manager

Source

pub fn with_storage(storage: Arc<dyn KvStore>) -> Self

Creates a new staking manager with persistent storage

Source

pub fn stake( &self, staker: Address, amount: u128, provider_type: ProviderType, ) -> Result<()>

Stakes tokens for a provider

§Arguments
  • staker - Address staking
  • amount - Amount to stake
  • provider_type - Type of provider
Source

pub fn unstake(&self, staker: &Address) -> Result<()>

Initiates unstaking (starts unbonding period)

§Arguments
  • staker - Address unstaking
Source

pub fn withdraw(&self, staker: &Address) -> Result<u128>

Completes withdrawal after unbonding period

§Arguments
  • staker - Address withdrawing stake

Returns the withdrawn amount

Source

pub fn slash( &self, staker: &Address, amount: u128, reason: String, slashed_by: Address, ) -> Result<()>

Slashes a stake

§Arguments
  • staker - Address to slash
  • amount - Amount to slash
  • reason - Reason for slashing
  • slashed_by - Address performing the slash

Note: Slashing enforces the minimum unbonding period. The slashed stake cannot be withdrawn until the full unbonding period has elapsed from the slash event, even if it was already unbonding.

Source

pub fn restore_slashed_stake( &self, staker: &Address, amount: u128, proposal_id: String, reason: String, authorized_by: Address, ) -> Result<()>

Restores previously-slashed stake under governance authorization.

This is intended for the rare case where the protocol slashed a validator due to a bug (e.g., the equivocation cascade at view=62 on 2026-04-27 caused by a missing persistent vote-state, not Byzantine intent). The restoration must be authorized by an on-chain governance proposal — proposal_id is required and recorded on the audit trail. The caller is responsible for verifying the proposal has passed and that authorized_by is the legitimate executor of that proposal; this manager does not own governance state.

§Arguments
  • staker - Address whose stake is being restored
  • amount - Amount to add back to the stake
  • proposal_id - Governance proposal authorizing the restoration (non-empty; required for audit)
  • reason - Human-readable reason
  • authorized_by - Address executing the restoration (typically the governance executor / treasury multisig)
§Errors
  • Unauthorized if proposal_id is empty.
  • InvalidAmount if amount is zero or exceeds the total previously-slashed amount on this stake (cannot restore more than was slashed).
  • StakeNotFound if no stake exists for staker.
  • ArithmeticOverflow on amount overflow.
Source

pub fn freeze_stake(&self, staker: &Address) -> Result<()>

Freezes a stake under kill-switch authority (Agent-Swarm Spec 1).

Called by the node post-execute scan when a KillSwitchPause or KillSwitchQuarantine log is observed for the machine DID that owns this stake address. While frozen, unstake, withdraw, and reward accrual (add_rewards) are rejected. Idempotent — freezing an already-frozen stake is a no-op.

slash is intentionally NOT gated by lifecycle_freeze: the terminate flow must be able to slash a frozen stake.

Source

pub fn thaw_stake(&self, staker: &Address) -> Result<()>

Thaws a previously-frozen stake (Agent-Swarm Spec 1).

Called by the node post-execute scan when a ResumedFromPause or ResumedFromQuarantine log is observed. Idempotent — thawing an already-thawed stake is a no-op.

Source

pub fn get_stake(&self, staker: &Address) -> Option<StakeInfo>

Returns stake information for an address

Source

pub fn get_total_staked(&self, provider_type: ProviderType) -> u128

Returns total staked for a provider type

Source

pub fn get_total_staked_all(&self) -> u128

Returns total staked across all provider types

Source

pub fn total_slashed(&self) -> u128

Returns the cumulative slash burn across all stakes, net of any governance restorations. Computed by summing slashing_history and subtracting restore_history per stake.

Saturating arithmetic — u128 can hold the full TNZO supply (1B scaled by 1e18) many times over, so an overflow here would indicate data corruption rather than legitimate flow. Consumed by the adaptive-burn observer at every epoch boundary to populate BurnBreakdown.slash.

Source

pub fn set_min_stake(&self, min_stake: u128)

Updates minimum stake requirement

Source

pub fn set_unbonding_period(&self, period_ms: i64)

Updates unbonding period

Source

pub fn get_all_stakes(&self) -> Vec<(Address, StakeInfo)>

Returns all active stakes

Trait Implementations§

Source§

impl Debug for StakingManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StakingManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more