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

chore: merge from branch 'release/v0.1.0' #14

Merged
merged 8 commits into from
Dec 15, 2023
4 changes: 2 additions & 2 deletions debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

verify_arg=""
extra_argument=""
op_command=""
op_command="op run --env-file="./.env" --"

for arg in "$@"; do
case $arg in
Expand Down Expand Up @@ -36,4 +36,4 @@ echo Value: ${VALUE}
echo Calldata:
cast pretty-calldata ${CALLDATA}
calldata=$(cast calldata 'trace(uint256,address,address,uint256,bytes)' ${BLOCK} ${FROM} ${TO} ${VALUE} ${CALLDATA})
${op_command} forge script ${verify_arg} --legacy ${@} script/OnchainDebugger.s.sol --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
${op_command} forge script ${verify_arg} --legacy ${@} OnchainDebugger --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
72 changes: 50 additions & 22 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { LibString } from "../lib/solady/src/utils/LibString.sol";
import { console, LibSharedAddress, StdStyle, IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol";
import { IArtifactFactory, ArtifactFactory } from "./ArtifactFactory.sol";
import { OnchainDebugger } from "./OnchainDebugger.s.sol"; // cheat to load artifact to parent `out` directory
import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
import { LibProxy } from "./libraries/LibProxy.sol";
import { DefaultContract } from "./utils/DefaultContract.sol";
Expand Down Expand Up @@ -166,12 +167,7 @@ abstract contract BaseMigration is ScriptExtended {
_mockUpgradeRaw(proxy.getProxyAdmin(), proxy, logic, args);
}

function _upgradeProxy(TContract contractType)
internal
virtual
logFn(string.concat("_upgradeProxy ", TContract.unwrap(contractType).unpackOne()))
returns (address payable proxy)
{
function _upgradeProxy(TContract contractType) internal virtual returns (address payable proxy) {
proxy = _upgradeProxy(contractType, arguments());
}

Expand All @@ -190,41 +186,73 @@ abstract contract BaseMigration is ScriptExtended {
internal
virtual
{
ITransparentUpgradeableProxy iProxy = ITransparentUpgradeableProxy(proxy);
ProxyAdmin wProxyAdmin = ProxyAdmin(proxyAdmin);
// if proxyAdmin is External Owned Wallet
if (proxyAdmin.code.length == 0) {
vm.prank(proxyAdmin);
if (args.length == 0) ITransparentUpgradeableProxy(proxy).upgradeTo(logic);
else ITransparentUpgradeableProxy(proxy).upgradeToAndCall(logic, args);
if (args.length == 0) iProxy.upgradeTo(logic);
else iProxy.upgradeToAndCall(logic, args);
} else {
try ProxyAdmin(proxyAdmin).owner() returns (address owner) {
vm.prank(owner);
try wProxyAdmin.owner() returns (address owner) {
if (args.length == 0) {
ProxyAdmin(proxyAdmin).upgrade(ITransparentUpgradeableProxy(proxy), logic);
// try `upgrade` function
vm.prank(owner);
(bool success,) = proxyAdmin.call(abi.encodeCall(ProxyAdmin.upgrade, (iProxy, logic)));
if (success) {
vm.prank(owner);
wProxyAdmin.upgrade(iProxy, logic);
} else {
console.log(
StdStyle.yellow(
"`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args..."
)
);
vm.prank(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
} else {
ProxyAdmin(proxyAdmin).upgradeAndCall(ITransparentUpgradeableProxy(proxy), logic, args);
vm.prank(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
} catch {
vm.prank(proxyAdmin);
if (args.length == 0) ITransparentUpgradeableProxy(proxy).upgradeTo(logic);
else ITransparentUpgradeableProxy(proxy).upgradeToAndCall(logic, args);
revert("BaseMigration: Unknown ProxyAdmin contract!");
}
}
}

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);
if (args.length == 0) ITransparentUpgradeableProxy(proxy).upgradeTo(logic);
else ITransparentUpgradeableProxy(proxy).upgradeToAndCall(logic, args);
if (args.length == 0) iProxy.upgradeTo(logic);
else iProxy.upgradeToAndCall(logic, args);
} else {
try ProxyAdmin(proxyAdmin).owner() returns (address owner) {
vm.broadcast(owner);
try wProxyAdmin.owner() returns (address owner) {
if (args.length == 0) {
ProxyAdmin(proxyAdmin).upgrade(ITransparentUpgradeableProxy(proxy), logic);
// try `upgrade` function
vm.prank(owner);
(bool success,) = proxyAdmin.call(abi.encodeCall(ProxyAdmin.upgrade, (iProxy, logic)));
if (success) {
vm.broadcast(owner);
wProxyAdmin.upgrade(iProxy, logic);
} else {
console.log(
StdStyle.yellow(
"`ProxyAdmin:upgrade` failed!. Retrying with `ProxyAdmin:upgradeAndCall` with emty args..."
)
);
vm.broadcast(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
} else {
ProxyAdmin(proxyAdmin).upgradeAndCall(ITransparentUpgradeableProxy(proxy), logic, args);
vm.broadcast(owner);
wProxyAdmin.upgradeAndCall(iProxy, logic, args);
}
} catch {
revert("BaseMigration: Unhandled case for upgrading proxy!");
revert("BaseMigration: Unknown ProxyAdmin contract!");
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions script/configs/WalletConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ abstract contract WalletConfig is IWalletConfig {

function getSender() public view virtual returns (address payable sender);

function getSenderPk() public view virtual returns (uint256) {
return _envPk;
}

function trezorPrefix() public view virtual returns (string memory) {
return "trezor://";
}
Expand Down
5 changes: 4 additions & 1 deletion script/extensions/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
console.log("> ", StdStyle.blue(fnName), "...");
_;
}

modifier onlyOn(TNetwork networkType) {
require(network() == networkType, string.concat("ScriptExtended: Only allowed on ", CONFIG.getAlias(networkType)));
_;
Expand All @@ -33,10 +33,13 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {

function _configByteCode() internal virtual returns (bytes memory);

function _postCheck() internal virtual { }

function run(bytes calldata callData, string calldata command) public virtual {
CONFIG.resolveCommand(command);
(bool success, bytes memory data) = address(this).delegatecall(callData);
success.handleRevert(msg.sig, data);
_postCheck();
}

function network() public view virtual returns (TNetwork) {
Expand Down
2 changes: 2 additions & 0 deletions script/interfaces/configs/IWalletConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.19;

interface IWalletConfig {
function getSenderPk() external view returns (uint256);

function getSender() external view returns (address payable sender);

function trezorPrefix() external view returns (string memory);
Expand Down
14 changes: 12 additions & 2 deletions script/libraries/LibProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ library LibProxy {
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

function getProxyAdmin(address payable proxy) internal returns (address payable proxyAdmin) {
function getProxyAdmin(address payable proxy, bool nullCheck) internal returns (address payable proxyAdmin) {
proxyAdmin = payable(address(uint160(uint256(vm.load(address(proxy), ADMIN_SLOT)))));
if (!nullCheck) return proxyAdmin;
require(
proxyAdmin != address(0x0),
string.concat("LibProxy: Null ProxyAdmin, Provided address: ", vm.getLabel(proxy), " is not EIP1967 Proxy")
);
}

function getProxyImplementation(address payable proxy) internal returns (address payable impl) {
function getProxyAdmin(address payable proxy) internal returns (address payable proxyAdmin) {
proxyAdmin = getProxyAdmin({ proxy: proxy, nullCheck: true });
}

function getProxyImplementation(address payable proxy, bool nullCheck) internal returns (address payable impl) {
impl = payable(address(uint160(uint256(vm.load(address(proxy), IMPLEMENTATION_SLOT)))));
if (!nullCheck) return impl;
require(
impl != address(0x0),
string.concat("LibProxy: Null Implementation, Provided address: ", vm.getLabel(proxy), " is not EIP1967 Proxy")
);
}

function getProxyImplementation(address payable proxy) internal returns (address payable impl) {
impl = getProxyImplementation({ proxy: proxy, nullCheck: true });
}
}
2 changes: 1 addition & 1 deletion src/WNT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import { ERC20 } from "../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import { IWNT } from "./interfaces/IWNT.sol";
import { LibNativeTransfer } from "./libraries/LibNativeTransfer.sol";
import { LibNativeTransfer } from "contract-libs/transfers/LibNativeTransfer.sol";

/// @notice Minimalist and modern Wrapped Ether implementation.
/// @author Solmate
Expand Down
40 changes: 0 additions & 40 deletions src/libraries/LibErrorHandler.sol

This file was deleted.

36 changes: 0 additions & 36 deletions src/libraries/LibNativeTransfer.sol

This file was deleted.

Loading