Skip to content
Verified contractExactUNLICENSED

AutomationReceiver

Address0x011b8ddf24ad0ee09cc198cb0ac4f076f90bb81d
Balance

0 ETH

 

Transactions

16

 

Compiler

solc 0.8.30

 

Same code

4 more contracts

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
UNLICENSED
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,032,813
Creation transaction
0xdcfc0c0d26…eb6648fffd

contracts/automation/AutomationReceiver.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {ICREReceiver} from "../interfaces/ICREReceiver.sol";

/// @title CRE automation receiver
/// @notice Validates CRE workflow reports and forwards approved upkeep calls.
/// @dev Deploy one instance per vault and allow only that vault's automation targets.
///      Reports are encoded as abi.encode(target, callData, chainSelector, scheduledAt). CRE identity metadata is packed as
///      workflowId (32 bytes), workflowName (10 bytes), and workflowOwner (20 bytes).
contract AutomationReceiver is ICREReceiver, Ownable {
    uint256 private constant IDENTITY_METADATA_LENGTH = 62;
    uint256 private constant FORWARDER_METADATA_LENGTH = 64;

    address public forwarder;
    address public workflowOwner;
    uint64 public chainSelector;

    mapping(bytes32 workflowId => bool allowed) public allowedWorkflowIds;
    mapping(address target => mapping(bytes4 selector => bool allowed)) public allowedCalls;
    mapping(address target => uint64 scheduledAt) public lastScheduledAt;

    error ZeroAddress();
    error InvalidMetadataLength(uint256 received);
    error InvalidSender(address received, address expected);
    error InvalidWorkflowOwner(address received, address expected);
    error WorkflowNotAllowed(bytes32 workflowId);
    error InvalidChainSelector();
    error UnexpectedChainSelector(uint64 received, uint64 expected);
    error StaleReport(address target, uint64 received, uint64 lastAccepted);
    error InvalidCallData();
    error CallNotAllowed(address target, bytes4 selector);
    error TargetCallFailed();

    event ForwarderUpdated(address indexed previousForwarder, address indexed newForwarder);
    event WorkflowOwnerUpdated(address indexed previousOwner, address indexed newOwner);
    event WorkflowPermissionUpdated(bytes32 indexed workflowId, bool allowed);
    event CallPermissionUpdated(address indexed target, bytes4 indexed selector, bool allowed);
    event CallForwarded(
        bytes32 indexed workflowId,
        address indexed target,
        bytes4 indexed selector
    );

    constructor(
        address initialOwner,
        address forwarder_,
        address workflowOwner_,
        uint64 chainSelector_
    ) Ownable(initialOwner) {
        if (forwarder_ == address(0) || workflowOwner_ == address(0)) revert ZeroAddress();
        if (chainSelector_ == 0) revert InvalidChainSelector();
        forwarder = forwarder_;
        workflowOwner = workflowOwner_;
        chainSelector = chainSelector_;
    }

    /// @notice Accept a verified CRE report and forward its approved call.
    function onReport(bytes calldata metadata, bytes calldata report) external override {
        if (msg.sender != forwarder) revert InvalidSender(msg.sender, forwarder);
        if (
            metadata.length != IDENTITY_METADATA_LENGTH &&
            metadata.length != FORWARDER_METADATA_LENGTH
        ) revert InvalidMetadataLength(metadata.length);

        (bytes32 workflowId, address reportWorkflowOwner) = _decodeMetadata(metadata);
        if (reportWorkflowOwner != workflowOwner)
            revert InvalidWorkflowOwner(reportWorkflowOwner, workflowOwner);
        if (!allowedWorkflowIds[workflowId]) revert WorkflowNotAllowed(workflowId);

        (
            address target,
            bytes memory callData,
            uint64 reportChainSelector,
            uint64 scheduledAt
        ) = abi.decode(report, (address, bytes, uint64, uint64));
        if (target == address(0)) revert ZeroAddress();
        if (reportChainSelector != chainSelector)
            revert UnexpectedChainSelector(reportChainSelector, chainSelector);
        uint64 previousScheduledAt = lastScheduledAt[target];
        if (scheduledAt == 0 || scheduledAt <= previousScheduledAt)
            revert StaleReport(target, scheduledAt, previousScheduledAt);
        if (callData.length < 4) revert InvalidCallData();

        bytes4 selector = _selector(callData);
        if (!allowedCalls[target][selector]) revert CallNotAllowed(target, selector);

        lastScheduledAt[target] = scheduledAt;
        (bool success, bytes memory returnData) = target.call(callData);
        if (!success) {
            if (returnData.length == 0) revert TargetCallFailed();
            assembly ("memory-safe") {
                revert(add(returnData, 32), mload(returnData))
            }
        }

        emit CallForwarded(workflowId, target, selector);
    }

    function setForwarder(address newForwarder) external onlyOwner {
        if (newForwarder == address(0)) revert ZeroAddress();
        address previousForwarder = forwarder;
        forwarder = newForwarder;
        emit ForwarderUpdated(previousForwarder, newForwarder);
    }

    function setWorkflowOwner(address newWorkflowOwner) external onlyOwner {
        if (newWorkflowOwner == address(0)) revert ZeroAddress();
        address previousOwner = workflowOwner;
        workflowOwner = newWorkflowOwner;
        emit WorkflowOwnerUpdated(previousOwner, newWorkflowOwner);
    }

    function setWorkflowPermission(bytes32 workflowId, bool allowed) external onlyOwner {
        allowedWorkflowIds[workflowId] = allowed;
        emit WorkflowPermissionUpdated(workflowId, allowed);
    }

    function setCallPermission(address target, bytes4 selector, bool allowed) external onlyOwner {
        if (target == address(0)) revert ZeroAddress();
        allowedCalls[target][selector] = allowed;
        emit CallPermissionUpdated(target, selector, allowed);
    }

    function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
        return
            interfaceId == type(ICREReceiver).interfaceId ||
            interfaceId == type(IERC165).interfaceId;
    }

    function _decodeMetadata(
        bytes calldata metadata
    ) private pure returns (bytes32 workflowId, address reportWorkflowOwner) {
        workflowId = bytes32(metadata[0:32]);
        reportWorkflowOwner = address(bytes20(metadata[42:62]));
    }

    function _selector(bytes memory callData) private pure returns (bytes4 selector) {
        selector = bytes4(callData);
    }
}

@openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

@openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

contracts/interfaces/ICREReceiver.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/// @title Chainlink CRE report receiver interface
/// @notice Mirrors Chainlink IReceiver using the repository's OpenZeppelin import path.
/// @dev Chainlink contracts 1.5.0 uses a versioned Foundry import in its IReceiver,
///      which this repository's Hardhat resolver cannot load directly.
interface ICREReceiver is IERC165 {
    function onReport(bytes calldata metadata, bytes calldata report) external;
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "details": {
      "yulDetails": {
        "optimizerSteps": "u"
      }
    },
    "enabled": true
  },
  "evmVersion": "cancun"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.