* Add impl plan for defihack * add Yellow + LI.FI multi-track support with ENS hydration and e2e demo runbook - implement end-to-end custom action support in compiler, IR generation, runtime action resolution, and executor routing - add new offchain venue adapters: and , and register/export them in - add adapter test suites for Yellow session lifecycle and LI.FI swap/bridge/compose_execute flows - add LI.FI compose_execute safety guard: enforce unless explicit override is set - add CLI ENS profile hydration (, ) for and - clamp ENS-hydrated to safe bounds (0..500) in - remove unused/dead ENS helper surface - add DefiHack demo spells and prompt-first README runbook (VM rehearsal + deterministic CLI e2e) - update README and reference docs for new venues and CLI flags * Add changeset * Remove unused docs
5.8 KiB
Grimoire
"Verba Volant, Scripta Manent."
Grimoire is a language for agents to express financial intent with readable syntax and deterministic execution. Spells compile to an intermediate representation (IR) and run through protocol adapters, so you can swap venues by changing aliases and configuration instead of rewriting strategy logic.
Start here
Grimoire runs in two execution environments. The spell syntax is the same; the guarantees are different.
VM mode (in-agent, best-effort)
Use this when you want to run inside an agent session for prototyping and reviews. VM mode does not bundle adapters, but it can use real venue data when the agent is allowed to run tools (for example, grimoire venue ...).
Install the VM skill:
npx skills add https://github.com/franalgaba/grimoire
Or copy it manually:
SKILLS_DIR="$HOME/.config/agents/skills"
mkdir -p "$SKILLS_DIR"
cp -R skills/grimoire-vm "$SKILLS_DIR/grimoire-vm"
Copy/paste demo (agent prompts):
Create a Grimoire VM spell named MorphoYieldOptimizer and save it to spells/morpho-yield-optimizer-vm.spell.
Use a snapshot params block, ignore markets with TVL < 5,000,000, and recommend switching when the spread over the current market is > 0.5%. Include a demo snapshot with 3 Morpho USDC markets and emit candidate + recommendation/hold events. No side effects.
Run it in VM mode:
Run spells/morpho-yield-optimizer-vm.spell in the Grimoire VM with trigger manual. Use defaults and no side effects.
Want real data? Replace the params: block with live snapshots:
grimoire venue morpho-blue vaults --chain 8453 --asset USDC --min-tvl 5000000 --format spell
For quick protocol prototyping, use the venue CLI to fetch metadata or snapshot params: blocks for VM runs. Execution still happens inside the agent session.
Next steps: run-grimoire-vm.md, vm-quickstart.md
Deterministic runtime (CLI)
Use this for reproducible simulation and onchain execution with adapters and state persistence.
Suggested flow: explore in VM → record advisory in CLI simulate → replay deterministically in cast.
npm i -g @grimoirelabs/cli
grimoire simulate spells/compute-only.spell --chain 1
grimoire cast spells/uniswap-swap-execute.spell \
--dry-run \
--key-env PRIVATE_KEY \
--rpc-url <rpc>
When you are ready to execute live:
grimoire cast spells/uniswap-swap-execute.spell --key-env PRIVATE_KEY --rpc-url <rpc>
Advisory steps (**...** and advise) call Pi when a model is configured (spell model, CLI model/provider, or Pi defaults). If no model is available, the runtime uses the spell’s fallback. Record advisory outputs with simulate (or cast --dry-run), then replay deterministically with --advisory-replay for live execution.
Next steps: cli-cast.md, transition-to-deterministic.md
Example spell
spell YieldOptimizer
assets: [USDC, DAI]
venues:
aave_v3: @aave_v3
morpho_blue: @morpho_blue
params:
amount: 100000
on hourly:
if **gas costs justify the move**:
amount_to_move = balance(USDC) * 50%
aave_v3.withdraw(USDC, amount_to_move)
morpho_blue.lend(USDC, amount_to_move)
Features
- Human-readable DSL with Python-like indentation
- Explicit constraints and limits via
withandlimits - Adapter-based venues (SDKs live in
@grimoirelabs/venues) - Onchain + offchain actions (EVM + Hyperliquid)
- Judgment boundary with
**...**andadvise - Structured control flow (loops, conditionals, try/catch, atomic)
- State persistence and run history for deterministic execution
- Two execution environments: in-agent VM and deterministic runtime
DefiHack Multi-Track
The spells/defihack/ folder provides one coherent flow that maps to multiple tracks:
| Track | Integration | Spell path |
|---|---|---|
| Yellow Network | yellow offchain app-session lifecycle |
spells/defihack/yellow-session-only.spell |
| Uniswap Foundation (v4) | uniswap_v4.swap with explicit constraints |
spells/defihack/uniswap-v4-rebalance.spell |
| LI.FI | lifi.bridge / lifi custom compose flow |
spells/defihack/lifi-crosschain-rebalance.spell |
| ENS | CLI ENS profile hydration (--ens-name) |
spells/defihack/session-vault.spell |
Primary end-to-end runbook:
grimoire simulate spells/defihack/session-vault.spell \
--ens-name <name.eth> \
--ens-rpc-url <rpc>
grimoire cast spells/defihack/session-vault.spell \
--dry-run \
--ens-name <name.eth> \
--ens-rpc-url <rpc> \
--key-env PRIVATE_KEY \
--rpc-url <rpc>
Documentation
- Start here: docs/README.md
- Spell syntax: docs/reference/spell-syntax.md
- CLI: docs/reference/cli.md
- VM spec: docs/reference/grimoire-vm.md
Updating
- Update the CLI:
npm i -g @grimoirelabs/cli@latest - Use
npxfor latest without install:npx -y @grimoirelabs/cli@latest <command> - Update packages in your project:
npm i @grimoirelabs/core@latest @grimoirelabs/venues@latest - Update the VM skill: re-install with
npx skills add https://github.com/franalgaba/grimoire(or copyskills/grimoire-vminto your agent skills directory again)
Development
bun install
bun run validate
For onchain tests and advanced workflows, see docs/how-to/run-tests.md.
License
MIT