Skip to content

Commit

Permalink
Merge pull request #131 from bcnmy/features/SMA-99-lint-style
Browse files Browse the repository at this point in the history
Features/sma 99 lint style
  • Loading branch information
livingrockrises authored Sep 14, 2023
2 parents daee7f8 + cb19f1d commit 328b8f2
Show file tree
Hide file tree
Showing 47 changed files with 555 additions and 518 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
artifacts
cache
coverage
gasReporterOutput.json
**/typechain/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ jobs:
steps:
- name: Checkout
uses: 'actions/checkout@master'

- name: Set Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Create a fake .secret file
run: echo "primary twist rack vendor diagram image used route theme frown either will" > .secret
- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --frozen-lockfile && yarn build
- name: Lint sources
run:
yarn run lint
yarn run lint

unit_test:
name: Unit tests
Expand All @@ -38,7 +39,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Create a fake .secret file
run: echo "primary twist rack vendor diagram image used route theme frown either will" > .secret
- name: Install dependencies
run: yarn install --frozen-lockfile && yarn build
- name: Run tests
run: yarn test
run: yarn test
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ artifacts
cache
coverage*
gasReporterOutput.json
**/typechain/

16 changes: 11 additions & 5 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,31 @@
"func-name-mixedcase": "error",
"func-param-name-mixedcase": "error",
"modifier-name-mixedcase": "error",
"private-vars-leading-underscore": ["error", { "strict": false }],
"private-vars-leading-underscore": ["off", { "strict": true }],
"use-forbidden-name": "error",
"var-name-mixedcase": "error",
"imports-on-top": "error",
"ordering": "error",
"visibility-modifier-order": "error",
"code-complexity": ["error", 7],
"function-max-lines": ["error", 65],
"function-max-lines": ["error", 80],
"max-line-length": ["warn", 120],
"max-states-count": ["error", 15],
"no-empty-blocks": "error",
"no-unused-vars": "error",
"payable-fallback": "error",
"payable-fallback": "off",
"constructor-syntax": "error",
"explicit-types": "error",
"no-unused-import": "error",
"one-contract-per-file": "error",
"one-contract-per-file": "warn",
"not-rely-on-time": "off",
"reason-string": "error"
"reason-string": "error",
"no-inline-assembly": "off",
"avoid-low-level-calls": "off",
"custom-errors": "off",
"no-complex-fallback": "off",
"no-global-import": "off",
"avoid-tx-origin": "off"
},
"plugins": ["prettier"]
}
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
artifacts
contracts/smart-account/test
contracts/smart-account/libs
19 changes: 7 additions & 12 deletions contracts/smart-account/BaseSmartAccount.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;

/* solhint-disable avoid-low-level-calls */
/* solhint-disable no-inline-assembly */
/* solhint-disable reason-string */

