Stakinator Technical Details

The Stakinator Facet is a core component of the Vaultinator Protocol that provides staking functionality. This document outlines the technical implementation details, including the contract architecture, function specifications, storage layout, and security considerations.

Contract Architecture

The Stakinator Facet follows the Diamond Standard (EIP-2535) pattern and is implemented as a facet that can be added to the Vaultinator Diamond. It manages staking pools and user stakes through a standardized interface.

Class Diagram

┌─────────────────┐      ┌───────────────────┐      ┌───────────────────┐
│  VaultinatorFacet│◄─────┤  StakinatorFacet  │─────►│  YieldinatorFacet │
└─────────────────┘      └───────────────────┘      └───────────────────┘
         ▲                         │                          ▲
         │                         │                          │
         │                         ▼                          │
┌─────────────────┐      ┌───────────────────┐      ┌───────────────────┐
│  DiamondStorage  │◄─────┤StakinatorStorage  │─────►│CollatinatorFacet  │
└─────────────────┘      └───────────────────┘      └───────────────────┘


                          ┌───────────────────┐
                          │    Pool Registry   │
                          └───────────────────┘


                          ┌───────────────────┐
                          │   Staking Adapters │
                          └───────────────────┘


                          ┌───────────────────┐
                          │ Staking Protocols  │
                          └───────────────────┘

Component Interaction

  1. Stakinator Facet: The main contract that implements the staking functionality

  2. Pool Registry: A registry of staking pools that the Stakinator manages

  3. Staking Adapters: Standardized adapters for interacting with different staking protocols

  4. Staking Protocols: External protocols that provide staking services

Function Specifications

Pool Management

Creates a new staking pool.

  • Parameters:

    • stakingToken: The address of the token to stake

    • rewardToken: The address of the token used for rewards

    • apr: The annual percentage rate in basis points (1/100 of a percent)

    • minStake: The minimum amount that can be staked

    • maxStake: The maximum amount that can be staked

    • lockDuration: The minimum lock duration in seconds

  • Returns: The ID of the created pool

  • Access Control: Only administrators can call this function

  • Events Emitted: PoolCreated(uint256 indexed poolId, address stakingToken, address rewardToken, uint256 apr, uint256 lockDuration)

Updates an existing staking pool.

  • Parameters:

    • poolId: The ID of the pool to update

    • apr: The new annual percentage rate in basis points

    • minStake: The new minimum stake amount

    • maxStake: The new maximum stake amount

    • lockDuration: The new minimum lock duration in seconds

  • Returns: bool indicating success

  • Access Control: Only administrators can call this function

  • Events Emitted: PoolUpdated(uint256 indexed poolId, uint256 apr, uint256 minStake, uint256 maxStake, uint256 lockDuration)

Deactivates a staking pool, preventing new stakes but allowing existing stakes to continue.

  • Parameters:

    • poolId: The ID of the pool to deactivate

  • Returns: bool indicating success

  • Access Control: Only administrators can call this function

  • Events Emitted: PoolDeactivated(uint256 indexed poolId)

Gets information about a staking pool.

  • Parameters:

    • poolId: The ID of the pool

  • Returns: A Pool struct containing information about the pool

  • Access Control: Anyone can call this function

Gets a list of all staking pool IDs.

  • Returns: An array of pool IDs

  • Access Control: Anyone can call this function

Staking Operations

Stakes tokens in a pool.

  • Parameters:

    • poolId: The ID of the pool to stake in

    • amount: The amount of tokens to stake

    • lockDuration: The lock duration in seconds

  • Returns: The ID of the created stake

  • Access Control: Anyone can call this function

  • Events Emitted: Staked(uint256 indexed stakeId, address indexed owner, uint256 indexed poolId, uint256 amount, uint256 lockDuration)

Unstakes tokens from a pool after the lock period has ended.

  • Parameters:

    • stakeId: The ID of the stake to unstake

  • Returns: The amount of tokens unstaked

  • Access Control: Only the stake owner can call this function

  • Events Emitted: Unstaked(uint256 indexed stakeId, uint256 amount)

Claims rewards for a stake.

  • Parameters:

    • stakeId: The ID of the stake to claim rewards for

  • Returns: The amount of rewards claimed

  • Access Control: Only the stake owner can call this function

  • Events Emitted: RewardsClaimed(uint256 indexed stakeId, uint256 amount)

Extends the lock duration of a stake.

  • Parameters:

    • stakeId: The ID of the stake

    • newLockDuration: The new lock duration in seconds

  • Returns: bool indicating success

  • Access Control: Only the stake owner can call this function

  • Events Emitted: LockExtended(uint256 indexed stakeId, uint256 newLockDuration)

Vault Integration

