Skip to main content

Staking for Other Accounts

Introduction

The stakeOnBehalf 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.

Key Differences from Existing Staking Methods

stake() vs delegateStake() vs stakeOnBehalf()

Key Distinction: With 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

  1. Clear Permissions: Ensure users understand who can stake on their behalf
  2. Event Logging: Emit comprehensive events for transparency
  3. Gas Efficiency: Use batch operations when possible
  4. Error Handling: Implement proper error handling and revert messages
  5. Documentation: Clearly document the trust model and permissions
Contract References: Integration Guides: