@anywalletkit/protocol-lending-morpho-evm

中文文档
0.4.0发布于 2026/11/05Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2114

Morpho for @anywalletkit/wallet-evm accounts: Morpho Vaults (MetaMorpho V1 and Vault V2, ERC-4626 deposit / redeem) and Morpho Blue markets (supply, withdraw, borrow, repay, collateral) as LendingProtocols, on 10 chains. Vaults are verified against Morpho

原始使用文档
文档目录8 节
  1. Install
  2. Chains
  3. Usage
  4. Safety before money moves
  5. Reads
  6. Tests
  7. Status
  8. Activity

@anywalletkit/protocol-lending-morpho-evm

npm

Morpho for @anywalletkit/wallet-evm accounts, two LendingProtocols in one package:

Install

npm install @anywalletkit/protocol-lending-morpho-evm @anywalletkit/core
# or: pnpm add @anywalletkit/protocol-lending-morpho-evm @anywalletkit/core  ·  yarn add @anywalletkit/protocol-lending-morpho-evm @anywalletkit/core

On npm: @anywalletkit/protocol-lending-morpho-evm, published from the release workflow with provenance.

  • MorphoVaultProtocolEvm — a Morpho Vault (MetaMorpho / Vault V1, or Vault V2): supply deposits the vault's asset for shares, withdraw redeems them. The simplest Earn product; borrow / repay reject.
  • MorphoMarketProtocolEvm — one Morpho Blue market: supply / withdraw lend the loan token, supplyCollateral / withdrawCollateral post and take collateral, borrow / repay take and return the loan token against it.

Written from the protocol's own interfaces (morpho-blue, metamorpho, vault-v2) with the same shares and interest maths as Morpho Blue's SharesMathLib / MathLib / Morpho._accrueInterest; one dependency (viem). The Morpho GraphQL API is used only for discovery and decoration (listing, APY, TVL); every money path reads the chain.

Chains

Ethereum, Base, Arbitrum, OP Mainnet, Polygon, Unichain, HyperEVM, Katana, Monad, Robinhood Chain (MORPHO_CHAINS). The Morpho (Blue) addresses come from docs.morpho.org; the vault factories are the ones behind every vault the Morpho API lists (the docs carry no factory table). Other chains take morpho in the config.

Usage

import WalletManagerEvm from '@anywalletkit/wallet-evm'
import { MorphoVaultProtocolEvm, MorphoMarketProtocolEvm, MorphoApi } from '@anywalletkit/protocol-lending-morpho-evm'

const account = await new WalletManagerEvm(seed, { provider: 'https://base-rpc…' }).getAccount(0)

// Discovery (API): the listed USDC vaults on Base, biggest first
const api = new MorphoApi()
const [best] = await api.listVaults({ chainId: 8453, asset: USDC })

// Vault
const vault = new MorphoVaultProtocolEvm(account, { vault: best.address })
await vault.getVault()                          // verified against Morpho's factories; asset, fees, timelock…
await vault.getApy()                            // 4.1 (net, percent, from the API)
await vault.supply({ amount: 5_000_000n })      // exact approve → deposit(assets, me)
await vault.getPosition()                       // { shares, assets, withdrawable }
await vault.withdraw({ amount: 'max' })         // redeem(every share) — refused up front if the vault lacks liquidity

// Market (Blue)
const market = new MorphoMarketProtocolEvm(account, { market: '0x9103…1836' })   // id or MarketParams
const m = await market.getMarket()              // loan/collateral tokens, LLTV, price, state accrued to now, APYs, liquidity
await market.supplyCollateral({ amount: 10n ** 7n })        // 0.1 cbBTC
await market.borrow({ amount: 3_000_000_000n })            // 3 000 USDC — refused if above LLTV or market liquidity
await market.getPosition()                      // debt (rounded up), collateral value, health factor, liquidation price
await market.repay({ amount: 'max' })           // by shares, no dust; allowance = debt + 0.1 %
await market.withdrawCollateral({ amount: 'max' })

