Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a5eb7ad
docs: add midnight action output TIB
Rubilmax Jun 25, 2026
0b51120
docs: clarify midnight action flow implementation
Rubilmax Jun 25, 2026
579d559
docs: explain midnight action flow compatibility
Rubilmax Jun 25, 2026
b98e38b
docs: address midnight action review feedback
Rubilmax Jun 25, 2026
288f4fc
docs: split midnight permit2 transfer requirements
Rubilmax Jun 25, 2026
b57fec7
docs: align midnight permit2 source reference
Rubilmax Jun 25, 2026
6770a69
docs: address midnight action review comments
Rubilmax Jun 25, 2026
807615a
docs(tib): rename midnight lend and borrow flows
Rubilmax Jun 25, 2026
fa6475f
docs(tib): align fixed-rate diffs with app validation
Rubilmax Jun 26, 2026
386661c
docs(tib): rename fixed-rate app to markets app
Rubilmax Jun 26, 2026
9e633df
docs: pair token signature requirement aliases
Rubilmax Jun 29, 2026
1f44f35
docs: clarify blue token signature aliases
Rubilmax Jun 29, 2026
c0b76cd
docs: use midnight face value for redeem
Rubilmax Jun 29, 2026
c480902
docs: clarify midnight group ids
Rubilmax Jun 29, 2026
f420eef
docs: require throwing tree mempool validation
Rubilmax Jun 29, 2026
021ccae
docs: clarify midnight validation error ownership
Rubilmax Jun 29, 2026
297d8cb
docs: preserve dai permit exception for midnight
Rubilmax Jun 29, 2026
f576017
docs: simplify markets app midnight migration
Rubilmax Jun 29, 2026
d26283f
docs: rename midnight borrow flows
Rubilmax Jun 29, 2026
e5201fb
docs: route dai permits through permit2
Rubilmax Jun 29, 2026
c0999a6
docs: align midnight action flow TIB
Rubilmax Jun 30, 2026
fa30547
docs(tibs): document midnight offer rate helpers
Rubilmax Jul 1, 2026
a29dded
docs: simplify midnight action output TIB examples
Rubilmax Jul 2, 2026
581bb5c
docs: address midnight bundles tib feedback
Rubilmax Jul 2, 2026
03d5f51
docs: update midnight bundles source reference
Rubilmax Jul 2, 2026
6d456f4
docs: address midnight action TIB review comments
Rubilmax Jul 6, 2026
c70656f
docs: clarify midnight maker reserve accounting
Rubilmax Jul 6, 2026
377032c
docs: rename midnight mempool submit action
Rubilmax Jul 7, 2026
88e4986
docs: clarify midnight redeem unit cap
Rubilmax Jul 7, 2026
005a13b
docs: clarify midnight offer tree signing
Rubilmax Jul 8, 2026
2effc1f
docs(tib): scope midnight actions to app migration
Rubilmax Jul 8, 2026
da3d2df
feat(morpho-sdk): add midnight action flows
Rubilmax Jun 29, 2026
bf9ca43
refactor(morpho-sdk): rename midnight takes to takeable offers
Rubilmax Jun 30, 2026
dc26113
refactor(morpho-sdk): finalize midnight action flows
Rubilmax Jun 30, 2026
5d9524b
docs(morpho-sdk): document midnight action flows
Rubilmax Jun 30, 2026
7a0b0b6
feat(morpho-sdk): add midnight prerequisites
Rubilmax Jun 30, 2026
9281614
refactor(morpho-sdk): rename midnight bundles requirements
Rubilmax Jul 1, 2026
fbb2aaf
fix(morpho-sdk): align midnight token permit errors
Rubilmax Jul 2, 2026
8a6260a
fix: align midnight bundles actions with v1 abi
Rubilmax Jul 2, 2026
4e9d221
fix(morpho-sdk): support midnight approval spenders
Rubilmax Jul 3, 2026
7e649ed
fix(morpho-sdk): pass account to midnight ratify
Rubilmax Jul 3, 2026
e9f730a
feat(morpho-sdk): refine Midnight action requirements
Rubilmax Jul 3, 2026
931c904
fix(morpho-sdk): factorize requirement helpers
Rubilmax Jul 6, 2026
dfc5be3
refactor(morpho-sdk): expose requirement helpers
Rubilmax Jul 6, 2026
a2b033d
refactor(morpho-sdk): rename setter ratifier action
Rubilmax Jul 6, 2026
fa47131
fix(morpho-sdk): validate midnight collateral withdrawals
Rubilmax Jul 6, 2026
4d1521c
fix(morpho-sdk): use shared midnight collateral lookup
Rubilmax Jul 6, 2026
3889193
fix(morpho-sdk): align midnight maker action flows
Rubilmax Jul 6, 2026
1eeac1f
fix(morpho-sdk): require midnight action deadlines
Rubilmax Jul 7, 2026
7e3c9ef
refactor(morpho-sdk): rename mempool submit offers action
Rubilmax Jul 7, 2026
e48c3c3
refactor(morpho-sdk): align midnight entity type layout
Rubilmax Jul 7, 2026
39654e0
fix(morpho-sdk): pin midnight position fetch block
Rubilmax Jul 7, 2026
05d7b2d
fix(morpho-sdk): add metadata to midnight mempool submissions
Rubilmax Jul 7, 2026
f599ba9
fix(morpho-sdk): cap midnight redeem units by credit
Rubilmax Jul 7, 2026
29b51fd
test(morpho-sdk): verify midnight offer tree signing
Rubilmax Jul 8, 2026
5734466
feat(midnight-sdk): add fixed rate offer chains
Rubilmax Jul 8, 2026
97aa97f
refactor(morpho-sdk): scope midnight flows to app usage
Rubilmax Jul 8, 2026
7b6d197
feat(morpho-sdk): add extended midnight bundle options
Rubilmax Jul 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fixed-rate-offer-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@morpho-org/midnight-sdk": minor
---

