Skip to content

Commit 2c39ac8

Browse files
authored
Merge pull request #199 from Nalon/hh2/upgrade/contracts-1.5.0
Bump @chainlink/contracts to v1.5.0 + Add remapping support
2 parents 703e6a9 + 0d70c16 commit 2c39ac8

File tree

10 files changed

+701
-146
lines changed

10 files changed

+701
-146
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Root
2+
* @zeuslawyer @andrejrakic @thodges-gh @Nalon @smartcontractkit/devrel

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
</a>
66
</p>
77
<br/>
8-
9-
## Tip
8+
9+
> [!IMPORTANT]
10+
> This branch contains the Hardhat 2 starter kit. For Hardhat 3, see the [hardhat-3 branch](https://github.com/smartcontractkit/hardhat-starter-kit/tree/hardhat-3). This branch uses Solidity [Remapping](#import-remapping) and the [hardhat-preprocessor](https://www.npmjs.com/package/hardhat-preprocessor) plugin to resolve imports correctly. <b>If you have errors when compiling dependencies please consult the [Remapping](#import-remapping) section of this README. </b>
11+
12+
## Tip
1013
> Please be attention that Chainlink Any API is removed from this starter kit because Chainlink Any API is currently replaced by [Chainlink Functions](https://docs.chain.link/chainlink-functions). Please find the starter kit for Chainlink Functions [here](https://github.com/smartcontractkit/functions-hardhat-starter-kit)
1114
1215
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/smartcontractkit/hardhat-starter-kit)
@@ -35,6 +38,7 @@
3538
- [Estimating Gas](#estimating-gas)
3639
- [Code Coverage](#code-coverage)
3740
- [Fuzzing](#fuzzing)
41+
- [Import Remapping](#import-remapping)
3842
- [Contributing](#contributing)
3943
- [Thank You!](#thank-you)
4044
- [Resources](#resources)
@@ -176,7 +180,7 @@ You can get one for free from [Alchemy](https://www.alchemy.com/), [Infura](http
176180

177181
This is your private key from your wallet, ie [MetaMask](https://metamask.io/). This is needed for deploying contracts to public networks. You can optionally set your `MNEMONIC` environment variable instead with some changes to the `hardhat.config.js`.
178182

179-
![WARNING](https://via.placeholder.com/15/f03c15/000000?text=+) **WARNING** ![WARNING](https://via.placeholder.com/15/f03c15/000000?text=+)
183+
**⚠️ WARNING ⚠️**
180184

181185
When developing, it's best practice to use a Metamask that isn't associated with any real money. A good way to do this is to make a new browser profile (on Chrome, Brave, Firefox, etc) and install Metamask on that browser, and never send this wallet money.
182186

@@ -436,6 +440,24 @@ To exit Echidna type
436440
exit
437441
```
438442

443+
# Import Remapping
444+
445+
In Solidity, [remapping](https://docs.soliditylang.org/en/latest/path-resolution.html#import-remapping) is a way to define shorthand import paths so that developers can avoid writing long relative paths when importing contracts. For example, instead of writing `import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";`, you could define a remapping such as `@openzeppelin/=node_modules/@openzeppelin/` and simply use `import "@openzeppelin/contracts/token/ERC20/ERC20.sol";`. This makes contract imports cleaner, easier to maintain, and more consistent across different projects. Remappings are commonly used in development environments like [Foundry](https://getfoundry.sh/guides/project-setup/dependencies/#remapping-dependencies) or [Hardhat 3](https://hardhat.org/docs/), but Hardhat 2 does not support them natively.
446+
447+
To work around this limitation, you can use the [hardhat-preprocessor](https://www.npmjs.com/package/hardhat-preprocessor) plugin, which preprocesses Solidity files before compilation and rewrites the imports according to your remapping rules. This plugin works by extending the available configuration options of the expected [`HardhatUserConfig`](https://v2.hardhat.org/hardhat-runner/docs/config) object to include a preprocess property.
448+
449+
This starter kit contains example code of this workaround in action within the [`remappings-helper.js`](./remappings-helper.js) file, and uses the remappings located within [`remappings.txt`](./remappings.txt).
450+
451+
> [!WARNING]
452+
> The [hardhat-preprocessor](https://www.npmjs.com/package/hardhat-preprocessor) plugin is a third-party plugin.
453+
> Use it at your own discretion and review its source before adopting it in any production environments.
454+
455+
## Adding your own remappings
456+
457+
As your project expands, you may find the need for more dependencies. This may result in the requirement of additional remappings. To include more remappings, simply add your remapping to the `remappings.txt` file.
458+
459+
The expected syntax is: `<prefix>=<resolved-path>`
460+
439461
# Contributing
440462

441463
Contributions are always welcome! Open a PR or an issue!

hardhat.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require("@nomicfoundation/hardhat-toolbox")
22
require("./tasks")
33
require("dotenv").config()
4+
const {remapImportPaths} = require("./remappings-helper.js")
45

56
const COMPILER_SETTINGS = {
67
optimizer: {
@@ -132,4 +133,5 @@ module.exports = {
132133
mocha: {
133134
timeout: 300000, // 300 seconds max for running tests
134135
},
136+
preprocess: remapImportPaths()
135137
}

0 commit comments

Comments
 (0)