-
Notifications
You must be signed in to change notification settings - Fork 18
Commit 865c8cd
Initial impl of an ERC20 Paymaster (#3687)
* update cargo lock
* feat: implement ERC20PaymasterV1 with dual payment support
Add new paymaster contract that allows users to pay gas fees with ERC20 tokens
while reimbursing bundlers with ETH. Supports both native token and arbitrary
ERC20 token payments with configurable exchange rates and beneficiary.
Key features:
- Dual payment support (native tokens and ERC20)
- Bundler authorization for security
- Dynamic exchange rates with time bounds
- Configurable beneficiary for token collection
- Automatic refunds for unused tokens
- Comprehensive security validations
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: resolve compilation errors and add comprehensive test suite for ERC20PaymasterV1
- Fix missing imports (UserOperationLib, IPaymaster)
- Fix PostOpMode enum reference to IPaymaster.PostOpMode
- Fix variable shadowing warning in _validatePaymasterUserOp
- Fix try-catch usage with SafeERC20 library functions
- Correct paymaster data encoding/decoding logic
- Add comprehensive test suite with 25 test cases covering:
- Constructor and initial state validation
- Bundler authorization management
- Beneficiary configuration
- Native token payment validation
- ERC20 token payment validation
- Balance and allowance checks
- Timestamp validation
- Post-operation handling with refunds
- Token withdrawal functionality
- Error handling scenarios
All tests pass successfully with proper edge case coverage.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat: comprehensive security improvements and decimal handling for ERC20PaymasterV1
Major improvements addressing all security and functionality concerns:
🔒 **Security Enhancements:**
- Add Math.mulDiv for overflow-safe arithmetic in token calculations
- Prevent "free approval" attacks by checking balance even for approval operations
- Enhanced validation for all user operations
- Safe token transfer error handling
💰 **Token Decimal Handling:**
- Add getTokenDecimals() helper function with fallback logic
- Add calculateExchangeRate() helper for precise rate calculations
- Update exchange rate documentation with decimal-aware examples
- Support for tokens with any decimal precision (6, 8, 18, etc.)
⚡ **Full Sponsorship Support:**
- Allow exchangeRate = 0 for complete gas sponsorship
- Proper handling of zero-cost operations
- Clear documentation of sponsorship modes
📚 **Enhanced Documentation:**
- Comprehensive README with decimal calculation examples
- Detailed exchange rate formulas and examples
- Security considerations and best practices
- Clear explanation of native token vs ERC20 payment flows
- Why native tokens don't need refunds (EntryPoint handles automatically)
🧪 **Comprehensive Testing:**
- 31 test cases covering all edge cases
- Arithmetic overflow protection tests
- Full sponsorship scenario tests
- Token decimal handling validation
- Helper function testing
All tests pass successfully with robust edge case coverage.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix selector for approve call
* remove native token logic
* refactor
* fix warnings
* cargo update
* charge user for approval
* add tests and error
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e1b7c64 commit 865c8cdCopy full SHA for 865c8cd
File tree
Expand file treeCollapse file tree
5 files changed
+2004
-543
lines changedFilter options
- parachain
- tee-worker/omni-executor
- aa-contracts
- src/core
- test
Expand file treeCollapse file tree
5 files changed
+2004
-543
lines changed
0 commit comments