Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

Commit

Permalink
chore: super crates
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Nov 11, 2024
1 parent 6598462 commit a510301
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 110 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ rustdoc-args = ["--cfg", "docsrs"]

[workspace.dependencies]
# Workspace
superchain-derive = { version = "0.11.0", path = "crates/derive", default-features = false }
superchain-registry = { version = "0.11.0", path = "crates/registry", default-features = false }
super-derive = { version = "0.11.0", path = "crates/derive", default-features = false }
super-registry = { version = "0.11.0", path = "crates/registry", default-features = false }

# Kona
kona-derive = { version = "0.0.6", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "superchain-derive"
name = "super-derive"
description = "An alloy-backed derivation pipeline for the OP Stack, built on `kona-derive`"

version.workspace = true
Expand Down
18 changes: 9 additions & 9 deletions crates/derive/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
## `superchain-derive`
## `super-derive`

<a href="https://github.com/anton-rs/superchain/actions/workflows/rust_ci.yaml"><img src="https://github.com/anton-rs/superchain/actions/workflows/rust_ci.yaml/badge.svg?label=ci" alt="CI"></a>
<a href="https://crates.io/crates/superchain-derive"><img src="https://img.shields.io/crates/v/superchain-derive.svg?label=superchain-derive&labelColor=2a2f35" alt="Kona Derive Alloy"></a>
<a href="https://github.com/anton-rs/superchain/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-d1d1f6.svg?label=license&labelColor=2a2f35" alt="License"></a>
<a href="https://img.shields.io/codecov/c/github/anton-rs/superchain"><img src="https://img.shields.io/codecov/c/github/anton-rs/superchain" alt="Codecov"></a>
<a href="https://github.com/anton-rs/super/actions/workflows/rust_ci.yaml"><img src="https://github.com/anton-rs/super/actions/workflows/rust_ci.yaml/badge.svg?label=ci" alt="CI"></a>
<a href="https://crates.io/crates/super-derive"><img src="https://img.shields.io/crates/v/super-derive.svg?label=super-derive&labelColor=2a2f35" alt="Kona Derive Alloy"></a>
<a href="https://github.com/anton-rs/super/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-d1d1f6.svg?label=license&labelColor=2a2f35" alt="License"></a>
<a href="https://img.shields.io/codecov/c/github/anton-rs/super"><img src="https://img.shields.io/codecov/c/github/anton-rs/super" alt="Codecov"></a>

_Notice: Requires an `std` environment._

An online, alloy-backed derivation pipeline, built on [`kona-derive`][d].

## Usage

The easiest way to use `superchain-derive-alloy` to construct a derivation pipeline
The easiest way to use `super-derive` to construct a derivation pipeline
backed by [alloy][a] providers is to use the exported `new_online_pipeline` method.

```rust
use std::sync::Arc;
use super_derive::prelude::*;
use op_alloy_protocol::BlockInfo;
use op_alloy_genesis::RollupConfig;
use superchain_derive::prelude::*;

let rollup_config = Arc::new(RollupConfig::default());
let chain_provider =
Expand Down Expand Up @@ -55,7 +55,7 @@ assert_eq!(pipeline.origin(), Some(origin));
## Features

The most up-to-date feature list will be available on the
[docs.rs `Feature Flags` tab][ff] of the `superchain-derive-alloy` crate.
[docs.rs `Feature Flags` tab][ff] of the `super-derive` crate.

Some features include the following.
- `test-utils`: Test utilities for downstream libraries.
Expand All @@ -66,4 +66,4 @@ Some features include the following.

[a]: https://github.com/alloy-rs/alloy
[d]: https://crates.io/crates/kona-derive
[ff]: https://docs.rs/crate/kona-derive-alloy/latest/features
[ff]: https://docs.rs/crate/super-derive/latest/features
8 changes: 5 additions & 3 deletions crates/net/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[package]
name = "superchain-net"
name = "super-net"
description = "Networking library for the OP Stack"
version = "0.0.0"

version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
keywords.workspace = true
repository.workspace = true
categories.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
Expand Down
8 changes: 6 additions & 2 deletions crates/net/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Consensus Network Library
# `super`

A consensus network library for the OP Stack.

Contains a gossipsub driver to run discv5 peer discovery and block gossip.

Expand All @@ -14,7 +16,7 @@ Contains a gossipsub driver to run discv5 peer discovery and block gossip.
```rust,no_run
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use alloy_primitives::address;
use superchain_net::driver::NetworkDriver;
use super_net::driver::NetworkDriver;
// Build the network driver.
let signer = address!("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
Expand All @@ -38,5 +40,7 @@ println!("NetworkDriver started.");

Largely based off [magi]'s [p2p module][p2p].

<!-- Links -->

[magi]: https://github.com/a16z/magi
[p2p]: https://github.com/a16z/magi/tree/master/src/network
8 changes: 4 additions & 4 deletions crates/net/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ impl NetworkDriverBuilder {
/// ## Example
///
/// ```rust,ignore
/// use superchain_net::gossip::config;
/// use superchain_net::NetworkDriverBuilder;
/// use super_net::gossip::config;
/// use super_net::NetworkDriverBuilder;
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
///
/// let chain_id = 10;
Expand Down Expand Up @@ -161,7 +161,7 @@ impl NetworkDriverBuilder {
/// use alloy_primitives::{address, Address};
/// use discv5::{ConfigBuilder, ListenConfig};
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
/// use superchain_net::builder::NetworkDriverBuilder;
/// use super_net::builder::NetworkDriverBuilder;
///
/// let id = 10;
/// let signer = Address::random();
Expand Down Expand Up @@ -202,7 +202,7 @@ impl NetworkDriverBuilder {
///
/// ```rust,ignore
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
/// use superchain_net::NetworkDriverBuilder;
/// use super_net::NetworkDriverBuilder;
///
/// let chain_id = 10;
/// let signer = Address::random();
Expand Down
2 changes: 1 addition & 1 deletion crates/net/src/discovery/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl DiscoveryDriver {
///
/// ```no_run
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
/// use superchain_net::discovery::builder::DiscoveryBuilder;
/// use super_net::discovery::builder::DiscoveryBuilder;
///
/// #[tokio::main]
/// async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion crates/registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "superchain-registry"
name = "super-registry"
description = "The Superchain Registry"

version.workspace = true
Expand Down
84 changes: 27 additions & 57 deletions crates/registry/README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,62 @@
<h1 align="center">
<img src="../../assets/banner.png" alt="Superchain" width="100%" align="center">
</h1>
## `super-registry`

<h4 align="center">
Rust bindings for the <a href="https://github.com/ethereum-optimism/superchain-registry">superchain-registry</a>.
</h4>
<a href="https://github.com/anton-rs/super/actions/workflows/rust_ci.yaml"><img src="https://github.com/anton-rs/super/actions/workflows/rust_ci.yaml/badge.svg?label=ci" alt="CI"></a>
<a href="https://crates.io/crates/super-registry"><img src="https://img.shields.io/crates/v/super-derive.svg?label=super-registry&labelColor=2a2f35" alt="Kona Derive Alloy"></a>
<a href="https://github.com/anton-rs/super/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-d1d1f6.svg?label=license&labelColor=2a2f35" alt="License"></a>
<a href="https://img.shields.io/codecov/c/github/anton-rs/super"><img src="https://img.shields.io/codecov/c/github/anton-rs/super" alt="Codecov"></a>

<p align="center">
<a href="https://github.com/anton-rs/superchain/actions/workflows/rust_ci.yaml"><img src="https://github.com/anton-rs/superchain/actions/workflows/rust_ci.yaml/badge.svg?label=ci" alt="CI"></a>
<img src="https://img.shields.io/badge/License-MIT-d1d1f6.svg?label=license&labelColor=2a2f35" alt="License">
<a href="https://crates.io/crates/superchain-registry"><img src="https://img.shields.io/crates/v/superchain-registry.svg" alt="Superchain Crate"></a>
<a href="https://github.com/ethereum-optimism/monorepo"><img src="https://img.shields.io/badge/OP%20Stack-monorepo-red?labelColor=2a2f35" alt="OP Stack"></a>
<a href="https://img.shields.io/codecov/c/github/anton-rs/superchain"><img src="https://img.shields.io/codecov/c/github/anton-rs/superchain" alt="Codecov"></a>
</p>

<p align="center">
<a href="#whats-superchain">What's Superchain?</a> •
<a href="#usage">Usage</a> •
<a href="#feature-flags">Feature Flags</a> •
<a href="#credits">Credits</a>
</p>


## What's Superchain?

The [Superchain][op-superchain] is a network of chains that share bridging,
decentralized governance, upgrades, a communication layer and more.

Chain configurations for the [Superchain][op-superchain] are defined in the
[superchain][s] directory. This repository provides rust bindings
for the [ethereum-optimism/superchain-registry][osr].

Interface with the rust bindings through [`superchain`][s], an optionally
`no_std` crate that binds to the [ethereum-optimism/superchain-registry][osr]
at compile-time.


### `superchain`

[`superchain`][sc] is a `no_std` crate that exports rust type definitions for chains
[`super-registry`][sc] is a `no_std` crate that exports rust type definitions for chains
in the [`superchain-registry`][osr]. Since it reads static files to read configurations for
various chains into instantiated objects, the [`superchain`][sc] crate requires
[`serde`][serde] as a dependency. To use the [`superchain`][sc] crate, add the crate
various chains into instantiated objects, the [`super-registry`][sc] crate requires
[`serde`][serde] as a dependency. To use the [`super-registry`][sc] crate, add the crate
as a dependency to a `Cargo.toml`.

```toml
superchain-registry = "0.9"
super-registry = "0.9"
```

[`superchain`][sc] declares lazy evaluated statics that expose `ChainConfig`s, `RollupConfig`s,
[`super-registry`][sc] declares lazy evaluated statics that expose `ChainConfig`s, `RollupConfig`s,
and `Chain` objects for all chains with static definitions in the superchain registry. The way this works
is the the golang side of the superchain registry contains an "internal code generation" script that has
been modified to output configuration files to the [`crates/superchain`][s] directory in the
`etc` folder that are read by the [`superchain`][sc] rust crate. These static config files
been modified to output configuration files to the [`crates/registry`][s] directory in the
`etc` folder that are read by the [`super-registry`][sc] rust crate. These static config files
contain an up-to-date list of all superchain configurations with their chain configs.

There are three core statics exposed by the [`superchain`][sc].
There are three core statics exposed by the [`super-registry`][sc].
- `CHAINS`: A list of chain objects containing the superchain metadata for this chain.
- `OPCHAINS`: A map from chain id to `ChainConfig`.
- `ROLLUP_CONFIGS`: A map from chain id to `RollupConfig`.

While the [`op-alloy-genesis`][oag] crate contains a few hardcoded `RollupConfig` objects, the
[`superchain`][sc] exports the _complete_ list of superchains and their chain's `RollupConfig`s
[`super-registry`][sc] exports the _complete_ list of superchains and their chain's `RollupConfig`s
and `ChainConfig`s.

[`CHAINS`][chains], [`OPCHAINS`][opchains], and [`ROLLUP_CONFIGS`][rollups] are exported at the top-level
of the [`superchain`][sc] crate and can be used directly. See the [usage](#usage) section
below for how to work with [`superchain`][sc] mappings.


## Usage
### Usage

Add the following to your `Cargo.toml`.

```toml
[dependencies]
superchain-registry = "0.9"
super-registry = "0.9"
```

To make `superchain` `no_std`, toggle `default-features` off like so.
To make `super-registry` `no_std`, toggle `default-features` off like so.

```toml
[dependencies]
superchain-registry = { version = "0.9", default-features = false }
super-registry = { version = "0.9", default-features = false }
```

Below demonstrates getting the `RollupConfig` for OP Mainnet (Chain ID `10`).

```rust
use superchain_registry::ROLLUP_CONFIGS;
use super_registry::ROLLUP_CONFIGS;

let op_chain_id = 10;
let op_rollup_config = ROLLUP_CONFIGS.get(&op_chain_id);
Expand All @@ -98,18 +66,20 @@ println!("OP Mainnet Rollup Config: {:?}", op_rollup_config);
A mapping from chain id to `ChainConfig` is also available.

```rust
use superchain_registry::OPCHAINS;
use super_registry::OPCHAINS;

let op_chain_id = 10;
let op_chain_config = OPCHAINS.get(&op_chain_id);
println!("OP Mainnet Chain Config: {:?}", op_chain_config);
```

## Feature Flags

### Feature Flags

- `std`: Uses the standard library to pull in environment variables.

## Credits

### Credits

[superchain-registry][osr] contributors for building and maintaining superchain types.

Expand All @@ -121,12 +91,12 @@ println!("OP Mainnet Chain Config: {:?}", op_chain_config);
[serde]: https://crates.io/crates/serde
[alloy]: https://github.com/alloy-rs/alloy
[op-alloy]: https://github.com/alloy-rs/op-alloy
[superchain-repo]: https://github.com/anton-rs/superchain
[super]: https://github.com/anton-rs/super
[op-superchain]: https://docs.optimism.io/stack/explainer
[osr]: https://github.com/ethereum-optimism/superchain-registry

[s]: ./crates/superchain
[sc]: https://crates.io/crates/superchain
[s]: ./crates/registry
[sc]: https://crates.io/crates/super-registry

[oag]: https://crates.io/crates/op-alloy-genesis
[chains]: https://docs.rs/superchain-registry/latest/superchain/struct.CHAINS.html
Expand Down
12 changes: 6 additions & 6 deletions crates/super/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ rust-version.workspace = true
workspace = true

[dependencies]
superchain-derive = { workspace = true, optional = true }
superchain-registry = { workspace = true, optional = true }
super-derive = { workspace = true, optional = true }
super-registry = { workspace = true, optional = true }

[features]
default = ["std", "full"]

std = ["superchain-registry?/std"]
std = ["super-registry?/std"]

full = [
"derive",
"registry",
]

derive = ["dep:superchain-derive"]
registry = ["dep:superchain-registry"]
derive = ["dep:super-derive"]
registry = ["dep:super-registry"]

test-utils = ["superchain-derive?/test-utils"]
test-utils = ["super-derive?/test-utils"]
Loading

0 comments on commit a510301

Please sign in to comment.