Skip to content

Commit

Permalink
Enable Hardhat configuration using environment variables (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriicw authored Mar 26, 2024
1 parent 9bea4f0 commit c3ca5df
Show file tree
Hide file tree
Showing 7 changed files with 1,083 additions and 1,176 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SOLIDITY_VERSION = 0.8.16
OPTIMIZER_ENABLED = true
OPTIMIZER_RUNS = 1000
GAS_REPORTER_ENABLED = false
HARDHAT_MNEMONIC = test test test test test test test test test test test junk
GANACHE_RPC = http://127.0.0.1:7545
GANACHE_MNEMONIC = test test test test test test test test test test test junk
CW_TESTNET_RPC =
CW_TESTNET_PK =
CW_TESTNET_MNEMONIC =
CW_MAINNET_RPC =
CW_MAINNET_PK =
CW_MAINNET_MNEMONIC =
61 changes: 18 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on:
Expand All @@ -10,50 +7,28 @@ on:
branches: "**"

jobs:
ubuntu-latest:
runs-on: ubuntu-latest
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [20.10]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npx hardhat compile
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}

macos-latest:
runs-on: macos-latest
strategy:
matrix:
node-version: [20.10]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npx hardhat compile
- name: Checkout code
uses: actions/checkout@v3

windows-latest:
runs-on: windows-latest
strategy:
matrix:
node-version: [20.10]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npx hardhat compile
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Copy .env file
run: cp .env.example .env

- run: npm install

- run: npx hardhat compile
61 changes: 18 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: test

on:
Expand All @@ -10,50 +7,28 @@ on:
branches: "**"

jobs:
ubuntu-latest:
runs-on: ubuntu-latest
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [20.10]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npx hardhat test
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}

macos-latest:
runs-on: macos-latest
strategy:
matrix:
node-version: [20.10]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npx hardhat test
- name: Checkout code
uses: actions/checkout@v3

windows-latest:
runs-on: windows-latest
strategy:
matrix:
node-version: [20.10]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npx hardhat test
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Copy .env file
run: cp .env.example .env

- run: npm install

- run: npx hardhat test
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@

This repository contains [Compound protocol](https://github.com/cloudwalk/compound-protocol) periphery smart contracts.

## Project Setup
1. Clone the repo.
2. Create the `.env` file based on the `.env.example` one:
* Windows:
```sh
copy .env.example .env
```
* MacOS/Linux:
```sh
cp .env.example .env
```
3. Update settings in the newly created `.env` file if needed (e.g. another solidity version, number of optimization runs, private keys (PK) for networks, network RPC URLs, etc.).


## Build and test

```sh
Expand Down
35 changes: 29 additions & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,52 @@ import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@openzeppelin/hardhat-upgrades";
import "hardhat-contract-sizer";
import "hardhat-gas-reporter";
import dotenv from "dotenv";

dotenv.config();

const config: HardhatUserConfig = {
solidity: {
version: "0.8.16",
version: process.env.SOLIDITY_VERSION ?? "",
settings: {
optimizer: {
enabled: true,
runs: 1000
enabled: process.env.OPTIMIZER_ENABLED === "true",
runs: Number(process.env.OPTIMIZER_RUNS)
}
}
},
networks: {
hardhat: {
accounts: {
mnemonic: "test test test test test test test test test test test junk"
mnemonic: process.env.HARDHAT_MNEMONIC
}
},
ganache: {
url: "http://127.0.0.1:7545",
url: process.env.GANACHE_RPC,
accounts: {
mnemonic: "test test test test test test test test test test test junk"
mnemonic: process.env.GANACHE_MNEMONIC
}
},
cw_testnet: {
url: process.env.CW_TESTNET_RPC,
accounts: process.env.CW_TESTNET_PK
? [process.env.CW_TESTNET_PK]
: {
mnemonic: process.env.CW_TESTNET_MNEMONIC || ""
}
},
cw_mainnet: {
url: process.env.CW_MAINNET_RPC,
accounts: process.env.CW_MAINNET_PK
? [process.env.CW_MAINNET_PK]
: {
mnemonic: process.env.CW_MAINNET_MNEMONIC || ""
}
}
},
gasReporter: {
enabled: process.env.GAS_REPORTER_ENABLED === "true"
}
};

Expand Down
Loading

0 comments on commit c3ca5df

Please sign in to comment.