Skip to content

Commit

Permalink
Merge pull request #101 from axieinfinity/merge/release/v0.2.0-featur…
Browse files Browse the repository at this point in the history
…e/runtime-config

chore(`runtime-config`): merge from `release/v0.2.0`
  • Loading branch information
TuDo1403 committed Mar 1, 2024
2 parents caaa9a3 + 86cbf0c commit 2384765
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
26 changes: 20 additions & 6 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,51 @@ abstract contract BaseMigration is ScriptExtended {
virtual
logFn(string.concat("_deployLogic ", TContract.unwrap(contractType).unpackOne()))
returns (address payable logic)
{
logic = _deployLogic(contractType, EMPTY_ARGS);
}

function _deployLogic(TContract contractType, bytes memory args)
internal
virtual
logFn(string.concat("_deployLogic ", TContract.unwrap(contractType).unpackOne()))
returns (address payable logic)
{
string memory contractName = CONFIG.getContractName(contractType);
string memory contractAbsolutePath = CONFIG.getContractAbsolutePath(contractType);

uint256 logicNonce;
(logic, logicNonce) = _deployRaw(contractAbsolutePath, EMPTY_ARGS);
(logic, logicNonce) = _deployRaw(contractAbsolutePath, args);
CONFIG.label(block.chainid, logic, string.concat(contractName, "::Logic"));
ARTIFACT_FACTORY.generateArtifact(
sender(), logic, contractAbsolutePath, string.concat(contractName, "Logic"), EMPTY_ARGS, logicNonce
sender(), logic, contractAbsolutePath, string.concat(contractName, "Logic"), args, logicNonce
);
}

function _deployProxy(TContract contractType) internal virtual returns (address payable deployed) {
deployed = _deployProxy(contractType, arguments());
}

function _deployProxy(TContract contractType, bytes memory args)
function _deployProxy(TContract contractType, bytes memory args) internal virtual returns (address payable deployed) {
deployed = _deployProxy(contractType, args, EMPTY_ARGS);
}

function _deployProxy(TContract contractType, bytes memory args, bytes memory argsLogicConstructor)
internal
virtual
logFn(string.concat("_deployProxy ", TContract.unwrap(contractType).unpackOne()))
returns (address payable deployed)
{
string memory contractName = CONFIG.getContractName(contractType);

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

(deployed, proxyNonce) = _deployRaw(proxyAbsolutePath, abi.encode(logic, proxyAdmin, args));
vm.broadcast(sender());
deployed = payable(address(new TransparentUpgradeableProxy(logic, proxyAdmin, args)));

// validate proxy admin
address actualProxyAdmin = deployed.getProxyAdmin();
Expand Down
8 changes: 4 additions & 4 deletions script/libraries/LibProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library LibProxy {
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

function getProxyAdmin(address payable proxy, bool nullCheck) internal returns (address payable proxyAdmin) {
function getProxyAdmin(address payable proxy, bool nullCheck) internal view returns (address payable proxyAdmin) {
proxyAdmin = payable(address(uint160(uint256(vm.load(address(proxy), ADMIN_SLOT)))));
if (!nullCheck) return proxyAdmin;
require(
Expand All @@ -18,11 +18,11 @@ library LibProxy {
);
}

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

function getProxyImplementation(address payable proxy, bool nullCheck) internal returns (address payable impl) {
function getProxyImplementation(address payable proxy, bool nullCheck) internal view returns (address payable impl) {
impl = payable(address(uint160(uint256(vm.load(address(proxy), IMPLEMENTATION_SLOT)))));
if (!nullCheck) return impl;
require(
Expand All @@ -31,7 +31,7 @@ library LibProxy {
);
}

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

0 comments on commit 2384765

Please sign in to comment.