From 13731145786169a9625584c7753de579c7c11bc0 Mon Sep 17 00:00:00 2001 From: James Kim Date: Mon, 4 Nov 2024 19:40:27 -0800 Subject: [PATCH] misc fixes --- README.md | 92 ++++++++++++++++++++------------ packages/contracts/README.md | 81 ++++++++++++++++------------ packages/frontend/src/Bridge.tsx | 8 --- 3 files changed, 104 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 897be7b6..57d52f1a 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,43 @@ +# SuperchainERC20 Starter Kit + +
+

๐Ÿ“‘ Table of Contents

+ -**Table of Contents** _generated with [DocToc](https://github.com/thlorenz/doctoc)_ - -- [SuperchainERC20 Starter Kit](#superchainerc20-starter-kit) - - [What is SuperchainERC20?](#what-is-superchainerc20) - - [`IERC7802`](#ierc7802) - - [Getting Started](#getting-started) - - [1. Install prerequisites: `foundry`](#1-install-prerequisites-foundry) - - [2. Clone and navigate to the repository:](#2-clone-and-navigate-to-the-repository) - - [3. Install project dependencies using pnpm:](#3-install-project-dependencies-using-pnpm) - - [4. Install smart contracts dependencies:](#4-install-smart-contracts-dependencies) - - [5. Start the development environment:](#5-start-the-development-environment) - - [Deploying SuperchainERC20s](#deploying-superchainerc20s) - - [Configuring RPC urls](#configuring-rpc-urls) - - [Deployment config](#deployment-config) - - [`[deploy-config]`](#deploy-config) - - [`[token]`](#token) - - [`[single_chain_deploy_config]`](#single_chain_deploy_config) - - [`[multi_chain_deploy_config]`](#multi_chain_deploy_config) - - [Deploying to multiple chains](#deploying-to-multiple-chains) - - [Deploying to single chain](#deploying-to-single-chain) - - [Best practices for deploying SuperchainERC20](#best-practices-for-deploying-superchainerc20) - - [Use Create2 to deploy SuperchainERC20](#use-create2-to-deploy-superchainerc20) - - [`crossChainMint` and `crosschainBurn` permissions](#crosschainmint-and-crosschainburn-permissions) - - [How to bridge a SuperchainERC20 token to another chain](#how-to-bridge-a-superchainerc20-token-to-another-chain) - - [Contributing](#contributing) - - [License](#license) +- [๐Ÿค” What is SuperchainERC20?](#-what-is-superchainerc20) + - [`IERC7802`](#ierc7802) +- [๐Ÿš€ Getting Started](#-getting-started) + - [1. Install prerequisites: `foundry`](#1-install-prerequisites-foundry) + - [2. Clone and navigate to the repository:](#2-clone-and-navigate-to-the-repository) + - [3. Install project dependencies using pnpm:](#3-install-project-dependencies-using-pnpm) + - [4. Initialize .env files:](#4-initialize-env-files) + - [5. Start the development environment:](#5-start-the-development-environment) +- [๐Ÿ“ฆ Deploying SuperchainERC20s](#-deploying-superchainerc20s) + - [Configuring RPC urls](#configuring-rpc-urls) + - [Deployment config](#deployment-config) + - [`[deploy-config]`](#deploy-config) + - [`[token]`](#token) + - [`[single_chain_deploy_config]`](#single_chain_deploy_config) + - [`[multi_chain_deploy_config]`](#multi_chain_deploy_config) + - [Deploying to multiple chains](#deploying-to-multiple-chains) + - [Deploying to single chain](#deploying-to-single-chain) + - [Best practices for deploying SuperchainERC20](#best-practices-for-deploying-superchainerc20) + - [Use Create2 to deploy SuperchainERC20](#use-create2-to-deploy-superchainerc20) + - [`crosschainMint` and `crosschainBurn` permissions](#crosschainmint-and-crosschainburn-permissions) +- [๐Ÿงช E2E Tests](#-e2e-tests) + - [Prerequisites](#prerequisites) + - [Running the Tests](#running-the-tests) +- [๐ŸŒ‰ Example: How to bridge a SuperchainERC20 token to another chain](#-example-how-to-bridge-a-superchainerc20-token-to-another-chain) +- [๐Ÿค Contributing](#-contributing) +- [โš–๏ธ License](#-license) -# SuperchainERC20 Starter Kit +
-## What is SuperchainERC20? +## ๐Ÿค” What is SuperchainERC20? `SuperchainERC20` is an implementation of [ERC-7802](https://ethereum-magicians.org/t/erc-7802-crosschain-token-interface/21508) designed to enable asset interoperability in the Superchain. `SuperchainERC20` tokens are fungible across the Superchain by giving the `SuperchainERC20Bridge` permission to mint and burn the token during cross-chain transfers. For more information on SuperchainERC20 please visit the [docs](https://docs.optimism.io/stack/interop/superchain-erc20). @@ -47,7 +52,7 @@ To achieve cross-chain functionality, the `SuperchainERC20` standard incorporate - **`crosschainBurn`**: Burns tokens on the source chain to facilitate the transfer. - **Events (`CrosschainMint` and `CrosschainBurn`)**: Emit when tokens are minted or burned, enabling transparent tracking of cross-chain transactions. -## Getting Started +## ๐Ÿš€ Getting Started ### 1. Install prerequisites: `foundry` @@ -86,7 +91,7 @@ This command will: pnpm dev ``` -## Deploying SuperchainERC20s +## ๐Ÿ“ฆ Deploying SuperchainERC20s ### Configuring RPC urls @@ -169,11 +174,30 @@ pnpm contracts:deploy:singlechain `Create2` ensures that the address is deterministically deterimined by the bytecode of the contract and the provided salt. This is crucial because in order for cross-chain transfers of `SuperchainERC20`s to work with interop, the tokens must be deployed at the same address across all chains. -#### `crossChainMint` and `crosschainBurn` permissions +#### `crosschainMint` and `crosschainBurn` permissions For best security practices `SuperchainERC20Bridge` should be the only contract with permission to call `crosschainMint` and `crosschainBurn`. These permissions are set up by default when using the `SuperchainERC20` contract. -## How to bridge a SuperchainERC20 token to another chain +## ๐Ÿงช E2E Tests + +The `packages/e2e-test` directory contains simple end-to-end integration tests using `vitest` that run against `supersim` + +### Prerequisites + +Before running the tests, ensure you have: + +1. Completed all steps in the [Getting Started](#-getting-started) section +2. Initialized your environment variables (`pnpm init:env`) + +### Running the Tests + +```sh +pnpm e2e-test +``` + +The tests will run against your local supersim instance. + +## ๐ŸŒ‰ Example: How to bridge a SuperchainERC20 token to another chain **Note**: Interop is currently in active development and not yet ready for production use. This example uses [supersim](https://github.com/ethereum-optimism/supersim) in order to demonstrate how cross-chain transfers will work once interop is live. @@ -232,11 +256,11 @@ Verify that the balance of the `L2NativeSuperchainERC20` on chain 902 has increa cast balance --erc20 0x5BCf71Ca0CE963373d917031aAFDd6D98B80B159 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546 ``` -## Contributing +## ๐Ÿค Contributing Contributions are encouraged, but please open an issue before making any major changes to ensure your changes will be accepted. -## License +## โš–๏ธ License Files are licensed under the [MIT license](./LICENSE). diff --git a/packages/contracts/README.md b/packages/contracts/README.md index 9265b455..14a4eae4 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -1,17 +1,54 @@ -## Foundry +# Contracts -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** +## Overview -Foundry consists of: +This repository contains contracts and tooling for deploying and managing SuperchainERC20 tokens. -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. +## Contracts -## Documentation +### src/ -https://book.getfoundry.sh/ +- `L2NativeSuperchainERC20.sol` - An simple SuperchainERC20 implementation that allows the owner to mint new tokens. + +## Tests + +### test/ + +- `L2NativeSuperchainERC20.t.sol` - Tests for the L2NativeSuperchainERC20 contract, covering basic ERC20 functionality, minting, ownership, and transfers. + +- `SuperchainERC20.t.sol` - Tests for cross-chain functionality including cross-chain minting and burning operations. + + - If you implement your own custom SuperchainERC20 token, make sure to run these unit tests against it to confirm that it works correctly with the [SuperchainERC20Bridge](https://specs.optimism.io/interop/predeploys.html#superchainerc20bridge) + + ```diff + // Example of updating SuperchainERC20Test to use your custom token implementation: + contract SuperchainERC20Test is Test { + address internal constant ZERO_ADDRESS = address(0); + address internal constant SUPERCHAIN_TOKEN_BRIDGE = Predeploys.SUPERCHAIN_TOKEN_BRIDGE; + address internal constant MESSENGER = Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER; + + - SuperchainERC20 public superchainERC20; + + MyCustomSuperchainERC20 public superchainERC20; + + /// @notice Sets up the test suite. + function setUp() public { + - superchainERC20 = new L2NativeSuperchainERC20(address(this), "Test", "TEST", 18); + + superchainERC20 = new MyCustomSuperchainERC20(); + } + ... + ``` + +## Scripts + +### scripts/ + +- `MultiChainSuperchainERC20Deployment.s.sol` - Script for deploying the L2NativeSuperchainERC20 token to multiple chains in sequence, reading chain configuration from TOML. +- `SingleChainSuperchainERC20Deployment.s.sol` - Script for deploying the L2NativeSuperchainERC20 token to a single chain, reading chain configuration from TOML. +- `SuperchainERC20Deployer.sol` - Base deployment logic used by both single and multi-chain deployment scripts. + +## Deploying + +For more information on how to deploy the token, check out [the deployment guide](../../README.md#-deploying-superchainerc20s). ## Usage @@ -38,29 +75,3 @@ $ forge fmt ```shell $ forge snapshot ``` - -### Anvil - -```shell -$ anvil -``` - -### Deploy - -```shell -$ forge script script/Counter.s.sol:CounterScript --rpc-url --private-key -``` - -### Cast - -```shell -$ cast -``` - -### Help - -```shell -$ forge --help -$ anvil --help -$ cast --help -``` diff --git a/packages/frontend/src/Bridge.tsx b/packages/frontend/src/Bridge.tsx index f7dfae05..e2191e4a 100644 --- a/packages/frontend/src/Bridge.tsx +++ b/packages/frontend/src/Bridge.tsx @@ -64,14 +64,6 @@ export const Bridge = () => { const isButtonDisabled = !address || !amount || !sourceChain || !targetChain || isLoading - console.log({ - address, - amount, - sourceChain, - targetChain, - isLoading, - isButtonDisabled, - }) return (