Add `OfferChainUtils.buildFixedRateOfferChain` and `getMaxFixedRateOfferChainEndTimestamp` so the markets app can build adjacent, grouped offers that keep a maker's displayed fixed rate stable across a long selected window.
15 changes: 15 additions & 0 deletions .changeset/quiet-midnight-flows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@morpho-org/morpho-sdk": minor
---

Add Midnight action flows under `client.morpho.midnight(chainId)`, expose Midnight SDK API helpers through `morpho-sdk/midnight-api` and shared ABI/constant/error/utility entrypoints, and expose pure Midnight transaction builders for fixed-rate taker, maker, redeem, repay/withdraw, and cancel flows.

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 takeable offers directly. UI labels, rate display logic, and offer-chain presentation stay on the integrator side.

Midnight market transaction builders are synchronous and consume caller-provided `marketData` state, with `redeem` also consuming caller-provided `positionData`. Maker-offer action builders consume caller-provided `offersData` from `getOffersData(...)`, which creates the tree from the same entries accepted by `Tree.create(...)` and runs mempool validation. `getMarketData(...)`, block-accrued `getPositionData(...)`, and `getOffersData(...)` remain async helpers so integrators can prepare state once, compose UI/validation around it, and then build transactions without hidden reads.

Midnight Bundles calls support ERC2612 and Permit2 token permits through the same `supportSignature` / `useSimplePermit` requirement flow as Blue, while preserving `PermitKind.None` for approval-based execution.

Borrow-side flows are explicit: `takeBorrow` and `makeBorrow` borrow without supplying collateral, while `supplyCollateralTakeBorrow` and `supplyCollateralMakeBorrow` perform collateral-supply plus borrow flows. Public maker flows are exposed through named synchronous actions such as `makeLend`, `makeBorrow`, and `supplyCollateralMakeBorrow`; they accept precomputed `offersData` prepared from one or more standalone offers or groups. Maker submit metadata exposes all submitted group ids, and the ratifier helpers enforce that the submitted tree uses one ratifier.

Named take transaction builders validate that their takeable offers match the expected maker side, and named maker entity flows validate that prepared maker trees match the expected maker side. `getOffersData(...)` stays side-agnostic so callers can prepare any valid tree.
4 changes: 4 additions & 0 deletions docs/tibs/TIB-2026-05-20-midnight-sdk-utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ Expose deterministic library methods:
- `TickLib.snapPriceToTick`
- `TickLib.rateToPrice`
- `TickLib.tickToRate`
- `TickLib.tickToApr`
- `TakeAmountsLib.buyerAssetsToUnits`
- `TakeAmountsLib.sellerAssetsToUnits`
- `TakeAmountsLib.toUnits` for SDK-only generic unit conversion convenience
Expand All @@ -412,6 +413,9 @@ SDK-only derived helpers should live beside the domain they describe:
- `MarketUtils.getLiquidationIncentiveFactor` with an explicit liquidation cursor
- `MarketUtils.getSettlementFee`
- `PositionUtils.accrueInterest`
- `OfferUtils.getPrice`
- `OfferUtils.getRate`
- `OfferUtils.getApr`
- `OfferUtils.getOfferExpiry`

The pure helpers that mirror `TakeAmountsLib` should accept `settlementFee` as an explicit input instead of reading the chain. Fetching settlement fee remains a boundary concern; fetch helpers that compute it should accept `timeToMaturity` directly so callers do not confuse wall-clock time with Solidity's `block.timestamp`.
Expand Down
952 changes: 952 additions & 0 deletions docs/tibs/TIB-2026-06-03-midnight-action-output-interface.md

