feat(predict): always use Permit2 fee auth and attach allowancesTx via feature flag#27028
feat(predict): always use Permit2 fee auth and attach allowancesTx via feature flag#27028
Conversation
… missing During placeOrder(), check if the user's proxy wallet has the required Permit2 allowances. When missing, generate a signed Safe TX and attach it to the relay API request as allowancesTx so the relay can submit it on-chain before processing the order. The allowancesTx is only attached when: - No feeAuthorization is present (no fees), OR - feeAuthorization is of type safe-permit2 Also simplifies previewOrder() to always use FAK when the Permit2/FAK config is active, since placeOrder now guarantees the allowance.
Add 6 test cases for placeOrder allowancesTx behavior: - Attaches when permit2 enabled + hasAllowances false + safe-permit2 fee - Attaches when permit2 enabled + hasAllowances false + no fees - Skips when feeAuthorization is safe-transaction (fallback path) - Skips when hasAllowances is true - Skips when permit2 is disabled - Continues order on allowance TX generation failure Add 2 test cases for submitClobOrder allowancesTx serialization. Update previewOrder tests to reflect simplified FAK logic (no more Permit2 allowance check in preview).
* main: (34 commits) chore: Update a message for Withdraw: Not enough POL (#27001) fix: Ensure `redux-persist-filesystem-storage` returns a promise and throws correctly cp-7.67.2 (#26979) chore: Bump `snaps-controllers` cp-7.67.2 (#26992) fix(TMCU-508): trigger NFT detection on homepage focus (#26919) fix: gas_paid_with metrics parameter for MMPay transactions (#26778) fix(card): cashback UI fixes (#26993) test: mock getQuoteStream with SSE format to fix SmokeTrade abort failures (#26977) feat: bump `@metamask-assets-controllers` to `^100.1.0` (#26987) feat(networks): add network deletion logic and update tests (#26983) fix(perps): remove duplicate AppState listener causing reconnection race cp-7.67.2 (#26982) feat(perps): inline deposit flow in pay-with token filter (#26543) feat: improve SDKConnectV2 error toasts (#26972) fix(predict): refresh balance/allowance before Polymarket order submission (#26954) fix(analytics): correct source prop for Perps section ">" navigation event (#26785) fix: market insights disclaimer text update (#26971) fix: request camera permission on Android during QR transaction signing (#26415) test: create Unified Gestures (#26932) feat: generic advanced charts component (#26459) fix(token-details): Use scoped account for EVM receive address after non-EVM network switch (#26965) chore: handle rewards 403 auth with retry (#26834) ...
… feature flag - Fix allowancesTx gate to use feeCollection.permit2Enabled feature flag instead of per-order fees, so SELL orders (no fees) also trigger it - Always use safe-permit2 fee authorization when permit2 is enabled, removing the safe-transaction fallback — backend submits allowancesTx on-chain first before redeeming the Permit2 authorization - Remove shouldAttachAllowancesTx restriction that blocked allowancesTx when fee auth was safe-transaction (chicken-and-egg problem) - Use random Permit2 nonce (crypto.getRandomValues) instead of on-chain bitmap lookup to avoid nonce collisions on back-to-back trades - Remove unused safeAddress param from getPermit2Nonce signature
…der type gating - Remove unused #isPermit2AllowanceReady method and hasPermit2Allowance import - Gate FAK order type on permit2AllowanceReady for fee-bearing orders - Remove all dead mockHasPermit2Allowance setup from tests - Extract setupAllowancesTxTest helper to reduce test duplication - Simplify multi-condition test names per unit testing guidelines
Add JSDoc explaining why getPermit2Nonce uses random values instead of on-chain bitmap reads: avoids nonce collisions on back-to-back orders whose fee collection hasn't settled, and removes an RPC round-trip.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts
Outdated
Show resolved
Hide resolved
…once conflict Both createSafeFeeAuthorization and getProxyWalletAllowancesTransaction read the same on-chain Safe nonce. If both execute in the same placeOrder call, the relay invalidates one when executing the other. Guard the allowancesTx block with hasSafeFeeAuth to skip it when a Safe fee authorization was already signed. Also remove unused fees param from setupAllowancesTxTest helper.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
These changes affect the order placement flow in Polymarket predictions. Per the tag descriptions:
The risk is medium because:
Performance Test Selection: |
The committed fixture schema is out of date. To update, comment: |
|



Description
When the Permit2 feature flag is enabled, the provider now:
allowancesTxto 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.previewOrderFAK logic — FAK order type is now determined purely from feature flags and Permit2 config, sinceplaceOrderguarantees allowances are available.allowancesTx).Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/PRED-720
Manual testing steps
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
Pre-merge reviewer checklist
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.
placeOrderno longer falls back to Safe fee authorization based on an on-chain Permit2 allowance check, andpreviewOrdernow selectsFAKpurely 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,
placeOrdergenerates and sends anallowancesTxto the relayer (and logs/continues if generation fails);submitClobOrderincludes 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.Written by Cursor Bugbot for commit 373d73b. This will update automatically on new commits. Configure here.