From 45a509f9c4b03fe13b4f3eda8620571611806d5d Mon Sep 17 00:00:00 2001 From: Giacomo Date: Wed, 25 Sep 2024 16:50:47 +0200 Subject: [PATCH] chore(contracts): update configs for networks and deployments; minor CI improvements --- .../workflows/{pull-requests.yml => main.yml} | 35 +++++++++------ .prettierrc.json | 4 +- packages/contracts/.env.example | 10 +++++ packages/contracts/.gitignore | 4 +- packages/contracts/foundry.toml | 36 ++++++++++++--- packages/contracts/hardhat.config.ts | 44 ++++++++++++++++++- packages/contracts/package.json | 19 ++++---- yarn.lock | 34 ++++++++------ 8 files changed, 143 insertions(+), 43 deletions(-) rename .github/workflows/{pull-requests.yml => main.yml} (78%) create mode 100644 packages/contracts/.env.example diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/main.yml similarity index 78% rename from .github/workflows/pull-requests.yml rename to .github/workflows/main.yml index 5179e62..272ed41 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/main.yml @@ -1,23 +1,31 @@ -name: pull-requests +name: main on: + push: + branches: + - main pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: style: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - - name: Install Node.js + - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 cache: yarn - - name: "Install Foundry" - uses: "foundry-rs/foundry-toolchain@v1" + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 - name: Install dependencies run: yarn @@ -31,6 +39,9 @@ jobs: - packages/contracts/**/*.{js,json,ts,sol} docs: - apps/docs/**/* + packages: + - packages/**/*.{js,json,ts} + - '!packages/{contracts}/**/*' to_format: - '**/*.{cjs,js,json,jsx,md,mdx,sol,ts,tsx,yaml,yml}' to_lint: @@ -48,7 +59,7 @@ jobs: yarn workspace excubiae-docs build yarn workspace excubiae-docs format - - if: steps.changed-files.outputs.libraries_any_changed == 'true' + - if: steps.changed-files.outputs.packages_any_changed == 'true' name: Build packages run: yarn build:packages @@ -64,16 +75,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - - name: Install Node.js + - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 cache: yarn - - name: "Install Foundry" - uses: "foundry-rs/foundry-toolchain@v1" + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 - name: Install dependencies run: yarn @@ -85,9 +97,6 @@ jobs: files_yaml: | contracts: - packages/contracts/**/*.{js,json,ts,sol} - libraries: - - packages/**/*.{js,json,ts} - - '!packages/{circuits,contracts}/**/*' - if: steps.changed-files.outputs.contracts_any_changed == 'true' name: Build and Test contracts diff --git a/.prettierrc.json b/.prettierrc.json index 717fb52..f212424 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -2,5 +2,7 @@ "semi": false, "arrowParens": "always", "trailingComma": "none", - "plugins": ["prettier-plugin-solidity"] + "plugins": ["prettier-plugin-solidity"], + "printWidth": 120, + "tabWidth": 4 } diff --git a/packages/contracts/.env.example b/packages/contracts/.env.example new file mode 100644 index 0000000..e184c03 --- /dev/null +++ b/packages/contracts/.env.example @@ -0,0 +1,10 @@ +# core +DEFAULT_NETWORK=hardhat + +# report & verify +REPORT_GAS=false +COINMARKETCAP_API_KEY= +ETHERSCAN_API_KEY= + +# account +BACKEND_PRIVATE_KEY= \ No newline at end of file diff --git a/packages/contracts/.gitignore b/packages/contracts/.gitignore index 50a694e..ec7554d 100644 --- a/packages/contracts/.gitignore +++ b/packages/contracts/.gitignore @@ -18,5 +18,5 @@ node_modules /coverage /coverage.json -# Hardhat Ignition default folder for deployments against a local node -ignition/deployments/chain-31337 +# Hardhat Ignition +ignition/deployments/chain-* diff --git a/packages/contracts/foundry.toml b/packages/contracts/foundry.toml index 0d5e169..2529a98 100644 --- a/packages/contracts/foundry.toml +++ b/packages/contracts/foundry.toml @@ -1,6 +1,32 @@ [profile.default] -src = 'contracts/src' -out = 'out' -libs = ['node_modules'] -test = 'contracts/test' -cache_path = 'cache_forge' \ No newline at end of file + # core + libs = ['node_modules'] + cache_path = 'cache_forge' + test = 'contracts/test' + src = 'contracts/src' + out = 'out' + script = "contracts/scripts" + + # sol + auto_detect_solc = false + fuzz = { runs = 1_000 } + gas_reports = ["*"] + optimizer = true + optimizer_runs = 200_000 + solc = "0.8.27" + +[rpc_endpoints] + sepolia = "https://rpc2.sepolia.org" + +[etherscan] + sepolia = { key = "${ETHERSCAN_API_KEY}" } + +[fmt] + bracket_spacing = true + int_types = "long" + line_length = 120 + multiline_func_header = "all" + number_underscore = "thousands" + quote_style = "double" + tab_width = 4 + wrap_comments = true \ No newline at end of file diff --git a/packages/contracts/hardhat.config.ts b/packages/contracts/hardhat.config.ts index fc92787..da82453 100644 --- a/packages/contracts/hardhat.config.ts +++ b/packages/contracts/hardhat.config.ts @@ -1,14 +1,56 @@ import { HardhatUserConfig } from "hardhat/config" +import { resolve } from "path" +import { config as dotenvConfig } from "dotenv" import "@nomicfoundation/hardhat-toolbox" import "@nomicfoundation/hardhat-foundry" +import "@nomicfoundation/hardhat-verify" +import "hardhat-gas-reporter" + +dotenvConfig({ path: resolve(__dirname, ".env") }) + +const backendPrivateKey = process.env.BACKEND_PRIVATE_KEY const config: HardhatUserConfig = { - solidity: "0.8.27", + solidity: { + version: "0.8.27", + settings: { + optimizer: { + enabled: true, + runs: 200 + } + } + }, paths: { sources: "./contracts/src", tests: "./test", cache: "./cache", artifacts: "./artifacts" + }, + networks: { + hardhat: { + chainId: 1337, + allowUnlimitedContractSize: true + }, + sepolia: { + chainId: 11155111, + url: "https://rpc2.sepolia.org", + accounts: !backendPrivateKey ? [] : [backendPrivateKey] + } + }, + gasReporter: { + currency: "USD", + enabled: process.env.REPORT_GAS === "true", + coinmarketcap: process.env.COINMARKETCAP_API_KEY + }, + typechain: { + target: "ethers-v6" + }, + etherscan: { + apiKey: process.env.ETHERSCAN_API_KEY, + customChains: [] + }, + sourcify: { + enabled: true } } diff --git a/packages/contracts/package.json b/packages/contracts/package.json index bbc9588..56db7de 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -10,10 +10,12 @@ "compile": "yarn compile:hardhat && yarn compile:forge", "compile:hardhat": "hardhat compile", "compile:forge": "forge compile", - "deploy": "hardhat deploy", + "deploy:lock": "hardhat ignition deploy ignition/modules/Lock.ts", + "deploy:lock-sepolia": "hardhat ignition deploy ignition/modules/Lock.ts --network sepolia", + "verify:lock-sepolia": "hardhat ignition verify sepolia-deployment", "test": "yarn test:hardhat && yarn test:forge", "test:hardhat": "hardhat test", - "test:forge": "forge test", + "test:forge": "forge test -vvv", "test:report-gas": "REPORT_GAS=true yarn test && forge test --gas-report", "test:coverage": "hardhat coverage && forge coverage", "typechain": "hardhat typechain", @@ -22,14 +24,14 @@ "lint:fix": "solhint 'contracts/**/*.sol' --fix --noPrompt" }, "devDependencies": { - "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", - "@nomicfoundation/hardhat-ethers": "^3.0.0", + "@nomicfoundation/hardhat-chai-matchers": "^2.0.8", + "@nomicfoundation/hardhat-ethers": "^3.0.8", "@nomicfoundation/hardhat-foundry": "^1.1.2", "@nomicfoundation/hardhat-ignition": "^0.15.5", - "@nomicfoundation/hardhat-ignition-ethers": "^0.15.0", - "@nomicfoundation/hardhat-network-helpers": "^1.0.0", + "@nomicfoundation/hardhat-ignition-ethers": "^0.15.5", + "@nomicfoundation/hardhat-network-helpers": "^1.0.12", "@nomicfoundation/hardhat-toolbox": "^5.0.0", - "@nomicfoundation/hardhat-verify": "^2.0.0", + "@nomicfoundation/hardhat-verify": "^2.0.11", "@nomicfoundation/ignition-core": "^0.15.5", "@typechain/ethers-v6": "^0.5.0", "@typechain/hardhat": "^9.0.0", @@ -37,12 +39,13 @@ "@types/mocha": ">=9.1.0", "@types/node": "^22.6.1", "chai": "^4.2.0", + "dotenv": "^16.4.5", "ethers": "^6.4.0", "forge-std": "github:foundry-rs/forge-std#v1.9.2", "hardhat": "^2.22.11", "hardhat-gas-reporter": "^1.0.8", "solhint": "^5.0.3", - "solidity-coverage": "^0.8.1", + "solidity-coverage": "^0.8.13", "ts-node": "^10.9.2", "typechain": "^8.3.0", "typescript": "5.3" diff --git a/yarn.lock b/yarn.lock index e072eb9..ad764ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3514,7 +3514,7 @@ __metadata: languageName: node linkType: hard -"@nomicfoundation/hardhat-chai-matchers@npm:^2.0.0": +"@nomicfoundation/hardhat-chai-matchers@npm:^2.0.8": version: 2.0.8 resolution: "@nomicfoundation/hardhat-chai-matchers@npm:2.0.8" dependencies: @@ -3531,7 +3531,7 @@ __metadata: languageName: node linkType: hard -"@nomicfoundation/hardhat-ethers@npm:^3.0.0": +"@nomicfoundation/hardhat-ethers@npm:^3.0.8": version: 3.0.8 resolution: "@nomicfoundation/hardhat-ethers@npm:3.0.8" dependencies: @@ -3555,7 +3555,7 @@ __metadata: languageName: node linkType: hard -"@nomicfoundation/hardhat-ignition-ethers@npm:^0.15.0": +"@nomicfoundation/hardhat-ignition-ethers@npm:^0.15.5": version: 0.15.5 resolution: "@nomicfoundation/hardhat-ignition-ethers@npm:0.15.5" peerDependencies: @@ -3585,7 +3585,7 @@ __metadata: languageName: node linkType: hard -"@nomicfoundation/hardhat-network-helpers@npm:^1.0.0": +"@nomicfoundation/hardhat-network-helpers@npm:^1.0.12": version: 1.0.12 resolution: "@nomicfoundation/hardhat-network-helpers@npm:1.0.12" dependencies: @@ -3622,7 +3622,7 @@ __metadata: languageName: node linkType: hard -"@nomicfoundation/hardhat-verify@npm:^2.0.0": +"@nomicfoundation/hardhat-verify@npm:^2.0.11": version: 2.0.11 resolution: "@nomicfoundation/hardhat-verify@npm:2.0.11" dependencies: @@ -4508,7 +4508,14 @@ __metadata: languageName: node linkType: hard -"@types/chai@npm:*, @types/chai@npm:^4.2.0": +"@types/chai@npm:*": + version: 5.0.0 + resolution: "@types/chai@npm:5.0.0" + checksum: 10/a6c03aa6b6d59ad40ddb48d07807690efb874628c15b9d89c17d97045a9305a487933398c1e5b5f94087b1a6a9a67a7c828eb9b635104526fd25bb5f9d4c4175 + languageName: node + linkType: hard + +"@types/chai@npm:^4.2.0": version: 4.3.19 resolution: "@types/chai@npm:4.3.19" checksum: 10/5ca7a48ec1c792e536bc228911f442c31eb8a24f1c3531f8a5e1e949590a6a045be17a2ec5a3d83f63dae8d59dd93dc5f6ca7355b9c1a9f003c553a733b2e591 @@ -9366,14 +9373,14 @@ __metadata: version: 0.0.0-use.local resolution: "excubiae-contracts@workspace:packages/contracts" dependencies: - "@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.0" - "@nomicfoundation/hardhat-ethers": "npm:^3.0.0" + "@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.8" + "@nomicfoundation/hardhat-ethers": "npm:^3.0.8" "@nomicfoundation/hardhat-foundry": "npm:^1.1.2" "@nomicfoundation/hardhat-ignition": "npm:^0.15.5" - "@nomicfoundation/hardhat-ignition-ethers": "npm:^0.15.0" - "@nomicfoundation/hardhat-network-helpers": "npm:^1.0.0" + "@nomicfoundation/hardhat-ignition-ethers": "npm:^0.15.5" + "@nomicfoundation/hardhat-network-helpers": "npm:^1.0.12" "@nomicfoundation/hardhat-toolbox": "npm:^5.0.0" - "@nomicfoundation/hardhat-verify": "npm:^2.0.0" + "@nomicfoundation/hardhat-verify": "npm:^2.0.11" "@nomicfoundation/ignition-core": "npm:^0.15.5" "@openzeppelin/contracts": "npm:^5.0.2" "@typechain/ethers-v6": "npm:^0.5.0" @@ -9382,12 +9389,13 @@ __metadata: "@types/mocha": "npm:>=9.1.0" "@types/node": "npm:^22.6.1" chai: "npm:^4.2.0" + dotenv: "npm:^16.4.5" ethers: "npm:^6.4.0" forge-std: "github:foundry-rs/forge-std#v1.9.2" hardhat: "npm:^2.22.11" hardhat-gas-reporter: "npm:^1.0.8" solhint: "npm:^5.0.3" - solidity-coverage: "npm:^0.8.1" + solidity-coverage: "npm:^0.8.13" ts-node: "npm:^10.9.2" typechain: "npm:^8.3.0" typescript: "npm:5.3" @@ -17765,7 +17773,7 @@ __metadata: languageName: node linkType: hard -"solidity-coverage@npm:^0.8.1": +"solidity-coverage@npm:^0.8.13": version: 0.8.13 resolution: "solidity-coverage@npm:0.8.13" dependencies: