Skip to content

fix: deposit the measured unlocked amount in MorphoAllocator.run#3

Merged
maximebrugel merged 1 commit into
mainfrom
fix/allocator-deposit-unlocked
Jul 9, 2026
Merged

fix: deposit the measured unlocked amount in MorphoAllocator.run#3
maximebrugel merged 1 commit into
mainfrom
fix/allocator-deposit-unlocked

Conversation

@maxencerb

@maxencerb maxencerb commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

MorphoAllocator.run deposits a caller-supplied depositAmount via Facility.depositManager, while the amount actually credited to the intent by unlock is measured on-chain (unlocked). The executor has to predict the unlocked amount off-chain when building the transaction, and any difference (unlock slippage, fund NAV movement between order creation and unlock) leaves collateral dust sitting on the intent. Cleaning that dust would otherwise require an extra sweep-deposit step in orchestration.

Fix

  • run now deposits the measured unlocked amount in full, so the intent is always left with zero collateral dust.
  • The signature is unchanged, so callers (grunt's SyncAllocatorDeposit script and its params encoding) need no changes. The slot that previously fixed the deposit amount is reinterpreted as minAmountReceived, a minimum on the unlocked amount; the stricter of it and minSharesUnlocked applies.

Note for executors: a value passed in the old depositAmount slot now acts as a floor on the unlocked amount, so it should be the slippage-adjusted minimum (or 0 to rely on minSharesUnlocked alone), not the raw predicted amount.

Tests

  • test_run_depositsUnlockedAmount: the full unlocked amount is deposited even when minAmountReceived is below it.
  • test_run_revertsWhenUnlockedBelowMinAmountReceived: the repurposed slot is enforced as a floor when it is the stricter of the two minimums.
  • Fuzz suite now also asserts the deposited amount equals the unlocked amount. The integration suite against real Morpho Vault V2 + Morpho Blue runs unchanged (same ABI); 35 tests pass.

Summary by CodeRabbit

  • Bug Fixes
    • The allocator now deposits the full unlocked collateral amount instead of a caller-supplied deposit amount.
    • Slippage protection has been tightened: the operation now fails if the unlocked amount is below the required minimum.
    • On successful allocation, the deposited amount now matches the actual unlocked amount.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b37aa7ac-5746-42fa-8e7d-fcd11c94d452

📥 Commits

Reviewing files that changed from the base of the PR and between 28ad403 and ced4211.

📒 Files selected for processing (2)
  • src/MorphoAllocator.sol
  • test/MorphoAllocator.t.sol

📝 Walkthrough

Walkthrough

MorphoAllocator's run function replaces its depositAmount parameter with minAmountReceived and now deposits the full measured unlocked amount via Facility.depositManager. The slippage guard enforces unlocked against max(minAmountReceived, minSharesUnlocked). Tests and event documentation are updated to reflect this behavior.

Changes

MorphoAllocator deposit-amount replacement with unlocked amount

Layer / File(s) Summary
Contract signature, slippage guard, and deposit logic
src/MorphoAllocator.sol
run's parameter list replaces depositAmount with minAmountReceived; the slippage check now enforces unlocked >= max(minAmountReceived, minSharesUnlocked), and Facility.depositManager is called with the measured unlocked amount. Event documentation for unlocked is updated accordingly.
Test coverage for unlocked-amount deposit and slippage revert
test/MorphoAllocator.t.sol
Replaces a test asserting deposit independence with one confirming depositManager uses the unlocked amount, adds a revert test for minAmountReceived exceeding unlocked, adjusts an existing slippage test's inputs, and extends the fuzz test to assert deposit equals unlocked.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant MorphoAllocator
  participant Facility

  Caller->>MorphoAllocator: run(intentId, deallocations, minAmountReceived, minSharesUnlocked, ...)
  MorphoAllocator->>MorphoAllocator: compute unlocked
  MorphoAllocator->>MorphoAllocator: minUnlocked = max(minAmountReceived, minSharesUnlocked)
  alt unlocked < minUnlocked
    MorphoAllocator--)Caller: revert SlippageExceeded(minUnlocked, unlocked)
  else
    MorphoAllocator->>Facility: depositManager(unlocked)
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: MorphoAllocator.run now deposits the measured unlocked amount instead of a caller-supplied deposit amount.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/allocator-deposit-unlocked

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@maxencerb maxencerb force-pushed the fix/allocator-deposit-unlocked branch from b07ba95 to ced4211 Compare July 9, 2026 10:24
@maxencerb maxencerb marked this pull request as ready for review July 9, 2026 10:25
@maximebrugel maximebrugel merged commit 805139b into main Jul 9, 2026
2 of 3 checks passed
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