Overview
Earn mode enables users to deposit into DeFi protocols for yield generation and staking. It supports both pre-integrated protocols (Aave, Morpho) and custom contract integrations with arbitrary calldata.Configuration
Required Props
| Prop | Type | Description |
|---|---|---|
mode | "earn" | Sets the widget to earn mode |
Required Props (Custom Protocol Integration)
| Prop | Type | Description |
|---|---|---|
toAddress | string | Protocol contract address |
toChainId | number | Protocol’s chain ID |
toToken | string | Token to deposit |
toCalldata | string | Encoded function call |
Optional Props (Custom Integration)
| Prop | Type | Description |
|---|---|---|
toAmount | string | Fixed deposit amount |
slippageTolerance | string | number | Slippage tolerance |
Implementation
Protocol Selection Widget
Use pre-integrated protocols (Aave, Morpho, etc.):Fixed Amount Protocol Deposit
Deposit a specific amount into a protocol:Dynamic Amount Deposits
Use placeholder amount for user-selected deposit amounts:ERC-4626 Vault Deposit
Standard vault deposit pattern:Calldata Patterns
When to Use TRAILS_CONTRACT_PLACEHOLDER_AMOUNT
Use the placeholder when:- Deposit amount is a function parameter
- User selects the deposit amount
- Amount needs to reflect post-swap/bridge value
When Static Values Work
Use static values when:- Function doesn’t take amount as parameter
- Amount is fixed and known in advance
- Contract reads balance internally
Protocol-Specific Examples
Aave V3 Deposit
Morpho Vault Deposit
Yearn Vault Deposit
Liquid Staking (Lido)
Event Handling
Supported Protocols
Pre-integrated
Trails has built-in support for:- Aave V3: Lending and borrowing across multiple chains
- Morpho: Optimized lending pools
Custom Integration
Any protocol with a deposit/stake function can be integrated:- Yearn Finance vaults
- Compound V3
- Convex Finance
- Curve pools
- Custom staking contracts
- Any ERC-4626 vault
Use Cases
- Lending Protocol Deposits: Supply assets to earn interest (Aave, Compound, Morpho)
- Yield Vault Deposits: Deposit into automated yield strategies (Yearn)
- Liquid Staking: Stake ETH while maintaining liquidity (Lido, Rocket Pool)
- LP Token Staking: Stake LP tokens in farming contracts
- Governance Staking: Lock tokens for governance rights
- Auto-compounding Vaults: Deposit into vaults that auto-compound rewards
Technical Notes
- Earn mode handles token approvals automatically
- Supports both ERC-20 tokens and native tokens (ETH, MATIC, etc.)
- All cross-chain swapping and bridging is handled
- Calldata execution is atomic with the deposit
TRAILS_CONTRACT_PLACEHOLDER_AMOUNT=uint256.maxinternally- Works with any contract that has
onBehalfOforreceiverparameter
Error Handling
See Also
- Use Case Examples - DeFi protocol integration examples
- Hooks Reference -
TRAILS_CONTRACT_PLACEHOLDER_AMOUNTconstant - Fund Mode - Similar input-driven flow patterns
- Configuration - Full configuration options