Skip to content

Add extended Midnight bundle options#857

Draft
Rubilmax wants to merge 58 commits into
mainfrom
hermes/marketv2-action-flows-extended
Draft

Add extended Midnight bundle options#857
Rubilmax wants to merge 58 commits into
mainfrom
hermes/marketv2-action-flows-extended

Conversation

@Rubilmax

@Rubilmax Rubilmax commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Stacked on hermes/marketv2-action-flows-implementation.

This follow-up restores the Midnight bundle options intentionally left out of the first markets-app implementation PR:

  • ERC2612 and Permit2 SignatureTransfer token-pull requirement helpers for Midnight Bundles.
  • Token-permit encoding into takeLend, supplyCollateralTakeBorrow, and repayWithdrawCollateral.
  • Public taker bundle options such as reduceOnly, referral fee parameters, max continuous fee cap, receiver overrides, and generic collateral withdrawal lists.

The first PR keeps the app-used approval-only, asset-targeted action surface. This stacked PR carries the broader SDK surface for a later review. The audit did not find a unit-target Midnight take helper in the current morpho-sdk implementation, so this branch does not add one.

Validation

  • pnpm exec vitest run --root . --project morpho-sdk packages/morpho-sdk/src/actions/midnight/takeLend.test.ts packages/morpho-sdk/src/actions/midnight/takeBorrow.test.ts packages/morpho-sdk/src/actions/midnight/supplyCollateralTakeBorrow.test.ts packages/morpho-sdk/src/actions/midnight/repayWithdrawCollateral.test.ts packages/morpho-sdk/src/entities/midnight/midnight.test.ts packages/morpho-sdk/src/actions/requirements/midnight/getMidnightBundlesRequirements.test.ts packages/morpho-sdk/src/actions/requirements/encode/encodeErc20Permit2Transfer.test.ts packages/morpho-sdk/src/actions/signatures/getMidnightTokenPermit.test.ts
  • pnpm --filter @morpho-org/morpho-sdk build

Rubilmax added 30 commits July 6, 2026 14:39
Rubilmax added 25 commits July 8, 2026 11:28
@Rubilmax
Rubilmax force-pushed the hermes/marketv2-action-flows-implementation branch from 0a07ac8 to 50c0fee Compare July 13, 2026 09:39
@Foulks-Plb

Copy link
Copy Markdown
Contributor

Non-zero referralFeePct breaks the assets↔debt identity on repay (funds footgun, undocumented API behavior)

repayWithdrawCollateral.ts passes repayAssets directly as assets. However, the TIB (line 238) documents that to repay a debt D when a referral fee is applied, the required amount is:

assets = floor(D * WAD / (WAD - referralFeePct))

—not assets = D.

The identity assets == D only holds when referralFeePct = 0.

Impact: An integrator setting referralFeePct > 0 and passing repayAssets = D will under-repay, leaving residual debt because part of the supplied assets is taken as the referral fee. This PR is the first one to expose referralFeePct, yet the parameter has no JSDoc (neither on the function parameters nor in types/action.ts).

  • also validate that referralFeePct < WAD to prevent on-chain reverts (PctExceeded / arithmetic underflow).

@Rubilmax
Rubilmax force-pushed the hermes/marketv2-action-flows-implementation branch from 0321d43 to 91d57a6 Compare July 16, 2026 09:19
Base automatically changed from hermes/marketv2-action-flows-implementation to main July 16, 2026 09:32
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.

2 participants