Contract
Overview
The smart contract system consists of three main components that work together to provide liquid staking functionality:
- StakeManager: The core contract that manages staking operations and validator management
- StakePool: The intermediary contract that handles fund management and cross-chain operations
- LsdToken: The liquid staking derivative token contract
StakeManager
The StakeManager contract is the central component that oversees all staking operations. It implements several key features:
Key Features
- Manages validator sets and their operations
- Handles staking rate calculations and updates
- Distributes staking rewards and protocol fees
- Manages era-based operations and updates
- Controls stake pool operations
Core Functions
stake()
: Allows users to stake tokens and receive LSD tokens in returnunstake()
: Enables users to unstake their LSD tokenswithdraw()
: Allows users to withdraw their unstaked tokensnewEra()
: Updates the staking era and calculates new ratesaddValidator()
/rmValidator()
: Manages validator setsstartRedelegate()
: Handles validator redelegation
Security Features
- Implements upgradeable proxy pattern (UUPS)
- Uses role-based access control
- Includes rate limiting and validation checks
- Implements emergency functions for critical situations
StakePool
The StakePool contract acts as an intermediary between stakers and the staking program, handling:
Key Features
- Manages cross-chain operations
- Handles delegation and undelegation of tokens
- Tracks pending operations and balances
- Implements settlement and redelegation processes
Core Functions
delegate()
: Delegates tokens to validatorsundelegate()
: Undelegates tokens from validatorsstartSettle()
: Initiates settlement processstartRedelegate()
: Handles redelegation between validatorswithdrawForStaker()
: Processes withdrawals for stakers
Cross-Chain Operations
settle()
: Initiates the settlement process, moving through different states (Start, BridgedToL1, CDeposited, Delegated, Undelegated, Withdrawn, End)sendDeposit()
: Sends deposited tokens to the L1 chainsendDelegate()
: Sends delegation instructions to validators on L1sendWithdraw()
: Initiates withdrawal process from L1endSettle()
: Completes the settlement process after all operations are donesendL1ToEvm()
: Bridges tokens from L1 back to EVM chain
State Management
- Tracks total pending delegations and undelegations
- Manages settlement and redelegation statuses
- Maintains spot balance and delegation information
- Handles cross-chain bridge operations
LsdToken
The LsdToken contract represents the liquid staking derivative token with the following features:
Key Features
- Implements ERC20 standard with burnable functionality
- Tracks staked positions and rewards
- Provides rate information for staking operations
- Manages token minting and burning
Core Functions
mint()
: Creates new LSD tokens (restricted to minter which is StakeManager)burn()
: Burns LSD tokensgetRate()
: Provides current staking rateupdateMinter()
: Updates the minter address
Integration
- Integrates with StakeManager for rate information
- Provides rate information to external protocols
- Maintains token supply and balance tracking
Contract Interactions
The contracts work together in the following way:
- Users interact with StakeManager to stake/unstake tokens
- StakeManager coordinates with StakePool for delegation operations
- StakePool handles cross-chain operations and validator interactions
- LsdToken represents the staked position and can be used in DeFi applications
- Era-based updates ensure proper rate calculations and reward distribution
Security Considerations
- All contracts implement upgradeable patterns for future improvements
- Strict access control is enforced through modifiers
- Critical operations have validation checks and error handling
- Cross-chain operations include safety checks and status tracking
- Emergency functions are available for critical situations