pub struct StakingManager { /* private fields */ }Expand description
Staking manager
Manages staking for validators and service providers.
Implementations§
Source§impl StakingManager
impl StakingManager
Sourcepub fn with_storage(storage: Arc<dyn KvStore>) -> Self
pub fn with_storage(storage: Arc<dyn KvStore>) -> Self
Creates a new staking manager with persistent storage
Sourcepub fn stake(
&self,
staker: Address,
amount: u128,
provider_type: ProviderType,
) -> Result<()>
pub fn stake( &self, staker: Address, amount: u128, provider_type: ProviderType, ) -> Result<()>
Stakes tokens for a provider
§Arguments
staker- Address stakingamount- Amount to stakeprovider_type- Type of provider
Sourcepub fn withdraw(&self, staker: &Address) -> Result<u128>
pub fn withdraw(&self, staker: &Address) -> Result<u128>
Completes withdrawal after unbonding period
§Arguments
staker- Address withdrawing stake
Returns the withdrawn amount
Sourcepub fn slash(
&self,
staker: &Address,
amount: u128,
reason: String,
slashed_by: Address,
) -> Result<()>
pub fn slash( &self, staker: &Address, amount: u128, reason: String, slashed_by: Address, ) -> Result<()>
Slashes a stake
§Arguments
staker- Address to slashamount- Amount to slashreason- Reason for slashingslashed_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.
Sourcepub fn restore_slashed_stake(
&self,
staker: &Address,
amount: u128,
proposal_id: String,
reason: String,
authorized_by: Address,
) -> Result<()>
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 restoredamount- Amount to add back to the stakeproposal_id- Governance proposal authorizing the restoration (non-empty; required for audit)reason- Human-readable reasonauthorized_by- Address executing the restoration (typically the governance executor / treasury multisig)
§Errors
Unauthorizedifproposal_idis empty.InvalidAmountifamountis zero or exceeds the total previously-slashed amount on this stake (cannot restore more than was slashed).StakeNotFoundif no stake exists forstaker.ArithmeticOverflowon amount overflow.
Sourcepub fn freeze_stake(&self, staker: &Address) -> Result<()>
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.
Sourcepub fn thaw_stake(&self, staker: &Address) -> Result<()>
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.
Sourcepub fn get_stake(&self, staker: &Address) -> Option<StakeInfo>
pub fn get_stake(&self, staker: &Address) -> Option<StakeInfo>
Returns stake information for an address
Sourcepub fn get_total_staked(&self, provider_type: ProviderType) -> u128
pub fn get_total_staked(&self, provider_type: ProviderType) -> u128
Returns total staked for a provider type
Sourcepub fn get_total_staked_all(&self) -> u128
pub fn get_total_staked_all(&self) -> u128
Returns total staked across all provider types
Sourcepub fn total_slashed(&self) -> u128
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.
Sourcepub fn set_min_stake(&self, min_stake: u128)
pub fn set_min_stake(&self, min_stake: u128)
Updates minimum stake requirement
Sourcepub fn set_unbonding_period(&self, period_ms: i64)
pub fn set_unbonding_period(&self, period_ms: i64)
Updates unbonding period
Sourcepub fn get_all_stakes(&self) -> Vec<(Address, StakeInfo)>
pub fn get_all_stakes(&self) -> Vec<(Address, StakeInfo)>
Returns all active stakes