morpho-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

morpho-cli

morpho-cli

Experimental (pre-v1.0) — Command syntax, response schemas, and available operations may change. Always verify critical outputs independently.
Query Morpho protocol data and build unsigned transactions. All commands output JSON to stdout. No private keys needed.
bash
morpho <command> [options]
Supported chains:
base
,
ethereum
. Every command requires
--chain
.
实验版本(v1.0之前) — 命令语法、响应结构和可用操作可能会发生变化。重要输出请务必独立验证。
查询Morpho协议数据,构建未签名交易。所有命令的输出都是JSON格式打印到标准输出,无需私钥。
bash
morpho <command> [options]
支持的链:
base
ethereum
。所有命令都需要指定
--chain
参数。

Response Schemas

响应结构

  • Read commands — exact JSON shapes for query-vaults, get-vault, query-markets, get-market, get-positions, get-position
  • Write commands — exact JSON shapes for prepare-*, simulate-transactions
  • 读操作命令 — query-vaults、get-vault、query-markets、get-market、get-positions、get-position的准确JSON结构定义
  • 写操作命令 — prepare-*、simulate-transactions的准确JSON结构定义

Quick Reference

快速参考

bash
undefined
bash
undefined

Read — query protocol state

读操作 — 查询协议状态

morpho query-vaults --chain base [--asset-symbol USDC] [--asset-address 0x...] [--sort apy_desc|apy_asc|tvl_desc|tvl_asc] [--limit 5] [--skip 0] [--fields address,name,symbol,apyPct,tvl,tvlUsd,feePct] morpho get-vault --chain base --address 0x... morpho query-markets --chain base --loan-asset 0x... --collateral-asset 0x... [--sort-by supplyApy|borrowApy|netSupplyApy|netBorrowApy|supplyAssetsUsd|borrowAssetsUsd|totalLiquidityUsd] [--sort-direction asc|desc] [--limit 10] [--skip 0] [--fields supplyApy,borrowApy,totalSupply,totalBorrow,totalCollateral,totalLiquidity,supplyAssetsUsd,borrowAssetsUsd,collateralAssetsUsd,liquidityAssetsUsd] morpho get-market --chain base --id 0x... morpho get-positions --chain base --user-address 0x... [--vault-address 0x...] [--market-id 0x...] morpho get-position --chain base --user-address 0x... [--vault-address 0x...]
morpho query-vaults --chain base [--asset-symbol USDC] [--asset-address 0x...] [--sort apy_desc|apy_asc|tvl_desc|tvl_asc] [--limit 5] [--skip 0] [--fields address,name,symbol,apyPct,tvl,tvlUsd,feePct] morpho get-vault --chain base --address 0x... morpho query-markets --chain base --loan-asset 0x... --collateral-asset 0x... [--sort-by supplyApy|borrowApy|netSupplyApy|netBorrowApy|supplyAssetsUsd|borrowAssetsUsd|totalLiquidityUsd] [--sort-direction asc|desc] [--limit 10] [--skip 0] [--fields supplyApy,borrowApy,totalSupply,totalBorrow,totalCollateral,totalLiquidity,supplyAssetsUsd,borrowAssetsUsd,collateralAssetsUsd,liquidityAssetsUsd] morpho get-market --chain base --id 0x... morpho get-positions --chain base --user-address 0x... [--vault-address 0x...] [--market-id 0x...] morpho get-position --chain base --user-address 0x... [--vault-address 0x...]

Write — prepare unsigned transactions (simulation runs by default; add --no-simulate to skip)

写操作 — 准备未签名交易(默认会自动运行模拟;添加--no-simulate可跳过)

morpho prepare-deposit --chain base --vault-address 0x... --user-address 0x... --amount 1000 morpho prepare-withdraw --chain base --vault-address 0x... --user-address 0x... --amount max morpho prepare-supply --chain base --market-id 0x... --user-address 0x... --amount 5000 morpho prepare-borrow --chain base --market-id 0x... --user-address 0x... --borrow-amount 1 morpho prepare-repay --chain base --market-id 0x... --user-address 0x... --amount max morpho prepare-supply-collateral --chain base --market-id 0x... --user-address 0x... --amount 5000 morpho prepare-withdraw-collateral --chain base --market-id 0x... --user-address 0x... --amount max
morpho prepare-deposit --chain base --vault-address 0x... --user-address 0x... --amount 1000 morpho prepare-withdraw --chain base --vault-address 0x... --user-address 0x... --amount max morpho prepare-supply --chain base --market-id 0x... --user-address 0x... --amount 5000 morpho prepare-borrow --chain base --market-id 0x... --user-address 0x... --borrow-amount 1 morpho prepare-repay --chain base --market-id 0x... --user-address 0x... --amount max morpho prepare-supply-collateral --chain base --market-id 0x... --user-address 0x... --amount 5000 morpho prepare-withdraw-collateral --chain base --market-id 0x... --user-address 0x... --amount max

Simulate — standalone re-simulation or arbitrary transaction simulation

模拟 — 独立重新模拟或任意交易模拟

morpho simulate-transactions --chain base --from 0x... --transactions '<JSON>' --analysis-context '<JSON>'
morpho simulate-transactions --chain base --from 0x... --transactions '<JSON>' --analysis-context '<JSON>'

Utility

工具类命令

morpho health-check morpho get-supported-chains
undefined
morpho health-check morpho get-supported-chains
undefined

Write Workflow: Prepare → Present

写操作工作流:准备 → 展示

