Skip to content

Commit

Permalink
Merge branch 'master' into SVM-EM-playground
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Sep 22, 2023
2 parents 8125f72 + 3bf128e commit 942e51a
Show file tree
Hide file tree
Showing 55 changed files with 33,788 additions and 3,178 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ BSCSCAN_API_KEY=
OPTIMISTIC_API_KEY=
AVALANCHE_API_KEY=
ARBITRUM_API_KEY=
BASE_API_KEY=
ARBITRUM_NOVA_API_KEY=
BASE_GOERLI_API_KEY=
BASE_MAINNET_API_KEY=
LINEA_API_KEY=
ZKEVM_API_KEY=
MOONBEAM_KEY=
# Generate on https://dashboard.nodereal.io/
Expand Down
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
64 changes: 64 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Contributing to Biconomy Projects 🚀

First off, thank you for considering contributing to Biconomy! We truly appreciate your effort and contributions from the community are what make Biconomy awesome. 🙌

Your contributions are valued and will help in driving the decentralized web forward.

> If you're passionate about our mission but can't contribute directly, there are other ways to support:
> - ⭐ Star our projects on GitHub
> - 🐦 [Tweet about Biconomy](https://twitter.com/biconomy/)
> - 📌 Reference Biconomy in your project's readme
> - 🗣️ Share about Biconomy at meetups or with peers
## Table of Contents

- [Contributing to Biconomy Projects 🚀](#contributing-to-biconomy-projects-)
- [Table of Contents](#table-of-contents)
- [Have a Question?](#have-a-question)
- [Ready to Contribute?](#ready-to-contribute)
- [Legal Notice 📜](#legal-notice-)
- [Reporting Bugs 🐛](#reporting-bugs-)
- [Suggesting Enhancements 💡](#suggesting-enhancements-)
- [First Time Contributing? 🌱](#first-time-contributing-)
- [Improving Documentation 📚](#improving-documentation-)
- [Commit Messages 📝](#commit-messages-)
- [Join Biconomy's Team! 🚀](#join-biconomys-team-)

## Have a Question?

Before reaching out, please ensure you've gone through our [Documentation](https://docs.biconomy.io/). If you still have questions:

1. Search for existing [Issues](https://github.com/bcnmy/scw-contracts/issues) that might answer your question.
2. Check out our [Forum](https://forum.biconomy.io/).
3. Join our [Discord](https://discord.com/invite/biconomy) or [Telegram](https://t.me/biconomy) communities.

If you still need assistance, feel free to open an [Issue](https://github.com/bcnmy/scw-contracts/issues/new) with your question.

## Ready to Contribute?

### Legal Notice 📜
By contributing, you agree that you've authored your contribution and that it can be provided under the project's license.

### Reporting Bugs 🐛

Before submitting a bug report, ensure you're using the latest version and that you've read our [documentation](https://docs.biconomy.io/). If you've identified a bug that hasn't been reported, open a new [Issue](https://github.com/bcnmy/scw-contracts/issues/new) detailing the bug.

### Suggesting Enhancements 💡

Have a feature in mind? First, ensure it aligns with Biconomy's mission and hasn't been suggested before. Then, open an [Issue](https://github.com/bcnmy/scw-contracts/issues/new) to discuss your enhancement.

### First Time Contributing? 🌱

Welcome! We're thrilled to have you. If you're unsure where to start, look for issues labeled `good first issue`.

### Improving Documentation 📚

Good documentation is key! If you spot areas for improvement or errors in our documentation, we'd love your input. If you wish to suggest changes, feel free to raise a PR on our [documentation repository](https://github.com/bcnmy/docs).

### Commit Messages 📝

Ensure your commit messages are clear and descriptive.

## Join Biconomy's Team! 🚀

Interested in joining our mission full-time? Check out our [current job openings](https://jobs.lever.co/biconomy).
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
Loading

0 comments on commit 942e51a

Please sign in to comment.