From 8095a10a2d901c74c7d53ebc2fcff4f40caafa0c Mon Sep 17 00:00:00 2001 From: Gas <86567384+gas1cent@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:33:36 +0400 Subject: [PATCH] refactor: turn `OracleTypehash` into a library (#54) --- .github/pull_request_template.md | 2 +- solidity/contracts/Oracle.sol | 32 ++++++++++++++++----- solidity/contracts/utils/OracleTypehash.sol | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4c717ef..e80c781 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,3 @@ # 🤖 Linear -Closes OPO-XXX +Closes OPT-XXX diff --git a/solidity/contracts/Oracle.sol b/solidity/contracts/Oracle.sol index be79396..7f2fcdc 100644 --- a/solidity/contracts/Oracle.sol +++ b/solidity/contracts/Oracle.sol @@ -13,7 +13,7 @@ import {ValidatorLib} from '../libraries/ValidatorLib.sol'; import {OracleAccessController} from './OracleAccessController.sol'; import {OracleTypehash} from './utils/OracleTypehash.sol'; -contract Oracle is IOracle, OracleAccessController, OracleTypehash { +contract Oracle is IOracle, OracleAccessController { using ValidatorLib for *; /// @inheritdoc IOracle @@ -128,7 +128,7 @@ contract Oracle is IOracle, OracleAccessController, OracleTypehash { AccessControl calldata _accessControl ) external - hasAccess(_request.accessModule, PROPOSE_TYPEHASH, abi.encode(_request, _response), _accessControl) + hasAccess(_request.accessModule, OracleTypehash.PROPOSE_TYPEHASH, abi.encode(_request, _response), _accessControl) returns (bytes32 _responseId) { _responseId = ValidatorLib._validateResponse(_request, _response); @@ -168,7 +168,12 @@ contract Oracle is IOracle, OracleAccessController, OracleTypehash { AccessControl calldata _accessControl ) external - hasAccess(_request.accessModule, DISPUTE_TYPEHASH, abi.encode(_request, _response, _dispute), _accessControl) + hasAccess( + _request.accessModule, + OracleTypehash.DISPUTE_TYPEHASH, + abi.encode(_request, _response, _dispute), + _accessControl + ) returns (bytes32 _disputeId) { bytes32 _responseId; @@ -213,7 +218,12 @@ contract Oracle is IOracle, OracleAccessController, OracleTypehash { AccessControl calldata _accessControl ) external - hasAccess(_request.accessModule, ESCALATE_TYPEHASH, abi.encode(_request, _response, _dispute), _accessControl) + hasAccess( + _request.accessModule, + OracleTypehash.ESCALATE_TYPEHASH, + abi.encode(_request, _response, _dispute), + _accessControl + ) { (bytes32 _responseId, bytes32 _disputeId) = ValidatorLib._validateResponseAndDispute(_request, _response, _dispute); @@ -251,7 +261,12 @@ contract Oracle is IOracle, OracleAccessController, OracleTypehash { AccessControl calldata _accessControl ) external - hasAccess(_request.accessModule, RESOLVE_TYPEHASH, abi.encode(_request, _response, _dispute), _accessControl) + hasAccess( + _request.accessModule, + OracleTypehash.RESOLVE_TYPEHASH, + abi.encode(_request, _response, _dispute), + _accessControl + ) { (bytes32 _responseId, bytes32 _disputeId) = ValidatorLib._validateResponseAndDispute(_request, _response, _dispute); @@ -309,7 +324,10 @@ contract Oracle is IOracle, OracleAccessController, OracleTypehash { IOracle.Request calldata _request, IOracle.Response calldata _response, AccessControl calldata _accessControl - ) external hasAccess(_request.accessModule, FINALIZE_TYPEHASH, abi.encode(_request, _response), _accessControl) { + ) + external + hasAccess(_request.accessModule, OracleTypehash.FINALIZE_TYPEHASH, abi.encode(_request, _response), _accessControl) + { bytes32 _requestId; bytes32 _responseId; @@ -422,7 +440,7 @@ contract Oracle is IOracle, OracleAccessController, OracleTypehash { AccessControl calldata _accessControl ) internal - hasAccess(_request.accessModule, CREATE_TYPEHASH, abi.encode(_request), _accessControl) + hasAccess(_request.accessModule, OracleTypehash.CREATE_TYPEHASH, abi.encode(_request), _accessControl) returns (bytes32 _requestId) { uint256 _requestNonce = totalRequestCount++; diff --git a/solidity/contracts/utils/OracleTypehash.sol b/solidity/contracts/utils/OracleTypehash.sol index 4ffb3e0..77ae352 100644 --- a/solidity/contracts/utils/OracleTypehash.sol +++ b/solidity/contracts/utils/OracleTypehash.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -contract OracleTypehash { +library OracleTypehash { bytes32 public constant CREATE_TYPEHASH = keccak256('createRequest(Request _request,bytes32 _ipfsHash,AccessControl _accessControl');