Skip to content

feat(money-account-utils): add money account transaction batch builders - #9680

Open
Jwhiles wants to merge 2 commits into
mainfrom
feat/add-hooks
Open

feat(money-account-utils): add money account transaction batch builders#9680
Jwhiles wants to merge 2 commits into
mainfrom
feat/add-hooks

Conversation

@Jwhiles

@Jwhiles Jwhiles commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Explanation

Stacked on #9397.

Ports the Money Account deposit and withdrawal transaction batch builders from metamask-mobile (app/components/UI/Money/utils/moneyAccountTransactions.ts) into this package, so mobile and extension encode the vault calls identically rather than each keeping its own copy.

What moved: the ABIs, the calldata encoders, the slippage and share arithmetic, the mUSD deposit-asset resolution, and the two contract reads (previewDeposit on the lens, getRate on the accountant).

What deliberately did not move: the four client wrappers (updateMoneyAccountDepositTokenAmount, updateMoneyAccountWithdrawTokenAmount, getMoneyAccountDepositTransactionsData, getMoneyAccountWithdrawTransactionsData). Those read vault config, provider and recipient from mobile's Redux/Engine singletons and return a Confirmations-owned type, so they stay in the client and delegate to these builders.

Signatures are unchanged from mobile, including the injected provider, so client call sites only change their import path. @ethersproject/{abi,abstract-provider,contracts} v5 is used directly rather than the ethers umbrella, matching the convention already established by money-account-balance-service (which reads the same lens and accountant contracts).

References

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate (100% coverage maintained)
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and ensured that new or referenced constants are available in those clients

🤖 Generated with Claude Code


Note

Medium Risk
Changes how on-chain deposit/withdraw batches are encoded and rounded; mistakes could cause failed txs or incorrect minima, though behavior is aligned with the prior mobile implementation and heavily tested.

Overview
Centralizes Money Account deposit and withdraw transaction encoding in @metamask/money-account-utils (ported from MetaMask Mobile) so clients share one implementation instead of duplicating vault calldata.

buildMoneyAccountDepositBatch returns an mUSD approve + teller deposit pair: it reads previewDeposit on the lens, sets minimumMint with 0.2% slippage, and can omit calldata via initialiseWithoutData or skip RPC for zero-amount placeholders. buildMoneyAccountWithdrawBatch returns teller withdraw (to the money account) plus mUSD transfer to the recipient, using getRate and getSharesForWithdrawal with ceiling division (plus minimumAssets = amount - 1) to avoid MinimumAssetsNotMet reverts from rounding.

Also exports helpers (applySlippage, deposit asset address/id resolution, TELLER_ABI, batch types) and adds @ethersproject contract dependencies with Jest coverage.

Reviewed by Cursor Bugbot for commit 061c619. Bugbot is set up for automated code reviews on this repo. Configure here.

@Jwhiles
Jwhiles requested review from a team as code owners July 28, 2026 13:46
@Jwhiles
Jwhiles force-pushed the feat/money-account-utils-package branch 3 times, most recently from bc4b92b to d90583a Compare July 30, 2026 12:51
Base automatically changed from feat/money-account-utils-package to main July 30, 2026 13:45
Jwhiles and others added 2 commits July 30, 2026 14:49
Ports the Money Account deposit and withdrawal batch builders from
metamask-mobile (`app/components/UI/Money/utils/moneyAccountTransactions.ts`)
so both clients encode the vault calls identically.

The client-resident wrappers around these builders stay in mobile: they read
vault config, provider and recipient from Redux/Engine singletons, which do
not belong in a shared package. Everything below that — ABIs, calldata
encoding, slippage and share arithmetic, and the two `previewDeposit`/`getRate`
reads — moves here, keeping the existing signatures so call sites only change
their import path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant