Skip to content

Commit 6473202

Browse files
authored
Merge pull request #8 from solidstate-network/hh3
Update for Hardhat 3
2 parents 1efa2aa + 4d8e30f commit 6473202

32 files changed

+4522
-2736
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.tsbuildinfo
12
artifacts/
23
cache/
34
dist/

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
yarn run lint-staged
2+
pnpm lint-staged --hide-unstaged --hide-untracked

.lintstagedrc.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"trailingComma": "all",
55
"bracketSpacing": true,
66
"plugins": [
7-
"prettier-plugin-ejs",
7+
"prettier-plugin-packagejson",
88
"prettier-plugin-solidity",
99
"@trivago/prettier-plugin-sort-imports"
1010
]

README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Hardhat Storage Layout Diff
1+
# Hardhat Storage Layout Inspector
22

33
Inspect and compare Solidity smart contract storage layouts.
44

@@ -7,17 +7,26 @@ Inspect and compare Solidity smart contract storage layouts.
77
## Installation
88

99
```bash
10-
npm install --save-dev @solidstate/hardhat-storage-layout-diff
10+
npm install --save-dev @solidstate/hardhat-storage-layout-inspector
1111
# or
12-
yarn add --dev @solidstate/hardhat-storage-layout-diff
12+
pnpm add -D @solidstate/hardhat-storage-layout-inspector
1313
```
1414

1515
## Usage
1616

1717
Load plugin in Hardhat config:
1818

1919
```javascript
20-
require('@solidstate/hardhat-storage-layout-diff');
20+
import HardhatStorageLayoutInspector from '@solidstate/hardhat-storage-layout-inspector';
21+
22+
const config: HardhatUserConfig = {
23+
plugins: [
24+
HardhatStorageLayoutInspector,
25+
],
26+
storageLayoutDiff: {
27+
... // see table for configuration options
28+
},
29+
};
2130
```
2231

2332
Add configuration under the `storageLayoutDiff` key:
@@ -31,42 +40,46 @@ Add configuration under the `storageLayoutDiff` key:
3140
| `except` | `Array` of `String` matchers used to exclude contracts | `[]` |
3241
| `spacing` | number of spaces per indentation level of formatted output | `2` |
3342

43+
Additional configuration options are provided by [`@solidstate/hardhat-git`](https://www.npmjs.com/package/@solidstate/hardhat-git), which is included as a dependency.
44+
3445
Export storage layouts:
3546

3647
```bash
3748
npx hardhat export-storage-layout
3849
# or
39-
yarn run hardhat export-storage-layout
50+
pnpm hardhat export-storage-layout
4051
```
4152

42-
Compare two contracts:
53+
Inspect a contract's storage layout:
4354

4455
```bash
45-
npx hardhat diff-storage-layout [CONTRACT_A_FULLY_QUALIFIED_NAME] [CONTRACT_B_FULLY_QUALIFIED_NAME]
56+
npx hardhat inspect-storage-layout [CONTRACT_IDENTIFIER]
4657
# or
47-
yarn run hardhat diff-storage-layout [CONTRACT_A_FULLY_QUALIFIED_NAME] [CONTRACT_B_FULLY_QUALIFIED_NAME]
58+
pnpm hardhat inspect-storage-layout [CONTRACT_IDENTIFIER]
4859
```
4960

50-
Include the optional `--a-ref` and/or `--b-ref` arguments to specify the git reference where contracts `a` and `b` are defined, respectively.
51-
52-
Compare a contract to an exported JSON layout:
61+
Compare two contracts:
5362

5463
```bash
55-
npx hardhat storage-layout-check --source [PATH_TO_LAYOUT_JSON] --b [CONTRACT_B_FULLY_QUALIFIED_NAME]
64+
npx hardhat diff-storage-layout [CONTRACT_A_IDENTIFIER] [CONTRACT_B_IDENTIFIER]
5665
# or
57-
yarn run hardhat storage-layout-check --source [PATH_TO_LAYOUT_JSON] --b [CONTRACT_B_FULLY_QUALIFIED_NAME]
66+
pnpm hardhat diff-storage-layout [CONTRACT_A_IDENTIFIER] [CONTRACT_B_IDENTIFIER]
5867
```
5968

69+
A contract identifier may be a name, a fully qualified name, or a path to a JSON file containing a storage layout.
70+
71+
Include the optional git rev options to look up a contract identifier at a particular git revision.
72+
6073
## Development
6174

62-
Install dependencies via Yarn:
75+
Install dependencies via pnpm:
6376

6477
```bash
65-
yarn install
78+
pnpm install
6679
```
6780

6881
Setup Husky to format code on commit:
6982

7083
```bash
71-
yarn prepare
84+
pnpm prepare
7285
```

contracts/Offset.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity *;
3+
4+
contract SlotsZero {}
5+
6+
contract SlotsOne {
7+
uint256 one;
8+
}
9+
10+
contract SlotsOneOffsetOne is SlotsOne layout at 1 {}
11+
12+
contract SlotsTwo is SlotsOne {
13+
uint256 two;
14+
}
15+
16+
contract SlotsTwoOffsetOne is SlotsTwo layout at 1 {}
17+
18+
contract SlotsTwoOffsetTwo is SlotsTwo layout at 2 {}

contracts/Test.sol

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
1-
// SPDX-License-Identifier: UNLICENSED
1+
// SPDX-License-Identifier: MIT
22
pragma solidity *;
33

4-
contract Test {
5-
enum E {
6-
ONE,
7-
TWO
8-
}
9-
10-
struct Struct {
11-
address a;
12-
E e;
13-
address b;
14-
E f;
15-
}
4+
import { E, S } from './Types.sol';
165

17-
Struct str;
6+
contract Test {
7+
// slots 0-1
8+
S str;
9+
// slot 2
1810
mapping(address => bool) map;
19-
uint128[5] five;
11+
// slots 3-5
12+
uint128[5] array;
13+
// slot 6
2014
bool b0;
2115
bool b1;
22-
bool[4][2] bools;
23-
}
24-
25-
contract Test2 {
26-
bytes29 _b;
27-
uint128 a;
28-
uint64 b;
29-
uint128 u;
30-
}
31-
32-
contract Test3 {
33-
bytes30 _b;
34-
uint64 a;
35-
uint128 b;
36-
uint128 u;
37-
uint64 uu;
16+
// slots 7-8
17+
bool[4][2] nestedArray;
3818
}

contracts/Types.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity *;
3+
4+
enum E {
5+
ONE,
6+
TWO
7+
}
8+
9+
struct S {
10+
address a;
11+
E e;
12+
bytes16 b;
13+
}

hardhat.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import './src/index';
1+
import HardhatStorageLayoutInspector from './src/index.js';
22
import { HardhatUserConfig } from 'hardhat/config';
33

44
const config: HardhatUserConfig = {
5-
solidity: '0.8.28',
5+
solidity: '0.8.29',
6+
plugins: [HardhatStorageLayoutInspector],
67
};
78

89
export default config;

lint-staged.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
'*.{js,ts,sol,json,md}': ['prettier --write'],
3+
'*': () => ['knip', 'knip --production'],
4+
};

0 commit comments

Comments
 (0)