Skip to content
Lattice

IChainlinkCREAdapter

Git Source

Title: IChainlinkCREAdapter

Author: Modified from the Chainlink CRE consumer-contract guide

(https://docs.chain.link/cre/guides/workflow/using-evm-client/onchain-write/building-consumer-contracts)

Interface for the ChainlinkCREAdapter Diamond facet — a Chainlink CRE (Chainlink Runtime Environment) workflow-report receiver.

Push receiver (the inverse of the price adapters' pull model). The KeystoneForwarder validates the DON's report signatures off-chain, then calls onReport, which is gated so that (a) only the configured forwarder may call it and (b) only an admin-allowlisted workflow id may write. The latest report per workflow is stored. Consumer facets that inherit ChainlinkCREAdapter should override onReport (calling super.onReport first) to act on the decoded report.

The module registers the canonical type(IReceiver).interfaceId for ERC-165 (so CRE tooling detects the receiver), analogous to how the token modules register canonical ERC-721/ERC-1155 ids rather than their Lattice-specific interface ids.

Functions

getForwarder

Returns the configured KeystoneForwarder.

function getForwarder() external view returns (address);

Returns

NameTypeDescription
<none>address

isWorkflowAllowed

Returns whether workflowId is allowed to write reports.

function isWorkflowAllowed(bytes32 workflowId) external view returns (bool);

Parameters

NameTypeDescription
workflowIdbytes32The CRE workflow id.

Returns

NameTypeDescription
<none>bool

getLatestReport

Returns the latest report stored for workflowId.

function getLatestReport(bytes32 workflowId) external view returns (bytes memory report, uint256 timestamp);

Parameters

NameTypeDescription
workflowIdbytes32The CRE workflow id.

Returns

NameTypeDescription
reportbytesThe ABI-encoded report payload (empty if none stored).
timestampuint256The block timestamp when the report was received (0 if none).

setForwarder

Sets or replaces the KeystoneForwarder.

Caller must hold DEFAULT_ADMIN_ROLE. Reverts CREInvalidForwarder on the zero address.

function setForwarder(address forwarder) external;

Parameters

NameTypeDescription
forwarderaddressThe forwarder allowed to call onReport.

setWorkflow

Allows or disallows a workflow id from writing reports.

Caller must hold DEFAULT_ADMIN_ROLE. Reverts CREInvalidWorkflowId on a zero id.

function setWorkflow(bytes32 workflowId, bool allowed) external;

Parameters

NameTypeDescription
workflowIdbytes32The CRE workflow id.
allowedboolTrue to allow, false to disallow.

onReport

Called by the KeystoneForwarder to deliver a CRE workflow report.

Gated to the configured forwarder and to an allowlisted workflow id; decodes the metadata, stores the latest report for that workflow, and emits ReportReceived. Consumer facets should override this to consume the report.

function onReport(bytes calldata metadata, bytes calldata report) external;

Parameters

NameTypeDescription
metadatabytesPacked workflow identity (workflowId, workflowName, workflowOwner) + report id.
reportbytesThe ABI-encoded workflow payload.

Events

CREForwarderSet

Emitted when the KeystoneForwarder is set.

event CREForwarderSet(address forwarder);

Parameters

NameTypeDescription
forwarderaddressThe forwarder allowed to call onReport.

CREWorkflowSet

Emitted when a workflow id's allowlist status changes.

event CREWorkflowSet(bytes32 indexed workflowId, bool allowed);

Parameters

NameTypeDescription
workflowIdbytes32The CRE workflow id.
allowedboolTrue if the workflow may now write reports.

ReportReceived

Emitted when a report is accepted and stored.

event ReportReceived(bytes32 indexed workflowId, address indexed workflowOwner, bytes2 reportId);

Parameters

NameTypeDescription
workflowIdbytes32The CRE workflow id that produced the report.
workflowOwneraddressThe workflow owner decoded from the metadata.
reportIdbytes2The 2-byte report id decoded from the metadata.

Errors

CRENotConfigured

The forwarder has not been configured (forwarder address is zero).

error CRENotConfigured();

CREInvalidForwarder

setForwarder was called with the zero address.

error CREInvalidForwarder();

CREInvalidWorkflowId

setWorkflow was called with a zero workflow id.

error CREInvalidWorkflowId();

CREOnlyForwarder

onReport was called by an address other than the configured forwarder.

error CREOnlyForwarder(address caller);

Parameters

NameTypeDescription
calleraddressThe unauthorised caller.

CREWorkflowNotAllowed

onReport carried a workflow id that is not on the allowlist.

error CREWorkflowNotAllowed(bytes32 workflowId);

Parameters

NameTypeDescription
workflowIdbytes32The disallowed workflow id.

CREInvalidMetadata

onReport was called with metadata shorter than the required 64 bytes.

error CREInvalidMetadata();