diff --git a/package.json b/package.json index 59c6d89..47ffd43 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,10 @@ "@layerzerolabs/lz-evm-oapp-v2": "^2.1.18", "@layerzerolabs/lz-evm-protocol-v2": "^2.1.27", "@layerzerolabs/lz-evm-v1-0.7": "^2.3.40", - "@openzeppelin/contracts": "4.9.2", - "@openzeppelin/contracts-upgradeable": "4.9.2", + "@openzeppelin/contracts": "5.0.2", + "@openzeppelin/contracts-upgradeable": "5.0.2", + "@openzeppelin/contracts-4.9.2": "npm:@openzeppelin/contracts@4.9.2", + "@openzeppelin/contracts-upgradeable-4.9.2": "npm:@openzeppelin/contracts-upgradeable@4.9.2", "hardhat-deploy": "^0.12.4", "husky": "^9.1.5", "lint-staged": "^15.2.10", diff --git a/remappings.txt b/remappings.txt index b55217d..a183524 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,7 +1,10 @@ @layerzerolabs/lz-evm-oapp-v2/contracts/=node_modules/@layerzerolabs/lz-evm-oapp-v2/contracts/ @layerzerolabs/lz-evm-v1-0.7/=node_modules/@layerzerolabs/lz-evm-v1-0.7/ -@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/ -@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/ +@openzeppelin/contracts/=node_modules/@openzeppelin/contracts-4.9.2/ +@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable-4.9.2/ + +@openzeppelin/contracts-5/=node_modules/@openzeppelin/contracts/ +@openzeppelin/contracts-upgradeable-5/=node_modules/@openzeppelin/contracts-upgradeable/ solidity-bytes-utils/=node_modules/solidity-bytes-utils/ hardhat-deploy/=node_modules/hardhat-deploy/ diff --git a/script/BaseScript.s.sol b/script/BaseScript.s.sol index d035806..e69ed67 100644 --- a/script/BaseScript.s.sol +++ b/script/BaseScript.s.sol @@ -9,7 +9,8 @@ import {ImmutableMultiChainDeployer} from "@/factory/ImmutableMultiChainDeployer import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol"; import {EndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/EndpointV2.sol"; import {TransparentUpgradeableProxy} from - "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + "@openzeppelin/contracts-5/proxy/transparent/TransparentUpgradeableProxy.sol"; +import {Utils} from "script/Utils.sol"; import {console} from "forge-std/console.sol"; import {Bytes32AddressLib} from "solmate/utils/Bytes32AddressLib.sol"; @@ -57,14 +58,14 @@ struct PeerConfig { address peer; } -contract BaseScript is BaseData { +contract BaseScript is BaseData, Utils { using Bytes32AddressLib for bytes32; BaseInput public baseInput; Deployment public deployment; ChainDeployment public currentDeployment; PredictedAddresses public predictions; - string private constant _version = "v0.0.1"; + string private constant _version = "v0.0.3"; function _getRateLimitConfigs() internal view returns (RateLimiter.RateLimitConfig[] memory) { RateLimiter.RateLimitConfig[] memory rateLimitConfigs = diff --git a/script/DeployL1OFTAdapter.s.sol b/script/DeployL1OFTAdapter.s.sol index 69fcd85..eaba4bd 100644 --- a/script/DeployL1OFTAdapter.s.sol +++ b/script/DeployL1OFTAdapter.s.sol @@ -6,10 +6,13 @@ import {BaseScript} from "./BaseScript.s.sol"; import {L1YnOFTAdapterUpgradeable} from "@/L1YnOFTAdapterUpgradeable.sol"; import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol"; + +import {Ownable} from "@openzeppelin/contracts-5/access/Ownable.sol"; import { ITransparentUpgradeableProxy, TransparentUpgradeableProxy -} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +} from "@openzeppelin/contracts-5/proxy/transparent/TransparentUpgradeableProxy.sol"; + import {console} from "forge-std/console.sol"; // forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter \ @@ -49,7 +52,10 @@ contract DeployL1OFTAdapter is BaseScript { ); vm.broadcast(); - ITransparentUpgradeableProxy(address(l1OFTAdapter)).changeAdmin(getData(block.chainid).PROXY_ADMIN); + + address newOwner = getData(block.chainid).PROXY_ADMIN; + console.log("Changing owner for L1OFTAdapter to: %s", newOwner); + Ownable(getTransparentUpgradeableProxyAdminAddress(address(l1OFTAdapter))).transferOwnership(newOwner); console.log("Deployed L1OFTAdapter at: %s", address(l1OFTAdapter)); } else { l1OFTAdapter = L1YnOFTAdapterUpgradeable(currentDeployment.oftAdapter); diff --git a/script/DeployL2OFTAdapter.s.sol b/script/DeployL2OFTAdapter.s.sol index bbb57ae..8771bb5 100644 --- a/script/DeployL2OFTAdapter.s.sol +++ b/script/DeployL2OFTAdapter.s.sol @@ -9,10 +9,12 @@ import {L2YnOFTAdapterUpgradeable} from "@/L2YnOFTAdapterUpgradeable.sol"; import {ImmutableMultiChainDeployer} from "@/factory/ImmutableMultiChainDeployer.sol"; import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol"; +import {Ownable} from "@openzeppelin/contracts-5/access/Ownable.sol"; import { ITransparentUpgradeableProxy, TransparentUpgradeableProxy -} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +} from "@openzeppelin/contracts-5/proxy/transparent/TransparentUpgradeableProxy.sol"; + import {console} from "forge-std/console.sol"; // forge script script/DeployL2OFTAdapter.s.sol:DeployL2Adapter \ @@ -69,7 +71,10 @@ contract DeployL2OFTAdapter is BaseScript { ); vm.broadcast(); - ITransparentUpgradeableProxy(address(l2ERC20)).changeAdmin(getData(block.chainid).PROXY_ADMIN); + + address newOwner = getData(block.chainid).PROXY_ADMIN; + console.log("Changing owner for L2ERC20 to: %s", newOwner); + Ownable(getTransparentUpgradeableProxyAdminAddress(address(l2ERC20))).transferOwnership(newOwner); console.log("Deployed L2ERC20 at: %s", address(l2ERC20)); } else { @@ -100,7 +105,10 @@ contract DeployL2OFTAdapter is BaseScript { ); vm.broadcast(); - ITransparentUpgradeableProxy(address(l2OFTAdapter)).changeAdmin(getData(block.chainid).PROXY_ADMIN); + + address newOwner = getData(block.chainid).PROXY_ADMIN; + console.log("Changing owner for L2OFTAdapter to: %s", newOwner); + Ownable(getTransparentUpgradeableProxyAdminAddress(address(l2OFTAdapter))).transferOwnership(newOwner); console.log("Deployed L2OFTAdapter at: %s", address(l2OFTAdapter)); } else { diff --git a/script/Utils.sol b/script/Utils.sol new file mode 100644 index 0000000..f6c9568 --- /dev/null +++ b/script/Utils.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: BSD 3-Clause License +pragma solidity ^0.8.24; + +import {Vm} from "lib/forge-std/src/Vm.sol"; +// import {ERC1967Utils} from "lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol"; + +import {ERC1967Utils} from "@openzeppelin/contracts-5/proxy/ERC1967/ERC1967Utils.sol"; + +contract Utils { + /** + * @dev Returns the admin address of a TransparentUpgradeableProxy contract. + * @param proxy The address of the TransparentUpgradeableProxy. + * @return The admin address of the proxy contract. + */ + function getTransparentUpgradeableProxyAdminAddress(address proxy) public view returns (address) { + address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; + Vm vm = Vm(CHEATCODE_ADDRESS); + + bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT); + return address(uint160(uint256(adminSlot))); + } + + /** + * @dev Returns the implementation address of a TransparentUpgradeableProxy contract. + * @param proxy The address of the TransparentUpgradeableProxy. + * @return The implementation address of the proxy contract. + */ + function getTransparentUpgradeableProxyImplementationAddress(address proxy) public view returns (address) { + address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; + Vm vm = Vm(CHEATCODE_ADDRESS); + + bytes32 implementationSlot = vm.load(proxy, ERC1967Utils.IMPLEMENTATION_SLOT); + return address(uint160(uint256(implementationSlot))); + } +} diff --git a/script/VerifyL1OFTAdapter.s.sol b/script/VerifyL1OFTAdapter.s.sol index b055c68..9abee79 100644 --- a/script/VerifyL1OFTAdapter.s.sol +++ b/script/VerifyL1OFTAdapter.s.sol @@ -12,7 +12,7 @@ import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/Ra import { ITransparentUpgradeableProxy, TransparentUpgradeableProxy -} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +} from "@openzeppelin/contracts-5/proxy/transparent/TransparentUpgradeableProxy.sol"; import {console} from "forge-std/console.sol"; // forge script script/VerifyL1OFTAdapter.s.sol:DeployL1OFTAdapter \ diff --git a/yarn.lock b/yarn.lock index b837ba7..be1c208 100644 --- a/yarn.lock +++ b/yarn.lock @@ -387,15 +387,25 @@ resolved "https://registry.yarnpkg.com/@layerzerolabs/lz-evm-v1-0.7/-/lz-evm-v1-0.7-2.3.40.tgz#8097560124439a4a5301f13f975f5df7e33a6dd7" integrity sha512-0tTD84gmrsPmy2EGyIq1ZIm3xxzHt7eul27MYIn1D2V1APJ6qo+GlXTi4jZwy241wKpd9khNe+ATHOIoaZdlTQ== -"@openzeppelin/contracts-upgradeable@4.9.2": +"@openzeppelin/contracts-4.9.2@npm:@openzeppelin/contracts@4.9.2": + version "4.9.2" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.2.tgz#1cb2d5e4d3360141a17dbc45094a8cad6aac16c1" + integrity sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg== + +"@openzeppelin/contracts-upgradeable-4.9.2@npm:@openzeppelin/contracts-upgradeable@4.9.2": version "4.9.2" resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz#a817c75688f8daede420052fbcb34e52482e769e" integrity sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg== -"@openzeppelin/contracts@4.9.2": - version "4.9.2" - resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.2.tgz#1cb2d5e4d3360141a17dbc45094a8cad6aac16c1" - integrity sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg== +"@openzeppelin/contracts-upgradeable@5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.0.2.tgz#3e5321a2ecdd0b206064356798c21225b6ec7105" + integrity sha512-0MmkHSHiW2NRFiT9/r5Lu4eJq5UJ4/tzlOgYXNAIj/ONkQTVnz22pLxDvp4C4uZ9he7ZFvGn3Driptn1/iU7tQ== + +"@openzeppelin/contracts@5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.2.tgz#b1d03075e49290d06570b2fd42154d76c2a5d210" + integrity sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA== "@pnpm/config.env-replace@^1.1.0": version "1.1.0"