morpho-vault-manager 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,179 @@
1
+ # Architecture
2
+
3
+ ## Purpose
4
+
5
+ This repository will produce a native OpenClaw plugin that onboards a user into a constrained Morpho vault-management agent and runs that agent periodically through OpenClaw cron.
6
+
7
+ The architecture is intentionally narrow. The system is not a general trading bot and not a generic DeFi wallet manager.
8
+
9
+ ## System Boundaries
10
+
11
+ ### In Scope
12
+
13
+ - Native OpenClaw plugin packaging
14
+ - `configure` onboarding flow with `clack`
15
+ - OWS wallet creation/import and API-key provisioning
16
+ - Morpho data reads and transaction preparation
17
+ - Periodic rebalancing through OpenClaw cron
18
+ - Reporting and auditability
19
+
20
+ ### Out of Scope for v1
21
+
22
+ - Cross-chain bridging
23
+ - Swaps
24
+ - Borrowing strategies
25
+ - Leverage
26
+ - Arbitrary smart-contract execution
27
+ - Custom OpenClaw agent harness runtime
28
+
29
+ ## Major Components
30
+
31
+ ### 1. OpenClaw Native Plugin
32
+
33
+ Responsibilities:
34
+
35
+ - expose CLI/setup entrypoints
36
+ - own plugin config and profile storage
37
+ - create/update the dedicated OpenClaw agent
38
+ - write standing instructions into the agent workspace
39
+ - create and manage cron jobs
40
+ - discover or persist per-profile cron delivery targets
41
+
42
+ ### 2. OpenClaw Agent Runtime
43
+
44
+ Responsibilities:
45
+
46
+ - execute the periodic rebalance turn
47
+ - use the vendored Morpho skill guidance
48
+ - call local script entrypoints and future plugin tools
49
+ - report results through OpenClaw task and cron surfaces
50
+
51
+ This repo assumes the standard OpenClaw agent runtime. The plugin does not own session compaction, thread lifecycle, or model transport.
52
+
53
+ ### 3. OWS
54
+
55
+ Responsibilities:
56
+
57
+ - wallet lifecycle
58
+ - API-key based agent access
59
+ - API-key provisioning may remain manual/out-of-process in v1 to keep the raw token out of plugin process memory
60
+ - signing
61
+ - future `signAndSend` support when a documented CLI surface exists
62
+
63
+ Current integration mode is local subprocess access. The current live wrapper signs through `ows sign tx` and then broadcasts through Base RPC because the documented OWS CLI reference does not currently document a `signAndSend` command. Future direct SDK or local daemon integration is optional.
64
+
65
+ ### 4. Morpho Tooling
66
+
67
+ Responsibilities:
68
+
69
+ - read Morpho vault and position state
70
+ - prepare unsigned transactions
71
+ - simulate transactions before execution
72
+
73
+ The rebalance runtime uses `morpho-cli` directly. Morpho skill content is installed as a workspace skill from [`morpho-org/morpho-skills`](https://github.com/morpho-org/morpho-skills/) so agents have Morpho-specific operating instructions available via the skill system.
74
+
75
+ ## End-to-End Flow
76
+
77
+ ### Configure
78
+
79
+ 1. User runs `openclaw vault-manager configure`.
80
+ 2. Plugin checks for required tools and daemon assumptions.
81
+ 3. Plugin creates or imports an OWS wallet.
82
+ 4. Plugin emits OWS API-key provisioning instructions, and the operator completes token creation out-of-process so the raw token never enters plugin process memory.
83
+ 6. Plugin records the risk profile.
84
+ 7. Plugin offers funding guidance and an optional "continue once funded" balance poll against Morpho token reads.
85
+ 8. Plugin offers optional model-routing preference for the dedicated agent.
86
+ 9. Plugin creates a dedicated OpenClaw agent workspace.
87
+ 10. Plugin writes `AGENTS.md` standing orders into that workspace.
88
+ 11. Plugin configures cron delivery for that profile: default `channel=last`, or an explicit Telegram target discovered from OpenClaw directory surfaces.
89
+ 12. Plugin creates an isolated OpenClaw cron job for periodic execution.
90
+ 13. Plugin runs a final validation plan against live Morpho state and persists the outcome in the profile.
91
+
92
+ ### Rebalance Run
93
+
94
+ 1. OpenClaw cron wakes the dedicated agent in an isolated session.
95
+ 2. The agent calls `openclaw vault-manager plan` to get a deterministic allocation plan (vault scoring, target allocations, actions).
96
+ 3. If the plan status is `no_op` or `blocked`, the agent reports reasons and stops.
97
+ 4. If the plan status is `planned`, the agent executes each action:
98
+ a. Prepares transactions using morpho-cli (`morpho prepare-deposit` or `morpho prepare-withdraw`).
99
+ b. Verifies simulation success. Stops on first failure.
100
+ c. Signs the prepared transaction using OWS (`ows sign tx`).
101
+ d. Broadcasts the signed transaction to the Base network.
102
+ e. Waits for transaction confirmation.
103
+ 5. The agent reports all executed transactions (hashes, gas) or failure reasons.
104
+
105
+ ## Repository Structure Targets
106
+
107
+ This is the intended direction for the repo:
108
+
109
+ ```text
110
+ .
111
+ ├── AGENTS.md
112
+ ├── ARCHITECTURE.md
113
+ ├── SECURITY.md
114
+ ├── docs/
115
+ │ ├── openclaw-vault-manager-spec.md
116
+ │ └── exec-plans/
117
+ │ └── active/
118
+ ├── evals/
119
+ ├── scripts/
120
+ │ ├── check/
121
+ │ ├── dev/
122
+ │ └── rebalance/
123
+ └── src/
124
+ └── plugin implementation
125
+ ```
126
+
127
+ `src/` now contains the native plugin, CLI surfaces, and the first rebalance runtime implementation.
128
+
129
+ ## Invariants
130
+
131
+ - The plugin must remain model-agnostic.
132
+ - All live writes must be signed through OWS.
133
+ - Base-only and USDC-only must be enforceable mechanically, not just mentioned in prompts.
134
+ - The rebalance runtime must only forward `morpho-cli`-prepared transactions to OWS. Agent-authored calldata never reaches signing.
135
+ - Simulation failure is terminal for a run.
136
+ - Live execution must be auditable from logs and evals.
137
+
138
+ ## Required Future Modules
139
+
140
+ ### Config/Profile Layer
141
+
142
+ - profile file loading
143
+ - risk profile resolution
144
+
145
+ ### OWS Adapter
146
+
147
+ - wallet lookup
148
+ - API key management
149
+ - sign wrapper plus broadcast/receipt verification
150
+
151
+ ### Morpho Adapter
152
+
153
+ - vault discovery
154
+ - position reads
155
+ - transaction preparation
156
+ - simulation handling
157
+
158
+ ### Rebalance Engine
159
+
160
+ - weighted scoring: `apy_weight * net_apy + tvl_weight * normalized_tvl - fee_weight * fee_pct - rewards_penalty`
161
+ - per-profile score weights and reward preference
162
+ - target weight computation
163
+ - drift detection
164
+ - execution plan generation
165
+
166
+ ### OpenClaw Adapter
167
+
168
+ - agent bootstrap
169
+ - workspace file generation
170
+ - cron management
171
+ - delivery-target discovery (`channels list`, `directory groups list`)
172
+ - reporting hooks
173
+
174
+ ## Design Bias
175
+
176
+ - Prefer explicit adapters over direct shell calls spread across the codebase.
177
+ - Prefer deterministic scripts over undocumented shell recipes.
178
+ - Prefer narrow data contracts over implicit object blobs.
179
+ - Prefer a few hard constraints over a large prompt.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Morpho Vault Manager
2
+
3
+ Native OpenClaw plugin for onboarding and running a constrained Morpho vault manager agent on Base.
4
+
5
+ ## Scope
6
+
7
+ - Base only
8
+ - USDC only
9
+ - Morpho vault management only
10
+ - All signing through OWS
11
+
12
+ ## Prerequisites
13
+
14
+ - `openclaw` installed and the gateway running
15
+ - OpenClaw gateway `2026.4.12` or newer
16
+ - `ows` installed and on `PATH`
17
+ - `bunx @morpho-org/cli` available
18
+ - A Base RPC URL configured if you plan to exercise live broadcast verification
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ openclaw plugins install morpho-vault-manager
24
+ openclaw plugins enable morpho-vault-manager
25
+ openclaw gateway restart
26
+ ```
27
+
28
+ ## Configure
29
+
30
+ ```bash
31
+ openclaw vault-manager configure
32
+ ```
33
+
34
+ The configure flow will:
35
+
36
+ 1. run preflight checks
37
+ 2. guide wallet create/import through OWS
38
+ 3. ask you to create the OWS API key in a separate shell
39
+ 4. record the token source as an env var or file reference
40
+ 5. generate the dedicated agent workspace and `AGENTS.md`
41
+ 6. choose how cron results are delivered (`last` route by default, or a pinned target)
42
+ 7. create the OpenClaw cron job
43
+ 8. run a final validation plan
44
+
45
+ The plugin never stores owner credentials or raw private keys in repo files, prompts, or profile JSON.
46
+
47
+ ## Verify
48
+
49
+ ```bash
50
+ openclaw vault-manager status
51
+ openclaw vault-manager plan --json
52
+ openclaw vault-manager run-now
53
+ ```
54
+
55
+ Release QA should include operating the installed plugin through `openclaw` directly, not just running repo-local checks.
56
+
57
+ For repository-level health checks before publishing:
58
+
59
+ ```bash
60
+ scripts/dev/doctor --format=json
61
+ scripts/check/publish
62
+ scripts/check/release-install
63
+ ```
64
+
65
+ ## Release QA
66
+
67
+ Use [docs/release-qa-checklist.md](docs/release-qa-checklist.md) as the final pre-release verification sheet for publish, install, configure, cron, and safety checks.
68
+ `scripts/check/release-install` is the fail-closed release gate for packed-artifact install on a supported OpenClaw version.
package/SECURITY.md ADDED
@@ -0,0 +1,103 @@
1
+ # Security
2
+
3
+ ## Security Goal
4
+
5
+ The system must let an agent manage a constrained Morpho vault portfolio without ever granting that agent unconstrained wallet access.
6
+
7
+ ## Primary Threat Model
8
+
9
+ We assume:
10
+
11
+ - the model may hallucinate or choose an unsafe action
12
+ - the local machine is trusted enough to run OpenClaw and OWS, but the agent should still operate under least privilege
13
+
14
+ We do not assume the prompt alone will prevent unsafe execution.
15
+
16
+ ## Non-Negotiable Invariants
17
+
18
+ - Owner credentials never enter agent-visible runtime state.
19
+ - Raw private keys never appear in plugin code, logs, prompts, config, or repo files.
20
+ - The agent receives only an OWS API token.
21
+ - The rebalance runtime only forwards transactions produced by `morpho-cli` prepare flows to OWS. No code path accepts agent-authored calldata.
22
+ - Live execution is allowed only on Base for v1.
23
+ - Live execution is allowed only for USDC Morpho vault operations for v1.
24
+ - All live signatures must come from OWS.
25
+ - Simulation failure aborts execution.
26
+
27
+ ## Credential Model
28
+
29
+ ### Owner Credential
30
+
31
+ - Full wallet authority
32
+ - Must never be used by the periodic vault-manager agent
33
+
34
+ ### OWS API Token
35
+
36
+ - Scoped to one wallet for v1
37
+ - The only credential the agent may use
38
+ - In v1, the raw token is provisioned out-of-process so the plugin never needs to load it into process memory
39
+
40
+ ### Broadcast Path
41
+
42
+ - Current implementation uses OWS for signing and Base RPC for broadcast plus receipt verification.
43
+ - This does not widen secret access: the signing boundary remains inside OWS.
44
+ - When the OWS CLI exposes a documented `signAndSend` surface, the plugin should move broadcast into OWS as well.
45
+
46
+ ## OWS Policy Model
47
+
48
+ The plugin does not create, attach, or enforce custom OWS policies.
49
+
50
+ OWS default policy behavior is left untouched. The plugin's enforcement point is the runtime path around OWS:
51
+
52
+ - only `morpho-cli` prepare flows may produce transactions for signing
53
+ - no code path accepts agent-authored calldata and hands it to OWS
54
+ - Base-only, USDC-only, turnover, and simulation constraints are enforced in the plugin runtime before signing
55
+
56
+ If a future change allows calldata to reach OWS through any path other than Morpho prepare output, the trust model must be re-evaluated and documented before merge.
57
+
58
+ ## Morpho Skill
59
+
60
+ Morpho protocol interaction is provided via the `morpho-cli` workspace skill (from [`morpho-org/morpho-skills`](https://github.com/morpho-org/morpho-skills/)). The skill provides CLI-based query and prepare commands that return unsigned transactions. The rebalance runtime uses `morpho-cli` directly and runs under the narrow AGENTS.md contract.
61
+
62
+ ## Logging Rules
63
+
64
+ - Do not log owner credentials, API tokens, private keys, mnemonics, or raw decrypted secret material.
65
+ - If logging command lines, redact secrets and token-like strings.
66
+ - If logging transaction plans, prefer summarized transaction metadata over full sensitive payload dumps unless debugging is explicitly enabled.
67
+
68
+ ## Storage Rules
69
+
70
+ - Do not commit secrets to the repo.
71
+ - Do not write owner credentials into OpenClaw prompts or workspace files.
72
+ - API tokens must be resolved through the configured token source (`env` or `file`), never hardcoded in profile JSON or plugin config.
73
+ - `file` sources are intended for mounted-secret setups (Docker/k8s/systemd EnvironmentFile). File contents are read at execution time and never copied into the profile.
74
+ - Profile files may contain public addresses, wallet IDs, thresholds, cron metadata, delivery targets/account ids, and the token source descriptor (kind + identifier), never the token value itself.
75
+ - The configure flow should emit the OWS API-key provisioning command and then accept only the resulting token source descriptor, not the raw token.
76
+
77
+ ## Cron Delivery
78
+
79
+ - Cron delivery routing is public operational metadata, not secret material.
80
+ - A profile may store `deliveryChannel`, `deliveryTo`, and `deliveryAccountId` so each managed agent can announce to a different chat destination.
81
+ - The default delivery route should be OpenClaw's `last` channel target unless the operator pins an explicit destination.
82
+ - Discovery of Telegram groups/topics should use OpenClaw CLI directory surfaces only; the plugin must not scrape or persist unrelated chat history to infer a target.
83
+
84
+ ## Execution Guardrails
85
+
86
+ - Configure flows should run a validation plan before completing onboarding.
87
+ - Transaction preparation and execution is delegated to the agent using morpho-cli and OWS. The agent's AGENTS.md instructions enforce:
88
+ - Only morpho-cli-prepared transactions reach OWS signing (no agent-authored calldata).
89
+ - Simulation failure is terminal — the agent must stop on first failure.
90
+ - Chain (Base) and asset (USDC) scope are enforced by the plan command's scoring engine.
91
+ - The agent must report transaction hashes and verification details after each run.
92
+
93
+ ## Review Checklist
94
+
95
+ Every write-path change should be reviewed against these questions:
96
+
97
+ 1. Does any new code handle sensitive material directly?
98
+ 2. Can this path produce a live transaction after a failed simulation?
99
+ 3. Can this path forward calldata to OWS that did not come from a `morpho-cli` prepare flow?
100
+ 4. Can this path operate on a non-Base chain or non-USDC asset?
101
+ 5. Is the failure mode explicit and visible to the operator?
102
+
103
+ If any answer is "yes", the change is blocked until the architecture and security docs are updated and the guardrail is encoded mechanically.
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
2
+ import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
3
+ import { registerVaultManagerCli } from "./src/cli/register.js";
4
+ import { registerInlineToken } from "./src/lib/secrets.js";
5
+ import { resolveVaultManagerSettings } from "./src/lib/settings.js";
6
+ export default definePluginEntry({
7
+ id: "morpho-vault-manager",
8
+ name: "Morpho Vault Manager",
9
+ description: "Onboard and operate a constrained Morpho vault manager agent on OpenClaw.",
10
+ register(api) {
11
+ const pluginConfig = (api.pluginConfig ?? {});
12
+ try {
13
+ const resolved = normalizeResolvedSecretInputString({
14
+ value: pluginConfig.apiKey,
15
+ refValue: pluginConfig.apiKeyValue,
16
+ path: "plugins.entries.morpho-vault-manager.apiKey"
17
+ });
18
+ if (resolved) {
19
+ registerInlineToken("plugin-config:apiKey", resolved);
20
+ pluginConfig.apiKeyValue = resolved;
21
+ }
22
+ }
23
+ catch (error) {
24
+ api.logger?.warn?.(`morpho-vault-manager: unresolved SecretRef for apiKey — ${error.message}`);
25
+ }
26
+ const settings = resolveVaultManagerSettings(pluginConfig);
27
+ api.registerCli(({ program, logger }) => {
28
+ registerVaultManagerCli({
29
+ program,
30
+ logger,
31
+ settings
32
+ });
33
+ }, {
34
+ descriptors: [
35
+ {
36
+ name: "vault-manager",
37
+ description: "Configure and operate the Morpho vault manager agent",
38
+ hasSubcommands: true
39
+ }
40
+ ]
41
+ });
42
+ }
43
+ });
@@ -0,0 +1,26 @@
1
+ function parseArgs(argv) {
2
+ let profileId = "default";
3
+ for (let index = 0; index < argv.length; index += 1) {
4
+ const arg = argv[index];
5
+ if (arg === "--profile") {
6
+ profileId = argv[index + 1] ?? profileId;
7
+ index += 1;
8
+ }
9
+ }
10
+ return { profileId };
11
+ }
12
+ async function main() {
13
+ const { profileId } = parseArgs(process.argv.slice(2));
14
+ const [{ runPlan }, { resolveVaultManagerSettings }] = await Promise.all([
15
+ import(new URL("../lib/rebalance.ts", import.meta.url).href),
16
+ import(new URL("../lib/settings.ts", import.meta.url).href)
17
+ ]);
18
+ const settings = resolveVaultManagerSettings();
19
+ const result = await runPlan(settings, profileId);
20
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
21
+ }
22
+ main().catch((error) => {
23
+ process.stderr.write(`${error.message}\n`);
24
+ process.exitCode = 1;
25
+ });
26
+ export {};