Skip to content

Commit

Permalink
Merge pull request #162 from axieinfinity/implement-feature/rework/re…
Browse files Browse the repository at this point in the history
…store-transparent-proxy-v4_9_5

feat(rework): implement `restore-transparent-proxy-v4_9_5`
  • Loading branch information
huyhuynh3103 authored Oct 10, 2024
2 parents 0f3f935 + ac0327d commit b426132
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
4 changes: 3 additions & 1 deletion script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Vm } from "../dependencies/forge-std-1.9.3/src/Vm.sol";
import { console } from "../dependencies/forge-std-1.9.3/src/console.sol";
import { LibString } from "../dependencies/solady-0.0.228/src/utils/LibString.sol";
import { RoninTransparentProxy } from "../src/RoninTransparentProxy.sol";
import { TransparentProxyOZv4_9_5 } from "../src/TransparentProxyOZv4_9_5.sol";

import { OnchainExecutor } from "./OnchainExecutor.s.sol";
import { IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol"; // cheat to load artifact to parent
Expand Down Expand Up @@ -328,6 +329,7 @@ abstract contract BaseMigration is ScriptExtended {
*/
function _precompileProxyContracts() internal pure virtual {
bytes memory dummy;
dummy = type(RoninTransparentProxy).creationCode;
dummy = type(RoninTransparentProxy).creationCode;
dummy = type(TransparentProxyOZv4_9_5).creationCode;
}
}
2 changes: 1 addition & 1 deletion script/libraries/LibDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ library LibDeploy {
DeployInfo memory proxyInfo;
proxyInfo.callValue = callValue;
proxyInfo.by = implInfo.by;
proxyInfo.contractName = "RoninTransparentProxy";
proxyInfo.contractName = "TransparentProxyOZv4_9_5";
proxyInfo.absolutePath = string.concat(proxyInfo.contractName, ".sol:", proxyInfo.contractName);
proxyInfo.artifactName = string.concat(vm.replace(implInfo.artifactName, "Logic", ""), "Proxy");
proxyInfo.constructorArgs = abi.encode(impl, proxyAdmin, callData);
Expand Down
7 changes: 5 additions & 2 deletions script/libraries/LibInitializeGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,12 @@ library LibInitializeGuard {
string memory path
) internal pure returns (string memory contractName) {
uint256 length = bytes(path).length;
// Remove ".sol"
contractName = path;
if (path.endsWith(".sol")) contractName = path.slice(0, length - 4);
return string(contractName);
string[] memory parts = contractName.split(":");
if (parts.length != 0) contractName = parts[parts.length - 1];
parts = contractName.split("/");
if (parts.length != 0) contractName = parts[parts.length - 1];
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/TransparentProxyOZv4_9_5.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

/**
* @title TransparentProxyOZv4_9_5
* @dev A contract that acts as a proxy for transparent upgrades.
*/
contract TransparentProxyOZv4_9_5 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) payable TransparentUpgradeableProxy(logic, admin, data) { }
}
3 changes: 2 additions & 1 deletion test/LibInitializeGuard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SampleProxyForTestingPurpose7 } from "src/mocks/ForTesting/SampleProxyF
import { SampleProxy } from "src/mocks/SampleProxy.sol";

interface ITransparentUpgradeableProxy {
function upgradeTo(address) external;
function upgradeToAndCall(address, bytes memory) external payable;
}

Expand Down Expand Up @@ -65,7 +66,7 @@ contract LibInitializeGuardTest is Test {

address newLogic = address(new SampleProxyForTestingPurpose2());
vm.prank(admin);
ITransparentUpgradeableProxy(address(_sample)).upgradeToAndCall(newLogic, "");
ITransparentUpgradeableProxy(address(_sample)).upgradeTo(newLogic);
MockConfig(address(vme)).updateSampleProxyLogicForTesting("SampleProxyForTestingPurpose2");

Vm.Log[] memory logs = vm.getRecordedLogs();
Expand Down

0 comments on commit b426132

Please sign in to comment.