hardhat 3.10.0 → 3.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +11 -7
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/cli/init/init.d.ts +3 -8
- package/dist/src/internal/cli/init/init.d.ts.map +1 -1
- package/dist/src/internal/cli/init/init.js +9 -27
- package/dist/src/internal/cli/init/init.js.map +1 -1
- package/dist/src/internal/cli/init/prompt.d.ts +0 -1
- package/dist/src/internal/cli/init/prompt.d.ts.map +1 -1
- package/dist/src/internal/cli/init/prompt.js +0 -24
- package/dist/src/internal/cli/init/prompt.js.map +1 -1
- package/dist/src/internal/cli/init/template.d.ts +1 -1
- package/dist/src/internal/cli/init/template.d.ts.map +1 -1
- package/dist/src/internal/cli/init/template.js +2 -2
- package/dist/src/internal/cli/init/template.js.map +1 -1
- package/dist/src/internal/cli/main.js +1 -1
- package/dist/src/internal/cli/main.js.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.d.ts +1 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.js +2 -2
- package/dist/src/internal/cli/telemetry/analytics/analytics.js.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/types.d.ts +1 -1
- package/dist/src/internal/cli/telemetry/analytics/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +13 -6
- package/src/internal/cli/init/init.ts +4 -38
- package/src/internal/cli/init/prompt.ts +0 -31
- package/src/internal/cli/init/template.ts +2 -4
- package/src/internal/cli/main.ts +1 -1
- package/src/internal/cli/telemetry/analytics/analytics.ts +1 -2
- package/src/internal/cli/telemetry/analytics/types.ts +1 -1
- package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/package.json +1 -1
- package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/package.json +1 -1
- package/templates/{hardhat-3/03-minimal → 03-minimal}/package.json +1 -1
- package/templates/hardhat-2/01-mocha-ethers-js/README.md +0 -13
- package/templates/hardhat-2/01-mocha-ethers-js/contracts/Lock.sol +0 -34
- package/templates/hardhat-2/01-mocha-ethers-js/gitignore +0 -17
- package/templates/hardhat-2/01-mocha-ethers-js/hardhat.config.js +0 -6
- package/templates/hardhat-2/01-mocha-ethers-js/ignition/modules/Lock.js +0 -18
- package/templates/hardhat-2/01-mocha-ethers-js/package.json +0 -23
- package/templates/hardhat-2/01-mocha-ethers-js/test/Lock.js +0 -126
- package/templates/hardhat-2/02-mocha-ethers-js-esm/README.md +0 -13
- package/templates/hardhat-2/02-mocha-ethers-js-esm/contracts/Lock.sol +0 -34
- package/templates/hardhat-2/02-mocha-ethers-js-esm/gitignore +0 -17
- package/templates/hardhat-2/02-mocha-ethers-js-esm/hardhat.config.cjs +0 -6
- package/templates/hardhat-2/02-mocha-ethers-js-esm/ignition/modules/Lock.js +0 -18
- package/templates/hardhat-2/02-mocha-ethers-js-esm/package.json +0 -24
- package/templates/hardhat-2/02-mocha-ethers-js-esm/test/Lock.js +0 -128
- package/templates/hardhat-2/03-mocha-ethers-ts/README.md +0 -13
- package/templates/hardhat-2/03-mocha-ethers-ts/contracts/Lock.sol +0 -34
- package/templates/hardhat-2/03-mocha-ethers-ts/gitignore +0 -17
- package/templates/hardhat-2/03-mocha-ethers-ts/hardhat.config.ts +0 -8
- package/templates/hardhat-2/03-mocha-ethers-ts/ignition/modules/Lock.ts +0 -20
- package/templates/hardhat-2/03-mocha-ethers-ts/package.json +0 -28
- package/templates/hardhat-2/03-mocha-ethers-ts/test/Lock.ts +0 -127
- package/templates/hardhat-2/03-mocha-ethers-ts/tsconfig.json +0 -11
- package/templates/hardhat-2/04-mocha-viem-ts/README.md +0 -13
- package/templates/hardhat-2/04-mocha-viem-ts/contracts/Lock.sol +0 -34
- package/templates/hardhat-2/04-mocha-viem-ts/gitignore +0 -17
- package/templates/hardhat-2/04-mocha-viem-ts/hardhat.config.ts +0 -8
- package/templates/hardhat-2/04-mocha-viem-ts/ignition/modules/Lock.ts +0 -21
- package/templates/hardhat-2/04-mocha-viem-ts/package.json +0 -25
- package/templates/hardhat-2/04-mocha-viem-ts/test/Lock.ts +0 -134
- package/templates/hardhat-2/04-mocha-viem-ts/tsconfig.json +0 -11
- package/templates/hardhat-2/05-empty-hardhat-config-js/hardhat.config.js +0 -4
- package/templates/hardhat-2/05-empty-hardhat-config-js/package.json +0 -9
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/AGENTS.md +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/README.md +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/contracts/Counter.sol +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/contracts/Counter.t.sol +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/gitignore +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/hardhat.config.ts +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/ignition/modules/Counter.ts +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/scripts/send-op-tx.ts +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/test/Counter.ts +0 -0
- /package/templates/{hardhat-3/01-node-test-runner-viem → 01-node-test-runner-viem}/tsconfig.json +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/AGENTS.md +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/README.md +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/contracts/Counter.sol +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/contracts/Counter.t.sol +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/gitignore +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/hardhat.config.ts +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/ignition/modules/Counter.ts +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/scripts/send-op-tx.ts +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/test/Counter.ts +0 -0
- /package/templates/{hardhat-3/02-mocha-ethers → 02-mocha-ethers}/tsconfig.json +0 -0
- /package/templates/{hardhat-3/03-minimal → 03-minimal}/README.md +0 -0
- /package/templates/{hardhat-3/03-minimal → 03-minimal}/gitignore +0 -0
- /package/templates/{hardhat-3/03-minimal → 03-minimal}/hardhat.config.ts +0 -0
- /package/templates/{hardhat-3/03-minimal → 03-minimal}/tsconfig.json +0 -0
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Sample Hardhat Project
|
|
2
|
-
|
|
3
|
-
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
|
4
|
-
|
|
5
|
-
Try running some of the following tasks:
|
|
6
|
-
|
|
7
|
-
```shell
|
|
8
|
-
npx hardhat help
|
|
9
|
-
npx hardhat test
|
|
10
|
-
REPORT_GAS=true npx hardhat test
|
|
11
|
-
npx hardhat node
|
|
12
|
-
npx hardhat ignition deploy ./ignition/modules/Lock.js
|
|
13
|
-
```
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
-
|
|
4
|
-
// Uncomment this line to use console.log
|
|
5
|
-
// import "hardhat/console.sol";
|
|
6
|
-
|
|
7
|
-
contract Lock {
|
|
8
|
-
uint public unlockTime;
|
|
9
|
-
address payable public owner;
|
|
10
|
-
|
|
11
|
-
event Withdrawal(uint amount, uint when);
|
|
12
|
-
|
|
13
|
-
constructor(uint _unlockTime) payable {
|
|
14
|
-
require(
|
|
15
|
-
block.timestamp < _unlockTime,
|
|
16
|
-
"Unlock time should be in the future"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
unlockTime = _unlockTime;
|
|
20
|
-
owner = payable(msg.sender);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function withdraw() public {
|
|
24
|
-
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
|
25
|
-
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
|
26
|
-
|
|
27
|
-
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
|
28
|
-
require(msg.sender == owner, "You aren't the owner");
|
|
29
|
-
|
|
30
|
-
emit Withdrawal(address(this).balance, block.timestamp);
|
|
31
|
-
|
|
32
|
-
owner.transfer(address(this).balance);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
.env
|
|
3
|
-
|
|
4
|
-
# Hardhat files
|
|
5
|
-
/cache
|
|
6
|
-
/artifacts
|
|
7
|
-
|
|
8
|
-
# TypeChain files
|
|
9
|
-
/typechain
|
|
10
|
-
/typechain-types
|
|
11
|
-
|
|
12
|
-
# solidity-coverage files
|
|
13
|
-
/coverage
|
|
14
|
-
/coverage.json
|
|
15
|
-
|
|
16
|
-
# Hardhat Ignition default folder for deployments against a local node
|
|
17
|
-
ignition/deployments/chain-31337
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
|
2
|
-
// Learn more about it at https://hardhat.org/ignition
|
|
3
|
-
|
|
4
|
-
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
|
5
|
-
|
|
6
|
-
const JAN_1ST_2030 = 1893456000;
|
|
7
|
-
const ONE_GWEI = 1_000_000_000n;
|
|
8
|
-
|
|
9
|
-
export default buildModule("LockModule", (m) => {
|
|
10
|
-
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
|
11
|
-
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
|
12
|
-
|
|
13
|
-
const lock = m.contract("Lock", [unlockTime], {
|
|
14
|
-
value: lockedAmount,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return { lock };
|
|
18
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "template-v2-mocha-ethers-js-esm",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"description": "A Javascript project using Mocha and Ethers.js (ESM)",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"devDependencies": {
|
|
8
|
-
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
|
|
9
|
-
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
|
10
|
-
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
|
11
|
-
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
|
|
12
|
-
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
|
13
|
-
"@nomicfoundation/hardhat-toolbox": "^6.0.0",
|
|
14
|
-
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
|
15
|
-
"@typechain/ethers-v6": "^0.5.0",
|
|
16
|
-
"@typechain/hardhat": "^9.0.0",
|
|
17
|
-
"chai": "^4.2.0",
|
|
18
|
-
"ethers": "^6.4.0",
|
|
19
|
-
"hardhat": "^2.14.0",
|
|
20
|
-
"hardhat-gas-reporter": "^2.3.0",
|
|
21
|
-
"solidity-coverage": "^0.8.0",
|
|
22
|
-
"typechain": "^8.3.0"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
time,
|
|
3
|
-
loadFixture,
|
|
4
|
-
} from "@nomicfoundation/hardhat-toolbox/network-helpers.js";
|
|
5
|
-
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs.js";
|
|
6
|
-
import chai from "chai";
|
|
7
|
-
|
|
8
|
-
const { expect } = chai;
|
|
9
|
-
|
|
10
|
-
describe("Lock", function () {
|
|
11
|
-
// We define a fixture to reuse the same setup in every test.
|
|
12
|
-
// We use loadFixture to run this setup once, snapshot that state,
|
|
13
|
-
// and reset Hardhat Network to that snapshot in every test.
|
|
14
|
-
async function deployOneYearLockFixture() {
|
|
15
|
-
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
|
16
|
-
const ONE_GWEI = 1_000_000_000;
|
|
17
|
-
|
|
18
|
-
const lockedAmount = ONE_GWEI;
|
|
19
|
-
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
|
20
|
-
|
|
21
|
-
// Contracts are deployed using the first signer/account by default
|
|
22
|
-
const [owner, otherAccount] = await ethers.getSigners();
|
|
23
|
-
|
|
24
|
-
const Lock = await ethers.getContractFactory("Lock");
|
|
25
|
-
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
|
26
|
-
|
|
27
|
-
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe("Deployment", function () {
|
|
31
|
-
it("Should set the right unlockTime", async function () {
|
|
32
|
-
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
|
33
|
-
|
|
34
|
-
expect(await lock.unlockTime()).to.equal(unlockTime);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("Should set the right owner", async function () {
|
|
38
|
-
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
|
39
|
-
|
|
40
|
-
expect(await lock.owner()).to.equal(owner.address);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("Should receive and store the funds to lock", async function () {
|
|
44
|
-
const { lock, lockedAmount } = await loadFixture(
|
|
45
|
-
deployOneYearLockFixture,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(await ethers.provider.getBalance(lock.target)).to.equal(
|
|
49
|
-
lockedAmount,
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("Should fail if the unlockTime is not in the future", async function () {
|
|
54
|
-
// We don't use the fixture here because we want a different deployment
|
|
55
|
-
const latestTime = await time.latest();
|
|
56
|
-
const Lock = await ethers.getContractFactory("Lock");
|
|
57
|
-
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
|
58
|
-
"Unlock time should be in the future",
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe("Withdrawals", function () {
|
|
64
|
-
describe("Validations", function () {
|
|
65
|
-
it("Should revert with the right error if called too soon", async function () {
|
|
66
|
-
const { lock } = await loadFixture(deployOneYearLockFixture);
|
|
67
|
-
|
|
68
|
-
await expect(lock.withdraw()).to.be.revertedWith(
|
|
69
|
-
"You can't withdraw yet",
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("Should revert with the right error if called from another account", async function () {
|
|
74
|
-
const { lock, unlockTime, otherAccount } = await loadFixture(
|
|
75
|
-
deployOneYearLockFixture,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// We can increase the time in Hardhat Network
|
|
79
|
-
await time.increaseTo(unlockTime);
|
|
80
|
-
|
|
81
|
-
// We use lock.connect() to send a transaction from another account
|
|
82
|
-
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
|
83
|
-
"You aren't the owner",
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
|
88
|
-
const { lock, unlockTime } = await loadFixture(
|
|
89
|
-
deployOneYearLockFixture,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// Transactions are sent using the first signer by default
|
|
93
|
-
await time.increaseTo(unlockTime);
|
|
94
|
-
|
|
95
|
-
await expect(lock.withdraw()).not.to.be.reverted;
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("Events", function () {
|
|
100
|
-
it("Should emit an event on withdrawals", async function () {
|
|
101
|
-
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
|
102
|
-
deployOneYearLockFixture,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
await time.increaseTo(unlockTime);
|
|
106
|
-
|
|
107
|
-
await expect(lock.withdraw())
|
|
108
|
-
.to.emit(lock, "Withdrawal")
|
|
109
|
-
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("Transfers", function () {
|
|
114
|
-
it("Should transfer the funds to the owner", async function () {
|
|
115
|
-
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
|
116
|
-
deployOneYearLockFixture,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
await time.increaseTo(unlockTime);
|
|
120
|
-
|
|
121
|
-
await expect(lock.withdraw()).to.changeEtherBalances(
|
|
122
|
-
[owner, lock],
|
|
123
|
-
[lockedAmount, -lockedAmount],
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Sample Hardhat Project
|
|
2
|
-
|
|
3
|
-
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
|
4
|
-
|
|
5
|
-
Try running some of the following tasks:
|
|
6
|
-
|
|
7
|
-
```shell
|
|
8
|
-
npx hardhat help
|
|
9
|
-
npx hardhat test
|
|
10
|
-
REPORT_GAS=true npx hardhat test
|
|
11
|
-
npx hardhat node
|
|
12
|
-
npx hardhat ignition deploy ./ignition/modules/Lock.ts
|
|
13
|
-
```
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
-
|
|
4
|
-
// Uncomment this line to use console.log
|
|
5
|
-
// import "hardhat/console.sol";
|
|
6
|
-
|
|
7
|
-
contract Lock {
|
|
8
|
-
uint public unlockTime;
|
|
9
|
-
address payable public owner;
|
|
10
|
-
|
|
11
|
-
event Withdrawal(uint amount, uint when);
|
|
12
|
-
|
|
13
|
-
constructor(uint _unlockTime) payable {
|
|
14
|
-
require(
|
|
15
|
-
block.timestamp < _unlockTime,
|
|
16
|
-
"Unlock time should be in the future"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
unlockTime = _unlockTime;
|
|
20
|
-
owner = payable(msg.sender);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function withdraw() public {
|
|
24
|
-
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
|
25
|
-
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
|
26
|
-
|
|
27
|
-
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
|
28
|
-
require(msg.sender == owner, "You aren't the owner");
|
|
29
|
-
|
|
30
|
-
emit Withdrawal(address(this).balance, block.timestamp);
|
|
31
|
-
|
|
32
|
-
owner.transfer(address(this).balance);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
.env
|
|
3
|
-
|
|
4
|
-
# Hardhat files
|
|
5
|
-
/cache
|
|
6
|
-
/artifacts
|
|
7
|
-
|
|
8
|
-
# TypeChain files
|
|
9
|
-
/typechain
|
|
10
|
-
/typechain-types
|
|
11
|
-
|
|
12
|
-
# solidity-coverage files
|
|
13
|
-
/coverage
|
|
14
|
-
/coverage.json
|
|
15
|
-
|
|
16
|
-
# Hardhat Ignition default folder for deployments against a local node
|
|
17
|
-
ignition/deployments/chain-31337
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
|
2
|
-
// Learn more about it at https://hardhat.org/ignition
|
|
3
|
-
|
|
4
|
-
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
|
5
|
-
|
|
6
|
-
const JAN_1ST_2030 = 1893456000;
|
|
7
|
-
const ONE_GWEI: bigint = 1_000_000_000n;
|
|
8
|
-
|
|
9
|
-
const LockModule = buildModule("LockModule", (m) => {
|
|
10
|
-
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
|
11
|
-
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
|
12
|
-
|
|
13
|
-
const lock = m.contract("Lock", [unlockTime], {
|
|
14
|
-
value: lockedAmount,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return { lock };
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export default LockModule;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "template-v2-mocha-ethers-ts",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"description": "A Typescript project using Mocha and Ethers.js",
|
|
6
|
-
"devDependencies": {
|
|
7
|
-
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
|
|
8
|
-
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
|
9
|
-
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
|
10
|
-
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
|
|
11
|
-
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
|
12
|
-
"@nomicfoundation/hardhat-toolbox": "^6.0.0",
|
|
13
|
-
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
|
14
|
-
"@typechain/ethers-v6": "^0.5.0",
|
|
15
|
-
"@typechain/hardhat": "^9.0.0",
|
|
16
|
-
"@types/chai": "^4.2.0",
|
|
17
|
-
"@types/mocha": ">=9.1.0",
|
|
18
|
-
"@types/node": ">=22.0.0",
|
|
19
|
-
"chai": "^4.2.0",
|
|
20
|
-
"ethers": "^6.4.0",
|
|
21
|
-
"hardhat": "^2.14.0",
|
|
22
|
-
"hardhat-gas-reporter": "^2.3.0",
|
|
23
|
-
"solidity-coverage": "^0.8.0",
|
|
24
|
-
"ts-node": ">=8.0.0",
|
|
25
|
-
"typechain": "^8.3.0",
|
|
26
|
-
"typescript": ">=4.5.0"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
|
|
2
|
-
import {
|
|
3
|
-
time,
|
|
4
|
-
loadFixture,
|
|
5
|
-
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
|
|
6
|
-
import { expect } from "chai";
|
|
7
|
-
import hre from "hardhat";
|
|
8
|
-
|
|
9
|
-
describe("Lock", function () {
|
|
10
|
-
// We define a fixture to reuse the same setup in every test.
|
|
11
|
-
// We use loadFixture to run this setup once, snapshot that state,
|
|
12
|
-
// and reset Hardhat Network to that snapshot in every test.
|
|
13
|
-
async function deployOneYearLockFixture() {
|
|
14
|
-
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
|
15
|
-
const ONE_GWEI = 1_000_000_000;
|
|
16
|
-
|
|
17
|
-
const lockedAmount = ONE_GWEI;
|
|
18
|
-
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
|
19
|
-
|
|
20
|
-
// Contracts are deployed using the first signer/account by default
|
|
21
|
-
const [owner, otherAccount] = await hre.ethers.getSigners();
|
|
22
|
-
|
|
23
|
-
const Lock = await hre.ethers.getContractFactory("Lock");
|
|
24
|
-
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
|
25
|
-
|
|
26
|
-
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe("Deployment", function () {
|
|
30
|
-
it("Should set the right unlockTime", async function () {
|
|
31
|
-
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
|
32
|
-
|
|
33
|
-
expect(await lock.unlockTime()).to.equal(unlockTime);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("Should set the right owner", async function () {
|
|
37
|
-
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
|
38
|
-
|
|
39
|
-
expect(await lock.owner()).to.equal(owner.address);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("Should receive and store the funds to lock", async function () {
|
|
43
|
-
const { lock, lockedAmount } = await loadFixture(
|
|
44
|
-
deployOneYearLockFixture,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(await hre.ethers.provider.getBalance(lock.target)).to.equal(
|
|
48
|
-
lockedAmount,
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("Should fail if the unlockTime is not in the future", async function () {
|
|
53
|
-
// We don't use the fixture here because we want a different deployment
|
|
54
|
-
const latestTime = await time.latest();
|
|
55
|
-
const Lock = await hre.ethers.getContractFactory("Lock");
|
|
56
|
-
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
|
57
|
-
"Unlock time should be in the future",
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("Withdrawals", function () {
|
|
63
|
-
describe("Validations", function () {
|
|
64
|
-
it("Should revert with the right error if called too soon", async function () {
|
|
65
|
-
const { lock } = await loadFixture(deployOneYearLockFixture);
|
|
66
|
-
|
|
67
|
-
await expect(lock.withdraw()).to.be.revertedWith(
|
|
68
|
-
"You can't withdraw yet",
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("Should revert with the right error if called from another account", async function () {
|
|
73
|
-
const { lock, unlockTime, otherAccount } = await loadFixture(
|
|
74
|
-
deployOneYearLockFixture,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// We can increase the time in Hardhat Network
|
|
78
|
-
await time.increaseTo(unlockTime);
|
|
79
|
-
|
|
80
|
-
// We use lock.connect() to send a transaction from another account
|
|
81
|
-
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
|
82
|
-
"You aren't the owner",
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
|
87
|
-
const { lock, unlockTime } = await loadFixture(
|
|
88
|
-
deployOneYearLockFixture,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
// Transactions are sent using the first signer by default
|
|
92
|
-
await time.increaseTo(unlockTime);
|
|
93
|
-
|
|
94
|
-
await expect(lock.withdraw()).not.to.be.reverted;
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe("Events", function () {
|
|
99
|
-
it("Should emit an event on withdrawals", async function () {
|
|
100
|
-
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
|
101
|
-
deployOneYearLockFixture,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
await time.increaseTo(unlockTime);
|
|
105
|
-
|
|
106
|
-
await expect(lock.withdraw())
|
|
107
|
-
.to.emit(lock, "Withdrawal")
|
|
108
|
-
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe("Transfers", function () {
|
|
113
|
-
it("Should transfer the funds to the owner", async function () {
|
|
114
|
-
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
|
115
|
-
deployOneYearLockFixture,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
await time.increaseTo(unlockTime);
|
|
119
|
-
|
|
120
|
-
await expect(lock.withdraw()).to.changeEtherBalances(
|
|
121
|
-
[owner, lock],
|
|
122
|
-
[lockedAmount, -lockedAmount],
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Sample Hardhat Project
|
|
2
|
-
|
|
3
|
-
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
|
4
|
-
|
|
5
|
-
Try running some of the following tasks:
|
|
6
|
-
|
|
7
|
-
```shell
|
|
8
|
-
npx hardhat help
|
|
9
|
-
npx hardhat test
|
|
10
|
-
REPORT_GAS=true npx hardhat test
|
|
11
|
-
npx hardhat node
|
|
12
|
-
npx hardhat ignition deploy ./ignition/modules/Lock.ts
|
|
13
|
-
```
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
-
|
|
4
|
-
// Uncomment this line to use console.log
|
|
5
|
-
// import "hardhat/console.sol";
|
|
6
|
-
|
|
7
|
-
contract Lock {
|
|
8
|
-
uint public unlockTime;
|
|
9
|
-
address payable public owner;
|
|
10
|
-
|
|
11
|
-
event Withdrawal(uint amount, uint when);
|
|
12
|
-
|
|
13
|
-
constructor(uint _unlockTime) payable {
|
|
14
|
-
require(
|
|
15
|
-
block.timestamp < _unlockTime,
|
|
16
|
-
"Unlock time should be in the future"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
unlockTime = _unlockTime;
|
|
20
|
-
owner = payable(msg.sender);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function withdraw() public {
|
|
24
|
-
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
|
25
|
-
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
|
26
|
-
|
|
27
|
-
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
|
28
|
-
require(msg.sender == owner, "You aren't the owner");
|
|
29
|
-
|
|
30
|
-
emit Withdrawal(address(this).balance, block.timestamp);
|
|
31
|
-
|
|
32
|
-
owner.transfer(address(this).balance);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
.env
|
|
3
|
-
|
|
4
|
-
# Hardhat files
|
|
5
|
-
/cache
|
|
6
|
-
/artifacts
|
|
7
|
-
|
|
8
|
-
# TypeChain files
|
|
9
|
-
/typechain
|
|
10
|
-
/typechain-types
|
|
11
|
-
|
|
12
|
-
# solidity-coverage files
|
|
13
|
-
/coverage
|
|
14
|
-
/coverage.json
|
|
15
|
-
|
|
16
|
-
# Hardhat Ignition default folder for deployments against a local node
|
|
17
|
-
ignition/deployments/chain-31337
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
|
2
|
-
// Learn more about it at https://hardhat.org/ignition
|
|
3
|
-
|
|
4
|
-
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
|
5
|
-
import { parseEther } from "viem";
|
|
6
|
-
|
|
7
|
-
const JAN_1ST_2030 = 1893456000;
|
|
8
|
-
const ONE_GWEI: bigint = parseEther("0.001");
|
|
9
|
-
|
|
10
|
-
const LockModule = buildModule("LockModule", (m) => {
|
|
11
|
-
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
|
12
|
-
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
|
13
|
-
|
|
14
|
-
const lock = m.contract("Lock", [unlockTime], {
|
|
15
|
-
value: lockedAmount,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return { lock };
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export default LockModule;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "template-v2-mocha-viem-ts",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"description": "A Typescript project using Mocha and Viem",
|
|
6
|
-
"devDependencies": {
|
|
7
|
-
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
|
8
|
-
"@nomicfoundation/hardhat-ignition-viem": "^0.15.0",
|
|
9
|
-
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
|
10
|
-
"@nomicfoundation/hardhat-toolbox-viem": "^4.1.0",
|
|
11
|
-
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
|
12
|
-
"@nomicfoundation/hardhat-viem": "^2.0.0",
|
|
13
|
-
"@types/chai": "^4.2.0",
|
|
14
|
-
"@types/chai-as-promised": "^7.1.6",
|
|
15
|
-
"@types/mocha": ">=9.1.0",
|
|
16
|
-
"@types/node": ">=22.0.0",
|
|
17
|
-
"chai": "^4.2.0",
|
|
18
|
-
"hardhat": "^2.14.0",
|
|
19
|
-
"hardhat-gas-reporter": "^2.3.0",
|
|
20
|
-
"solidity-coverage": "^0.8.0",
|
|
21
|
-
"ts-node": ">=8.0.0",
|
|
22
|
-
"typescript": "~5.0.4",
|
|
23
|
-
"viem": "^2.47.6"
|
|
24
|
-
}
|
|
25
|
-
}
|