Skip to content

Commit e29dfc1

Browse files
committed
feat(morpho-sdk): add midnight action flows
1 parent 1870b00 commit e29dfc1

19 files changed

Lines changed: 2491 additions & 27 deletions

File tree

.changeset/quiet-midnight-flows.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@morpho-org/morpho-sdk": minor
3+
---
4+
5+
Add Midnight action flows under `client.morpho.midnight(chainId)` and expose pure Midnight transaction builders for fixed-rate taker, maker, redeem, repay/withdraw, and cancel flows.
6+
7+
The Midnight entity returns lazy action outputs with `getRequirements()` and synchronous `buildTx(...)` methods, matching the existing `morpho-sdk` action pattern while accepting fixed-rate API quote takes directly. UI labels, rate display logic, and offer-chain presentation stay on the integrator side.

packages/morpho-sdk/AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# `packages/morpho-sdk/`
22

3-
Transaction builders for VaultV1, VaultV2, and Blue. Subfolders carry the layer-scoped detail; this file is the package overview + glossary.
3+
Transaction builders for VaultV1, VaultV2, Blue, and Midnight. Subfolders carry the layer-scoped detail; this file is the package overview + glossary.
44

55
> Architecture / type / test / doc / release rules apply per the [root `AGENTS.md`](../../AGENTS.md). Subfolder rules: see each `src/<layer>/AGENTS.md`.
66
77
## Routing summary
88

99
- **VaultV1 / VaultV2 deposits** route through bundler3 via GeneralAdapter1 (which enforces `maxSharePrice`, protecting against inflation attacks). VaultV1/V2 `withdraw` and `redeem` are direct vault calls. VaultV2 `forceWithdraw` / `forceRedeem` use `multicall` with `forceDeallocate` calls before the final withdraw/redeem.
1010
- **Blue bundled paths** (`supply`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `repayWithdrawCollateral`, `withdraw`) route through bundler3 via GeneralAdapter1. `repay` and `withdraw` each accept assets or shares (mutually exclusive); `repayWithdrawCollateral` repays first then withdraws. Loan-asset `supply` supports native wrapping when `loanToken === wNative`; loan-asset `withdraw` supports optional PublicAllocator reallocations to top up market liquidity (same mechanism as `borrow`).
11+
- **Midnight paths** expose lazy action outputs under `client.morpho.midnight(chainId)`. Fixed-rate market taker flows route through Midnight Bundles, direct collateral supply/cancel/redeem route through Midnight, and maker flows return root-ratification requirements plus the mempool payload transaction. The SDK owns protocol transactions and requirements; integrators keep UI labels, rate math, and display decisions.
1112
- **Bundle composition, native wrapping, and reallocation rules** are canonical in [`src/actions/AGENTS.md`](./src/actions/AGENTS.md).
1213

1314
## Tests
@@ -21,6 +22,7 @@ Protocol terms used across this package's docs and JSDoc:
2122
### Contracts and adapters
2223

2324
- **Blue / Morpho Blue** — Morpho's immutable, **variable-rate** lending primitive (formerly called "MarketV1" in this SDK). Each market is an isolated pair whose borrow rate floats with utilization, driven by the market's IRM. A market is identified by `MarketParams { loanToken, collateralToken, oracle, irm, lltv }`. Exposed via `client.blue(marketParams, chainId) → MorphoBlue`. This is the canonical definition of "Blue" for the whole package; other docs link here rather than redefine it.
25+
- **Midnight** — Morpho's fixed-rate lending primitive. Takers consume signed offers through Midnight Bundles; makers submit offer groups/trees to the Midnight mempool after Ecrecover signing or Setter ratification.
2426
- **VaultV1 / MetaMorpho** — ERC-4626 vault layered on top of Blue.
2527
- **VaultV2** — successor vault with adapter-based liquidity routing and `forceDeallocate`.
2628
- **bundler3** — the bundler entry point; receives a sequence of adapter actions in one transaction.

packages/morpho-sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"dependencies": {
9494
"@morpho-org/blue-sdk": "workspace:^",
9595
"@morpho-org/blue-sdk-viem": "workspace:^",
96+
"@morpho-org/midnight-sdk": "workspace:^",
9697
"@morpho-org/morpho-ts": "workspace:^",
9798
"zod": "^4.4.3"
9899
},

packages/morpho-sdk/src/actions/AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Pure synchronous transaction builders. Each action returns a deep-frozen `Transa
77
- `vaultV1/` — VaultV1 (MetaMorpho) `deposit` / `withdraw` / `redeem` / `migrateToV2`.
88
- `vaultV2/` — VaultV2 `deposit` / `withdraw` / `redeem` / `forceWithdraw` / `forceRedeem`.
99
- `blue/` — Morpho Blue `supplyCollateral` / `borrow` / `supplyCollateralBorrow` / `repay` / `repayWithdrawCollateral` / `withdrawCollateral`. Borrow paths support optional shared liquidity via `reallocations`.
10+
- `midnight/` — Midnight fixed-rate direct and bundled transaction encoders plus take normalization for fixed-rate API quote outputs.
1011
- `requirements/` — token approvals, permit/permit2 signatures, Morpho authorization resolved before deposit/supply.
12+
Midnight also uses this layer for Midnight authorization and Setter root-ratification prerequisites.
1113

1214
## Common builder pattern
1315

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export type { BlueActions } from "../entities/blue/index.js";
2+
export type { MidnightActions } from "../entities/midnight/index.js";
23
export type { VaultV1Actions } from "../entities/vaultV1/index.js";
34
export type { VaultV2Actions } from "../entities/vaultV2/index.js";
45
export * from "./blue/index.js";
6+
export * from "./midnight/index.js";
57
export * from "./requirements/index.js";
68
export * from "./vaultV1/index.js";
79
export * from "./vaultV2/index.js";

0 commit comments

Comments
 (0)