Skip to content

Commit

Permalink
Implement Data Streams plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav committed Dec 14, 2023
1 parent e427abb commit 1d6f4ce
Show file tree
Hide file tree
Showing 53 changed files with 3,886 additions and 107 deletions.
8 changes: 6 additions & 2 deletions contracts/scripts/native_solc_compile_all_llo-feeds
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ compileContract llo-feeds/VerifierProxy.sol
compileContract llo-feeds/FeeManager.sol
compileContract llo-feeds/RewardManager.sol

#Test | Mocks

# Test | Mocks
compileContract llo-feeds/test/mocks/ErroredVerifier.sol
compileContract llo-feeds/test/mocks/ExposedVerifier.sol
compileContract llo-feeds/test/mocks/ExposedVerifier.sol

# Streams
compileContract llo-feeds/dev/StreamConfigStore.sol
107 changes: 107 additions & 0 deletions contracts/src/v0.8/llo-feeds/dev/StreamConfigStore.sol
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 contracts/src/v0.8/llo-feeds/dev/interfaces/IStreamConfigStore.sol
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;
}

}
Loading

0 comments on commit 1d6f4ce

Please sign in to comment.