Skip to main content

Overview

The UnstakingManager contract handles time-delayed withdrawals from StakingVaults. When a user withdraws from a vault with an unstaking delay, their tokens are held in this contract until the unlock time, after which they can be claimed.

Key Features

  • Time-Locked Withdrawals: Holds tokens until unlock time
  • Cancel Option: Users can cancel and re-stake before unlock
  • Simple Lock Management: Each withdrawal creates a numbered lock
  • Immutable Configuration: Tied to specific vault and token

Lock Structure

address
Address that owns the lock
uint256
Amount of tokens locked
uint256
Timestamp when lock becomes claimable
uint256
Timestamp when lock was claimed (0 if unclaimed)

Functions

Create Lock

Create a new time-locked withdrawal (called only by vault).
address
Address that will own the lock
uint256
Amount of tokens to lock
uint256
Timestamp when tokens become claimable
UnstakingManager.sol
Only the associated StakingVault can call this function. It’s automatically called during vault withdrawals.

Claim Lock

Claim tokens from an unlocked withdrawal.
uint256
ID of the lock to claim
UnstakingManager.sol
Anyone can call this function, but tokens are always sent to the lock’s original owner. The lock must be past its unlock time and not already claimed.

Cancel Lock

Cancel a lock and re-stake the tokens back into the vault.
uint256
ID of the lock to cancel
UnstakingManager.sol
This deposits the locked tokens back into the vault on behalf of the user. This is useful if the user changes their mind about unstaking or wants to avoid the waiting period.

View Functions

Get Lock Details

Retrieve information about a specific lock.
UnstakingManager.sol

Target Token

Get the token being managed.
UnstakingManager.sol

Vault

Get the associated StakingVault.
UnstakingManager.sol

Events

event
Emitted when a new lock is createdParameters:
  • lockId - Unique identifier for the lock
  • user - Address that owns the lock
  • amount - Amount of tokens locked
  • unlockTime - Timestamp when claimable
event
Emitted when a lock is cancelled and tokens are re-stakedParameters:
  • lockId - ID of the cancelled lock
event
Emitted when a lock is claimedParameters:
  • lockId - ID of the claimed lock

Errors

error
Thrown when caller is not authorized for the operation
error
Thrown when trying to claim before unlock time
error
Thrown when trying to claim or cancel an already-claimed lock

Usage Flow

Standard Unstaking

Cancel and Re-stake

Security Considerations

The UnstakingManager is automatically deployed by the StakingVault during initialization. The vault address is immutable and set in the constructor.
Locks cannot be transferred or traded. They are permanently tied to the original user address.

Lock ID Sequence

uint256
Counter that increments for each new lock, starting at 0
Lock IDs are sequential starting from 0 and increment with each new lock creation. Once a lock is claimed or cancelled, its ID is not reused.