> ## Documentation Index
> Fetch the complete documentation index at: https://docs.defindex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Factory Methods

Deploying a vault by calling the factory contract yourself, for a deployment script or `stellar-cli`. To deploy through the API instead, see [Create a Vault](/integration-guide/creating-a-defindex-vault/index).

Factory addresses are on [Contract Deployments](/contract-deployments/index).

## Vault Role IDs

When calling the factory contract directly, roles are passed as a `Map<u32, Address>`. The role IDs are:

| ID  | Role              | Description                                          |
| --- | ----------------- | ---------------------------------------------------- |
| `0` | Emergency Manager | Can pause strategies and rescue funds in emergencies |
| `1` | Fee Receiver      | Receives vault performance fees                      |
| `2` | Manager           | Full administrative control over the vault           |
| `3` | Rebalance Manager | Can rebalance asset allocations across strategies    |

All four roles must be assigned. The same address can be used for multiple roles.

***

## Function: `create_defindex_vault`

```rust theme={null}
fn create_defindex_vault(
    e: Env,
    roles: Map<u32, Address>,
    vault_fee: u32,
    assets: Vec<AssetStrategySet>,
    soroswap_router: Address,
    name_symbol: Map<String, String>,
    upgradable: bool,
) -> Result<Address, FactoryError>
```

### Parameter Reference

| Parameter         | Type                    | Description                                                                                                                      |
| ----------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `roles`           | `Map<u32, Address>`     | Maps role IDs (0–3) to Stellar addresses. All four roles are required.                                                           |
| `vault_fee`       | `u32`                   | Vault fee in basis points (1 bps = 0.01%). Range: 0 to 9,000. Above 9,000 the vault panics with `MaximumFeeExceeded`, error 106. |
| `assets`          | `Vec<AssetStrategySet>` | The assets the vault manages and their associated strategies.                                                                    |
| `soroswap_router` | `Address`               | Address of the Soroswap router used for internal swaps.                                                                          |
| `name_symbol`     | `Map<String, String>`   | Metadata: must contain keys `"name"` and `"symbol"`.                                                                             |
| `upgradable`      | `bool`                  | If `true`, the Manager can upgrade the vault's WASM without user signatures.                                                     |

### `AssetStrategySet` Structure

```rust theme={null}
struct AssetStrategySet {
    address: Address,          // The token contract address (e.g., USDC or XLM SAC)
    strategies: Vec<Strategy>, // Strategies that manage this asset
}

struct Strategy {
    address: Address, // Strategy contract address
    name: String,     // Human-readable name (stored on-chain)
    paused: bool,     // Set to false on creation; strategies start active
}
```

### Example: `stellar-cli` (Testnet, USDC vault)

```bash theme={null}
stellar contract invoke \
  --rpc-url https://soroban-testnet.stellar.org \
  --network-passphrase 'Test SDF Network ; September 2015' \
  --id CDSCWE4GLNBYYTES2OCYDFQA2LLY4RBIAX6ZI32VSUXD7GO6HRPO4A32 \
  --source-account deployer \
  -- \
  create_defindex_vault \
  --roles '{"0":"GCKFBEIY...","1":"GCKFBEIY...","2":"GCKFBEIY...","3":"GCKFBEIY..."}' \
  --vault_fee 100 \
  --assets '[{"address":"CAQCFVLOBK5GIULPNZRGATJJMIZL5BSP7X5YJVMGCPTUEPFM4AVSRCJU","strategies":[{"address":"CALLOM5I7XLQPPOPQMYAHUWW4N7O3JKT42KQ4ASEEVBXDJQNJOALFSUY","name":"BlendUSDC Strategy","paused":false}]}]' \
  --soroswap_router CCJUD55AG6W5HAI5LRVNKAE5WDP5XGZBUDS5WNTIVDU7O264UZZE7BRD \
  --name_symbol '{"name":"My USDC Vault","symbol":"MUSDC"}' \
  --upgradable true
```

> Replace `GCKFBEIY...` with your actual Stellar addresses for each role.

## Function: `create_defindex_vault_deposit`

Creates a vault **and** makes the initial deposit in one transaction.

```rust theme={null}
fn create_defindex_vault_deposit(
    e: Env,
    caller: Address,
    roles: Map<u32, Address>,
    vault_fee: u32,
    assets: Vec<AssetStrategySet>,
    soroswap_router: Address,
    name_symbol: Map<String, String>,
    upgradable: bool,
    amounts: Vec<i128>,
) -> Result<Address, FactoryError>
```

Additional parameter over `create_defindex_vault`:

| Parameter | Type        | Description                                                                                              |
| --------- | ----------- | -------------------------------------------------------------------------------------------------------- |
| `caller`  | `Address`   | The address that signs the transaction and makes the deposit.                                            |
| `amounts` | `Vec<i128>` | Initial deposit amounts in stroops, one per asset in the same order as `assets`. Minimum 1001 per asset. |
