Skip to content

feat(transaction-pay-middleware): accept a zero amount for perpsWithdraw - #11114

Merged
OGPoyraz merged 4 commits into
mainfrom
ogp/wallet-pay-withdraw-zero-amount
Oct 27, 2026
Merged

OGPoyraz merged 4 commits into
mainfrom
ogp/wallet-pay-withdraw-zero-amount

Conversation

@OGPoyraz

@OGPoyraz OGPoyraz commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Explanation

wallet_pay only accepts a positive amount, or no amount. A dApp opening a perpsWithdraw without knowing the amount up front, and passing "0", was rejected with -32602. The in-wallet withdraw opens with no prefilled amount and lets the user enter it on the confirmation.

This PR accepts a zero amount for perpsWithdraw:

  • AmountStruct now accepts any non-negative decimal with up to 6 decimals.
  • WalletPayFlow gets an optional allowZeroAmount property. After validating the params, walletPay rejects a zero amount with -32602 unless the requested type's flow sets it.
  • perpsWithdrawFlow sets allowZeroAmount: true. A zero amount is encoded the same way as no amount (0x0), so the confirmation opens without a prefilled amount.
  • perpsDeposit still requires a positive amount when one is given.

No amount is still accepted for both types, as before.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • 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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Low Risk
Narrows validation for one pay type behind an explicit flow flag; deposit rules unchanged and behavior for zero withdraw matches omitting amount.

Overview
wallet_pay no longer rejects "0" for perpsWithdraw. Dapps that do not know the withdraw amount up front can pass a zero amount (or omit it) and get the same confirmation UX as the in-wallet withdraw—no prefilled amount.

Validation is split: AmountStruct now allows any non-negative decimal (up to 6 places), and walletPay adds assertAmountAllowed, which returns -32602 for a zero amount unless the flow sets the new optional allowZeroAmount on WalletPayFlow. Only perpsWithdrawFlow enables that flag; perpsDeposit still requires a positive amount when amount is present. Zero amounts encode like a missing amount (zero USDC transfer data).

README and changelog document the behavior; tests cover deposit rejection vs withdraw acceptance.

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

@OGPoyraz
OGPoyraz marked this pull request as ready for review October 27, 2026 10:36
@OGPoyraz
OGPoyraz requested review from a team as code owners October 27, 2026 10:36
@OGPoyraz
OGPoyraz added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit 3512d1a Oct 27, 2026
46 checks passed
@OGPoyraz
OGPoyraz deleted the ogp/wallet-pay-withdraw-zero-amount branch October 27, 2026 12:46
This was referenced Oct 27, 2026
gaohan1994 pushed a commit to gaohan1994/core that referenced this pull request Oct 28, 2026
## Explanation

Release `1368.0.0` with a major version bump for:

- **`@metamask/transaction-pay-middleware`** `1.0.0` → `2.0.0`

### `@metamask/transaction-pay-middleware@2.0.0`

**Breaking:** `wallet_pay` now selects the requested account before
adding the transaction, once the request has passed every check
([MetaMask#11109](MetaMask#11109))
- The messenger must now allow `AccountsController:getAccountByAddress`,
`AccountsController:getSelectedAccount` and
`AccountTreeController:setSelectedAccountGroupByAccountId`.
- A request whose `from` is not a known account is rejected with `4100`.

Other changes:
- Add support for Node.js 26
([MetaMask#10981](MetaMask#10981))
- Accept a zero `amount` for `perpsWithdraw`, which opens the
confirmation without a prefilled amount; adds optional `allowZeroAmount`
to `WalletPayFlow`
([MetaMask#11114](MetaMask#11114))
- Add dependencies `@metamask/accounts-controller` (`^40.1.0`) and
`@metamask/account-tree-controller` (`^11.2.0`)
([MetaMask#11109](MetaMask#11109))
- Bump `@metamask/perps-controller` from `^21.0.0` to `^22.0.0`
([MetaMask#11029](MetaMask#11029))
- Bump `@metamask/utils` from `^12.0.0` to `^12.0.1`
([MetaMask#11107](MetaMask#11107))

### Dependency updates

No packages in the monorepo depend on
`@metamask/transaction-pay-middleware`, so there are no downstream range
updates. All upstream dependencies are already at their released
versions and were marked `intentionally-skip`.

## References

- [MetaMask#11109](MetaMask#11109) — select the
requested account for `wallet_pay`
- [MetaMask#11114](MetaMask#11114) — accept a zero
amount for `perpsWithdraw`

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Version and changelog edits only; no application code changes in this
diff.
> 
> **Overview**
> Cuts **monorepo release `1368.0.0`** and publishes
**`@metamask/transaction-pay-middleware@2.0.0`** by bumping root and
package versions and moving unreleased changelog entries into a
**`[2.0.0]`** section with updated compare links.
> 
> The documented **2.0.0** behavior (already merged elsewhere) includes
a **breaking** change: `wallet_pay` selects the `from` account before
enqueueing the transaction, with new messenger actions and `4100` for
unknown accounts; plus Node 26 support, optional zero `amount` for
`perpsWithdraw` via `allowZeroAmount`, and dependency bumps. No other
monorepo packages declare a dependency on this middleware, so this PR
does not update downstream version ranges.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
e9c6ee0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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