Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow log multi-sig proposal when upgrade proxy #42

Merged
merged 4 commits into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}