Commit 2b288d1
authored
feat(predict): always use Permit2 fee auth and attach allowancesTx via feature flag (#27028)
## **Description**
When the Permit2 feature flag is enabled, the provider now:
1. **Always uses Permit2 fee authorization** — removes the on-chain
allowance readiness gate that previously caused a fallback to Safe fee
authorization when the Permit2 allowance wasn't set on-chain yet.
2. **Attaches `allowancesTx`** to the relay order when the proxy wallet
lacks the required Permit2 allowances, so the relay can submit the
allowance transaction on-chain before processing the order.
3. **Simplifies `previewOrder` FAK logic** — FAK order type is now
determined purely from feature flags and Permit2 config, since
`placeOrder` guarantees allowances are available.
4. **Gates FAK on actual allowance readiness** — for fee-bearing Buy
orders, FAK requires both Permit2 fee auth AND confirmed allowance
availability (on-chain or via `allowancesTx`).
5. **Replaces on-chain Permit2 nonce bitmap** with random nonce
generation to avoid collisions on back-to-back orders and eliminate an
RPC round-trip.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/PRED-720
## **Manual testing steps**
```gherkin
Feature: Permit2 fee authorization and allowancesTx relay
Scenario: user places a BUY order with Permit2 enabled and proxy wallet lacking allowances
Given Permit2 feature flag is enabled
And the proxy wallet does not have Permit2 allowances set on-chain
When user places a BUY order with fees
Then the order uses Permit2 fee authorization (not Safe fallback)
And an allowancesTx is attached to the relay request
And the order type is FAK (if fakOrdersEnabled)
Scenario: user places a BUY order with Permit2 enabled and proxy wallet already has allowances
Given Permit2 feature flag is enabled
And the proxy wallet already has Permit2 allowances on-chain
When user places a BUY order with fees
Then the order uses Permit2 fee authorization
And no allowancesTx is attached
And the order type is FAK (if fakOrdersEnabled)
Scenario: user places a SELL order with Permit2 enabled
Given Permit2 feature flag is enabled
When user places a SELL order (no fees)
Then no fee authorization is generated
And an allowancesTx is attached if proxy wallet lacks allowances
And the order type is FAK (if fakOrdersEnabled)
Scenario: allowancesTx generation fails gracefully
Given Permit2 feature flag is enabled
And getProxyWalletAllowancesTransaction throws an error
When user places a BUY order with fees
Then the order still submits (without allowancesTx)
And the order type falls back to FOK (not FAK)
And the error is logged but does not block order placement
```
## **Screenshots/Recordings**
### Before
https://www.loom.com/share/5bd9ee06414042e7a4ba944c666b1b9a
### After
FOK + Permit2:
https://www.loom.com/share/1241e70594684c43bf86880ad29b9fdf
FAK + Permit2:
https://www.loom.com/share/94c01e493c6149ef806f09b32afe5430
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches order submission/fee-collection logic and relayer request
payloads; incorrect gating or allowance handling could cause orders to
fail or use the wrong order type (FAK vs FOK). Changes are localized but
impact a critical trading path.
>
> **Overview**
> **Permit2 fee collection is now treated as always-available when
enabled.** `placeOrder` no longer falls back to Safe fee authorization
based on an on-chain Permit2 allowance check, and `previewOrder` now
selects `FAK` purely from feature flags/config.
>
> **Order submission can now include a prerequisite allowances
transaction.** When the Permit2 feature flag is on and the proxy wallet
lacks allowances, `placeOrder` generates and sends an `allowancesTx` to
the relayer (and logs/continues if generation fails); `submitClobOrder`
includes this optional field in the request body. Permit2 nonce
generation was also switched from on-chain bitmap reads to a random
nonce to avoid extra RPC calls/collisions, with tests updated
accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
373d73b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 54365c8 commit 2b288d1
File tree
6 files changed
+350
-187
lines changed- app/components/UI/Predict/providers/polymarket
- safe
6 files changed
+350
-187
lines changed
0 commit comments