-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
3,886 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; | ||
import {IStreamConfigStore} from "./interfaces/IStreamConfigStore.sol"; | ||
import {TypeAndVersionInterface} from "../../interfaces/TypeAndVersionInterface.sol"; | ||
|
||
contract StreamConfigStore is ConfirmedOwner, IStreamConfigStore, TypeAndVersionInterface { | ||
|
||
mapping(bytes32 => ChannelDefinition) private s_channelDefinitions; | ||
|
||
mapping(bytes32 => ChannelConfiguration) private s_channelProductionConfigurations; | ||
mapping(bytes32 => ChannelConfiguration) private s_channelStagingConfigurations; | ||
|
||
event NewChannelDefinition(bytes32 channelId, ChannelDefinition channelDefinition); | ||
event ChannelDefinitionRemoved(bytes32 channelId); | ||
event NewProductionConfig(ChannelConfiguration channelConfig); | ||
event NewStagingConfig(ChannelConfiguration channelConfig); | ||
event PromoteStagingConfig(bytes32 channelId); | ||
|
||
error OnlyCallableByEOA(); | ||
error StagingConfigAlreadyPromoted(); | ||
error EmptyStreamIDs(); | ||
error ZeroReportFormat(); | ||
error ZeroChainSelector(); | ||
error ChannelDefinitionNotFound(); | ||
|
||
constructor() ConfirmedOwner(msg.sender) {} | ||
|
||
function setStagingConfig(bytes32 channelId, ChannelConfiguration calldata channelConfig) external onlyOwner { | ||
s_channelStagingConfigurations[channelId] = channelConfig; | ||
|
||
emit NewStagingConfig(channelConfig); | ||
} | ||
|
||
//// this will trigger the following: | ||
//// - offchain ShouldRetireCache will start returning true for the old (production) | ||
//// protocol instance | ||
//// - once the old production instance retires it will generate a handover | ||
//// retirement report | ||
//// - the staging instance will become the new production instance once | ||
//// any honest oracle that is on both instances forward the retirement | ||
//// report from the old instance to the new instace via the | ||
//// PredecessorRetirementReportCache | ||
//// | ||
//// Note: the promotion flow only works if the previous production instance | ||
//// is working correctly & generating reports. If that's not the case, the | ||
//// owner is expected to "setProductionConfig" directly instead. This will | ||
//// cause "gaps" to be created, but that seems unavoidable in such a scenario. | ||
function promoteStagingConfig(bytes32 channelId) external onlyOwner { | ||
ChannelConfiguration memory stagingConfig = s_channelStagingConfigurations[channelId]; | ||
|
||
if(stagingConfig.channelConfigId.length == 0) { | ||
revert StagingConfigAlreadyPromoted(); | ||
} | ||
|
||
s_channelProductionConfigurations[channelId] = s_channelStagingConfigurations[channelId]; | ||
|
||
emit PromoteStagingConfig(channelId); | ||
} | ||
|
||
function addChannel(bytes32 channelId, ChannelDefinition calldata channelDefinition) external onlyOwner { | ||
|
||
if(channelDefinition.streamIDs.length == 0) { | ||
revert EmptyStreamIDs(); | ||
} | ||
|
||
if(channelDefinition.chainSelector == 0) { | ||
revert ZeroChainSelector(); | ||
} | ||
|
||
if(channelDefinition.reportFormat == 0) { | ||
revert ZeroReportFormat(); | ||
} | ||
|
||
s_channelDefinitions[channelId] = channelDefinition; | ||
|
||
emit NewChannelDefinition(channelId, channelDefinition); | ||
} | ||
|
||
function removeChannel(bytes32 channelId) external onlyOwner { | ||
if(s_channelDefinitions[channelId].streamIDs.length == 0) { | ||
revert ChannelDefinitionNotFound(); | ||
} | ||
|
||
delete s_channelDefinitions[channelId]; | ||
|
||
emit ChannelDefinitionRemoved(channelId); | ||
} | ||
|
||
function getChannelDefinitions(bytes32 channelId) external view returns (ChannelDefinition memory) { | ||
if(msg.sender != tx.origin) { | ||
revert OnlyCallableByEOA(); | ||
} | ||
|
||
return s_channelDefinitions[channelId]; | ||
} | ||
|
||
function typeAndVersion() external override pure returns (string memory) { | ||
return "StreamConfigStore 0.0.0"; | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) external pure returns (bool) { | ||
return interfaceId == type(IStreamConfigStore).interfaceId; | ||
} | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
contracts/src/v0.8/llo-feeds/dev/interfaces/IStreamConfigStore.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import {IERC165} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/interfaces/IERC165.sol"; | ||
|
||
interface IStreamConfigStore is IERC165 { | ||
|
||
function setStagingConfig(bytes32 channelId, ChannelConfiguration calldata channelConfig) external; | ||
|
||
function promoteStagingConfig(bytes32 channelId) external; | ||
|
||
function addChannel(bytes32 channelId, ChannelDefinition calldata channelDefinition) external; | ||
|
||
function removeChannel(bytes32 channelId) external; | ||
|
||
function getChannelDefinitions(bytes32 channelId) external view returns (ChannelDefinition memory); | ||
|
||
struct ChannelConfiguration { | ||
bytes32 channelConfigId; | ||
} | ||
|
||
struct ChannelDefinition { | ||
// e.g. evm, solana, CosmWasm, kalechain, etc... | ||
bytes8 reportFormat; | ||
// Specifies the chain on which this channel can be verified. Currently uses | ||
// CCIP chain selectors, but lots of other schemes are possible as well. | ||
uint64 chainSelector; | ||
// We assume that StreamIDs is always non-empty and that the 0-th stream | ||
// contains the verification price in LINK and the 1-st stream contains the | ||
// verification price in the native coin. | ||
bytes32[] streamIDs; | ||
} | ||
|
||
} |
Oops, something went wrong.