What This Template Does
This template automates DeFi vault harvesting โ a specialized version of the keeper pattern for vault-specific operations like yield harvesting and compounding.
The workflow:
- Cron trigger fires every 5 minutes (configurable)
- Reads vault state:
shouldHarvest(),pendingYield(),totalHarvested(),harvestCount() - If profitable (time elapsed AND yield > threshold): Sends a signed report to trigger harvest on-chain
- If not profitable: Logs and skips โ no wasted gas on unprofitable harvests
- On-chain: Harvests pending yield, resets state, and emits an event
This pattern is compatible with vault protocols like Beefy, Yearn, and Alchemix.
Key Technologies:
- CRE (Chainlink Runtime Environment) โ Orchestrates periodic workflows with DON consensus
- Profitability checking โ Time + yield threshold validation off-chain
- Yield tracking โ Harvest counter and history
How It Works
Getting Started
1 Install dependencies
cd my-workflow && bun install && cd .. && cd contracts && bun install && cd ..
2 Run tests
cd my-workflow && bun test
3 Simulate the workflow
Dry run:
cre workflow simulate my-workflow --target staging-settings
With broadcast (writes on-chain):
cre workflow simulate my-workflow --target staging-settings --broadcast
4 Deploy your own contract
Deploy VaultHarvester with constructor arguments: forwarder address, harvest interval in seconds, and minimum yield threshold in wei:
forge create src/VaultHarvester.sol:VaultHarvester \
--broadcast --private-key <KEY> --rpc-url <RPC> \
--constructor-args 0x15fc6ae953e024d975e77382eeec56a9101f9f88 300 1000000000000000000
Simulate yield accrual for testing:
cast send <YOUR_CONTRACT> "accrueYield(uint256)" 2000000000000000000
Then update contractAddress in my-workflow/config.staging.json.
Customization
- Change schedule โ Edit
scheduleinconfig.staging.json(cron syntax) - Change profitability check โ Modify
shouldHarvest()in the contract - Change harvest logic โ Update
_processReport()for your vault's harvest + compound strategy
For full details, see the TypeScript README on GitHub.
CREATED BY CHAINLINK LABS