Stakes tokens from a vault in a pool.

  • Parameters:

    • vaultId: The ID of the vault

    • poolId: The ID of the pool to stake in

    • amount: The amount of tokens to stake

    • lockDuration: The lock duration in seconds

  • Returns: The ID of the created stake

  • Access Control: Only vault owners or authorized users can call this function

  • Events Emitted: VaultStaked(uint256 indexed vaultId, uint256 indexed stakeId, uint256 indexed poolId, uint256 amount, uint256 lockDuration)

Unstakes tokens and sends them to a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • stakeId: The ID of the stake to unstake

  • Returns: The amount of tokens unstaked

  • Access Control: Only vault owners or authorized users can call this function

  • Events Emitted: VaultUnstaked(uint256 indexed vaultId, uint256 indexed stakeId, uint256 amount)

Claims rewards for a stake and sends them to a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • stakeId: The ID of the stake to claim rewards for

  • Returns: The amount of rewards claimed

  • Access Control: Only vault owners or authorized users can call this function

  • Events Emitted: VaultRewardsClaimed(uint256 indexed vaultId, uint256 indexed stakeId, uint256 amount)

Information and Metrics

Gets information about a stake.

  • Parameters:

    • stakeId: The ID of the stake

  • Returns: A Stake struct containing information about the stake

  • Access Control: Anyone can call this function

Gets a list of all stake IDs for a user.

  • Parameters:

    • user: The address of the user

  • Returns: An array of stake IDs

  • Access Control: Anyone can call this function

Gets the estimated rewards for a stake.

  • Parameters:

    • stakeId: The ID of the stake

  • Returns: The estimated rewards

  • Access Control: Anyone can call this function

Gets the total value locked in a pool.

  • Parameters:

    • poolId: The ID of the pool

  • Returns: The total value locked

  • Access Control: Anyone can call this function

Gets the total value staked across all pools.

  • Returns: The total value staked

  • Access Control: Anyone can call this function

Gets the total rewards distributed across all pools.

  • Returns: The total rewards distributed

  • Access Control: Anyone can call this function

Emergency Operations

Performs an emergency unstake, which may incur a penalty.

  • Parameters:

    • stakeId: The ID of the stake to unstake

  • Returns: The amount of tokens unstaked

  • Access Control: Only the stake owner can call this function

  • Events Emitted: EmergencyUnstaked(uint256 indexed stakeId, uint256 amount, uint256 penalty)

Pauses all Stakinator operations.

  • Returns: bool indicating success

  • Access Control: Only administrators can call this function

  • Events Emitted: StakinatorPaused(address indexed admin)

Unpauses all Stakinator operations.

  • Returns: bool indicating success

  • Access Control: Only administrators can call this function

  • Events Emitted: StakinatorUnpaused(address indexed admin)

Storage Layout

The Stakinator Facet uses the Diamond Storage pattern to store its state. The storage layout is defined in the LibStakinatorStorage library.

Events

The Stakinator Facet emits the following events:

Security Considerations

Reentrancy Protection

The Stakinator Facet uses a reentrancy guard to prevent reentrancy attacks. All external functions that interact with other contracts are protected by the reentrancy guard.

Access Control

The Stakinator Facet uses role-based access control to restrict access to certain functions. The access control is implemented through the Vaultinator Facet.

Pause Mechanism

The Stakinator Facet includes a pause mechanism that allows administrators to pause all operations in case of an emergency.

Lock Period Enforcement

The Stakinator Facet enforces lock periods for stakes. Users cannot unstake their tokens until the lock period has ended.

Emergency Unstake

The Stakinator Facet includes an emergency unstake function that allows users to unstake their tokens before the lock period has ended, but with a penalty.

Reward Calculation

The Stakinator Facet uses a time-based reward calculation to ensure that rewards are distributed fairly.

Integration with Other Facets

The Stakinator Facet integrates with other facets in the Vaultinator Protocol:

  1. Vaultinator Facet: For vault management and access control

  2. Yieldinator Facet: For staking yield-generating assets

  3. Collatinator Facet: For using staked assets as collateral

Vaultinator Integration

Yieldinator Integration

Collatinator Integration

Staking Strategies

The Stakinator Facet supports multiple staking strategies:

Fixed APR Staking

Fixed APR staking provides a guaranteed return on staked assets, regardless of external factors.

Variable APR Staking

Variable APR staking provides a return that varies based on external factors, such as protocol performance.

Tiered Staking

Tiered staking provides different APRs based on the amount staked and the lock duration.

Boosted Staking

Boosted staking provides increased rewards for users who also stake a secondary token.

Conclusion

The Stakinator Facet is a powerful component of the Vaultinator Protocol that enables users to stake tokens and earn rewards. Its modular design, security features, and integration with other facets make it a flexible and robust solution for staking.