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

# CLI

Follow the steps in the [CLI introduction](https://docs.glam.systems/v1/cli/introduction) to install the GLAM CLI.

<Info>
  All transactions mentioned on this page were executed on mainnet using GLAM CLI v1.0.2. There might be some differences in the most recent versions. Check help messages first if you encounter any issues.
</Info>

### Preparation

Before starting, ensure you have:

* **Solana keypairs** for each persona. Create new keypairs with `solana-keygen new -o keypair.json`. See [Solana CLI docs](https://solana.com/docs/intro/installation) for more details.
* **SOL** in each account for transaction fees.
* **USDC** for the user account to subscribe to the vault.
* **Jupiter API key** (optional but recommended). Required for commands that fetch token prices (e.g., `vault token-balances`). Get one for free on [Jupiter Developer Platform](https://portal.jup.ag/pricing).

### Setup

In this quickstart, there are three personas:

* **Vault owner**: creates a vault, configures it, and grants the delegate proper permissions for operations.
  * `HQsXBSrJait1Gt8FJSNhf87p8cddRAy4WEbGzQvdeC3M`
  * Funded with 0.1 SOL
* **Delegate**: allocates fund, and fulfills user requests.
  * `ndcXmTFuMPkJ5mE4sYNnZdSo99Ajzny88xnrids4QnG`
  * Funded with 0.01 SOL
* **User**: subscribes to the vault, then redeems shares.
  * `gpoPk9Aa7yZoFsfkAUiaH85UsdDvoFz8gZrTGbjtAX8`
  * Funded with 0.01 SOL plus 5 USDC

Prepare CLI configs for each persona:

```json owner-config.json lines theme={null}
{
  "cluster": "mainnet-beta",
  "json_rpc_url": "https://mainnet.helius-rpc.com/?api-key=<api-key>",
  "keypair_path": "/path/to/owner-keypair.json",
  "priority_fee": { "micro_lamports": 5000 },
  "jupiter_api_key": "<jupiter-api-key>"
}
```

```json manager-config.json lines theme={null}
{
  "cluster": "mainnet-beta",
  "json_rpc_url": "https://mainnet.helius-rpc.com/?api-key=<api-key>",
  "keypair_path": "/path/to/delegate-keypair.json",
  "priority_fee": { "micro_lamports": 5000 },
  "jupiter_api_key": "<jupiter-api-key>"
}
```

```json user-config.json lines theme={null}
{
  "cluster": "mainnet-beta",
  "json_rpc_url": "https://mainnet.helius-rpc.com/?api-key=<api-key>",
  "keypair_path": "/path/to/user-keypair.json",
  "priority_fee": { "micro_lamports": 5000 },
  "jupiter_api_key": "<jupiter-api-key>"
}
```

For convenience, place all user config files, as well as vault setup `tokenized.json` (see below) in the same directory. All commands, unless specified otherwise, are run from this directory.

### Create a Tokenized Vault

```bash theme={null}
glam-cli -C ./owner-config.json vault create ./tokenized.json
```

* [Transaction](https://solscan.io/tx/47ebP75gwYWNiKgYtjxHC1y2T9SfeAcueh3kDq2sKVD46MFUHi5rS3TFRWCC1rNfmXgr6p245SXD6HTQZAZLGAEC)
* Vault State: [3ciXL6K3kxF754sjqP5acHYHjhZWNK6rj6svjrYouNpY](https://solscan.io/account/3ciXL6K3kxF754sjqP5acHYHjhZWNK6rj6svjrYouNpY)
* Vault PDA: [9hcpVEWDe55hHDHkk4SbN4AVnqqWYXUE7EW3cjai4JAE](https://solscan.io/account/9hcpVEWDe55hHDHkk4SbN4AVnqqWYXUE7EW3cjai4JAE)
* Mint PDA: [J6wov8kN6tw48u57JBKszD4Vn4hmx32bHxHK82ZvrXDe](https://solscan.io/account/J6wov8kN6tw48u57JBKszD4Vn4hmx32bHxHK82ZvrXDe)

Vault setup:

```json tokenized.json expandable lines theme={null}
{
  "state": {
    "accountType": "tokenizedVault"
  },
  "mint": {
    "name": "GLAM Quickstart USDC",
    "symbol": "gqUSD",
    "uri": "",
    "baseAssetMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "maxCap": 1000000000,
    "minSubscription": 1000000,
    "minRedemption": 100000,
    "lockupPeriod": 0,
    "feeStructure": {
      "vault": {
        "subscriptionFeeBps": 0,
        "redemptionFeeBps": 0
      },
      "manager": {
        "subscriptionFeeBps": 0,
        "redemptionFeeBps": 0
      },
      "management": {
        "feeBps": 0
      },
      "performance": {
        "feeBps": 0,
        "hurdleRateBps": 0,
        "hurdleType": "hard"
      }
    },
    "notifyAndSettle": {
      "model": "continuous",
      "permissionlessFulfillment": false,
      "subscribeNoticePeriodType": "hard",
      "subscribeNoticePeriod": 0,
      "subscribeSettlementPeriod": 0,
      "subscribeCancellationWindow": 0,
      "redeemNoticePeriodType": "hard",
      "redeemNoticePeriod": 0,
      "redeemSettlementPeriod": 0,
      "redeemCancellationWindow": 0,
      "timeUnit": "second"
    }
  }
}
```

<Info>
  The vault setup format may change between CLI versions. See the [templates](https://github.com/glamsystems/glam-cli/tree/main/templates) directory for the most up-to-date examples.
</Info>

### Enable Kamino Vaults

Kamino Vaults needs to be enabled before it can be used.

```bash theme={null}
glam-cli -C ./owner-config.json integration enable KaminoVaults
```

* [Transaction](https://solscan.io/tx/2vxwLr96jRd3bHBFRiakTR1GudsRGiDnsFdiz8HmaKHMMaj2gTUT1XGT3wJGuP4vpUJPqcX3XKRMjFB6cgYApkGA)

### Grant Delegate Permissions

<Info>
  Refer to [Integrations](https://docs.glam.systems/v1/platform/integrations) and [Delegated Accounts](https://docs.glam.systems/v1/access-control/delegated-accounts) for more details on protocols and permissions.
</Info>

Vault owner grants the delegate the following permissions:

* `Fulfill` permission from `GlamMint` so it can fulfill user requests.
* `Deposit` and `Withdraw` permissions from `KaminoVaults` so it can deploy GLAM vault assets to Kamino vaults.

```bash theme={null}
glam-cli -C ./owner-config.json delegate grant --protocol GlamMint \
  ndcXmTFuMPkJ5mE4sYNnZdSo99Ajzny88xnrids4QnG Fulfill
```

```bash theme={null}
glam-cli -C ./owner-config.json delegate grant --protocol KaminoVaults \
  ndcXmTFuMPkJ5mE4sYNnZdSo99Ajzny88xnrids4QnG Deposit Withdraw
```

* [Transaction granting Fulfill permission](https://solscan.io/tx/49KGiCUvqAZQEC9mKhGbozgqYRTcL5GgK4qRJY7g9K4JiaFnXrCvcqQEiNWhqeCxgffryznFWJnyVhXoXcjEmyeF)
* [Transaction granting Deposit and Withdraw permissions](https://solscan.io/tx/4wHrovpvFS98EFY7uaLiamosfTifkict23XJHqdZbvUnevaY2CjtKmUf86LDimMJReBZq9QFKSSr63H76a6tyVQQ)

### Subscribe to GLAM Vault

Set the active GLAM vault to user's CLI config:

```bash theme={null}
glam-cli -C ./user-config.json vault set 3ciXL6K3kxF754sjqP5acHYHjhZWNK6rj6svjrYouNpY
```

User subscribes to GLAM vault with 5 USDC:

```bash theme={null}
glam-cli -C ./user-config.json invest subscribe 5
```

* [Transaction](https://solscan.io/tx/5EJje4PQR6P2CaiiZienZ4yLJ7JJ2uBxsqHZRkm8Z9qXX6XR8BK1MoKLSHKuCmVDsEzjsTb1Zcm87n2wgBBPNnk8)

We've configured the vault with 0 fees, so user receives 5 shares (initial share price is 1 USDC).

### Allocate Idle Capital

User deposited 5 USDC has arrived in the GLAM vault, held by vault PDA. Now the delegate can allocate idle capital to a Kamino vault to start generating yield.

Set the active GLAM vault to delegate's CLI config:

```bash theme={null}
glam-cli -C ./delegate-config.json vault set 3ciXL6K3kxF754sjqP5acHYHjhZWNK6rj6svjrYouNpY
```

Display vault token balances:

```bash theme={null}
glam-cli -C ./delegate-config.json vault token-balances
```

Output:

```bash theme={null}
Token        Mint                                          Amount          Value (USD)
SOL          N/A                                           0.000000000     0.000000
USDC         EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v  5               4.999002
```

Deposit to Kamino vault [USDC Prime](https://kamino.com/lend/HDsayqAsDWy3QvANGqh2yNraqcD8Fnjgh73Mhb3WRS5E):

```bash theme={null}
glam-cli -C ./delegate-config.json kamino-vaults \
  deposit HDsayqAsDWy3QvANGqh2yNraqcD8Fnjgh73Mhb3WRS5E 5
```

* [Transaction depositing 5 USDC](https://solscan.io/tx/5B654xatXaTR1TveRqW83AzgfHRHjDVwvo1Lv5sRFYX5tfimn3kKX44maMAwX8udHSGaBFfsRfoLucFQR4AvPG8q)

Withdraw from Kamino vault [USDC Prime](https://kamino.com/lend/HDsayqAsDWy3QvANGqh2yNraqcD8Fnjgh73Mhb3WRS5E):

```bash theme={null}
glam-cli -C ./delegate-config.json kamino-vaults \
  withdraw HDsayqAsDWy3QvANGqh2yNraqcD8Fnjgh73Mhb3WRS5E 3
```

* [Transaction withdrawing from USDC Prime](https://solscan.io/tx/3VyhR9xMAcQHJhzL8XQnLCbE4kxttHeErRTsZELmqSxFvLEL8hvsnH9dufPrYNijFFMMEztfGNnrUGdzuBjc7ydc)

### Redeem GLAM Vault Shares

User holds 5 GLAM vault shares, and redeems 2 shares to get back USDC. Redemption request is queued, and withdrawal amount can be claimed after the request is fulfilled.

```bash theme={null}
glam-cli -C ./user-config.json invest redeem 2
```

* [Transaction](https://solscan.io/tx/KLPSgtwgmXnCYM7VKJe7uF9eHNhQB3jrHvu1bZJ2Mzupx7hoXG5PhaTuY4t7648WHKvbqjKC7vQj7s6tGe3B9yd)

### Fulfill Redemption

The delegate has been granted `Fulfill` permission from `GlamMint`, so it can fulfill user requests.

```bash theme={null}
glam-cli -C ./delegate-config.json manage fulfill
```

* [Transaction](https://solscan.io/tx/HcCvwWKDgzKPQn3igDYZyBMVcJ9rAeLETUgv8gPfH87m2fgm5ZseokhvUUQCPrqs9164eGyBM1QTsEPoiaz9aCv)

### Claim from Redemption

User claims USDC from fulfilled redemption.

```bash theme={null}
glam-cli -C ./user-config.json invest claim-redemption
```

* [Transaction](https://solscan.io/tx/4rSw2WH6o2KWsEyXU4LBc2Wc3YtCRg5bC4B8JxYH5bYdwGsqXyYqjAFgGDda7CpUKzDiVsNw8uHCMxwrASBqDkY)
