Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Streams - Update #1869

Merged
merged 12 commits into from
Apr 23, 2024
Binary file modified public/images/data-streams/data-streams-architecture.webp
Binary file not shown.
Binary file modified public/images/data-streams/sequence-diagram.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion public/samples/DataStreams/LogEmitter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.19;
pragma solidity 0.8.19;

contract LogEmitter {
event Log(address indexed msgSender);
Expand Down
43 changes: 25 additions & 18 deletions public/samples/DataStreams/StreamsUpkeep.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import {IERC20} from "@chainlink/contracts/src/v0.8/vendor/openzeppelin-solidity

// Custom interfaces for IVerifierProxy and IFeeManager
interface IVerifierProxy {
/**
* @notice Verifies that the data encoded has been signed.
* correctly by routing to the correct verifier, and bills the user if applicable.
* @param payload The encoded data to be verified, including the signed
* report.
* @param parameterPayload Fee metadata for billing. For the current implementation this is just the abi-encoded fee token ERC-20 address.
* @return verifierResponse The encoded report from the verifier.
*/
function verify(
bytes calldata payload,
bytes calldata parameterPayload
Expand All @@ -24,6 +32,18 @@ interface IVerifierProxy {
}

interface IFeeManager {
/**
* @notice Calculates the fee and reward associated with verifying a report, including discounts for subscribers.
* This function assesses the fee and reward for report verification, applying a discount for recognized subscriber addresses.
* @param subscriber The address attempting to verify the report. A discount is applied if this address
* is recognized as a subscriber.
* @param unverifiedReport The report data awaiting verification. The content of this report is used to
* determine the base fee and reward, before considering subscriber discounts.
* @param quoteAddress The payment token address used for quoting fees and rewards.
* @return fee The fee assessed for verifying the report, with subscriber discounts applied where applicable.
* @return reward The reward allocated to the caller for successfully verifying the report.
* @return totalDiscount The total discount amount deducted from the fee for subscribers.
*/
function getFeeAndReward(
address subscriber,
bytes memory unverifiedReport,
Expand All @@ -38,17 +58,7 @@ interface IFeeManager {
}

contract StreamsUpkeep is ILogAutomation, StreamsLookupCompatibleInterface {
struct BasicReport {
bytes32 feedId; // The feed ID the report has data for
uint32 validFromTimestamp; // Earliest timestamp for which price is applicable
uint32 observationsTimestamp; // Latest timestamp for which price is applicable
uint192 nativeFee; // Base cost to validate a transaction using the report, denominated in the chain’s native token (WETH/ETH)
uint192 linkFee; // Base cost to validate a transaction using the report, denominated in LINK
uint32 expiresAt; // Latest timestamp where the report can be verified onchain
int192 price; // DON consensus median price, carried to 8 decimal places
}

struct PremiumReport {
struct Report {
bytes32 feedId; // The feed ID the report has data for
uint32 validFromTimestamp; // Earliest timestamp for which price is applicable
uint32 observationsTimestamp; // Latest timestamp for which price is applicable
Expand All @@ -73,10 +83,10 @@ contract StreamsUpkeep is ILogAutomation, StreamsLookupCompatibleInterface {
string public constant DATASTREAMS_QUERYLABEL = "timestamp";
int192 public last_retrieved_price;

// This example reads the ID for the basic ETH/USD price report on Arbitrum Sepolia.
// This example reads the ID for the ETH/USD report on Arbitrum Sepolia.
// Find a complete list of IDs at https://docs.chain.link/data-streams/stream-ids
string[] public feedIds = [
"0x00027bbaff688c906a3e20a34fe951715d1018d262a5b66e38eda027a674cd1b"
"0x000359843a543ee2fe414dc14c7e7920ef10f4372990b79d6361cdc0dd1ba782"
];

constructor(address _verifier) {
Expand Down Expand Up @@ -162,11 +172,8 @@ contract StreamsUpkeep is ILogAutomation, StreamsLookupCompatibleInterface {
abi.encode(feeTokenAddress)
);

// Decode verified report data into BasicReport struct
BasicReport memory verifiedReport = abi.decode(
verifiedReportData,
(BasicReport)
);
// Decode verified report data into a Report struct
Report memory verifiedReport = abi.decode(verifiedReportData, (Report));

// Log price from report
emit PriceUpdate(verifiedReport.price);
Expand Down
19 changes: 3 additions & 16 deletions public/samples/DataStreams/StreamsUpkeepRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,7 @@ contract StreamsUpkeepRegistrar is
LinkTokenInterface public immutable i_link;
AutomationRegistrarInterface public immutable i_registrar;

struct BasicReport {
bytes32 feedId; // The feed ID the report has data for
uint32 validFromTimestamp; // Earliest timestamp for which price is applicable
uint32 observationsTimestamp; // Latest timestamp for which price is applicable
uint192 nativeFee; // Base cost to validate a transaction using the report, denominated in the chain’s native token (WETH/ETH)
uint192 linkFee; // Base cost to validate a transaction using the report, denominated in LINK
uint32 expiresAt; // Latest timestamp where the report can be verified onchain
int192 price; // DON consensus median price, carried to 8 decimal places
}

struct PremiumReport {
struct Report {
bytes32 feedId; // The feed ID the report has data for
uint32 validFromTimestamp; // Earliest timestamp for which price is applicable
uint32 observationsTimestamp; // Latest timestamp for which price is applicable
Expand Down Expand Up @@ -233,11 +223,8 @@ contract StreamsUpkeepRegistrar is
abi.encode(feeTokenAddress)
);

// Decode verified report data into BasicReport struct
BasicReport memory verifiedReport = abi.decode(
verifiedReportData,
(BasicReport)
);
// Decode verified report data into a Report struct
Report memory verifiedReport = abi.decode(verifiedReportData, (Report));

// Log price from report
emit PriceUpdate(verifiedReport.price);
Expand Down
9 changes: 1 addition & 8 deletions src/content/data-streams/getting-started-hardhat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ whatsnext: {
import { Aside } from "@components"
import DataStreams from "@features/data-streams/common/DataStreams.astro"

<Aside type="note" title="Mainnet Access">
Chainlink Data Streams is available on Arbitrum Mainnet and Arbitrum Sepolia.
</Aside>

<Aside type="note" title="Talk to an expert">
<a href="https://chainlinkcommunity.typeform.com/datastreams?#ref_id=docs">Contact us</a> to talk to an expert about
integrating Chainlink Data Streams with your applications.
</Aside>
<DataStreams section="dsNotes" />

<DataStreams section="gettingStartedHardhat" />
9 changes: 1 addition & 8 deletions src/content/data-streams/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ whatsnext: {
import { Aside } from "@components"
import DataStreams from "@features/data-streams/common/DataStreams.astro"

<Aside type="note" title="Mainnet Access">
Chainlink Data Streams is available on Arbitrum Mainnet and Arbitrum Sepolia.
</Aside>

<Aside type="note" title="Talk to an expert">
<a href="https://chainlinkcommunity.typeform.com/datastreams?#ref_id=docs">Contact us</a> to talk to an expert about
integrating Chainlink Data Streams with your applications.
</Aside>
<DataStreams section="dsNotes" />

<DataStreams section="gettingStarted" />
14 changes: 4 additions & 10 deletions src/content/data-streams/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ whatsnext:

import { Aside, ClickToZoom } from "@components"
import button from "@chainlink/design-system/button.module.css"
import DataStreams from "@features/data-streams/common/DataStreams.astro"

<Aside type="note" title="Mainnet Access">
Chainlink Data Streams is available on Arbitrum Mainnet and Arbitrum Sepolia.
</Aside>

<Aside type="note" title="Talk to an expert">
<a href="https://chainlinkcommunity.typeform.com/datastreams?#ref_id=docs">Contact us</a> to talk to an expert about
integrating Chainlink Data Streams with your applications.
</Aside>
<DataStreams section="dsNotes" />

Chainlink Data Streams provides low-latency delivery of market data offchain that you can verify onchain. With Chainlink Data Streams, decentralized applications (dApps) now have on-demand access to high-frequency market data backed by decentralized and transparent infrastructure. When combined with [Chainlink Automation](/chainlink-automation/introduction), Chainlink Data Streams allows decentralized applications to automate trade execution, mitigate frontrunning, and limit bias or adverse incentives in executing non-user-triggered orders.

Expand All @@ -46,8 +40,8 @@ Chainlink Data Streams supports fee payments in LINK and in alternative assets,

Chainlink Data Streams has the following core components:

- **A Chainlink Decentralized Oracle Network (DON):** This DON operates similarly to the DONs that power [Chainlink Data Feeds](/data-feeds), but the key difference is that it signs and delivers reports to the Chainlink Data Engine rather than delivering answers onchain directly. This allows the Data Streams DON to deliver reports more frequently for time-sensitive applications. Nodes in the DON retrieve data from many different data providers, reach a concensus about the median price of an asset, sign a report including that data, and deliver the report to the Chainlink Data Engine.
- **The Chainlink Data Engine:** The Data Engine stores the signed reports and delivers them to Chainlink Automation when it is requested.
- **A Chainlink Decentralized Oracle Network (DON):** This DON operates similarly to the DONs that power [Chainlink Data Feeds](/data-feeds), but the key difference is that it signs and delivers reports to the Data Streams Aggregation Network rather than delivering answers onchain directly. This allows the Data Streams DON to deliver reports more frequently for time-sensitive applications. Nodes in the DON retrieve data from many different data providers, reach a concensus about the median price of an asset, sign a report including that data, and deliver the report to the Data Streams Aggregation Network.
- **The Data Streams Aggregation Network:** The Data Streams Aggregation Network stores the signed reports and delivers them to Chainlink Automation when it is requested.
- **The Chainlink Verifier Contract:** This contract verifies the signature from the DON to cryptographically guarantee that the report has not been altered from the time that the DON reached concensus to the point where you use the data in your application.

<ClickToZoom src="/images/data-streams/data-streams-architecture.webp" />
Expand Down
10 changes: 2 additions & 8 deletions src/content/data-streams/reference/interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ title: "Interfaces"
---

import { Aside, CodeSample } from "@components"
import DataStreams from "@features/data-streams/common/DataStreams.astro"

<Aside type="note" title="Mainnet Access">
Chainlink Data Streams is available on Arbitrum Mainnet and Arbitrum Sepolia.
</Aside>

<Aside type="note" title="Talk to an expert">
<a href="https://chainlinkcommunity.typeform.com/datastreams?#ref_id=docs">Contact us</a> to talk to an expert about
integrating Chainlink Data Streams with your applications.
</Aside>
<DataStreams section="dsNotes" />

Data Streams require several interfaces in order to retrieve and verify reports.

Expand Down
45 changes: 15 additions & 30 deletions src/content/data-streams/reference/report-schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,22 @@ title: "Report Schema Reference"
---

import { Aside } from "@components"
import DataStreams from "@features/data-streams/common/DataStreams.astro"

<Aside type="note" title="Mainnet Access">
Chainlink Data Streams is available on Arbitrum Mainnet and Arbitrum Sepolia.
</Aside>
<DataStreams section="dsNotes" />

<Aside type="note" title="Talk to an expert">
<a href="https://chainlinkcommunity.typeform.com/datastreams?#ref_id=docs">Contact us</a> to talk to an expert about
integrating Chainlink Data Streams with your applications.
</Aside>
Data Streams feeds have the following values specifically applicable to market pricing data. Current Data Streams feeds adhere to the schema outlined below:

Data Streams can deliver a broad array of information in each report. The values you can expect in each report depend on the schema for the Stream ID that you select. You can find the schema for each ID on the [Stream IDs](/data-streams/stream-ids) page.
| Value | Type | Description |
| ----------------------- | --------- | ------------------------------------------------------------------------------------- |
| `feedID` | `bytes32` | The unique identifier for the Data Streams feed |
| `validFromTimestamp` | `uint32` | The earliest timestamp during which the price is valid |
| `observationsTimestamp` | `uint32` | The latest timestamp during which the price is valid |
| `nativeFee` | `uint192` | The cost to verify this report onchain when paying with the blockchain's native token |
| `linkFee` | `uint192` | The cost to verify this report onchain when paying with LINK |
| `expiresAt` | `uint32` | The expiration date of this report |
| `price` | `int192` | The DON's consensus median price for this report carried to 18 decimal places |
| `bid` | `int192` | The simulated price impact of a buy order up to the X% depth of liquidity usage |
| `ask` | `int192` | Simulated price impact of a sell order up to the X% depth of liquidity usage |

## Basic schema

Streams with the `Basic` schema have the following values specifically applicable to market pricing data:

| Value | Type | Description |
| ----------------------- | --------- | ----------------------------------------------------------------------------- |
| `feedID` | `bytes32` | The unique identifier for the stream |
| `validFromTimestamp` | `uint32` | The earliest timestamp during which the price is valid |
| `observationsTimestamp` | `uint32` | The latest timestamp during which the price is valid |
| `nativeFee` | `uint192` | The cost to verify this report when paying with the blockchain's native token |
| `linkFee` | `uint192` | The cost to verify this report when paying with LINK |
| `expiresAt` | `uint32` | The expiration date of this report |
| `price` | `int192` | The DON's consensus median price for this report carried to 8 decimal places |

## Premium schema

The `Premium` schema includes all values from the `Basic` schema, and also includes `bid` and `ask` values:

| Value | Type | Description |
| ----- | -------- | ------------------------------------------------------------------------------- |
| `bid` | `int192` | The simulated price impact of a buy order up to the X% depth of liquidity usage |
| `ask` | `int192` | Simulated price impact of a sell order up to the X% depth of liquidity usage |
Note: Future Data Streams feeds may use different report schemas.
6 changes: 1 addition & 5 deletions src/content/data-streams/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ whatsnext:

import { Aside } from "@components"

<Aside type="note" title="Mainnet Access">
Chainlink Data Streams is available on Arbitrum Mainnet and Arbitrum Sepolia.
</Aside>

<Aside type="note" title="Talk to an expert">
<a href="https://chainlinkcommunity.typeform.com/datastreams?#ref_id=docs">Contact us</a> to talk to an expert about
integrating Chainlink Data Streams with your applications.
</Aside>

## 2024-01-25 - Arbitrum Sepolia

Chainlink Data Streams is available on <a href="/data-streams/stream-ids?network=arbitrum&page=1">Arbitrum Sepolia</a>.
Chainlink Data Streams is available in Early Access on <a href="/data-streams/stream-ids?network=arbitrum&page=1">Arbitrum Sepolia</a>.

## 2023-10-02 - Data Streams Early Access

Expand Down
Loading
Loading