# Create a vault

> Deploy a HyperVault and HyperPerpEngine pair through HyperVaultFactory, then fund it, set a keeper and run the first roll.

Source: https://docs.degenhive.ai/vaults/create

This guide deploys a third-party vault on HyperEVM (chain 999) with one call to `HyperVaultFactory.deployStrategyVault`, then takes it to its first trade.

You need:

- a wallet that passes `canCreateVault` (see step 1), with HYPE for gas and at least 20 USDC on HyperEVM (10 USDC creation fee, 10 USDC first deposit);
- a keeper address for your trading bot (it can hold only gas);
- `viem` 2.x or Foundry's `cast`.

> [!IMPORTANT]
> Nothing is deployed yet. `FACTORY`, `CONFIG`, `USDC`, `VAULT` and `ENGINE` are placeholders. Addresses publish at launch on [Network](https://docs.degenhive.ai/network.md).

Shared setup for the viem snippets:

`client.ts`

```ts
import { createPublicClient, createWalletClient, defineChain, http, type Address } from "viem";
import { privateKeyToAccount } from "viem/accounts";

// Placeholders: addresses publish at launch.
export const CONFIG = process.env.CONFIG as Address;   // HyperVaultConfig
export const FACTORY = process.env.FACTORY as Address; // HyperVaultFactory
export const USDC = process.env.USDC as Address;       // USDC on HyperEVM
export const VAULT = process.env.VAULT as Address;     // your vault, after step 6
export const ENGINE = process.env.ENGINE as Address;   // your engine, after step 6
export const KEEPER = process.env.KEEPER as Address;

export const hyperEvm = defineChain({
  id: 999,
  name: "HyperEVM",
  nativeCurrency: { name: "HYPE", symbol: "HYPE", decimals: 18 },
  rpcUrls: { default: { http: ["https://rpc.hyperliquid.xyz/evm"] } },
});

export const account = privateKeyToAccount(process.env.MANAGER_KEY as `0x${string}`);
export const publicClient = createPublicClient({ chain: hyperEvm, transport: http() });
export const wallet = createWalletClient({ account, chain: hyperEvm, transport: http() });
```

## Step 1: Check that you can create a vault

`HyperVaultConfig.creationMode` starts at `OFF`, where only the council deploys, and only flagships. In `WHITELISTED` mode your address must be on the council's creator whitelist. In `PERMISSIONLESS` mode anyone can deploy. Ask the config directly:

**viem**

```ts
import { parseAbi } from "viem";
import { CONFIG, account, publicClient } from "./client";

export const configAbi = parseAbi([
  "struct TierBounds { uint24 maxGrossBps; uint16 maxNetExposureBps; uint16 maxDailyLossBps; uint16 maxDrawdownBps; uint32 assetWeightMultiplierBps; }",
  "function canCreateVault(address creator, bool isFlagship) view returns (bool)",
  "function creationMode() view returns (uint8)",
  "function creationFeeUsdc() view returns (uint256)",
  "function maxCapForManager(address manager) view returns (uint256)",
  "function tierBounds(uint8 tier) view returns (TierBounds)",
  "function isAssetAllowedForVault(uint32 assetId, uint8 marketTier, uint8 vaultTier) view returns (bool allowed, uint16 maxWeightBps)",
]);

const allowed = await publicClient.readContract({
  address: CONFIG, abi: configAbi, functionName: "canCreateVault", args: [account.address, false],
});
const capCeiling = await publicClient.readContract({
  address: CONFIG, abi: configAbi, functionName: "maxCapForManager", args: [account.address],
});
console.log({ allowed, capCeiling }); // capCeiling defaults to 2,000,000 USDC (2_000_000e6)
```

**cast**

```bash
cast call $CONFIG "canCreateVault(address,bool)(bool)" $ME false --rpc-url $HYPEREVM_RPC
cast call $CONFIG "maxCapForManager(address)(uint256)" $ME --rpc-url $HYPEREVM_RPC
cast call $CONFIG "tierBounds(uint8)((uint24,uint16,uint16,uint16,uint32))" 2 --rpc-url $HYPEREVM_RPC
```

If `canCreateVault` returns false, the deploy reverts with `CreationNotAllowed(creator, isFlagship)`.

## Step 2: Choose the DNA

DNA is permanent. The factory checks it against the global bounds and your tier's `TierBounds` (see the table on [Vaults](https://docs.degenhive.ai/vaults.md#tiers)), then copies it into the engine with no setter.

| Field | Type | Rule |
|---|---|---|
| `isFlagship` | `bool` | `false` for every third-party vault. Must equal `vaultTier == FLAGSHIP`. |
| `marketTier` | `uint8` | 1 (majors), 2 (top 50 + HIP-3) or 3 (long tail). You may trade every tier up to this one. |
| `maxGrossBps` | `uint24` | 5,000–50,000 and at most the tier's `maxGrossBps` |
| `maxNetExposureBps` | `uint16` | At most `maxGrossBps`, the tier cap (5,000 or 30,000) and the global cap (30,000) |
| `maxDailyLossBps` | `uint16` | 50–1,000, at most the tier cap |
| `vaultTier` | `uint8` | 1 `INSTITUTIONAL` or 2 `COMMUNITY_ARENA` |
| `maxDrawdownBps` | `uint16` | 200 up to the tier cap (2,500 institutional, 5,000 community arena) |

Any rule broken reverts with `InvalidPolicy()`.

## Step 3: Choose fees and the forecast job

| Field | Type | Rule |
|---|---|---|
| `mgmtFeeBps` | `uint16` | 0–200 per year, on external shares |
| `perfFeeBps` | `uint16` | 1,000–2,500, above the per-share high-water mark |
| `forecastShareBps` | `uint16` | 0–5,000, share of the net performance fee paid to the job's forecasters |
| `forecastJobId` | `uint64` | Required when the share is above 0. Job 1 (the flagship job) or a job bound to this vault. |
| `managerFeeRecipient` | `address` | Required. Receives your share of both fees. |

`stepMarket` trades the signal of `forecastJobId`, or job 1 when it is 0. A vault that pays a forecaster share usually follows that job's rounds. See [Jobs and rounds](https://docs.degenhive.ai/forecasters/jobs-and-rounds.md). Out-of-bounds fees revert with `InvalidPolicy()`; a zero fee recipient reverts with `ZeroAddress()`.

## Step 4: Choose the starting risk params

`EngineRiskParams` are the engine's execution knobs. You can tighten them at once later and loosen them after 7 days.

| Field | Type | Default bound | Meaning |
|---|---|---|---|
| `minMarginRatioBps` | `uint16` | 1,000–10,000 | Equity over total notional. Below it, gross-increasing steps revert and anyone may flatten. |
| `maxDailyTurnoverBps` | `uint32` | 5,000–100,000 | Traded notional per UTC day, in bps of day-start equity |
| `maxStepBps` | `uint16` | 0–50,000 | Largest weight change per step. 0 means go straight to target. |
| `maxSlippageBps` | `uint16` | 5–500 | Limit price distance from the oracle for IOC and GTC orders |
| `makerOffsetBps` | `uint16` | 0–200 | Distance inside the oracle price for ALO orders |
| `defaultTif` | `uint8` | 1–3 | 1 ALO, 2 GTC, 3 IOC |
| `maxIdleSecs` | `uint32` | 1–14 days | After this long with no step or heartbeat, anyone may flatten |

Out-of-bounds values revert with `InvalidPolicy()`.

## Step 5: Approve the creation fee

Third-party vaults pay `creationFeeUsdc` (10 USDC by default, at most 1,000 USDC) when the caller is not the council. The factory sends it straight to `HyperRevenueRouter.notifyRevenue`. Set `maxCreationFeeUsdc` in your params to the fee you read, so a fee change cannot surprise you.

**viem**

```ts
import { erc20Abi } from "viem";
import { CONFIG, FACTORY, USDC, publicClient, wallet } from "./client";
import { configAbi } from "./check";

const fee = await publicClient.readContract({ address: CONFIG, abi: configAbi, functionName: "creationFeeUsdc" });
await wallet.writeContract({ address: USDC, abi: erc20Abi, functionName: "approve", args: [FACTORY, fee] });
```

**cast**

```bash
FEE=$(cast call $CONFIG "creationFeeUsdc()(uint256)" --rpc-url $HYPEREVM_RPC)
cast send $USDC "approve(address,uint256)" $FACTORY $FEE --rpc-url $HYPEREVM_RPC --account manager
```

If the live fee is above your `maxCreationFeeUsdc`, the deploy reverts with `CreationFeeTooHigh(feeUsdc, maxFeeUsdc)`.

## Step 6: Deploy the vault

This call deploys an engine proxy and a vault proxy, initializes both and registers them. The struct below matches `DeployVaultParams` in `IHyperVaultPlatform.sol`, field for field. `VaultTier` is a `uint8` in the ABI.

**viem**

```ts
import { parseAbi, parseEventLogs, parseUnits, zeroAddress } from "viem";
import { FACTORY, KEEPER, account, publicClient, wallet } from "./client";

const factoryAbi = parseAbi([
  "struct VaultDna { bool isFlagship; uint8 marketTier; uint24 maxGrossBps; uint16 maxNetExposureBps; uint16 maxDailyLossBps; uint8 vaultTier; uint16 maxDrawdownBps; }",
  "struct FeeConfig { uint16 mgmtFeeBps; uint16 perfFeeBps; uint16 forecastShareBps; uint64 forecastJobId; address managerFeeRecipient; }",
  "struct EngineRiskParams { uint16 minMarginRatioBps; uint32 maxDailyTurnoverBps; uint16 maxStepBps; uint16 maxSlippageBps; uint16 makerOffsetBps; uint8 defaultTif; uint32 maxIdleSecs; }",
  "struct DeployVaultParams { string name; string symbol; address strategyManager; address keeper; address complianceAdmin; VaultDna dna; FeeConfig fees; EngineRiskParams risk; uint256 vaultCapUsdc; bool lockerCapEnabled; bool whitelistEnabled; bool whitelistTransfers; uint256 maxCreationFeeUsdc; }",
  "function deployStrategyVault(DeployVaultParams params) returns (address vault, address engine)",
  "event VaultDeployed(address indexed vault, address indexed engine, address indexed creator, address strategyManager, address complianceAdmin, address vaultProxyAdmin, address engineProxyAdmin, uint256 creationFeeUsdc, DeployVaultParams params)",
  "error CreationNotAllowed(address creator, bool isFlagship)",
  "error VaultCapCeilingExceeded(uint256 requestedCap, uint256 maxAllowedCap)",
  "error CreationFeeTooHigh(uint256 feeUsdc, uint256 maxFeeUsdc)",
  "error InvalidPolicy()",
  "error Unauthorized()",
  "error ZeroAddress()",
  "error ZeroAmount()",
]);

const params = {
  name: "Trend50",
  symbol: "dhT50",
  strategyManager: zeroAddress, // zero = you
  keeper: KEEPER,
  complianceAdmin: zeroAddress, // zero with a whitelist = the manager
  dna: {
    isFlagship: false,
    marketTier: 2,           // majors plus top 50 and HIP-3
    maxGrossBps: 20_000,     // 2x gross
    maxNetExposureBps: 10_000, // 1x net
    maxDailyLossBps: 300,    // 3% daily loss stop
    vaultTier: 2,            // COMMUNITY_ARENA
    maxDrawdownBps: 2_000,   // 20% below the high-water mark latches
  },
  fees: {
    mgmtFeeBps: 100,         // 1% per year
    perfFeeBps: 2_000,       // 20% above HWM
    forecastShareBps: 1_000, // 10% of the net perf fee to job 1's forecasters
    forecastJobId: 1n,
    managerFeeRecipient: account.address,
  },
  risk: {
    minMarginRatioBps: 1_500,
    maxDailyTurnoverBps: 20_000,
    maxStepBps: 2_500,
    maxSlippageBps: 30,
    makerOffsetBps: 2,
    defaultTif: 1,           // ALO
    maxIdleSecs: 3 * 86_400,
  },
  vaultCapUsdc: parseUnits("250000", 6),
  lockerCapEnabled: false,
  whitelistEnabled: false,
  whitelistTransfers: false,
  maxCreationFeeUsdc: parseUnits("10", 6),
} as const;

const { request } = await publicClient.simulateContract({
  account, address: FACTORY, abi: factoryAbi, functionName: "deployStrategyVault", args: [params],
});
const hash = await wallet.writeContract(request);
const receipt = await publicClient.waitForTransactionReceipt({ hash });

const [deployed] = parseEventLogs({ abi: factoryAbi, eventName: "VaultDeployed", logs: receipt.logs });
console.log("vault", deployed.args.vault, "engine", deployed.args.engine);
```

**cast**

```bash
PARAMS_SIG="deployStrategyVault((string,string,address,address,address,(bool,uint8,uint24,uint16,uint16,uint8,uint16),(uint16,uint16,uint16,uint64,address),(uint16,uint32,uint16,uint16,uint16,uint8,uint32),uint256,bool,bool,bool,uint256))"
ZERO=0x0000000000000000000000000000000000000000

cast send $FACTORY "$PARAMS_SIG" \
  "(Trend50,dhT50,$ZERO,$KEEPER,$ZERO,(false,2,20000,10000,300,2,2000),(100,2000,1000,1,$ME),(1500,20000,2500,30,2,1,259200),250000000000,false,false,false,10000000)" \
  --rpc-url $HYPEREVM_RPC --account manager
```

What the factory does in that transaction:

1. Pulls the creation fee and sends it to `HyperRevenueRouter`.
2. Deploys the engine and vault pair behind a 72-hour upgrade delay.
3. Writes a `VaultRecord` (`vaultRecord(vault)`, `isVault(vault)`, `engineOf(vault)`) and adds 1 to `managerActiveVaultCount(manager)`.
4. Initializes the vault (fees, cap, keeper, whitelist) and the engine (DNA, risk params, the Core deposit wallet). It re-validates the DNA and risk params.
5. At token launch, registers the vault with `HyperBookRewards`. Before the token this step is skipped.
6. Emits `VaultDeployed`.

Reverts you can hit:

- `CreationNotAllowed(creator, isFlagship)`: the creation mode does not allow you.
- `InvalidPolicy()`: empty name or symbol, or DNA, fees or risk params out of bounds.
- `ZeroAmount()`: `vaultCapUsdc` is 0.
- `Unauthorized()`: you named someone else as `strategyManager`. Only the council may.
- `VaultCapCeilingExceeded(requestedCap, maxAllowedCap)`: the cap is above `maxCapForManager(you)`.
- `CreationFeeTooHigh(feeUsdc, maxFeeUsdc)`: the live fee is above your limit.
- `ZeroAddress()`: missing fee recipient, or the protocol's router or upgrade controller is not wired.

## Step 7: Set the keeper

The keeper is the hot address your bot signs with. It can trade, bridge, deploy idle USDC to the engine and roll early. It cannot change fees, risk params or the manager. Change it any time; the change is instant.

**viem**

```ts
import { parseAbi } from "viem";
import { VAULT, wallet } from "./client";

const NEW_KEEPER = "0x..." as const; // your bot's address
const vaultAbi = parseAbi(["function setKeeper(address keeper)"]);
await wallet.writeContract({ address: VAULT, abi: vaultAbi, functionName: "setKeeper", args: [NEW_KEEPER] });
```

**cast**

```bash
cast send $VAULT "setKeeper(address)" $NEW_KEEPER --rpc-url $HYPEREVM_RPC --account manager
```

Only the manager or the council can call it (`Unauthorized()` otherwise). A zero keeper is allowed; then only you and the council can trade.

## Step 8: Make the first deposit

Seed the vault with your own capital. The minimum request is 10 USDC (`DepositBelowMinimum(amount, minAmount)` below that). The very first roll that mints shares sends 1 share (1e6 units, 1 USDC at the starting price) to `0x…dEaD`, so a tiny first deposit cannot distort the share price.

**viem**

```ts
import { erc20Abi, parseAbi, parseUnits } from "viem";
import { USDC, VAULT, account, wallet } from "./client";

const amount = parseUnits("1000", 6);
const depositAbi = parseAbi([
  "function requestDeposit(uint256 assets, address controller, address owner) returns (uint256)",
]);
await wallet.writeContract({ address: USDC, abi: erc20Abi, functionName: "approve", args: [VAULT, amount] });
await wallet.writeContract({
  address: VAULT, abi: depositAbi, functionName: "requestDeposit", args: [amount, account.address, account.address],
});
```

**cast**

```bash
cast send $USDC "approve(address,uint256)" $VAULT 1000000000 --rpc-url $HYPEREVM_RPC --account manager
cast send $VAULT "requestDeposit(uint256,address,address)" 1000000000 $ME $ME --rpc-url $HYPEREVM_RPC --account manager
```

When the council enables skin in the game, outside deposits are capped by your own stake: the free starter cap (50,000 USDC by default) plus 20 times your co-investment. See [Risk](https://docs.degenhive.ai/vaults/risk.md#manager-skin-in-the-game).

## Step 9: Run the first roll and fund the engine

The vault's clock starts on the UTC day of deployment. The first roll is due from the next 00:00 UTC. Your keeper rolls between 00:00 and 02:00; after that, anyone can.

**viem**

```ts
import { parseAbi, parseUnits } from "viem";
import { ENGINE, VAULT, account, wallet } from "./client";

const opsAbi = parseAbi([
  "function roll()",
  "function realize(address user)",
  "function deployToEngine(uint256 usdcAmount)",
  "function bridgeUsdcToCore(uint256 usdcAmount, uint32 destinationDex)",
]);

await wallet.writeContract({ address: VAULT, abi: opsAbi, functionName: "roll" });
await wallet.writeContract({ address: VAULT, abi: opsAbi, functionName: "realize", args: [account.address] });
await wallet.writeContract({ address: VAULT, abi: opsAbi, functionName: "deployToEngine", args: [parseUnits("900", 6)] });
await wallet.writeContract({ address: ENGINE, abi: opsAbi, functionName: "bridgeUsdcToCore", args: [parseUnits("900", 6), 0] });
```

**cast**

```bash
cast send $VAULT "roll()" --rpc-url $HYPEREVM_RPC --account keeper
cast send $VAULT "realize(address)" $ME --rpc-url $HYPEREVM_RPC --account manager
cast send $VAULT "deployToEngine(uint256)" 900000000 --rpc-url $HYPEREVM_RPC --account keeper
cast send $ENGINE "bridgeUsdcToCore(uint256,uint32)" 900000000 0 --rpc-url $HYPEREVM_RPC --account keeper
```

`roll()` reverts with `RollNotDue()` if the vault already rolled today, and `Unauthorized()` if a non-role calls it before 02:00 UTC. `bridgeUsdcToCore` sends USDC to perp dex 0 (`0`) or to spot (`4294967295`, `type(uint32).max`). It opens a 30-second bridge window: deposits, rolls and steps revert with `BridgeInFlight()` until it closes. A second bridge within 2 minutes reverts with `BridgeTooSoon(nextAllowedAt)`.

Before you step an asset, confirm it is open to your vault with `isAssetAllowedForVault(assetId, marketTier, vaultTier)` on the config. Every stepped market must also be listed in `HyperSignalBook`.

## Step 10: Where to go next

- [Trading](https://docs.degenhive.ai/vaults/trading.md) Write the keeper loop that steps your book.
- [Risk](https://docs.degenhive.ai/vaults/risk.md) What stops a vault and how to wind one down.
- [Fees](https://docs.degenhive.ai/vaults/fees.md) How your fees flow through the waterfall.
- [Deposits & withdrawals](https://docs.degenhive.ai/vaults/depositors.md) How depositors enter, settle and redeem shares.
