Vault (V3)
The Vault contract is an ERC-4626 compliant vault token contract that represents shares in a YieldFi v3 vault.
Connecting to Vault
Using Wagmi
import { connectVault } from "yieldfi-sdk";
import { ethers } from "ethers";
import { useAccount, useWalletClient } from "wagmi";
import VaultABI from "yieldfi-sdk/abis/v3/Vault.json";
function VaultExample() {
const { address } = useAccount();
const { data: walletClient } = useWalletClient();
const connectVaultContract = async (vaultAddress: string) => {
if (!walletClient) {
throw new Error("Wallet not connected");
}
const provider = new ethers.BrowserProvider(walletClient);
const signer = await provider.getSigner();
// For read-only operations, use provider
const vaultReadOnly = connectVault(vaultAddress, VaultABI, provider);
// For write operations, use signer
const vault = connectVault(vaultAddress, VaultABI, signer);
return { vault, vaultReadOnly };
};
}Using Browser Provider
ERC-20 Operations
Get Balance
Transfer Shares
Approve Spending
Get Allowance
ERC-4626 Operations
Deposit Assets
Deposit assets directly to the vault (alternative to using Manager).
Redeem Shares
Redeem shares for assets.
Mint Shares
Mint shares by depositing assets.
Withdraw Assets
Withdraw assets by redeeming shares.
Conversion Functions
Convert Shares to Assets
Convert Assets to Shares
Preview Functions
Preview the amount you'll receive before executing operations.
Preview Deposit
Preview Mint
Preview Redeem
Preview Withdraw
Vault-Specific Functions
Get Asset Address
Get Total Assets
Get Total Supply
Get Rate
Get the current exchange rate (assets per share).
Locked Shares
Get locked shares for a user (shares locked in redemption queue).
Lock Shares (Internal)
Lock shares for redemption (typically called by Manager).
Unlock Shares (Internal)
Unlock shares (typically called by Manager when cancelling redemption).
Vault Information
Get Vault Details
Complete Example
Using Wagmi
Using Browser Provider
Type Safety
The SDK provides TypeScript types for type-safe contract interactions:
Using Wagmi
Using Browser Provider
Last updated