Skip to main content

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.
Earn mode includes both deposit and withdrawal tabs. To deep-link users directly into withdrawals, use Withdraw mode.

Quick start

Pre-configure the destination protocol:

Props

Required

Destination (optional)

Source (optional)

The from shape is a discriminated union on paymentMethod. Crypto source (paymentMethod is "CONNECTED_WALLET", "EXCHANGE", "CRYPTO_TRANSFER", or omitted): Fiat source (paymentMethod is "CREDIT_DEBIT_CARD"):

Payment method (optional)

paymentMethod controls how the user sources funds:

Lifecycle callbacks

Examples

Protocol selection — user picks everything

Fixed amount protocol deposit

Deposit 1 USDC into Aave V3 on Arbitrum:

ERC-4626 vault with dynamic amount

Use TRAILS_ROUTER_PLACEHOLDER_AMOUNT when the deposit amount is a parameter and the user selects it:
Use TRAILS_ROUTER_PLACEHOLDER_AMOUNT when:
  • Deposit amount is a function parameter
  • User selects the deposit amount
  • Amount needs to reflect post-swap/bridge output
Do not use it for functions that read balance internally (e.g. depositAll()).

Composable actions (pre-integrated protocols)

For Aave, Compound, Morpho, Yearn, and other natively supported protocols, use composable actions instead of manual calldata encoding:
Use useEarnMarkets to discover available market IDs. See Markets and Providers.

Calldata reference

When to use TRAILS_ROUTER_PLACEHOLDER_AMOUNT

TRAILS_ROUTER_PLACEHOLDER_AMOUNT is uint256.max internally. Trails replaces it with the actual output amount at execution time.

See also