Skip to main content
The Vault Bot is an open source service that automates vault operations. It invests idle capital, rebalances allocations using a chosen strategy, and attempts to exit reserves that show signs of risk. Risk checks and rebalances run on a schedule, so the vault responds without manual updates. The bot signs as the vault’s Allocation Admin.

How the Bot Works

The bot runs two loops with separate switches. Danger detection runs only in the allocation loop, so the invest loop alone never exits a risky reserve.
LoopWhat it doesSigner
Invest loopINVEST_LOOPSends permissionless invest instructions that move capital toward the weights already on chain. It never changes weights.Any wallet with SOL
Allocation loopALLOCATION_REBALANCE_LOOPRuns danger checks, then writes new weights from the strategy for each vault that is due, then invests.Allocation Admin
The allocation loop works in rounds, called passes. Each pass starts with danger checks, and passes run at most DANGER_PASS_INTERVAL_SECONDS apart, 300 by default, so risk is checked about every five minutes. Each vault still rebalances on its own rebalanceFrequencySeconds, 3,600 by default.
Every strategy except UNCHANGED overwrites weights the curator sets by hand on the vault’s next rebalance. To control weights directly, set them with FIXED_WEIGHTS in the allocation config and restart the allocation loop, or switch the vault to UNCHANGED. The allocation loop reads its config only at startup.
The invest loop builds its vault list from INVEST_VAULTS, the vaults owned by INVEST_OWNERS, and, with INVEST_UI_VAULTS on, the vaults listed in the Kamino app. If the app’s list fails to load, it invests only the configured vaults for that pass. With INVEST_UI_VAULTS off and the other two empty, it invests every vault on chain. With INVEST_UI_VAULTS on, an empty app list and no other vaults set skips the pass instead. An address that holds no vault is skipped and logged.The loop skips any vault with an exit in progress or a blacklisted reserve, and sends no deposits to reserves the allocation loop has blocked, though withdrawals still go through. After the allocation worker restarts, it keeps the last blocked list until the next successful pass. A vault is invested only when the amount to move, the larger of its deposits and its withdrawals, is more than MIN_INVEST_TOKENS whole tokens, and both the bot’s delay (MIN_SECONDS_SINCE_LAST_INVEST) and the program’s own delay have passed.Before investing, the loop creates missing token accounts and keeps small token balances in the invest signer to cover rounding, buying them through KSwap or by wrapping SOL within both slippage limits. If the program rejects an invest for one reserve, the loop skips that reserve for the vault for RESERVE_INVEST_COOLDOWN_MS while the others continue. More than one invest process can run, but all of them must use the same safety file and the same ALLOCATION_CONFIG_PATH. The invest loop rereads that config before each normal invest.
Between passes, the allocation loop sleeps for the shortest of DANGER_PASS_INTERVAL_SECONDS, any vault’s rebalanceFrequencySeconds, and the next scheduled data refresh. The time a pass takes adds to the gap.For a vault that is due, the strategy computes target weights and the bot writes every change in one transaction. After it confirms, the bot waits five seconds, reloads the vault, and invests. It invests after every due rebalance, even when the weights did not change, and a failed update means no invest for that vault.The bot checks that the Allocation Admin wallet holds a small amount of each vault’s token, because that wallet pays the rounding on the invests and emergency withdrawals it sends. Without it, those transactions fail and the bot logs an error. Blacklisted reserves get zero weight. Reserves blocked from new funds keep their weight but receive no deposits, and the bot can lower their cap to enforce that. It never changes cToken caps.
A failed rebalance is retried after one pass interval, then after twice as long for each failure in a row, up to the vault’s rebalance frequency. A vault that fails to load is skipped for that pass. If no vault loads, the pass counts as failed and retries after 10 seconds. An empty allocationsConfig leaves the loop idle with a warning.If a vault’s weight changes do not fit in one Solana transaction, the bot sends none, skips that vault’s invest, and logs whether a vault lookup table would make them fit.The bot combines each vault’s on-chain lookup table with Kamino’s managed tables from https://api.kamino.finance/luts/managed. If the managed tables fail to load, it uses the on-chain table alone. If the on-chain table fails to load, that vault’s operation fails. After a failed send, the bot drops any table that is being deactivated and refreshes the managed list, but does not resend the transaction. A send with an unknown outcome may need a manual check.

Strategies

