Skip to content

Update for Hardhat 3 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 113 commits into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
1bac604
update hardhat dependencies, configure package as module
ItsNickBarry Apr 18, 2025
ad3932c
fix imports, export HardhatPlugin object
ItsNickBarry Apr 18, 2025
0249c0c
Merge branch 'master' into hh3
ItsNickBarry Apr 19, 2025
9a8b352
export HardhatPlugin object
ItsNickBarry Apr 19, 2025
fe91182
update tasks to Hardhat 3 API, register tasks in HardhatPlugin
ItsNickBarry Apr 19, 2025
3cc2e77
move task action functions to actions/ directory
ItsNickBarry Apr 19, 2025
770406b
load plugin into test config
ItsNickBarry Apr 19, 2025
2ba8158
fix lib file
ItsNickBarry Apr 19, 2025
a5a2145
fix build script
ItsNickBarry Apr 19, 2025
d6bdaf6
run clean script before build script
ItsNickBarry Apr 20, 2025
a4a0edd
use patch-package to patch hardhat output selection in development
ItsNickBarry Apr 20, 2025
9619276
replace extendConfig call with config hook
ItsNickBarry Apr 20, 2025
f3f710a
exclude artifacts from tsc
ItsNickBarry Apr 20, 2025
51cc205
add missing action export
ItsNickBarry Apr 20, 2025
73f5305
compile before all tasks
ItsNickBarry Apr 20, 2025
3989b3d
support non-fully-qualifed contract names
ItsNickBarry Apr 20, 2025
7902932
remove getCollatedStorageLayout function
ItsNickBarry Apr 20, 2025
f470b85
add git ref option to inspect task
ItsNickBarry Apr 20, 2025
15053cf
update test contract for git testing
ItsNickBarry Apr 20, 2025
a51bcf4
add callAtGitRef helper and getRawStorageLayoutFromArtifact callback
ItsNickBarry Apr 20, 2025
eb2fcc8
rename getRawStorageLayout to loadRawStorageLayout
ItsNickBarry Apr 20, 2025
a4d4ce2
read storage layout from file if path to .json is passed
ItsNickBarry Apr 20, 2025
707aca5
remove obsolete storage-layout-check task
ItsNickBarry Apr 20, 2025
fce55ff
update readme
ItsNickBarry Apr 20, 2025
1150c95
do not initialize git repository, wrap git checkout errors in Hardhat…
ItsNickBarry Apr 20, 2025
2c084c6
invert if condition to reduce nesting
ItsNickBarry Apr 20, 2025
0b061cb
remove obsolete ejs and mocha utilities
ItsNickBarry Apr 21, 2025
a5a1417
Merge branch 'solidstate' into hh3
ItsNickBarry Apr 21, 2025
2594b6b
avoid git checkout for file inputs
ItsNickBarry Apr 21, 2025
d407541
fix structure of loadRawStorageLayout
ItsNickBarry Apr 21, 2025
fc45bed
allow passing hre into bound function
ItsNickBarry Apr 21, 2025
f3b8a8b
add todo note
ItsNickBarry Apr 21, 2025
6231cb4
run patch-package on postinstall
ItsNickBarry Apr 21, 2025
76c0510
add getTmpHreAtGitRef helper, avoid double recompilation after git ch…
ItsNickBarry Apr 21, 2025
4f43935
remove callback pattern
ItsNickBarry Apr 21, 2025
c8019b0
remove unused intermediate variable
ItsNickBarry Apr 21, 2025
a5f44bf
update hardhat output selection patch
ItsNickBarry May 1, 2025
3b58f32
update hardhat output selection patch
ItsNickBarry May 1, 2025
e17a5e3
upgrade dependencies
ItsNickBarry May 5, 2025
e933705
handle git and npm errors
ItsNickBarry May 5, 2025
eb8684d
load remote createHardhatRuntimeEnvironment function
ItsNickBarry May 5, 2025
d1daa28
load remote findClosestHardhatConfig function
ItsNickBarry May 5, 2025
d3bff18
add todo notes
ItsNickBarry May 5, 2025
e633dbc
use indicator file to detect failed temporary git clone setup
ItsNickBarry May 5, 2025
1164293
replace pendingSetupIndicatorFile with successfulSetupIndicatorFile
ItsNickBarry May 5, 2025
5d09e93
upgrade dependencies
ItsNickBarry May 7, 2025
7129ea1
use prettier-plugin-packagejson to sort package.json
ItsNickBarry May 7, 2025
cc1e3a0
move types to types.ts
ItsNickBarry May 7, 2025
39923be
move print functions to separate file
ItsNickBarry May 7, 2025
de8ba31
do not export visualizeSlot function
ItsNickBarry May 7, 2025
0ebdc23
upgrade dependencies, remove patch-package and hardhat patch
ItsNickBarry May 7, 2025
0fd775a
rename load functions
ItsNickBarry May 7, 2025
6b4708c
support passing HookContext to getTmpHreAtGitRef, do not return HRE w…
ItsNickBarry May 8, 2025
c256f5e
use undefined default value for ref task options
ItsNickBarry May 8, 2025
f84ba04
use undefined ref options in task actions
ItsNickBarry May 8, 2025
78ec191
export compile task name
ItsNickBarry May 8, 2025
e762638
process git refs in tasks
ItsNickBarry May 8, 2025
20967ff
add --no-compile flag to all tasks
ItsNickBarry May 8, 2025
92df2f1
use hardhat-git plugin
ItsNickBarry May 10, 2025
29f3201
upgrade dependencies
ItsNickBarry May 11, 2025
9007357
update git hre factory calls, delegate npmInstall configuration to ha…
ItsNickBarry May 11, 2025
54e4695
import NewTaskActionFunction as type
ItsNickBarry May 11, 2025
d485920
set export task description
ItsNickBarry May 11, 2025
373321b
use knip
ItsNickBarry May 16, 2025
43d5b56
fix task action file extension
ItsNickBarry May 16, 2025
576eeb8
remove ts-node
ItsNickBarry May 16, 2025
afe49e0
set exports in package.json, remove dist/src/ nesting
ItsNickBarry May 16, 2025
9f8456a
fix export paths
ItsNickBarry May 17, 2025
5199a1d
upgrade dependencies
ItsNickBarry May 20, 2025
d6eb10a
run knip via lint-staged
ItsNickBarry May 20, 2025
b155341
switch from yarn to pnpm
ItsNickBarry May 20, 2025
b774a17
remove option to load tracked files at git ref, remove simple-git dep…
ItsNickBarry May 26, 2025
b92f2e2
validate storage layout json
ItsNickBarry May 26, 2025
03a9ec0
user hardhat utils to read json file, add validation note
ItsNickBarry May 26, 2025
e53275b
set hardhat-utils as peer dependency
ItsNickBarry May 26, 2025
cc97874
add prepareHardhatRuntimeEnvironment wrapper
ItsNickBarry May 26, 2025
a45927b
upgrade dependencies
ItsNickBarry May 26, 2025
dcd6e3b
pass config hook to git hre
ItsNickBarry May 26, 2025
c12cad7
move compilation of git ref HREs to prepare function
ItsNickBarry May 26, 2025
a091e78
upgrade dependencies
ItsNickBarry May 27, 2025
abf4e80
rename git reference to revision
ItsNickBarry May 27, 2025
e7c2ff9
use experimental version of lint-staged with support for hiding all u…
ItsNickBarry May 28, 2025
7442305
run knip in production mode on commit
ItsNickBarry May 28, 2025
907d0d6
use readJsonFile helper to read build info
ItsNickBarry May 28, 2025
8bee15e
remove redundant error
ItsNickBarry May 28, 2025
ed2956d
clean up variables
ItsNickBarry May 28, 2025
279d695
remove obsolete or redundant todo notes
ItsNickBarry May 28, 2025
35a4425
use tsx for tests, test loadStorageLayout function
ItsNickBarry May 29, 2025
4e439ff
test collateStorageLayout function, simplify and document test contract
ItsNickBarry May 30, 2025
7194198
compile before testing
ItsNickBarry May 30, 2025
765cc46
rename mergeCollatedSlots to mergeCollatedStorageLayouts
ItsNickBarry May 30, 2025
11d0e7b
add second test contract
ItsNickBarry May 30, 2025
74a3d06
include unpaired slot entries in output
ItsNickBarry May 30, 2025
5aa6c13
rename storage variable in TestModified contract
ItsNickBarry May 30, 2025
0153302
include unpaired slots in output
ItsNickBarry May 30, 2025
1382901
format empty slots as <empty> in print function
ItsNickBarry May 30, 2025
a539774
avoid modification of entries arrays
ItsNickBarry May 30, 2025
823a39b
fix local Entry type
ItsNickBarry May 30, 2025
d074062
set solidity version to 0.8.29 and declare layout offset in test cont…
ItsNickBarry May 30, 2025
933bdcb
support layout offset in collateStorageLayout function
ItsNickBarry May 30, 2025
58ae40e
remove <empty> output
ItsNickBarry May 30, 2025
5471760
fix layout offset support
ItsNickBarry May 30, 2025
ac39656
support zero-length storage layouts
ItsNickBarry May 30, 2025
28cf9c4
support bytes and string types
ItsNickBarry May 30, 2025
35d0742
test mergeCollatedStorageLayouts function
ItsNickBarry May 30, 2025
a240335
remove unused test contract, move merge test contracts to separate file
ItsNickBarry May 30, 2025
6044662
rename plugin to hardhat-storage-layout-inspector
ItsNickBarry May 30, 2025
7ed9b39
license test contracts under MIT
ItsNickBarry May 30, 2025
973d24d
update readme title
ItsNickBarry May 30, 2025
8a398da
build project in prepublishOnly script
ItsNickBarry May 30, 2025
8f5e858
use hardhat-solidstate-utils dependency
ItsNickBarry May 31, 2025
6cf3596
replace cli-table3 direct dependency with export from hardhat-solidst…
ItsNickBarry May 31, 2025
4d8e30f
import only / except config and helper function from hardhat-solidsta…
ItsNickBarry May 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.tsbuildinfo
artifacts/
cache/
dist/
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
yarn run lint-staged
pnpm lint-staged --hide-unstaged --hide-untracked
3 changes: 0 additions & 3 deletions .lintstagedrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"trailingComma": "all",
"bracketSpacing": true,
"plugins": [
"prettier-plugin-ejs",
"prettier-plugin-packagejson",
"prettier-plugin-solidity",
"@trivago/prettier-plugin-sort-imports"
]
Expand Down
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Hardhat Storage Layout Diff
# Hardhat Storage Layout Inspector

