Add Permit2 preflight validation checks#204
Merged
Conversation
Implements ENG-1907 by adding comprehensive preflight validation for orders: - Token balance verification (balanceOf check) - ERC20 approval validation (allowance to Permit2) - Permit2 nonce consumption validation (nonceBitmap check) Adds PreflightChecker with async validation methods: - check_token_balance() - verifies sufficient token balance - check_erc20_approval() - verifies Permit2 allowance - check_permit2_nonce() - verifies nonce availability - check_all() - runs all validations together Includes comprehensive error handling, unit tests, and documentation. Closes ENG-1907
prestwich
requested changes
Feb 27, 2026
Member
prestwich
left a comment
There was a problem hiding this comment.
functions should operate on the high-level types that compose orders and fills.
- UnsignedOrder (from signet_types)
- SignedOrder (from signet_types)
- OrdersAndFills
consider packaging these in an extension trait for Provider
Member
|
resolve CI |
- Remove Transport generic constraint, use Provider directly - Make new() and with_permit2_address() const functions - Fix call() return value handling (single returns don't need field accessor) - Add u64 suffix to hex literal to fix overflow warning - Remove network-dependent async test
prestwich
requested changes
Mar 6, 2026
Member
prestwich
left a comment
There was a problem hiding this comment.
previous comments still apply. this API should be higher-level and use an extension trait
| } | ||
|
|
||
| /// The canonical Permit2 contract address. | ||
| pub const PERMIT2_ADDRESS: Address = |
Member
There was a problem hiding this comment.
this should be re-used from somewhere else. look for existing definitions, and move them to the constants crate, then import from there
| nonce: u64, | ||
| ) -> Result<(), PreflightError> { | ||
| // Check balance | ||
| self.check_token_balance(token, user, amount).await?; |
Member
There was a problem hiding this comment.
run these in parallel using try_join
…trait Redesign preflight validation to use an extension trait on Provider instead of a wrapper struct. This follows alloy's provider extension pattern and provides a more ergonomic API. - Add Permit2PreflightExt trait with methods for SignedOrder, UnsignedOrder, and OrdersAndFills types - Use try_join_all for concurrent preflight checks - Export PERMIT2_ADDRESS from signet-types instead of duplicating it - Accept U256 nonces to match Permit2Batch types directly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
prestwich
reviewed
Mar 7, 2026
prestwich
requested changes
Mar 7, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address review comments on PR #204: - Rename trait to Permit2Ext, methods to check_* - Import sol! interfaces from signet-constants - Make free functions into trait methods - Use tokio::try_join! for known future counts - Remove boxed futures and unnecessary collects Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use functional combinators (then_some/ok_or) instead of if/return Err - Replace tokio::try_join! with futures_util::try_join/try_join3, removing unnecessary tokio dependency - Use .map(|_| ()) instead of trailing Ok(()) - Make contracts module private with selective pub use re-exports - Replace glob import in tests with explicit imports - Convert doctest from ignore to no_run Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move contract bindings and Permit2 address constant from signet-constants and signet-types into signet-zenith where the other contract bindings live. Add nonce_to_bitmap_position as a method on IPermit2Instance. Add default impls for check_signed_order, check_unsigned_order, and check_orders_and_fills on the Permit2Ext trait. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
prestwich
approved these changes
Mar 18, 2026
Member
prestwich
left a comment
There was a problem hiding this comment.
[Claude Code]
LGTM. All review comments addressed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Permit2 preflight validation checks to the signet-orders crate via a
Permit2Extextension trait on any alloyProvider.Checks performed:
Implementation
Permit2Exttrait extends anyProviderwith:sufficient_balance,token_approved,nonce_availablecheck_signed_order,check_unsigned_order,check_orders_and_fillssignet-constants::contractsfor reusetokio::try_join!for known future groups +try_join_allfor dynamic counts (no boxing, no unnecessary collects)API Usage
Closes ENG-1907