Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index 4337 UserOperations #1884

Merged
merged 49 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
46a5f1d
Index 4337 UserOperations
Uxio0 Feb 21, 2024
66b15c4
WIP
Uxio0 Feb 22, 2024
d3d4c8b
Add missing attributes to UserOperation
Uxio0 Feb 26, 2024
a3cc878
Add missing attributes to tx processor
Uxio0 Feb 26, 2024
8409a05
Improve logging for tx processor
Uxio0 Feb 27, 2024
8ca943a
Add SafeOperation conversion to model
Uxio0 Feb 28, 2024
74dfade
Use new app for ERC4337 related logic
Uxio0 Feb 28, 2024
cbb42f7
Clean pre-commit on CI
Uxio0 Feb 28, 2024
f28eef5
Update precommit
Uxio0 Feb 28, 2024
6a35480
Add support for deposits
Uxio0 Feb 29, 2024
a8d748f
Index User Operation even if UserOperation exists on DB
Uxio0 Feb 29, 2024
7a822a0
Fix migrations
Uxio0 Feb 29, 2024
04a97d7
Add SafeOperation model
Uxio0 Mar 4, 2024
50edbae
Add serializer for creating a SafeOperation
Uxio0 Mar 5, 2024
6a8b0d6
Add endpoints to work with SafeOperations
Uxio0 Mar 6, 2024
33b016f
Rename Account Abstraction TestCase
Uxio0 Mar 6, 2024
103f052
Add tests for 4337 endpoints
Uxio0 Mar 8, 2024
807870c
WIP
Uxio0 Mar 8, 2024
da8059f
Update safe-eth-py dependency to use git
Uxio0 Mar 11, 2024
23e00c7
Fix logic for updating SafeOperations created using our endpoint
Uxio0 Mar 12, 2024
679bcfc
Detect module address from module events
Uxio0 Mar 13, 2024
65a5d9a
Refactor some logic into safe-eth-py
Uxio0 Mar 13, 2024
5a9262a
Optimize keccak calls
Uxio0 Mar 15, 2024
9243b59
Fix tests
Uxio0 Mar 15, 2024
e7fd366
Fix typo
Uxio0 Mar 18, 2024
eb44032
Fix typo
Uxio0 Mar 18, 2024
bc93d64
Fix creating UserOperationReceipt
Uxio0 Mar 18, 2024
2c00711
Fix typo SafeOperationModel -> SafeOperation
Uxio0 Mar 18, 2024
52b5695
Don't index failed UserOperations
Uxio0 Mar 18, 2024
683995e
Refactor AA indexer into own class
Uxio0 Mar 19, 2024
aa32c61
Add bundler to CI
Uxio0 Mar 19, 2024
183dc5e
Update description
Uxio0 Mar 19, 2024
d7e8bbd
Process SafeOperation datetime in safe-eth-py
Uxio0 Mar 20, 2024
578c16b
Fix typo
Uxio0 Mar 20, 2024
943e5b0
Add missing admin classes
Uxio0 Mar 21, 2024
5267755
Fix admin
Uxio0 Mar 21, 2024
06c436c
Update safe_transaction_service/account_abstraction/models.py
Uxio0 Mar 25, 2024
d228dd4
Use HexV2Field
Uxio0 Mar 25, 2024
a902f63
Refactor SIGNATURE_LENGTH into constants
Uxio0 Mar 25, 2024
55908f1
Set valid safe-eth-py version
Uxio0 Mar 25, 2024
75797dc
Refactor datetime_to_str to utils package
Uxio0 Mar 25, 2024
7cffc0b
Fix view
Uxio0 Mar 25, 2024
a502cfc
Add tests for Account Abstraction models
Uxio0 Mar 26, 2024
916664a
Don't set log as DEBUG for tx_processor
Uxio0 Mar 27, 2024
2597232
Add method to get 4337 EthereumTxs
Uxio0 Mar 27, 2024
8406506
Update safe_transaction_service/account_abstraction/serializers.py
Uxio0 Apr 1, 2024
c25b6cf
Add Moises suggestions
Uxio0 Apr 1, 2024
22badbc
Fix tests
Uxio0 Apr 1, 2024
c1b5198
Fix format
Uxio0 Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
ETHEREUM_MAINNET_NODE: ${{ secrets.ETHEREUM_MAINNET_NODE }}
ETHEREUM_NODE_URL: http://localhost:8545
ETHEREUM_TRACING_NODE_URL: http://localhost:8545
ETHEREUM_4337_BUNDLER_URL: ${{ secrets.ETHEREUM_4337_BUNDLER_URL }}
Uxio0 marked this conversation as resolved.
Show resolved Hide resolved
ETH_HASH_BACKEND: pysha3
REDIS_URL: redis://localhost:6379/0
EVENTS_QUEUE_URL: amqp://guest:guest@localhost:5672/
Expand Down
15 changes: 14 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@
"rest_framework.authtoken",
]
LOCAL_APPS = [
"safe_transaction_service.account_abstraction.apps.AccountAbstractionConfig",
"safe_transaction_service.analytics.apps.AnalyticsConfig",
"safe_transaction_service.contracts.apps.ContractsConfig",
"safe_transaction_service.events.apps.EventsConfig",
"safe_transaction_service.history.apps.HistoryConfig",
"safe_transaction_service.notifications.apps.NotificationsConfig",
"safe_transaction_service.safe_messages.apps.SafeMessagesConfig",
"safe_transaction_service.tokens.apps.TokensConfig",
"safe_transaction_service.events.apps.EventsConfig",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
Expand Down Expand Up @@ -435,6 +436,18 @@
# ------------------------------------------------------------------------------
ETHEREUM_NODE_URL = env("ETHEREUM_NODE_URL", default=None)

# Ethereum 4337 Bundler RPC
# ------------------------------------------------------------------------------
ETHEREUM_4337_BUNDLER_URL = env("ETHEREUM_4337_BUNDLER_URL", default=None)
ETHEREUM_4337_SUPPORTED_ENTRY_POINTS = env.list(
"ETHEREUM_4337_SUPPORTED_ENTRY_POINTS",
default=["0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"],
)
ETHEREUM_4337_SUPPORTED_SAFE_MODULES = env.list(
"ETHEREUM_4337_SUPPORTED_SAFE_MODULES",
default=["0xa581c4A4DB7175302464fF3C06380BC3270b4037"],
)

# Tracing indexing configuration (not useful for L2 indexing)
# ------------------------------------------------------------------------------
ETHEREUM_TRACING_NODE_URL = env("ETHEREUM_TRACING_NODE_URL", default=None)
Expand Down
7 changes: 7 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@

urlpatterns_v1 = [
path("", include("safe_transaction_service.history.urls", namespace="history")),
path(
"",
include(
"safe_transaction_service.account_abstraction.urls",
namespace="account_abstraction",
),
),
path(
"contracts/",
include("safe_transaction_service.contracts.urls", namespace="contracts"),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ psycogreen==1.0.2
psycopg2==2.9.9
redis==5.0.3
requests==2.31.0
safe-eth-py[django]==6.0.0b22
safe-eth-py[django]==6.0.0b23
web3==6.15.1
Empty file.
91 changes: 91 additions & 0 deletions safe_transaction_service/account_abstraction/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from django.contrib import admin

from eth_typing import ChecksumAddress, HexStr

from safe_transaction_service.history import models as history_models

from .models import SafeOperation, UserOperation, UserOperationReceipt


@admin.register(UserOperation)
class UserOperationAdmin(admin.ModelAdmin):
list_display = ("hash", "ethereum_tx", "sender", "nonce", "success")
list_filter = [
"receipt__success",
]
search_fields = [
"==sender",
]
ordering = ["-nonce"]

@admin.display(boolean=True, description="Is successful?")
def success(self, obj: UserOperation) -> bool:
return obj.receipt.success


@admin.register(UserOperationReceipt)
class UserOperationReceiptAdmin(admin.ModelAdmin):
list_display = (
"user_operation_hash",
"user_operation_sender",
"user_operation_nonce",
"success",
"deposited",
)
list_filter = [
"success",
]
search_fields = [
"==user_operation__sender",
]

@admin.display()
def user_operation_hash(self, obj: UserOperationReceipt) -> HexStr:
return obj.user_operation.hash

@admin.display()
def user_operation_sender(self, obj: UserOperationReceipt) -> ChecksumAddress:
return obj.user_operation.sender

@admin.display()
def user_operation_nonce(self, obj: UserOperationReceipt) -> int:
return obj.user_operation.nonce


@admin.register(SafeOperation)
class SafeOperationAdmin(admin.ModelAdmin):
list_display = (
"hash",
"user_operation_hash",
"ethereum_tx",
"user_operation_sender",
"user_operation_nonce",
"success",
"module_address",
)
list_filter = ["module_address"]
list_select_related = ["user_operation__receipt"]
search_fields = [
"==user_operation__sender",
]
ordering = ["-modified"]

@admin.display()
def ethereum_tx(self, obj: SafeOperation) -> history_models.EthereumTx:
return obj.user_operation.ethereum_tx

@admin.display()
def user_operation_hash(self, obj: SafeOperation) -> HexStr:
return obj.user_operation.hash

@admin.display()
def user_operation_sender(self, obj: SafeOperation) -> ChecksumAddress:
return obj.user_operation.sender

@admin.display()
def user_operation_nonce(self, obj: SafeOperation) -> int:
return obj.user_operation.nonce

@admin.display(boolean=True, description="Is successful?")
def success(self, obj: SafeOperation) -> bool:
return obj.user_operation.receipt.success
6 changes: 6 additions & 0 deletions safe_transaction_service/account_abstraction/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountAbstractionConfig(AppConfig):
name = "safe_transaction_service.account_abstraction"
verbose_name = "Account Abstraction (ERC4337) indexing support"
23 changes: 23 additions & 0 deletions safe_transaction_service/account_abstraction/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
ERC4337 Constants

EntryPoint v0.6.0 and 0.7.0
---------------------------
0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f
UserOperationEvent (
indexed bytes32 userOpHash,
indexed address sender,
indexed address paymaster,
uint256 nonce,
bool success,
uint256 actualGasCost,
uint256 actualGasUsed
)
"""

from hexbytes import HexBytes

USER_OPERATION_NUMBER_TOPICS = 4
USER_OPERATION_EVENT_TOPICS = {
HexBytes("0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f")
}
Empty file.
Loading
Loading