Skip to content

Commit

Permalink
function ordering + solhint for 0.8 (#10980)
Browse files Browse the repository at this point in the history
* function ordering

* indent

* disable cache temporarly

* indent fix

* indent fix 2

* add solhint version

* force cache rebuild
  • Loading branch information
pahor167 authored Apr 23, 2024
1 parent 7fae8ec commit da9b495
Show file tree
Hide file tree
Showing 84 changed files with 5,539 additions and 5,511 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = {
},
],
'import/no-internal-modules': 'off',
indent: 'off',
indent: ['off', 2],
'linebreak-style': 'off',
'max-classes-per-file': ['error', 1],
'max-len': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/celo-monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defaults:

env:
# Increment these to force cache rebuilding
NODE_MODULE_CACHE_VERSION: 5
NODE_MODULE_CACHE_VERSION: 6
NODE_OPTIONS: '--max-old-space-size=4096'
TERM: dumb
GRADLE_OPTS: '-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.configureondemand=true -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"'
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
rules: {
'import/no-extraneous-dependencies': 'off',
'no-underscore-dangle': 'off',
indent: ['off', 2],
},
}
7 changes: 3 additions & 4 deletions packages/protocol/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "solhint:default",
"rules": {
"compiler-fixed": false,
"function-max-lines": 70,
"indent": "off",
"max-line-length": "off"
"function-max-lines": "off",
"max-line-length": "off",
"ordering": "error"
}
}
190 changes: 95 additions & 95 deletions packages/protocol/contracts-0.8/common/GasPriceMinimum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ contract GasPriceMinimum is
{
using FixidityLib for FixidityLib.Fraction;

event TargetDensitySet(uint256 targetDensity);
event GasPriceMinimumFloorSet(uint256 gasPriceMinimumFloor);
event AdjustmentSpeedSet(uint256 adjustmentSpeed);
event GasPriceMinimumUpdated(uint256 gasPriceMinimum);
event BaseFeeOpCodeActivationBlockSet(uint256 baseFeeOpCodeActivationBlock);

uint256 public deprecated_gasPriceMinimum;
uint256 public gasPriceMinimumFloor;

Expand All @@ -41,23 +35,18 @@ contract GasPriceMinimum is
uint256 public baseFeeOpCodeActivationBlock;
uint256 public constant ABSOLUTE_MINIMAL_GAS_PRICE = 1;

event TargetDensitySet(uint256 targetDensity);
event GasPriceMinimumFloorSet(uint256 gasPriceMinimumFloor);
event AdjustmentSpeedSet(uint256 adjustmentSpeed);
event GasPriceMinimumUpdated(uint256 gasPriceMinimum);
event BaseFeeOpCodeActivationBlockSet(uint256 baseFeeOpCodeActivationBlock);

/**
* @notice Sets initialized == true on implementation contracts
* @param test Set to true to skip implementation initialization
*/
constructor(bool test) public Initializable(test) {}

/**
* @notice Returns the storage, major, minor, and patch version of the contract.
* @return Storage version of the contract.
* @return Major version of the contract.
* @return Minor version of the contract.
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 2, 0, 1);
}

/**
* @notice Used in place of the constructor to allow the contract to be upgradable via proxy.
* @param _registryAddress The address of the registry core smart contract.
Expand All @@ -82,6 +71,60 @@ contract GasPriceMinimum is
_setBaseFeeOpCodeActivationBlock(_baseFeeOpCodeActivationBlock, true);
}

/**
* @notice Set the activation block of the baseFee opCode.
* @param _baseFeeOpCodeActivationBlock Block number where the baseFee opCode is activated
* @dev Value is expected to be > 0.
*/
function setBaseFeeOpCodeActivationBlock(uint256 _baseFeeOpCodeActivationBlock)
external
onlyOwner
{
_setBaseFeeOpCodeActivationBlock(_baseFeeOpCodeActivationBlock, false);
}

/**
* @notice Adjust the gas price minimum based on governable parameters
* and block congestion.
* @param blockGasTotal The amount of gas in the most recent block.
* @param blockGasLimit The maxBlockGasLimit of the past block.
* @return result of the calculation (new gas price minimum)
*/
function updateGasPriceMinimum(uint256 blockGasTotal, uint256 blockGasLimit)
external
onlyVm
returns (uint256)
{
deprecated_gasPriceMinimum = getUpdatedGasPriceMinimum(blockGasTotal, blockGasLimit);
emit GasPriceMinimumUpdated(deprecated_gasPriceMinimum);
return deprecated_gasPriceMinimum;
}

/**
* @notice Retrieve the current gas price minimum for a currency.
* When caled for 0x0 or Celo address, it returns gasPriceMinimum().
* For other addresses it returns gasPriceMinimum() mutiplied by
* the SortedOracles median of the token. It does not check tokenAddress is a valid fee currency.
* this function will never returns values less than ABSOLUTE_MINIMAL_GAS_PRICE.
* If Oracle rate doesn't exist, it returns ABSOLUTE_MINIMAL_GAS_PRICE.
* @dev This functions assumes one unit of token has 18 digits.
* @param tokenAddress The currency the gas price should be in (defaults to Celo).
* @return current gas price minimum in the requested currency
*/
function getGasPriceMinimum(address tokenAddress) external view returns (uint256) {
return Math.max(_getGasPriceMinimum(tokenAddress), ABSOLUTE_MINIMAL_GAS_PRICE);
}
/**
* @notice Returns the storage, major, minor, and patch version of the contract.
* @return Storage version of the contract.
* @return Major version of the contract.
* @return Minor version of the contract.
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 2, 0, 1);
}

/**
* @notice Set a multiplier that impacts how quickly gas price minimum is adjusted.
* @param _adjustmentSpeed How quickly the minimum changes, expressed as a fixidity fraction.
Expand Down Expand Up @@ -115,35 +158,6 @@ contract GasPriceMinimum is
emit GasPriceMinimumFloorSet(_gasPriceMinimumFloor);
}

/**
* @notice Set the activation block of the baseFee opCode.
* @param _baseFeeOpCodeActivationBlock Block number where the baseFee opCode is activated
* @dev Value is expected to be > 0.
*/
function setBaseFeeOpCodeActivationBlock(uint256 _baseFeeOpCodeActivationBlock)
external
onlyOwner
{
_setBaseFeeOpCodeActivationBlock(_baseFeeOpCodeActivationBlock, false);
}

/**
* @notice Set the activation block of the baseFee opCode.
* @param _baseFeeOpCodeActivationBlock Block number where the baseFee opCode is activated
* @dev Value is expected to be > 0.
*/
function _setBaseFeeOpCodeActivationBlock(uint256 _baseFeeOpCodeActivationBlock, bool allowZero)
private
onlyOwner
{
require(
allowZero || _baseFeeOpCodeActivationBlock > 0,
"baseFee opCode activation block must be greater than zero"
);
baseFeeOpCodeActivationBlock = _baseFeeOpCodeActivationBlock;
emit BaseFeeOpCodeActivationBlockSet(_baseFeeOpCodeActivationBlock);
}

function gasPriceMinimum() public view returns (uint256) {
if (baseFeeOpCodeActivationBlock > 0 && block.number >= baseFeeOpCodeActivationBlock) {
return block.basefee;
Expand All @@ -152,55 +166,6 @@ contract GasPriceMinimum is
}
}

function _getGasPriceMinimum(address tokenAddress) private view returns (uint256) {
if (
tokenAddress == address(0) ||
tokenAddress == registry.getAddressForOrDie(GOLD_TOKEN_REGISTRY_ID)
) {
return gasPriceMinimum();
} else {
ISortedOracles sortedOracles = ISortedOracles(
registry.getAddressForOrDie(SORTED_ORACLES_REGISTRY_ID)
);
uint256 rateNumerator;
uint256 rateDenominator;
(rateNumerator, rateDenominator) = sortedOracles.medianRate(tokenAddress);
return ((gasPriceMinimum() * rateNumerator) / rateDenominator);
}
}

/**
* @notice Retrieve the current gas price minimum for a currency.
* When caled for 0x0 or Celo address, it returns gasPriceMinimum().
* For other addresses it returns gasPriceMinimum() mutiplied by
* the SortedOracles median of the token. It does not check tokenAddress is a valid fee currency.
* this function will never returns values less than ABSOLUTE_MINIMAL_GAS_PRICE.
* If Oracle rate doesn't exist, it returns ABSOLUTE_MINIMAL_GAS_PRICE.
* @dev This functions assumes one unit of token has 18 digits.
* @param tokenAddress The currency the gas price should be in (defaults to Celo).
* @return current gas price minimum in the requested currency
*/
function getGasPriceMinimum(address tokenAddress) external view returns (uint256) {
return Math.max(_getGasPriceMinimum(tokenAddress), ABSOLUTE_MINIMAL_GAS_PRICE);
}

/**
* @notice Adjust the gas price minimum based on governable parameters
* and block congestion.
* @param blockGasTotal The amount of gas in the most recent block.
* @param blockGasLimit The maxBlockGasLimit of the past block.
* @return result of the calculation (new gas price minimum)
*/
function updateGasPriceMinimum(uint256 blockGasTotal, uint256 blockGasLimit)
external
onlyVm
returns (uint256)
{
deprecated_gasPriceMinimum = getUpdatedGasPriceMinimum(blockGasTotal, blockGasLimit);
emit GasPriceMinimumUpdated(deprecated_gasPriceMinimum);
return deprecated_gasPriceMinimum;
}

/**
* @notice Calculates the gas price minimum based on governable parameters
* and block congestion.
Expand Down Expand Up @@ -234,4 +199,39 @@ contract GasPriceMinimum is

return newGasPriceMinimum >= gasPriceMinimumFloor ? newGasPriceMinimum : gasPriceMinimumFloor;
}

/**
* @notice Set the activation block of the baseFee opCode.
* @param _baseFeeOpCodeActivationBlock Block number where the baseFee opCode is activated
* @dev Value is expected to be > 0.
*/
function _setBaseFeeOpCodeActivationBlock(uint256 _baseFeeOpCodeActivationBlock, bool allowZero)
private
onlyOwner
{
require(
allowZero || _baseFeeOpCodeActivationBlock > 0,
"baseFee opCode activation block must be greater than zero"
);
baseFeeOpCodeActivationBlock = _baseFeeOpCodeActivationBlock;
emit BaseFeeOpCodeActivationBlockSet(_baseFeeOpCodeActivationBlock);
}

function _getGasPriceMinimum(address tokenAddress) private view returns (uint256) {
if (
tokenAddress == address(0) ||
tokenAddress == registry.getAddressForOrDie(GOLD_TOKEN_REGISTRY_ID)
) {
return gasPriceMinimum();
} else {
ISortedOracles sortedOracles = ISortedOracles(
registry.getAddressForOrDie(SORTED_ORACLES_REGISTRY_ID)
);
uint256 rateNumerator;
uint256 rateDenominator;
(rateNumerator, rateDenominator) = sortedOracles.medianRate(tokenAddress);
return ((gasPriceMinimum() * rateNumerator) / rateDenominator);
}
}

}
4 changes: 2 additions & 2 deletions packages/protocol/contracts-0.8/common/UsingRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import "@openzeppelin/contracts8/token/ERC20/IERC20.sol";
import "../../contracts/common/interfaces/IRegistry.sol";

