Skip to content
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
47 changes: 19 additions & 28 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
# Deployment Key
PRIVATE_KEY=XXX
PRIVATE_KEY=

# Network and account info
RPC_URL_MAINNET=XXX
RPC_URL_GOERLI=XXX
RPC_URL_ARBITRUM=XXX
RPC_URL_BERACHAIN=XXX
RPC_URL_OPTIMISM=XXX
RPC_URL_POLYGON=XXX
RPC_URL_AVALANCHE=XXX
RPC_URL_FANTOM=XXX
RPC_URL_ZKEVM=https://zkevm-rpc.com
# RPC URLs - Mainnet
RPC_URL_MAINNET=
RPC_URL_ARBITRUM=
RPC_URL_BASE=
RPC_URL_BSC=
RPC_URL_SCROLL=

# Testnets
RPC_URL_CONSENSYS_ZKEVM_TESTNET=XXX
RPC_URL_BSC_TESTNET=XXX
RPC_URL_SCROLL_ALPHA=https://alpha-rpc.scroll.io/l2
# RPC URLs - Testnet
RPC_URL_SEPOLIA=
RPC_URL_ARBITRUM_SEPOLIA=
RPC_URL_BASE_SEPOLIA=
RPC_URL_BSC_TESTNET=
RPC_URL_SCROLL_SEPOLIA=

# Block Explorere for verification
ETHERSCAN_KEY=XXX
ARBISCAN_KEY=XXX
BERACHAIN_ETHERSCAN_API_KEY=XXX
POLYGONSCAN_KEY=XXX
OPTIMISM_ETHERSCAN_KEY=XXX
SNOWTRACE_KEY=XXX
FTMSCAN_KEY=XXX
BSCSCAN_KEY=XXX
GNOSISBSCOUT_KEY=XXX
MOONRIVER_MOONSCAN_KEY=XXX
MOONBEAM_MOONSCAN_KEY=XXX
NOVA_ARBISCAN_KEY=XXX
# Block Explorer API Keys
ETHERSCAN_KEY=
ARBISCAN_KEY=
BASESCAN_API_KEY=
BSCSCAN_KEY=
SCROLLSCAN_API_KEY=
46 changes: 43 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: test

on: workflow_dispatch
on:
push:
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci
Expand All @@ -13,10 +16,15 @@ jobs:
name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
with:
submodules: recursive

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '18'

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
Expand All @@ -25,10 +33,42 @@ jobs:
- name: Run Forge build
run: |
forge --version
forge build --sizes
forge build
id: build

- name: Run Forge fmt
run: |
forge fmt --check
id: fmt

- name: Run Forge lint
run: |
forge lint src test script
id: lint

- name: Run Forge tests
run: |
forge test -vvv
id: test

- name: Install npm dependencies
run: npm ci

- name: Run solhint
run: |
yes | npm run lint
id: solhint

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.x'

- name: Install Slither
run: |
pip install slither-analyzer

