# Contracts

## v3 Contracts

The YieldFi SDK provides TypeScript types for type-safe smart contract interactions with YieldFi v3 contracts using ethers.js. This section covers how to interact with YieldFi v3 smart contracts.

### Available V3 Contracts

* **Manager V3** - Core protocol manager contract for deposits and withdrawals
* **Vault** - ERC-4626 vault token contracts (represents vault shares)

### V3 Contract ABIs

V3 contract ABIs are included in the SDK package:

```typescript
import ManagerV3ABI from "yieldfi-sdk/abis/v3/Manager.json";
import VaultABI from "yieldfi-sdk/abis/v3/Vault.json";
```

### Quick Start

#### Using Wagmi

```typescript
import {
  connectManagerV3,
  connectVault,
  getContractAddresses,
  Chain,
} from "yieldfi-sdk";
import { ethers } from "ethers";
import { useAccount, useWalletClient } from "wagmi";
import ManagerV3ABI from "yieldfi-sdk/abis/v3/Manager.json";
import VaultABI from "yieldfi-sdk/abis/v3/Vault.json";

function ContractExample() {
  const { address } = useAccount();
  const { data: walletClient } = useWalletClient();

  const connectContracts = async () => {
    if (!walletClient || !address) {
      throw new Error("Wallet not connected");
    }

    // Setup provider and signer from wagmi
    const provider = new ethers.BrowserProvider(walletClient);
    const signer = await provider.getSigner();

    // Get contract addresses
    const contracts = getContractAddresses(Chain.ETHEREUM);

    // Connect to Manager V3
    const managerV3 = connectManagerV3(
      contracts.manager,
      ManagerV3ABI,
      signer
    );

    // Connect to a specific Vault (get address from Vault API)
    const vaultAddress = "0x5bE91d34FeFbB7554497a74e25dC6df96bFef5DB";
    const vault = connectVault(vaultAddress, VaultABI, provider);

    return { managerV3, vault };
  };
}
```

#### Using Browser Provider

```typescript
import {
  connectManagerV3,
  connectVault,
  getContractAddresses,
  Chain,
} from "yieldfi-sdk";
import { ethers } from "ethers";
import ManagerV3ABI from "yieldfi-sdk/abis/v3/Manager.json";
import VaultABI from "yieldfi-sdk/abis/v3/Vault.json";

// Connect to browser wallet
if (!window.ethereum) {
  throw new Error("No wallet found");
}

const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

// Get contract addresses
const contracts = getContractAddresses(Chain.ETHEREUM);

// Connect to Manager V3
const managerV3 = connectManagerV3(
  contracts.manager,
  ManagerV3ABI,
  signer
);

// Connect to a specific Vault (get address from Vault API)
const vaultAddress = "0x5bE91d34FeFbB7554497a74e25dC6df96bFef5DB";
const vault = connectVault(vaultAddress, VaultABI, provider);
```

### V3 Contract Architecture

#### Manager V3

The Manager V3 contract handles:

* **Deposits**: Users deposit assets, receive vault shares
* **Redemption Requests**: Users request redemption, shares are locked
* **Redemption Processing**: Operators process redemptions from queue
* **Queue Management**: Track and manage redemption queue

#### Vault Contract (ERC-4626)

The Vault contract is an ERC-4626 compliant vault token:

* Represents shares in a vault
* Supports standard ERC-4626 operations
* Shares can be locked for redemption requests
* Provides conversion between shares and assets

### Next Steps

* Manager Contract - Manager V3 contract operations
* Vault Contract - Vault contract operations (ERC-4626)
* Examples - Complete integration examples


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yield.fi/earn-with-yieldfi/integration-sdk/contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
