Skip to main content

Earn with Trails

A variety of applications enable users to earn yield on their assets by depositing liquidity into various protocols. This is a complex task as developers must manually integrate various protocols across chains that also meets their target risk profile. Then once integrated, users must find a bridge, manually move their liquidity to the desired chain, potentially swap to the vault or pool asset, and finally deposit into the protocol. Trails simplifies this by natively integrating with various DeFi protocols for easy integration - highlighting APY, TVL and other metrics important for users. Additionally, developers can specify any arbitrary logic and pass it to trails for more complex or custom flows. For users, all the complexity is handled for them including swapping and bridging to the corresponding vault or pool token in a single transaction to immediately begin earning yield.

Examples

Deposit into a user-selected Aave or Morpho vault

Trails has integrated multiple DeFi pools and vaults across several protocols such as Aave and Morpho that your users can select from out of the box.
import { TrailsWidget } from '0xtrails/widget'

export const App = () => {
  return (
    <TrailsWidget
      apiKey="YOUR_API_KEY"
      mode="earn"
      renderInline={true}
      theme="auto"
    />
  )
}

Deposit into a specific DeFi pool

You can also use Trails with any lending pool that you define. The user can select any token they hold in their wallet from any supported chain to automatically swap to the corresponding pool token for a deposit. The calldata can be changed to support virtually any function and contract that you specify. For example, depositing USDC into an Aave pool on Base:
import { TrailsWidget } from '0xtrails/widget'
import { encodeFunctionData } from 'viem'
import { aaveABI } from './abi.ts'

export const AaveDepositExample = () => {
  // Aave V3 Pool contract on Base
  const AAVE_POOL_CONTRACT = "0xa0d9C1E9E48Ca30c8d8C3B5D69FF5dc1f6DFfC24"
  
  // Encode the deposit function call on Aave
  const depositCalldata = encodeFunctionData({
    abi: aaveABI,
    functionName: 'depositETH',
    args: [
      "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5", // pool address
      "0x97c4a952b46becad0663f76357d3776ba11566e1", // user's wallet address
      0, // referralCode
    ],
  })

  return (
    <TrailsWidget
      apiKey="YOUR_API_KEY"
      mode="earn"
      toAddress={AAVE_POOL_CONTRACT}
      toAmount="100" // 100 USDC
      toChainId={8453} // Base
      toToken="USDC"
      toCalldata={depositCalldata}
      theme="auto"
    />
  )
}