Skip to content

Commit

Permalink
Merge pull request #42 from axieinfinity/feature/upgrade
Browse files Browse the repository at this point in the history
feat: allow log multi-sig proposal when upgrade proxy
  • Loading branch information
TuDo1403 authored Dec 28, 2023
2 parents a1c4d62 + 70862c2 commit 51c6d91
Showing 1 changed file with 72 additions and 11 deletions.
83 changes: 72 additions & 11 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { DefaultContract } from "./utils/DefaultContract.sol";
import { TContract } from "./types/Types.sol";

abstract contract BaseMigration is ScriptExtended {
using StdStyle for string;
using StdStyle for *;
using LibString for bytes32;
using LibProxy for address payable;

Expand Down Expand Up @@ -232,6 +232,7 @@ abstract contract BaseMigration is ScriptExtended {
function _upgradeRaw(address proxyAdmin, address payable proxy, address logic, bytes memory args) internal virtual {
ITransparentUpgradeableProxy iProxy = ITransparentUpgradeableProxy(proxy);
ProxyAdmin wProxyAdmin = ProxyAdmin(proxyAdmin);

// if proxyAdmin is External Owned Wallet
if (proxyAdmin.code.length == 0) {
vm.broadcast(proxyAdmin);
Expand All @@ -240,36 +241,96 @@ abstract contract BaseMigration is ScriptExtended {
} else {
try wProxyAdmin.owner() returns (address owner) {
if (args.length == 0) {
// try `upgrade` function
// try `upgrade(address,address)` function
vm.prank(owner);
(bool success,) = proxyAdmin.call(abi.encodeCall(ProxyAdmin.upgrade, (iProxy, logic)));
if (success) {
vm.broadcast(owner);
wProxyAdmin.upgrade(iProxy, logic);
if (owner.code.length != 0) {
_cheatUpgrade(owner, wProxyAdmin, iProxy, logic);
} else {
vm.broadcast(owner);
wProxyAdmin.upgrade(iProxy, logic);
}
} else {
console.log(
StdStyle.yellow(
"`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args..."
)
"`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args...".yellow()
);
if (owner.code.length != 0) {
_cheatUpgradeAndCall(owner, wProxyAdmin, iProxy, logic, args);
} else {
vm.broadcast(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
}
} else {
if (owner.code.length != 0) {
_cheatUpgradeAndCall(owner, wProxyAdmin, iProxy, logic, args);
} else {
vm.broadcast(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
} else {
vm.broadcast(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
} catch {
revert("BaseMigration: Unknown ProxyAdmin contract!");
}
}
}

function _cheatUpgrade(address owner, ProxyAdmin wProxyAdmin, ITransparentUpgradeableProxy iProxy, address logic)
internal
virtual
{
bytes memory callData = abi.encodeCall(ProxyAdmin.upgrade, (iProxy, logic));
console.log(
"------------------------------------------------------------------------------- Multi-Sig Proposal -------------------------------------------------------------------------------"
);
console.log("To:".cyan(), vm.getLabel(address(wProxyAdmin)));
console.log(
"Method:\n".cyan(),
string.concat(" - upgrade(address,address)\n - ", vm.getLabel(address(iProxy)), "\n - ", vm.getLabel(logic))
);
console.log("Raw Calldata Data:\n".cyan(), string.concat(" - ", vm.toString(callData)));
console.log(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
);

// cheat prank to update `implementation slot` for next call
vm.prank(owner);
wProxyAdmin.upgrade(iProxy, logic);
}

function _cheatUpgradeAndCall(
address owner,
ProxyAdmin wProxyAdmin,
ITransparentUpgradeableProxy iProxy,
address logic,
bytes memory args
) internal virtual {
bytes memory callData = abi.encodeCall(ProxyAdmin.upgradeAndCall, (iProxy, logic, args));
console.log(
"------------------------------------------------------------------------------- Multi-Sig Proposal -------------------------------------------------------------------------------"
);
console.log("To:".cyan(), vm.getLabel(address(wProxyAdmin)));
console.log(
"Method:\n".cyan(),
" - upgradeAndCall(address,address,bytes)\n",
string.concat(" - ", vm.getLabel(address(iProxy)), "\n - ", vm.getLabel(logic), "\n - ", vm.toString(args))
);
console.log("Raw Call Data:\n".cyan(), " - ", vm.toString(callData));
console.log(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
);

// cheat prank to update `implementation slot` for next call
vm.prank(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}

function _setDependencyDeployScript(TContract contractType, IScriptExtended deployScript) internal virtual {
_deployScript[contractType] = IMigrationScript(address(deployScript));
}

function _setDependencyDeployScript(TContract contractType, address deployScript) internal virtual {
_deployScript[contractType] = IMigrationScript(deployScript);
}
}
}

0 comments on commit 51c6d91

Please sign in to comment.