@@ -44,6 +44,10 @@ const ContractABIPaths = {
44
44
ChainBridgeBatchRebaseReport : 'contracts/_utilities' ,
45
45
} ;
46
46
47
+ const sleep = ( sec ) => {
48
+ return new Promise ( ( resolve ) => setTimeout ( resolve , sec * 1000 ) ) ;
49
+ } ;
50
+
47
51
const getCompiledContractFactory = ( ethers , contract ) => {
48
52
return ethers . getContractFactory (
49
53
`${ ContractABIPaths [ contract ] } /${ contract } .sol:${ contract } ` ,
@@ -100,6 +104,63 @@ const deployProxyContract = async (
100
104
return contract ;
101
105
} ;
102
106
107
+ const upgradeProxyContract = async (
108
+ ethers ,
109
+ network ,
110
+ contractName ,
111
+ deployedContractRef ,
112
+ signer ,
113
+ txParams ,
114
+ force = false ,
115
+ ) => {
116
+ const proxyAdmin = await getDeployedContractInstance (
117
+ network ,
118
+ 'proxyAdmin' ,
119
+ ethers . provider ,
120
+ ) ;
121
+
122
+ const proxy = await getDeployedContractInstance (
123
+ network ,
124
+ deployedContractRef ,
125
+ ethers . provider ,
126
+ ) ;
127
+
128
+ const currentImplAddr = await proxyAdmin . getProxyImplementation ( proxy . address ) ;
129
+ console . log ( `Current implementation for ${ contractName } is at` , currentImplAddr ) ;
130
+
131
+ // deploy new implementation
132
+ let newImpl ;
133
+ if ( ! force ) {
134
+ const Factory = await getCompiledContractFactory ( ethers , contractName ) ;
135
+ newImpl = await upgrades . prepareUpgrade ( proxy . address , Factory ) ;
136
+ } else {
137
+ console . log ( `CAUTION: Skpping storage layout verification!` )
138
+ console . log ( `CANCEL NOW to stop, this action is not reversable` )
139
+ await sleep ( 10 ) ;
140
+ newImpl = await deployContract (
141
+ ethers ,
142
+ contractName ,
143
+ signer ,
144
+ [ ] ,
145
+ txParams ,
146
+ ) ;
147
+ }
148
+ console . log ( `New implementation for ${ contractName } is at` , newImpl . address ) ;
149
+
150
+ if ( ( await proxyAdmin . owner ( ) ) == ( await signer . getAddress ( ) ) ) {
151
+ await proxyAdmin
152
+ . connect ( signer )
153
+ . upgrade ( proxy . address , newImpl . address , txParams ) ;
154
+ } else {
155
+ console . log ( 'Signer not proxy onwer, cant upgrade' ) ;
156
+ console . log (
157
+ `Execute proxyAdmin.upgrade(${ proxy . address } , ${ newImpl . address } )` ,
158
+ ) ;
159
+ }
160
+
161
+ return newImpl ;
162
+ } ;
163
+
103
164
const getDeployedContractInstance = async ( network , contractName , provider ) => {
104
165
const contractData = await readContractDeploymentData ( network , contractName ) ;
105
166
return new ethers . Contract ( contractData . address , contractData . abi , provider ) ;
@@ -188,10 +249,6 @@ const filterContractEvents = async (
188
249
endBlock = endBlock || ( await provider . getBlockNumber ( ) ) ;
189
250
const freq = timeFrameSec * BLOCKS_PER_SEC ;
190
251
191
- const sleep = ( sec ) => {
192
- return new Promise ( ( resolve ) => setTimeout ( resolve , sec * 1000 ) ) ;
193
- } ;
194
-
195
252
console . log ( address , event , startBlock , endBlock , timeFrameSec ) ;
196
253
197
254
let logs = [ ] ;
@@ -250,6 +307,7 @@ module.exports = {
250
307
deployContract,
251
308
deployProxyAdminContract,
252
309
deployProxyContract,
310
+ upgradeProxyContract,
253
311
254
312
filterContractEvents,
255
313
} ;
0 commit comments