Safety before money moves

  • Vault identity. getVault() asks the chain's Morpho vault factories (isMetaMorpho / isVaultV2) whether they created the address, and a V1 vault's MORPHO() must be the chain's singleton. An unknown address is refused unless allowUnverifiedVault: true.

  • Vault limits. V1: deposits are checked against maxDeposit (caps), withdrawals against maxWithdraw / maxRedeem (vault liquidity) — the error says how much is possible right now. V2 answers 0 from every max* view, so its transfer gates are read (canReceiveShares / canSendAssets in, canSendShares / canReceiveAssets out) and caps and liquidity are left to the eth_call proof that runs before every send.

  • Dead deposit. Before a vault deposit or a market supply, the target must hold a dead deposit at 0x…dEaD, the rule Morpho's own SDK applies (morpho-sdk 9.2.0): at least MIN_DEAD_SHARES (1e9) shares (Blue supply shares for a market, vault shares for a vault); a Vault V2's must also be worth MIN_VAULT_V2_DEAD_ASSETS (1e6 base units), with its share price above 1 / (10 × virtualShares). Without one, a nearly empty target's share price can be inflated against the next depositor. A target that fails is refused with MorphoDeadDepositError (code: 'InsufficientDeadDeposit', observed, required) unless the config passes allowWithoutDeadDeposit: true. getDeadDeposit() reads it without supplying. Withdrawals, collateral, borrows and repayments are never gated by it.

    Only the target itself is checked. Morpho's SDK also walks the markets a vault can allocate to (every withdraw-queue market of a Vault V1, every capped allocation and the liquidity market of a Vault V2). This module does not, for two reasons. First, the target check guards the deposit itself: the depositor's assets rounding down in the target's own share math. A market the vault allocates to affects the vault's assets, which the curator chooses, caps bound and every holder shares; that is curation risk, which this module does not try to judge. Second, the walk refuses most listed vaults: on 2026-11-04 it would have refused 45 of 69 listed Vault V1s, mostly because of the idle markets (no collateral) curators keep in their queues.

  • Listing vs depositing. MorphoApi.listVaults returns what the API lists, Vault V1 and V2 alike. The API has no dead-deposit field, so a listed vault that fails the rule stays in the list, just like a vault whose caps are full or whose V2 gates refuse the account. Depositability is decided on-chain by the vault protocol: getDeadDeposit() shows the rule, and quoteSupply / supply refuse a failing dead deposit (MorphoDeadDepositError), full V1 caps (ExceededMaxDeposit) and V2 gates (CannotReceiveShares, CannotSendAssets) with a typed error before anything is approved. Call quoteSupply (or getDeadDeposit) before offering a deposit.

  • Market identity. An id is resolved with idToMarketParams, and the RPC's answer must hash back to the id or it is refused; params given in config are hashed to the id and the market must exist (lastUpdate ≠ 0). The golden test derives the live Base cbBTC/USDC id from its params.

  • Market state. market() is accrued to now exactly as accrueInterest would (Taylor-compounded borrow rate from the IRM, fee shares), so supplied / borrowed assets, health and liquidity are current, not last-touch.

  • Health. Borrows and collateral withdrawals are checked against collateral × price / 1e36 × LLTV; liquidity against supply − borrow. onBehalfOf borrows need isAuthorized.

  • Proof. Every main transaction is eth_called from the account; Morpho's revert strings (insufficient liquidity, insufficient collateral, …) and the vaults' custom errors (AllCapsReached, ERC4626ExceededMaxWithdraw, V2 CannotReceiveShares, …) become readable MorphoErrors.

  • Approvals are exact (never unlimited), with the approve(0) reset Ethereum's USDT demands. Morpho has no native-coin path: wrap first.

Reads

returns
vault.getVault()version, factory, name, asset, totalAssets, share price, fees, timelock, curator
vault.getPosition()shares, assets, withdrawable now
vault.getApy(), vault.getStats()net APY %, API record
vault.getDeadDeposit(), market.getDeadDeposit()shares (and V2 assets) at 0x…dEaD, whether the dead-deposit rule passes and what failed
market.getMarket()params, tokens, LLTV, oracle price (1e36), accrued state, liquidity, utilization, borrow/supply APY
market.getPosition(user?)supply/borrow shares and assets, collateral, collateral value, max borrow, health factor, LTV, liquidation price
MorphoApi.listVaults / listMarkets / vault / marketByIddiscovery, biggest first, listed: true (V1 and V2; listed is not depositable, see above)

