Appearance
Keeper Bot
The keeper bot is an off-chain TypeScript service that automates vault operations.
Responsibilities
| Task | Frequency | Description |
|---|---|---|
| Harvest | Periodic | Claim rewards, compound yield |
| Rebalance | On threshold | Shift allocations to higher-yield protocols |
| Monitor | Continuous | Track APYs, balances, health |
| Alert | On events | Telegram notifications for significant events |
Harvest Flow
The keeper uses the enhanced harvestWithSlippage() function for MEV protection:
- Query accrued rewards from each protocol
- Fetch Morpho rewards from Merkl API (
https://api.merkl.xyz/v4/claim?user={strategyAddress}&chainId=1329) - Calculate fair prices for reward token → USDC swaps using DEX quotes
- Apply slippage tolerance (typically 1%) to determine
minAmountOutfor each swap:minAmountOut = dexQuote * 0.99 // 1% slippage tolerance - Call harvest functions:
strategy.harvestWithSlippage(takaraMinOut, morphoMinOut)for main harveststrategy.claimMorphoRewards(tokens, amounts, proofs, minAmountsOut)for Merkl rewards
- Strategy executes:
- Claims all rewards
- Swaps to USDC with slippage protection (reverts if price is manipulated)
- Redeposits compounded USDC
- Log yield amount and send Telegram summary
Slippage Calculation
The keeper calculates minimum output amounts off-chain to protect against MEV:
typescript
// Get fair price from Sailor DEX
const quote = await sailorDex.getQuote(rewardToken, usdc, rewardAmount);
// Apply 1% slippage tolerance
const minAmountOut = quote.outputAmount * 0.99;
// If actual output < minAmountOut, transaction reverts
await strategy.harvestWithSlippage(takaraMinOut, morphoMinOut);This ensures that if a sandwich bot or price manipulator tries to extract value, the transaction fails instead of completing at a bad price.
Rebalance Logic
current_apys = [yei_apy, takara_apy, morpho_apy]
optimal_allocation = calculate_optimal(current_apys)
current_allocation = strategy.getAllocations()
if deviation(optimal, current) > threshold:
strategy.setAllocations(optimal_allocation)
strategy.rebalance()
send_telegram_alert(old, new, reason)The keeper compares current allocations against optimal allocations based on live APY data. If the deviation exceeds a configurable threshold, it triggers a rebalance.
MEV Protection
The keeper includes comprehensive MEV protection measures:
- Slippage limits — all swaps require
minAmountOutcalculated off-chain from fair DEX quotes - Price validation — keeper fetches current prices before every harvest
- Transaction reversion — if actual swap output < expected, transaction reverts (funds safe)
- Private transactions — submits through private mempools when available
- Timing randomization — avoids predictable harvest patterns
- Gas optimization — batches operations when possible
How slippage protection works:
- Keeper queries Sailor DEX for current reward token → USDC prices
- Applies 1% slippage tolerance:
minOut = quoteAmount * 0.99 - Passes
minAmountOutto harvest function - If sandwich bot manipulates price, actual output will be < minOut
- Transaction reverts, sandwich bot pays gas but gets nothing
This makes attacking Kana harvests unprofitable for MEV bots.
Telegram Alerts
The bot sends alerts for:
- ✅ Successful harvests (with yield amount)
- 🔄 Rebalance events (old → new allocations)
- ⚠️ Errors or failed transactions
- 📊 Daily summary reports
- 🚨 Emergency events (large withdrawals, unusual APY changes)
Configuration
typescript
{
harvestInterval: '4h', // Harvest every 4 hours
rebalanceThreshold: 100, // 1% deviation triggers rebalance
minHarvestAmount: '10', // Min $10 yield to harvest (gas efficiency)
telegramChatId: '...',
rpcUrl: 'https://evm-rpc.sei-apis.com',
}Tech Stack
- Runtime: Node.js / TypeScript
- Web3: ethers.js / viem
- Scheduling: Node cron or setInterval
- Alerts: Telegram Bot API
- Monitoring: Structured logging