Skip to content

Commit

Permalink
Merge pull request #256 from privacy-scaling-explorations/feature/con…
Browse files Browse the repository at this point in the history
…tracts

feat(contracts): add maci-platform-contracts boilerplate
  • Loading branch information
0xmad authored Aug 12, 2024
2 parents cc7182b + a1abaab commit d71bb81
Show file tree
Hide file tree
Showing 22 changed files with 1,289 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
command: ["prettier", "types", "lint"]
command: ["prettier", "types", "lint:ts", "lint:sol"]

runs-on: ubuntu-22.04

Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/contracts-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Contracts

on:
push:
branches: [main]
pull_request:

env:
NEXT_PUBLIC_CHAIN_NAME: ${{ vars.NEXT_PUBLIC_CHAIN_NAME }}
NEXT_PUBLIC_ADMIN_ADDRESS: ${{ vars.NEXT_PUBLIC_ADMIN_ADDRESS }}
NEXT_PUBLIC_APPROVAL_SCHEMA: ${{ vars.NEXT_PUBLIC_APPROVAL_SCHEMA }}
NEXT_PUBLIC_METADATA_SCHEMA: ${{ vars.NEXT_PUBLIC_METADATA_SCHEMA }}
NEXT_PUBLIC_ROUND_ID: ${{ vars.NEXT_PUBLIC_ROUND_ID }}
NEXT_PUBLIC_SKIP_APPROVED_VOTER_CHECK: false
NEXT_PUBLIC_MACI_ADDRESS: ${{ vars.NEXT_PUBLIC_MACI_ADDRESS }}
NEXT_PUBLIC_TALLY_URL: ${{ vars.NEXT_PUBLIC_TALLY_URL }}
NEXT_PUBLIC_WALLETCONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLETCONNECT_ID }}

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install
run: |
pnpm install --frozen-lockfile --prefer-offline
- name: Build
run: |
pnpm run build
- name: Test
run: pnpm run test
working-directory: packages/contracts
1 change: 1 addition & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"**/*.{ts,js,tsx,jsx}": ["prettier --ignore-unknown --write", "eslint --fix"],
"**/*.sol": ["prettier --ignore-unknown --write", "solhint --fix --noPrompt"],
"*": ["prettier --ignore-unknown --write"]
}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
build/
dist/
artifacts/
cache/
typechain-types/
.next/
node_modules/
coverage/
Expand Down
13 changes: 12 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,16 @@
"semi": true,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all"
"trailingComma": "all",
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120,
"useTabs": false,
"singleQuote": false,
"semi": true
}
}
]
}
12 changes: 12 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-suicide": "error",
"avoid-sha3": "warn",
"max-line-length": ["warn", 120],
"quotes": ["error", "double"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"state-visibility": "error",
"immutable-vars-naming": ["warn", { "immutablesAsConstants": false }]
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"download-zkeys:prod": "lerna run download-zkeys:prod --scope=maci-coordinator",
"prettier": "prettier -c .",
"prettier:fix": "prettier -w .",
"lint": "eslint './**/**/*.ts' './**/**/*.tsx'",
"lint:fix": "pnpm run lint --fix",
"lint:ts": "eslint './**/**/*.ts' './**/**/*.tsx'",
"lint:ts:fix": "pnpm run lint:ts --fix",
"lint:sol": "solhint './packages/contracts/contracts/**/*.sol'",
"lint:sol:fix": "pnpm run lint:sol --fix --noPrompt",
"types": "lerna run types",
"docs": "lerna run docs",
"prepare": "is-ci || husky",
Expand Down Expand Up @@ -48,6 +50,7 @@
"lerna": "^8.1.7",
"lint-staged": "^15.2.7",
"prettier": "^3.3.3",
"solhint": "^5.0.3",
"typescript": "^5.5.4"
},
"config": {
Expand Down
27 changes: 27 additions & 0 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
MNEMONIC=
# api key for eth mainnet etherscan
ETH_ETHERSCAN_API_KEY=
# api key for optimism mainnet etherscan
OPTIMISM_ETHERSCAN_API_KEY=
# api key for scroll etherscan
SCROLL_ETHERSCAN_API_KEY=
# api key for base etherscan
BASE_ETHERSCAN_API_KEY=
# api key for arbitrum etherscan
ARB_ETHERSCAN_API_KEY=
# RPC url to talk to optimism mainnet
SEPOLIA_RPC_URL=
# RPC url to talk to optimism sepolia
OP_SEPOLIA_RPC_URL=
# RPC url to talk to scroll mainnet
SCROLL_RPC_URL=
# RPC url to talk to scroll sepolia
SCROLL_SEPOLIA_RPC_URL=
# Forking url for testing
FORKING_URL=
# Gas price to use for transactions
GAS_PRICE=
# Block number to fork from
FORKING_BLOCK_NUM=
# Hardhat logging level (true/false)
HARDHAT_LOGGING=
20 changes: 20 additions & 0 deletions packages/contracts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require("path");

module.exports = {
root: true,
extends: ["../../.eslintrc.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: path.resolve(__dirname, "./tsconfig.json"),
sourceType: "module",
typescript: true,
ecmaVersion: 2022,
experimentalDecorators: true,
requireConfigFile: false,
ecmaFeatures: {
classes: true,
impliedStrict: true,
},
warnOnUnsupportedTypeScriptVersion: true,
},
};
8 changes: 8 additions & 0 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docs
.env
deploy-config.json
deployed-contracts.json
cache
artifacts
typechain-types

4 changes: 4 additions & 0 deletions packages/contracts/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests
build/tests
.etherlime-store
solc
8 changes: 8 additions & 0 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# `maci-platform-contracts`

[![Actions Status][contracts-actions-badge]][contracts-actions-link]

This submodule contains all the Ethereum contracts and tests for MACI Platform.

[contracts-actions-badge]: https://github.com/privacy-scaling-explorations/maci/actions/workflows/contracts-build.yml/badge.svg
[contracts-actions-link]: https://github.com/privacy-scaling-explorations/maci/actions?query=workflow%3Acontracts
48 changes: 48 additions & 0 deletions packages/contracts/contracts/interfaces/IRecipientRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/// @title IRecipientRegistry
/// @notice An interface for a recipient registry
interface IRecipientRegistry {
/// @notice A struct representing a recipient
struct Recipient {
// recipient metadata url
bytes32 metadataUrl;
// recipient address
address recipient;
}

/// @notice Get a registry metadata url
/// @return The metadata url in bytes32 format
function getRegistryMetadataUrl() external view returns (bytes32);

/// @notice Add a recipient
/// @param recipient The recipient data
/// @return The index of the recipient
function addRecipient(Recipient calldata recipient) external returns (uint256);

/// @notice Remove a recipient
/// @param index The index of the recipient
function removeRecipient(uint256 index) external;

/// @notice Change a recipient
/// @param index The index of the recipient
function changeRecipient(uint256 index, Recipient calldata recipient) external view;

/// @notice Get a recipient
/// @param index The index of the recipient
/// @return The address of the recipient and metadata url or id
function getRecipient(uint256 index) external view returns (Recipient memory);

/// @notice Get the max number of recipients
/// @return The max number of recipients
function maxRecipients() external view returns (uint256);

/// @notice Set the max number of recipients
/// @return The max number of recipients
function setMaxRecipients(uint256 maxRecipients) external returns (uint256);

/// @notice Get the number of recipients
/// @return The number of recipients
function getRecipientCount() external view returns (uint256);
}
Loading

0 comments on commit d71bb81

Please sign in to comment.