Every write operation follows two steps. Simulation runs automatically inside
prepare-*
.
  1. Prepare — run a
    prepare-*
    command. The CLI handles token decimals, allowances, approvals, and simulation automatically. Returns
    {operation, simulation}
    where
    operation
    has transactions/summary/warnings/preview and
    simulation
    has execution results, gas, and post-state analysis. Use
    --no-simulate
    to skip simulation.
  2. Present — show the summary, list of unsigned transactions, simulation results, and any warnings (low health factor, partial liquidity) in tabular format. If
    simulation.allSucceeded
    is false — diagnose before presenting.
Use
simulate-transactions
separately only for re-simulating with different parameters or simulating arbitrary transactions.
所有写操作都遵循两个步骤。
prepare-*
命令内部会自动运行模拟。
  1. 准备 — 执行
    prepare-*
    命令。CLI会自动处理代币精度、授权限额、批准和模拟。返回
    {operation, simulation}
    结构,其中
    operation
    包含交易/摘要/警告/预览信息,
    simulation
    包含执行结果、gas消耗和交易后状态分析。可添加
    --no-simulate
    参数跳过模拟。
  2. 展示 — 以表格形式展示摘要、未签名交易列表、模拟结果和所有警告(健康因子过低、流动性不足等)。如果
    simulation.allSucceeded
    为false — 请先诊断问题再展示结果。
仅当需要使用不同参数重新模拟或模拟任意交易时,才单独使用
simulate-transactions
命令。

Simulation Failures

模拟失败说明

RevertCauseWhat to do
ERC20: insufficient allowance
Missing approvalRe-prepare — CLI should include approvals automatically
ERC4626ExceededMaxWithdraw
Vault liquidity insufficientReduce amount (see below)
insufficient balance
User lacks tokensTell the user
Custom error hexProtocol-specificQuery state with
get-market
or
get-vault
to diagnose
报错信息原因解决方法
ERC20: insufficient allowance
缺少授权重新执行准备命令 — CLI会自动包含授权操作
ERC4626ExceededMaxWithdraw
金库流动性不足减少取款金额(见下文)
insufficient balance
用户代币余额不足告知用户
自定义错误十六进制码协议特定报错使用
get-market
get-vault
查询协议状态来诊断问题

Partial Withdrawal

部分取款说明

If
prepare-withdraw --amount max
returns a liquidity warning:
  1. Parse the safe amount from
    summary
    , apply ~1% buffer (
    parsedAmount * 0.99
    )
  2. Re-call
    prepare-withdraw
    with the buffered amount, then simulate
  3. Tell the user: remaining locked assets free up as borrowers repay
如果
prepare-withdraw --amount max
返回流动性警告:
  1. summary
    中解析安全取款金额,添加约1%的缓冲(
    解析后金额 * 0.99
  2. 使用带缓冲的金额重新调用
    prepare-withdraw
    ,然后执行模拟
  3. 告知用户:剩余锁定资产会随着借款人还款而逐步解锁

Safety Rules

安全规则

  1. Check simulation before presenting — simulation runs by default; check
    simulation.allSucceeded
    before presenting
  2. Never sign or broadcast — unsigned payloads only
  3. Watch health factor for borrows — warn if below 1.1
  4. Communicate liquidity constraints clearly for partial withdrawals
  1. 展示前先检查模拟结果 — 默认会自动运行模拟;展示前请先检查
    simulation.allSucceeded
    字段
  2. 绝不签名或广播交易 — 仅生成未签名负载
  3. 借款时关注健康因子 — 如果低于1.1请发出警告
  4. 部分取款时要清晰告知流动性限制

CLI Errors

CLI错误处理

When a morpho CLI command fails, stop and report the error to the user. Do not:
  • Retry with different parameters you invented
  • Fall back to alternative tools or APIs
  • Attempt to work around missing required options
  • Pipe output through
    jq
    or other filters — use the CLI's built-in flags (
    --fields
    ,
    --sort-by
    ,
    --limit
    , etc.) to shape the response
当morpho CLI命令执行失败时,停止操作并向用户上报错误。请勿:
  • 自行修改参数重试
  • 切换到其他工具或API作为兜底
  • 尝试绕过必填参数的限制
  • 通过
    jq
    或其他过滤器处理输出 — 使用CLI内置的参数(
    --fields
    --sort-by
    --limit
    等)来调整返回结果格式

Common Mistakes

常见错误

  • Forgetting
    --chain
    — every command requires it, there is no default
  • Using chain IDs (
    1
    ,
    8453
    ) instead of names (
    ethereum
    ,
    base
    )
  • Displaying raw amounts without dividing by
    10^decimals
    "2000000000"
    USDC is
    2000
    , not 2 billion
  • Assuming 18 decimals — USDC/USDT have 6
  • Passing raw units as
    --amount
    — CLI expects human-readable (
    1000
    not
    1000000000
    )
  • Using
    --no-simulate
    without reason — simulation is on by default; only skip when debugging or for speed
  • Ignoring
    simulation.allSucceeded === false
    — diagnose before presenting
  • 忘记加
    --chain
    参数 — 所有命令都需要该参数,没有默认值
  • 使用链ID(
    1
    8453
    )而不是链名称(
    ethereum
    base
  • 展示原始金额时没有除以
    10^精度
    "2000000000"
    USDC对应的是
    2000
    ,而不是20亿
  • 默认为18位精度 — USDC/USDT的精度是6位
  • --amount
    传入原始单位值 — CLI需要的是人类可读的数值(
    1000
    而不是
    1000000000
  • 无理由使用
    --no-simulate
    — 默认开启模拟;仅在调试或需要提升速度时跳过
  • 忽略
    simulation.allSucceeded === false
    的情况 — 先诊断问题再展示结果