Skip to main content
Glama
README.md
# morpho-direct

**A local borrowing toolkit for Morpho on Base.** One core, a CLI for people and scripts, and a read/plan-only MCP server for agents.

[![Checks](https://github.com/jessysw/morpho-direct/actions/workflows/ci.yml/badge.svg)](https://github.com/jessysw/morpho-direct/actions/workflows/ci.yml)

**Development preview (`0.1.0-dev.0`).** This TypeScript implementation is not audited and has not completed a real-funds round trip. Do not treat successful tests as a production safety guarantee. There is no npm release yet; use the source installation below. See [verification status](docs/verification/README.md).

## Why this exists

Borrowing has plenty of interfaces. The difficult part of a small integration is getting the details right: interest between reads, repayment shares, decimal precision, atomic calls, transaction outcomes, and a crash after submission.

This project makes those details visible and testable. It adapts borrowing flows developed in a private trading system into a standalone tool. The earlier system's real-world experience informs the implementation; it does **not** establish that this new implementation is verified.

Direct Morpho calls avoid the loan-processing fee of an intermediary borrowing interface. **Market interest and network gas still apply**, along with liquidation, oracle, smart-contract and underlying-asset risks. No fixed saving or borrowing rate is promised. This tool does not call Coinbase's managed Borrow API or charge an author fee.

## Boundaries

- Runs on **your** machine. No author-hosted backend, account system, telemetry or log upload.
- Uses **your** RPC and, optionally, **your** CDP project. No shared service credentials.
- Never accepts or stores a private key. The CDP signer authenticates in the user's browser.
- MCP can read, build plans and simulate. It has **no sign, execute or send tool**.
- The optional approval page binds only to `127.0.0.1`. It is a temporary local UI, not a hosted service.
- One supported chain (Base, `8453`); two reviewed-in-code market IDs (cbBTC/USDC and WETH/USDC).
- No Coinbase account API access in v0.1. Fund the wallet manually. The optional transfer adapter is future work.
- No trading strategies, unattended borrowing, Coinbase-app loan management, EOA execution or generic Safe execution.

Local software still contacts your RPC and Coinbase CDP when used. Blockchain activity is public. Your agent/model provider may receive tool outputs such as addresses and balances. Nothing is sent to the author by this software.

## Install from source

Requires **Node.js 24 (24.12 or newer)** and npm. Node's built-in SQLite avoids a native addon; its API is still evolving in Node 24. The supported Node range and CI are deliberately narrow.

The optional CDP adapter depends on Coinbase's Frontend SDK. Its pinned npm artifacts do not specify a license; this repository does not relicense or redistribute that SDK. See [third-party notices](THIRD_PARTY_NOTICES.md) before building/distributing a bundle. npm publication is disabled pending that review.

```sh
git clone https://github.com/jessysw/morpho-direct.git
cd morpho-direct
npm ci --ignore-scripts
npm run build
node dist/cli.js --help
```

Use `node /absolute/path/to/morpho-direct/dist/cli.js` in place of `morpho-direct` in the examples below. Alternatively, `npm link --ignore-scripts` installs the local command.

```sh
morpho-direct init
# Edit ~/.config/morpho-direct/config.toml with YOUR account.
# Set the RPC environment variable through your preferred secret manager.
export MORPHO_DIRECT_RPC_URL="https://YOUR_BASE_RPC"
morpho-direct doctor
morpho-direct status --json
```

`init` creates a mode-0600 template and never overwrites a file. It does not create a wallet or send any transaction. `doctor` verifies chain/market reads and deployment; it cannot verify ownership or fund the account. See [configuration](docs/configuration.md).

## A complete workflow

Start with an **already deployed Coinbase Smart Wallet-compatible account** on Base. Have collateral in that account, USDC for repayment, and gas (unless you configure sponsorship). The simulator deliberately refuses EOAs and undeployed accounts.

```sh
morpho-direct plan borrow --market cbbtc-usdc --add-collateral 0.03 --amount 1500
morpho-direct show pln_REPLACE_WITH_RETURNED_ID

# Human terminal only; configure your own CDP project first:
morpho-direct approve pln_REPLACE_WITH_RETURNED_ID

# A submitted hash is not proof of success:
morpho-direct confirm pln_REPLACE_WITH_RETURNED_ID

morpho-direct plan repay --market cbbtc-usdc --amount 250
morpho-direct plan close --market cbbtc-usdc
```

Each `plan` returns an immutable plan ID, exact calls, fund flows, projected LTV, liquidation price, expiry and simulation result. `approve` prints a private local URL to the human terminal. Review the page, authenticate with your own CDP project, type the plan suffix, and click **Approve & sign**. No terminal `--yes` bypass exists.

Other actions: `plan add-collateral`, `plan withdraw`, and `plan repay --amount all --withdraw all`. Default receivers are your own account. Named external receivers must be configured with permitted assets. With a WETH position, an ETH receiver triggers withdraw → unwrap → send; the default self receiver keeps WETH.

`export PLAN_ID --out unsigned.json` produces an unsigned Coinbase-smart-wallet batch. It does not sign or broadcast. External tools must support that wallet's `executeBatch` ABI. This is **not** an EOA transaction sequence or a Safe Transaction Service payload. An exported file can be copied and signed elsewhere; local software cannot enforce external one-time use. Confirm the result with `confirm PLAN_ID --tx HASH`.

## Use with an agent

Configure a local stdio MCP process in a client that supports it:

```json
{
  "mcpServers": {
    "morpho-direct": {
      "command": "node",
      "args": ["/absolute/path/to/morpho-direct/dist/cli.js", "mcp"],
      "env": {
        "MORPHO_DIRECT_CONFIG": "/absolute/path/to/your/config.toml"
      }
    }
  }
}
```

Pass your RPC environment variable securely to the client process. Do not paste private RPC URLs or credentials into chat. The MCP server has no network listener. It offers 12 tools: markets/account/position reads, five plan actions, plan/operation reads, and `request_approval` (which returns only a **command for the human**).

An appropriate prompt: “Read my position and prepare a plan to repay 500 USDC. Explain the before/after LTV. Do not execute it.”

MCP restrictions are an application boundary, not a sandbox against an agent with independent shell/browser access to your machine. See the [threat model](docs/security-model.md).

## Failure recovery

Local plans and events live in `~/.local/state/morpho-direct/ops.sqlite` (owner-only permissions). Submission intent and a stable CDP idempotency key are committed **before** the browser can call the provider. Only one outstanding submission/export is permitted per state directory.

If submission times out or the browser closes, run `ops` and `confirm`. An unknown outcome stays locked. If the callback hash was lost, recover it from wallet history:

```sh
morpho-direct confirm PLAN_ID --user-op 0xUSER_OPERATION_HASH
# or
morpho-direct confirm PLAN_ID --tx 0xTRANSACTION_HASH
```

Confirmation verifies the account, exact batch, canonical receipt and EntryPoint event; it waits for three block inclusions. It never retries a financial operation. There is intentionally no automatic “reset unknown and resend” command. See [recovery limits](docs/design.md).

## Develop

```sh
npm run check          # types, lint, offline unit/integration tests, browser bundle
npm run test:browser   # local mock wallet flow + real bundle rendering; no real signing
npm audit
npm pack --dry-run --ignore-scripts
```

Tests cross-check integer debt and interest calculations against the official Morpho SDK. They cover reducing risk above policy limits, allowances, ETH wrapping, concurrency, failed simulations, MCP protocol behavior and loopback request validation. They do not substitute for fork tests, an audit, or a user-authorized live verification.

[Design](docs/design.md) · [Configuration](docs/configuration.md) · [Security model](docs/security-model.md) · [SDK dependency notes](docs/cdp-sdk-patch.md) · [Verification](docs/verification/README.md)

## License and maintenance

Apache-2.0. Copyright 2026 jessysw. Contributions welcome; maintenance is best effort, with no SLA, support commitment or bug bounty. See [SECURITY.md](SECURITY.md) for private vulnerability reporting. Unofficial; not affiliated with, endorsed by or sponsored by Morpho or Coinbase. No third-party logos are used.