Skip to content

Commit

Permalink
resolve root level solhint issues (#10929)
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR authored Oct 12, 2023
1 parent 4983951 commit f21c9c3
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 147 deletions.
10 changes: 0 additions & 10 deletions contracts/.solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
#./src/v0.8/l2ep/dev


# Temp ignore the following files as they contain issues.
./src/v0.8/ChainlinkClient.sol
./src/v0.8/Flags.sol
./src/v0.8/KeepersVRFConsumer.sol
./src/v0.8/PermissionedForwardProxy.sol
./src/v0.8/ValidatorProxy.sol
./src/v0.8/Chainlink.sol
./src/v0.8/ChainSpecificUtil.sol


# Ignore tests, this should not be the long term plan but is OK in the short term
./src/v0.8/**/*.t.sol
./src/v0.8/mocks
Expand Down
30 changes: 15 additions & 15 deletions contracts/src/v0.8/ChainSpecificUtil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ library ChainSpecificUtil {
* @notice Otherwise, it uses the blockhash opcode.
* @notice Note that the blockhash opcode will return the L2 blockhash on Optimism.
*/
function getBlockhash(uint64 blockNumber) internal view returns (bytes32) {
function _getBlockhash(uint64 blockNumber) internal view returns (bytes32) {
uint256 chainid = block.chainid;
if (isArbitrumChainId(chainid)) {
if ((getBlockNumber() - blockNumber) > 256 || blockNumber >= getBlockNumber()) {
if (_isArbitrumChainId(chainid)) {
if ((_getBlockNumber() - blockNumber) > 256 || blockNumber >= _getBlockNumber()) {
return "";
}
return ARBSYS.arbBlockHash(blockNumber);
Expand All @@ -70,9 +70,9 @@ library ChainSpecificUtil {
* @notice Otherwise, it uses the block.number opcode.
* @notice Note that the block.number opcode will return the L2 block number on Optimism.
*/
function getBlockNumber() internal view returns (uint256) {
function _getBlockNumber() internal view returns (uint256) {
uint256 chainid = block.chainid;
if (isArbitrumChainId(chainid)) {
if (_isArbitrumChainId(chainid)) {
return ARBSYS.arbBlockNumber();
}
return block.number;
Expand All @@ -86,11 +86,11 @@ library ChainSpecificUtil {
* @notice On Optimism, the provided calldata is passed to the OVM_GasPriceOracle predeploy
* @notice and getL1Fee is called to get the fees.
*/
function getCurrentTxL1GasFees(bytes memory txCallData) internal view returns (uint256) {
function _getCurrentTxL1GasFees(bytes memory txCallData) internal view returns (uint256) {
uint256 chainid = block.chainid;
if (isArbitrumChainId(chainid)) {
if (_isArbitrumChainId(chainid)) {
return ARBGAS.getCurrentTxL1GasFees();
} else if (isOptimismChainId(chainid)) {
} else if (_isOptimismChainId(chainid)) {
return OVM_GASPRICEORACLE.getL1Fee(bytes.concat(txCallData, L1_FEE_DATA_PADDING));
}
return 0;
Expand All @@ -100,23 +100,23 @@ library ChainSpecificUtil {
* @notice Returns the gas cost in wei of calldataSizeBytes of calldata being posted
* @notice to L1.
*/
function getL1CalldataGasCost(uint256 calldataSizeBytes) internal view returns (uint256) {
function _getL1CalldataGasCost(uint256 calldataSizeBytes) internal view returns (uint256) {
uint256 chainid = block.chainid;
if (isArbitrumChainId(chainid)) {
if (_isArbitrumChainId(chainid)) {
(, uint256 l1PricePerByte, , , , ) = ARBGAS.getPricesInWei();
// see https://developer.arbitrum.io/devs-how-tos/how-to-estimate-gas#where-do-we-get-all-this-information-from
// for the justification behind the 140 number.
return l1PricePerByte * (calldataSizeBytes + 140);
} else if (isOptimismChainId(chainid)) {
return calculateOptimismL1DataFee(calldataSizeBytes);
} else if (_isOptimismChainId(chainid)) {
return _calculateOptimismL1DataFee(calldataSizeBytes);
}
return 0;
}

/**
* @notice Return true if and only if the provided chain ID is an Arbitrum chain ID.
*/
function isArbitrumChainId(uint256 chainId) internal pure returns (bool) {
function _isArbitrumChainId(uint256 chainId) internal pure returns (bool) {
return
chainId == ARB_MAINNET_CHAIN_ID ||
chainId == ARB_GOERLI_TESTNET_CHAIN_ID ||
Expand All @@ -127,7 +127,7 @@ library ChainSpecificUtil {
* @notice Return true if and only if the provided chain ID is an Optimism chain ID.
* @notice Note that optimism chain id's are also OP stack chain id's.
*/
function isOptimismChainId(uint256 chainId) internal pure returns (bool) {
function _isOptimismChainId(uint256 chainId) internal pure returns (bool) {
return
chainId == OP_MAINNET_CHAIN_ID ||
chainId == OP_GOERLI_CHAIN_ID ||
Expand All @@ -136,7 +136,7 @@ library ChainSpecificUtil {
chainId == BASE_GOERLI_CHAIN_ID;
}

function calculateOptimismL1DataFee(uint256 calldataSizeBytes) internal view returns (uint256) {
function _calculateOptimismL1DataFee(uint256 calldataSizeBytes) internal view returns (uint256) {
// from: https://community.optimism.io/docs/developers/build/transaction-fees/#the-l1-data-fee
// l1_data_fee = l1_gas_price * (tx_data_gas + fixed_overhead) * dynamic_overhead
// tx_data_gas = count_zero_bytes(tx_data) * 4 + count_non_zero_bytes(tx_data) * 16
Expand Down
17 changes: 9 additions & 8 deletions contracts/src/v0.8/Chainlink.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {BufferChainlink} from "./vendor/BufferChainlink.sol";
* @dev Uses imported CBOR library for encoding to buffer
*/
library Chainlink {
uint256 internal constant defaultBufferSize = 256; // solhint-disable-line const-name-snakecase
// solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables
uint256 internal constant defaultBufferSize = 256;

using CBORChainlink for BufferChainlink.buffer;

Expand All @@ -30,7 +31,7 @@ library Chainlink {
* @param callbackFunc The callback function signature
* @return The initialized request
*/
function initialize(
function _initialize(
Request memory self,
bytes32 jobId,
address callbackAddr,
Expand All @@ -49,7 +50,7 @@ library Chainlink {
* @param self The initialized request
* @param data The CBOR data
*/
function setBuffer(Request memory self, bytes memory data) internal pure {
function _setBuffer(Request memory self, bytes memory data) internal pure {
BufferChainlink.init(self.buf, data.length);
BufferChainlink.append(self.buf, data);
}
Expand All @@ -60,7 +61,7 @@ library Chainlink {
* @param key The name of the key
* @param value The string value to add
*/
function add(Request memory self, string memory key, string memory value) internal pure {
function _add(Request memory self, string memory key, string memory value) internal pure {
self.buf.encodeString(key);
self.buf.encodeString(value);
}
Expand All @@ -71,7 +72,7 @@ library Chainlink {
* @param key The name of the key
* @param value The bytes value to add
*/
function addBytes(Request memory self, string memory key, bytes memory value) internal pure {
function _addBytes(Request memory self, string memory key, bytes memory value) internal pure {
self.buf.encodeString(key);
self.buf.encodeBytes(value);
}
Expand All @@ -82,7 +83,7 @@ library Chainlink {
* @param key The name of the key
* @param value The int256 value to add
*/
function addInt(Request memory self, string memory key, int256 value) internal pure {
function _addInt(Request memory self, string memory key, int256 value) internal pure {
self.buf.encodeString(key);
self.buf.encodeInt(value);
}
Expand All @@ -93,7 +94,7 @@ library Chainlink {
* @param key The name of the key
* @param value The uint256 value to add
*/
function addUint(Request memory self, string memory key, uint256 value) internal pure {
function _addUint(Request memory self, string memory key, uint256 value) internal pure {
self.buf.encodeString(key);
self.buf.encodeUInt(value);
}
Expand All @@ -104,7 +105,7 @@ library Chainlink {
* @param key The name of the key
* @param values The array of string values to add
*/
function addStringArray(Request memory self, string memory key, string[] memory values) internal pure {
function _addStringArray(Request memory self, string memory key, string[] memory values) internal pure {
self.buf.encodeString(key);
self.buf.startArray();
for (uint256 i = 0; i < values.length; i++) {
Expand Down
66 changes: 35 additions & 31 deletions contracts/src/v0.8/ChainlinkClient.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Chainlink.sol";
import "./interfaces/ENSInterface.sol";
import "./shared/interfaces/LinkTokenInterface.sol";
import "./interfaces/ChainlinkRequestInterface.sol";
import "./interfaces/OperatorInterface.sol";
import "./interfaces/PointerInterface.sol";
import {Chainlink} from "./Chainlink.sol";
import {ENSInterface} from "./interfaces/ENSInterface.sol";
import {LinkTokenInterface} from "./shared/interfaces/LinkTokenInterface.sol";
import {ChainlinkRequestInterface} from "./interfaces/ChainlinkRequestInterface.sol";
import {OperatorInterface} from "./interfaces/OperatorInterface.sol";
import {PointerInterface} from "./interfaces/PointerInterface.sol";
import {ENSResolver as ENSResolver_Chainlink} from "./vendor/ENSResolver.sol";

/**
* @title The ChainlinkClient contract
* @notice Contract writers can inherit this contract in order to create requests for the
* Chainlink network
*/
// solhint-disable custom-errors
abstract contract ChainlinkClient {
using Chainlink for Chainlink.Request;

Expand Down Expand Up @@ -44,13 +45,13 @@ abstract contract ChainlinkClient {
* @param callbackFunctionSignature function signature to use for the callback
* @return A Chainlink Request struct in memory
*/
function buildChainlinkRequest(
function _buildChainlinkRequest(
bytes32 specId,
address callbackAddr,
bytes4 callbackFunctionSignature
) internal pure returns (Chainlink.Request memory) {
Chainlink.Request memory req;
return req.initialize(specId, callbackAddr, callbackFunctionSignature);
return req._initialize(specId, callbackAddr, callbackFunctionSignature);
}

/**
Expand All @@ -59,12 +60,12 @@ abstract contract ChainlinkClient {
* @param callbackFunctionSignature function signature to use for the callback
* @return A Chainlink Request struct in memory
*/
function buildOperatorRequest(
function _buildOperatorRequest(
bytes32 specId,
bytes4 callbackFunctionSignature
) internal view returns (Chainlink.Request memory) {
Chainlink.Request memory req;
return req.initialize(specId, address(this), callbackFunctionSignature);
return req._initialize(specId, address(this), callbackFunctionSignature);
}

/**
Expand All @@ -74,8 +75,8 @@ abstract contract ChainlinkClient {
* @param payment The amount of LINK to send for the request
* @return requestId The request ID
*/
function sendChainlinkRequest(Chainlink.Request memory req, uint256 payment) internal returns (bytes32) {
return sendChainlinkRequestTo(address(s_oracle), req, payment);
function _sendChainlinkRequest(Chainlink.Request memory req, uint256 payment) internal returns (bytes32) {
return _sendChainlinkRequestTo(address(s_oracle), req, payment);
}

/**
Expand All @@ -88,7 +89,7 @@ abstract contract ChainlinkClient {
* @param payment The amount of LINK to send for the request
* @return requestId The request ID
*/
function sendChainlinkRequestTo(
function _sendChainlinkRequestTo(
address oracleAddress,
Chainlink.Request memory req,
uint256 payment
Expand Down Expand Up @@ -117,8 +118,8 @@ abstract contract ChainlinkClient {
* @param payment The amount of LINK to send for the request
* @return requestId The request ID
*/
function sendOperatorRequest(Chainlink.Request memory req, uint256 payment) internal returns (bytes32) {
return sendOperatorRequestTo(address(s_oracle), req, payment);
function _sendOperatorRequest(Chainlink.Request memory req, uint256 payment) internal returns (bytes32) {
return _sendOperatorRequestTo(address(s_oracle), req, payment);
}

/**
Expand All @@ -132,7 +133,7 @@ abstract contract ChainlinkClient {
* @param payment The amount of LINK to send for the request
* @return requestId The request ID
*/
function sendOperatorRequestTo(
function _sendOperatorRequestTo(
address oracleAddress,
Chainlink.Request memory req,
uint256 payment
Expand Down Expand Up @@ -182,7 +183,7 @@ abstract contract ChainlinkClient {
* @param callbackFunc The callback function specified for the request
* @param expiration The time of the expiration for the request
*/
function cancelChainlinkRequest(
function _cancelChainlinkRequest(
bytes32 requestId,
uint256 payment,
bytes4 callbackFunc,
Expand All @@ -199,47 +200,47 @@ abstract contract ChainlinkClient {
* @dev starts at 1 in order to ensure consistent gas cost
* @return returns the next request count to be used in a nonce
*/
function getNextRequestCount() internal view returns (uint256) {
function _getNextRequestCount() internal view returns (uint256) {
return s_requestCount;
}

/**
* @notice Sets the stored oracle address
* @param oracleAddress The address of the oracle contract
*/
function setChainlinkOracle(address oracleAddress) internal {
function _setChainlinkOracle(address oracleAddress) internal {
s_oracle = OperatorInterface(oracleAddress);
}

/**
* @notice Sets the LINK token address
* @param linkAddress The address of the LINK token contract
*/
function setChainlinkToken(address linkAddress) internal {
function _setChainlinkToken(address linkAddress) internal {
s_link = LinkTokenInterface(linkAddress);
}

/**
* @notice Sets the Chainlink token address for the public
* network as given by the Pointer contract
*/
function setPublicChainlinkToken() internal {
setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());
function _setPublicChainlinkToken() internal {
_setChainlinkToken(PointerInterface(LINK_TOKEN_POINTER).getAddress());
}

/**
* @notice Retrieves the stored address of the LINK token
* @return The address of the LINK token
*/
function chainlinkTokenAddress() internal view returns (address) {
function _chainlinkTokenAddress() internal view returns (address) {
return address(s_link);
}

/**
* @notice Retrieves the stored address of the oracle contract
* @return The address of the oracle contract
*/
function chainlinkOracleAddress() internal view returns (address) {
function _chainlinkOracleAddress() internal view returns (address) {
return address(s_oracle);
}

Expand All @@ -249,7 +250,10 @@ abstract contract ChainlinkClient {
* @param oracleAddress The address of the oracle contract that will fulfill the request
* @param requestId The request ID used for the response
*/
function addChainlinkExternalRequest(address oracleAddress, bytes32 requestId) internal notPendingRequest(requestId) {
function _addChainlinkExternalRequest(
address oracleAddress,
bytes32 requestId
) internal notPendingRequest(requestId) {
s_pendingRequests[requestId] = oracleAddress;
}

Expand All @@ -259,31 +263,31 @@ abstract contract ChainlinkClient {
* @param ensAddress The address of the ENS contract
* @param node The ENS node hash
*/
function useChainlinkWithENS(address ensAddress, bytes32 node) internal {
function _useChainlinkWithENS(address ensAddress, bytes32 node) internal {
s_ens = ENSInterface(ensAddress);
s_ensNode = node;
bytes32 linkSubnode = keccak256(abi.encodePacked(s_ensNode, ENS_TOKEN_SUBNAME));
ENSResolver_Chainlink resolver = ENSResolver_Chainlink(s_ens.resolver(linkSubnode));
setChainlinkToken(resolver.addr(linkSubnode));
updateChainlinkOracleWithENS();
_setChainlinkToken(resolver.addr(linkSubnode));
_updateChainlinkOracleWithENS();
}

/**
* @notice Sets the stored oracle contract with the address resolved by ENS
* @dev This may be called on its own as long as `useChainlinkWithENS` has been called previously
*/
function updateChainlinkOracleWithENS() internal {
function _updateChainlinkOracleWithENS() internal {
bytes32 oracleSubnode = keccak256(abi.encodePacked(s_ensNode, ENS_ORACLE_SUBNAME));
ENSResolver_Chainlink resolver = ENSResolver_Chainlink(s_ens.resolver(oracleSubnode));
setChainlinkOracle(resolver.addr(oracleSubnode));
_setChainlinkOracle(resolver.addr(oracleSubnode));
}

/**
* @notice Ensures that the fulfillment is valid for this contract
* @dev Use if the contract developer prefers methods instead of modifiers for validation
* @param requestId The request ID for fulfillment
*/
function validateChainlinkCallback(
function _validateChainlinkCallback(
bytes32 requestId
)
internal
Expand Down
Loading

0 comments on commit f21c9c3

Please sign in to comment.