Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Set up solc
uses: ARR4N/setup-solc@v0.2.0
with:
version: '0.8.30'
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -87,6 +92,11 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Set up solc
uses: ARR4N/setup-solc@v0.2.0
with:
version: '0.8.30'
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ diffs/
avalanchego/

.direnv

# Contract compilation artifacts and generated bindings
contracts/artifacts/
contracts/bindings/*.go
!contracts/bindings/bindings.go
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "contracts/submodules/openzeppelin-contracts"]
path = contracts/submodules/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts.git
6 changes: 5 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ tasks:
- task: check-generate-rlp

setup-contracts:
desc: Set up contracts by installing NPM dependencies, cleaning Hardhat cache, and compiling contracts
desc: Set up contracts by compiling Solidity contracts and generating Go bindings
dir: ./contracts
cmds:
# Keep npm/Hardhat compilation for existing TypeScript tests (Phase 2-3 migration)
- cmd: npm ci
- cmd: npx hardhat clean
- cmd: npx hardhat compile
# New: Compile contracts with solc and generate Go bindings
- cmd: go generate ./compile.go
- cmd: go generate ./bindings/bindings.go

shellcheck:
desc: Run shellcheck static analysis on all shell scripts with version management
Expand Down
43 changes: 39 additions & 4 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,57 @@ The goal of this guide is to lay out best practices regarding writing, testing a

## Prerequisites

### NodeJS and NPM
### Go

First, install the LTS (long-term support) version of [nodejs](https://nodejs.org/en). This is `18.16.0` at the time of writing. NodeJS bundles `npm`.
This project requires Go 1.21 or later. Install from [golang.org](https://golang.org/dl/).

### Solidity Compiler (solc)

The Solidity compiler version 0.8.30 is required to compile contracts. In CI, this is installed automatically via the [setup-solc](https://github.com/ARR4N/setup-solc) GitHub Action.

For local development, you can install solc via:
- **macOS**: `brew install solidity` (or `brew install solidity@0.8` for version 0.8.x)
- **Linux**: Follow instructions at [solidity docs](https://docs.soliditylang.org/en/latest/installing-solidity.html)
- **CI**: Automatically installed via GitHub Actions (version 0.8.30)

### Solidity and Avalanche

It is also helpful to have a basic understanding of [Solidity](https://docs.soliditylang.org) and [Avalanche](https://docs.avax.network).

## Dependencies

Clone the repo and install the necessary packages via `yarn`.
Clone the repo and initialize submodules:

```bash
git clone https://github.com/ava-labs/subnet-evm.git
cd subnet-evm
git submodule update --init --recursive
```

## Compiling Contracts

Contracts are compiled using `solc` directly, and Go bindings are generated using `abigen` from [libevm](https://github.com/ava-labs/libevm).

From the repository root, run:

```bash
./scripts/run_task.sh setup-contracts
```

This will:
1. Compile all Solidity contracts in `contracts/contracts/` to ABIs and bytecode
2. Generate Go bindings in `contracts/bindings/`

The compilation artifacts are stored in `contracts/artifacts/` (gitignored).

### Manual Compilation

To manually compile contracts:

```bash
cd contracts
npm install
go generate ./compile.go # Compile Solidity contracts
go generate ./bindings/bindings.go # Generate Go bindings
```

## Write Contracts
Expand Down
26 changes: 26 additions & 0 deletions contracts/bindings/bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// Package bindings provides Go bindings for Solidity contracts.
// This file contains go:generate directives to generate Go bindings using abigen.
package bindings

// Generate bindings for main contracts
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type AllowList --abi ../artifacts/AllowList.abi --bin ../artifacts/AllowList.bin --out allowlist.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ERC20NativeMinter --abi ../artifacts/ERC20NativeMinter.abi --bin ../artifacts/ERC20NativeMinter.bin --out erc20nativeminter.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleDeployerList --abi ../artifacts/ExampleDeployerList.abi --bin ../artifacts/ExampleDeployerList.bin --out exampledeployerlist.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type Example --abi ../artifacts/Example.abi --bin ../artifacts/Example.bin --out example.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleFeeManager --abi ../artifacts/ExampleFeeManager.abi --bin ../artifacts/ExampleFeeManager.bin --out examplefeemanager.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleRewardManager --abi ../artifacts/ExampleRewardManager.abi --bin ../artifacts/ExampleRewardManager.bin --out examplerewardmanager.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleTxAllowList --abi ../artifacts/ExampleTxAllowList.abi --bin ../artifacts/ExampleTxAllowList.bin --out exampletxallowlist.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleWarp --abi ../artifacts/ExampleWarp.abi --bin ../artifacts/ExampleWarp.bin --out examplewarp.go

// Generate bindings for interface contracts
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type IAllowList --abi ../artifacts/IAllowList.abi --bin ../artifacts/IAllowList.bin --out iallowlist.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type IFeeManager --abi ../artifacts/IFeeManager.abi --bin ../artifacts/IFeeManager.bin --out ifeemanager.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type INativeMinter --abi ../artifacts/INativeMinter.abi --bin ../artifacts/INativeMinter.bin --out inativeminter.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type IRewardManager --abi ../artifacts/IRewardManager.abi --bin ../artifacts/IRewardManager.bin --out irewardmanager.go
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type IWarpMessenger --abi ../artifacts/IWarpMessenger.abi --bin ../artifacts/IWarpMessenger.bin --out iwarpmessenger.go

// NOTE: Test contract bindings are not generated here
// Test contracts use DS-Test which we're deprecating. Tests will be rewritten in Go in Phase 3.
26 changes: 26 additions & 0 deletions contracts/compile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// Package contracts provides contract compilation directives.
// This file contains go:generate directives to compile Solidity contracts using solc.
package contracts

// Compile main contracts
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/AllowList.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/ERC20NativeMinter.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/ExampleDeployerList.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/ExampleFeeManager.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/ExampleRewardManager.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/ExampleTxAllowList.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/ExampleWarp.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/

// Compile interface contracts
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/interfaces/IAllowList.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/interfaces/IFeeManager.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/interfaces/INativeMinter.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/interfaces/IRewardManager.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/
//go:generate solc -o ./artifacts --overwrite --abi --bin --base-path . contracts/interfaces/IWarpMessenger.sol @openzeppelin/contracts/=submodules/openzeppelin-contracts/contracts/

// NOTE: Test contracts (contracts/test/*Test.sol) are NOT compiled here
// They use DS-Test which we're deprecating. These will be replaced with Go tests in Phase 3.
// The existing TypeScript tests will continue to use Hardhat-compiled versions until migration is complete.
1 change: 1 addition & 0 deletions contracts/submodules/openzeppelin-contracts
Submodule openzeppelin-contracts added at f95b9c
Loading