From 7a8c974f3984809a055fa4299b25552d3f49d9d4 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Wed, 14 Feb 2024 16:31:50 +0000 Subject: [PATCH] build: install openzeppelin docs: update README.md file --- README.md | 21 +++++++++++++++++---- package.json | 4 +++- remappings.txt | 7 ++++--- scripts/foundry/Base.s.sol | 2 +- test/foundry/Base.t.sol | 2 +- yarn.lock | 26 +++++++++++++++++++++----- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cfb7e95..5d9f216 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,7 @@ A Foundry + Hardhat based template for developing Solidity smart contracts, with deploy smart contracts - [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing -- [Solhint Community](https://github.com/solhint-community/solhint-community): code linter -- [Prettier Plugin Solidity](https://github.com/prettier-solidity/prettier-plugin-solidity): code - formatter +- [Solhint](https://github.com/protofire/solhint): linter for Solidity code ## Table of Contents @@ -78,7 +76,7 @@ $ cd my-project $ forge init --template ahmedali8/foundry-hardhat-template ``` -Recommended node version is v18.x +Recommended node version is v20.x If you have [nvm](https://github.com/nvm-sh/nvm) then run: @@ -145,6 +143,21 @@ Note though that by default it injects `.env.example` env variables into github You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml). +## Installing Dependencies + +Foundry typically uses git submodules to manage dependencies, but this template uses Node.js +packages because [submodules don't scale](https://twitter.com/PaulRBerg/status/1736695487057531328). + +This is how to install dependencies: + +1. Install the dependency using your preferred package manager, e.g. + `yarn add dependency-name:dependency-url` + - Use this syntax to install from GitHub: `yarn add repo-name@github:username/repo-name#tag-name` +2. Add a remapping for the dependency in [remappings.txt](./remappings.txt), e.g. + `dependency-name=node_modules/dependency-name` + +Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example. + # Usage ### Pre Requisites diff --git a/package.json b/package.json index 316bfcb..8d13ee3 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@nomicfoundation/hardhat-network-helpers": "^1.0.10", "@nomicfoundation/hardhat-toolbox": "^4.0.0", "@nomicfoundation/hardhat-verify": "^2.0.4", + "@openzeppelin/contracts": "^5.0.1", "@primitivefi/hardhat-dodoc": "^0.2.3", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@typechain/ethers-v6": "^0.5.1", @@ -51,11 +52,12 @@ "chalk": "4.1.2", "cross-env": "^7.0.3", "dotenv": "^16.4.4", + "ds-test": "github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "ethers": "6.11.0", "evm-bn": "^1.1.2", - "forge-std": "github:foundry-rs/forge-std#v1.7.5", + "forge-std": "github:foundry-rs/forge-std#v1.7.6", "fs-extra": "^11.2.0", "hardhat": "2.20.0", "hardhat-contract-sizer": "2.10.0", diff --git a/remappings.txt b/remappings.txt index 156bcd4..921bf15 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,3 +1,4 @@ -ds-test/=node_modules/forge-std/lib/ds-test/src/ -forge-std/=node_modules/forge-std/src/ -hardhat/=node_modules/hardhat/ \ No newline at end of file +ds-test/=node_modules/ds-test/src/ +forge-std/=node_modules/forge-std/ +hardhat/=node_modules/hardhat/ +@openzeppelin/=node_modules/@openzeppelin/ \ No newline at end of file diff --git a/scripts/foundry/Base.s.sol b/scripts/foundry/Base.s.sol index a163fc9..b9eb127 100644 --- a/scripts/foundry/Base.s.sol +++ b/scripts/foundry/Base.s.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.23 <=0.9.0; -import { Script } from "forge-std/Script.sol"; +import { Script } from "forge-std/src/Script.sol"; abstract contract BaseScript is Script { /// @dev Included to enable compilation of the script without a $MNEMONIC environment variable. diff --git a/test/foundry/Base.t.sol b/test/foundry/Base.t.sol index 862f31e..7407248 100644 --- a/test/foundry/Base.t.sol +++ b/test/foundry/Base.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.23 <0.9.0; -import { Test } from "forge-std/Test.sol"; +import { Test } from "forge-std/src/Test.sol"; import { Lock } from "contracts/Lock.sol"; diff --git a/yarn.lock b/yarn.lock index 3b1d265..1657a4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30,6 +30,7 @@ __metadata: "@nomicfoundation/hardhat-network-helpers": "npm:^1.0.10" "@nomicfoundation/hardhat-toolbox": "npm:^4.0.0" "@nomicfoundation/hardhat-verify": "npm:^2.0.4" + "@openzeppelin/contracts": "npm:^5.0.1" "@primitivefi/hardhat-dodoc": "npm:^0.2.3" "@trivago/prettier-plugin-sort-imports": "npm:^4.3.0" "@typechain/ethers-v6": "npm:^0.5.1" @@ -44,11 +45,12 @@ __metadata: chalk: "npm:4.1.2" cross-env: "npm:^7.0.3" dotenv: "npm:^16.4.4" + ds-test: "github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0" eslint: "npm:^8.56.0" eslint-config-prettier: "npm:^9.1.0" ethers: "npm:6.11.0" evm-bn: "npm:^1.1.2" - forge-std: "github:foundry-rs/forge-std#v1.7.5" + forge-std: "github:foundry-rs/forge-std#v1.7.6" fs-extra: "npm:^11.2.0" hardhat: "npm:2.20.0" hardhat-contract-sizer: "npm:2.10.0" @@ -1494,6 +1496,13 @@ __metadata: languageName: node linkType: hard +"@openzeppelin/contracts@npm:^5.0.1": + version: 5.0.1 + resolution: "@openzeppelin/contracts@npm:5.0.1" + checksum: 10/d0a9ae98c2486eb3c4a3fa31cb9d4e8ea21aef3f1d0d4709a6c8550be0133ccfbad541e524980356b802c10c47de24c49844fac1b746980dbd5b560bd1762301 + languageName: node + linkType: hard + "@pkgjs/parseargs@npm:^0.11.0": version: 0.11.0 resolution: "@pkgjs/parseargs@npm:0.11.0" @@ -3277,6 +3286,13 @@ __metadata: languageName: node linkType: hard +"ds-test@github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0": + version: 1.0.0 + resolution: "ds-test@https://github.com/dapphub/ds-test.git#commit=e282159d5170298eb2455a6c05280ab5a73a4ef0" + checksum: 10/a63cada107d8f2775934bc580f04cb6f6509f843cb41cbc3a617e77b2e628a86d7fd858f964e7e2d6f41c3797c0e16ec2d87a6cb4c6187c5b6c2bc969ccae4b3 + languageName: node + linkType: hard + "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" @@ -3923,10 +3939,10 @@ __metadata: languageName: node linkType: hard -"forge-std@github:foundry-rs/forge-std#v1.7.5": - version: 1.7.5 - resolution: "forge-std@https://github.com/foundry-rs/forge-std.git#commit=36c303b7ffdd842d06b1ec2744c9b9b5fb3083f3" - checksum: 10/3e21412f608e4be5136bc1fcc06e30c85554a78940385187f8d37d04db23a471f7f8d82644cf303a8b21e5d559c52b326c49a1ef43c017bb346fde19cf5f2932 +"forge-std@github:foundry-rs/forge-std#v1.7.6": + version: 1.7.6 + resolution: "forge-std@https://github.com/foundry-rs/forge-std.git#commit=ae570fec082bfe1c1f45b0acca4a2b4f84d345ce" + checksum: 10/40f626df42a21f9b14f66489d5c4de7d4e14fd96e92629c2f68dac636b454af4453fb44c0dbf9c10e0e15114b3b81cf0a98f15b5dae55b9c3d8738de48c2bea7 languageName: node linkType: hard