# Grant Application: Shepherd - Programmable Blockchain Automation Infrastructure

- Space: [CoW DAO Grants](https://snapshot.box/s:cowgrants.eth.md)
- Author: 0xE618050F1adb1F6bb7d03A3484346AC42F3E71EE
- State: Passed
- Voting type: Basic
- Start: 2025-12-15 12:32 UTC
- End: 2025-12-18 12:32 UTC
- Votes: 4
- Quorum: 3 voting power
- Discussion: https://forum.cow.fi/t/grant-application-shepherd-programmable-blockchain-automation-infrastructure/3288
- Open in Snapshot: https://snapshot.box/#/s:cowgrants.eth/proposal/0xf7de627f8e04c92a63dcc3f6a08d1819220d4ad55fd511704c246150c8345b39

## Results

- For: 4 voting power, 100.0%
- Against: 0 voting power, 0.0%
- Abstain: 0 voting power, 0.0%

## Proposal

## Author(s)

**mfw78.eth**

- GitHub: https://github.com/mfw78 and https://github.com/nxm-rs
- Gitcoin: https://gitcoin.co/mfw78

## Experiences and Qualifications

**Relevant Experience:**
- Former CoW Protocol Core Contributor (Aug 2023 - Oct 2024)
- Author: ComposableCoW conditional order framework
- Author: TWAP orders implementation
- Author: ComposableCoW SDK
- Author: Fee Automation architecture (multi-chain bridging, automation)

**Technical Background:**
- Deep knowledge of CoW Protocol architecture and conditional orders
- Experience building watch-tower infrastructure for TWAP monitoring
- Smart contract development (Solidity, Foundry)
- Backend development (TypeScript, Rust)

**Why I'm Uniquely Qualified:**
This grant is the natural progression: From building conditional orders (ComposableCoW) → specific order types (TWAP) → now building programmable infrastructure to execute and monitor them flexibly.

## Type of Grant

This is a **milestone-based grant** with 5 distinct milestones, each with clearly defined deliverables and success criteria.

## Grant Description

### Overview

Shepherd is foundational programmable automation infrastructure for CoW Protocol that replaces the current hardcoded watch-tower with a flexible WASM runtime. It serves as the base layer for all future automation needs—from simple TWAP monitoring to complex multi-chain operations, fee automation, and gas abstraction services.

**The Evolution:**
1. ComposableCoW (2023): Built the conditional order framework
2. TWAP Orders: Implemented specific order types
3. Watch-Tower: Created hardcoded monitoring infrastructure (inflexible)
4. **Shepherd**: Provides programmable foundation for ALL automation needs

Instead of rebuilding infrastructure for each new automation pattern, Shepherd provides a secure sandbox where developers deploy WASM modules with well-defined APIs for blockchain interaction, CoW Protocol order submission, and state management.

### Problem Statement

**Current Watch-Tower Limitations:**
- Hardcoded logic: Cannot easily adapt for new order types
- Not extensible: Community cannot build custom automation
- Difficult to iterate: Infrastructure changes required for improvements
- Single use case: Only TWAP monitoring, not reusable

**The Missing Piece:**
We have on-chain conditional orders (ComposableCoW) and fixed-case off-chain execution (watch-tower/EthFlow), but we're missing a programmable off-chain execution layer. Shepherd fills this gap.

### Solution: Shepherd Architecture

**WASM-Based Runtime:**
- Load and execute WebAssembly modules ("shepherds")
- Sandboxed execution (CPU/memory/storage limits)
- Automatic restart and error handling
- Flexible deployment across chains

### Use Cases

**Core Protocol Use Cases:**
1. **TWAP Order Monitoring** - Replace current watch-tower with WASM module
2. **Ethflow Order Monitoring** - Replace existing monitoring, reduce backend complexity
3. **Methane Gas Abstraction** (Future) - Monitor gas prices, trigger paymasters
4. **Fee Automation System** (Future) - Monitor balances, trigger bridges, initiate TWAP buybacks

**Community Use Cases:**
- Stop-loss/take-profit orders
- Automated portfolio rebalancing
- Yield farming automation
- DAO governance automation

### Technology Stack

**Runtime:** Rust, wasmtime (WASM runtime), Tokio (async), alloy (RPC), redb (embedded key-value store)

**SDK:** Rust SDK with types, traits, macros, testing utilities

**Deployment:** Docker container, CLI, TOML configuration

### Security Model

- **WASM Sandboxing:** No file system access, no network access, enforced resource limits
- **Order Submission:** Permissionless API (no authentication required)
- **Audit Trail:** All events, state changes, and submissions logged

## Milestones

| Milestone | Title | Duration | Effort | Funding (€100/hr) |
|-----------|-------|----------|--------|-------------------|
| 1 | Core Runtime & Event System | 3 weeks | 120 hours | €12,000 |
| 2 | TWAP & Ethflow Module Implementation | 2.5 weeks | 100 hours | €10,000 |
| 3 | SDK & Developer Experience | 1.5 weeks | 60 hours | €6,000 |
| 4 | Production Hardening | 1.5 weeks | 60 hours | €6,000 |
| 5 | Multi-Chain & Final Testing | 1 week | 40 hours | €4,000 |
| **Total** | | **9.5 weeks** | **380 hours** | **€38,000** |

---

### Milestone 1: Core Runtime & Event System

**Duration:** 3 weeks | **Effort:** 120 hours

**Deliverables:**
- WASM runtime with lifecycle management (load, execute, restart)
- Event monitor supporting `eth_subscribe` (new blocks and logs)
- Basic blockchain interface (`eth_call`, `eth_getTransactionReceipt`)
- redb-backed state store with per-module isolation
- CLI for testing WASM modules locally
- Example "hello world" module

**Success Criteria:**
- Can load WASM module and receive new block events
- Module can read blockchain state via `eth_call`
- Module can persist data in state store
- No memory leaks or crashes over 24-hour test run

---

### Milestone 2: TWAP & Ethflow Module Implementation

**Duration:** 2.5 weeks | **Effort:** 100 hours

**Deliverables:**
- Complete TWAP monitoring module (Rust → WASM)
- Complete Ethflow monitoring module (Rust → WASM)
- Smart contract modifications to ComposableCoW/TWAP handler for efficient polling
- Integration with modified ComposableCoW to query active orders
- Order submission to CoW Protocol API
- State tracking to avoid duplicate posts

**Success Criteria:**
- Modified ComposableCoW contracts deployed and tested
- TWAP module successfully monitors and posts orders on Arbitrum testnet
- Ethflow module successfully monitors and posts orders on testnet
- No duplicate order posts
- Handles edge cases (reorgs, failed submissions)
- 100% uptime over 48-hour test period

---

### Milestone 3: SDK & Developer Experience

**Duration:** 1.5 weeks | **Effort:** 60 hours

**Deliverables:**
- Rust SDK crate (`shepherd-sdk`) with types and utilities
- Macros for common patterns
- Testing framework for WASM modules
- Example modules (TWAP monitor, price alert, balance tracker)
- Documentation: API reference, tutorial, deployment guide

**Success Criteria:**
- External developer can build simple module in <4 hours using docs
- SDK has clear error messages
- All examples compile and run

---

### Milestone 4: Production Hardening

**Duration:** 1.5 weeks | **Effort:** 60 hours

**Deliverables:**
- Resource limits with enforcement
- Automatic restart with exponential backoff
- Poison pill detection
- Comprehensive logging
- Prometheus metrics export
- Production deployment guide

**Success Criteria:**
- System runs for 7 days on testnet without manual intervention
- Handles RPC failures gracefully
- Module crashes don't affect runtime stability
- All operations logged and observable

---

### Milestone 5: Multi-Chain Considerations & Final Testing

**Duration:** 1 week | **Effort:** 40 hours

**Deliverables:**
- Documentation for multi-chain deployment patterns
- Support for configuring RPC endpoints (Arbitrum, Base, Gnosis, Mainnet)
- Module chain configuration capabilities
- Docker image for deployment
- Comprehensive deployment documentation

**Success Criteria:**
- Clear documentation for multi-chain deployment
- Flexible architecture supporting single and multi-chain setups
- Docker image runs on fresh server with minimal configuration
- Complete documentation for production deployment

## Length

**Expected Completion:** 9.5 weeks from commencement date

**Commencement Date:** Upon successful passing of the proposal on Snapshot

**Final Delivery Date:** Approximately 2 months from commencement

This grant will be completed well within the 6-month maximum timeframe.

## Funding Request

**Rate:** €100/hour  
**Total Grant Amount:** €38,000

**Payment Terms:**
- 25% up-front: €9,500 (upon grant approval)
- 75% on completion: €28,500 (upon successful delivery of all milestones)

## Gnosis Chain Address

`0xc0de401Dfb531Ec15A453C3301E5807Cf2C8323e`

## Other Information

### Value to CoW Protocol

**Immediate Benefits:**
- Replace hardcoded watch-tower with flexible, updatable WASM module
- Eliminate Ethflow-specific logic from backend, improving maintainability
- Enable novel order types without infrastructure changes
- Competitive differentiation: most DeFi protocols lack programmable automation

**Long-Term Strategic Value:**
- Module marketplace potential (community-built automation)
- Automation increases CoW Protocol usage and volume
- Foundation for Methane integration and cross-chain automation

### Comparison to Existing Solutions

Shepherd is the only fully programmable, self-hosted, community-extensible automation platform compared to centralised alternatives (Gelato, Chainlink Keepers, OpenZeppelin Defender) which charge per-transaction fees and offer limited programmability.

### Open Source Commitment

All code released under AGPL license per CoW DAO requirements:
- `shepherd-runtime`: Core WASM runtime
- `shepherd-sdk`: SDK for module development
- `shepherd-modules`: Official modules and examples

### Conflict of Interest Disclosure

- Previous Work: Core contributor to CoW Protocol (Aug 2023 - Oct 2024)
- Current Position: Active member of CoW DAO Grants Committee—**will abstain from voting on this proposal**
- No ongoing financial relationship with CoW Protocol

### Communication

- Weekly progress reports posted to CoW Protocol forum
- All code public from day 1
- Architecture decisions documented

## Terms and Conditions

By submitting this grant application, I acknowledge and agree to be bound by the [CoW DAO Participation Agreement](https://cow.fi/legal/cowdao-participation-agreement) and the [CoW DAO Grant Agreement Terms](https://cow.fi/legal/cow-grants-terms-conditions).

---

**NOTE TO COMMITTEE:**

Please notify the Grantee of their reviewer and their steward in the thread and latest upon successful approval of the Grant on Snapshot.

---

To vote or create proposals from an AI assistant, connect the Snapshot MCP at https://mcp.snapshot.box