A strategy computes target weights for every vault in an allocation config entry. The bot only updates reserves the vault already holds. The Vault Admin adds every reserve a strategy can use before the bot runs.
GoalStrategyNote
A set splitFIXED_WEIGHTSWeights are shares: 1 and 3 mean 25% and 75%. The list must name every healthy reserve.
An even splitEQUALGives every reserve the same weight.
Highest APYMAX_YIELDApplies the optimum at once.
Highest APY, moved graduallyMAX_YIELD_DRIPPINGCloses 20% of the gap per due rebalance by default. Set with drippingRatePercent.
Highest APY with a floorMAX_YIELD_WITH_FIXED_RESERVESKeeps a minimum combined share in a named set of reserves.
Even yieldsMAX_YIELD_STABLENarrows the spread between reserve yields.
Danger exits onlyUNCHANGEDKeeps current weights and reports APY.
driftRatePercent moves other strategies part of the way toward their target on each due rebalance. Setting driftRatePercent on a MAX_YIELD_DRIPPING vault fails config loading. A RANDOM strategy also exists for testing only.
EQUAL, FIXED_WEIGHTS, and RANDOM scale their targets to the vault’s current weight total, keep the vault’s unallocated share, and leave blocked reserves’ weights alone. With no unallocated share, the bot can multiply a small weight total by a whole number to reduce rounding. These three do not check how much each reserve can take or return, so on-chain caps can make a later invest fall short or fail.The max-yield strategies check each reserve’s room for deposits and withdrawals. If no allocation fits, the vault keeps its current allocation, and normal investing can be blocked when the current target is unsafe. They search a coarse grid, then refine the best areas, and may use a coarser step than GRID_SEARCH_RESOLUTION for vaults with many reserves. A search that reaches GRID_SEARCH_MAX_CANDIDATES or GRID_SEARCH_MAX_MS keeps the current allocation for that pass. Raising GRID_SEARCH_RESOLUTION is the first thing to try before raising those limits.Farm rewards count toward yield when includeReservesSupplyFarmRewardsApy is on, and a vault whose farm data fails to load skips its rebalance for that pass. MAX_YIELD_WITH_FIXED_RESERVES and MAX_YIELD_STABLE treat reservesAllocationPercentageBPS as a minimum for the search, not a guarantee, because capacity limits can still change the result. MAX_YIELD_STABLE reports APY but does not use it to break ties.
With driftRatePercent set, a strategy moves that share of the gap per due rebalance instead of jumping to the target. UNCHANGED does not drift.MAX_YIELD_DRIPPING uses drippingRatePercent instead and ignores minimum allocations. With enforceUtilizationCap on, it moves from actual token holdings and limits each reserve’s utilization change to maxUtilizationChangeBps. Otherwise it moves from configured weights.Drift does not start a vault whose healthy weight total is zero, and very small gaps send no update. Exits for danger always happen at once, without drift.

Danger Detection

Each check returns a safety score between zero and one, and the scores multiply. A reserve is exited when its combined score falls strictly below the threshold for the vault’s riskAppetiteMode. The bot does not check DEX liquidity, full deposit caps, sudden borrowing spikes, or governance changes. The danger catalog is the source for the thresholds below.
Risk appetite: exits when the combined score is below
PARANOID0.5
SENSIBLEDefault0.3
YOLO0.1
SignalWhat the bot doesLasts
Catastrophice.g. unexpected mintingSets the reserve’s weight to zero, attempts withdrawals, and blacklists the reserve.Until cleared
TemporarySets the reserve’s weight to zero and attempts withdrawals. From that moment, no vault sends the reserve new funds for 2,700 s.Until the vault holds none
DominancemaxVaultDominanceBpsWhen set, exits at any risk appetite once the vault’s share of the reserve reaches the limit. Handled like a temporary signal.Until the vault holds none
An exit keeps retrying on every pass until the vault holds no weight and no tokens in the reserve. If a market price the checks need is older than MARKET_PRICE_MAX_AGE_SECONDS, 300 by default, the bot skips normal rebalancing for that pass rather than act on stale data. Exits already in progress still retry.
To exit, the bot blacklists catastrophic reserves, starts the 2,700 second no-new-funds period for temporary ones, and records the exit in the safety file. It then sets the reserves’ weights to zero two at a time, waits five seconds, reloads the vault, and withdraws from each reserve whose weight is now zero. If a batch fails, it retries one reserve at a time.Exit transactions are sent even if a test run of the transaction fails, so the bot does not wait while capital is at risk. After three failed exits for the same reserve in a vault, it only sends exits that pass the test run first. A successful exit or a restart resets this. Failures explained by an earlier skipped withdrawal, or caused by an instruction the bot adds such as a Jito tip, do not count toward the three.A temporary signal on a reserve the vault does not hold still starts the no-new-funds period. The two checks that look at the vault’s own position, exit liquidity and dominant depositor, are skipped when the reserve already scores 0.
When a reserve’s oracle price is stale, reads zero, or falls below one millionth of the KSwap market price, the bot first stops sending new deposits to the reserve. If the problem continues and the score falls below the vault’s threshold, the bot moves the vault’s capital out. A price that reaches the reserve’s own oracle age limit also blocks new funds at once, separately from the bot’s stale timer. A zero price that keeps refreshing blocks deposits but does not cause an exit just by lasting. A reserve without a valid oracle price setup gets no age check.Stablecoins are compared to 1 USD, except a fixed list of non-USD and yield-bearing stablecoins such as EURC, VGBP, vCHF, PRIME, and USD+, which still get the oracle divergence check. Liquid staking tokens are compared to SOL at one to one, not the stake pool’s higher redemption rate. Both use Kamino’s token flags feed. If that feed is down, the bot uses its last copy. With no copy, the pass fails.The bot also checks the collateral in each lending market the vault lends into: every reserve in that market with a positive loan-to-value or an elevation group, hidden ones included. An unexpected mint of a collateral token blacklists every reserve the vault holds in that market. A collateral price that stops updating or reads zero blocks new funds to those reserves, and the vault exits them once the price is old enough to cross the risk threshold. Each market is checked separately, even when a token appears in more than one.
The bot needs a fresh KSwap price for every token it checks, and asks again after one and two seconds. If a price is still missing or too old, or a required read fails, the bot makes no new decisions that pass but keeps working on exits already in progress.If only a market’s reserve list or a collateral check cannot be read, the affected reserves get no new funds for that pass, with no exit. If the chain time cannot be read, or the pass runs past its time limit of the number of vaults × RPC_REQUEST_TIMEOUT_MS × 4, the pass stops.After three failed passes in a row, /ready reports the bot as not ready. A single vault that goes unchecked three passes in a row is logged on every pass but does not affect /ready.

