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

fix: could not get transaction hash for sequencer transactions #40

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,44 @@ Installing this plugin adds support for the Optimism ecosystem:
ape console --network optimism:sepolia
```

### OP Stack

Use the `optimism` base-class in any custom networks using the OP stack.
For example, to configure a custom network for Fraxtal network, add the following to your `pyproject.toml`

```toml
[[tool.ape.networks.custom]]
name = "mainnet"
ecosystem = "fraxtal"
# Tell Ape to use optimism as the base plugin, instead of ethereum.
base_ecosystem_plugin = "optimism"
chain_id = 252

# (optional): Configure an RPC. Else, Ape will select a random one automatically.
[tool.ape.node.fraxtal.mainnet]
uri = "https://rpc.frax.com"
```

Or equivalent `ape-config.yaml`:

```yaml
networks:
custom:
- name: mainnet
ecosystem: fraxtal
base_ecosystem_plugin: optimism

node:
fraxtal:
mainnet:
uri: https://rpc.frax.com
```

There are two main benefits of using Optimism as the base-class instead of Ethereum for networks using the OP stack:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fubuloubu What other benefits can we include in the plugin?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of docs what we currently have, think we have that covered nicely

In terms of ideas, some ideas:

  • track L1 block confirmations
  • do native bridge actions (there are other bridge types):
    • L1 -> L2 deposits of supported tokens e.g. ETH
    • L2 -> L1 withdrawals (which take 7 days)
  • they also have some native "pre-compiles" that come out of the box w/ OP stack chains


1. **Closer defaults**: The block time default is `2` for Optimism networks, which may be a better default value than Ethereum's higher block time parameters.
2. **Existence of System Transactions**: The Optimism base-class is aware of system transactions, which are transactions invoked by the sequencer.

## Development

Comments, questions, criticisms and pull requests are welcomed.
22 changes: 17 additions & 5 deletions ape_optimism/ecosystem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, cast
from typing import cast

from ape.api import TransactionAPI
from ape.exceptions import ApeException, APINotImplementedError
Expand All @@ -8,9 +8,7 @@
NetworkConfig,
create_network_config,
)

if TYPE_CHECKING:
from eth_pydantic_types import HexBytes
from eth_pydantic_types import HexBytes

NETWORKS = {
# chain_id, network_id
Expand All @@ -34,16 +32,30 @@ class OptimismConfig(BaseEthereumConfig):

class SystemTransaction(TransactionAPI):
type: int = SYSTEM_TRANSACTION
_hash: HexBytes

def __init__(self, *args, **kwargs):
hash = kwargs.pop("hash", None)
super().__init__(*args, **kwargs)
self._hash = hash

@property
def txn_hash(self) -> "HexBytes":
raise APINotImplementedError("Unable to calculate the hash of system transactions.")
return self._hash

def serialize_transaction(self) -> bytes:
raise APINotImplementedError("Unable to serialize system transactions.")


class Optimism(Ethereum):
"""
A base class for Optimism or OP-stack networks.
The main differences from Ethereum are:

1. Different network defaults (block time is only '2', by default).
2. Recognition of "System transactions" (type 126).
"""

@property
def config(self) -> OptimismConfig: # type: ignore
return cast(OptimismConfig, self.config_manager.get_config("optimism"))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_ecosystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from ape_ethereum.transactions import TransactionType
from ethpm_types.abi import MethodABI
from hexbytes import HexBytes

from ape_optimism.ecosystem import SYSTEM_TRANSACTION, SystemTransaction

Expand Down Expand Up @@ -45,6 +46,7 @@ def test_create_transaction_type_2(optimism, tx_kwargs):


def test_create_transaction_type_126(optimism):
txn_hash = "0x417b3339801514042a4b3fa24658931438389996b29d0749cc7555a13a9ad89a"
data = {
"chainId": 0,
"to": "0x4200000000000000000000000000000000000015",
Expand All @@ -55,10 +57,12 @@ def test_create_transaction_type_126(optimism):
"data": "0x",
"type": 126,
"accessList": [],
"hash": HexBytes(txn_hash),
}
actual = optimism.create_transaction(**data)
assert isinstance(actual, SystemTransaction)
assert actual.type == SYSTEM_TRANSACTION
assert actual.txn_hash == HexBytes(txn_hash)


@pytest.mark.parametrize(
Expand Down
Loading