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

# Running Bots & Scripts

> Automate vault operations for optimal performance

Vault operations are operationally manual unless you automate them yourself.

<Warning>
  **You must host your own automation.** Ranger Earn/Ranger does not provide managed bot services. You are responsible for deploying, running, and monitoring your own scripts and bots.
</Warning>

## Why Automation Is Needed

| Task                | Why It Needs Automation                                  |
| ------------------- | -------------------------------------------------------- |
| Rebalancing         | Rates and allocations change over time                   |
| Reward claiming     | Unclaimed rewards leave value idle                       |
| Reward swapping     | Claimed rewards often need conversion back to base asset |
| Position monitoring | Strategy-specific health can degrade without alerts      |
| Fee harvesting      | Accumulated fees should be collected periodically        |

## Script Repositories

| Repository                                                                                            | Use Case                                                   |
| ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [ranger-finance/lend-scripts](https://github.com/voltrxyz/lend-scripts)                               | Lending strategy init (Project0, Save)                     |
| [ranger-finance/kamino-scripts](https://github.com/voltrxyz/kamino-scripts)                           | Kamino strategy init, rewards claiming                     |
| [ranger-finance/drift-scripts](https://github.com/voltrxyz/drift-scripts)                             | Drift vaults/lend/perps strategy init, position management |
| [ranger-finance/spot-scripts](https://github.com/voltrxyz/spot-scripts)                               | Jupiter Swap/Lend strategy init                            |
| [ranger-finance/client-raydium-clmm-scripts](https://github.com/voltrxyz/client-raydium-clmm-scripts) | Raydium CLMM strategy init                                 |
| [ranger-finance/trustful-scripts](https://github.com/voltrxyz/trustful-scripts)                       | Trustful adaptor strategy init                             |
| [ranger-finance/rebalance-bot-template](https://github.com/voltrxyz/rebalance-bot-template)           | Production-ready rebalance bot (equal-weight allocation)   |

## Rebalance Bot Template

The [rebalance-bot-template](https://github.com/voltrxyz/rebalance-bot-template) is a production-ready bot that handles the core automation tasks listed above. It distributes funds equally across lending strategies on a fixed schedule and includes:

* **Rebalance loop** — equal-weight allocation across all strategies, triggered on interval and on new deposits
* **Refresh loop** — keeps on-chain receipt values up to date
* **Harvest fee loop** — collects protocol/admin/manager fees
* **Claim reward loops** — claims Kamino farm rewards and swaps them back via Jupiter

Supports Drift, Jupiter Lend, Kamino Market, and Kamino Vault strategies out of the box.

```bash theme={null}
git clone https://github.com/voltrxyz/rebalance-bot-template.git
cd rebalance-bot-template
pnpm install
cp .env.example .env   # fill in your vault addresses and keypair
pnpm run build && pnpm start
```

See the [repository README](https://github.com/voltrxyz/rebalance-bot-template#readme) for full configuration options and Replit deployment instructions.

## Basic Script Shape

```typescript theme={null}
import { createKeyPairSignerFromBytes, createSolanaRpc } from "@solana/kit";
import {
  fetchVault,
  getPositionAndTotalValuesForVault,
} from "@voltr/vault-sdk";

async function main() {
  const rpc = createSolanaRpc(process.env.RPC_URL!);
  const managerSigner = await createKeyPairSignerFromBytes(
    Uint8Array.from(JSON.parse(process.env.MANAGER_KEY!))
  );

  const vaultAccount = await fetchVault(rpc, vaultAddress);
  const positions = await getPositionAndTotalValuesForVault(rpc, vaultAddress);

  // 1. Read idle and deployed balances
  // 2. Pull strategy-side data
  // 3. Decide on reallocations
  // 4. Build strategy deposit/withdraw instructions

  console.log(vaultAccount.data.asset.totalValue, positions.strategies.length);
}

main().catch(console.error);
```

## Operational Requirements

* keep manager and admin wallets funded with SOL
* add retries and alerting
* respect RPC limits
* make scripts idempotent where possible
* keep signing keys isolated from application code