Keys and Permissions

The bot holds up to two keys. The Vault Admin can also sign allocation updates, but it carries authority the bot does not need, so it stays with the curator.
SignerWhat it can doHeld by the bot
Invest signerINVESTOR_SECRET_PATHSends permissionless invest instructions.Yes
Allocation AdminALLOCATION_ADMIN_SECRET_PATHUpdates weights and caps of reserves already in the vault.Yes
Vault AdminAdds reserves and holds broader authority over the vault.No
If the bot’s key is neither a vault’s Allocation Admin nor its Vault Admin, the bot skips that vault’s rebalance and logs it, and emergency exits for that vault fail. Dry run does not check the key, so confirm it before going live.

Restarts and Outages

The safety file at DANGER_BLACKLIST_PATH keeps the bot’s long-lived state across restarts. Everything else lives in memory.
StateWhere it livesAfter a restart
Blacklists, pending exits, original capsSafety file on diskKept
Cooldowns, failure counters, rebalance scheduleMemoryReset
A restart rebalances every configured vault on its first pass, and resets the baselines the bot uses to detect unexpected minting. If the bot stops, Kamino’s sync crank keeps investing vaults toward their current weights. The weights stay frozen and no danger exits happen until the bot is running again.
The safety file holds three lists: blacklistedReserves, pendingEvacuations, and depositFreezes. The repository’s danger_blacklist_example.json shows the blacklist format, and the other two lists appear once the bot writes them. The bot writes the file under a lock file next to it and replaces it in one step, so a crash never leaves it half written. A missing or blank file counts as empty if its folder exists. An unreadable or invalid file stops the danger checks and the invest loop until it is fixed.A pending exit is retried on every pass, even after the signal recovers, and blocks the vault’s strategy and the invest loop until the vault holds nothing in the reserve.When the bot lowers a cap to block deposits, it records the original cap before sending the change. Once the reserve recovers, it restores that cap, but only if the cap is still the one the bot set. If someone else changed the cap, the bot leaves it and drops the record. While a cap change the bot sent can still land, it keeps the freeze in place. Records also clear when a reserve leaves the vault, and failed cap updates retry on the next pass.

Set Up the Bot

The steps below install the bot, test it with a dry run, and take it live. Settings and defaults on this page are for kvault-bot v2.0.1. Newer releases are documented in the README. Before starting, the bot requires:
  • Node.js, which Kamino runs on 26.12.1.
  • Yarn Classic 1.22.22.
  • A Solana RPC endpoint.
  • Solana keypair files in JSON format, as created by solana-keygen, for the Allocation Admin and, if the invest loop runs, the invest signer.
  • SOL in each signer wallet for fees, plus a little extra in the invest signer.
  • A small amount of each vault’s token in the Allocation Admin wallet, such as 0.01 USDC for a USDC vault.
  • A server with persistent storage for the safety file.
