11import * as fs from 'fs' ;
22import { deployments , ethers } from 'hardhat' ;
33import * as path from 'path' ;
4- import config from '../../utils/config' ;
5-
6- // Get the absolute path to the config file
7- const configPath = path . resolve ( 'config/config.json' ) ;
4+ import localConfig from '../../utils/config' ;
85
96async function main ( ) : Promise < void > {
7+ // Get the absolute path to the config file
8+ const configPath = path . resolve ( 'config/config.json' ) ;
109 // Get network info from ethers
1110 const network = await ethers . provider . getNetwork ( ) ;
1211 const networkName = network . name ;
1312 const chainId = network . chainId . toString ( ) ;
1413
1514 console . log ( `Working with network: ${ networkName } (Chain ID: ${ chainId } )` ) ;
16- const deployment = await deployments . get ( 'DiamondProxy ' ) ;
15+ const deployment = await deployments . get ( 'Diamond ' ) ;
1716 const contractAddress = deployment . address ;
1817
1918 if ( ! contractAddress || contractAddress === 'null' ) {
20- console . error ( `Failed to extract a valid DiamondProxy address from deployment file ` ) ;
19+ console . error ( `Failed to extract a valid Diamond proxy address from Hardhat deployment ` ) ;
2120 process . exit ( 1 ) ;
2221 }
23-
24- console . log ( `Found DiamondProxy address: ${ contractAddress } ` ) ;
25- const localConfig = config ;
22+ console . log ( `Diamond proxy address to save: ${ contractAddress } ` ) ;
2623
2724 // Ensure the chain structure exists
2825 if ( ! localConfig . chains ) {
2926 localConfig . chains = { } ;
3027 }
31-
3228 if ( ! localConfig . chains [ chainId ] ) {
3329 localConfig . chains [ chainId ] = {
34- _comment : `Chain ${ chainId } (${ networkName } )` ,
30+ _comment : `Chain ${ networkName } (${ chainId } )` ,
3531 asset : 'Token' , // Default value, update as needed
3632 v3 : {
3733 Hub : null ,
@@ -42,21 +38,29 @@ async function main(): Promise<void> {
4238 v5 : { } ,
4339 } ;
4440 }
45-
4641 if ( ! localConfig . chains [ chainId ] . v5 ) {
4742 localConfig . chains [ chainId ] . v5 = { } ;
4843 }
49-
50- const contractKey = 'DiamondProxy' ;
51- const previousValue = localConfig . chains [ chainId ] . v5 [ contractKey ] || 'null' ;
52- localConfig . chains [ chainId ] . v5 [ contractKey ] = contractAddress ;
53-
44+ // Save the Diamond proxy address.
45+ const diamondProxyName = 'DiamondProxy' ;
46+ const previousDiamondAddress = localConfig . chains [ chainId ] . v5 [ diamondProxyName ] || 'null' ;
47+ localConfig . chains [ chainId ] . v5 [ diamondProxyName ] = contractAddress ;
48+ console . log (
49+ `Updated ${ chainId } .v5.${ diamondProxyName } from ${ previousDiamondAddress } to ${ contractAddress } ` ,
50+ ) ;
51+ // Save `IexecLibOrders_v5` address if it exists
52+ const iexecLibOrdersName = 'IexecLibOrders_v5' ;
53+ const iexecLibOrdersDeployment = await deployments . get ( iexecLibOrdersName ) ;
54+ if ( iexecLibOrdersDeployment && iexecLibOrdersDeployment . address ) {
55+ const previousLibAddress = localConfig . chains [ chainId ] . v5 [ iexecLibOrdersName ] || 'null' ;
56+ localConfig . chains [ chainId ] . v5 [ iexecLibOrdersName ] = iexecLibOrdersDeployment . address ;
57+ console . log (
58+ `Updated ${ chainId } .v5.${ iexecLibOrdersName } from ${ previousLibAddress } to ${ iexecLibOrdersDeployment . address } ` ,
59+ ) ;
60+ }
5461 // Write the updated config back to file
5562 fs . writeFileSync ( configPath , JSON . stringify ( localConfig , null , 2 ) ) ;
56-
57- console . log ( `Updated ${ chainId } .v5.${ contractKey } :` ) ;
58- console . log ( `Previous: ${ previousValue } ` ) ;
59- console . log ( `New: ${ contractAddress } ` ) ;
63+ console . log ( `Configuration updated successfully in ${ configPath } ` ) ;
6064}
6165
6266// Execute the main function and handle any errors
0 commit comments