11// SPDX-FileCopyrightText: 2025 IEXEC BLOCKCHAIN TECH <[email protected] > 22// SPDX-License-Identifier: Apache-2.0
33
4+ import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers' ;
45import { ZeroAddress } from 'ethers' ;
56import { ethers } from 'hardhat' ;
67import { FacetCutAction } from 'hardhat-deploy/dist/types' ;
7- import type { IDiamond } from '../../typechain' ;
8+ import type { DiamondCutFacet , IDiamond } from '../../typechain' ;
89import {
910 DiamondCutFacet__factory ,
1011 DiamondLoupeFacet__factory ,
@@ -19,7 +20,7 @@ import { linkContractToProxy } from '../../utils/proxy-tools';
1920import { tryVerify } from '../verify' ;
2021import { printFunctions } from './upgrade-helper' ;
2122
22- ( async ( ) => {
23+ async function main ( ) {
2324 console . log ( 'Deploying and updating IexecPocoAccessorsFacet & IexecPoco1Facet...' ) ;
2425
2526 const { deployer, owner } = await getDeployerAndOwnerSigners ( ) ;
@@ -50,12 +51,49 @@ import { printFunctions } from './upgrade-helper';
5051 proxyOwnerSigner ,
5152 ) ;
5253
53- console . log ( '\n=== Step 1: Deploying all new facets ===' ) ;
54- const factoryDeployer = new FactoryDeployer ( deployer , chainId ) ;
54+ const { iexecPocoAccessorsFacet, newIexecPoco1Facet } = await deployNewFacets (
55+ deployer ,
56+ chainId ,
57+ deploymentOptions . IexecLibOrders_v5 ,
58+ ) ;
5559 const iexecLibOrders = {
5660 [ 'contracts/libs/IexecLibOrders_v5.sol:IexecLibOrders_v5' ] :
5761 deploymentOptions . IexecLibOrders_v5 ,
5862 } ;
63+ const iexecPocoAccessorsFacetFactory = new IexecPocoAccessorsFacet__factory ( iexecLibOrders ) ;
64+ const newIexecPoco1FacetFactory = new IexecPoco1Facet__factory ( iexecLibOrders ) ;
65+ await removeOldFacetsFromDiamond ( diamondProxyAsOwner , chainId ) ;
66+ await linkNewFacetsToDiamond (
67+ diamondProxyAsOwner ,
68+ iexecPocoAccessorsFacet ,
69+ newIexecPoco1Facet ,
70+ iexecPocoAccessorsFacetFactory ,
71+ newIexecPoco1FacetFactory ,
72+ ) ;
73+ await tryVerify ( [
74+ {
75+ name : 'IexecPocoAccessorsFacet' ,
76+ address : iexecPocoAccessorsFacet ,
77+ constructorArguments : [ ] ,
78+ } ,
79+ {
80+ name : 'IexecPoco1Facet' ,
81+ address : newIexecPoco1Facet ,
82+ constructorArguments : [ ] ,
83+ } ,
84+ ] ) ;
85+ }
86+
87+ async function deployNewFacets (
88+ deployer : SignerWithAddress ,
89+ chainId : bigint ,
90+ iexecLibOrdersAddress : string ,
91+ ) {
92+ console . log ( '\n=== Step 1: Deploying all new facets ===' ) ;
93+ const factoryDeployer = new FactoryDeployer ( deployer , chainId ) ;
94+ const iexecLibOrders = {
95+ [ 'contracts/libs/IexecLibOrders_v5.sol:IexecLibOrders_v5' ] : iexecLibOrdersAddress ,
96+ } ;
5997
6098 console . log ( 'Deploying new IexecPocoAccessorsFacet...' ) ;
6199 const iexecPocoAccessorsFacetFactory = new IexecPocoAccessorsFacet__factory ( iexecLibOrders ) ;
@@ -66,12 +104,16 @@ import { printFunctions } from './upgrade-helper';
66104 console . log ( 'Deploying new IexecPoco1Facet...' ) ;
67105 const newIexecPoco1FacetFactory = new IexecPoco1Facet__factory ( iexecLibOrders ) ;
68106 const newIexecPoco1Facet = await factoryDeployer . deployContract ( newIexecPoco1FacetFactory ) ;
107+ return { iexecPocoAccessorsFacet, newIexecPoco1Facet } ;
108+ }
69109
110+ async function removeOldFacetsFromDiamond ( diamondProxyAsOwner : DiamondCutFacet , chainId : bigint ) {
111+ const diamondProxyAddress = await diamondProxyAsOwner . getAddress ( ) ;
70112 console . log (
71113 '\n=== Step 2: Remove old facets (IexecAccessorsFacet & IexecPocoAccessorsFacet & IexecPoco1Facet) ===' ,
72114 ) ;
73115
74- const diamondLoupe = DiamondLoupeFacet__factory . connect ( diamondProxyAddress , owner ) ;
116+ const diamondLoupe = DiamondLoupeFacet__factory . connect ( diamondProxyAddress , ethers . provider ) ;
75117 const currentFacets = await diamondLoupe . facets ( ) ;
76118
77119 console . log ( '\nCurrent facets in diamond:' ) ;
@@ -142,6 +184,16 @@ import { printFunctions } from './upgrade-helper';
142184 console . log ( 'Diamond functions after removing old facets:' ) ;
143185 await printFunctions ( diamondProxyAddress ) ;
144186 }
187+ }
188+
189+ async function linkNewFacetsToDiamond (
190+ diamondProxyAsOwner : DiamondCutFacet ,
191+ iexecPocoAccessorsFacet : string ,
192+ newIexecPoco1Facet : string ,
193+ iexecPocoAccessorsFacetFactory : IexecPocoAccessorsFacet__factory ,
194+ newIexecPoco1FacetFactory : IexecPoco1Facet__factory ,
195+ ) {
196+ const diamondProxyAddress = await diamondProxyAsOwner . getAddress ( ) ;
145197 console . log ( '\n=== Step 3: Updating diamond proxy with all new facets ===' ) ;
146198 console . log ( 'Adding new IexecPocoAccessorsFacet...' ) ;
147199 await linkContractToProxy (
@@ -161,16 +213,11 @@ import { printFunctions } from './upgrade-helper';
161213 console . log ( '\nUpgrade completed successfully!' ) ;
162214 console . log ( `New IexecPocoAccessorsFacet deployed at: ${ iexecPocoAccessorsFacet } ` ) ;
163215 console . log ( `New IexecPoco1Facet deployed at: ${ newIexecPoco1Facet } ` ) ;
164- await tryVerify ( [
165- {
166- name : 'IexecPocoAccessorsFacet' ,
167- address : iexecPocoAccessorsFacet ,
168- constructorArguments : [ ] ,
169- } ,
170- {
171- name : 'IexecPoco1Facet' ,
172- address : newIexecPoco1Facet ,
173- constructorArguments : [ ] ,
174- } ,
175- ] ) ;
176- } ) ( ) ;
216+ }
217+
218+ if ( require . main === module ) {
219+ main ( ) . catch ( ( error ) => {
220+ console . error ( error ) ;
221+ process . exitCode = 1 ;
222+ } ) ;
223+ }
0 commit comments