|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.23; |
| 3 | + |
| 4 | +import {IAccount} from "./IAccount.sol"; |
| 5 | +import {UserOperation} from "./UserOperation.sol"; |
| 6 | +import {IUUPSUpgradeable} from "./IUUPSUpgradeable.sol"; |
| 7 | + |
| 8 | +import {IERC1271} from "./IERC1271.sol"; |
| 9 | +import {IMultiOwnable} from "./IMultiOwnable.sol"; |
| 10 | + |
| 11 | +/// @title Coinbase Smart Wallet - extracted interface |
| 12 | +/// |
| 13 | +/// @notice ERC-4337-compatible smart account, based on Solady's ERC4337 account implementation |
| 14 | +/// with inspiration from Alchemy's LightAccount and Daimo's DaimoAccount. |
| 15 | +/// @dev This interface is the conversion of the CoinbaseSmartWallet.sol contract into an interface, |
| 16 | +// with all of its inherited classes converted into interfaces and included in this repo to minimize external dependencies. |
| 17 | +// The original contract was located at https://github.com/coinbase/smart-wallet/blob/6579faa7f7f7a7de75db92f93e92584764ae1aa2/src/CoinbaseSmartWallet.sol |
| 18 | +/// |
| 19 | +/// @author Coinbase (https://github.com/coinbase/smart-wallet) |
| 20 | +/// @author Solady (https://github.com/vectorized/solady/blob/main/src/accounts/ERC4337.sol) |
| 21 | +interface ICoinbaseSmartWallet is IERC1271, IAccount, IMultiOwnable, IUUPSUpgradeable { |
| 22 | + /// @notice A wrapper struct used for signature validation so that callers |
| 23 | + /// can identify the owner that signed. |
| 24 | + struct SignatureWrapper { |
| 25 | + /// @dev The index of the owner that signed, see `MultiOwnable.ownerAtIndex` |
| 26 | + uint256 ownerIndex; |
| 27 | + /// @dev If `MultiOwnable.ownerAtIndex` is an Ethereum address, this should be `abi.encodePacked(r, s, v)` |
| 28 | + /// If `MultiOwnable.ownerAtIndex` is a external key, this should be `abi.encode(WebAuthnAuth)`. |
| 29 | + bytes signatureData; |
| 30 | + } |
| 31 | + |
| 32 | + /// @notice Represents a call to make. |
| 33 | + struct Call { |
| 34 | + /// @dev The address to call. |
| 35 | + address target; |
| 36 | + /// @dev The value to send when making the call. |
| 37 | + uint256 value; |
| 38 | + /// @dev The data of the call. |
| 39 | + bytes data; |
| 40 | + } |
| 41 | + |
| 42 | + /// @notice Thrown when `initialize` is called but the account already has had at least one owner. |
| 43 | + error Initialized(); |
| 44 | + |
| 45 | + /// @notice Thrown when a call is passed to `executeWithoutChainIdValidation` that is not allowed by |
| 46 | + /// `canSkipChainIdValidation` |
| 47 | + /// |
| 48 | + /// @param selector The selector of the call. |
| 49 | + error SelectorNotAllowed(bytes4 selector); |
| 50 | + |
| 51 | + /// @notice Thrown in validateUserOp if the key of `UserOperation.nonce` does not match the calldata. |
| 52 | + /// |
| 53 | + /// @dev Calls to `this.executeWithoutChainIdValidation` MUST use `REPLAYABLE_NONCE_KEY` and |
| 54 | + /// calls NOT to `this.executeWithoutChainIdValidation` MUST NOT use `REPLAYABLE_NONCE_KEY`. |
| 55 | + /// |
| 56 | + /// @param key The invalid `UserOperation.nonce` key. |
| 57 | + error InvalidNonceKey(uint256 key); |
| 58 | + |
| 59 | + /// @notice Initializes the account with the `owners`. |
| 60 | + /// |
| 61 | + /// @dev Reverts if the account has had at least one owner, i.e. has been initialized. |
| 62 | + /// |
| 63 | + /// @param owners Array of initial owners for this account. Each item should be |
| 64 | + /// an ABI encoded Ethereum address, i.e. 32 bytes with 12 leading 0 bytes, |
| 65 | + /// or a 64 byte external key. |
| 66 | + function initialize(bytes[] calldata owners) external payable; |
| 67 | + |
| 68 | + /// @notice Executes `calls` on this account (i.e. self call). |
| 69 | + /// |
| 70 | + /// @dev Can only be called by the Entrypoint. |
| 71 | + /// @dev Reverts if the given call is not authorized to skip the chain ID validtion. |
| 72 | + /// @dev `validateUserOp()` will recompute the `userOpHash` without the chain ID before validating |
| 73 | + /// it if the `UserOperation.calldata` is calling this function. This allows certain UserOperations |
| 74 | + /// to be replayed for all accounts sharing the same address across chains. E.g. This may be |
| 75 | + /// useful for syncing owner changes. |
| 76 | + /// |
| 77 | + /// @param calls An array of calldata to use for separate self calls. |
| 78 | + function executeWithoutChainIdValidation(bytes[] calldata calls) external payable; |
| 79 | + |
| 80 | + /// @notice Executes the given call from this account. |
| 81 | + /// |
| 82 | + /// @dev Can only be called by the Entrypoint or an owner of this account (including itself). |
| 83 | + /// |
| 84 | + /// @param target The address to call. |
| 85 | + /// @param value The value to send with the call. |
| 86 | + /// @param data The data of the call. |
| 87 | + function execute(address target, uint256 value, bytes calldata data) external; |
| 88 | + |
| 89 | + /// @notice Executes batch of `Call`s. |
| 90 | + /// |
| 91 | + /// @dev Can only be called by the Entrypoint or an owner of this account (including itself). |
| 92 | + /// |
| 93 | + /// @param calls The list of `Call`s to execute. |
| 94 | + function executeBatch(Call[] calldata calls) external; |
| 95 | + |
| 96 | + /// @notice Returns the address of the EntryPoint v0.6. |
| 97 | + /// |
| 98 | + /// @return The address of the EntryPoint v0.6 |
| 99 | + function entryPoint() external view returns (address); |
| 100 | + |
| 101 | + /// @notice Computes the hash of the `UserOperation` in the same way as EntryPoint v0.6, but |
| 102 | + /// leaves out the chain ID. |
| 103 | + /// |
| 104 | + /// @dev This allows accounts to sign a hash that can be used on many chains. |
| 105 | + /// |
| 106 | + /// @param userOp The `UserOperation` to compute the hash for. |
| 107 | + /// |
| 108 | + /// @return The `UserOperation` hash, which does not depend on chain ID. |
| 109 | + function getUserOpHashWithoutChainId(UserOperation calldata userOp) external view returns (bytes32); |
| 110 | + |
| 111 | + /// @notice Returns the implementation of the ERC1967 proxy. |
| 112 | + /// |
| 113 | + /// @return $ The address of implementation contract. |
| 114 | + function implementation() external view returns (address $); |
| 115 | + |
| 116 | + /// @notice Returns whether `functionSelector` can be called in `executeWithoutChainIdValidation`. |
| 117 | + /// |
| 118 | + /// @param functionSelector The function selector to check. |
| 119 | + //// |
| 120 | + /// @return `true` is the function selector is allowed to skip the chain ID validation, else `false`. |
| 121 | + function canSkipChainIdValidation(bytes4 functionSelector) external pure returns (bool); |
| 122 | +} |
0 commit comments