Add delegation support to ContractFunc execute method and Wallet class#4
Open
devin-ai-integration[bot] wants to merge 5 commits intomainfrom
Open
Add delegation support to ContractFunc execute method and Wallet class#4devin-ai-integration[bot] wants to merge 5 commits intomainfrom
devin-ai-integration[bot] wants to merge 5 commits intomainfrom
Conversation
* Add EIP-7702 delegation utilities - Add AuthorizationItem model for delegation authorization lists - Extend PreparedTransaction and BaseTransaction to support type 4 transactions - Create delegation utilities for easy sponsorship of delegated transactions - Add helper functions for creating authorization items and preparing delegation transactions Implements EIP-7702 account delegation with utilities similar to web3.py patterns but implemented natively in eth_rpc. Includes create_authorization_item, prepare_delegation_transaction, and sponsor_delegation functions. Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Improve sponsor_delegation API to use delegate_wallet parameter - Replace separate delegatee_address and delegatee_private_key parameters with single delegate_wallet parameter - Makes API cleaner and more consistent with existing eth_rpc wallet patterns - Updated test to verify the improved wallet-based API works correctly - All EIP-7702 functionality continues to work as expected Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Create Counter contract example for EIP-7702 delegation workflow - Rename test_eip7702.py to example_eip7702.py - Add realistic Counter contract using ProtocolBase pattern with increment method - Load delegate private key from DELEGATE_PRIVATE_KEY environment variable - Demonstrate complete EIP-7702 delegation workflow: - Sponsor wallet pays gas for transaction - Delegate wallet authorizes delegation via EIP-7702 - Counter contract increment method called on behalf of delegate - Educational example showing practical usage of sponsor_delegation function - Clear step-by-step workflow explanation for users learning EIP-7702 Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Fix EIP-7702 delegation utilities implementation - Fix create_authorization_item to authorize setting EOA code to contract - Fix sponsor_delegation to use correct transaction structure (to=delegate_address) - Update example workflow to match EIP-7702 specification - Fix documentation to reflect correct delegation mechanics - Resolve opcode 0xef error by implementing proper transaction structure - Add fixed gas values to avoid RPC calls in example demonstration Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Fix sponsor/delegate wallet logic in EIP-7702 example - Sponsor wallet now loaded from SPONSOR_PRIVATE_KEY environment variable (has funds to pay gas) - Delegate wallet now randomly created (doesn't need funds, just authorizes code setting) - Maintains correct EIP-7702 delegation mechanics and transaction structure - Example demonstrates realistic sponsor/delegate relationship Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Implement network-aware nonce management for EIP-7702 delegation - Add automatic network-aware nonce lookup using wallet[network].get_nonce() - Handle sponsor == delegate case with correct nonce coordination - Automatically detect chain_id from sponsor wallet's network context - Simplify API by eliminating manual nonce management - Update example script to demonstrate simplified workflow Requested by: @talos-agent Link to Devin run: https://app.devin.ai/sessions/db696e5c71a24f2486898e00991075ba Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Update example_eip7702.py --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…nsaction receipts (empyrealapp#106) * Add event receipt utility for extracting and decoding events from transaction receipts - Created EventReceiptUtility class with methods to extract events from receipts and transaction hashes - Added support for single and multiple event extraction - Included comprehensive test suite with mocked dependencies - Added convenience functions for easier usage - Integrated with existing Event system using Event.match() and Event.process_log() - Handles edge cases like missing receipts and processing exceptions Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Add uv.lock file Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Fix Black formatting issues in test file - Break long lines with HexAddress and HexStr constructors - Improve code readability with proper indentation - Address lint check failures Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Apply additional Black formatting fixes - Break long function signatures into multiple lines - Fix monkeypatch.setattr line length issues - Ensure all lines comply with Black formatting standards Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Replace mocked tests with real transaction data - Use real transaction receipts with Transfer and Approval events - Import TransferEvent and ApprovalEvent from eth_typeshed - Simplify test structure by removing complex mocking - Maintain comprehensive test coverage for all utility functions - Fix Black formatting issues Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Add comprehensive mocked RPC tests for end-to-end testing - Mock Transaction.get_receipt_by_hash() calls to return constructed receipts - Test get_events_from_tx_hash and get_single_event_from_tx_hash with mocks - Add invalid hash handling test with mocked RPC - Test convenience functions with mocked RPC calls - Eliminate external API dependencies for complete test isolation Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Fix circular import issues in event_receipt utility - Use TYPE_CHECKING imports to avoid runtime circular dependencies - Add string type annotations for Event, EventData, TransactionReceipt - Move Transaction import inside method to avoid initialization conflicts - Resolves ImportError during test collection Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Replace eth_typeshed imports with local Event type definitions - Define TransferEventType and ApprovalEventType locally in test file - Create TransferEvent and ApprovalEvent instances from local types - Follows same pattern as other test files to avoid import dependencies - Resolves ModuleNotFoundError for eth_typeshed package Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Fix Black formatting in event_receipt.py - Apply Black formatting to resolve lint check failures - No functional changes, only formatting improvements Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Fix import sorting in test_event_receipt.py - Apply isort formatting to resolve lint check failures - Ensure imports are correctly sorted according to project standards Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Remove uv.lock file - Remove uv.lock file as requested - Clean up repository structure Author: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Add wait_until_finalized method to TransactionReceipt class - Adds async method that polls for transaction receipt until finalized - Configurable sleep_time parameter (default 4.0 seconds) - Optional timeout parameter to prevent infinite polling - Raises exception for failed transactions (status == 0) - Returns finalized receipt when status == 1 - Follows existing async patterns from codebase Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Remove test file, keep only the main implementation Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> * Remove uv.lock file that was accidentally committed - uv.lock files should not be checked into version control - Keeps only the intended changes for wait_until_finalized method Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Enhanced execute() method in ContractFunc to accept optional delegate_wallet parameter - When delegate_wallet is provided, automatically uses sponsored delegation flow - Added delegate_to_contract() method to BaseWallet for simple delegation without contract data - Updated example_eip7702.py to demonstrate both new utility methods - Follows existing async/sync patterns with proper overloads - Abstracts sponsor_delegation + sign + send flow into single method calls Authored-by: Talos Co-Authored-By: talosgma@gmail.com <talosgma@gmail.com>
cd098e4 to
7ea8221
Compare
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.
Add delegation support to ContractFunc execute method and Wallet class
Summary
This PR adds utility methods to simplify EIP-7702 sponsored delegation transactions by abstracting the manual
sponsor_delegation+ sign + send flow into single method calls.Key Changes:
execute()method inContractFuncto accept optional delegation parameters (delegate_wallet,chain_id,gas)delegate_to_contract()method toBaseWalletfor simple delegation without contract dataUsage Examples:
Review & Testing Checklist for Human
execute()calls still work without delegation parametersRecommended Test Plan:
example_eip7702.pywithSPONSOR_PRIVATE_KEYsetDiagram
%%{ init : { "theme" : "default" }}%% graph TD FunctionPy["packages/eth_rpc/src/eth_rpc/<br/>contract/function.py"]:::major-edit WalletPy["packages/eth_rpc/src/eth_rpc/<br/>wallet.py"]:::major-edit ExamplePy["example_eip7702.py"]:::minor-edit DelegationPy["packages/eth_rpc/src/eth_rpc/<br/>delegation.py"]:::context FunctionPy -->|"uses"| DelegationPy WalletPy -->|"uses"| DelegationPy ExamplePy -->|"demonstrates"| FunctionPy ExamplePy -->|"demonstrates"| WalletPy subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
sponsor_delegationfunction fromdelegation.pyexecute()method maintains full backward compatibilityexecute_sponsored()method that provides the same functionality with explicit namingLink to Devin run: https://app.devin.ai/sessions/6277ae0e44924c06b7205c3842b45a38
Requested by: @talos-agent