Skip to content

Implement the staking Contract's Staking, Rewards, and Unbonding Entrypoints #201

Open

Description

@dami-005

Description:
Reconstruct the staking crate from a non-compiling shell into a working Soroban contract with stake, unstake/unbond, and reward-claim entrypoints, matching whatever interface the crate's existing tests and callers imply.

Problem Statement & Context:
The task under way notes that the two newer crates staking and streams "currently fail to compile outright." Restoring them to a compiling state is being handled separately, but a stub that compiles provides no protocol functionality. staking matters because price_oracle feeder staking/slashing (covered elsewhere) and LP incentivization both depend on an actual staking primitive; without it those paths have nowhere to lock and reward.

Scope & Acceptance Criteria:

  • Entrypoints for stake, initiate-unbond (with any lock/cooldown the design requires), withdraw-after-cooldown, and claim rewards.
  • Correct accounting of per-staker principal and accrued rewards; no cross-staker leakage.
  • Admin surface to configure reward rate / reward source, gated via common::require_admin_or_multisig if common is adopted here.
  • Out of scope: any off-chain reward-funding tooling and frontend integration.

Implementation Guidelines:

  1. Key Files/Modules: staking/src/lib.rs, staking/src/types.rs/storage.rs (create if missing), common/ helpers, staking test module.
  2. Design/Architecture: typed persistent storage keyed by staker address for positions, plus a global reward-accumulator (index) so reward math is O(1) per action; keep math in a dedicated module.
  3. Edge Cases/Constraints: zero-amount stake/unstake, unstake before cooldown elapses, staking while a prior unbond is pending, reward-accumulator overflow, and storage TTL extension on every write.
  4. Testing: stake/unstake round-trip, two-staker reward-split correctness, cooldown enforcement, and unauthorized admin calls; assert no reward is claimable twice.

Definition of "Done":

  • Code written, tested, and documented.
  • All acceptance criteria met; crate compiles and its tests pass in CI.
  • PR submitted with a clear description, passing CI, relevant test output.
  • Code reviewed and approved.

Resources:

  • README.md, Cargo.toml (workspace membership).

Complexity: High (8 points)

Activity

  1. Dimank92 commented on Oct 28, 2026

    @Dimank92

    I have implemented the staking contract's entrypoints in PR #324.

    Implementation Summary

    • Reconstructed zenith-staking into a compiling and fully verified Soroban contract with entrypoints for:
      • stake, request_unstake, withdraw, claim_rewards, notify_reward
      • Admin surface: set_reward_rate, reward_rate (capped at 10,000 bps)
      • Cooldown management: set_cooldown, cooldown, with in-flight unbond safety
      • Emergency mode: set_emergency_unstake, emergency_unstake_enabled, and emergency_unstake (instant principal exit, pauses new stakes)
    • Added build = "../common/build_meta.rs", repository.workspace = true, and event-spec test dependency.
    • All 25 unit and event-spec tests pass (100% green).

    Unified payout wallet: 0xC345C07229307d4f1c7935aD2cAe48e390215808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions