Skip to content

Prepare SDK prerequisites for Midnight action flows#829

Merged
Rubilmax merged 10 commits into
mainfrom
hermes/midnight-action-flow-prerequisites
Jul 3, 2026
Merged

Prepare SDK prerequisites for Midnight action flows#829
Rubilmax merged 10 commits into
mainfrom
hermes/midnight-action-flow-prerequisites

Conversation

@Rubilmax

Copy link
Copy Markdown
Contributor

Summary

This PR isolates the prerequisite SDK/package work that should sit between the Midnight action-flow TIB and the concrete morpho-sdk action-flow implementation.

It includes:

  • midnight-sdk API/error/tree-validation updates needed by the action flows
  • blue/existing morpho-sdk requirement-helper refactors and shared signature/action types
  • morpho-sdk re-export paths for midnight-sdk surfaces such as midnight-api
  • shared address/WDK updates and focused tests for the prerequisite helpers

It intentionally does not add the MorphoMidnight entity or the actions/midnight transaction builders; those remain in the implementation PR stacked on top.

Validation

  • pnpm --filter @morpho-org/morpho-sdk build
  • pnpm --filter @morpho-org/midnight-sdk build
  • pnpm --filter @morpho-org/midnight-sdk test -- src/signatures/TreeUtils.test.ts
  • pnpm --filter @morpho-org/morpho-sdk test -- src/actions/requirements was attempted, but fork-backed suites require MAINNET_RPC_URL; 327 tests passed before env-gated suites failed during setup.

@Rubilmax

Copy link
Copy Markdown
Contributor Author

@codex

@Rubilmax Rubilmax self-assigned this Jun 30, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 75aa4f00fb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/midnight-sdk/src/signatures/TreeUtils.ts Outdated
Comment thread .changeset/add-midnight-sdk.md
@yum0e

yum0e commented Jun 30, 2026

Copy link
Copy Markdown

One broader issue I could not attach to a diff line: the current ConsumableUnitsLib path seems to undercount asset-capped buy offers. Onchain checks buyerAssets = floor(units * buyerPrice / WAD) <= remainingAssets, so the max-safe inverse should be floor(((remainingAssets + 1n) * WAD - 1n) / buyerPrice).

Example: at price 0.5 WAD and remainingAssets = 1, onchain accepts 3 units (floor(3 * 0.5) = 1), but the helper path returns 2. This can make routers leave usable liquidity unrouted.

@Rubilmax Rubilmax force-pushed the hermes/tib-midnight-action-output-interface branch from b33e9e1 to 16a2721 Compare June 30, 2026 12:53
@Rubilmax Rubilmax force-pushed the hermes/midnight-action-flow-prerequisites branch from 75aa4f0 to 5d98ef3 Compare June 30, 2026 12:54
Comment thread .changeset/blue-requirements-helpers.md Outdated

@Foulks-Plb Foulks-Plb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parallel PR Review (Claude)

Reviewed commit: 6fd6eea2

9 personas ran (8 baseline + ci-release-security); 0 failed. The core change — Blue/Midnight requirement-helper split, the widened Requirement/RequirementSignature generics, the new Midnight requirement resolvers, ABI arg ordering, Permit2 SignatureTransfer + DAI routing, changeset/lockfile/packaging — was reviewed by the code-quality, module-api, morpho-protocol, web3-security, silent-failure, style-conventions and ci-release personas and came back clean. Findings are concentrated in docs/JSDoc and test coverage of the new Midnight surface.

Severity Count
Critical 0
High 0
Medium 7
Low 2

Out-of-scope note (not posted inline)

packages/morpho-sdk/BUNDLER3.md is not in this PR's diff, so it was dropped by the scope filter — but the renames in this PR leave dangling links/symbols there: it still points at src/actions/requirements/getRequirements.ts (lines 21, 73) and getMorphoAuthorizationRequirement.ts (lines 101, 111), both moved to blue/getBlueRequirements.ts / blue/getBlueAuthorizationRequirement.ts. Worth a follow-up.

Note on the AGENTS.md findings

Several AGENTS.md edits document Midnight symbols/folders that don't exist yet in this stacked PR (MorphoMidnight/MidnightActions, client.morpho.midnight(...), an actions/midnight/ folder). If these are intentional forward-references for the rest of the stack, consider deferring them to the PR that lands the code so the agent-facing docs never describe absent surface.

This is an automated parallel review posted as a comment — it does not approve or request changes. A human decides.

Comment thread packages/midnight-sdk/src/offers/Offer.ts Outdated
Comment thread packages/midnight-sdk/src/offers/OfferUtils.ts Outdated
Comment thread packages/morpho-sdk/AGENTS.md Outdated
Comment thread packages/morpho-sdk/src/actions/AGENTS.md Outdated
Comment thread packages/morpho-sdk/src/entities/AGENTS.md Outdated
Comment thread packages/midnight-sdk/src/offers/Offer.ts

@Rubilmax Rubilmax left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Rubilmax Rubilmax force-pushed the hermes/midnight-action-flow-prerequisites branch from 34a0273 to 8478fd9 Compare July 1, 2026 08:02
@Rubilmax Rubilmax changed the base branch from hermes/tib-midnight-action-output-interface to main July 1, 2026 08:02
@Rubilmax Rubilmax marked this pull request as ready for review July 1, 2026 08:53
@Rubilmax Rubilmax requested a review from a team as a code owner July 1, 2026 08:53
@Rubilmax Rubilmax requested review from Foulks-Plb, Copilot and yum0e and removed request for yum0e July 1, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prepares prerequisite SDK changes to support upcoming Morpho Midnight action flows by reshaping Morpho Blue “requirements” helpers/types, and extending midnight-sdk tree validation and offer/market utilities.

Changes:

  • Renames and restructures Morpho SDK requirement helpers/types (Blue-specific requirements + Bundler3 permit helpers), including authorization action discriminator changes.
  • Updates Morpho SDK entities/actions/tests and WDK adapter code to consume the new Blue authorization/requirements surfaces.
  • Enhances midnight-sdk mempool tree validation to optionally validate ratified payload bytes, and adds/relocates offer math & consumable-units helpers (removing older fetch/math surfaces).

Reviewed changes

Copilot reviewed 68 out of 69 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pnpm-lock.yaml Locks viem bump to 2.53.1.
packages/wdk-protocol-lending-morpho-evm/src/morpho-protocol-evm.ts Updates requirement authorization action typing to BlueAuthorizationAction.
packages/wdk-protocol-lending-morpho-evm/src/morpho-protocol-evm.test.ts Adjusts mocked requirement action discriminator to blueAuthorization.
packages/morpho-sdk/test/actions/blue/withdraw.test.ts Uses isRequirementBlueAuthorization guard.
packages/morpho-sdk/test/actions/blue/supplyCollateralBorrow.test.ts Uses blueAuthorization discriminator + isRequirementBlueAuthorization.
packages/morpho-sdk/test/actions/blue/repayWithdrawCollateral.test.ts Uses isRequirementBlueAuthorization in requirement execution loop.
packages/morpho-sdk/test/actions/blue/refinance.test.ts Uses isRequirementBlueAuthorization for auth-only requirement sets.
packages/morpho-sdk/test/actions/blue/reallocations.test.ts Uses isRequirementBlueAuthorization; updates one test name for clarity.
packages/morpho-sdk/test/actions/blue/borrow.test.ts Uses isRequirementBlueAuthorization.
packages/morpho-sdk/test/actions/blue/authorization.test.ts Updates expectations to blueAuthorization discriminator and new guard.
packages/morpho-sdk/src/utils.ts Removes getDaiPermitTypedData re-export from utils barrel.
packages/morpho-sdk/src/types/error.ts Adds deposit/signature mismatch errors for owner/spender.
packages/morpho-sdk/src/types/AGENTS.md Updates docs to BlueAuthorizationAction and prerequisites wording.
packages/morpho-sdk/src/types/action.ts Renames MorphoAuthorizationActionBlueAuthorizationAction; generifies Requirement/RequirementSignature; introduces isRequirementBlueAuthorization.
packages/morpho-sdk/src/helpers/validate.ts Updates doc references for signature requirement paths.
packages/morpho-sdk/src/entities/vaultV2/vaultV2.ts Switches to getBlueRequirements for vault requirement resolution.
packages/morpho-sdk/src/entities/vaultV1/vaultV1.ts Switches to getBlueRequirements for vault requirement resolution.
packages/morpho-sdk/src/entities/blue/blue.ts Migrates Blue entity requirements/authorization helpers to Blue-prefixed APIs/types and adds useSimplePermit docstrings.
packages/morpho-sdk/src/entities/blue/blue.test.ts Updates test titles to “Blue authorization”.
packages/morpho-sdk/src/entities/AGENTS.md Updates signature-requirement doc references (encodeBundler3Erc20Permit2).
packages/morpho-sdk/src/actions/vaultV2/deposit.test.ts Uses getBlueRequirements in unit tests.
packages/morpho-sdk/src/actions/vaultV1/migrateToV2.test.ts Uses getBlueRequirements in unit tests.
packages/morpho-sdk/src/actions/vaultV1/deposit.test.ts Uses getBlueRequirements in unit tests.
packages/morpho-sdk/src/actions/requirements/index.ts Re-exports new blue/ and bundler3/ requirement modules; removes old entrypoints.
packages/morpho-sdk/src/actions/requirements/getRequirementsAction.ts Updates inline docs to avoid old helper naming.
packages/morpho-sdk/src/actions/requirements/encode/index.ts Exports encodeBundler3Erc20Permit2 and removes old permit2 encoder export.
packages/morpho-sdk/src/actions/requirements/encode/encodeErc20Permit.ts Tightens return type generics and clarifies doc about standard ERC-2612 tokens.
packages/morpho-sdk/src/actions/requirements/encode/encodeErc20Permit.test.ts Removes DAI permit signing test from standard ERC-2612 encoder suite.
packages/morpho-sdk/src/actions/requirements/encode/encodeErc20Approval.ts Updates docs to reference Bundler3 permit2 helper.
packages/morpho-sdk/src/actions/requirements/encode/encodeBundler3Erc20Permit2.ts Introduces Bundler3-scoped Permit2 signature requirement encoder.
packages/morpho-sdk/src/actions/requirements/encode/encodeBundler3Erc20Permit2.test.ts Renames tests to new encoder entrypoint.
packages/morpho-sdk/src/actions/requirements/bundler3/index.ts Adds Bundler3 requirement barrel exports.
packages/morpho-sdk/src/actions/requirements/bundler3/getBundler3RequirementsPermit2.ts Renames and re-types Permit2 requirement helper for Bundler3.
packages/morpho-sdk/src/actions/requirements/bundler3/getBundler3RequirementsPermit.ts Renames EIP-2612 permit requirement helper for Bundler3 and fixes import path.
packages/morpho-sdk/src/actions/requirements/blue/index.ts Adds Blue requirement barrel exports.
packages/morpho-sdk/src/actions/requirements/blue/getBlueRequirements.ts Adds Blue-specific requirement resolver that routes ERC-2612 vs Permit2 vs approval.
packages/morpho-sdk/src/actions/requirements/blue/getBlueRequirements.test.ts Updates tests for renamed Blue/Bundler3 requirement helpers and DAI routing behavior.
packages/morpho-sdk/src/actions/requirements/blue/getBlueAuthorizationRequirement.ts Renames authorization prerequisite helper and discriminator to blueAuthorization.
packages/morpho-sdk/src/actions/requirements/blue/getBlueAuthorizationRequirement.test.ts Updates tests for renamed Blue authorization helper.
packages/morpho-sdk/src/actions/blue/supplyCollateralBorrow.test.ts Uses getBlueRequirements in unit tests.
packages/morpho-sdk/src/actions/blue/supplyCollateral.test.ts Uses getBlueRequirements in unit tests.
packages/morpho-sdk/src/actions/blue/supply.test.ts Uses getBlueRequirements in unit tests.
packages/morpho-sdk/src/actions/blue/refinance.ts Updates doc wording to “authorized on Blue”.
packages/morpho-sdk/README.md Updates builder=signer invariant references to encodeBundler3Erc20Permit2.
packages/morpho-sdk/BUNDLER3.md Updates builder=signer section to encodeBundler3Erc20Permit2 (but still contains outdated authorization helper links).
packages/midnight-sdk/src/signatures/TreeUtils.ts Extends mempool validation to optionally include ratification data and throws on API validation issues.
packages/midnight-sdk/src/signatures/TreeUtils.test.ts Adds tests for ecrecover/setter ratification validation and new thrown error behavior.
packages/midnight-sdk/src/signatures/Tree.ts Re-exports new ratification type; updates mempoolValidate docs.
packages/midnight-sdk/src/offers/OfferUtils.ts Adds offer price/rate/APR/consumable-units helpers; refactors parameter typing and market handling.
packages/midnight-sdk/src/offers/OfferUtils.test.ts Adds coverage for new offer helpers and consumable-units behavior (incl. property tests).
packages/midnight-sdk/src/offers/Offer.ts Allows hydrated Market on offer.market and adds convenience getters/methods.
packages/midnight-sdk/src/math/TickLib.ts Adds tickToApr helper using time-to-maturity annualization.
packages/midnight-sdk/src/math/TickLib.test.ts Extends test coverage to tickToApr.
packages/midnight-sdk/src/math/TakeAmountsLib.test.ts Removes tests for deleted ConsumableUnitsLib.
packages/midnight-sdk/src/math/index.ts Stops exporting removed ConsumableUnitsLib.
packages/midnight-sdk/src/math/ConsumableUnitsLib.ts Removes old consumable-units library module.
packages/midnight-sdk/src/market/Position.ts Normalizes hydrated Market via new Market.from.
packages/midnight-sdk/src/market/Market.ts Adds Market.from constructor/normalization helper.
packages/midnight-sdk/src/market/Market.test.ts Adds tests for Market.from.
packages/midnight-sdk/src/fetch/Offer.ts Removes fetchConsumableUnits (logic moved to offer utils + explicit reads).
packages/midnight-sdk/src/fetch/index.ts Stops exporting removed offer fetch helper.
packages/midnight-sdk/src/fetch/fetch.test.ts Removes tests for deleted fetchConsumableUnits.
packages/midnight-sdk/src/errors.ts Adds MidnightMempoolValidationError for API validation failures.
packages/midnight-sdk/src/api/MidnightApi.ts Updates docs to reflect ratification-aware tree validation.
packages/midnight-sdk/src/abis.ts Adds midnightBundlesAbi and supporting tuple component constants.
packages/midnight-sdk/README.md Updates make-side flow to validate ratified payload bytes and document thrown validation error.
packages/midnight-sdk/package.json Bumps viem to 2.53.1.
.changeset/blue-requirements-helpers.md Declares Morpho SDK major for requirement helper renames and DAI permit changes; WDK patch.
.changeset/add-midnight-sdk.md Updates midnight-sdk changeset text to reflect new Market.from, ratification validation, bundles ABI, and moved consumable-units logic.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/morpho-sdk/BUNDLER3.md Outdated

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2df3f3c26a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/morpho-sdk/src/actions/requirements/blue/getBlueRequirements.ts Outdated
Comment thread .changeset/blue-requirements-helpers.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 68 out of 69 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread packages/morpho-sdk/BUNDLER3.md Outdated
Foulks-Plb
Foulks-Plb previously approved these changes Jul 2, 2026
@Rubilmax

Rubilmax commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 5e91b48150

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Foulks-Plb
Foulks-Plb previously approved these changes Jul 2, 2026
@Rubilmax Rubilmax force-pushed the hermes/midnight-action-flow-prerequisites branch from 5e91b48 to a249138 Compare July 2, 2026 14:13
Comment thread packages/midnight-sdk/src/signatures/TreeUtils.ts Outdated
Comment thread .changeset/blue-requirements-helpers.md
Comment thread packages/midnight-sdk/src/signatures/EcrecoverRatifierUtils.ts Outdated
@Rubilmax

Rubilmax commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex

Comment thread packages/midnight-sdk/src/signatures/EcrecoverRatifierUtils.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68658c8d1b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/morpho-sdk/BUNDLER3.md
@Rubilmax

Rubilmax commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: c0e5938186

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Rubilmax Rubilmax enabled auto-merge (squash) July 3, 2026 14:36
@Rubilmax Rubilmax merged commit 4d85d35 into main Jul 3, 2026
6 checks passed
@Rubilmax Rubilmax deleted the hermes/midnight-action-flow-prerequisites branch July 3, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants