Skip to content

refactor(morpho-sdk): Extract morpho-sdk bundler action encoding#669

Merged
Rubilmax merged 13 commits into
extract-public-reallocationfrom
drop-bundler-sdk-viem
May 21, 2026
Merged

refactor(morpho-sdk): Extract morpho-sdk bundler action encoding#669
Rubilmax merged 13 commits into
extract-public-reallocationfrom
drop-bundler-sdk-viem

Conversation

@Rubilmax
Copy link
Copy Markdown
Collaborator

@Rubilmax Rubilmax commented May 13, 2026

Summary

  • Extract the Bundler3 action encoding surface required by morpho-sdk into packages/morpho-sdk.
  • Remove @morpho-org/bundler-sdk-viem from morpho-sdk dependencies and lockfile importer data.
  • Keep migration-sdk-viem unchanged, including its existing bundler-sdk-viem wiring, because it is slated for deprecation.
  • Move the new BundlerErrors namespace into packages/morpho-sdk/src/types/error.ts and re-export it from the local bundler action surface.

Fixes SDK-186

Validation

  • pnpm --filter @morpho-org/morpho-sdk exec tsc --noEmit -p tsconfig.build.esm.json
  • pnpm --filter @morpho-org/morpho-sdk exec tsc --noEmit -p tsconfig.build.cjs.json
  • pnpm exec vitest --root . --project morpho-sdk packages/morpho-sdk/src/actions/bundler.test.ts --run
  • pnpm lint
  • git diff --check

@Rubilmax Rubilmax changed the title [codex] Extract morpho-sdk bundler action encoding refactor(morpho-sdk): Extract morpho-sdk bundler action encoding May 13, 2026
@Rubilmax Rubilmax force-pushed the extract-public-reallocation branch from 5eb6445 to fd7e814 Compare May 13, 2026 14:28
@Rubilmax Rubilmax force-pushed the drop-bundler-sdk-viem branch 3 times, most recently from 05e19d9 to 71e4a01 Compare May 13, 2026 15:19
Copy link
Copy Markdown
Collaborator Author

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

LGTM

@Rubilmax Rubilmax marked this pull request as ready for review May 13, 2026 15:21
@Rubilmax Rubilmax self-assigned this May 13, 2026
@Rubilmax
Copy link
Copy Markdown
Collaborator Author

@codex

Copy link
Copy Markdown

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

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 4 additional findings.

Open in Devin Review

@Rubilmax Rubilmax force-pushed the extract-public-reallocation branch from fd7e814 to b5d0ec4 Compare May 13, 2026 17:24
@Rubilmax Rubilmax requested a review from a team as a May 13, 2026 17:24
@Foulks-Plb Foulks-Plb self-requested a review May 15, 2026 08:42
@Rubilmax Rubilmax force-pushed the extract-public-reallocation branch from 33a1ca8 to 784418d Compare May 18, 2026 13:28
@Rubilmax Rubilmax force-pushed the drop-bundler-sdk-viem branch 2 times, most recently from 0cc8a72 to 73889ac Compare May 18, 2026 14:09
@linear
Copy link
Copy Markdown

linear Bot commented May 18, 2026

SDK-186

@Rubilmax Rubilmax force-pushed the drop-bundler-sdk-viem branch from 1bddb17 to cef0841 Compare May 20, 2026 12:42
Copy link
Copy Markdown
Collaborator Author

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

Automated /pr-review-local findings, posted as inline comments.

Severity Count
Critical 1
High 4
Medium 11
Low 4

9 personas fired (baseline + ci-release-security). 0 agent failures. Deduplicated against branch base extract-public-reallocation (merge-base 1b736238). Scope filter dropped 2 findings on files outside the diff.

Guard against /pr-review-local's known limits: messages may drift between reruns (LLM nondeterminism); the line of a finding is always within the changed-line window of the file, but the exact line can lag the symbol by a few lines on dense files.

Comment thread packages/morpho-sdk/BUNDLER3.md Outdated
Comment thread packages/morpho-sdk/package.json
Comment thread packages/morpho-sdk/src/abis.ts Outdated
Comment thread packages/morpho-sdk/src/abis.ts Outdated
Comment thread packages/morpho-sdk/src/bundler/actions.test.ts
Comment thread packages/morpho-sdk/src/types/error.ts
Comment thread packages/morpho-sdk/src/types/error.ts
Comment thread packages/morpho-sdk/src/types/error.ts
Comment thread packages/morpho-sdk/src/types/error.ts Outdated
Comment thread packages/morpho-sdk/src/types/error.ts Outdated
@Rubilmax Rubilmax force-pushed the drop-bundler-sdk-viem branch 5 times, most recently from 546d028 to 4138026 Compare May 21, 2026 08:00
@Rubilmax Rubilmax force-pushed the extract-public-reallocation branch from 4d430a3 to 1ab3b0d Compare May 21, 2026 08:30
Comment thread packages/morpho-sdk/src/abis.ts Outdated
Comment thread packages/morpho-sdk/src/actions/marketV1/borrow.ts
Comment thread packages/morpho-sdk/src/actions/marketV1/supplyCollateralBorrow.ts
Comment thread packages/morpho-sdk/src/actions/vaultV1/deposit.ts
Comment thread packages/morpho-sdk/src/actions/vaultV2/deposit.ts
Comment thread packages/morpho-sdk/src/bundler/actions.test.ts
Comment thread packages/morpho-sdk/src/bundler/actions.test.ts
Comment thread packages/morpho-sdk/src/bundler/actions.ts Outdated
Comment thread packages/morpho-sdk/src/bundler/actions.ts
Comment thread packages/morpho-sdk/src/bundler/actions.ts Outdated
Comment thread packages/morpho-sdk/src/bundler/actions.ts Outdated
Comment thread packages/morpho-sdk/src/bundler/actions.ts
Comment thread packages/morpho-sdk/src/bundler/actions.ts
Comment thread packages/morpho-sdk/src/bundler/actions.ts
Comment thread packages/morpho-sdk/src/bundler/types.ts
Comment thread packages/morpho-sdk/src/index.ts Outdated
Comment thread packages/morpho-sdk/src/types/error.ts
Comment thread packages/morpho-sdk/package.json
@Rubilmax
Copy link
Copy Markdown
Collaborator Author

Rubilmax commented May 21, 2026

📍 Finding targets packages/morpho-sdk/BUNDLER3.md:13 — the line is unchanged in this PR's diff so an inline review comment cannot be anchored. Posting as a top-level comment.

[MEDIUM] Stale line reference src/actions/vaultV1/deposit.ts#L82-L84 for the getChainAddresses(chainId).bundler3.generalAdapter1 claim. The added @throws {Permit2ExpirationMissingError} JSDoc in vaultV1/deposit.ts shifts the actual destructuring; in HEAD it lives at L115-L118 (and was never at L82-L84 even before — those lines are inside the JSDoc).

Suggestion: update to #L115 or drop the line anchor.

Copy link
Copy Markdown
Collaborator

@Foulks-Plb Foulks-Plb left a comment

Choose a reason for hiding this comment

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

Parallel PR Review (Claude) — focus: security / fund loss / tx flow

Reviewed commit: 9cb99a1b • Base: extract-public-reallocation

Severity Count
Critical 0
High 0
Medium 0
Low 1

Transaction-flow / tx.value audit (no fund-loss bugs found)

The core refactor — moving tx.value from explicit callsite overrides (value: nativeAmount, value: reallocationFee, value: nativeAmount + reallocationFee) to a derived value computed by the new BundlerAction.encodeBundle — was traced end-to-end:

  • nativeTransfer(bundler3, generalAdapter1, X) emits one bundler call with value=X; consumeCallValue deficits the bundler-available balance and rolls the shortfall into tx.value. ✓
  • nativeTransfer(user, bundler3, X) enters the prefund branch (addBundlerPrefund), which increments BOTH state.value and availableBundlerValue, so later value-carrying calls (e.g. reallocateTo) consume the prefund before adding to tx.value. ✓
  • reallocateTo action carries value: fee; each reallocateTo correctly bumps tx.value by fee minus any remaining prefund. ✓
  • Per-builder traces match the legacy explicit values:
    • supplyCollateral (native): tx.value = nativeAmount
    • borrow (with reallocations): tx.value = Σ fees
    • supplyCollateralBorrow (native + reallocations): tx.value = nativeAmount + Σ fees
    • repay / repayWithdrawCollateral: tx.value = 0n
    • vaultV1 / vaultV2 deposit (native): tx.value = nativeAmount
  • Callback actions inside morphoSupplyCollateral / morphoRepay are correctly recursed in encodeBundleAction, so a value > 0n callback (e.g. a transfer in a callback) correctly contributes to tx.value. ✓

The parity test in bundler/actions.test.ts documents the new tx.value = 130n vs legacyTx.value = 123n for the same mixed bundle — the new encoder accounts for a reallocateTo fee whose value exceeds the remaining bundler prefund (the legacy encodeBundle did not, which is why the old callsites had to override value explicitly). Removing the explicit value override is therefore only safe because the new encoder is more accurate — both observations are true together.