import {IAccount} from "@account-abstraction/contracts/interfaces/IAccount.sol";
import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint.sol";
import {UserOperationLib, UserOperation} from "@account-abstraction/contracts/interfaces/UserOperation.sol";
Expand All @@ -19,17 +15,16 @@ import "@account-abstraction/contracts/core/Helpers.sol";
abstract contract BaseSmartAccount is IAccount, BaseSmartAccountErrors {
using UserOperationLib for UserOperation;

//return value in case of signature failure, with no time-range.
// Return value in case of signature failure, with no time-range.
// equivalent to _packValidationData(true,0,0);
uint256 internal constant SIG_VALIDATION_FAILED = 1;

/**
* @dev Initialize the Smart Account with required states
* @param handler Default fallback handler provided in Smart Account
* @param moduleSetupContract Contract, that setups initial auth module for this smart account. It can be a module factory or
* a registry module that serves several smart accounts.
* @param moduleSetupData data containing address of the Setup Contract and a setup data
* @notice devs need to make sure it is only callable once (use initializer modifier or state check restrictions)
* @dev Initialize the Smart Account with required states.
* @param handler Default fallback handler for the Smart Account.
* @param moduleSetupContract Initializes the auth module; can be a factory or registry for multiple accounts.
* @param moduleSetupData Contains address of the Setup Contract and setup data.
* @notice Ensure this is callable only once (use initializer modifier or state checks).
*/
function init(
address handler,
Expand All @@ -48,7 +43,7 @@ abstract contract BaseSmartAccount is IAccount, BaseSmartAccountErrors {
* otherwise, an address of an "authorizer" contract.
* <6-byte> validUntil - last timestamp this operation is valid. 0 for "indefinite"
* <6-byte> validAfter - first timestamp this operation is valid
* If the account doesn't use time-range, it is enough to return SIG_VALIDATION_FAILED value (1) for signature failure.
* If no time-range in account, return SIG_VALIDATION_FAILED (1) for signature failure.
* Note that the validation code cannot use block.timestamp (or block.number) directly.
*/
function validateUserOp(
Expand Down
16 changes: 10 additions & 6 deletions contracts/smart-account/SmartAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ contract SmartAccount is
mapping(uint256 => uint256) public noncesDeprecated;

// AA immutable storage
IEntryPoint private immutable _entryPoint;
address private immutable _self;
IEntryPoint private immutable ENTRY_POINT;
address private immutable SELF;

// Events
event ImplementationUpdated(
Expand All @@ -63,10 +63,10 @@ contract SmartAccount is
* @param anEntryPoint The address of the entry point contract.
*/
constructor(IEntryPoint anEntryPoint) {
_self = address(this);
SELF = address(this);
if (address(anEntryPoint) == address(0))
revert EntryPointCannotBeZero();
_entryPoint = anEntryPoint;
ENTRY_POINT = anEntryPoint;
_modules[SENTINEL_MODULES] = SENTINEL_MODULES;
}

Expand All @@ -77,7 +77,7 @@ contract SmartAccount is
* sources and accepts Ether as payment.
*/
receive() external payable {
if (address(this) == _self) revert DelegateCallsOnly();
if (address(this) == SELF) revert DelegateCallsOnly();
emit SmartAccountReceivedNativeToken(msg.sender, msg.value);
}

Expand Down Expand Up @@ -233,6 +233,8 @@ contract SmartAccount is
emit ImplementationUpdated(oldImplementation, _implementation);
}

/* solhint-disable func-name-mixedcase */

/**
* @dev Execute a transaction (called by entryPoint)
* @notice Name is optimized for this method to be cheaper to be called
Expand Down Expand Up @@ -275,6 +277,8 @@ contract SmartAccount is
}
}

/* solhint-enable func-name-mixedcase */

/**
* @dev Deposit more funds for this account in the entryPoint
*/
Expand Down Expand Up @@ -313,7 +317,7 @@ contract SmartAccount is
* @dev This function should be implemented by the subclass to return the current entry point used by this account.
*/
function entryPoint() public view virtual override returns (IEntryPoint) {
return _entryPoint;
return ENTRY_POINT;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/smart-account/base/Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract Executor {
uint256 txGas
);

function execute(
function _execute(
address to,
uint256 value,
bytes memory data,
Expand Down
15 changes: 7 additions & 8 deletions contracts/smart-account/base/FallbackManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ abstract contract FallbackManager is SelfAuthorized, FallbackManagerErrors {
bytes32 internal constant FALLBACK_HANDLER_STORAGE_SLOT =
0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d4;

uint256[24] private __gap;

event ChangedFallbackHandler(
address indexed previousHandler,
address indexed handler
);

// solhint-disable-next-line payable-fallback,no-complex-fallback
fallback() external {
bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;

Expand Down Expand Up @@ -50,17 +51,17 @@ abstract contract FallbackManager is SelfAuthorized, FallbackManagerErrors {
}
}

/// @dev Allows to add a contract to handle fallback calls.
/// Only fallback calls without value and with data will be forwarded
/// @param handler contract to handle fallback calls.
function setFallbackHandler(address handler) external virtual;

function getFallbackHandler() public view returns (address _handler) {
assembly {
_handler := sload(FALLBACK_HANDLER_STORAGE_SLOT)
}
}

/// @dev Allows to add a contract to handle fallback calls.
/// Only fallback calls without value and with data will be forwarded
/// @param handler contract to handle fallback calls.
function setFallbackHandler(address handler) external virtual;

function _setFallbackHandler(address handler) internal {
if (handler == address(0)) revert HandlerCannotBeZero();
address previousHandler;
Expand All @@ -75,6 +76,4 @@ abstract contract FallbackManager is SelfAuthorized, FallbackManagerErrors {
}
emit ChangedFallbackHandler(previousHandler, handler);
}

uint256[24] private __gap;
}
7 changes: 3 additions & 4 deletions contracts/smart-account/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract contract ModuleManager is
) revert ModuleNotEnabled(msg.sender);
// Execute transaction without further confirmations.
// Can add guards here to allow delegatecalls for selected modules (msg.senders) only
success = execute(
success = _execute(
to,
value,
data,
Expand Down Expand Up @@ -266,7 +266,7 @@ abstract contract ModuleManager is
bytes memory data,
Enum.Operation operation
) internal returns (bool success) {
success = execute(to, value, data, operation, gasleft());
success = _execute(to, value, data, operation, gasleft());
if (success) {
emit ModuleTransaction(msg.sender, to, value, data, operation);
emit ExecutionFromModuleSuccess(msg.sender);
Expand All @@ -275,8 +275,7 @@ abstract contract ModuleManager is

/**
* @notice Setup function sets the initial storage of the contract.
* @param setupContract Contract, that setups initial auth module for this smart account. It can be a module factory or
* a registry module that serves several smart accounts
* @param setupContract initializing the auth module; can be a module factory or a registry for multiple accounts.
* @param setupData modules setup data (a standard calldata for the module setup contract)
*/
function _initialSetupModules(
Expand Down
10 changes: 5 additions & 5 deletions contracts/smart-account/common/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ pragma solidity 0.8.17;

/// @title Reentrancy Guard - reentrancy protection
abstract contract ReentrancyGuard {
error ReentrancyProtectionActivated();

uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;

uint256 private _reentrancyStatus;

constructor() {
_reentrancyStatus = NOT_ENTERED;
}
error ReentrancyProtectionActivated();

modifier nonReentrant() {
if (_reentrancyStatus == ENTERED)
Expand All @@ -22,6 +18,10 @@ abstract contract ReentrancyGuard {
_reentrancyStatus = NOT_ENTERED;
}

constructor() {
_reentrancyStatus = NOT_ENTERED;
}

function _isReentrancyGuardEntered() internal view returns (bool) {
return _reentrancyStatus == ENTERED;
}
Expand Down
22 changes: 12 additions & 10 deletions contracts/smart-account/deployer/Create3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pragma solidity 0.8.17;
library Create3 {
/**
@notice The bytecode for a contract that proxies the creation of another contract
@dev If this code is deployed using CREATE2 it can be used to decouple `creationCode` from the child contract address
@dev If deployed via CREATE2, decouple creationCode from child contract address.
0x67363d3d37363d34f03d5260086018f3:
0x00 0x67 0x67XXXXXXXXXXXXXXXX PUSH8 bytecode 0x363d3d37363d34f0
0x01 0x3d 0x3d RETURNDATASIZE 0 0x363d3d37363d34f0
Expand Down Expand Up @@ -43,7 +43,7 @@ library Create3 {
/**
@notice Creates a new contract with given `_creationCode` and `_salt`
@param _salt Salt of the contract creation, resulting address will be derivated from this value only
@param _creationCode Creation code (constructor) of the contract to be deployed, this value doesn't affect the resulting address
@param _creationCode Constructor code for contract to be deployed; it doesn't affect the resulting address.
@return addr of the deployed contract, reverts on error
*/
function create3(
Expand All @@ -56,7 +56,7 @@ library Create3 {
/**
@notice Creates a new contract with given `_creationCode` and `_salt`
@param _salt Salt of the contract creation, resulting address will be derivated from this value only
@param _creationCode Creation code (constructor) of the contract to be deployed, this value doesn't affect the resulting address
@param _creationCode Constructor code for contract to be deployed; it doesn't affect the resulting address.
@param _value In WEI of ETH to be forwarded to child contract
@return addr of the deployed contract, reverts on error
*/
Expand Down Expand Up @@ -108,12 +108,14 @@ library Create3 {
}

/**
@notice Computes the resulting address of a contract deployed using address(this) and the given `_salt`
@param _salt Salt of the contract creation, resulting address will be derivated from this value only
@return addr of the deployed contract, reverts on error
@dev The address creation formula is: keccak256(rlp([keccak256(0xff ++ address(this) ++ _salt ++ keccak256(childBytecode))[12:], 0x01]))
*/
* @notice Computes the resulting address of a contract deployed using address(this) and the given `_salt`
*
* @dev Address creation formula:
* keccak256(rlp([keccak256(0xff+address(this)+_salt+keccak256(childBytecode))[12:],0x01]))
*
* @param _salt Salt of the contract creation, resulting address will be derived from this value only
* @return addr of the deployed contract, reverts on error
*/
function addressOf(bytes32 _salt) internal view returns (address) {
address proxy = addressOfProxy(_salt);
return
Expand Down
Loading

0 comments on commit 328b8f2

Please sign in to comment.