Skip to content

Latest commit

 

History

History
232 lines (167 loc) · 7.94 KB

File metadata and controls

232 lines (167 loc) · 7.94 KB

t1 Contracts

Contracts

Solidity Foundry License: MIT

This project contains the Solidity code for 𝚝𝟷 L1 bridge and rollup contracts, plus L2 bridge and pre-deployed contracts.

Directory Structure

├── script: Deployment scripts
├── src
│   ├── 7683: ERC7683 contracts
│   ├── L1: Contracts deployed on the L1 (Ethereum)
│   │   ├── gateways: Gateway router and token gateway contracts
│   │   ├── rollup: Rollup contracts for data availability and finalization
│   │   ├── IL1T1Messenger.sol: L1 T1 messenger interface
│   │   └── L1T1Messenger.sol: L1 T1 messenger contract
│   ├── L2: Contracts deployed on the L2 (T1)
│   │   ├── gateways: Gateway router and token gateway contracts
│   │   ├── predeploys: Pre-deployed contracts on L2
│   │   ├── IL2T1Messenger.sol: L2 T1 messenger interface
│   │   └── L2T1Messenger.sol: L2 T1 messenger contract
│   ├── libraries: Shared contract libraries
│   ├── misc: Miscellaneous contracts
│   ├── mocks: Mock contracts used in the testing
│   └── test: Unit tests in solidity
├── foundry.toml: Foundry configuration
├── remappings.txt: Foundry dependency mappings
└── deployments: Metadata from previous deployments
...

Core Contracts Overview

𝚝𝟷's architecture consists of these key components:

T1Chain

The backbone of 𝚝𝟷, responsible for managing batches, state roots, and cross-chain verification.

Messaging Layer

  • L1T1Messenger: facilitates message passing between L1 and L2, with the ability to retry failed messages
  • L2T1Messenger: the L2 counterpart, handling incoming messages from L1 and sending outbound messages
  • L1MessageQueue: maintains the ordered queue of L1→L2 messages awaiting processing
  • L2MessageQueue: maintains the ordered queue of L2→L1 messages awaiting processing
  • T1XChainReader: facilitates cross-chain read requests between supported chains

Bridge Infrastructure

  • GatewayRouter: entry point for all token bridging operations
  • L1EthGateway: handles native ETH bridging from L1→L2
  • L1WethGateway: specialized gateway for WETH transfers
  • L1StandardERC20Gateway: supports general ERC20 token bridging

Dependencies

  • Forge: compile, test, fuzz, format, and deploy smart contracts
  • Forge Std: collection of helpful contracts and utilities for testing
  • Husky: Git hooks made easy
  • Openzeppelin: library for secure smart contract development
  • Prettier: code formatter for non-Solidity files
  • Solhint: linter for Solidity code
  • Solmate: gas optimized building blocks
  • Uniswap/permit2: next generation token approvals mechanism

Sensible Defaults

This project comes with a set of sensible default configurations for you to use. These defaults can be found in the following files:

├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── foundry.toml
└── remappings.txt

GitHub Actions

This project comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull request made to the canary branch.

You can edit the CI script in contracts.yml.

Install Foundry

curl -L https://foundry.paradigm.xyz | bash

Installing Dependencies

Foundry typically uses git submodules to manage dependencies, but this project uses Node.js packages because submodules don't scale.

This is how to install dependencies:

  1. Install the dependency using your preferred package manager, e.g. bun install dependency-name
    • Use this syntax to install from GitHub: bun install github:username/repo-name
  2. Add a remapping for the dependency in remappings.txt, e.g. dependency-name=node_modules/dependency-name

Writing Tests

To write a new test contract, you start by importing Test from forge-std, and then you inherit it in your test contract. Forge Std comes with a pre-instantiated cheatcodes environment accessible via the vm property. If you would like to view the logs in the terminal output, you can add the -vvv flag and use console.log.

Usage

This is a list of the most frequently needed commands.

Build

Build the contracts:

$ bun run build

Clean

Delete the build artifacts and cache directories:

$ bun clean

Deploy

Deploy to Anvil:

$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545

For this script to work, you need to have a MNEMONIC environment variable set to a valid BIP39 mnemonic.

For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.

After deploying contracts, add a new json file to the deployments directory. At minimum, it should include the following:

{
  "metadata": {
    "version": "chainN",
    "date": "00-00-2025",
    "by": "<your name>",
    "from_machine": "name of VM or local machine",
    "from_branch": "canary",
    "from_commit": "a7e7dae0dd90aa4091ba034e820ac224213d8a30",
    "RPC_URL_L2": "https://rpc.devnet.t1protocol.com",
    "RPC_URL_L1": "https://sepolia.infura.io/v3/XXXXX"
  },
  "addresses": {
    "CONTRACT_NAME": "0x0000000000000000000000000000000000000001"
  }
}

Format

Format the contracts:

$ bun format

Gas Usage

Get a gas report:

$ forge test --gas-report

Lint

Lint the contracts:

$ bun run lint

Test & Coverage

Run the tests:

$ bun run test

Generate test coverage and output result to the terminal:

$ bun test:coverage

Generate test coverage with lcov report (you'll have to open the ./coverage/index.html file in your browser, to do so simply copy paste the path):

$ bun test:coverage:report

License

This project is licensed under the MIT LICENSE.

Acknowledgments

This repository is a fork of Scroll contracts created by Scroll, licensed under the MIT LICENSE.