Other correctness checks that came up while auditing the diff:

  • The bundler-sdk-viem === → isAddressEqual fix (separate changeset, included in this PR) is a real bug fix — the old === on bundler3 / generalAdapter1 recipients would miss non-checksummed inputs and either skip value-counting or skip the recipient===bundler3 short-circuit in nativeTransfer. The new morpho-sdk encoder already uses isAddressEqual everywhere. morpho-sdk action builders source addresses from getChainAddresses (always canonical), so the old === bug never affected morpho-sdk outputs, but external bundler-sdk-viem callers could have hit it.
  • BundlerErrors.MissingSignature / UnexpectedAction are now distinct classes from the ones in @morpho-org/bundler-sdk-viem. Anyone catching BundlerErrors.X from the old bundler-sdk-viem path will not match throws from the new morpho-sdk encoder via instanceof. The PR description notes migration-sdk-viem intentionally keeps the bundler-sdk-viem wiring, so this is the expected break, but worth flagging in release notes / migration guide.
  • Note on scope: the extract-public-reallocation base branch (separate PR) is the one that removes the legacy 1h delay margin from ReallocationData.getMarketPublicReallocations. That is a behaviour change worth reviewing on the base PR, not this one.

Findings

See inline comment.

This is an automated parallel review. Findings list is conservative — only issues a reviewer would clearly act on in this PR.

@Foulks-Plb
Copy link
Copy Markdown
Collaborator

One finding (Low): ABI duplicationpackages/morpho-sdk/src/abis.ts ships 12 ABIs but the bundler only uses 3 of them (bundler3Abi, coreAdapterAbi, generalAdapter1Abi). The other 9 (URD, paraswap, Aave/Compound migrations, etc.) are dead code in this package and create a drift surface with bundler-sdk-viem. Suggestion: narrow to the 3 actually used, or add a comment naming the expected external consumer.

@Rubilmax Rubilmax merged commit 4eaf61c into extract-public-reallocation May 21, 2026
4 checks passed
@Rubilmax Rubilmax deleted the drop-bundler-sdk-viem branch May 21, 2026 15:31
Rubilmax added a commit that referenced this pull request May 26, 2026
* docs: add morpho-ts utility re-export plan

* feat(morpho-sdk): extract public reallocation data

* fix(morpho-sdk): format reallocation data

* test(morpho-sdk): cover reallocation data migration

* docs(morpho-sdk): document reallocation data APIs

* chore(morpho-sdk): drop simulation sdk dev dependency

* fix(morpho-sdk): remove reallocation delay lookahead

* docs: document reallocation timestamp accrual

* refactor(liquidity-sdk-viem): use morpho reallocation data

* chore: satisfy biome after main rebase

* fix: address CI failures after reallocation refactor

* docs: remove TIB changes from implementation PR

* fix: normalize reallocatable vault filters

* refactor: drop holdings from reallocation data

* fix: optimize public reallocation capping

* test: restore reallocation simulation parity

* test: fill reallocation parity gaps

* fix(morpho-sdk): ignore disabled reallocation markets

* chore: address reallocation review feedback

* test: cover reallocation timestamp overload

* docs: document reallocation fallback behavior

* perf: optimize reallocation state cloning

* docs: clarify public reallocation API

* fix: sort reallocation withdrawals bytewise

* fix: address reallocation review feedback

* fix: address reallocation review feedback

* fix: validate reallocation data chain

* fix: add liquidity reallocation delay

* test: update liquidity loader snapshots

* refactor(morpho-sdk): Extract morpho-sdk bundler action encoding (#669)

* refactor(liquidity-sdk-viem): use morpho reallocation data

* feat(morpho-sdk): extract bundler action encoding

* docs(morpho-sdk): document Permit2 expiration error

* test(liquidity-sdk-viem): checksum loader owner fixture

* fix(morpho-sdk): remove unused bundler signature error

* fix(morpho-sdk): derive bundler transaction value

* docs: document bundler encodeBundle errors

* test(morpho-sdk): cover bundler value derivation

* docs(morpho-sdk): clarify bundler encoding constraints

* docs(morpho-sdk): document native transfer skip behavior

* fix: account callback bundle value

* test(liquidity-sdk-viem): update loader expectations

* refactor(morpho-sdk): remove unused rewards ABI

* fix: normalize reallocation allocator fees

* refactor: reuse market id comparator

* feat(morpho-sdk): Re-export blue SDK surfaces from morpho-sdk (#714)

* refactor(liquidity-sdk-viem): use morpho reallocation data

* feat(morpho-sdk): re-export blue sdk surfaces

* chore: align reallocation entity exports

* fix(morpho-sdk): align re-export subpaths

* docs: add package deprecation migration notes

* fix(morpho-sdk): preserve source augment side effects
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