Skip to content

Commit

Permalink
feat: add consumer and sdk contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk committed Dec 27, 2024
1 parent 0912020 commit 612f890
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "git+https://github.com/defi-wonderland/solidity-foundry-boilerplate.git"
},
"license": "PPL",
"license": "MIT",
"author": "Breadchain, fork ofWonderland",
"scripts": {
"build": "forge build",
Expand Down
7 changes: 0 additions & 7 deletions src/contracts/AVSConsumer.sol

This file was deleted.

36 changes: 36 additions & 0 deletions src/contracts/LayerConsumer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol';
import {ILayerConsumer} from 'interfaces/ILayerConsumer.sol';

contract LayerConsumer is ILayerConsumer {
/// @notice bytes4(keccak256("isValidSignature(bytes32,bytes)")
bytes4 internal constant _ERC1271_SIGNATURE = 0x1626ba7e;

/// @inheritdoc ILayerConsumer
ECDSAStakeRegistry public immutable STAKE_REGISTRY;

/// @notice Enforce that the caller is an operator
modifier onlyOperator() {
if (!STAKE_REGISTRY.operatorRegistered(msg.sender)) revert NotOperator();
_;
}

/**
* @notice Initializer
* @param _stakeRegistry The address of the stake registry contract
*/
constructor(address _stakeRegistry) {
STAKE_REGISTRY = ECDSAStakeRegistry(_stakeRegistry);
}

/**
* @notice Validates a layer task from off-chain AVS operator
* @param _task The message and signatures to verify
* @return _isValid Whether the task is valid
*/
function _validateLayerTask(Task memory _task) internal view returns (bool _isValid) {
_isValid = (_ERC1271_SIGNATURE == STAKE_REGISTRY.isValidSignature(_task.dataHash, _task.signatureData));
}
}
16 changes: 16 additions & 0 deletions src/contracts/LayerSDK.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {LayerConsumer} from 'contracts/LayerConsumer.sol';
import {ILayerSDK} from 'interfaces/ILayerSDK.sol';

contract LayerSDK is LayerConsumer, ILayerSDK {
/// @notice Initializer
constructor(address _stakeRegistry) LayerConsumer(_stakeRegistry) {}

/// @inheritdoc ILayerSDK
function validateLayerTask(string calldata _offchainData) external view onlyOperator returns (bool _isValid) {
Task memory _task = Task({dataHash: bytes32(bytes(_offchainData[0:32])), signatureData: bytes(_offchainData[32:])});
_isValid = _validateLayerTask(_task);
}
}
25 changes: 0 additions & 25 deletions src/interfaces/IAVSConsumer.sol

This file was deleted.

42 changes: 42 additions & 0 deletions src/interfaces/ILayerConsumer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {ECDSAStakeRegistry} from '@eigenlayer-middleware/unaudited/ECDSAStakeRegistry.sol';

/**
* @title AVSConsumer Contract
* @author Breadchain
* @notice LayerConsumer contract to validate layer tasks from off-chain AVS operators
*/
interface ILayerConsumer {
/*///////////////////////////////////////////////////////////////
DATA STRUCTURES
//////////////////////////////////////////////////////////////*/

/**
* @notice The task structure
* @param dataHash The hash of the data to verify
* @param signatureData The signature(s) to verify
*/
struct Task {
bytes32 dataHash;
bytes signatureData;
}

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

/// @notice Error thrown when the caller is not an operator
error NotOperator();

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice The stake registry contract
* @return _stakeRegistry The stake registry address
*/
function STAKE_REGISTRY() external view returns (ECDSAStakeRegistry _stakeRegistry); // solhint-disable-line func-name-mixedcase
}
17 changes: 17 additions & 0 deletions src/interfaces/ILayerSDK.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {ILayerConsumer} from 'interfaces/ILayerConsumer.sol';

interface ILayerSDK is ILayerConsumer {
/*///////////////////////////////////////////////////////////////
LOGIC
//////////////////////////////////////////////////////////////*/

/**
* @notice Validates a layer task from off-chain AVS operator
* @param _offchainData The off-chain data to verify
* @return _isValid Whether the task is valid
*/
function validateLayerTask(string calldata _offchainData) external view returns (bool _isValid);
}
7 changes: 0 additions & 7 deletions test/unit/AVSConsumer.t.sol

This file was deleted.

6 changes: 6 additions & 0 deletions test/unit/LayerConsumer.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {Test} from 'forge-std/Test.sol';

contract UnitLayerConsumer is Test {}

0 comments on commit 612f890

Please sign in to comment.