Skip to content

Commit a5361c3

Browse files
committed
feat: Upgrade contracts to use OpenZeppelin's upgradeable libraries and adjust submodule paths
1 parent ef3951d commit a5361c3

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
[submodule "lib/rlc-faucet-contract"]
1111
path = lib/rlc-faucet-contract
1212
url = https://github.com/iExecBlockchainComputing/rlc-faucet-contract
13-
[submodule "lib/openzeppelin-contracts"]
14-
path = lib/openzeppelin-contracts
15-
url = https://github.com/OpenZeppelin/openzeppelin-contracts
13+
[submodule "lib/openzeppelin-contracts-upgradeable"]
14+
path = lib/openzeppelin-contracts-upgradeable
15+
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable

foundry.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ libs = ["lib"]
55
fs_permissions = [{ access = "read-write", path = "./" }]
66

77
remappings = [
8+
'@layerzerolabs/oft-evm-upgradeable/=lib/devtools/packages/oft-evm-upgradeable/',
89
'@layerzerolabs/oft-evm/=lib/devtools/packages/oft-evm/',
10+
'@layerzerolabs/oapp-evm-upgradeable/=lib/devtools/packages/oapp-evm-upgradeable/',
911
'@layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/',
1012
'@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol',
11-
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/',
13+
'@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/',
1214
]
1315

1416

15-
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
17+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

src/RLCAdapter.sol

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,48 @@
33

44
pragma solidity ^0.8.22;
55

6-
import {OFTAdapter} from "@layerzerolabs/oft-evm/contracts/OFTAdapter.sol";
7-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6+
import {OFTAdapterUpgradeable} from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTAdapterUpgradeable.sol";
7+
import {AccessControlDefaultAdminRulesUpgradeable} from "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol";
8+
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
9+
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
810

911
/// @notice OFTAdapter uses a deployed ERC-20 token and safeERC20 to interact with the OFTCore contract.
10-
contract RLCAdapter is Ownable, OFTAdapter {
11-
constructor(address _token, address _lzEndpoint, address _owner)
12-
Ownable(_owner)
13-
OFTAdapter(_token, _lzEndpoint, _owner)
14-
{}
12+
// There can only be one OFT Adapter deployed per chain. Multiple OFT Adapters break omnichain unified
13+
// liquidity by effectively creating token pools.
14+
contract RLCAdapter is
15+
OFTAdapterUpgradeable,
16+
UUPSUpgradeable,
17+
AccessControlDefaultAdminRulesUpgradeable
18+
{
19+
// Upgrader Role RLCAdapter contracts.
20+
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
21+
// Bridge Minter Role required for minting RLC Token
22+
bytes32 public constant BRIDGE_ROLE = keccak256("BRIDGE_ROLE");
23+
24+
/// @custom:oz-upgrades-unsafe-allow constructor
25+
constructor(
26+
address _token,
27+
address _lzEndpoint
28+
) OFTAdapterUpgradeable(_token, _lzEndpoint) {
29+
_disableInitializers();
30+
}
31+
32+
/// @notice Initializes the contract
33+
/// @param _delegate Address of the contract owner
34+
function initialize(address _delegate) public initializer {
35+
__OFTAdapter_init(_delegate);
36+
__Ownable_init(_delegate);
37+
__UUPSUpgradeable_init();
38+
__AccessControlDefaultAdminRules_init(0, _delegate);
39+
_grantRole(UPGRADER_ROLE, _delegate);
40+
}
41+
42+
43+
function owner() public view override(OwnableUpgradeable, AccessControlDefaultAdminRulesUpgradeable) returns (address) {
44+
return AccessControlDefaultAdminRulesUpgradeable.owner();
45+
}
46+
47+
function _authorizeUpgrade(
48+
address newImplementation
49+
) internal virtual override {}
1550
}

src/RLCOFT.sol

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,41 @@
22
// SPDX-License-Identifier: Apache-2.0
33
pragma solidity ^0.8.22;
44

5-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6-
import {OFT} from "@layerzerolabs/oft-evm/contracts/OFT.sol";
5+
import {OFTUpgradeable} from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTUpgradeable.sol";
6+
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
7+
import {AccessControlDefaultAdminRulesUpgradeable} from "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol";
78
import {ITokenSpender} from "src/ITokenSpender.sol";
89

910
/// @notice OFT is an ERC-20 token that extends the OFTCore contract.
10-
contract RLCOFT is Ownable, OFT {
11-
constructor(string memory _name, string memory _symbol, address _lzEndpoint, address _delegate)
12-
Ownable(_delegate)
13-
OFT(_name, _symbol, _lzEndpoint, _delegate)
14-
{}
11+
contract RLCOFT is OFTUpgradeable, UUPSUpgradeable, AccessControlDefaultAdminRulesUpgradeable {
12+
// Upgrader Role RLCAdapter contracts.
13+
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
14+
// Bridge Minter Role required for minting RLC Token
15+
bytes32 public constant BRIDGE_ROLE = keccak256("BRIDGE_ROLE");
16+
17+
/// @custom:oz-upgrades-unsafe-allow constructor
18+
constructor(address _lzEndpoint) OFTUpgradeable(_lzEndpoint) {
19+
_disableInitializers();
20+
}
21+
22+
/// @notice Initializes the contract
23+
/// @param _name Name of the token
24+
/// @param _symbol Symbol of the token
25+
/// @param _delegate Address of the contract owner
26+
function initialize(string memory _name, string memory _symbol, address _delegate) public initializer {
27+
__OFT_init(_name, _symbol, _delegate);
28+
__Ownable_init(_delegate);
29+
__UUPSUpgradeable_init();
30+
__AccessControlDefaultAdminRules_init(0, _delegate);
31+
_grantRole(UPGRADER_ROLE, _delegate);
32+
}
33+
34+
/// @notice Authorizes an upgrade to a new implementation
35+
/// @dev Can only be called by the owner
36+
/// @param newImplementation Address of the new implementation
37+
function _authorizeUpgrade(
38+
address newImplementation
39+
) internal override onlyRole(UPGRADER_ROLE) {}
1540

1641
/**
1742
* @dev Override the decimals function to return 9 instead of the default 18

0 commit comments

Comments
 (0)