@@ -48,33 +48,22 @@ export default async function deploy() {
4848 console . log ( 'Deploying PoCo..' ) ;
4949 const network = await ethers . provider . getNetwork ( ) ;
5050 const chainId = network . chainId ;
51- const [ owner ] = await ethers . getSigners ( ) ;
51+ const [ deployer ] = await ethers . getSigners ( ) ;
5252 const deploymentOptions = config . getChainConfigOrDefault ( chainId ) ;
53- factoryDeployer = new FactoryDeployer ( owner , chainId ) ;
53+ const ownerAddress = deploymentOptions . owner || deployer . address ;
54+ factoryDeployer = new FactoryDeployer ( deployer , chainId ) ;
5455 // Deploy RLC
5556 const isTokenMode = ! config . isNativeChain ( deploymentOptions ) ;
5657 let rlcInstanceAddress = isTokenMode
57- ? await getOrDeployRlc ( deploymentOptions . token ! , owner ) // token
58+ ? await getOrDeployRlc ( deploymentOptions . token ! , deployer , ownerAddress ) // token
5859 : ZeroAddress ; // native
5960 console . log ( `RLC: ${ rlcInstanceAddress } ` ) ;
6061 /**
6162 * Deploy proxy and facets.
6263 */
6364 // TODO put inside init() function.
64- const transferOwnershipCall = await Ownable__factory . connect (
65- ZeroAddress , // any is fine
66- owner , // any is fine
67- )
68- . transferOwnership . populateTransaction ( owner . address )
69- . then ( ( tx ) => tx . data )
70- . catch ( ( ) => {
71- throw new Error ( 'Failed to prepare transferOwnership data' ) ;
72- } ) ;
73- const diamondProxyAddress = await deployDiamondProxyWithDefaultFacets (
74- owner ,
75- // transferOwnershipCall, //TODO
76- ) ;
77- const diamond = DiamondCutFacet__factory . connect ( diamondProxyAddress , owner ) ;
65+ const diamondProxyAddress = await deployDiamondProxyWithDefaultFacets ( deployer ) ;
66+ const diamond = DiamondCutFacet__factory . connect ( diamondProxyAddress , deployer ) ;
7867 console . log ( `IexecInstance found at address: ${ await diamond . getAddress ( ) } ` ) ;
7968 // Deploy library & facets
8069 const iexecLibOrdersAddress = await factoryDeployer . deployContract (
@@ -106,7 +95,7 @@ export default async function deploy() {
10695 // Verify linking on Diamond Proxy
10796 const diamondLoupeFacetInstance : DiamondLoupeFacet = DiamondLoupeFacet__factory . connect (
10897 diamondProxyAddress ,
109- owner ,
98+ deployer ,
11099 ) ;
111100 const diamondFacets = await diamondLoupeFacetInstance . facets ( ) ;
112101 const functionCount = diamondFacets
@@ -121,27 +110,24 @@ export default async function deploy() {
121110 /**
122111 * Deploy registries and link them to the proxy.
123112 */
124- const appRegistryAddress = await factoryDeployer . deployContract (
125- new AppRegistry__factory ( ) ,
126- [ ] ,
127- transferOwnershipCall ,
128- ) ;
113+ const appRegistryAddress = await factoryDeployer . deployContract ( new AppRegistry__factory ( ) , [ ] ) ;
129114 const datasetRegistryAddress = await factoryDeployer . deployContract (
130115 new DatasetRegistry__factory ( ) ,
131116 [ ] ,
132- transferOwnershipCall ,
133117 ) ;
134118 const workerpoolRegistryAddress = await factoryDeployer . deployContract (
135119 new WorkerpoolRegistry__factory ( ) ,
136120 [ ] ,
137- transferOwnershipCall ,
138121 ) ;
139122
140- const appRegistryInstance = AppRegistry__factory . connect ( appRegistryAddress , owner ) ;
141- const datasetRegistryInstance = DatasetRegistry__factory . connect ( datasetRegistryAddress , owner ) ;
123+ const appRegistryInstance = AppRegistry__factory . connect ( appRegistryAddress , deployer ) ;
124+ const datasetRegistryInstance = DatasetRegistry__factory . connect (
125+ datasetRegistryAddress ,
126+ deployer ,
127+ ) ;
142128 const workerpoolRegistryInstance = WorkerpoolRegistry__factory . connect (
143129 workerpoolRegistryAddress ,
144- owner ,
130+ deployer ,
145131 ) ;
146132 // Base URI configuration from config.json
147133 const baseURIApp = config . registriesBaseUri . app ;
@@ -172,11 +158,11 @@ export default async function deploy() {
172158 }
173159
174160 // Set main configuration
175- const iexecAccessorsInstance = IexecAccessors__factory . connect ( diamondProxyAddress , owner ) ;
161+ const iexecAccessorsInstance = IexecAccessors__factory . connect ( diamondProxyAddress , deployer ) ;
176162 const iexecInitialized = ( await iexecAccessorsInstance . eip712domain_separator ( ) ) != ZeroHash ;
177163 if ( ! iexecInitialized ) {
178164 // TODO replace this with DiamondInit.init().
179- await IexecConfigurationFacet__factory . connect ( diamondProxyAddress , owner )
165+ await IexecConfigurationFacet__factory . connect ( diamondProxyAddress , deployer )
180166 . configure (
181167 rlcInstanceAddress ,
182168 'Staked RLC' ,
@@ -193,7 +179,7 @@ export default async function deploy() {
193179 const catCountBefore = await iexecAccessorsInstance . countCategory ( ) ;
194180 for ( let i = Number ( catCountBefore ) ; i < config . categories . length ; i ++ ) {
195181 const category = config . categories [ i ] ;
196- await IexecCategoryManager__factory . connect ( diamondProxyAddress , owner )
182+ await IexecCategoryManager__factory . connect ( diamondProxyAddress , deployer )
197183 . createCategory (
198184 category . name ,
199185 JSON . stringify ( category . description ) ,
@@ -206,16 +192,28 @@ export default async function deploy() {
206192 for ( let i = 0 ; i < Number ( catCountAfter ) ; i ++ ) {
207193 console . log ( `Category ${ i } : ${ await iexecAccessorsInstance . viewCategory ( i ) } ` ) ;
208194 }
209-
195+ // Transfer ownership of all contracts to the configured owner.
196+ await transferOwnershipOfProxyAndRegistries (
197+ diamondProxyAddress ,
198+ appRegistryAddress ,
199+ datasetRegistryAddress ,
200+ workerpoolRegistryAddress ,
201+ deployer ,
202+ ownerAddress ,
203+ ) ;
210204 if ( network . name !== 'hardhat' && network . name !== 'localhost' ) {
211205 console . log ( 'Waiting for block explorer to index the contracts...' ) ;
212206 await new Promise ( ( resolve ) => setTimeout ( resolve , 60000 ) ) ;
213207 await import ( '../scripts/verify' ) . then ( ( module ) => module . default ( ) ) ;
214208 }
215209}
216210
217- async function getOrDeployRlc ( token : string , owner : SignerWithAddress ) {
218- const rlcFactory = new RLC__factory ( ) . connect ( owner ) ;
211+ async function getOrDeployRlc (
212+ token : string ,
213+ deployer : SignerWithAddress ,
214+ ownerAddress : string ,
215+ ) : Promise < string > {
216+ const rlcFactory = new RLC__factory ( ) . connect ( deployer ) ;
219217 let rlcAddress : string ;
220218
221219 if ( token ) {
@@ -228,6 +226,10 @@ async function getOrDeployRlc(token: string, owner: SignerWithAddress) {
228226 . then ( ( contract ) => contract . waitForDeployment ( ) )
229227 . then ( ( contract ) => contract . getAddress ( ) ) ;
230228 console . log ( `New RLC token deployed at: ${ rlcAddress } ` ) ;
229+ await Ownable__factory . connect ( rlcAddress , deployer )
230+ . transferOwnership ( ownerAddress )
231+ . then ( ( tx ) => tx . wait ( ) ) ;
232+ console . log ( `Ownership of RLC token transferred to: ${ deployer . address } ` ) ;
231233 }
232234
233235 await deployments . save ( 'RLC' , {
@@ -243,13 +245,10 @@ async function getOrDeployRlc(token: string, owner: SignerWithAddress) {
243245 * Deploys and initializes a Diamond proxy contract with default facets.
244246 * @returns The address of the deployed Diamond proxy contract.
245247 */
246- async function deployDiamondProxyWithDefaultFacets (
247- owner : SignerWithAddress ,
248- // transferOwnershipCall: string, // TODO
249- ) : Promise < string > {
248+ async function deployDiamondProxyWithDefaultFacets ( deployer : SignerWithAddress ) : Promise < string > {
250249 const initAddress = await factoryDeployer . deployContract ( new DiamondInit__factory ( ) ) ;
251250 const initCalldata = DiamondInit__factory . createInterface ( ) . encodeFunctionData ( 'init' ) ;
252- const libDiamondConfig = await getLibDiamondConfigOrEmpty ( owner ) ;
251+ const libDiamondConfig = await getLibDiamondConfigOrEmpty ( deployer ) ;
253252 // Deploy required proxy facets.
254253 const facetFactories = [
255254 new DiamondCutFacet__factory ( libDiamondConfig ) ,
@@ -268,13 +267,35 @@ async function deployDiamondProxyWithDefaultFacets(
268267 }
269268 // Set diamond constructor arguments
270269 const diamondArgs : DiamondArgsStruct = {
271- owner : owner . address ,
270+ owner : deployer . address ,
272271 init : initAddress ,
273272 initCalldata : initCalldata ,
274273 } ;
275- return await factoryDeployer . deployContract (
276- new Diamond__factory ( libDiamondConfig ) ,
277- [ facetCuts , diamondArgs ] ,
278- // transferOwnershipCall, // TODO
279- ) ;
274+ return await factoryDeployer . deployContract ( new Diamond__factory ( libDiamondConfig ) , [
275+ facetCuts ,
276+ diamondArgs ,
277+ ] ) ;
280278}
279+
280+ async function transferOwnershipOfProxyAndRegistries (
281+ diamondAddress : string ,
282+ appRegistryAddress : string ,
283+ datasetRegistryAddress : string ,
284+ workerpoolRegistryAddress : string ,
285+ deployer : SignerWithAddress ,
286+ ownerAddress : string ,
287+ ) {
288+ for ( const contractAddress of [
289+ diamondAddress ,
290+ appRegistryAddress ,
291+ datasetRegistryAddress ,
292+ workerpoolRegistryAddress ,
293+ ] ) {
294+ const contractAsOwnable = Ownable__factory . connect ( contractAddress , deployer ) ;
295+ const currentOwner = await contractAsOwnable . owner ( ) ;
296+ await contractAsOwnable . transferOwnership ( ownerAddress ) . then ( ( tx ) => tx . wait ( ) ) ;
297+ console . log (
298+ `Ownership of contract ${ contractAddress } transferred from ${ currentOwner } to ${ ownerAddress } ` ,
299+ ) ;
300+ }
301+ }
0 commit comments