Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
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:
versions: '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:
versions: '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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts.git
branch = v5.4.0
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 ./contracts/compile.go
- cmd: go generate ./bindings/bindings.go

shellcheck:
desc: Run shellcheck static analysis on all shell scripts with version management
Expand Down
45 changes: 41 additions & 4 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,59 @@ 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).

OpenZeppelin contracts are included as a git submodule at `contracts/lib/openzeppelin-contracts/` (pinned to v5.4.0).

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 ./contracts/compile.go # Compile Solidity contracts
go generate ./bindings/bindings.go # Generate Go bindings
```

## Write Contracts
Expand Down
14 changes: 14 additions & 0 deletions contracts/bindings/bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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

//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 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
8 changes: 8 additions & 0 deletions contracts/contracts/compile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 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

//go:generate solc-v0.8.30 -o ../artifacts --overwrite --abi --bin --base-path . @openzeppelin/contracts/=../lib/openzeppelin-contracts/contracts/ AllowList.sol ERC20NativeMinter.sol ExampleDeployerList.sol ExampleFeeManager.sol ExampleRewardManager.sol ExampleTxAllowList.sol ExampleWarp.sol
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at c64a1e
Loading