Large diffs are not rendered by default.

106 changes: 84 additions & 22 deletions packages/midnight-sdk/src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2717,9 +2717,9 @@ export const midnightAbi = [
/**
* ABI JSON for the Midnight Bundles periphery used by app-compatible taker and repay flows.
*
* Source: `morpho-org/morpho-apps` commit `4e903d545184a1f46b378c5c0c4ad414575a5b94`,
* `packages/contracts/solidity/interfaces/IMidnightBundles.sol`, adapted to the current
* Midnight `Market` and `Offer` struct fields exported by this package.
* Source: `morpho-org/bundles` commit `4c71ac5ee7254b2a448b6054e003bd81e171d86e`,
* `src/midnight/IMidnightBundlesV1.sol`, adapted to the current Midnight `Market`
* and `Offer` struct fields exported by this package.
*
* @example
* ```ts
Expand All @@ -2729,19 +2729,6 @@ export const midnightAbi = [
* ```
*/
export const midnightBundlesAbi = [
{
type: "function",
name: "PERMIT2",
inputs: [],
outputs: [
{
name: "",
type: "address",
internalType: "address",
},
],
stateMutability: "view",
},
{
type: "function",
name: "MIDNIGHT",
Expand All @@ -2757,7 +2744,7 @@ export const midnightBundlesAbi = [
},
{
type: "function",
name: "buyWithUnitsTargetAndWithdrawCollateral",
name: "midnightBundlesV1BuyWithUnitsTargetAndWithdrawCollateral",
inputs: [
{
name: "targetUnits",
Expand All @@ -2774,6 +2761,11 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "reduceOnly",
type: "bool",
internalType: "bool",
},
{
name: "loanTokenPermit",
type: "tuple",
Expand Down Expand Up @@ -2807,13 +2799,23 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "maxContinuousFee",
type: "uint256",
internalType: "uint256",
},
{
name: "deadline",
type: "uint256",
internalType: "uint256",
},
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "supplyCollateralAndSellWithUnitsTarget",
name: "midnightBundlesV1SupplyCollateralAndSellWithUnitsTarget",
inputs: [
{
name: "targetUnits",
Expand All @@ -2830,6 +2832,11 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "reduceOnly",
type: "bool",
internalType: "bool",
},
{
name: "receiver",
type: "address",
Expand Down Expand Up @@ -2857,13 +2864,23 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "maxContinuousFee",
type: "uint256",
internalType: "uint256",
},
{
name: "deadline",
type: "uint256",
internalType: "uint256",
},
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "buyWithAssetsTargetAndWithdrawCollateral",
name: "midnightBundlesV1BuyWithAssetsTargetAndWithdrawCollateral",
inputs: [
{
name: "targetBuyerAssets",
Expand All @@ -2880,6 +2897,11 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "reduceOnly",
type: "bool",
internalType: "bool",
},
{
name: "loanTokenPermit",
type: "tuple",
Expand Down Expand Up @@ -2913,13 +2935,23 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "maxContinuousFee",
type: "uint256",
internalType: "uint256",
},
{
name: "deadline",
type: "uint256",
internalType: "uint256",
},
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "supplyCollateralAndSellWithAssetsTarget",
name: "midnightBundlesV1SupplyCollateralAndSellWithAssetsTarget",
inputs: [
{
name: "targetSellerAssets",
Expand All @@ -2936,6 +2968,11 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "reduceOnly",
type: "bool",
internalType: "bool",
},
{
name: "receiver",
type: "address",
Expand Down Expand Up @@ -2963,13 +3000,23 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "maxContinuousFee",
type: "uint256",
internalType: "uint256",
},
{
name: "deadline",
type: "uint256",
internalType: "uint256",
},
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "repayAndWithdrawCollateral",
name: "midnightBundlesV1RepayAndWithdrawCollateral",
inputs: [
{
name: "market",
Expand Down Expand Up @@ -3014,13 +3061,23 @@ export const midnightBundlesAbi = [
type: "address",
internalType: "address",
},
{
name: "deadline",
type: "uint256",
internalType: "uint256",
},
],
outputs: [],
stateMutability: "nonpayable",
},
{
type: "error",
name: "ApproveReturnedFalse",
name: "ContinuousFeeAboveMax",
inputs: [],
},
{
type: "error",
name: "DeadlinePassed",
inputs: [],
},
{
Expand All @@ -3043,6 +3100,11 @@ export const midnightBundlesAbi = [
name: "PctExceeded",
inputs: [],
},
{
type: "error",
name: "NotReduceOnly",
inputs: [],
},
{
type: "error",
name: "SellerAssetsTooLow",
Expand Down
Loading