# Fund Creation

## Fund Creation

Anyone can create a vault via `HyperFunFactory` or the [hypers.fun/launch](https://www.hypers.fun/launch) UI.

### Launch UI (hypers.fun)

#### Required Fields

| Field           | Description                                     |
| --------------- | ----------------------------------------------- |
| **Vault Name**  | Name of your fund (e.g., "Alpha Trading Vault") |
| **Symbol**      | 2-10 letter token symbol (e.g., "ATV")          |
| **Vault Image** | PNG or JPG, up to 5MB                           |

#### Optional Fields

| Field                   | Description                                                                  |
| ----------------------- | ---------------------------------------------------------------------------- |
| **Performance Fee (%)** | Fee charged on profits when investors exit with gains (default 10%, max 30%) |
| **Description**         | Details about your vault strategy                                            |
| **Social Links**        | Twitter, Telegram, etc.                                                      |

#### UI Flow

1. Connect wallet
2. Fill in vault details
3. Preview on the right panel
4. Click "Create Token" / "DEPLOY"
5. Approve USDC (1 USDC for L1 init fee)
6. Confirm transaction
7. Vault created!

***

### Factory Entrypoints

#### Simple Creation

```solidity
function createVault(
    string calldata _name,           // "Alpha Trading Vault"
    string calldata _symbol,         // "ATV"
    uint256 _performanceFeeBps       // Performance fee (max 30%)
) external returns (address core, address trading);
```

Creates a vault with default bonding curve parameters. Exit fees use global settings from Factory.

#### Advanced Creation (Owner Only)

```solidity
function createVaultAdvanced(
    string calldata _name,
    string calldata _symbol,
    uint256 _performanceFeeBps,
    uint256 _bcVirtualBase,          // Bonding curve virtual base
    uint256 _bcVirtualTokens,        // Bonding curve virtual tokens
    uint256 _initialAssets           // Initial assets baseline
) external onlyOwner returns (address core, address trading);
```

Creates a vault with custom bonding curve parameters. Only factory owner can use this.

***

### Creation Requirements

| Requirement     | Value                    |
| --------------- | ------------------------ |
| Performance Fee | Max 30% (3000 bps)       |
| Name            | Non-empty string         |
| Symbol          | 2-10 letters             |
| L1 Init Fee     | 1 USDC (paid by creator) |
| Creation Fee    | Configurable (default 0) |

***

### Creation Flow

```
Creator calls createVault()
         │
         ▼
┌─────────────────────────────────────────┐
│ 1. Validate parameters                  │
│    • name not empty                     │
│    • symbol not empty                   │
│    • feeBps <= 3000 (30%)              │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│ 2. Collect fees                         │
│    • Creation fee → Treasury (if set)   │
│    • L1 init fee (1 USDC) → Factory    │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│ 3. Deploy contracts                     │
│    • Deploy Trading proxy (ERC1967)     │
│    • Deploy Token proxy (ERC1967)       │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│ 4. Initialize contracts                 │
│    • Trading.initialize(token, factory) │
│    • Token.initialize(leader, trading)  │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│ 5. Configure vault                      │
│    • Approve builder fee (if set)       │
│    • Set admin to factory owner         │
│    • Initialize L1 account (1 USDC)     │
└─────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────┐
│ 6. Register vault                       │
│    • Add to allVaults[]                 │
│    • Add to vaultsByLeader[creator]     │
│    • Store VaultInfo                    │
└─────────────────────────────────────────┘
         │
         ▼
    Emit VaultCreated event
    Return (core, trading)
```

***

### Default Parameters

When using `createVault()`, these defaults are applied:

| Parameter         | Default Value     | Description           |
| ----------------- | ----------------- | --------------------- |
| `bcVirtualBase`   | 2,000,000 \* 1e18 | Virtual USDC reserve  |
| `bcVirtualTokens` | 2,000,000 \* 1e18 | Virtual token reserve |
| `initialAssets`   | 100,000 \* 1e18   | BC scaling baseline   |

***

### Global Settings (Applied to All Vaults)

Exit fees and other settings are managed globally by factory owner:

#### Trading Settings

| Setting     | Default | Description                    |
| ----------- | ------- | ------------------------------ |
| Trading Fee | 1%      | Fee on buy/sell                |
| Min Deposit | 5 USDC  | Minimum buy amount             |
| Max Buy     | 1%      | Max % of vault per transaction |

#### Price Limits

| Setting      | Default | Description                   |
| ------------ | ------- | ----------------------------- |
| Max Premium  | 100%    | Price can be up to 2x NAV     |
| Max Discount | 50%     | Price can be down to 0.5x NAV |

#### Rebalance Settings

| Setting        | Default | Description            |
| -------------- | ------- | ---------------------- |
| Reserve Ratio  | 50%     | Target EVM reserve     |
| Rebalance Low  | 48%     | Trigger when EVM < 48% |
| Rebalance High | 52%     | Trigger when EVM > 52% |

#### Exit Fee Tiers (Default)

| Days Held  | Fee |
| ---------- | --- |
| < 7 days   | 15% |
| 7-30 days  | 8%  |
| 30-90 days | 3%  |
| > 90 days  | 0%  |

***

### Roles After Creation

| Role   | Assigned To   | Permissions                      |
| ------ | ------------- | -------------------------------- |
| Leader | Vault creator | Trading, API wallets, metadata   |
| Admin  | Factory owner | Pause, trading module, emergency |
| Owner  | Factory owner | Upgrades                         |

> **Note:** The creator becomes the Leader but NOT the Admin. This protects investors from malicious upgrades.

***

### Post-Creation Setup

After vault creation, the leader can:

#### 1. Update Metadata

If you created via UI, metadata is already set. To update:

```solidity
IHyperFunToken(core).setMetadataURI("ipfs://Qm...");
```

Metadata JSON format:

```json
{
  "name": "Alpha Trading Vault",
  "description": "High-frequency SOL trading strategy",
  "image": "ipfs://Qm.../image.png",
  "social": {
    "twitter": "https://twitter.com/...",
    "telegram": "https://t.me/..."
  }
}
```

#### 2. Add API Wallets (Optional)

```solidity
IHyperFunTrading(trading).addApiWallet(
    apiWalletAddress,
    "Trading Bot",
    90  // Duration in days (60-180, or 0 for unlimited)
);
```

#### 3. Make Initial Deposit

```solidity
// Approve USDC first
IERC20(USDC).approve(core, amount);

// Leader deposit at NAV (no bonding curve, no trading fee)
IHyperFunToken(core).deposit(amount);
```

#### 4. Start Trading

```solidity
// Open a long position on SOL
IHyperFunTrading(trading).executeMarketOrder(
    5,          // asset (5 = SOL)
    true,       // isBuy (long)
    100000000,  // size (1.0 SOL in 1e8)
    15000000000 // price with slippage (1e8 format)
);
```

***

### Example: Create Vault via Contract

```javascript
const { ethers } = require('ethers');

const FACTORY = '0xeE7dB1582e46c054792AdD4bb52b8D4D6ab45555';
const USDC = '0xb88339CB7199b77E23DB6E890353E22632Ba630f';

const factoryAbi = [
  'function createVault(string,string,uint256) external returns (address,address)'
];
const erc20Abi = [
  'function approve(address,uint256) external returns (bool)'
];

async function createVault(signer) {
  const factory = new ethers.Contract(FACTORY, factoryAbi, signer);
  const usdc = new ethers.Contract(USDC, erc20Abi, signer);

  // Approve 1 USDC for L1 init fee
  await usdc.approve(FACTORY, 1000000);

  // Create vault
  const tx = await factory.createVault(
    "My Alpha Vault",    // name
    "MAV",               // symbol
    2000                 // 20% performance fee (2000 bps)
  );

  const receipt = await tx.wait();

  // Parse VaultCreated event
  const iface = new ethers.Interface([
    'event VaultCreated(address indexed leader, address indexed core, address indexed trading, string name, string symbol, uint256 performanceFeeBps)'
  ]);

  for (const log of receipt.logs) {
    try {
      const parsed = iface.parseLog(log);
      console.log("Core:", parsed.args.core);
      console.log("Trading:", parsed.args.trading);
      return { core: parsed.args.core, trading: parsed.args.trading };
    } catch {}
  }
}
```

***

### Events

```solidity
event VaultCreated(
    address indexed leader,
    address indexed core,
    address indexed trading,
    string name,
    string symbol,
    uint256 performanceFeeBps
);
```

***

### Query Vaults

```solidity
// Get all vaults
function getAllVaults() external view returns (address[] memory);

// Get vaults by leader
function getVaultsByLeader(address leader) external view returns (address[] memory);

// Get vault info
function getVaultInfo(address vault) external view returns (VaultInfo memory);

// Get verified vaults only
function getVerifiedVaults() external view returns (address[] memory);

// Total vault count
function totalVaults() external view returns (uint256);
```

***

### Related Pages

* VaultCore - Token contract details
* VaultTrading - Trading module details
* VaultFactory - Factory contract details
* ContractAddresses - Deployed addresses
* Buy & Sell - Trading vault tokens


---

# 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://hyper-fun.gitbook.io/hypers.fun/how-it-works/fund-creation.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.
