feat(predict): add Permit2 fee authorization support#26711
Conversation
|
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. |
Add Permit2FeeAuthorization type, PERMIT2_ADDRESS and SAFE_MSG_TYPEHASH constants. Extend PredictFeeCollection and PredictFees with optional executors and permit2Enabled fields (defaults: empty/false). PERMIT2_ADDRESS is NOT added to the static usdcSpenders array — approval is conditional on the permit2Enabled feature flag.
Add getPermit2Nonce (bitmap-based nonce reading from Permit2 contract), createPermit2FeeAuthorization (EIP-1271 wrapped Permit2 SignatureTransfer), and hasPermit2Allowance (checks Safe USDC approval to Permit2). Update createAllowancesSafeTransaction, hasAllowances, and getProxyWalletAllowancesTransaction to accept optional extraUsdcSpenders for conditional Permit2 approval during deposit.
calculateFees now passes through executors and permit2Enabled fields from fee collection config. submitClobOrder accepts Permit2FeeAuthorization union type and optional executor parameter in the request body.
…rovider placeOrder now branches between Permit2 and Safe transaction fee authorization based on permit2Enabled flag, executor availability, and USDC Permit2 allowance. Falls back to Safe tx when conditions are not met. Always uses FOK order type (FAK support in next PR). getAccountState and prepareDeposit conditionally include PERMIT2_ADDRESS in extraUsdcSpenders when permit2Enabled, ensuring the approval is bundled into the deposit transaction only when the feature is active.
b7dc763 to
db73a13
Compare
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
The changes are well-tested with comprehensive unit tests covering:
Risk is medium because:
Performance Test Selection: |
Description
Adds Permit2 SignatureTransfer fee authorization as an alternative to Safe
execTransactionfor fee collection. Feature-flagged OFF by default viapermit2Enabledandexecutorsfields on the fee collection remote config.How it works:
When
permit2Enabledis true, executors are configured, AND the user's Safe has approved USDC to the Permit2 contract:PermitTransferFromsignature is created (EIP-1271 wrapped for Safe)Fallback behavior: If any condition is not met (flag off, no executors, no Permit2 allowance), the existing Safe transaction fee authorization is used. Zero behavior change for existing users.
Conditional approval: The Permit2 USDC approval is only bundled into deposit transactions when
permit2Enabledis true — existing users without the flag don't get an extra approval transaction.Key additions:
Permit2FeeAuthorizationtype withsafe-permit2discriminatorgetPermit2Nonce()— bitmap-based nonce reading from Permit2 contractcreatePermit2FeeAuthorization()— EIP-1271 wrapped Permit2 SignatureTransfer signaturehasPermit2Allowance()— checks Safe USDC approval to Permit2extraUsdcSpendersparameter oncreateAllowancesSafeTransaction,hasAllowances,getProxyWalletAllowancesTransactionfor conditional approvalcalculateFeespasses throughexecutorsandpermit2EnabledsubmitClobOrderaccepts Permit2 auth union type andexecutorparamplaceOrderbranching: Permit2 → Safe tx fallbackgetAccountStateandprepareDepositconditionally include Permit2 approvalStill uses FOK orders — FAK support comes in the next PR.
Depends on: #26703 (feature flag refactor)
Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/PRED-715
Manual testing steps
Screenshots/Recordings
N/A — backend logic, no UI changes.
Before
N/A
After
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Adds a new, feature-flagged fee authorization path that changes how trade fees are signed and submitted (Permit2 + executor selection) and conditionally alters allowance/approval behavior for Safe wallets. While gated off by default with fallbacks, it touches trading flow, signing, and on-chain allowance checks.
Overview
Adds an alternative Permit2 SignatureTransfer fee authorization path for Polymarket order placement: when
permit2Enabledis true,executorsare configured, and the Safe has a Permit2 USDC allowance,placeOrderselects a random executor, creates asafe-permit2authorization payload, and submits it alongside the order (otherwise it falls back to the existingsafe-transactionauthorization).Extends fee/flag types and defaults to include
executorsandpermit2Enabled, updates relayer payloads to acceptexecutorand the new authorization union, and conditionally includes Permit2 as an extra USDC spender in allowance checks/approval transaction generation. Adds comprehensive unit tests for nonce calculation, Permit2 authorization creation, fallback behavior, and request-body changes.Written by Cursor Bugbot for commit db73a13. This will update automatically on new commits. Configure here.