Docs/Examples/Yield Harvester

YieldHarvester (Autonomous Yield)

Harvests a vault on schedule without requiring a human trigger — no VRF required.


Overview

YieldHarvester calls harvest() on a mock ERC4626-style vault on a fixed schedule. It demonstrates AutoLoop's value in DeFi yield automation: whoever triggers a harvest first can front-run the yield distribution. A neutral scheduler eliminates that attack surface.

PropertyValue
Base contractAutoLoopCompatible (no VRF)
VRF usageNone
Gas per tick~60k
Sourceautoloop/src/agents/YieldHarvester.sol
Tests17 passing (unit + fuzz)

Why AutoLoop Is Structurally Required

The harvester who triggers gets front-run. In yield protocols, calling harvest() first lets you see the yield amount before it's distributed. A miner or bot watching the mempool can sandwich the transaction. Automated, schedule-based execution via AutoLoop removes the manual trigger and with it the front-running surface.

Mechanics

  • shouldProgressLoop() returns true when block.timestamp - lastHarvest >= harvestInterval and vault.pendingYield() >= minYieldToHarvest
  • progressLoop() calls vault.harvest(), takes a 1% protocol fee from the harvested amount, and records the harvest in totalHarvested / harvestCount
  • Skip logic: if pending yield is below the minimum threshold, the loop is not marked ready — preventing pointless gas-heavy no-op ticks

Revenue Model

  • 1% protocol fee on each harvest
  • AutoLoop gas fee per tick

Deploy

forge create src/agents/YieldHarvester.sol:YieldHarvester \
  --constructor-args 0xVAULT_ADDRESS 3600 0 \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Args: vault, harvestInterval (seconds), minYieldToHarvest (wei, 0 = no minimum).

Dashboard

View YieldHarvester on the AutoLoop Dashboard.