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.INVEST_LOOPSends permissionless invest instructions that move capital toward the weights already on chain. It never changes weights.Any wallet with SOLALLOCATION_REBALANCE_LOOPRuns danger checks, then writes new weights from the strategy for each vault that is due, then invests.Allocation AdminDANGER_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.
How the Invest Loop Works
How the Invest Loop Works
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.How Rebalancing Works
How Rebalancing Works
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.How Failures and Retries Work
How Failures and Retries Work
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.FIXED_WEIGHTSWeights are shares: 1 and 3 mean 25% and 75%. The list must name every healthy reserve.EQUALGives every reserve the same weight.MAX_YIELDApplies the optimum at once.MAX_YIELD_DRIPPINGCloses 20% of the gap per due rebalance by default. Set with drippingRatePercent.MAX_YIELD_WITH_FIXED_RESERVESKeeps a minimum combined share in a named set of reserves.MAX_YIELD_STABLENarrows the spread between reserve yields.UNCHANGEDKeeps 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.
How Strategies Set Weights
How Strategies Set Weights
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.How Drift Works
How Drift Works
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’sriskAppetiteMode. 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.
PARANOID0.5SENSIBLEDefault0.3YOLO0.1maxVaultDominanceBpsWhen 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 noneMARKET_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.
Danger Checks
Danger Checks
Check Thresholds
Check Thresholds
Stale Price Scores
Stale Price Scores
How Exits Run
How Exits Run
How Prices and Collateral Are Checked
How Prices and Collateral Are Checked
What Happens When Data Fails
What Happens When Data Fails
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.INVESTOR_SECRET_PATHSends permissionless invest instructions.YesALLOCATION_ADMIN_SECRET_PATHUpdates weights and caps of reserves already in the vault.YesRestarts and Outages
The safety file atDANGER_BLACKLIST_PATH keeps the bot’s long-lived state across restarts. Everything else lives in memory.
Safety State
Safety State
How the Safety File Works
How the Safety File Works
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.
Install and Build
Clone the repository, install its dependencies, and build its three packages.Create the Profile
Create.env.mainnet-beta in the repository root. This profile runs only the allocation loop, in dry-run mode.investing-bot folder.Required Settings
Required Settings
RPC and Transaction Settings
RPC and Transaction Settings
Invest Loop Settings
Invest Loop Settings
Allocation and Danger Settings
Allocation and Danger Settings
Other Settings
Other Settings
How Profiles and Paths Work
How Profiles and Paths Work
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.Write the Allocation Config
Assign a strategy to each vault. Each entry inallocationsConfig 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.Allocation Config Fields
Allocation Config Fields
How the Config Is Validated
How the Config Is Validated
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.Run a Dry Run
Start the allocation loop without sending transactions. The logs show the vault set, strategy, excluded reserves, and target weights.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.SetALLOCATION_DRY_RUN=false in the profile and start the bot in production mode.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.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.Commands
Commands
How Recovery Works
How Recovery Works
--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.How Health Checks Work
How Health Checks Work
/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.