Skip to content

Commit 6feadf3

Browse files
authored
feat: Add relayerDeployer ACL role to the factory (#499)
### Description We realised that it would be better operationally to separate the proxy ownership ACL from the deployer ACL, that way we can keep using the `mento-deployer` account for relayer deploy, and use the multisig only for proxy updates. ### Other changes N/A ### Tested Tests added ### Related issues N/A ### Backwards compatibility No, but no mainnet deployment yet. ### Documentation N/A
1 parent 7f9f7b9 commit 6feadf3

File tree

4 files changed

+133
-56
lines changed

4 files changed

+133
-56
lines changed

contracts/interfaces/IChainlinkRelayerFactory.sol

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,28 @@ interface IChainlinkRelayerFactory {
1919
IChainlinkRelayer.ChainlinkAggregator[] aggregators
2020
);
2121

22+
/**
23+
* @notice Emitted when the relayer deployer is updated.
24+
* @param newRelayerDeployer Address of the new relayer deployer.
25+
* @param oldRelayerDeployer Address of the old relayer deployer.
26+
*/
27+
event RelayerDeployerUpdated(address indexed newRelayerDeployer, address indexed oldRelayerDeployer);
28+
2229
/**
2330
* @notice Emitted when a relayer is removed.
2431
* @param relayerAddress Address of the removed relayer.
2532
* @param rateFeedId Rate feed ID for which the relayer reported.
2633
*/
2734
event RelayerRemoved(address indexed relayerAddress, address indexed rateFeedId);
2835

29-
function initialize(address _sortedOracles) external;
36+
function initialize(address _sortedOracles, address _relayerDeployer) external;
3037

3138
function sortedOracles() external returns (address);
3239

40+
function setRelayerDeployer(address _relayerDeployer) external;
41+
42+
function relayerDeployer() external returns (address);
43+
3344
function deployRelayer(
3445
address rateFeedId,
3546
string calldata rateFeedDescription,

contracts/oracles/ChainlinkRelayerFactory.sol

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ contract ChainlinkRelayerFactory is IChainlinkRelayerFactory, OwnableUpgradeable
2323
*/
2424
address[] public rateFeeds;
2525

26+
/**
27+
* @notice Account that is allowed to deploy relayers.
28+
*/
29+
address public relayerDeployer;
30+
2631
/**
2732
* @notice Thrown when trying to deploy a relayer to an address that already has code.
2833
* @param contractAddress Address at which the relayer could not be deployed.
@@ -51,6 +56,17 @@ contract ChainlinkRelayerFactory is IChainlinkRelayerFactory, OwnableUpgradeable
5156
*/
5257
error NoRelayerForRateFeedId(address rateFeedId);
5358

59+
/// @notice Thrown when a non-deployer tries to call a deployer-only function.
60+
error NotAllowed();
61+
62+
/// @notice Modifier to restrict a function to the deployer.
63+
modifier onlyDeployer() {
64+
if (msg.sender != relayerDeployer && msg.sender != owner()) {
65+
revert NotAllowed();
66+
}
67+
_;
68+
}
69+
5470
/**
5571
* @notice Constructor for the logic contract.
5672
* @param disable If `true`, disables the initializer.
@@ -69,9 +85,20 @@ contract ChainlinkRelayerFactory is IChainlinkRelayerFactory, OwnableUpgradeable
6985
* @notice Initializes the factory.
7086
* @param _sortedOracles The SortedOracles instance deployed relayers should report to.
7187
*/
72-
function initialize(address _sortedOracles) external initializer {
88+
function initialize(address _sortedOracles, address _relayerDeployer) external initializer {
7389
__Ownable_init();
7490
sortedOracles = _sortedOracles;
91+
relayerDeployer = _relayerDeployer;
92+
}
93+
94+
/**
95+
* @notice Sets the address of the relayer deployer.
96+
* @param newRelayerDeployer The address of the relayer deployer.
97+
*/
98+
function setRelayerDeployer(address newRelayerDeployer) external onlyOwner {
99+
address oldRelayerDeployer = relayerDeployer;
100+
relayerDeployer = newRelayerDeployer;
101+
emit RelayerDeployerUpdated(newRelayerDeployer, oldRelayerDeployer);
75102
}
76103

77104
/**
@@ -87,7 +114,7 @@ contract ChainlinkRelayerFactory is IChainlinkRelayerFactory, OwnableUpgradeable
87114
address rateFeedId,
88115
string calldata rateFeedDescription,
89116
IChainlinkRelayer.ChainlinkAggregator[] calldata aggregators
90-
) public onlyOwner returns (address relayerAddress) {
117+
) public onlyDeployer returns (address relayerAddress) {
91118
if (address(deployedRelayers[rateFeedId]) != address(0)) {
92119
revert RelayerForFeedExists(rateFeedId);
93120
}
@@ -121,7 +148,7 @@ contract ChainlinkRelayerFactory is IChainlinkRelayerFactory, OwnableUpgradeable
121148
* @notice Removes a relayer from the list of deployed relayers.
122149
* @param rateFeedId The rate feed whose relayer should be removed.
123150
*/
124-
function removeRelayer(address rateFeedId) public onlyOwner {
151+
function removeRelayer(address rateFeedId) public onlyDeployer {
125152
address relayerAddress = address(deployedRelayers[rateFeedId]);
126153

127154
if (relayerAddress == address(0)) {
@@ -156,7 +183,7 @@ contract ChainlinkRelayerFactory is IChainlinkRelayerFactory, OwnableUpgradeable
156183
address rateFeedId,
157184
string calldata rateFeedDescription,
158185
IChainlinkRelayer.ChainlinkAggregator[] calldata aggregators
159-
) external onlyOwner returns (address relayerAddress) {
186+
) external onlyDeployer returns (address relayerAddress) {
160187
removeRelayer(rateFeedId);
161188
return deployRelayer(rateFeedId, rateFeedDescription, aggregators);
162189
}

test/integration/ChainlinkRelayerIntegration.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ contract ChainlinkRelayerIntegration is IntegrationTest {
3535
abi.encode(
3636
address(relayerFactoryImplementation),
3737
address(proxyAdmin),
38-
abi.encodeWithSignature("initialize(address)", address(sortedOracles))
38+
abi.encodeWithSignature("initialize(address,address)", address(sortedOracles), owner)
3939
)
4040
)
4141
);
@@ -82,7 +82,7 @@ contract ChainlinkRelayerIntegration_ProxySetup is ChainlinkRelayerIntegration {
8282

8383
function test_implementationNotInitializable() public {
8484
vm.expectRevert("Initializable: contract is already initialized");
85-
relayerFactoryImplementation.initialize(address(sortedOracles));
85+
relayerFactoryImplementation.initialize(address(sortedOracles), address(this));
8686
}
8787
}
8888

0 commit comments

Comments
 (0)