1
1
import { task } from 'hardhat/config' ;
2
2
import { HardhatRuntimeEnvironment } from 'hardhat/types' ;
3
- import fs from 'fs' ;
4
- import path from 'path' ;
5
-
6
- interface Deployment {
7
- contractName : string ;
8
- address : string ;
9
- args : any [ ] ;
10
- isProxy ?: boolean ;
11
- isImplementation ?: boolean ;
12
- proxyAddress ?: string ;
13
- }
14
-
15
- const BLOCKS_PER_COMMIT_INTERVAL = 30 ;
16
- const TIME_TO_FINALIZE = 5 ;
17
- const COMMIT_COOLDOWN = TIME_TO_FINALIZE ;
18
3
19
4
task ( 'verify-deployment' , 'Verifies the deployed contract bytecode' ) . setAction (
20
5
async ( taskArgs : any , hre : HardhatRuntimeEnvironment ) : Promise < void > => {
@@ -23,41 +8,15 @@ task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
23
8
`Verifying contract bytecode on ${ network } :${ hre . network . config . chainId } ...`
24
9
) ;
25
10
26
- const deploymentsFile = path . join ( `deployments/${ network } /${ network } .json` ) ;
27
- if ( ! fs . existsSync ( deploymentsFile ) ) {
28
- console . error ( `Deployments file not found: ${ deploymentsFile } ` ) ;
29
- return ;
30
- }
31
-
32
- const deployments : Deployment [ ] = JSON . parse (
33
- fs . readFileSync ( deploymentsFile , 'utf8' )
34
- ) ;
11
+ const deployments = await hre . deployments . all ( ) ;
35
12
36
- for ( const deployment of deployments ) {
37
- console . log (
38
- `\nVerifying ${ deployment . contractName } (${ deployment . address } ):`
39
- ) ;
13
+ for ( const [ contractName , deployment ] of Object . entries ( deployments ) ) {
14
+ console . log ( `\nVerifying ${ contractName } (${ deployment . address } ):` ) ;
40
15
41
16
try {
42
- console . log ( ' Reading contract artifact...' ) ;
43
- const artifactPath = path . join (
44
- `artifacts/contracts/fuelchain/${ deployment . contractName } .sol/${ deployment . contractName } .json`
45
- ) ;
46
-
47
- if ( ! fs . existsSync ( artifactPath ) ) {
48
- console . log ( ' Artifact not found. Compiling contracts...' ) ;
49
- await hre . run ( 'compile' ) ;
50
-
51
- if ( ! fs . existsSync ( artifactPath ) ) {
52
- throw new Error (
53
- `Artifact not found even after compilation: ${ artifactPath } `
54
- ) ;
55
- }
56
- }
57
-
58
17
console . log ( '--- Fetching deployed bytecode...' ) ;
59
18
let deployedBytecode : string ;
60
- if ( deployment . isProxy ) {
19
+ if ( deployment . linkedData . isProxy ) {
61
20
const implementationAddress =
62
21
await hre . upgrades . erc1967 . getImplementationAddress (
63
22
deployment . address
@@ -78,53 +37,45 @@ task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
78
37
79
38
console . log ( '--- Deploying contract locally...' ) ;
80
39
const ContractFactory = await localHardhat . ethers . getContractFactory (
81
- deployment . contractName
40
+ contractName
82
41
) ;
83
42
let localAddress : string ;
84
- if ( deployment . isProxy ) {
43
+ if ( deployment . linkedData . isProxy ) {
85
44
const localContract = await localHardhat . upgrades . deployProxy (
86
45
ContractFactory ,
87
46
[ ] ,
88
47
{
89
48
kind : 'uups' ,
90
49
initializer : 'initialize' ,
91
- constructorArgs : [
92
- TIME_TO_FINALIZE ,
93
- BLOCKS_PER_COMMIT_INTERVAL ,
94
- COMMIT_COOLDOWN ,
95
- ] ,
50
+ constructorArgs : deployment . linkedData . constructorArgs ,
96
51
}
97
52
) ;
98
53
await localContract . waitForDeployment ( ) ;
99
54
localAddress = await localContract . getAddress ( ) ;
100
- } else if ( deployment . isImplementation ) {
55
+ } else if ( deployment . linkedData . isImplementation ) {
101
56
console . log ( '--- Validating Upgrade...' ) ;
102
57
await localHardhat . upgrades . validateUpgrade (
103
- deployment . proxyAddress as string ,
58
+ deployment . linkedData . proxyAddress as string ,
104
59
ContractFactory ,
105
60
{
106
61
kind : 'uups' ,
107
- constructorArgs : [
108
- TIME_TO_FINALIZE ,
109
- BLOCKS_PER_COMMIT_INTERVAL ,
110
- COMMIT_COOLDOWN ,
111
- ] ,
62
+ constructorArgs : deployment . linkedData . constructorArgs ,
112
63
}
113
64
) ;
114
65
115
66
console . log ( '--- Upgrade success' ) ;
116
67
localAddress = deployment . address ;
117
68
} else {
118
69
const localContract = await ContractFactory . deploy (
119
- ...deployment . args
70
+ ...deployment . linkedData . constructorArgs
120
71
) ;
121
72
await localContract . deployed ( ) ;
122
73
localAddress = await localContract . getAddress ( ) ;
123
74
}
124
75
125
76
console . log ( '--- Fetching local deployment bytecode...' ) ;
126
77
let localBytecode : string ;
127
- if ( deployment . isProxy ) {
78
+ if ( deployment . linkedData . isProxy ) {
128
79
const localImplementationAddress =
129
80
await localHardhat . upgrades . erc1967 . getImplementationAddress (
130
81
localAddress
@@ -153,17 +104,17 @@ task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
153
104
hre . ethers . keccak256 ( localBytecode )
154
105
) {
155
106
console . log (
156
- `✅ ${ deployment . contractName } (${ deployment . address } ): Bytecode verified successfully`
107
+ `✅ ${ contractName } (${ deployment . address } ): Bytecode verified successfully`
157
108
) ;
158
109
} else {
159
110
console . log (
160
- `❌ ${ deployment . contractName } (${ deployment . address } ): Bytecode mismatch`
111
+ `❌ ${ contractName } (${ deployment . address } ): Bytecode mismatch`
161
112
) ;
162
113
throw new Error ( 'Bytecode mismatch' ) ;
163
114
}
164
115
} catch ( error ) {
165
116
console . log (
166
- `❌ ${ deployment . contractName } (${ deployment . address } ): Verification failed`
117
+ `❌ ${ contractName } (${ deployment . address } ): Verification failed`
167
118
) ;
168
119
console . error ( ` Error: ${ error . message } ` ) ;
169
120
}
0 commit comments