🧭leader
Struct LeaderCapabilitiesAdminCap
Admin capability for modifying the allowlist in [CapabilityManger].
Struct CapabilityManger
Leader capability issuer state stored inside [LeaderRegistry].
Struct LeaderRegistry
Shared registry for leader operator records and pooled stake.
This is intended to be created once (by the workflow package initializer) and shared.
Struct LeaderRegistryInnerV1
Version one stored layout for [LeaderRegistry].
Struct StakeManager
Per-leader stake accounting (stored inside [Leader]).
Struct StakePosition
Per-(leader, staker) stake position.
Pending shares remain exposed to slashing because they still participate in the pool.
Struct Metadata
Arbitrary operator-provided metadata for a leader record.
This module does not interpret these values. The only enforced constraint is a size bound: bcs::to_bytes(&meta).length() <= MAX_META_LEN.
Struct Leader
Per-leader record stored in [LeaderRegistry].
The record is keyed by the leader's capability ID (ID) inside the registry table.
Struct LeaderRegistryCreatedEvent
Emitted when a new [LeaderRegistry] is created.
Struct LeaderUpsertedEvent
Emitted when a leader record is created or updated via [upsert_self].
Struct LeaderCapIssuedEvent
Emitted when a leader capability is issued and transferred.
This is the authoritative off-chain signal that a new leader cap ID exists for this registry/network.
Struct LeaderStatusChangedEvent
Emitted when a leader's status changes, e.g. via [set_status], a suspension through [suspend_if_token], or a Suspended -> Active transition in [activate_and_claim].
Struct LeaderClaimedEvent
Emitted when a leader claims (or re-claims) ownership of the Active state via [activate_and_claim]. claim_token is the activating transaction's own digest.
Struct LeaderSuspensionSkippedEvent
Emitted when [suspend_if_token] is called by an instance that does not own the current Active state (the presented token does not match the one on record). The suspension is skipped.
Struct UnbondingDurationUpdatedEvent
Emitted when the registry's unbonding duration is updated.
Struct MinStakeUsUpdatedEvent
Emitted when the registry's minimum eligible stake is updated.
Struct MaxTransactionBudgetUpdatedEvent
Emitted when the registry's per-transaction max budget is updated.
Struct StakeDepositedEvent
Emitted when stake is deposited into a leader pool and shares are minted.
Struct UnstakeRequestedEvent
Emitted when a staker requests an unstake, locking shares until the unlock time.
Struct UnstakeClaimedEvent
Emitted when a staker claims a matured unstake and receives the withdrawn US.
Struct StakeSlashedEvent
Emitted when a leader's pooled stake is slashed.
Enum LeaderStatus
Leader liveness/eligibility status.
Constants
Maximum metadata length (bytes).
Default unbonding duration (in ms). This is a placeholder default.
Bootstrap minimum stake (in $US base units) required for leader eligibility. The maximum u64 value is a fail-closed sentinel, not an economic policy. The protocol owner must set the intended policy before registering leaders.
Default maximum budget (in MIST) a leader may spend on a single transaction.
Minimum maximum-transaction-budget (in MIST) that can be configured (1 SUI).
Function unbonding_duration_ms
Returns the registry's unbonding delay (in milliseconds) for stake withdrawals.
Function min_stake_us
Returns the minimum stake (in US base units) a leader needs to be eligible for ranking.
Function max_transaction_budget
Returns the maximum budget (in MIST) a leader may spend on a single transaction.
Function assert_transaction_budget
Verifies that one reimbursed transaction respects the registry gas ceiling. It aborts with ETransactionBudgetExceeded before the caller mutates payment or scheduler state.
Function network_id
Returns the network ID shared by all leader capabilities issued by this registry.
Function leader_stamp_id
Anyone can query the expected stamp ID (for tool configuration). This is the same as the registry's object ID.
Function status_active
Returns the Active leader status value.
Function status_suspended
Returns the Suspended leader status value.
Function status_slashed
Returns the Slashed leader status value.
Function new_metadata
Creates a metadata container from pre-defined key/value pairs.
Function empty_metadata
Returns an empty metadata container.
Function exists
Returns whether a leader record exists for the given capability ID.
Function assert_registered
Aborts with [ELeaderNotRegistered] unless a record exists for the capability ID.
Function assert_execution_inputs_allowed
Aborts when any execution input references an issued LeaderCap.
Function assert_output_objects_allowed
Aborts when any explicit output Object field references an issued LeaderCap.
Function status
Returns the current status of a leader record.
Aborts with [ELeaderNotFound] if the leader has no record.
Function claim_token
Returns the current ownership claim token for a leader record.
Aborts with [ELeaderNotFound] if the leader has no record.
Function is_active
Returns whether a leader record exists and has status Active.
Function is_eligible
Returns whether a leader is active and sufficiently staked.
Function assert_active
Asserts that a leader is active.
Aborts with [ELeaderNotActive] if the leader is missing or not active.
Function metadata
Returns the metadata for a leader record.
Aborts with [ELeaderNotFound] if the leader has not registered a record.
Function metadata_data
Convenience getter for the underlying key/value map inside [Metadata].
Function leader_pool_total
Returns the total pooled stake (in US base units) backing a leader.
Aborts with [ELeaderNotFound] if the leader has no record.
Function leader_total_shares
Returns the total stake shares outstanding for a leader.
Aborts with [ELeaderNotFound] if the leader has no record.
Function staker_active_shares
Returns a staker's active (non-pending) shares in a leader pool, or 0 if none.
Aborts with [ELeaderNotFound] if the leader has no record.
Function staker_pending_shares
Returns a staker's pending (unstake-locked) shares in a leader pool, or 0 if none.
Aborts with [ELeaderNotFound] if the leader has no record.
Function staker_total_shares
Returns a staker's total (active plus pending) shares in a leader pool.
Aborts with [ELeaderNotFound] if the leader has no record.
Function staker_value
Current stake value (in US base units) for a staker in the given leader pool.
Returns 0 if either:
the leader has no shares, or
the staker has no shares.
Function upsert_self
Upsert the sender's leader record.
Requires a leader capability for this workflow instance.
Behavior:
Keyed by
object::id(leader_cap).leader_capmust belong to this registry network.Updates metadata for an existing record when called by the holder of the leader cap.
Enforces a size bound on
metaviabcs::to_bytes(&meta)(see [MAX_META_LEN]).
Function stake
Stake amount in $US base units into a leader's pool.
Anyone can stake into any active leader. Staking mints shares for the caller based on the current pool value and total shares.
Function request_unstake
Request to unstake amount in $US base units from a leader pool.
Deposits mint amount × total_shares / pool shares using floor division (or one share per base unit for an empty pool), so they never mint more value than deposited. This withdrawal request locks ceil(amount × total_shares / pool) shares, ensuring the pending share amount covers the requested withdrawal at the current price. It then moves those shares from the caller's active position into a pending position and records the request timestamp.
Function assert_leader_cap_matches_registry
Function assert_current_leader_cap
Asserts that the concrete leader capability belongs to and is currently listed by this registry.
Function rank_active_leaders_uniform
Return the top-2 leaders from a uniform deterministic ranking over all active leaders in this registry.
Aborts with [EEmptyLeaderSet] if there are no eligible leaders (see [is_eligible]). If exactly one eligible leader remains, it is duplicated to produce a length-2 result.
Function rank_active_leaders_stake_weighted
Return the top-2 leaders from a stake-weighted deterministic ranking over all active leaders in this registry.
Aborts with [EEmptyLeaderSet] if there are no eligible leaders (see [is_eligible]). If exactly one eligible leader remains, it is duplicated to produce a length-2 result.
Function stamp_workflow_worksheet
Stamps a worksheet with this registry through the current runtime authority.
Function activate_and_claim
Activate a leader and claim ownership of its Active state.
Sets status = Active and writes a fresh ownership token = the activating transaction's own digest (*ctx.digest()), which Sui guarantees is globally unique. The off-chain instance learns this digest from the transaction receipt and remembers it, so it can later prove ownership when suspending.
Aborts with [ELeaderSlashed] if the leader is Slashed (the only abort path); a slashed leader can never reclaim. Aborts with [ELeaderNotFound] if no record exists.
Function suspend_if_token
Suspend a leader only if the caller still owns the current Active state.
This never aborts on a mismatch — the expected race during a rolling restart (a departing instance that no longer owns the record) must be a cheap no-op, not an abort, because the shutdown suspend runs inside a bounded time budget.
Behavior:
returns
false(no-op) ifstatus!= Active;if
claim_token== token: setsSuspended, emits [LeaderStatusChangedEvent], returnstrue;otherwise: emits [LeaderSuspensionSkippedEvent] and returns
false.
Does not clear claim_token; the next activation overwrites it. Aborts with [ELeaderNotFound] if no record exists.
Function set_unbonding_duration_ms
Set the unbonding duration (in milliseconds) applied to [request_unstake].
This is an administrative action gated by the leader capabilities admin cap.
Function set_min_stake_us
Set the minimum stake (in US base units) required for leader eligibility.
This is an administrative action gated by the leader capabilities admin cap.
Function set_max_transaction_budget
Set the maximum budget (in MIST) a leader may spend on a single transaction.
This is an administrative action gated by the leader capabilities admin cap. Aborts with [EMaxTransactionBudgetTooLow] if the new value is below [MIN_TRANSACTION_BUDGET_MIST].
Function slash_stake
Slash stake for a leader. Returns the slashed balance to the caller.
Slashing reduces the leader pool and therefore reduces share value for all stakers.
Function allow_address
Allow [address] to request capabilities from this registry.
Function disallow_address
Revoke [address] from requesting capabilities.
Function request_leader_cap
Clone and transfer a leader capability to the sender.
The sender must be in the capabilities allowlist.
Function register
Register the sender as a leader in a single atomic flow:
clone and transfer [leader_cap::OverNetwork],
create the leader record,
store metadata and stake.
Requirements:
sender is in the capabilities allowlist.
amount >=min_stake_us(self)(eligible on registration).
Last updated

