@@ -9,14 +9,14 @@ import {
9
9
import { LibString } from "../lib/solady/src/utils/LibString.sol " ;
10
10
import { console, LibSharedAddress, StdStyle, IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol " ;
11
11
import { IArtifactFactory, ArtifactFactory } from "./ArtifactFactory.sol " ;
12
- import { OnchainDebugger } from "./OnchainDebugger .s.sol " ; // cheat to load artifact to parent `out` directory
12
+ import { OnchainExecutor } from "./OnchainExecutor .s.sol " ; // cheat to load artifact to parent `out` directory
13
13
import { IMigrationScript } from "./interfaces/IMigrationScript.sol " ;
14
14
import { LibProxy } from "./libraries/LibProxy.sol " ;
15
15
import { DefaultContract } from "./utils/DefaultContract.sol " ;
16
16
import { TContract } from "./types/Types.sol " ;
17
17
18
18
abstract contract BaseMigration is ScriptExtended {
19
- using StdStyle for string ;
19
+ using StdStyle for * ;
20
20
using LibString for bytes32 ;
21
21
using LibProxy for address payable ;
22
22
@@ -232,6 +232,7 @@ abstract contract BaseMigration is ScriptExtended {
232
232
function _upgradeRaw (address proxyAdmin , address payable proxy , address logic , bytes memory args ) internal virtual {
233
233
ITransparentUpgradeableProxy iProxy = ITransparentUpgradeableProxy (proxy);
234
234
ProxyAdmin wProxyAdmin = ProxyAdmin (proxyAdmin);
235
+
235
236
// if proxyAdmin is External Owned Wallet
236
237
if (proxyAdmin.code.length == 0 ) {
237
238
vm.broadcast (proxyAdmin);
@@ -240,31 +241,91 @@ abstract contract BaseMigration is ScriptExtended {
240
241
} else {
241
242
try wProxyAdmin.owner () returns (address owner ) {
242
243
if (args.length == 0 ) {
243
- // try `upgrade` function
244
+ // try `upgrade(address,address) ` function
244
245
vm.prank (owner);
245
246
(bool success ,) = proxyAdmin.call (abi.encodeCall (ProxyAdmin.upgrade, (iProxy, logic)));
246
247
if (success) {
247
- vm.broadcast (owner);
248
- wProxyAdmin.upgrade (iProxy, logic);
248
+ if (owner.code.length != 0 ) {
249
+ _cheatUpgrade (owner, wProxyAdmin, iProxy, logic);
250
+ } else {
251
+ vm.broadcast (owner);
252
+ wProxyAdmin.upgrade (iProxy, logic);
253
+ }
249
254
} else {
250
255
console.log (
251
- StdStyle.yellow (
252
- "`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args... "
253
- )
256
+ "`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args... " .yellow ()
254
257
);
258
+ if (owner.code.length != 0 ) {
259
+ _cheatUpgradeAndCall (owner, wProxyAdmin, iProxy, logic, args);
260
+ } else {
261
+ vm.broadcast (owner);
262
+ wProxyAdmin.upgradeAndCall (iProxy, logic, args);
263
+ }
264
+ }
265
+ } else {
266
+ if (owner.code.length != 0 ) {
267
+ _cheatUpgradeAndCall (owner, wProxyAdmin, iProxy, logic, args);
268
+ } else {
255
269
vm.broadcast (owner);
256
270
wProxyAdmin.upgradeAndCall (iProxy, logic, args);
257
271
}
258
- } else {
259
- vm.broadcast (owner);
260
- wProxyAdmin.upgradeAndCall (iProxy, logic, args);
261
272
}
262
273
} catch {
263
274
revert ("BaseMigration: Unknown ProxyAdmin contract! " );
264
275
}
265
276
}
266
277
}
267
278
279
+ function _cheatUpgrade (address owner , ProxyAdmin wProxyAdmin , ITransparentUpgradeableProxy iProxy , address logic )
280
+ internal
281
+ virtual
282
+ {
283
+ bytes memory callData = abi.encodeCall (ProxyAdmin.upgrade, (iProxy, logic));
284
+ console.log (
285
+ "------------------------------------------------------------------------------- Multi-Sig Proposal ------------------------------------------------------------------------------- "
286
+ );
287
+ console.log ("To: " .cyan (), vm.getLabel (address (wProxyAdmin)));
288
+ console.log (
289
+ "Method:\n " .cyan (),
290
+ string .concat (" - upgrade(address,address)\n - " , vm.getLabel (address (iProxy)), "\n - " , vm.getLabel (logic))
291
+ );
292
+ console.log ("Raw Calldata Data:\n " .cyan (), string .concat (" - " , vm.toString (callData)));
293
+ console.log (
294
+ "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- "
295
+ );
296
+
297
+ // cheat prank to update `implementation slot` for next call
298
+ vm.prank (owner);
299
+ wProxyAdmin.upgrade (iProxy, logic);
300
+ }
301
+
302
+ function _cheatUpgradeAndCall (
303
+ address owner ,
304
+ ProxyAdmin wProxyAdmin ,
305
+ ITransparentUpgradeableProxy iProxy ,
306
+ address logic ,
307
+ bytes memory args
308
+ ) internal virtual {
309
+ bytes memory callData = abi.encodeCall (ProxyAdmin.upgradeAndCall, (iProxy, logic, args));
310
+ console.log (
311
+ "------------------------------------------------------------------------------- Multi-Sig Proposal ------------------------------------------------------------------------------- "
312
+ );
313
+ console.log ("To: " .cyan (), vm.getLabel (address (wProxyAdmin)));
314
+ console.log (
315
+ "Method:\n " .cyan (),
316
+ " - upgradeAndCall(address,address,bytes)\n " ,
317
+ string .concat (" - " , vm.getLabel (address (iProxy)), "\n - " , vm.getLabel (logic), "\n - " , vm.toString (args))
318
+ );
319
+ console.log ("Raw Call Data:\n " .cyan (), " - " , vm.toString (callData));
320
+ console.log (
321
+ "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- "
322
+ );
323
+
324
+ // cheat prank to update `implementation slot` for next call
325
+ vm.prank (owner);
326
+ wProxyAdmin.upgradeAndCall (iProxy, logic, args);
327
+ }
328
+
268
329
function _setDependencyDeployScript (TContract contractType , IScriptExtended deployScript ) internal virtual {
269
330
_deployScript[contractType] = IMigrationScript (address (deployScript));
270
331
}
0 commit comments