Deploy Vault
To deploy a new Aave vault, follow these steps.
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.
Reserve
const reserve: Reserve = { __typename: "Reserve", market: { __typename: "MarketInfo", address: "0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2", chainId: 1, // … }, underlyingToken: { __typename: "Currency", symbol: "WETH", name: "Wrapped Ether", address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // … }, isFrozen: false, isPaused: false, // …};
Ensure the reserve is not frozen or paused.
Next, create the execution plan for deploying the vault.
- React
- TypeScript
- GraphQL
Use the useVaultDeploy hook to create the execution plan for deploying a vault.
Deploy Vault
import { useWalletClient } from "wagmi";import { useVaultDeploy, bigDecimal, evmAddress } from "@aave/react";
// …
const { data: walletClient } = useWalletClient();
const [deployVault, deploying] = useVaultDeploy();
const execute = async () => { const result = await deployVault({ 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(3), // 3% performance fee shareName: "Aave WETH Vault Shares", shareSymbol: "avWETH", initialLockDeposit: bigDecimal(1000), // 1000 WETH initial deposit });
// …};
Finally, handle the execution plan.
- React
- TypeScript
- GraphQL
Use the useSendTransaction hook for the wallet library of your choice to send the transactions in the execution plan.
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 statesconst loading = deploying.loading || sending.loading;const error = deploying.error || sending.error;
// …
const execute = async () => { const result = await deployVault({ // … }).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); }};