Staking for Other Accounts
Introduction
ThestakeOnBehalf function in Reward Vaults allows any account to stake tokens directly for another account without requiring delegation permissions. This feature enables new integration patterns and simplifies certain protocol workflows.
::: tip User Guide Available
For end users wanting to understand how protocols can claim BGT on their behalf, see the BGT claiming guide.
:::
Key Differences from Existing Staking Methods
stake() vs delegateStake() vs stakeOnBehalf()
| Method | Who Stakes | Who Owns Tokens | Who Controls Staked Balance | Use Case |
|---|---|---|---|---|
stake() | Account holder | Account holder | Account holder | Direct user staking |
delegateStake() | Delegate/Protocol | Delegate/Protocol | Delegate can withdraw | Protocol staking with control |
stakeOnBehalf() | Any account | Staker | Account holder | Protocol staking without control |
stakeOnBehalf, the staking account provides the tokens, but the beneficiary account gains full control over the staked balance and can withdraw at any time.
Use Cases
1. Protocol-to-Protocol Integrations
Protocols can stake tokens for users as part of their core functionality:2. Automated Staking Services
Services can automatically stake newly acquired tokens for users:3. Custodial Solutions
Custodial services can stake on behalf of their customers while maintaining user ownership:Implementation Examples
Basic Integration
Advanced Integration with Access Control
Security Considerations
1. Token Approval Management
Always ensure proper token approvals and consider using safe approval patterns:2. Access Control
Implement appropriate access controls for who can stake on behalf of others:3. Front-Running Protection
Consider implementing protection against front-running in sensitive operations:Gas Optimization Tips
1. Batch Operations
When staking for multiple users, batch operations to save gas:2. Pre-approved Contracts
For frequent operations, consider pre-approving maximum amounts:Interface Definition
Integration Examples
Viem Integration
EthersJS Integration
Foundry Testing Example
Deployment Script
Best Practices
- Clear Permissions: Ensure users understand who can stake on their behalf
- Event Logging: Emit comprehensive events for transparency
- Gas Efficiency: Use batch operations when possible
- Error Handling: Implement proper error handling and revert messages
- Documentation: Clearly document the trust model and permissions
Related Documentation
Contract References:- Reward Vault Contract - Complete API documentation
stakeOnBehalffunction - Function reference
- Advanced PoL Integration - Non-ERC20 protocols
- PoL Integration Quickstart - Getting started
- Partial Reward Claims - Complementary feature
- BGT Claiming Guide - End user perspective on protocol claiming