Skip to content

Commit

Permalink
Merge pull request #127 from axieinfinity/feature/misc
Browse files Browse the repository at this point in the history
feat: add minor utility functions and rename variables
  • Loading branch information
TuDo1403 authored Mar 12, 2024
2 parents 64011e1 + dab7ee5 commit d363121
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
4 changes: 2 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ for arg in "$@"; do
--trezor)
extra_argument+=trezor@
;;
--disable-postcheck)
set -- "${@/#--disable-postcheck/}"
--no-postcheck)
set -- "${@/#--no-postcheck/}"
extra_argument+=no-postcheck@
;;
--generate-artifacts)
Expand Down
34 changes: 27 additions & 7 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
pragma solidity ^0.8.19;

import { ProxyAdmin } from "../lib/openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {
ITransparentUpgradeableProxy,
TransparentUpgradeableProxy
} from "../lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import { ITransparentUpgradeableProxy, Proxy } from "../src/Proxy.sol";
import { LibString } from "../lib/solady/src/utils/LibString.sol";
import {
console,
Expand All @@ -22,10 +19,12 @@ import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
import { LibProxy } from "./libraries/LibProxy.sol";
import { DefaultContract } from "./utils/DefaultContract.sol";
import { TContract } from "./types/Types.sol";
import { LibErrorHandler } from "../lib/contract-libs/src/LibErrorHandler.sol";

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

IArtifactFactory public constant ARTIFACT_FACTORY = IArtifactFactory(LibSharedAddress.ARTIFACT_FACTORY);
Expand Down Expand Up @@ -139,14 +138,13 @@ abstract contract BaseMigration is ScriptExtended {
string memory contractName = CONFIG.getContractName(contractType);

address logic = _deployLogic(contractType, argsLogicConstructor);
string memory proxyAbsolutePath =
"./out/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json";
string memory proxyAbsolutePath = "Proxy.sol:Proxy";
uint256 proxyNonce = vm.getNonce(sender());
address proxyAdmin = _getProxyAdmin();
assertTrue(proxyAdmin != address(0x0), "BaseMigration: Null ProxyAdmin");

vm.broadcast(sender());
deployed = payable(address(new TransparentUpgradeableProxy(logic, proxyAdmin, args)));
deployed = payable(address(new Proxy(logic, proxyAdmin, args)));

// validate proxy admin
address actualProxyAdmin = deployed.getProxyAdmin();
Expand Down Expand Up @@ -308,6 +306,28 @@ abstract contract BaseMigration is ScriptExtended {
}
}

function _cheatBroadcast(address from, address to, bytes memory callData) internal virtual {
string[] memory commandInputs = new string[](3);
commandInputs[0] = "cast";
commandInputs[1] = "4byte-decode";
commandInputs[2] = vm.toString(callData);
string memory decodedCallData = string(vm.ffi(commandInputs));

console.log("\n");
console.log("--------------------------- Call Detail ---------------------------");
console.log("To:".cyan(), vm.getLabel(to));
console.log(
"Raw Calldata Data (Please double check using `cast pretty-calldata {raw_bytes}`):\n".cyan(),
string.concat(" - ", vm.toString(callData))
);
console.log("Cast Decoded Call Data:".cyan(), decodedCallData);
console.log("--------------------------------------------------------------------");

vm.prank(from);
(bool success, bytes memory returnOrRevertData) = to.call(callData);
success.handleRevert(bytes4(callData), returnOrRevertData);
}

function _cheatUpgrade(address owner, ProxyAdmin wProxyAdmin, ITransparentUpgradeableProxy iProxy, address logic)
internal
virtual
Expand Down
21 changes: 21 additions & 0 deletions src/Proxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {
ITransparentUpgradeableProxy,
TransparentUpgradeableProxy
} from "../lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

/**
* @title Proxy
* @dev A contract that acts as a proxy for transparent upgrades.
*/
contract Proxy is TransparentUpgradeableProxy {
/**
* @dev Initializes the Proxy contract.
* @param _logic The address of the logic contract.
* @param _admin The address of the admin contract.
* @param _data The initialization data.
*/
constructor(address _logic, address _admin, bytes memory _data) TransparentUpgradeableProxy(_logic, _admin, _data) { }
}

0 comments on commit d363121

Please sign in to comment.