Skip to content

Commit 86e677d

Browse files
committed
Draft implementation of ChannelConfigStore.addChannelDefinitions
1 parent 8eb761a commit 86e677d

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

contracts/src/v0.8/llo-feeds/v0.5.0/configuration/ChannelConfigStore.sol

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,103 @@
22
pragma solidity ^0.8.19;
33

44
import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol";
5+
import {EnumerableSet} from "@openzeppelin/[email protected]/utils/structs/EnumerableSet.sol";
56

67
import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";
78
import {IChannelConfigStore} from "./interfaces/IChannelConfigStore.sol";
89

910
contract ChannelConfigStore is ConfirmedOwner, IChannelConfigStore, ITypeAndVersion {
11+
using EnumerableSet for EnumerableSet.UintSet;
12+
1013
event NewChannelDefinition(uint256 indexed donId, uint32 version, string url, bytes32 sha);
14+
event ChannelDefinitionAdded(uint256 indexed donId, uint32 indexed channelAdderId, string url, bytes32 sha);
15+
event ChannelAdderSet(uint256 indexed donId, uint32 indexed channelAdderId, bool allowed);
16+
event ChannelAdderAddressSet(uint32 indexed channelAdderId, address adderAddress);
17+
18+
error UnauthorizedChannelAdder();
1119

1220
constructor() ConfirmedOwner(msg.sender) {}
1321

1422
/// @notice The version of a channel definition keyed by DON ID
1523
// Increments by 1 on every update
1624
mapping(uint256 => uint256) internal s_channelDefinitionVersions;
25+
26+
/// @notice Mapping from channel adder ID to its corresponding address
27+
mapping(uint32 => address) internal s_channelAdderAddresses;
28+
29+
/// @notice Mapping from DON ID to the set of allowed channel adder IDs
30+
mapping(uint256 => EnumerableSet.UintSet) internal s_allowedChannelAdders;
1731

1832
function setChannelDefinitions(uint32 donId, string calldata url, bytes32 sha) external onlyOwner {
1933
uint32 newVersion = uint32(++s_channelDefinitionVersions[uint256(donId)]);
2034
emit NewChannelDefinition(donId, newVersion, url, sha);
2135
}
2236

37+
/// @notice Allows a channel adder to add channel definitions to the specified DON.
38+
/// The DON enforces (in its consensus rules), that the channel definitions provided
39+
/// by the channel adder are well-formed, purely additive, and do not overlaod the DON.
40+
/// @param donId The DON ID
41+
/// @param channelAdderId The channel adder ID
42+
/// @param url The URL of the channel definition
43+
/// @param sha The SHA hash of the channel definition
44+
function addChannelDefinitions(
45+
uint256 donId,
46+
uint32 channelAdderId,
47+
string calldata url,
48+
bytes32 sha
49+
) external {
50+
if (msg.sender != s_channelAdderAddresses[channelAdderId]) {
51+
revert UnauthorizedChannelAdder();
52+
}
53+
if (!s_allowedChannelAdders[donId].contains(channelAdderId)) {
54+
revert UnauthorizedChannelAdder();
55+
}
56+
emit ChannelDefinitionAdded(donId, channelAdderId, url, sha);
57+
}
58+
59+
/// @notice Sets the address for a channel adder ID
60+
/// @param channelAdderId The channel adder ID
61+
/// @param adderAddress The address to associate with the channel adder ID
62+
function setChannelAdderAddress(uint32 channelAdderId, address adderAddress) external onlyOwner {
63+
s_channelAdderAddresses[channelAdderId] = adderAddress;
64+
emit ChannelAdderAddressSet(channelAdderId, adderAddress);
65+
}
66+
67+
/// @notice Sets whether a channel adder ID is allowed for a DON
68+
/// @param donId The DON ID
69+
/// @param channelAdderId The channel adder ID
70+
/// @param allowed Whether the channel adder should be allowed or removed
71+
function setChannelAdder(uint256 donId, uint32 channelAdderId, bool allowed) external onlyOwner {
72+
if (allowed) {
73+
s_allowedChannelAdders[donId].add(channelAdderId);
74+
} else {
75+
s_allowedChannelAdders[donId].remove(channelAdderId);
76+
}
77+
emit ChannelAdderSet(donId, channelAdderId, allowed);
78+
}
79+
80+
/// @notice Gets the address associated with a channel adder ID
81+
/// @param channelAdderId The channel adder ID
82+
/// @return The address associated with the channel adder ID
83+
function getChannelAdderAddress(uint32 channelAdderId) external view returns (address) {
84+
return s_channelAdderAddresses[channelAdderId];
85+
}
86+
87+
/// @notice Checks if a channel adder is allowed for a DON
88+
/// @param donId The DON ID
89+
/// @param channelAdderId The channel adder ID
90+
/// @return True if the channel adder is allowed for the DON
91+
function isChannelAdderAllowed(uint256 donId, uint32 channelAdderId) external view returns (bool) {
92+
return s_allowedChannelAdders[donId].contains(channelAdderId);
93+
}
94+
95+
/// @notice Gets all allowed channel adder IDs for a DON
96+
/// @param donId The DON ID
97+
/// @return An array of allowed channel adder IDs
98+
function getAllowedChannelAdders(uint256 donId) external view returns (uint256[] memory) {
99+
return s_allowedChannelAdders[donId].values();
100+
}
101+
23102
function typeAndVersion() external pure override returns (string memory) {
24103
return "ChannelConfigStore 0.0.1";
25104
}

0 commit comments

Comments
 (0)