feat(morpho-sdk): add native wrapping to blueRepay#827
Conversation
Allow funding part or all of a Blue repay's transferAmount by wrapping native into wNative via GeneralAdapter1, mirroring blueSupply / blueSupplyCollateral. Adds the optional nativeAmount arg, the BlueRepayAction.nativeAmount field, and the exported NativeAmountExceedsTransferAmountError. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
For mixed native repayments (nativeAmount > 0 with an ERC-20 remainder), blueRepay passes erc20Funding = transferAmount - nativeFunding to getRequirementsAction, so a permit/Permit2 signed for the full args.transferAmount is rejected with DepositAmountMismatchError. This public @throws text tells integrators to sign transferAmount, which makes the new mixed native+permit path fail during transaction construction; it should reference the ERC-20 remainder instead.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Fix DepositAmountMismatchError JSDoc to reference the ERC-20 remainder (transferAmount - nativeAmount) pulled in mixed native repays, not the full transferAmount (Codex P2). - Reuse the WstethWethBlue fixture in blueRepay native unit tests instead of spreading WethUsdsBlue, whose cached MarketParams.id no longer matched the WETH loan-token tuple (Codex P3). - Add fork e2e tests: full-native repay and mixed native+ERC-20 repay, asserting the funding split (GA1 pulls only the ERC-20 remainder). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@codex review |
|
@prd-carapulse[bot] Eeview this PR with a strong focus on security and fund safety. Verify that no loss of funds is possible through the Bundler or the General Adapter. Also ensure that the PR follows the Morpho SDK standards, maintains a high level of developer experience (DevEx), and is consistent with the existing architecture and conventions. |
|
Verdict: ✅ No blocking issues found on current head • Fund safety: • Bundler / GeneralAdapter flow: native funds enter as • Mixed funding: ERC-20 pull / permit amount is exactly • Shares mode: residual overfund remains wNative and is skimmed back to • SDK standards / DevEx: action-layer scope matches PR body. Entity-layer • Verification run:
• Non-blocking suggestion: promote the by-shares native fork test into the committed suite, since that path carries the residual-skim fund-safety invariant. Track: https://carapulse.morpho.dev/dashboard/runs?run_id=gw_run_5a81658649ed |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…tests The fully-native repay test only checked that getRequirementsAction was not called, which proves nothing about the plain erc20TransferFrom path. Assert on the GeneralAdapter1 call selectors instead: the fully-native bundle must contain wrapNative and must NOT contain erc20TransferFrom, while the mixed bundle must contain both. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Express blueRepay funding as amount (ERC-20) + nativeAmount (wrapped),
summing to the GeneralAdapter1 transfer — the same DepositAmountArgs
surface as blueSupply / blueSupplyCollateral. Mode is selected by `shares`
(omit for assets mode, set for full repay). Removes the redundant
assets/transferAmount pair from the action args; transferAmount is now
derived. Drops the now-unreachable NativeAmountExceedsTransferAmountError.
The MorphoBlue.repay() entity API and the BlueRepayAction result shape are
unchanged. Updates entity wiring, unit + e2e tests, docs, and bumps the
changeset to major with a migration guide.
BREAKING CHANGE: blueRepay args replace { assets, transferAmount } with
{ amount, nativeAmount? } that sum to the transfer; mode is set by `shares`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The repay entity now accepts an optional nativeAmount alongside
{ assets } | { shares }, giving the surface DevEx: asset, asset+native,
share, or share+native (assets/shares stay mutually exclusive). It sources
up to nativeAmount of the funding by wrapping native ETH (capped at the
required transfer, so over-providing funds the repay fully with native),
pulls the remainder as ERC-20, and getRequirements returns an approval only
for that ERC-20 remainder (empty when fully native).
Converts the native repay fork e2e tests to drive the entity API and adds a
shares-mode fully-native case. Updates docs and the changeset.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Motivation
Repaying a wNative-denominated Blue debt previously required the integrator to wrap native ETH into wNative in a separate step, even though
blueSupplyandblueSupplyCollateralalready support native wrapping inline. This closes that gap so a repay can be funded directly with native ETH.Solution
blueRepaynow accepts an optionalargs.nativeAmountthat funds part or all oftransferAmountby prependingnativeTransfer → wrapNative(viaGeneralAdapter1), with any remainder pulled through the existing ERC-20/permit path — exactly the pattern used by the supply actions. The loan token must be the chain's wNative, and in shares mode the skimmed residual is returned as wNative (documented). Adds the publicBlueRepayAction.args.nativeAmountfield and the exportedNativeAmountExceedsTransferAmountError, plus six unit tests and a minor changeset. The entity layer (MorphoBlue.repay()) is intentionally untouched and left for a follow-up.