Tests

pnpm test — 27 offline tests over an in-memory Morpho on Base (Blue singleton with the real cbBTC/USDC market params, IRM, oracle, a MetaMorpho vault behind the v1.0 factory, a look-alike vault, Multicall3, reverts) plus the conformance suite for both protocols. pnpm verify:live reads Base through a public RPC and the API.

Status

2026-10-10: built, offline tests green, live read-only verification on Base. No funded transaction through the module yet (plan: 5 USDC into a Base vault, withdraw).

Activity

describeActivity(tx, { own }) labels Morpho transactions for a wallet's history, offline and synchronously (shared by both classes through MorphoBase):

  • Blue is recognized by address: the called contract is the Morpho singleton of the transaction's chain (MORPHO_CHAINS, or the morpho this instance was configured with) and the selector is supply / withdraw / borrow / repay / supplyCollateral / withdrawCollateral (→ supply / withdraw / borrow / repay) or setAuthorization (→ contract). The principal asset is MarketParams.loanToken from calldata when present.
  • Vaults (MetaMorpho / Vault V1, Vault V2) cannot be listed offline — they come from factories and the isMetaMorpho / isVaultV2 proof needs a node — so the rule is: the selector is an ERC-4626 entry point (deposit / mint → supply, withdraw / redeem → withdraw) and the called contract is itself the share token the receipt shows minted to (deposit) or burned from (withdraw) one of the wallet's addresses, on a chain with a Morpho deployment. The vault a MorphoVaultProtocolEvm instance is configured with is accepted by address alone. Caveat: any ERC-4626 vault on a Morpho chain satisfies the generic rule; the kit asks modules in registry order, so a module that knows a specific vault should be registered before this one.
  • Title "<Verb> <asset>" ("Deposited USDC", "Withdrew USDC"; the share token is never the principal), subtitle "Morpho · <chain>" / "Morpho Vault · <chain>", counterparty the contract called, protocol the package name; assetsIn / assetsOut are the wallet's net movements (shares included).
  • Null otherwise.

Fixtures in fixtures/activity/ are public Base transactions (a Moonwell Flagship USDC vault deposit / redeem by one account, a Blue supply / withdraw by another; the test wallet has not run Morpho yet), negatives/ an Aave gateway deposit and a plain USDC transfer.

版本与发布记录

@anywalletkit/protocol-lending-morpho-evm 共发布 13 个版本,首次发布于 2026/10/25;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/11/052 天前
0.3.12026/11/035 天前
0.3.02026/10/309 天前
0.2.102026/10/2910 天前
0.2.92026/10/2811 天前
0.2.82026/10/2712 天前

关于 @anywalletkit/protocol-lending-morpho-evm 的常见问题

@anywalletkit/protocol-lending-morpho-evm 是什么?

Morpho for @anywalletkit/wallet-evm accounts: Morpho Vaults (MetaMorpho V1 and Vault V2, ERC-4626 deposit / redeem) and Morpho Blue markets (supply, withdraw, borrow, repay, collateral) as LendingProtocols, on 10 chains. Vaults are verified against Morpho

如何安装 @anywalletkit/protocol-lending-morpho-evm?

在项目目录运行 npm install @anywalletkit/protocol-lending-morpho-evm,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@anywalletkit/core(0.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@anywalletkit/protocol-lending-morpho-evm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anywalletkit/protocol-lending-morpho-evm 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@anywalletkit/protocol-lending-morpho-evm 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anywalletkit/protocol-lending-morpho-evm 可以商用吗?

@anywalletkit/protocol-lending-morpho-evm 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@anywalletkit/protocol-lending-morpho-evm 的下载量有多少?

根据 npm 官方下载统计,@anywalletkit/protocol-lending-morpho-evm 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,114 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anywalletkit/protocol-lending-morpho-evm 还在维护吗?

最新版本 0.4.0 发布于 2026/11/05(2 天前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/10/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。