contract UsingRegistry is Ownable {
event RegistrySet(address indexed registryAddress);

// solhint-disable state-visibility
bytes32 constant ACCOUNTS_REGISTRY_ID = keccak256(abi.encodePacked("Accounts"));
bytes32 constant ATTESTATIONS_REGISTRY_ID = keccak256(abi.encodePacked("Attestations"));
Expand Down Expand Up @@ -40,6 +38,8 @@ contract UsingRegistry is Ownable {

IRegistry public registry;

event RegistrySet(address indexed registryAddress);

modifier onlyRegisteredContract(bytes32 identifierHash) {
require(registry.getAddressForOrDie(identifierHash) == msg.sender, "only registered contract");
_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ contract FeeCurrencyAdapter is Initializable, CalledByVm, IFeeCurrencyAdapter {
return expectedDecimals;
}

function _setAdaptedToken(address _adaptedToken) internal virtual {
adaptedToken = IFeeCurrency(_adaptedToken);
}

function upscale(uint256 value) internal view returns (uint256) {
return value * digitDifference;
}
Expand All @@ -175,8 +179,4 @@ contract FeeCurrencyAdapter is Initializable, CalledByVm, IFeeCurrencyAdapter {
function downscale(uint256 value) internal view returns (uint256) {
return (value + digitDifference - 1) / digitDifference;
}

function _setAdaptedToken(address _adaptedToken) internal virtual {
adaptedToken = IFeeCurrency(_adaptedToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
pragma solidity >=0.8.7 <0.8.20;

interface IFeeCurrencyAdapter {
/**
* @notice Same as debitGasFees in IFeeCurrency, always using the number of decimals the evm expects.
*/
function debitGasFees(address from, uint256 value) external;

/**
* @notice Same as creditGasFees in IFeeCurrency, always using the number of decimals the evm expects.
*/
function creditGasFees(
address refundRecipient,
address tipRecipient,
address _gatewayFeeRecipient,
address baseFeeRecipient,
uint256 refundAmount,
uint256 tipAmount,
uint256 _gatewayFeeAmount,
uint256 baseFeeAmount
) external;

/**
* @return The address of the adapted token.
*/
Expand Down Expand Up @@ -36,23 +55,4 @@ interface IFeeCurrencyAdapter {
* @return Same as decimals.
*/
function expectedDecimals() external view returns (uint8);

/**
* @notice Same as debitGasFees in IFeeCurrency, always using the number of decimals the evm expects.
*/
function debitGasFees(address from, uint256 value) external;

/**
* @notice Same as creditGasFees in IFeeCurrency, always using the number of decimals the evm expects.
*/
function creditGasFees(
address refundRecipient,
address tipRecipient,
address _gatewayFeeRecipient,
address baseFeeRecipient,
uint256 refundAmount,
uint256 tipAmount,
uint256 _gatewayFeeAmount,
uint256 baseFeeAmount
) external;
}
Loading

0 comments on commit da9b495

Please sign in to comment.