- name: Run Slither
run: |
slither src/
id: slither
15 changes: 15 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "solhint:recommended",
"rules": {
"import-path-check": "off",
"func-visibility": ["warn", {"ignoreConstructors": true}],
"gas-strict-inequalities": "off",
"gas-indexed-events": "off",
"no-console": "off",
"one-contract-per-file": "off",
"no-empty-blocks": "off",
"var-name-mixedcase": "off",
"func-name-mixedcase": "off",
"gas-small-strings": "off"
}
}
2 changes: 2 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto-generated verifier contracts
src/verifiers/**
155 changes: 155 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# AGENTS.md

This file provides context for AI coding agents working on this project.

## Project Overview

This is a CREATE3 Factory contract that enables deterministic contract deployment across multiple EVM chains. Contracts deployed via this factory will have the same address on all supported chains, regardless of constructor arguments.

## Key Concepts

### CREATE3 vs CREATE2 vs CREATE

| Method | Address Depends On | Use Case |
|--------|-------------------|----------|
| CREATE | deployer address + nonce | Standard deployment |
| CREATE2 | deployer + salt + bytecode hash | Deterministic, but bytecode-dependent |
| CREATE3 | factory + salt + caller | Deterministic, bytecode-independent |

### How This Factory is Deployed

This factory uses **CREATE2** (not CREATE) for deployment to ensure the same factory address across all chains without nonce synchronization:

```solidity
// Deploy.s.sol
bytes32 salt = keccak256("intmax");
factory = new CREATE3Factory{salt: salt}();
```

The factory address is determined by:
- Deployer address (from PRIVATE_KEY)
- Salt ("intmax")
- Factory bytecode

### Bytecode Determinism

To ensure identical bytecode across different compilation environments:

```toml
# foundry.toml
bytecode_hash = "none"
cbor_metadata = false
```

These settings disable compiler metadata embedding.

## Project Structure

```
create3-factory/
├── src/
│ ├── CREATE3Factory.sol # Main factory contract
│ ├── ICREATE3Factory.sol # Interface
│ └── CREATE3Factory.flattened # Flattened for verification
├── script/
│ └── Deploy.s.sol # Foundry deployment script
├── deploy/
│ └── deploy.sh # Shell script wrapper
├── deployments/ # Deployment records (JSON)
├── lib/ # Git submodules (solmate, forge-std)
├── foundry.toml # Foundry configuration
└── .env.example # Environment variables template
```

## Supported Chains

| Mainnet | Testnet |
|---------|---------|
| Ethereum | Sepolia |
| Arbitrum | Arbitrum Sepolia |
| Base | Base Sepolia |
| BSC | BSC Testnet |
| Scroll | Scroll Sepolia |

## Development Workflow

### Setup

```bash
# Install dependencies
forge install

# Copy and configure environment
cp .env.example .env
# Edit .env with your values
```

### Build

```bash
forge build
```

### Deploy

```bash
# Deploy to a specific network
./deploy/deploy.sh <network>

# Example
./deploy/deploy.sh sepolia
```

## Important Technical Details

### Factory Address Calculation

The CREATE3Factory address is calculated as:
```
address = keccak256(0xff ++ deployer ++ salt ++ keccak256(bytecode))[12:]
```

### User Contract Address Calculation

When users call `factory.deploy(salt, creationCode)`:
```
finalSalt = keccak256(msg.sender ++ userSalt)
address = f(factoryAddress, finalSalt) // Independent of creationCode
```

### Security Notes

- The salt in Deploy.s.sol ("intmax") does not need to be secret
- Security relies on the deployer's private key, not the salt
- Each caller (msg.sender) has their own address namespace

## Environment Variables

Required in `.env`:

```bash
PRIVATE_KEY= # Deployer private key

# RPC URLs
RPC_URL_MAINNET=
RPC_URL_ARBITRUM=
RPC_URL_BASE=
RPC_URL_BSC=
RPC_URL_SCROLL=
RPC_URL_SEPOLIA=
RPC_URL_ARBITRUM_SEPOLIA=
RPC_URL_BASE_SEPOLIA=
RPC_URL_BSC_TESTNET=
RPC_URL_SCROLL_SEPOLIA=

# Etherscan API Keys (for verification)
ETHERSCAN_KEY=
ARBISCAN_KEY=
BASESCAN_API_KEY=
BSCSCAN_KEY=
SCROLLSCAN_API_KEY=
```

## Solidity Version

This project uses Solidity 0.8.33 with strict version pinning for bytecode determinism.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

Factory contract for easily deploying contracts to the same address on multiple chains, using CREATE3.

This was forked from https://github.com/zeframlou/create3-factory

The deploy script was updated to use legacy (non EIP-1559) transactions due to the fact that some chains that LIFI supports do not support EIP-1559.
This was forked from https://github.com/lifinance/create3-factory (originally from https://github.com/ZeframLou/create3-factory)

## Why?

Expand All @@ -15,11 +13,19 @@ One could use a `CREATE2` factory that deterministically deploys contracts to an

A `CREATE3` factory offers the best solution: the address of the deployed contract is determined by only the deployer address and the salt. This makes it far easier to deploy contracts to multiple chains at the same addresses.

LIFI Supports a large number of chains and we are only growing. CREATE3 allows us to manage our deployments better as well as make integration by developers more painless.
## Supported Chains

| Mainnet | Testnet |
|---------|---------|
| Ethereum | Sepolia |
| Arbitrum | Arbitrum Sepolia |
| Base | Base Sepolia |
| BSC | BSC Testnet |
| Scroll | Scroll Sepolia |

## Deployments

For a list of all deployments and their respective addresses of the `CREATE3Factory` please check folder deployments/
For a list of all deployments and their respective addresses of the `CREATE3Factory` please check folder `deployments/`

## Usage

Expand All @@ -35,7 +41,7 @@ A few notes:
To install with [Foundry](https://github.com/foundry-rs/foundry):

```
forge install lifinance/create3-factory
forge install InternetMaximalism/create3-factory
```

## Local development
Expand Down
8 changes: 8 additions & 0 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"lib/forge-std": {
"rev": "cb69e9c07fbd002819c8c6c8db3caeab76b90d6b"
},
"lib/solmate": {
"rev": "bff24e835192470ed38bf15dbed6084c2d723ace"
}
}
Loading