Inspect and compare Solidity smart contract storage layouts.

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

```bash
npm install --save-dev @solidstate/hardhat-storage-layout-diff
npm install --save-dev @solidstate/hardhat-storage-layout-inspector
# or
yarn add --dev @solidstate/hardhat-storage-layout-diff
pnpm add -D @solidstate/hardhat-storage-layout-inspector
```

## Usage

Load plugin in Hardhat config:

```javascript
require('@solidstate/hardhat-storage-layout-diff');
import HardhatStorageLayoutInspector from '@solidstate/hardhat-storage-layout-inspector';

const config: HardhatUserConfig = {
plugins: [
HardhatStorageLayoutInspector,
],
storageLayoutDiff: {
... // see table for configuration options
},
};
```

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

Additional configuration options are provided by [`@solidstate/hardhat-git`](https://www.npmjs.com/package/@solidstate/hardhat-git), which is included as a dependency.

Export storage layouts:

```bash
npx hardhat export-storage-layout
# or
yarn run hardhat export-storage-layout
pnpm hardhat export-storage-layout
```

Compare two contracts:
Inspect a contract's storage layout:

```bash
npx hardhat diff-storage-layout [CONTRACT_A_FULLY_QUALIFIED_NAME] [CONTRACT_B_FULLY_QUALIFIED_NAME]
npx hardhat inspect-storage-layout [CONTRACT_IDENTIFIER]
# or
yarn run hardhat diff-storage-layout [CONTRACT_A_FULLY_QUALIFIED_NAME] [CONTRACT_B_FULLY_QUALIFIED_NAME]
pnpm hardhat inspect-storage-layout [CONTRACT_IDENTIFIER]
```

Include the optional `--a-ref` and/or `--b-ref` arguments to specify the git reference where contracts `a` and `b` are defined, respectively.

Compare a contract to an exported JSON layout:
Compare two contracts:

```bash
npx hardhat storage-layout-check --source [PATH_TO_LAYOUT_JSON] --b [CONTRACT_B_FULLY_QUALIFIED_NAME]
npx hardhat diff-storage-layout [CONTRACT_A_IDENTIFIER] [CONTRACT_B_IDENTIFIER]
# or
yarn run hardhat storage-layout-check --source [PATH_TO_LAYOUT_JSON] --b [CONTRACT_B_FULLY_QUALIFIED_NAME]
pnpm hardhat diff-storage-layout [CONTRACT_A_IDENTIFIER] [CONTRACT_B_IDENTIFIER]
```

A contract identifier may be a name, a fully qualified name, or a path to a JSON file containing a storage layout.

Include the optional git rev options to look up a contract identifier at a particular git revision.

## Development

Install dependencies via Yarn:
Install dependencies via pnpm:

```bash
yarn install
pnpm install
```

Setup Husky to format code on commit:

```bash
yarn prepare
pnpm prepare
```
18 changes: 18 additions & 0 deletions contracts/Offset.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity *;

contract SlotsZero {}

contract SlotsOne {
uint256 one;
}

contract SlotsOneOffsetOne is SlotsOne layout at 1 {}

contract SlotsTwo is SlotsOne {
uint256 two;
}

contract SlotsTwoOffsetOne is SlotsTwo layout at 1 {}

contract SlotsTwoOffsetTwo is SlotsTwo layout at 2 {}
42 changes: 11 additions & 31 deletions contracts/Test.sol
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity *;

contract Test {
enum E {
ONE,
TWO
}

struct Struct {
address a;
E e;
address b;
E f;
}
import { E, S } from './Types.sol';

Struct str;
contract Test {
// slots 0-1
S str;
// slot 2
mapping(address => bool) map;
uint128[5] five;
// slots 3-5
uint128[5] array;
// slot 6
bool b0;
bool b1;
bool[4][2] bools;
}

contract Test2 {
bytes29 _b;
uint128 a;
uint64 b;
uint128 u;
}

contract Test3 {
bytes30 _b;
uint64 a;
uint128 b;
uint128 u;
uint64 uu;
// slots 7-8
bool[4][2] nestedArray;
}
13 changes: 13 additions & 0 deletions contracts/Types.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity *;

enum E {
ONE,
TWO
}

struct S {
address a;
E e;
bytes16 b;
}
5 changes: 3 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import './src/index';
import HardhatStorageLayoutInspector from './src/index.js';
import { HardhatUserConfig } from 'hardhat/config';

const config: HardhatUserConfig = {
solidity: '0.8.28',
solidity: '0.8.29',
plugins: [HardhatStorageLayoutInspector],
};

export default config;
4 changes: 4 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
'*.{js,ts,sol,json,md}': ['prettier --write'],
'*': () => ['knip', 'knip --production'],
};
54 changes: 31 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@solidstate/hardhat-storage-layout-diff",
"name": "@solidstate/hardhat-storage-layout-inspector",
"version": "1.0.0",
"license": "MIT",
"description": "Compare storage layouts between two contracts",
"keywords": [
"hardhat",
Expand All @@ -14,40 +13,49 @@
"blockchain",
"wow"
],
"repository": "github:solidstate-network/hardhat-storage-layout-diff",
"repository": "github:solidstate-network/hardhat-storage-layout-inspector",
"license": "MIT",
"author": "Nick Barry",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"scripts": {
"build": "tsc --build --clean",
"prepare": "husky",
"prettier": "prettier --write ."
"type": "module",
"exports": {
".": "./dist/index.js",
"./types": "./dist/types.js"
},
"types": "./dist/index.d.ts",
"files": [
"dist/src",
"src"
],
"peerDependencies": {
"hardhat": "^2.0.0"
"scripts": {
"build": "pnpm clean && tsc --build",
"clean": "tsc --build --clean",
"prepare": "husky",
"prepublishOnly": "pnpm build",
"prettier": "prettier --write .",
"test": "pnpm build && hardhat compile && tsx --test"
},
"dependencies": {
"@solidstate/hardhat-git": "^1.0.0-next.5",
"@solidstate/hardhat-solidstate-utils": "1.0.0-next.3",
"chalk": "^5.4.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-utils": "3.0.0-next.11",
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
"@types/ejs": "^3.1.5",
"@types/mocha": "^10.0.10",
"@types/node": "^22.14.1",
"hardhat": "^2.23.0",
"@types/node": "^22.15.21",
"hardhat": "^3.0.0-next.11",
"husky": "^9.1.7",
"lint-staged": "^15.5.1",
"knip": "^5.58.1",
"lint-staged": "github:ItsNickBarry/lint-staged#hide-all",
"prettier": "^3.5.3",
"prettier-plugin-ejs": "^1.0.3",
"prettier-plugin-solidity": "^1.4.2",
"ts-node": "^10.9.2",
"prettier-plugin-packagejson": "^2.5.14",
"prettier-plugin-solidity": "^2.0.0",
"tsx": "^4.19.4",
"typescript": "^5.8.3"
},
"dependencies": {
"chalk": "^5.4.1",
"cli-table3": "^0.6.5",
"simple-git": "^3.27.0"
"peerDependencies": {
"@nomicfoundation/hardhat-utils": "3.0.0-next.11",
"hardhat": "^3.0.0-next.6"
},
"publishConfig": {
"access": "public"
Expand Down
Loading