1

Install and Build

Clone the repository, install its dependencies, and build its three packages.
View Code
2

Create the Profile

Create .env.mainnet-beta in the repository root. This profile runs only the allocation loop, in dry-run mode.
Use absolute paths. Relative paths resolve from the investing-bot folder.
The repository’s .env.example turns on the invest loop and INVEST_UI_VAULTS. The invest loop has no dry run, so a copy left unchanged invests every vault listed in the Kamino app as soon as it starts. It also sets a 10-second invest interval, a 100-token minimum, and relative paths. Start from the profile above instead.
PROFILE in the shell selects .env.PROFILE in the repository root. Without PROFILE, CLUSTER selects it, and the default is mainnet-beta. Settings already set in the shell override the profile. The profile can reference other environment variables, and the bot expands them on load. Without a profile file, the bot uses the shell environment alone. NODE_OPTIONS must be set in the shell, because Node reads it before the profile loads.yarn start and yarn cli run from the investing-bot folder, so relative paths, including --path, resolve from there. If a keypair file is not found, the bot also looks in the parent folder.A blank value for a number setting is rejected at startup. The bot sets its own time zone to UTC, so all log timestamps are in UTC.
3

Write the Allocation Config

Assign a strategy to each vault. Each entry in allocationsConfig gives one strategy to a list of vaults, written as plain addresses or as objects with their own settings. This config splits one vault 25/75 between two reserves.
The bot checks the file at startup and rejects invalid strategies, addresses, duplicates, frequencies, flags, rates, and basis point ranges. It does not check that an address belongs to a real vault.Before each rebalance, the bot checks that every reserve in fixedReserves is already in the vault’s allocation list. A vault given as a plain address has no fixedReserves.A driftRatePercent set on an entry also fails loading when one of its vault objects switches to MAX_YIELD_DRIPPING. In that case, set the rate on the other vault objects instead.
4

Create the Safety File

Create the folder on persistent storage, then initialize the file.
The CLI does not load the profile. Pass --path with every danger command.
5

Run a Dry Run

Start the allocation loop without sending transactions. The logs show the vault set, strategy, excluded reserves, and target weights.
Dry run covers only the allocation loop and writes nothing to the safety file. It does not check that the key is each vault’s Allocation Admin. The invest loop sends transactions whenever it is on.
6

Go Live

Before going live, check each vault’s reserve whitelist, caps, minimum amounts, and invest delays. The program can reject a transaction even when the bot’s own checks pass.Set ALLOCATION_DRY_RUN=false in the profile and start the bot in production mode.
To run the invest loop too, set INVEST_LOOP=true and INVESTOR_SECRET_PATH, and list the vaults with INVEST_VAULTS, INVEST_OWNERS, or INVEST_UI_VAULTS. With all three empty, the invest loop invests every vault on chain.
7

Monitor and Recover

The health server on port 8080 exposes /health, /live, and /ready. /ready fails when a loop stops sending heartbeats or danger passes keep failing.A blacklisted reserve stays blacklisted until it is cleared manually. Inspect the safety file, fix the cause, then clear the reserve.
Never replace a live safety file with an empty one or delete its deposit freeze records. They hold the original caps the bot restores.
The CLI does not load the profile. Without --path, it uses an exported DANGER_BLACKLIST_PATH, then ./danger_blacklist.json in the investing-bot folder. Run commands from the repository root.Clear commands send no transactions. They keep pending exits, deposit freeze records, and no-new-funds periods, and the running bot picks up cleared entries on its next pass without a restart.Clear a reserve only after its cause is fixed, because an active catastrophic signal blacklists it again. After clearing, keep the allocation loop running with dry run off for the affected vaults, and check after a successful pass that exits have finished and caps are where they should be.
Use /ready as the deployment readiness probe. It requires a heartbeat from every enabled loop and successful danger passes, and the bot rechecks it every 15 seconds. With no loop turned on, the process runs only the health server. Settings for the enabled loops are checked at startup, before any loop starts.The allocation loop runs in a separate worker with a 4 GB limit on its long-lived memory and 2 GB for short-lived memory. If the worker crashes, the bot restarts it up to three times, five seconds apart, and a completed pass resets that count. A worker that stays unhealthy needs a full process restart.SIGINT and SIGTERM stop the worker, then the health server. The process exits after 20 seconds if shutdown has not finished. Production logs are JSON. LOG_LEVEL sets the level, and VERBOSE=true adds allocation detail.

Allocations

Weight, cap, type, and priority mechanics.

Roles & ownership

Vault Admin, Allocation Admin, and Farm Authority.