Skip to content

Commit

Permalink
Merge pull request #141 from bcnmy/fixes/sma-153-150-refactor
Browse files Browse the repository at this point in the history
SMA-153,SMA-150: Refactor
  • Loading branch information
ankurdubey521 authored Oct 10, 2023
2 parents aca3977 + c163b24 commit 2cd521a
Show file tree
Hide file tree
Showing 82 changed files with 1,216 additions and 2,629 deletions.
45 changes: 10 additions & 35 deletions contracts/smart-account/BaseSmartAccount.sol
Original file line number Diff line number Diff line change
@@ -1,70 +1,45 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;

import {IAccount} from "@account-abstraction/contracts/interfaces/IAccount.sol";
import {IBaseSmartAccount} from "./interfaces/IBaseSmartAccount.sol";
import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint.sol";
import {UserOperationLib, UserOperation} from "@account-abstraction/contracts/interfaces/UserOperation.sol";
import {BaseSmartAccountErrors} from "./common/Errors.sol";
import "@account-abstraction/contracts/core/Helpers.sol";

/**
* Basic account implementation.
* This contract provides the basic logic for implementing the IAccount interface: validateUserOp function
* Specific account implementation should inherit it and provide the account-specific logic
*/
abstract contract BaseSmartAccount is IAccount, BaseSmartAccountErrors {
abstract contract BaseSmartAccount is IBaseSmartAccount {
using UserOperationLib for UserOperation;

// 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 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).
*/
/// @inheritdoc IBaseSmartAccount
function init(
address handler,
address moduleSetupContract,
bytes calldata moduleSetupData
) external virtual returns (address);
) external virtual override returns (address);

/**
* Validates the userOp.
* @param userOp validate the userOp.signature field
* @param userOpHash convenient field: the hash of the request, to check the signature against
* (also hashes the entrypoint and chain id)
* @param missingAccountFunds the amount of funds required to pay to EntryPoint to pay for the userOp execution.
* @return validationData signature and time-range of this operation
* <20-byte> sigAuthorizer - 0 for valid signature, 1 to mark signature failure,
* 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 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.
*/
/// @inheritdoc IBaseSmartAccount
function validateUserOp(
UserOperation calldata userOp,
bytes32 userOpHash,
uint256 missingAccountFunds
) external virtual override returns (uint256);

/**
* @return nonce the account nonce.
* @dev This method returns the next sequential nonce.
* @notice Provides 2D nonce functionality by allowing to use a nonce of a specific key.
*/
function nonce(uint192 _key) public view virtual returns (uint256) {
/// @inheritdoc IBaseSmartAccount
function nonce(
uint192 _key
) public view virtual override returns (uint256) {
return entryPoint().getNonce(address(this), _key);
}

/**
* return the entryPoint used by this account.
* subclass should return the current entryPoint used by this account.
*/
/// @inheritdoc IBaseSmartAccount
function entryPoint() public view virtual returns (IEntryPoint);

/**
Expand Down
Loading

0 comments on commit 2cd521a

Please sign in to comment.