Skip to content

Commit

Permalink
upgrade to oz 5
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Oct 8, 2024
1 parent 3a7fe18 commit 807db4d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 18 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]",
"@openzeppelin/contracts-upgradeable-4.9.2": "npm:@openzeppelin/[email protected]",
"hardhat-deploy": "^0.12.4",
"husky": "^9.1.5",
"lint-staged": "^15.2.10",
Expand Down
7 changes: 5 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
7 changes: 4 additions & 3 deletions script/BaseScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 =
Expand Down
10 changes: 8 additions & 2 deletions script/DeployL1OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions script/DeployL2OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions script/Utils.sol
Original file line number Diff line number Diff line change
@@ -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)));
}
}
2 changes: 1 addition & 1 deletion script/VerifyL1OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
20 changes: 15 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
"@openzeppelin/contracts-4.9.2@npm:@openzeppelin/[email protected]":
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/[email protected]":
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/[email protected]":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.2.tgz#1cb2d5e4d3360141a17dbc45094a8cad6aac16c1"
integrity sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==
"@openzeppelin/[email protected]":
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/[email protected]":
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"
Expand Down

0 comments on commit 807db4d

Please sign in to comment.