Skip to content

Commit

Permalink
feat: prepare for release (#1)
Browse files Browse the repository at this point in the history
* feat: prepare for release

* feat: use dynamic import

* feat: do not have task at install

* feat: add skip load to prepare script

* feat: move tasks to dedicated folder

* fix: fix remaining issues
  • Loading branch information
VGLoic authored Jul 10, 2022
1 parent ca04157 commit 5c08aa8
Show file tree
Hide file tree
Showing 13 changed files with 23,804 additions and 15,176 deletions.
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY>
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1

ETHERSCAN_API_KEY=
REPORT_GAS=
COINMARKET_CAP_API_KEY=
INFURA_PROJECT_ID=
GOERLI_MNEMONIC=
LOCALHOST_MNEMONIC=
7 changes: 1 addition & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ module.exports = {
parserOptions: {
ecmaVersion: 12,
},
rules: {
"node/no-unsupported-features/es-syntax": [
"error",
{ ignores: ["modules"] },
],
},
rules: {},
};
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Main Workflow
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
name: Compile and build
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
cache: npm
- run: npm install
- run: npm run compile
- run: npm run build
release:
needs: build
runs-on: ubuntu-latest
name: Release
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
cache: npm
- run: npm install
- run: npm run compile
- run: npm run build
- name: Semantic release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

17 changes: 17 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pull Request Worflow
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
name: Compile and build
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
cache: npm
- run: npm install
- run: npm run compile
- run: npm run build
3 changes: 3 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"branches": ["main"]
}
84 changes: 49 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
# Advanced Sample Hardhat Project

This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.

The project comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. It also comes with a variety of other tools, preconfigured to work with the project code.

Try running some of the following tasks:

```shell
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx hardhat coverage
npx hardhat run scripts/deploy.ts
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
npx eslint '**/*.{js,ts}'
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md}' --check
npx prettier '**/*.{json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix

# Semaphore Demo Contracts

:warning: This application has been developed for educational purposes and should not be considered as a serious product :warning:

This repository contains the only and simple contract for this Semaphore demo app. The contract acts as a Semaphore group admin and allows anyone to join the managed group.

## Local Development

This repository is developped using [hardhat](https://hardhat.org/). One is free to directly use the available scripts from hardhat using `npx`, otherwise, a set of local script have been made in order to allow safe local development.

### Setup

#### Environment Variables

Proper environment variables are needed in order to run the various scripts
- `REPORT_GAS`: if truthy, the gas measurements of the tests will be translated in USD value. The `COINMARKET_CAP_API_KEY` environment variable will need to be set,
- `COINMARKET_CAP_API_KEY`: an API key for CoinMarket Cap in order to retrieve USD value of ETH,
- `ETHERSCAN_KEY`: an etherscan key used in order to verify the contracts on Etherscan,

#### Nvm

Use configured node and npm versions
```console
nvm use
```

# Etherscan verification
Nvm installation instructions may be found [here](https://github.com/nvm-sh/nvm);

To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.
#### Dependencies

In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:
Install dependencies
```console
npm install
```

```shell
hardhat run --network ropsten scripts/deploy.ts
### Compile the smart contracts

```console
npm run compile
```

Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:
### Tests

Run all the tests
```console
npm run test
```

```shell
npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
Obtain the test coverage
```console
npm run test:cover
```

# Performance optimizations
### Solhint

For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable `TS_NODE_TRANSPILE_ONLY` to `1` in hardhat's environment. For more details see [the documentation](https://hardhat.org/guides/typescript.html#performance-optimizations).
Run a security and practices analysis by [solhint](https://github.com/protofire/solhint)
```console
npm run solhint
```
11 changes: 9 additions & 2 deletions contracts/SemaphoreDemo.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//SPDX-License-Identifier: Unlicense
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "hardhat/console.sol";
import {ISemaphore} from "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";

/**
* This contract is the admin of a Semaphore group, see https://semaphore.appliedzkp.org/docs/guides/groups
* It allows anyone to join the group by presenting an identity commitment
*/
contract SemaphoreDemo {
ISemaphore public immutable semaphore;
uint256 public immutable groupId;
Expand All @@ -13,6 +16,10 @@ contract SemaphoreDemo {
groupId = _groupId;
}

/**
* @notice Join the group using an identity commitment
* @param identityCommitment The identity commitment to add to the group
*/
function join(uint256 identityCommitment) public {
semaphore.addMember(groupId, identityCommitment);
}
Expand Down
57 changes: 13 additions & 44 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,27 @@
import path from 'path';
import fs from 'fs';
import * as dotenv from "dotenv";
import { HardhatUserConfig, task } from "hardhat/config";
import { HardhatUserConfig } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import "hardhat-gas-reporter";
import "hardhat-deploy";
import 'hardhat-deploy-ethers';
import "solidity-coverage";
import { ISemaphore__factory } from "./typechain";
import { address as SEMAPHORE_DEMO_GOERLI_ADDRESS } from './deployments/goerli/SemaphoreDemo.json';

dotenv.config();

const SEMAPHORE_GOERLI_ADDRESS = "0x99aAb52e60f40AAC0BFE53e003De847bBDbC9611";
const GROUP_ID = 123456789

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("createGroup", "Create a group on Semaphore", async (_, hre) => {
const [deployer] = await hre.ethers.getSigners()

const semaphore = ISemaphore__factory.connect(
SEMAPHORE_GOERLI_ADDRESS,
deployer
)

const tx = await semaphore.createGroup(
GROUP_ID,
20,
0,
deployer.address
);
console.log("Create group tx submitted: ", tx.hash);

await tx.wait();
console.log("Group created");
});

task("updateGroupAdmin", "Update group admin on Semaphore", async (_, hre) => {
const [deployer] = await hre.ethers.getSigners()

const semaphore = ISemaphore__factory.connect(
SEMAPHORE_GOERLI_ADDRESS,
deployer
);

const tx = await semaphore.updateGroupAdmin(GROUP_ID, SEMAPHORE_DEMO_GOERLI_ADDRESS);

console.log("Update group admin tx submitted: ", tx.hash);

await tx.wait();

console.log("Group admin updated!");
})
if (!process.env.SKIP_TASKS) {
[''].forEach((folder) => {
const tasksPath = path.join(__dirname, 'tasks', folder);
fs.readdirSync(tasksPath)
.filter((pth) => pth.includes('.ts'))
.forEach((task) => {
require(`${tasksPath}/${task}`);
});
});
}

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
Expand Down
22 changes: 22 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MultiNetworkContractStore } from "contract-store";
import semaphoreDemoGoerli from "./deployments/goerli/SemaphoreDemo.json";
import semaphore from './artifacts/@semaphore-protocol/contracts/interfaces/ISemaphore.sol/ISemaphore.json';

export * from "./typechain";

enum Network {
goerli = 5,
}

const SEMAPHORE_GOERLI_ADDRESS = "0x99aAb52e60f40AAC0BFE53e003De847bBDbC9611";

export const contractStore = new MultiNetworkContractStore([Network.goerli]);

contractStore.registerContract(Network.goerli, "SEMAPHORE_DEMO", {
abi: semaphoreDemoGoerli.abi,
address: semaphoreDemoGoerli.address
});
contractStore.registerContract(Network.goerli, "SEMAPHORE", {
abi: semaphore.abi,
address: SEMAPHORE_GOERLI_ADDRESS
});
Loading

0 comments on commit 5c08aa8

Please sign in to comment.