# Vaults Documentation (full)
> Every Vaults page in one file. It covers Vaults only: other sections have their own files, listed at https://aave.com/docs/llms.txt.
Source: https://aave.com/docs/vaults/stable-vaults.md
# Aave Stable Vaults
Stable Vaults let financial platforms offer stable-rate earning on stablecoins without exposing their users to the complexity of DeFi.
## Overview
DeFi lending rates change with market utilization. Stable Vaults pay depositors a stable rate instead, compounded continuously. The vault's smart contracts handle accounting and liquidity, and allocate deposits to yield strategies. The rate is not guaranteed: interest is paid from the yield the vault earns.
The integrator sets who can deposit and each user's rate, and claims surplus yield. Supported stablecoins are treated as equivalent once deposited, so users can withdraw in any supported asset regardless of what they put in.
Learn more about how Stable Vaults work:
- [Features](./stable-vaults/features): stable-rate earnings, multi-strategy and multi-chain earning, per-user rates, allowlisting, surplus management, and multi-asset deposits & withdrawals.
- [Architecture](./stable-vaults/architecture): the Accounting Chain, Earning Chains, and roles & access controls.
- [ERC-4626 Yield Strategies](./stable-vaults/yield-strategies): the yield sources the vault allocates deposits into.
---
Source: https://aave.com/docs/vaults/stable-vaults/features.md
# Stable Vault Features
Stable Vaults combine stable-rate earning, per-user rates, and access controls in one product.
## Stable-Rate Earnings
A deposit accrues at the per-second rate of the user's SubVault, which does not follow market rates. The rate is not guaranteed: SubVault rates can change, and accrued interest can only be withdrawn while the vault holds enough surplus (see [Vault Surplus Management](#vault-surplus-management)). An off-chain rebalancer allocates deposits across yield strategies to earn that yield.
## Multi-Strategy Earning
Deposits are not tied to a single yield source. The Allocator routes assets across multiple approved [ERC-4626 yield strategies](./yield-strategies), such as Aave V4 markets, Aave V3 markets, the Savings GHO vault, or any other compliant vault approved by the integrator. Managers rebalance allocations between strategies as market conditions change, diversifying yield sources without any action required from depositors.
## Multi-Chain Earning
The system spans multiple networks. The Accounting Chain is the source of truth for user balances and withdrawals, while one or more Earning Chains host additional yield strategies. This lets the vault allocate deposits to yield opportunities wherever they exist, and lets users bridge their IOUs to redeem into assets available on other supported chains. Funds move between chains through multiple approved bridge providers. See [Architecture](./architecture) for how the chains fit together.
## Per-User Rates
Each user’s position belongs to exactly one SubVault. A SubVault defines a set per-second accrual rate, and a user’s withdrawable balance is their shares multiplied by the SubVault’s current conversion rate. Because different SubVaults carry different rates, integrators can assign different rates to different user segments based on loyalty tiers, promotional campaigns, subscription levels, or other product logic. SubVault assignment is managed off chain: it is applied at the point of deposit and can be updated at any time afterward, throughout the life of the user’s position.
## Allowlist
Deposit access to the Stable Vault can be restricted to a set of approved wallets. This lets integrators run controlled embedded earning programs where only eligible users, such as those who have completed KYC, belong to a specific tier, or have been explicitly enrolled, can deposit. The allowlist is managed per deployment and does not affect the ability of existing depositors to withdraw.
## Vault Surplus Management
The system tracks each user’s original deposit principal separately from accrued interest. Users can always convert their principal into IOUs. Converting IOUs into stablecoins is subject to withdrawal fees, the global redemption rate limit, and the assets available on that chain. Interest is gated by the system’s trusted, price-weighted surplus, meaning users can only convert accrued interest into IOUs when the system’s assets exceed its obligations by that amount. The integrator can claim surplus interest via `claimSurplusInterest`, subject to the same surplus check.
Withdrawal fees are configured per asset in basis points and applied by the Withdrawal Execution Policy at redemption time. Because fees are set per asset, the vault can support multiple stablecoins as eligible deposit and withdrawal assets while preventing users from taking advantage of the system for one-to-one swaps between them.
## Multi-Asset Deposits & Withdrawals
All supported stablecoins are treated as interchangeable inside the vault. When a user deposits, the system validates the asset’s price and credits the position in the vault’s denomination currency, valued at nominally one U.S. dollar, so what a user deposited places no restriction on what they can withdraw. At withdrawal, users choose any supported output asset on the chain where they redeem, and managers are responsible for ensuring the system holds enough assets on each chain, in each supported denomination, to fulfill instant withdrawals. A user who deposited USDC may redeem into USDT, GHO, or another supported asset on the Accounting Chain, or bridge their IOUs to an Earning Chain to redeem into assets available there such as PYUSD or RLUSD.
Asset support is controlled by the Asset Registry, which tracks whether an asset may be deposited by users, deposited into the Allocator, used as a swap input, or received as a swap output. Assets can be marked as distrusted to exclude them from the system’s surplus accounting without blocking users from voluntarily redeeming IOUs into those assets, ensuring the system accounts conservatively for assets that have depegged or whose price integrity is uncertain.
## Security Controls
A _global redemption rate limit_ throttles the total volume of IOU redemptions across all users and assets within a given period, bounding how quickly value can exit the system during abnormal conditions. The limit carries configurable floor values that prevent the policy from being tightened below a minimum throughput, so redemptions can never be effectively frozen through configuration alone.
---
Source: https://aave.com/docs/vaults/stable-vaults/architecture.md
# Stable Vault Architecture
The system is split across an Accounting Chain and one or more Earning Chains. The Accounting Chain is the source of truth for user balances, the system surplus, and withdrawal accounting. Earning Chains host yield strategies and periodically publish balance snapshots back to the Accounting Chain through a Chainlink-powered oracle feed. An off-chain system monitors protocol state and submits rebalance and bridge transactions.
## Accounting Chain
The Accounting Chain handles deposits, withdrawal requests, share accounting, and surplus gating. For the Aave App, the Accounting Chain is Arbitrum.
The **Stable Vault** is the user entrypoint. It validates asset prices through the Price Oracle on each deposit, mints shares into the user’s assigned SubVault, and manages the two-step withdrawal flow. On `requestWithdrawal`, shares are burned and IOU tokens are minted representing a denomination currency claim. The principal portion of a position is always redeemable as IOUs; the interest portion is gated by the system’s trusted surplus. On `executeWithdrawal`, IOUs are burned, the Withdrawal Execution Policy applies any fees, and the user receives their chosen output asset. Share positions can be transferred between users via `transfer` and `transferAll`.
The **Funds Handler** sits between the Stable Vault and the Allocator. It aggregates the total price-weighted asset value across local balances and registered Earning Chains by querying the Chain Balance Oracle on demand for remote chain data. Stale Earning Chain data contributes zero to the aggregation, so the system conservatively underestimates its surplus rather than overstating it. This protects depositors by not inflating the global interest pool earned by the Stable Vault’s assets.
The **Allocator** holds idle assets and executes rebalances. It maintains an approved list of ERC-4626 strategy contracts and handles swaps through a dedicated Swapper. Swaps enforce a nominal one-to-one exchange rate, with any slippage or venue fees covered by an external Slippage Coverage Vault rather than customer deposits. User deposits land idle on the Allocator and are allocated to strategies by the off-chain manager via `rebalance()`, so strategy-side issues such as supply cap breaches or paused markets do not block user deposits.
The **Accounting Chain Gateway** routes outbound funds and messages to Earning Chains and ingests inbound messages. It validates inbound message block numbers against the Chain Balance Oracle to preserve accounting integrity.
## Earning Chains
Earning Chains (currently Ethereum Mainnet) host yield strategies and the infrastructure needed to exchange IOUs for local assets and return funds to the Accounting Chain.
Funds and messages move between the Accounting Chain and Earning Chains through multiple bridge providers, such as CCIP, LayerZero, Hyperlane, and Across, as well as potentially others, as long as their usage follows the protocol’s security requirements.
The **Earning Chain Gateway** handles inbound bridge messages, exchanges IOU tokens for local assets against available liquidity, and pushes funds back to the Accounting Chain when needed. It computes price-weighted local balances using the same aggregation logic as the Funds Handler.
The **Earning Chain State Provider** exposes the local price-weighted balance in an encoded format that Chainlink operators read and publish to the Accounting Chain via the Chain Balance Oracle. Feed updates are triggered by specific on-chain events such as funds received or sent and asset trust status changes, by a configured deviation threshold, and by a fixed heartbeat interval. The Accounting Chain treats data older than the configured staleness threshold as zero, keeping the surplus accounting conservative.
## Roles & Access Controls
The protocol separates configuration authority from operational authority through a role hierarchy. Higher roles define the boundaries; lower roles operate within them.
**Integrators** hold the broadest authority. They configure the total trusted surface of the vault:
- **Assets**: which stablecoins can be deposited, swapped, or used as withdrawal outputs (via the Asset Registry)
- **Yield strategies**: which ERC-4626 strategies are approved on the Allocator (e.g. Aave V4 Tokenization Spokes, sGHO, or any other compliant vault)
- **Bridges**: which cross-chain bridge contracts are permitted for moving funds between the Accounting Chain and Earning Chains
These allowlists are exhaustive: a manager can only use strategies, assets, and bridges the integrator has approved.
**Managers** operate within whatever the integrator has configured. A manager can:
- Call `rebalance()` to shift allocations between approved yield strategies
- Initiate bridge transfers to/from approved Earning Chains
- Adjust yield allocations in response to changing market conditions
Managers cannot modify the allowlists or claim surplus interest. Those actions are reserved for the integrator role.
This separation means a fintech deploying a vault can lock down protocol-level risk (which counterparties are trusted, which assets move) while safely delegating routine yield operations to an automated off-chain system or third-party manager without exposing configuration authority.
---
Source: https://aave.com/docs/vaults/stable-vaults/yield-strategies.md
# Stable Vault Yield Strategies
The Allocator routes assets into approved ERC-4626 strategies. Each strategy is a vault interface to an underlying yield source and is added or removed by the integrator. The Allocator may also hold assets that have no assigned strategy when a suitable strategy does not exist for a given asset or chain.
## Aave V4 Markets
Aave V4 markets are supported natively, with no adapter required. The Allocator deposits directly into Aave V4 Tokenization Spokes, which are ERC-4626 compliant, in the same way as any other depositor.
## Aave V3 Markets
Assets are supplied to Aave V3 lending markets using an extended AToken vault adapter. The extension adds support for claiming Merkl rewards, which is required because a significant portion of the yield from supplying certain assets to Aave V3 markets comes from off-chain reward distributions rather than on-chain lending interest alone.
## Savings GHO Vault
GHO can be deposited into the sGHO savings vault, which accrues yield through the GHO Savings Rate mechanism. This strategy is available on chains where sGHO is deployed.
## Generic ERC-4626 Vault
Any ERC-4626 compliant vault approved by the integrator and added to the Allocator’s allowlist can serve as a strategy. This design allows the system to adopt new yield sources without protocol changes, as long as the strategy conforms to the standard vault interface and the other requirements of the Allocator contract.
---
Source: https://aave.com/docs/vaults/simple-earn/overview.md
# Aave Simple Earn Vaults
Aave Simple Earn Vaults are ERC-4626 compliant yield-bearing vaults that allow users to supply and withdraw ERC-20 tokens supported by Aave V3. Vaults manage the supply and withdrawal of assets in the Aave Protocol while enabling vault managers to take a fee on the yield earned.
To deploy a vault, follow the [deployment guide](./deploy).
Aave Simple Earn Vaults follow the [ERC-4626 Tokenized Vault Standard](https://eips.ethereum.org/EIPS/eip-4626), which standardizes the interface for yield-bearing vaults. This standard simplifies integration with various applications and aggregators while improving interoperability across the DeFi ecosystem.
Each vault allows depositors to:
- Deposit supported tokens (assets) and receive vault shares in return
- Redeem vault shares for the underlying assets plus accrued yield
- Automatically earn yield from Aave V3 markets without direct interaction with the protocol
## Architecture
Aave Simple Earn Vaults consist of three key components:
1. **ERC-4626 Interface**: Standardized methods for deposit, withdrawal, and accounting of assets.
2. **Yield Strategy**: Manages deposits into Aave V3 markets and handles yield accrual.
3. **Fee Management**: Enables vault managers to collect a percentage of the yield generated.
When a user deposits an asset into a vault:
- The vault mints proportional vault shares (ERC-20 tokens) to the user
- The vault deposits the underlying assets into the corresponding Aave V3 market
- The vault receives aTokens from Aave, which automatically accrue yield
- Yield is reflected in the increasing value of vault shares over time
## Fee Structure
> [!NOTE]
> Vaults deployed via Aave Labs’ API or SDK can set the performance fee as low
> as 0%. Aave Labs automatically receives 50% of any fee set.
Vault managers can set a fee percentage on the yield generated by the vault. This fee structure includes:
- **Performance Fee**: A percentage of the yield earned that goes to the vault manager
- **Max Fee**: A maximum limit on the performance fee that can be charged
- **Fee Recipients**: The addresses that receive the collected fees
Fees are collected when yield is realized through:
- User withdrawals or redemptions
- Explicit fee collection by the vault manager
The fee is only applied to the yield portion of the assets and not to the principal amount deposited by users.
## Interacting with Vaults
Vaults implement the standard ERC-4626 interface with methods such as:
- `deposit(uint256 assets, address receiver)`: Deposit assets and receive vault shares
- `withdraw(uint256 assets, address receiver, address owner)`: Withdraw assets by burning vault shares
- `mint(uint256 shares, address receiver)`: Mint exact amount of shares by depositing assets
- `redeem(uint256 shares, address receiver, address owner)`: Redeem shares for underlying assets
Additionally, vaults provide view functions to check:
- `totalAssets()`: Total assets managed by the vault
- `convertToShares(uint256 assets)`: Convert asset amount to vault shares
- `convertToAssets(uint256 shares)`: Convert vault shares to asset amount
- `previewDeposit(uint256 assets)`: Preview shares received for a deposit
- `previewWithdraw(uint256 assets)`: Preview shares needed for a withdrawal
For a detailed contract reference, see [the contracts documentation](/aave-v3/smart-contracts/vaults).
## Benefits for Users
- **Simplified Yield**: Earn yield from Aave V3 without managing multiple transactions
- **Standard Interface**: Easier integration with other DeFi protocols and applications
- **Composability**: Vault shares can be used in other DeFi applications
## Benefits for Vault Managers
- **Yield Capture**: Earn fees on yield generated by user deposits
- **Customization**: Configure fee parameters to suit different strategies
- **Standardization**: Leverage the ERC-4626 standard for broader integration
---
Source: https://aave.com/docs/vaults/simple-earn/deploy.md
# Deploy an Aave Simple Earn Vault
## Deploying a Vault
To deploy a new Aave Simple Earn Vault, follow these steps:
> [!NOTE]
> Only vaults deployed this way appear in Aave Labs’ API and SDKs.
### 1. Identify the Reserve
First, determine which reserve you want your vault to be based on.
Let’s say we choose the WETH supply reserve of an Ethereum market.
```ts title="Reserve"
const reserve: Reserve = {
__typename: "Reserve",
market: {
__typename: "MarketInfo",
address: "0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2",
chain: { __typename: "Chain", chainId: 1, /* … */ },
// …
},
underlyingToken: {
__typename: "Currency",
symbol: "WETH",
name: "Wrapped Ether",
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
// …
},
isFrozen: false,
isPaused: false,
// …
};
```
> [!NOTE]
> Ensure the reserve is not frozen or paused.
### 2. Define Configuration
Next, define the configuration for deploying the vault.
The `initialLockDeposit` is **permanently locked** in the vault and cannot be withdrawn. It protects against inflation attacks by ensuring the share price cannot be manipulated immediately after deployment, and the protection strengthens as TVL grows.
The amount is derived from a `TARGET_DONATION`: the minimum raw asset units an attacker would need to donate to double the share price at deployment. A higher `TARGET_DONATION` raises the attack cost. Setting it to `1_000_000` raw units is a conservative default that is cheap for most assets while remaining meaningful.
```txt
initialLockDeposit = max(TARGET_DONATION / 10^decimals, 1e-9)
// With TARGET_DONATION = 1_000_000:
// USDC (6 dec) → 1 USDC
// WETH (18 dec) → 0.000000001 WETH
```
You can tune `TARGET_DONATION` upward for higher-value assets or increase it if you want a stronger guarantee at vault launch.
The minimal configuration to deploy a vault is:
```tsx title="Minimal Configuration"
import { bigDecimal, evmAddress, VaultDeployRequest } from "@aave/react";
// …
const request: VaultDeployRequest = {
market: reserve.market.address,
chainId: reserve.market.chain.chainId,
underlyingToken: reserve.underlyingToken.address,
deployer: evmAddress(walletClient!.account.address),
// owner: evmAddress("0x1234…"), if different from deployer
initialFee: bigDecimal(0), // 0% performance fee
shareName: "Aave WETH Vault Shares",
shareSymbol: "avWETH",
initialLockDeposit: bigDecimal(0.000000001), // 0.000000001 WETH, permanently locked
};
```
```ts title="Minimal Configuration"
import { bigDecimal, evmAddress, VaultDeployRequest } from "@aave/client";
const request: VaultDeployRequest = {
market: reserve.market.address,
chainId: reserve.market.chain.chainId,
underlyingToken: reserve.underlyingToken.address,
deployer: evmAddress(wallet.account.address),
// owner: evmAddress("0x1234…"), if different from deployer
initialFee: bigDecimal(0), // 0% performance fee
shareName: "Aave WETH Vault Shares",
shareSymbol: "avWETH",
initialLockDeposit: bigDecimal(0.000000001), // 0.000000001 WETH, permanently locked
};
```
```jsonc title="Minimal Configuration"
{
"request": {
"market": "0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2",
"chainId": 1,
"underlyingToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"deployer": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
// "owner": "0x1234…", if different from deployer
"initialFee": "0", // 0% performance fee
"shareName": "Aave WETH Vault Shares",
"shareSymbol": "avWETH",
"initialLockDeposit": "0.000000001" // 0.000000001 WETH, permanently locked
}
}
```
Vaults deployed via Aave Labs' API or SDK can set the performance fee as low as 0%.
When a performance fee is set, 50% of that fee is automatically allocated to Aave Labs.
When a recipient is not specified, the fee revenue is distributed equally between the vault owner and Aave Labs.
Let’s explore a more advanced recipient configuration with an example. Suppose you want to deploy a vault where you keep 70% of the fee revenue and share the remaining 30% with your partner.
```tsx title="Configuration with Fee Recipients"
import { bigDecimal, evmAddress, VaultDeployRequest } from "@aave/react";
const request: VaultDeployRequest = {
// …
recipients: [
{
address: evmAddress("0x1234…"),
percent: bigDecimal(30),
},
{
address: evmAddress("0x4567…"),
percent: bigDecimal(70),
},
],
};
```
```ts title="Configuration with Fee Recipients"
import { bigDecimal, evmAddress, VaultDeployRequest } from "@aave/client";
const request: VaultDeployRequest = {
// …
recipients: [
{
address: evmAddress("0x1234…"),
percent: bigDecimal(30),
},
{
address: evmAddress("0x4567…"),
percent: bigDecimal(70),
},
],
};
```
```jsonc title="Configuration with Fee Recipients"
{
"request": {
// …
"recipients": [
{
"address": "0x1234…",
"percent": "30"
},
{
"address": "0x4567…",
"percent": "70"
}
]
}
}
```
If the vault generates 100 WETH in fee revenue, the distribution will be as follows:
- `partner`: 15 WETH
- `owner`: 35 WETH
- `Aave Labs`: 50 WETH
Since Aave Labs retains 50% of the total fee revenue by default, the remaining 50% is divided between the owner and partner according to the specified percentages.
### 3. Deploy the Vault
Finally, deploy the vault.
- **React**: Use the `useVaultDeploy` and `useSendTransaction` hooks with the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transactions.
- **TypeScript**: Use `vaultDeploy` action and `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to send the transactions, and await indexing with `client.waitForTransaction`.
- **GraphQL**: Use the `vaultDeploy` query to deploy a vault.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { errAsync, useVaultDeploy } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [deployVault, deploying] = useVaultDeploy();
const [sendTransaction, sending] = useSendTransaction(walletClient);
// …
// Optional: combine loading states
const loading = deploying.loading || sending.loading;
const error = deploying.error || sending.error;
// …
const result = await deployVault(request).andThen((plan) => {
switch (plan.__typename) {
case "TransactionRequest":
// Single transaction execution
return sendTransaction(plan);
case "ApprovalRequired":
// Approval + transaction sequence
return sendTransaction(plan.approval).andThen(() =>
sendTransaction(plan.originalTransaction),
);
case "InsufficientBalanceError":
return errAsync(
new Error(`Insufficient balance: ${plan.required.value} required.`),
);
}
});
if (result.isErr()) {
console.error("Vault deployment failed:", result.error);
} else {
console.log("Vault deployment successful with hash:", result.value);
}
```
```ts title="Viem"
import { vaultDeploy } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultDeploy(client, request)
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Vault deployment failed:", result.error);
} else {
console.log("Vault deployment successful:", result.value);
}
```
```graphql title="Query"
query {
vaultDeploy(request: {
# …
}) {
__typename
... on TransactionRequest {
to
from
data
value
chainId
operation
}
... on ApprovalRequired {
reason
requiredAmount {
value
decimals
}
currentAllowance {
value
decimals
}
approval {
to
from
data
value
chainId
operation
}
originalTransaction {
to
from
data
value
chainId
operation
}
}
... on InsufficientBalanceError {
required {
value
decimals
}
available {
value
decimals
}
}
}
}
```
In GraphQL, depending on the response, you can handle the response accordingly.
| Response Type | Description |
| ------------------------ | ----------------------------------------------------------------------------------------- |
| TransactionRequest | You can send it directly using the wallet associated with the `from` address. |
| ApprovalRequired | Send the approval transaction first, then the original transaction. |
| InsufficientBalanceError | Inform the user that they don’t have enough balance for the initial deposit in the vault. |
Below are examples illustrating the response for each response type.
```json title="TransactionRequest"
{
"data": {
"vaultDeploy": {
"__typename": "TransactionRequest",
"to": "0x…",
"from": "0x…",
"data": "0x…",
"value": "0",
"chainId": 1,
"operation": "VAULT_DEPLOYED"
}
}
}
```
```json title="ApprovalRequired"
{
"data": {
"vaultDeploy": {
"__typename": "ApprovalRequired",
"reason": "Insufficient allowance",
"requiredAmount": { "value": "1000", "decimals": 18 },
"currentAllowance": { "value": "0", "decimals": 18 },
"approval": {
"to": "0x…",
"from": "0x…",
"data": "0x…",
"value": "0",
"chainId": 1,
"operation": null
},
"originalTransaction": {
"to": "0x…",
"from": "0x…",
"data": "0x…",
"value": "0",
"chainId": 1,
"operation": "VAULT_DEPLOYED"
}
}
}
}
```
```json title="InsufficientBalanceError"
{
"data": {
"vaultDeploy": {
"__typename": "InsufficientBalanceError",
"required": {
"value": "1000.0",
"decimals": 6
},
"available": {
"value": "750.0",
"decimals": 6
}
}
}
}
```
---
Source: https://aave.com/docs/vaults/simple-earn/management.md
# Manage an Aave Simple Earn Vault
Manage your deployed vaults with fee configuration and revenue collection.
## Identify the Vault
All actions below apply to a vault you own. [Fetch the vault](/vaults/simple-earn/data#fetching-a-single-vault) first; this page uses the following vault in its examples:
```ts title="Owned Vault"
const vault: Vault = {
__typename: "Vault",
address: "0x1234567890abcdef1234567890abcdef12345678",
owner: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234", // Your address
shareName: "Aave USDC Vault Shares",
shareSymbol: "avUSDC",
chainId: 1,
usedReserve: {
__typename: "Reserve",
underlyingToken: {
__typename: "Currency",
symbol: "USDC",
name: "USD Coin",
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
// …
},
// …
},
fee: {
__typename: "PercentValue",
raw: "150000000000000000000000000",
decimals: 27,
value: "0.15",
formatted: "15", // 15% performance fee
},
totalFeeRevenue: {
__typename: "TokenAmount",
amount: {
__typename: "DecimalValue",
value: "1250.75", // Lifetime fees collected
// …
},
usd: "1250.75",
// …
},
feesBalance: {
__typename: "TokenAmount",
amount: {
__typename: "DecimalValue",
value: "100.00", // Fees currently available for withdrawal
// …
},
usd: "100.00",
// …
},
// …
};
```
## Set Vault Fee
> [!NOTE]
> The fee can be 0% to 100%. Aave Labs automatically receives 50% of it.
Update the performance fee for your vault (vault owner only).
### 1. Prepare the Fee Update
Next, create the transaction request for updating the vault fee. Use the `useVaultSetFee` hook in React, the `vaultSetFee` action in TypeScript, or the `vaultSetFee` query in GraphQL to create the transaction request for updating the vault fee.
```tsx title="Set Fee"
import { useVaultSetFee, bigDecimal } from "@aave/react";
// …
const [setFee, settingFee] = useVaultSetFee();
const result = await setFee({
chainId: vault.chainId,
vault: vault.address,
newFee: bigDecimal(15), // 15% performance fee
});
// …
```
```ts title="Set Fee"
import { bigDecimal } from "@aave/client";
import { vaultSetFee } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultSetFee(client, {
chainId: vault.chainId,
vault: vault.address,
newFee: bigDecimal(15), // 15% performance fee
});
// …
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vaultSetFee(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
newFee: "15"
}
) {
to
from
data
value
chainId
}
}
```
### 2. Send the Fee Update
Finally, send the transaction.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transaction.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to initiate the transaction, and await indexing with `client.waitForTransaction`.
- **GraphQL**: The response is a `TransactionRequest` that can be sent directly using the wallet associated with the `from` address.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { useVaultSetFee } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [setFee, settingFee] = useVaultSetFee();
const [sendTransaction, sending] = useSendTransaction(walletClient);
const loading = settingFee.loading || sending.loading;
const error = settingFee.error || sending.error;
// …
const result = await setFee({
// …
}).andThen(sendTransaction);
if (result.isErr()) {
console.error("Set fee failed:", result.error);
} else {
console.log("Set fee successful with hash:", result.value);
}
```
```ts title="Viem"
import { vaultSetFee } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultSetFee(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Set fee failed:", result.error);
} else {
console.log("Set fee successful:", result.value);
}
```
```ts title="wallet.ts"
import { createWalletClient, http, type Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
export const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
chain: mainnet,
transport: http(),
});
```
```json title="TransactionRequest"
{
"data": {
"vaultSetFee": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x69fe0e2d000000000000000000000000000000000000000000000000000000000000000f",
"value": "0",
"chainId": 1
}
}
}
```
## Withdraw Fees
Withdraw accumulated fees from your vault (vault owner only).
> [!NOTE]
> Fees are withdrawn as the reserve’s aTokens.
### 1. Prepare the Fee Withdrawal
Next, create the transaction request for withdrawing fees. Use the `useVaultWithdrawFees` hook in React, the `vaultWithdrawFees` action in TypeScript, or the `vaultWithdrawFees` query in GraphQL to create the transaction request for withdrawing fees.
```tsx title="Withdraw Exact Amount"
import { useVaultWithdrawFees, bigDecimal } from "@aave/react";
// …
const [withdrawFees, withdrawingFees] = useVaultWithdrawFees();
const result = await withdrawFees({
chainId: vault.chainId,
vault: vault.address,
amount: {
exact: bigDecimal(100), // 100 USDC of fees
},
// sendTo: evmAddress("0x1234…"), if different from vault owner
});
// …
```
```tsx title="Withdraw Max Amount"
import { useVaultWithdrawFees } from "@aave/react";
// …
const [withdrawFees, withdrawingFees] = useVaultWithdrawFees();
const result = await withdrawFees({
chainId: vault.chainId,
vault: vault.address,
amount: {
max: true,
},
// sendTo: evmAddress("0x1234…"), if different from vault owner
});
// …
```
```ts title="Withdraw Exact Amount"
import { bigDecimal } from "@aave/client";
import { vaultWithdrawFees } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultWithdrawFees(client, {
chainId: vault.chainId,
vault: vault.address,
amount: {
exact: bigDecimal(100), // 100 USDC of fees
},
// sendTo: evmAddress("0x1234…"), if different from vault owner
});
// …
```
```ts title="Withdraw Max Amount"
import { vaultWithdrawFees } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultWithdrawFees(client, {
chainId: vault.chainId,
vault: vault.address,
amount: {
max: true,
},
// sendTo: evmAddress("0x1234…"), if different from vault owner
});
// …
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vaultWithdrawFees(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
amount: {
exact: "100"
# OR
# max: true
}
# sendTo: "0x1234…", if different from vault owner
}
) {
to
from
data
value
chainId
}
}
```
### 2. Send the Fee Withdrawal
Finally, send the transaction.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transaction.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to initiate the transaction, and await indexing with `client.waitForTransaction`.
- **GraphQL**: The response is a `TransactionRequest` that can be sent directly using the wallet associated with the `from` address.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { useVaultWithdrawFees } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [withdrawFees, withdrawingFees] = useVaultWithdrawFees();
const [sendTransaction, sending] = useSendTransaction(walletClient);
const loading = withdrawingFees.loading || sending.loading;
const error = withdrawingFees.error || sending.error;
// …
const result = await withdrawFees({
// …
}).andThen(sendTransaction);
if (result.isErr()) {
console.error("Withdraw fees failed:", result.error);
} else {
console.log("Withdraw fees successful with hash:", result.value);
}
```
```ts title="Viem"
import { vaultWithdrawFees } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultWithdrawFees(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Withdraw fees failed:", result.error);
} else {
console.log("Withdraw fees successful:", result.value);
}
```
```ts title="wallet.ts"
import { createWalletClient, http, type Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
export const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
chain: mainnet,
transport: http(),
});
```
```json title="TransactionRequest"
{
"data": {
"vaultWithdrawFees": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0xad3b1b47000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b12340000000000000000000000000000000000000000000000000000000005f5e100",
"value": "0",
"chainId": 1
}
}
}
```
## Transfer Vault Ownership
Transfer the ownership of a vault to a new address (vault owner only).
### 1. Prepare the Ownership Transfer
Next, create the transaction request for transferring the ownership of the vault. Use the `useVaultTransferOwnership` hook in React, the `vaultTransferOwnership` action in TypeScript, or the `vaultTransferOwnership` query in GraphQL to create the transaction request for transferring the ownership of the vault.
```tsx title="Transfer Ownership"
import { useVaultTransferOwnership, evmAddress } from "@aave/react";
// …
const [transferOwnership, transferring] = useVaultTransferOwnership();
const result = await transferOwnership({
chainId: vault.chainId,
vault: vault.address,
newOwner: evmAddress("0x9876543210fedcba9876543210fedcba98765432"),
});
// …
```
```ts title="Transfer Ownership"
import { evmAddress } from "@aave/client";
import { vaultTransferOwnership } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultTransferOwnership(client, {
chainId: vault.chainId,
vault: vault.address,
newOwner: evmAddress("0x9876543210fedcba9876543210fedcba98765432"),
});
// …
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vaultTransferOwnership(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
newOwner: "0x9876543210fedcba9876543210fedcba98765432"
}
) {
to
from
data
value
chainId
}
}
```
### 2. Send the Ownership Transfer
Finally, send the transaction.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transaction.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to initiate the transaction, and await indexing with `client.waitForTransaction`.
- **GraphQL**: The response is a `TransactionRequest` that can be sent directly using the wallet associated with the `from` address.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { useVaultTransferOwnership } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [transferOwnership, transferringOwnership] = useVaultTransferOwnership();
const [sendTransaction, sending] = useSendTransaction(walletClient);
const loading = transferringOwnership.loading || sending.loading;
const error = transferringOwnership.error || sending.error;
// …
const result = await transferOwnership({
// …
}).andThen(sendTransaction);
if (result.isErr()) {
console.error("Transfer ownership failed:", result.error);
} else {
console.log("Transfer ownership successful with hash:", result.value);
}
```
```ts title="Viem"
import { vaultTransferOwnership } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultTransferOwnership(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Transfer ownership failed:", result.error);
} else {
console.log("Transfer ownership successful:", result.value);
}
```
```ts title="wallet.ts"
import { createWalletClient, http, type Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
export const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
chain: mainnet,
transport: http(),
});
```
```json title="TransactionRequest"
{
"data": {
"vaultTransferOwnership": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0xf2fde38b0000000000000000000000009876543210fedcba9876543210fedcba98765432",
"value": "0",
"chainId": 1
}
}
}
```
---
Source: https://aave.com/docs/vaults/simple-earn/data.md
# Aave Simple Earn Vault Data
Fetch a single vault, list vaults, and read a user’s vault positions, history, and activity.
## Vault Data Structure
Aave Simple Earn Vault data describes ERC-4626 compliant yield-bearing vaults:
- Vault identification (address, owner, share token details)
- Reserve information (underlying asset, yield strategy)
- Fee structure (performance fees, accumulated revenue, fee recipients)
- Vault metrics (total balance, user shares)
> [!NOTE]
> Include a user address to also get the user’s vault shares
> (`userShares.shares`) and their underlying balance (`userShares.balance`).
The following TypeScript interfaces illustrate the core Vault type and its related types:
```ts title="Vault"
interface Vault {
address: EvmAddress;
owner: EvmAddress;
shareName: string;
shareSymbol: string;
usedReserve: Reserve;
fee: PercentValue;
totalFeeRevenue: TokenAmount;
balance: TokenAmount;
feesBalance: TokenAmount;
chainId: ChainId;
userShares?: UserVaultShares;
recipients?: VaultFeesRecipientsConfiguration;
}
```
```ts title="VaultFeesRecipientsConfiguration"
interface VaultFeesRecipientsConfiguration {
address: EvmAddress;
entries: VaultFeesRecipientSplit[];
}
```
```ts title="VaultFeesRecipientSplit"
interface VaultFeesRecipientSplit {
address: EvmAddress;
split: PercentValue;
isAaveLabs: boolean;
}
```
```ts title="UserVaultShares"
interface UserVaultShares {
shares: TokenAmount;
balance: TokenAmount;
}
```
```ts title="Reserve"
interface Reserve {
market: MarketInfo;
underlyingToken: Currency;
aToken: Currency;
vToken: Currency;
acceptsNative?: NativeCurrency;
size: TokenAmount;
usdExchangeRate: BigDecimal;
usdOracleAddress: EvmAddress;
isFrozen: boolean;
isPaused: boolean;
flashLoanEnabled: boolean;
supplyInfo: ReserveSupplyInfo;
borrowInfo?: ReserveBorrowInfo;
isolationModeConfig?: ReserveIsolationModeConfig; // deprecated in Aave V3.7
eModeInfo: EmodeReserveInfo[];
userState?: ReserveUserState;
}
```
The following GraphQL fragments illustrate the core Vault type and its related types:
```graphql title="Vault"
fragment Vault on Vault {
__typename
address
owner
shareName
shareSymbol
usedReserve {
...Reserve
}
fee {
...PercentValue
}
totalFeeRevenue {
...TokenAmount
}
balance {
...TokenAmount
}
feesBalance {
...TokenAmount
}
chainId
userShares {
...UserVaultShares
}
recipients {
...VaultFeesRecipientsConfiguration
}
}
```
```graphql title="UserVaultShares"
fragment UserVaultShares on UserVaultShares {
__typename
shares {
...TokenAmount
}
balance {
...TokenAmount
}
}
```
```graphql title="VaultFeesRecipientsConfiguration"
fragment VaultFeesRecipientsConfiguration on VaultFeesRecipientsConfiguration {
__typename
address
entries {
...VaultFeesRecipientSplit
}
}
```
```graphql title="VaultFeesRecipientSplit"
fragment VaultFeesRecipientSplit on VaultFeesRecipientSplit {
__typename
address
split {
...PercentValue
}
isAaveLabs
}
```
```graphql title="Reserve"
fragment Reserve on Reserve {
__typename
market {
...MarketInfo
}
underlyingToken {
...Currency
}
aToken {
...Currency
}
vToken {
...Currency
}
acceptsNative {
...NativeCurrency
}
size {
...TokenAmount
}
usdExchangeRate
usdOracleAddress
isFrozen
isPaused
flashLoanEnabled
supplyInfo {
...ReserveSupplyInfo
}
borrowInfo {
...ReserveBorrowInfo
}
isolationModeConfig {
...ReserveIsolationModeConfig
}
eModeInfo {
...EmodeReserveInfo
}
userState {
...ReserveUserState
}
}
```
```graphql title="Common"
fragment TokenAmount on TokenAmount {
__typename
usdPerToken
amount {
...DecimalValue
}
usd
}
fragment DecimalValue on DecimalValue {
__typename
raw
decimals
value
}
fragment Currency on Currency {
__typename
address
imageUrl
name
symbol
decimals
chainId
}
fragment PercentValue on PercentValue {
__typename
raw
decimals
value
formatted
}
```
## Fetching a Single Vault
Retrieve detailed information about a specific vault including underlying reserve and user shares.
Use the `useVault` hook in React, the `vault` action in TypeScript, or the `vault` query in GraphQL to fetch detailed information about a specific vault.
```ts title="Loading State"
const { data, loading, error } = useVault({
by: VaultRequestBy,
chainId: ChainId,
user: EvmAddress | undefined,
});
```
```ts title="React Suspense"
const { data } = useVault({
by: VaultRequestBy,
chainId: ChainId,
user: EvmAddress | undefined,
suspense: true,
});
```
```ts title="Vault By Address/ChainId"
import { evmAddress, chainId } from "@aave/client";
import { vault } from "@aave/client/actions";
import { client } from "./client";
const result = await vault(client, {
by: {
address: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
},
chainId: chainId(1),
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: Vault | null
console.log(result.value);
}
```
```ts title="Vault By Transaction Hash"
import { chainId } from "@aave/client";
import { vault } from "@aave/client/actions";
import { client } from "./client";
const result = await vault(client, {
by: {
txHash:
"0xeef2ffc57b99ce887edd8362c6d57e5c7a4d8c8a9b2c3d4e5f6789abc123def4",
},
chainId: chainId(1),
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: Vault | null
console.log(result.value);
}
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vault(
request: {
by: {
address: "0x1234567890abcdef1234567890abcdef12345678"
# OR
# txHash: "0xeef2ffc57b99ce887edd…"
}
chainId: 1
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
}
) {
address
owner
shareName
shareSymbol
fee {
raw
decimals
value
formatted
}
totalFeeRevenue {
amount {
value
}
usd
}
balance {
amount {
value
}
usd
}
feesBalance {
amount {
value
}
usd
}
usedReserve {
underlyingToken {
symbol
name
address
}
supplyInfo {
apy {
value
}
}
}
userShares {
shares {
amount {
value
}
usd
}
balance {
amount {
value
}
usd
}
}
}
}
```
```json title="Response"
{
"data": {
"vault": {
"address": "0x1234567890abcdef1234567890abcdef12345678",
"owner": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"shareName": "Aave USDC Vault Shares",
"shareSymbol": "avUSDC",
"fee": {
"raw": "100000000000000000000000000",
"decimals": 27,
"value": "0.1",
"formatted": "10.0"
},
"totalFeeRevenue": {
"amount": {
"value": "150.25"
},
"usd": "150.25"
},
"balance": {
"amount": {
"value": "50000.0"
},
"usd": "50000.0"
},
"feesBalance": {
"amount": {
"value": "100.00"
},
"usd": "100.00"
},
"usedReserve": {
"underlyingToken": {
"symbol": "USDC",
"name": "USD Coin",
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
},
"supplyInfo": {
"apy": {
"value": "0.045"
}
}
},
"userShares": {
"shares": {
"amount": {
"value": "1000.0"
},
"usd": "1025.5"
},
"balance": {
"amount": {
"value": "1025.5"
},
"usd": "1025.5"
}
}
}
}
}
```
In React, fetch a specific vault by address.
```tsx title="An Ethereum Vault"
import { useVault, evmAddress, chainId } from "@aave/react";
// …
const { data, loading, error } = useVault({
by: {
address: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
},
chainId: chainId(1),
});
if (loading) {
return Loading vault…;
}
if (error) {
return Error: {error.message};
}
if (!data) {
return Vault not found;
}
// data: Vault
```
Include a user address to get user-specific vault data like shares owned.
```tsx title="With User State"
import { useVault, evmAddress, chainId } from "@aave/react";
// …
const { data, loading, error } = useVault({
by: {
address: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
},
chainId: chainId(1),
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
});
```
```ts title="With User State"
import { evmAddress, chainId } from "@aave/client";
import { vault } from "@aave/client/actions";
import { client } from "./client";
const result = await vault(client, {
by: {
address: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
},
chainId: chainId(1),
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"), // Include user for userShares data
});
```
## Listing Available Vaults
Fetch multiple vaults with filtering and pagination support.
Use the `useVaults` hook in React, the `vaults` action in TypeScript, or the `vaults` query in GraphQL to fetch paginated vaults based on filter criteria.
```ts title="Loading State"
const { data, error, loading } = useVaults({
criteria: VaultsRequestFilterCriteria,
pageSize: PageSize | undefined,
user: EvmAddress | undefined,
cursor: Cursor | undefined,
});
```
```ts title="React Suspense"
const { data } = useVaults({
criteria: VaultsRequestFilterCriteria,
pageSize: PageSize | undefined,
user: EvmAddress | undefined,
cursor: Cursor | undefined,
suspense: true,
});
```
```ts title="VaultsRequestFilterCriteria"
interface VaultsRequestFilterCriteria {
/** Filter by specific vault addresses */
vaults?: VaultInput[];
/** Filter by owner addresses */
ownedBy?: EvmAddress[];
}
interface VaultInput {
/** The address of the vault */
address: EvmAddress;
/** The chain id the vault is on */
chainId: ChainId;
}
```
```ts title="Vaults By Owner"
import { evmAddress, PageSize } from "@aave/client";
import { vaults } from "@aave/client/actions";
import { client } from "./client";
const result = await vaults(client, {
criteria: {
ownedBy: [evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234")],
},
pageSize: PageSize.Ten,
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: PaginatedVaultsResult
console.log(result.value);
}
```
```ts title="Vaults By Address/ChainId"
import { evmAddress, chainId, PageSize } from "@aave/client";
import { vaults } from "@aave/client/actions";
import { client } from "./client";
const result = await vaults(client, {
criteria: {
vaults: [
{
address: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
chainId: chainId(1),
},
],
},
pageSize: PageSize.Ten,
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value.items: Vault[]
// result.value.pageInfo.next: Cursor | null
// result.value.pageInfo.prev: Cursor | null
console.log(result.value);
}
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vaults(
request: {
criteria: {
ownedBy: ["0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"]
# OR
# vaults: [
# {
# address: "0x1234567890abcdef1234567890abcdef12345678",
# chainId: 1,
# },
# ],
}
pageSize: TEN
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
}
) {
items {
address
owner
shareName
shareSymbol
fee {
raw
decimals
value
formatted
}
totalFeeRevenue {
amount {
value
}
usd
}
balance {
amount {
value
}
usd
}
feesBalance {
amount {
value
}
usd
}
chainId
}
pageInfo {
next
prev
}
}
}
```
```json title="Response"
{
"data": {
"vaults": {
"items": [
{
"address": "0x1234567890abcdef1234567890abcdef12345678",
"owner": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"shareName": "Aave USDC Vault Shares",
"shareSymbol": "avUSDC",
"fee": {
"raw": "100000000000000000000000000",
"decimals": 27,
"value": "0.1",
"formatted": "10.0"
},
"totalFeeRevenue": {
"amount": {
"value": "150.25"
},
"usd": "150.25"
},
"balance": {
"amount": {
"value": "50000.0"
},
"usd": "50000.0"
},
"feesBalance": {
"amount": {
"value": "100.00"
},
"usd": "100.00"
},
"chainId": 1
}
],
"pageInfo": {
"next": null,
"prev": null
}
}
}
}
```
In React, fetch vaults owned by a specific address.
```tsx title="Owned Vaults"
import { useVaults, evmAddress, PageSize } from "@aave/react";
// …
const { data, error, loading } = useVaults({
criteria: {
ownedBy: [evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234")],
},
pageSize: PageSize.Ten,
});
if (loading) {
return Loading…;
}
if (error) {
return {error.message};
}
// data.items: Vault[]
// data.pageInfo.next: Cursor | null
// data.pageInfo.prev: Cursor | null
```
Include a user address to get user-specific vault data like shares owned.
```tsx title="With User State"
import { useVaults, evmAddress, PageSize } from "@aave/react";
// …
const { data, loading, error } = useVaults({
criteria: {
ownedBy: [evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234")],
},
pageSize: PageSize.Ten,
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
});
```
```ts title="With User State"
import { evmAddress, PageSize } from "@aave/client";
import { vaults } from "@aave/client/actions";
import { client } from "./client";
const result = await vaults(client, {
criteria: {
ownedBy: [evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234")],
},
pageSize: PageSize.Ten,
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"), // Include user for userShares data
});
```
## User Vault Positions
Track user vault positions and shares across Aave Simple Earn Vaults.
Use the `useUserVaults` hook in React, the `userVaults` action in TypeScript, or the `userVaults` query in GraphQL to fetch paginated vaults that a user has shares in.
```ts title="Loading State"
const { data, loading, error } = useUserVaults({
user: EvmAddress,
filters: UserVaultsFilter | undefined,
orderBy: UserVaultsOrderBy | undefined,
pageSize: PageSize | undefined,
cursor: Cursor | undefined,
});
```
```ts title="React Suspense"
const { data } = useUserVaults({
user: EvmAddress,
filters: UserVaultsFilter | undefined,
orderBy: UserVaultsOrderBy | undefined,
pageSize: PageSize | undefined,
cursor: Cursor | undefined,
suspense: true,
});
```
```ts title="userVaults"
import { evmAddress, PageSize, OrderDirection } from "@aave/client";
import { userVaults } from "@aave/client/actions";
import { client } from "./client";
const result = await userVaults(client, {
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
orderBy: { shares: OrderDirection.Desc },
pageSize: PageSize.Ten,
});
if (result.isErr()) {
console.error("User vaults error:", result.error);
} else {
// result.value.items: Vault[]
// result.value.pageInfo.next: Cursor | null
// result.value.pageInfo.prev: Cursor | null
console.log(result.value);
}
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
userVaults(
request: {
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
orderBy: { shares: DESC }
pageSize: FIFTY
}
) {
items {
address
shareName
shareSymbol
usedReserve {
underlyingToken {
symbol
name
}
}
userShares {
shares {
amount {
value
}
usd
}
balance {
amount {
value
}
usd
}
}
}
pageInfo {
next
prev
}
}
}
```
```json title="Response"
{
"data": {
"userVaults": {
"items": [
{
"address": "0x1234567890abcdef1234567890abcdef12345678",
"shareName": "Aave USDC Vault Shares",
"shareSymbol": "avUSDC",
"usedReserve": {
"underlyingToken": {
"symbol": "USDC",
"name": "USD Coin"
}
},
"userShares": {
"shares": {
"amount": {
"value": "1000.0"
},
"usd": "1025.5"
},
"balance": {
"amount": {
"value": "1025.5"
},
"usd": "1025.5"
}
}
}
],
"pageInfo": {
"next": null,
"prev": null
}
}
}
}
```
In React, fetch user vaults ordered by shares amount.
```tsx title="User Vaults"
import {
useUserVaults,
evmAddress,
PageSize,
OrderDirection,
} from "@aave/react";
// …
const { data, error, loading } = useUserVaults({
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
orderBy: { shares: OrderDirection.Desc },
pageSize: PageSize.Fifty,
});
if (error) {
return Error: {error.message};
}
if (loading) {
return Loading positions…;
}
// data.items: Vault[]
// data.pageInfo.next: Cursor | null
// data.pageInfo.prev: Cursor | null
```
## User Vault Transaction History
Track user vault transaction history.
Use the `useVaultUserTransactionHistory` hook in React, the `vaultUserTransactionHistory` action in TypeScript, or the `vaultUserTransactionHistory` query in GraphQL to fetch a paginated user’s vault transaction history.
```ts title="Loading State"
const { data, loading, error } = useVaultUserTransactionHistory({
user: EvmAddress,
vault: EvmAddress,
chainId: ChainId,
filters: VaultUserHistoryAction | undefined,
orderBy: VaultUserTransactionHistoryOrderBy | undefined,
pageSize: PageSize | undefined,
cursor: Cursor | undefined,
});
```
```ts title="React Suspense"
const { data } = useVaultUserTransactionHistory({
user: EvmAddress,
vault: EvmAddress,
chainId: ChainId,
filters: VaultUserHistoryAction | undefined,
orderBy: VaultUserTransactionHistoryOrderBy | undefined,
pageSize: PageSize | undefined,
cursor: Cursor | undefined,
suspense: true,
});
```
```ts title="vaultUserTransactionHistory"
import { evmAddress, chainId, PageSize, OrderDirection } from "@aave/client";
import { vaultUserTransactionHistory } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultUserTransactionHistory(client, {
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
vault: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
chainId: chainId(1),
orderBy: { date: OrderDirection.Desc },
pageSize: PageSize.Ten,
});
if (result.isErr()) {
console.error("User vault transactions error:", result.error);
} else {
// result.value.items: VaultUserTransactionHistoryItem[]
// result.value.pageInfo.next: Cursor | null
// result.value.pageInfo.prev: Cursor | null
console.log(result.value);
}
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vaultUserTransactionHistory(
request: {
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
vault: "0x1234567890abcdef1234567890abcdef12345678"
chainId: 1
orderBy: { date: DESC }
pageSize: FIFTY
}
) {
items {
... on VaultUserDepositItem {
asset {
usd
usdPerToken
amount {
raw
decimals
value
}
}
shares {
usd
usdPerToken
amount {
raw
decimals
value
}
}
blockExplorerUrl
txHash
timestamp
}
... on VaultUserWithdrawItem {
asset {
usd
usdPerToken
amount {
raw
decimals
value
}
}
shares {
usd
usdPerToken
amount {
raw
decimals
value
}
}
blockExplorerUrl
txHash
timestamp
}
}
pageInfo {
next
prev
}
}
}
```
```json title="Response"
{
"data": {
"vaultUserTransactionHistory": {
"items": [
{
"asset": {
"usd": "1000.0",
"usdPerToken": "1.0",
"amount": {
"raw": "1000000000",
"decimals": 6,
"value": "1000.0"
}
},
"shares": {
"usd": "1000.0",
"usdPerToken": "1.0",
"amount": {
"raw": "1000000000",
"decimals": 6,
"value": "1000.0"
}
},
"blockExplorerUrl": "https://etherscan.io/tx/0xeef2ffc57b99ce887edd8362c6d57e5c7a4d8c8a9b2c3d4e5f6789abc123def4",
"txHash": "0xeef2ffc57b99ce887edd8362c6d57e5c7a4d8c8a9b2c3d4e5f6789abc123def4",
"timestamp": "2021-01-01T00:00:00Z"
}
],
"pageInfo": {
"next": null,
"prev": null
}
}
}
}
```
In React, fetch user vault transaction history ordered by date.
```tsx title="User Vault Transactions"
import {
useVaultUserTransactionHistory,
evmAddress,
chainId,
PageSize,
OrderDirection,
} from "@aave/react";
// …
const { data, error, loading } = useVaultUserTransactionHistory({
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
vault: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
chainId: chainId(1),
orderBy: { date: OrderDirection.Desc },
pageSize: PageSize.Fifty,
});
if (error) {
return Error: {error.message};
}
if (loading) {
return Loading transactions…;
}
// data.items: VaultUserTransactionHistoryItem[]
// data.pageInfo.next: Cursor | null
// data.pageInfo.prev: Cursor | null
```
## Vault User Activity
Return a user’s activity for a vault, including earnings breakdowns over time.
Use the `useVaultUserActivity` hook in React, the `vaultUserActivity` action in TypeScript, or the `vaultUserActivity` query in GraphQL to fetch the user’s activity for a vault.
```ts title="Loading State"
const { data, loading, error } = useVaultUserActivity({
user: EvmAddress,
vault: EvmAddress,
chainId: ChainId,
window: VaultUserActivityTimeWindow,
});
```
```ts title="React Suspense"
const { data } = useVaultUserActivity({
user: EvmAddress,
vault: EvmAddress,
chainId: ChainId,
window: VaultUserActivityTimeWindow,
suspense: true,
});
```
```ts title="vaultUserActivity"
import { evmAddress, chainId, VaultUserActivityTimeWindow } from "@aave/client";
import { vaultUserActivity } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultUserActivity(client, {
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
vault: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
chainId: chainId(1),
window: VaultUserActivityTimeWindow.LastWeek,
});
if (result.isErr()) {
console.error("User vault activity error:", result.error);
} else {
// result.value: VaultUserActivityResult
}
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```graphql title="Query"
query {
vaultUserActivity(
request: {
user: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
vault: "0x1234567890abcdef1234567890abcdef12345678"
chainId: 1
window: LAST_WEEK
}
) {
earned {
usd
usdPerToken
amount {
raw
decimals
value
}
}
breakdown {
balance {
usd
usdPerToken
amount {
raw
decimals
value
}
}
earned {
usd
usdPerToken
amount {
raw
decimals
value
}
}
withdrew {
usd
usdPerToken
amount {
raw
decimals
value
}
}
deposited {
usd
usdPerToken
amount {
raw
decimals
value
}
}
date
}
}
}
```
```json title="Response"
{
"data": {
"vaultUserActivity": {
"earned": {
"usd": "1000.0",
"usdPerToken": "1.0",
"amount": {
"raw": "1000000000",
"decimals": 6,
"value": "1000.0"
}
},
"breakdown": [
{
"balance": {
"usd": "1000.0",
"usdPerToken": "1.0",
"amount": {
"raw": "1000000000",
"decimals": 6,
"value": "1000.0"
}
},
"earned": {
"usd": "1000.0",
"usdPerToken": "1.0",
"amount": {
"raw": "1000000000",
"decimals": 6,
"value": "1000.0"
}
},
"withdrew": null,
"deposited": null,
"date": "2021-01-01T00:00:00Z"
}
]
}
}
}
```
In React, fetch the user’s vault activity.
```tsx title="User Vault Activity"
import {
useVaultUserActivity,
evmAddress,
chainId,
VaultUserActivityTimeWindow,
} from "@aave/react";
// …
const { data, error, loading } = useVaultUserActivity({
user: evmAddress("0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"),
vault: evmAddress("0x1234567890abcdef1234567890abcdef12345678"),
chainId: chainId(1),
window: VaultUserActivityTimeWindow.LastWeek,
});
if (error) {
return Error: {error.message};
}
if (loading) {
return Loading transactions…;
}
// data: VaultUserActivityResult
```
---
Source: https://aave.com/docs/vaults/simple-earn/operations.md
# Aave Simple Earn Vault Operations
Execute core vault operations such as deposits and withdrawals. Users can choose to interact with the vault using either the asset amount deposited or the vault shares minted.
Shares start at a 1:1 ratio when the vault launches. As the vault earns interest, each share is worth more of the underlying asset, so a deposit mints fewer shares than the assets it adds.
## Identify the Vault
[Fetch the vault](/vaults/simple-earn/data#fetching-a-single-vault) with the user address to populate `userShares`. This page uses the following vault in its examples:
```ts title="Vault"
const vault: Vault = {
__typename: "Vault",
address: "0x1234567890abcdef1234567890abcdef12345678",
shareName: "Aave USDC Vault Shares",
shareSymbol: "avUSDC",
chainId: 1,
usedReserve: {
__typename: "Reserve",
underlyingToken: {
__typename: "Currency",
symbol: "USDC",
name: "USD Coin",
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
// …
},
isFrozen: false,
isPaused: false,
// …
},
userShares: {
__typename: "UserVaultShares",
shares: {
__typename: "TokenAmount",
amount: {
__typename: "DecimalValue",
value: "1000.0", // User has 1000 vault shares
// …
},
// …
},
// …
},
// …
};
```
> [!NOTE]
> Deposits and mints need the reserve not frozen and not paused. Withdrawals and
> redeems need it not paused.
## Deposit Assets
Depositing assets into an Aave Simple Earn Vault gives the user an amount of vault shares.
To deposit assets into an Aave Simple Earn Vault, follow these steps.
### 1. Preview the Deposit
First, preview the deposit operation to determine the amount of vault shares that would be received for a given amount of assets. Use the `useVaultDepositPreview` hook in React, the `vaultPreviewDeposit` action in TypeScript, or the `vaultPreviewDeposit` query in GraphQL to preview the deposit operation.
```tsx title="Preview the Deposit"
import { bigDecimal, useVaultDepositPreview } from "@aave/react";
// …
const [preview /* , { loading, error } */] = useVaultDepositPreview();
// …
const result = await preview({
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 USDC
});
// …
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 975.13408 (shares to receive)
}
```
```ts title="Preview the Deposit"
import { bigDecimal } from "@aave/client";
import { vaultPreviewDeposit } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultPreviewDeposit(client, {
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 USDC
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 975.13408 (shares to receive)
}
```
```graphql title="Query"
query {
vaultPreviewDeposit(
request: {
vault: "0x1234567890abcdef1234567890abcdef12345678"
chainId: 1
amount: "1000"
}
) {
usdPerToken
amount {
raw
decimals
value
}
usd
}
}
```
```json title="Response"
{
"data": {
"vaultPreviewDeposit": {
"usdPerToken": "1.0255",
"amount": {
"raw": "975134080",
"decimals": 6,
"value": "975.13408"
},
"usd": "1000"
}
}
}
```
### 2. Prepare the Deposit Execution Plan
Next, create the execution plan for the deposit operation. Use the `useVaultDeposit` hook in React, the `vaultDeposit` action in TypeScript, or the `vaultDeposit` query in GraphQL to create the execution plan for depositing assets into a vault.
> [!NOTE]
> Deposits the underlying asset by default. Set `asAToken` to `true` to deposit
> the aToken instead.
```tsx title="Deposit Assets"
import { useWalletClient } from "wagmi";
import { useVaultDeposit, bigDecimal, evmAddress } from "@aave/react";
// …
const { data: walletClient } = useWalletClient();
const [deposit, depositing] = useVaultDeposit();
const execute = async () => {
const result = await deposit({
chainId: vault.chainId,
vault: vault.address,
amount: {
value: bigDecimal(1000), // 1000 USDC
// Optional: If set to true, the aToken associated with the vault will be deposited
// asAToken: false (default)
},
depositor: evmAddress(walletClient!.account.address),
});
// …
};
```
```ts title="Deposit Assets"
import { bigDecimal, evmAddress } from "@aave/client";
import { vaultDeposit } from "@aave/client/actions";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultDeposit(client, {
chainId: vault.chainId,
vault: vault.address,
amount: {
value: bigDecimal(1000), // 1000 USDC
// Optional: If set to true, the aToken associated with the vault will be deposited
// asAToken: false (default)
},
depositor: evmAddress(wallet.account.address),
});
// …
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```ts title="wallet.ts"
import { createWalletClient, http, type Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
export const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
chain: mainnet,
transport: http(),
});
```
```graphql title="Query"
query {
vaultDeposit(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
amount: {
value: "1000"
# Optional: If set to true, the aToken associated with the vault will be deposited
# asAToken: false (default)
}
depositor: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
}
) {
__typename
... on TransactionRequest {
to
from
data
value
chainId
operation
}
... on ApprovalRequired {
reason
requiredAmount {
value
decimals
}
currentAllowance {
value
decimals
}
approval {
to
from
data
value
chainId
operation
}
originalTransaction {
to
from
data
value
chainId
operation
}
}
... on InsufficientBalanceError {
required {
value
decimals
}
available {
value
decimals
}
}
}
}
```
### 3. Process the Deposit Execution Plan
Finally, handle the execution plan.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transactions in the execution plan.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to send the transactions in the execution plan, and await indexing with `client.waitForTransaction`.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { errAsync, useVaultDeposit } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [deposit, depositing] = useVaultDeposit();
const [sendTransaction, sending] = useSendTransaction(walletClient);
// …
const loading = depositing.loading || sending.loading;
const error = depositing.error || sending.error;
// …
const execute = async () => {
const result = await deposit({
// …
}).andThen((plan) => {
switch (plan.__typename) {
case "TransactionRequest":
// Single transaction execution
return sendTransaction(plan);
case "ApprovalRequired":
// Approval + transaction sequence
return sendTransaction(plan.approval).andThen(() =>
sendTransaction(plan.originalTransaction)
);
case "InsufficientBalanceError":
return errAsync(
new Error(`Insufficient balance: ${plan.required.value} required.`)
);
}
});
if (result.isErr()) {
console.error("Deposit failed:", result.error);
} else {
console.log("Deposit successful with hash:", result.value);
}
};
```
```ts title="Viem"
import { vaultDeposit } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultDeposit(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Deposit failed:", result.error);
} else {
console.log("Deposit successful:", result.value);
}
```
In GraphQL, if the response is a `TransactionRequest`, you can send it directly using the wallet associated with the `from` address.
```json title="TransactionRequest"
{
"data": {
"vaultDeposit": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x6e553f65000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"value": "0",
"chainId": 1,
"operation": "VAULT_DEPOSIT"
}
}
}
```
If the response is an `ApprovalRequired`, you must first send the `approval` transaction. Once it succeeds, you can then send the `originalTransaction`.
```json title="ApprovalRequired"
{
"data": {
"vaultDeposit": {
"__typename": "ApprovalRequired",
"reason": "Insufficient allowance for ERC-20 token transfer",
"requiredAmount": {
"value": "1000.0",
"decimals": 6
},
"currentAllowance": {
"value": "0.0",
"decimals": 6
},
"approval": {
"to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x095ea7b3000000000000000000000000123456789…",
"value": "0",
"chainId": 1,
"operation": null
},
"originalTransaction": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x6e553f65000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"value": "0",
"chainId": 1,
"operation": "VAULT_DEPOSIT"
}
}
}
}
```
If the response is an `InsufficientBalanceError`, inform the user that they don’t have enough balance to deposit the requested amount.
```json title="InsufficientBalanceError"
{
"data": {
"vaultDeposit": {
"__typename": "InsufficientBalanceError",
"required": {
"value": "1000.0",
"decimals": 6
},
"available": {
"value": "750.0",
"decimals": 6
}
}
}
}
```
## Mint Vault Shares
Minting vault shares is the process of creating new vault shares by depositing assets into the vault.
To mint vault shares, follow these steps.
### 1. Preview the Mint
First, preview the mint operation to determine the amount of assets needed to mint the requested amount of vault shares. Use the `useVaultMintPreview` hook in React, the `vaultPreviewMint` action in TypeScript, or the `vaultPreviewMint` query in GraphQL to preview the mint operation.
```tsx title="Preview the Mint"
import { bigDecimal, useVaultMintPreview } from "@aave/react";
// …
const [preview /* , { loading, error } */] = useVaultMintPreview();
// …
const result = await preview({
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 vault shares
});
// …
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 1025.5 (assets needed)
}
```
```ts title="Preview the Mint"
import { bigDecimal } from "@aave/client";
import { vaultPreviewMint } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultPreviewMint(client, {
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 vault shares
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 1025.5 (assets needed)
}
```
```graphql title="Query"
query {
vaultPreviewMint(
request: {
vault: "0x1234567890abcdef1234567890abcdef12345678"
chainId: 1
amount: "1000"
}
) {
usdPerToken
amount {
raw
decimals
value
}
usd
}
}
```
```json title="Response"
{
"data": {
"vaultPreviewMint": {
"usdPerToken": "1.0",
"amount": {
"raw": "1025500000",
"decimals": 6,
"value": "1025.5"
},
"usd": "1025.5"
}
}
}
```
### 2. Prepare the Mint Execution Plan
Next, create the execution plan for the mint shares operation. Use the `useVaultMintShares` hook in React, the `vaultMintShares` action in TypeScript, or the `vaultMintShares` query in GraphQL to create the execution plan for minting vault shares.
```tsx title="Mint Shares"
import { useWalletClient } from "wagmi";
import { useVaultMintShares, bigDecimal, evmAddress } from "@aave/react";
// …
const { data: walletClient } = useWalletClient();
const [mintShares, minting] = useVaultMintShares();
const execute = async () => {
const result = await mintShares({
chainId: vault.chainId,
vault: vault.address,
shares: {
amount: bigDecimal(1000), // 1000 vault shares
},
minter: evmAddress(walletClient!.account.address),
// sharesRecipient: evmAddress("0x1234…"), if different from minter
});
// …
};
```
```ts title="Mint Shares"
import { bigDecimal, evmAddress } from "@aave/client";
import { vaultMintShares } from "@aave/client/actions";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultMintShares(client, {
chainId: vault.chainId,
vault: vault.address,
shares: {
amount: bigDecimal(1000), // 1000 vault shares
},
minter: evmAddress(wallet.account.address),
// sharesRecipient: evmAddress("0x1234…"), if different from minter
});
// …
```
```ts title="client.ts"
import { AaveClient } from "@aave/client";
export const client = AaveClient.create();
```
```ts title="wallet.ts"
import { createWalletClient, http, type Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
export const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
chain: mainnet,
transport: http(),
});
```
```graphql title="Query"
query {
vaultMintShares(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
shares: { amount: "1000" }
minter: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
# sharesRecipient: "0x1234…", if different from minter
}
) {
__typename
... on TransactionRequest {
to
from
data
value
chainId
operation
}
... on ApprovalRequired {
reason
requiredAmount {
value
decimals
}
currentAllowance {
value
decimals
}
approval {
to
from
data
value
chainId
operation
}
originalTransaction {
to
from
data
value
chainId
operation
}
}
... on InsufficientBalanceError {
required {
value
decimals
}
available {
value
decimals
}
}
}
}
```
### 3. Process the Mint Execution Plan
Finally, handle the execution plan.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transactions in the execution plan.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to send the transactions in the execution plan, and await indexing with `client.waitForTransaction`.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { errAsync, useVaultMintShares } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [mintShares, minting] = useVaultMintShares();
const [sendTransaction, sending] = useSendTransaction(walletClient);
// …
const loading = minting.loading || sending.loading;
const error = minting.error || sending.error;
// …
const execute = async () => {
const result = await mintShares({
// …
}).andThen((plan) => {
switch (plan.__typename) {
case "TransactionRequest":
// Single transaction execution
return sendTransaction(plan);
case "ApprovalRequired":
// Approval + transaction sequence
return sendTransaction(plan.approval).andThen(() =>
sendTransaction(plan.originalTransaction)
);
case "InsufficientBalanceError":
return errAsync(
new Error(`Insufficient balance: ${plan.required.value} required.`)
);
}
});
if (result.isErr()) {
console.error("Mint shares failed:", result.error);
} else {
console.log("Mint shares successful with hash:", result.value);
}
};
```
```ts title="Viem"
import { vaultMintShares } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultMintShares(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Mint shares failed:", result.error);
} else {
console.log("Mint shares successful:", result.value);
}
```
In GraphQL, if the response is a `TransactionRequest`, you can send it directly using the wallet associated with the `from` address.
```json title="TransactionRequest"
{
"data": {
"vaultMintShares": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x94bf804d000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"value": "0",
"chainId": 1,
"operation": "VAULT_DEPOSIT"
}
}
}
```
If the response is an `ApprovalRequired`, you must first send the `approval` transaction. Once it succeeds, you can then send the `originalTransaction`.
```json title="ApprovalRequired"
{
"data": {
"vaultMintShares": {
"__typename": "ApprovalRequired",
"reason": "Insufficient allowance for ERC-20 token transfer",
"requiredAmount": {
"value": "1025.5",
"decimals": 6
},
"currentAllowance": {
"value": "0.0",
"decimals": 6
},
"approval": {
"to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x095ea7b3000000000000000000000000123456789…",
"value": "0",
"chainId": 1,
"operation": null
},
"originalTransaction": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0x94bf804d000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"value": "0",
"chainId": 1,
"operation": "VAULT_DEPOSIT"
}
}
}
}
```
If the response is an `InsufficientBalanceError`, inform the user that they don’t have enough balance to mint the requested amount of shares.
```json title="InsufficientBalanceError"
{
"data": {
"vaultMintShares": {
"__typename": "InsufficientBalanceError",
"required": {
"value": "1025.5",
"decimals": 6
},
"available": {
"value": "750.0",
"decimals": 6
}
}
}
}
```
## Withdraw Assets
Withdrawing assets from an Aave Simple Earn Vault gives the user an amount of assets. The corresponding amount of vault shares is burned.
To withdraw assets from an Aave Simple Earn Vault, follow these steps.
### 1. Preview the Withdraw
First, preview the withdraw operation to determine the amount of shares that will be burned for a given amount of assets. Use the `useVaultWithdrawPreview` hook in React, the `vaultPreviewWithdraw` action in TypeScript, or the `vaultPreviewWithdraw` query in GraphQL to preview the withdraw operation.
```tsx title="Preview the Withdraw"
import { bigDecimal, useVaultWithdrawPreview } from "@aave/react";
// …
const [preview /* , { loading, error } */] = useVaultWithdrawPreview();
// …
const result = await preview({
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 USDC
});
// …
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 975.134081 (shares to burn)
}
```
```ts title="Preview the Withdraw"
import { bigDecimal } from "@aave/client";
import { vaultPreviewWithdraw } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultPreviewWithdraw(client, {
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 USDC
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 975.134081 (shares to burn)
}
```
```graphql title="Query"
query {
vaultPreviewWithdraw(
request: {
vault: "0x1234567890abcdef1234567890abcdef12345678"
chainId: 1
amount: "1000"
}
) {
usdPerToken
amount {
raw
decimals
value
}
usd
}
}
```
```json title="Response"
{
"data": {
"vaultPreviewWithdraw": {
"usdPerToken": "1.0255",
"amount": {
"raw": "975134081",
"decimals": 6,
"value": "975.134081"
},
"usd": "1000"
}
}
}
```
### 2. Prepare the Withdraw Transaction
Next, create the transaction request for the withdrawal operation. Use the `useVaultWithdraw` hook in React, the `vaultWithdraw` action in TypeScript, or the `vaultWithdraw` query in GraphQL to create the transaction request for withdrawing assets from a vault.
> [!NOTE]
> Withdraws the underlying asset by default. Set `asAToken` to `true` to
> withdraw the aToken instead.
```tsx title="Withdraw Assets"
import { useWalletClient } from "wagmi";
import { useVaultWithdraw, bigDecimal, evmAddress } from "@aave/react";
// …
const { data: walletClient } = useWalletClient();
const [withdraw, withdrawing] = useVaultWithdraw();
const execute = async () => {
const result = await withdraw({
chainId: vault.chainId,
vault: vault.address,
amount: {
value: bigDecimal(500), // 500 USDC
// Optional: If set to true, the aToken associated with the vault will be withdrawn
// asAToken: false (default)
},
sharesOwner: evmAddress(walletClient!.account.address),
// recipient: evmAddress("0x1234…"), if different from sharesOwner
});
// …
};
```
```ts title="Withdraw Assets"
import { bigDecimal, evmAddress } from "@aave/client";
import { vaultWithdraw } from "@aave/client/actions";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultWithdraw(client, {
chainId: vault.chainId,
vault: vault.address,
amount: {
value: bigDecimal(500), // 500 USDC
// Optional: If set to true, the aToken associated with the vault will be withdrawn
// asAToken: false (default)
},
sharesOwner: evmAddress(wallet.account.address),
// recipient: evmAddress("0x1234…"), if different from sharesOwner
});
// …
```
```graphql title="Query"
query {
vaultWithdraw(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
amount: {
value: "500"
# Optional: If set to true, the aToken associated with the vault will be withdrawn
# asAToken: false (default)
}
sharesOwner: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
# recipient: "0x1234…", if different from sharesOwner
}
) {
to
from
data
value
chainId
}
}
```
### 3. Send the Withdraw Transaction
Finally, send the transaction.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transaction.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to initiate the transaction, and await indexing with `client.waitForTransaction`.
- **GraphQL**: The response is a `TransactionRequest` that can be sent directly using the wallet associated with the `from` address.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { useVaultWithdraw } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [withdraw, withdrawing] = useVaultWithdraw();
const [sendTransaction, sending] = useSendTransaction(walletClient);
const loading = withdrawing.loading || sending.loading;
const error = withdrawing.error || sending.error;
// …
const execute = async () => {
const result = await withdraw({
// …
}).andThen(sendTransaction);
if (result.isErr()) {
console.error("Withdrawal failed:", result.error);
} else {
console.log("Withdrawal successful with hash:", result.value);
}
};
```
```ts title="Viem"
import { vaultWithdraw } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultWithdraw(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Withdrawal failed:", result.error);
} else {
console.log("Withdrawal successful:", result.value);
}
```
```json title="TransactionRequest"
{
"data": {
"vaultWithdraw": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0xb460af94000000000000000000000000000000000000000000000000000000001dcd6500000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"value": "0",
"chainId": 1,
"operation": "VAULT_WITHDRAW"
}
}
}
```
## Redeem Vault Shares
Redeeming vault shares is the process of burning vault shares and receiving the underlying assets.
To redeem vault shares, follow these steps.
### 1. Preview the Redeem
First, preview the redeem operation to determine the amount of assets that will be received for a given amount of shares burned. Use the `useVaultRedeemPreview` hook in React, the `vaultPreviewRedeem` action in TypeScript, or the `vaultPreviewRedeem` query in GraphQL to preview the redeem operation.
```tsx title="Preview the Redeem"
import { bigDecimal, useVaultRedeemPreview } from "@aave/react";
// …
const [preview /* , { loading, error } */] = useVaultRedeemPreview();
// …
const result = await preview({
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 vault shares
});
// …
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 1025.5 (assets to receive)
}
```
```ts title="Preview the Redeem"
import { bigDecimal } from "@aave/client";
import { vaultPreviewRedeem } from "@aave/client/actions";
import { client } from "./client";
const result = await vaultPreviewRedeem(client, {
vault: vault.address,
chainId: vault.chainId,
amount: bigDecimal(1000), // 1000 vault shares
});
if (result.isErr()) {
console.error(result.error);
} else {
// result.value: TokenAmount
console.log(result.value.amount.value); // 1025.5 (assets to receive)
}
```
```graphql title="Query"
query {
vaultPreviewRedeem(
request: {
vault: "0x1234567890abcdef1234567890abcdef12345678"
chainId: 1
amount: "1000"
}
) {
usdPerToken
amount {
raw
decimals
value
}
usd
}
}
```
```json title="Response"
{
"data": {
"vaultPreviewRedeem": {
"usdPerToken": "1.0",
"amount": {
"raw": "1025500000",
"decimals": 6,
"value": "1025.5"
},
"usd": "1025.5"
}
}
}
```
### 2. Prepare the Redeem Transaction
Next, create the transaction request for the redeem operation. Use the `useVaultRedeemShares` hook in React, the `vaultRedeemShares` action in TypeScript, or the `vaultRedeemShares` query in GraphQL to create the transaction request for redeeming vault shares.
```tsx title="Redeem Shares"
import { useWalletClient } from "wagmi";
import { useVaultRedeemShares, bigDecimal, evmAddress } from "@aave/react";
// …
const { data: walletClient } = useWalletClient();
const [redeemShares, redeeming] = useVaultRedeemShares();
const execute = async () => {
const result = await redeemShares({
chainId: vault.chainId,
vault: vault.address,
shares: {
amount: bigDecimal(1000), // 1000 vault shares
},
sharesOwner: evmAddress(walletClient!.account.address),
// recipient: evmAddress("0x1234…"), if different from sharesOwner
});
// …
};
```
```ts title="Redeem Shares"
import { bigDecimal, evmAddress } from "@aave/client";
import { vaultRedeemShares } from "@aave/client/actions";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultRedeemShares(client, {
chainId: vault.chainId,
vault: vault.address,
shares: {
amount: bigDecimal(1000), // 1000 vault shares
},
sharesOwner: evmAddress(wallet.account.address),
// recipient: evmAddress("0x1234…"), if different from sharesOwner
});
// …
```
```graphql title="Query"
query {
vaultRedeemShares(
request: {
chainId: 1
vault: "0x1234567890abcdef1234567890abcdef12345678"
shares: { amount: "1000" }
sharesOwner: "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234"
# recipient: "0x1234…", if different from sharesOwner
}
) {
to
from
data
value
chainId
}
}
```
### 3. Send the Redeem Transaction
Finally, send the transaction.
- **React**: Use the `useSendTransaction` hook for the [wallet library of your choice](/aave-v3/getting-started/react#send-aave-transactions) to send the transaction.
- **TypeScript**: Use `sendWith` for your [chosen wallet library](/aave-v3/getting-started/typescript#send-aave-transactions) to initiate the transaction, and await indexing with `client.waitForTransaction`.
- **GraphQL**: The response is a `TransactionRequest` that can be sent directly using the wallet associated with the `from` address.
```tsx title="Viem"
import { useWalletClient } from "wagmi";
import { useVaultRedeemShares } from "@aave/react";
import { useSendTransaction } from "@aave/react/viem";
// …
const { data: walletClient } = useWalletClient();
const [redeemShares, redeeming] = useVaultRedeemShares();
const [sendTransaction, sending] = useSendTransaction(walletClient);
const loading = redeeming.loading || sending.loading;
const error = redeeming.error || sending.error;
// …
const execute = async () => {
const result = await redeemShares({
// …
}).andThen(sendTransaction);
if (result.isErr()) {
console.error("Redeem shares failed:", result.error);
} else {
console.log("Redeem shares successful with hash:", result.value);
}
};
```
```ts title="Viem"
import { vaultRedeemShares } from "@aave/client/actions";
import { sendWith } from "@aave/client/viem";
import { client } from "./client";
import { wallet } from "./wallet";
const result = await vaultRedeemShares(client, {
// …
})
.andThen(sendWith(wallet))
.andThen(client.waitForTransaction);
if (result.isErr()) {
console.error("Redeem shares failed:", result.error);
} else {
console.log("Redeem shares successful:", result.value);
}
```
```json title="TransactionRequest"
{
"data": {
"vaultRedeemShares": {
"to": "0x1234567890abcdef1234567890abcdef12345678",
"from": "0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"data": "0xba087652000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234000000000000000000000000742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234",
"value": "0",
"chainId": 1,
"operation": "VAULT_WITHDRAW"
}
}
}
```