Why This Matters
Users accumulate positions across multiple DeFi protocols over time. When rates change, they need to move funds - but doing it manually means multiple transactions, multiple signatures, and wasted gas. Most users never bother. The Portfolio Rebalancer lets you build products that shift allocations across Aave, Morpho vaults, and Pendle markets in one atomic transaction. Users set their target allocation, sign once, and the API handles the rest.What It Does
Given a user’s current positions and a set of target allocations, the rebalancer computes the optimal set of withdrawals, swaps, and deposits to reach the target state. All actions are bundled into one transaction using the Bundle endpoint. You call our API, we return a transaction payload. The user signs once, and their portfolio rebalances atomically. Important: Users must first create an Earn Account before rebalancing.How It Works
- Fetch current positions - Call the positions endpoint to see where the user’s funds are deployed
- Compute the plan - Determine what needs to move: withdrawals from over-allocated venues, swaps between tokens, deposits into under-allocated venues
- Bundle the actions - Send the actions to
POST /v2/earn/bundlein order - User signs once - The API returns a single transaction (or EIP-712 data for gas sponsorship)
- Execution - All actions execute atomically on-chain
Action Order
The bundle executes actions in the order you provide. For a rebalance, the typical order is:- Withdraw from venues that are over-allocated
- Swap tokens if the target venue uses a different asset
- Deposit into venues that are under-allocated
Example: Rebalance from Aave to a Morpho Vault
A user has 100 USDC in Aave earning 4.8% APY. They want to move half to a Morpho vault earning 6.2% APY. This requires three bundled actions: withdraw 50 USDC from Aave, then deposit 50 USDC into the vault.Example: Cross-Token Rebalance with Swap
A user has 200 USDC in an Aave market but wants to move 100 into a WETH vault. This requires a withdraw, swap, and deposit - all in one bundle.Portfolio Manager Widget
If you want a ready-made UI for rebalancing, use the Portfolio Manager widget. It handles position display, target allocation editing, preview, and execution out of the box.Try the Portfolio Manager
Try the live widget in the Widget Builder Studio.
Widget Docs
See installation and customization options.
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | ’Portfolio Manager’ | Title shown in the header |
chain | string | undefined | Lock to a specific chain. Hides chain selector when set. |
showChainSwitcher | boolean | true | Show the chain selector dropdown |
showWalletStatus | boolean | true | Show the wallet connection status |
showTopUp | boolean | true | Show the Top Up button to transfer from wallet |
defaultSlippage | number | 0.5 | Default slippage tolerance for swaps (%) |
minRebalanceThresholdUsd | number | 0.01 | Minimum USD value to include in rebalance |
venues | object | undefined | Filter which venues are shown (aave, vaults, pendle) |
height | string | ’600px’ | Widget height |
onRebalance | function | undefined | Callback after successful rebalance with plan and tx hash |
onError | function | undefined | Callback on error |
Supported Venues
| Protocol | Venue Type | Description |
|---|---|---|
| Aave V3 | AAVE | Lending markets with variable supply rates |
| Morpho / ERC-4626 | VAULT | Curated vaults with optimized yield |
| Pendle | PENDLE_PT | Fixed-rate yield via principal tokens |