@@ -62,10 +62,22 @@ export default async function deploy() {
6262 ? await getOrDeployRlc ( deploymentOptions . token ! , deployer , ownerAddress ) // token
6363 : ZeroAddress ; // native
6464 console . log ( `RLC: ${ rlcInstanceAddress } ` ) ;
65+ // Prepare transferOwnership call to the deployer.
66+ // Ownership transfer should be done in the same deployment transaction
67+ // otherwise it is not possible to transfer ownership before hand if the
68+ // factory is set as the owner.
69+ const transferOwnershipToDeployerCall = await Ownable__factory . connect (
70+ ZeroAddress , // any is fine
71+ ethers . provider ,
72+ )
73+ . transferOwnership . populateTransaction ( deployer . address )
74+ . then ( ( tx ) => tx . data )
75+ . catch ( ( ) => {
76+ throw new Error ( 'Failed to prepare transferOwnership data' ) ;
77+ } ) ;
6578 /**
6679 * Deploy proxy and facets.
6780 */
68- // TODO put inside init() function.
6981 const diamondProxyAddress = await deployDiamondProxyWithDefaultFacets ( deployer ) ;
7082 const diamond = DiamondCutFacet__factory . connect ( diamondProxyAddress , deployer ) ;
7183 console . log ( `IexecInstance found at address: ${ await diamond . getAddress ( ) } ` ) ;
@@ -114,14 +126,20 @@ export default async function deploy() {
114126 /**
115127 * Deploy registries and link them to the proxy.
116128 */
117- const appRegistryAddress = await factoryDeployer . deployContract ( new AppRegistry__factory ( ) , [ ] ) ;
129+ const appRegistryAddress = await factoryDeployer . deployContract (
130+ new AppRegistry__factory ( ) ,
131+ [ ] ,
132+ transferOwnershipToDeployerCall ,
133+ ) ;
118134 const datasetRegistryAddress = await factoryDeployer . deployContract (
119135 new DatasetRegistry__factory ( ) ,
120136 [ ] ,
137+ transferOwnershipToDeployerCall ,
121138 ) ;
122139 const workerpoolRegistryAddress = await factoryDeployer . deployContract (
123140 new WorkerpoolRegistry__factory ( ) ,
124141 [ ] ,
142+ transferOwnershipToDeployerCall ,
125143 ) ;
126144
127145 const appRegistryInstance = AppRegistry__factory . connect ( appRegistryAddress , deployer ) ;
@@ -197,7 +215,7 @@ export default async function deploy() {
197215 console . log ( `Category ${ i } : ${ await iexecAccessorsInstance . viewCategory ( i ) } ` ) ;
198216 }
199217 // Transfer ownership of all contracts to the configured owner.
200- await transferOwnershipOfProxyAndRegistries (
218+ await transferOwnershipToFinalOwner (
201219 diamondProxyAddress ,
202220 appRegistryAddress ,
203221 datasetRegistryAddress ,
@@ -281,25 +299,26 @@ async function deployDiamondProxyWithDefaultFacets(deployer: SignerWithAddress):
281299 ] ) ;
282300}
283301
284- async function transferOwnershipOfProxyAndRegistries (
302+ /**
303+ * Prepares the transferOwnership calls for all provided contracts.
304+ */
305+ async function transferOwnershipToFinalOwner (
285306 diamondAddress : string ,
286307 appRegistryAddress : string ,
287308 datasetRegistryAddress : string ,
288309 workerpoolRegistryAddress : string ,
289- deployer : SignerWithAddress ,
310+ currentOwner : SignerWithAddress ,
290311 ownerAddress : string ,
291312) {
292- for ( const contractAddress of [
293- diamondAddress ,
294- appRegistryAddress ,
295- datasetRegistryAddress ,
296- workerpoolRegistryAddress ,
313+ for ( const contract of [
314+ { name : 'Diamond' , address : diamondAddress } ,
315+ { name : 'AppRegistry' , address : appRegistryAddress } ,
316+ { name : 'DatasetRegistry' , address : datasetRegistryAddress } ,
317+ { name : 'WorkerpoolRegistry' , address : workerpoolRegistryAddress } ,
297318 ] ) {
298- const contractAsOwnable = Ownable__factory . connect ( contractAddress , deployer ) ;
299- const currentOwner = await contractAsOwnable . owner ( ) ;
300- await contractAsOwnable . transferOwnership ( ownerAddress ) . then ( ( tx ) => tx . wait ( ) ) ;
301- console . log (
302- `Ownership of contract ${ contractAddress } transferred from ${ currentOwner } to ${ ownerAddress } ` ,
303- ) ;
319+ await Ownable__factory . connect ( contract . address , currentOwner )
320+ . transferOwnership ( ownerAddress )
321+ . then ( ( tx ) => tx . wait ( ) ) ;
322+ console . log ( `Owner of ${ contract . name } : ${ ownerAddress } ` ) ;
304323 }
305- }
324+ }
0 commit comments