2121// dry-run (default): SLOT_NAME=Foo npx hardhat run scripts/replace_hub_slot.ts --network <net>
2222// live: SLOT_NAME=Foo REGISTRY_REPLACE_WRITE=1 npx hardhat run scripts/replace_hub_slot.ts --network <net>
2323
24+ /* eslint-disable @typescript-eslint/no-explicit-any */
25+
2426import * as fs from 'fs' ;
2527import * as path from 'path' ;
2628
@@ -37,14 +39,24 @@ async function main() {
3739
3840 console . log ( `╔════ Replace Hub slot "${ SLOT } " on ${ network . name } ════╗` ) ;
3941
40- const deploymentsPath = path . join ( __dirname , '..' , 'deployments' , `${ network . name } _contracts.json` ) ;
42+ const deploymentsPath = path . join (
43+ __dirname ,
44+ '..' ,
45+ 'deployments' ,
46+ `${ network . name } _contracts.json` ,
47+ ) ;
4148 if ( ! fs . existsSync ( deploymentsPath ) ) {
42- throw new Error ( `No deployments JSON for network "${ network . name } " at ${ deploymentsPath } ` ) ;
49+ throw new Error (
50+ `No deployments JSON for network "${ network . name } " at ${ deploymentsPath } ` ,
51+ ) ;
4352 }
44- const { contracts } = JSON . parse ( fs . readFileSync ( deploymentsPath , 'utf8' ) ) as {
53+ const { contracts } = JSON . parse (
54+ fs . readFileSync ( deploymentsPath , 'utf8' ) ,
55+ ) as {
4556 contracts : Record < string , { evmAddress : string } > ;
4657 } ;
47- if ( ! contracts . Hub ?. evmAddress ) throw new Error ( 'Hub.evmAddress missing in deployments JSON' ) ;
58+ if ( ! contracts . Hub ?. evmAddress )
59+ throw new Error ( 'Hub.evmAddress missing in deployments JSON' ) ;
4860 const HUB = contracts . Hub . evmAddress ;
4961
5062 const hub = await ethers . getContractAt (
@@ -64,25 +76,37 @@ async function main() {
6476
6577 const slotExists = await hub [ 'isContract(string)' ] ( SLOT ) ;
6678 if ( ! slotExists ) {
67- throw new Error ( `Sanity fail: Hub has no slot named "${ SLOT } ". Check the spelling.` ) ;
79+ throw new Error (
80+ `Sanity fail: Hub has no slot named "${ SLOT } ". Check the spelling.` ,
81+ ) ;
6882 }
6983
7084 console . log ( '\n--- BEFORE ---' ) ;
7185 const beforeAddr = await hub . getContractAddress ( SLOT ) ;
7286 const beforeTargetRegistered = await hub [ 'isContract(address)' ] ( beforeAddr ) ;
73- const beforePlaceholderRegistered = await hub [ 'isContract(address)' ] ( PLACEHOLDER ) ;
74- const beforeBytecodeLen = ( ( await ethers . provider . getCode ( beforeAddr ) ) . length - 2 ) / 2 ;
87+ const beforePlaceholderRegistered =
88+ await hub [ 'isContract(address)' ] ( PLACEHOLDER ) ;
89+ const beforeBytecodeLen =
90+ ( ( await ethers . provider . getCode ( beforeAddr ) ) . length - 2 ) / 2 ;
7591 console . log ( `Hub.getContractAddress("${ SLOT } ") = ${ beforeAddr } ` ) ;
76- console . log ( `bytecode at currently-registered addr = ${ beforeBytecodeLen } bytes` ) ;
77- console . log ( `Hub.isContract(<currently-registered>) = ${ beforeTargetRegistered } ` ) ;
78- console . log ( `Hub.isContract(<placeholder>) = ${ beforePlaceholderRegistered } ` ) ;
92+ console . log (
93+ `bytecode at currently-registered addr = ${ beforeBytecodeLen } bytes` ,
94+ ) ;
95+ console . log (
96+ `Hub.isContract(<currently-registered>) = ${ beforeTargetRegistered } ` ,
97+ ) ;
98+ console . log (
99+ `Hub.isContract(<placeholder>) = ${ beforePlaceholderRegistered } ` ,
100+ ) ;
79101
80102 if ( beforeAddr . toLowerCase ( ) === PLACEHOLDER . toLowerCase ( ) ) {
81103 console . log ( `NOOP: slot already points at placeholder. Nothing to do.` ) ;
82104 return ;
83105 }
84106 if ( beforePlaceholderRegistered ) {
85- throw new Error ( `Sanity fail: placeholder ${ PLACEHOLDER } is already in Hub.contractSet under a different slot. Aborting.` ) ;
107+ throw new Error (
108+ `Sanity fail: placeholder ${ PLACEHOLDER } is already in Hub.contractSet under a different slot. Aborting.` ,
109+ ) ;
86110 }
87111 if ( beforeBytecodeLen === 0 && process . env . ALLOW_NON_CONTRACT !== '1' ) {
88112 throw new Error (
@@ -99,37 +123,55 @@ async function main() {
99123 console . log (
100124 '\n[DRY-RUN] REGISTRY_REPLACE_WRITE != "1" — not sending tx. Set REGISTRY_REPLACE_WRITE=1 to execute.' ,
101125 ) ;
102- const calldata = hub . interface . encodeFunctionData ( 'setContractAddress' , [ SLOT , PLACEHOLDER ] ) ;
126+ const calldata = hub . interface . encodeFunctionData ( 'setContractAddress' , [
127+ SLOT ,
128+ PLACEHOLDER ,
129+ ] ) ;
103130 console . log ( 'Calldata that would be sent:' ) ;
104131 console . log ( ` to: ${ HUB } ` ) ;
105132 console . log ( ` data: ${ calldata } ` ) ;
106133 return ;
107134 }
108135
109- console . log ( `\nSending Hub.setContractAddress("${ SLOT } ", "${ PLACEHOLDER } ")...` ) ;
136+ console . log (
137+ `\nSending Hub.setContractAddress("${ SLOT } ", "${ PLACEHOLDER } ")...` ,
138+ ) ;
110139 const tx = await hub . connect ( signer ) . setContractAddress ( SLOT , PLACEHOLDER ) ;
111140 console . log ( `tx hash: ${ tx . hash } ` ) ;
112141 const rc = await tx . wait ( ) ;
113- console . log ( `mined in block ${ rc ?. blockNumber } , gas used ${ rc ?. gasUsed ?. toString ( ) } ` ) ;
142+ console . log (
143+ `mined in block ${ rc ?. blockNumber } , gas used ${ rc ?. gasUsed ?. toString ( ) } ` ,
144+ ) ;
114145
115146 console . log ( '\n--- AFTER ---' ) ;
116147 const afterAddr = await hub . getContractAddress ( SLOT ) ;
117148 const afterTargetRegistered = await hub [ 'isContract(address)' ] ( beforeAddr ) ;
118- const afterPlaceholderRegistered = await hub [ 'isContract(address)' ] ( PLACEHOLDER ) ;
149+ const afterPlaceholderRegistered =
150+ await hub [ 'isContract(address)' ] ( PLACEHOLDER ) ;
119151 console . log ( `Hub.getContractAddress("${ SLOT } ") = ${ afterAddr } ` ) ;
120- console . log ( `Hub.isContract(<previously-registered ${ beforeAddr } >) = ${ afterTargetRegistered } ` ) ;
121- console . log ( `Hub.isContract(<placeholder>) = ${ afterPlaceholderRegistered } ` ) ;
152+ console . log (
153+ `Hub.isContract(<previously-registered ${ beforeAddr } >) = ${ afterTargetRegistered } ` ,
154+ ) ;
155+ console . log (
156+ `Hub.isContract(<placeholder>) = ${ afterPlaceholderRegistered } ` ,
157+ ) ;
122158
123159 if ( afterAddr . toLowerCase ( ) !== PLACEHOLDER . toLowerCase ( ) ) {
124- throw new Error ( `POST-CHECK FAIL: slot did not move to placeholder (got ${ afterAddr } )` ) ;
160+ throw new Error (
161+ `POST-CHECK FAIL: slot did not move to placeholder (got ${ afterAddr } )` ,
162+ ) ;
125163 }
126164 if ( afterTargetRegistered ) {
127- throw new Error ( `POST-CHECK FAIL: previously-registered address is still in Hub.contractSet` ) ;
165+ throw new Error (
166+ `POST-CHECK FAIL: previously-registered address is still in Hub.contractSet` ,
167+ ) ;
128168 }
129169 if ( ! afterPlaceholderRegistered ) {
130170 throw new Error ( `POST-CHECK FAIL: placeholder is not in Hub.contractSet` ) ;
131171 }
132- console . log ( `\n✓ SLOT "${ SLOT } " UPDATED. Hub no longer authorises ${ beforeAddr } .` ) ;
172+ console . log (
173+ `\n✓ SLOT "${ SLOT } " UPDATED. Hub no longer authorises ${ beforeAddr } .` ,
174+ ) ;
133175}
134176
135177main ( ) . catch ( ( e ) => {
0 commit comments