draft-IERC7579.sol 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.2.0-rc.0) (interfaces/draft-IERC7579.sol)
  3. pragma solidity ^0.8.20;
  4. import {PackedUserOperation} from "./draft-IERC4337.sol";
  5. uint256 constant VALIDATION_SUCCESS = 0;
  6. uint256 constant VALIDATION_FAILED = 1;
  7. uint256 constant MODULE_TYPE_VALIDATOR = 1;
  8. uint256 constant MODULE_TYPE_EXECUTOR = 2;
  9. uint256 constant MODULE_TYPE_FALLBACK = 3;
  10. uint256 constant MODULE_TYPE_HOOK = 4;
  11. /// @dev Minimal configuration interface for ERC-7579 modules
  12. interface IERC7579Module {
  13. /**
  14. * @dev This function is called by the smart account during installation of the module
  15. * @param data arbitrary data that may be required on the module during `onInstall` initialization
  16. *
  17. * MUST revert on error (e.g. if module is already enabled)
  18. */
  19. function onInstall(bytes calldata data) external;
  20. /**
  21. * @dev This function is called by the smart account during uninstallation of the module
  22. * @param data arbitrary data that may be required on the module during `onUninstall` de-initialization
  23. *
  24. * MUST revert on error
  25. */
  26. function onUninstall(bytes calldata data) external;
  27. /**
  28. * @dev Returns boolean value if module is a certain type
  29. * @param moduleTypeId the module type ID according the ERC-7579 spec
  30. *
  31. * MUST return true if the module is of the given type and false otherwise
  32. */
  33. function isModuleType(uint256 moduleTypeId) external view returns (bool);
  34. }
  35. /**
  36. * @dev ERC-7579 Validation module (type 1).
  37. *
  38. * A module that implements logic to validate user operations and signatures.
  39. */
  40. interface IERC7579Validator is IERC7579Module {
  41. /**
  42. * @dev Validates a UserOperation
  43. * @param userOp the ERC-4337 PackedUserOperation
  44. * @param userOpHash the hash of the ERC-4337 PackedUserOperation
  45. *
  46. * MUST validate that the signature is a valid signature of the userOpHash
  47. * SHOULD return ERC-4337's SIG_VALIDATION_FAILED (and not revert) on signature mismatch
  48. * See {IAccount-validateUserOp} for additional information on the return value
  49. */
  50. function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) external returns (uint256);
  51. /**
  52. * @dev Validates a signature using ERC-1271
  53. * @param sender the address that sent the ERC-1271 request to the smart account
  54. * @param hash the hash of the ERC-1271 request
  55. * @param signature the signature of the ERC-1271 request
  56. *
  57. * MUST return the ERC-1271 `MAGIC_VALUE` if the signature is valid
  58. * MUST NOT modify state
  59. */
  60. function isValidSignatureWithSender(
  61. address sender,
  62. bytes32 hash,
  63. bytes calldata signature
  64. ) external view returns (bytes4);
  65. }
  66. /**
  67. * @dev ERC-7579 Hooks module (type 4).
  68. *
  69. * A module that implements logic to execute before and after the account executes a user operation,
  70. * either individually or batched.
  71. */
  72. interface IERC7579Hook is IERC7579Module {
  73. /**
  74. * @dev Called by the smart account before execution
  75. * @param msgSender the address that called the smart account
  76. * @param value the value that was sent to the smart account
  77. * @param msgData the data that was sent to the smart account
  78. *
  79. * MAY return arbitrary data in the `hookData` return value
  80. */
  81. function preCheck(
  82. address msgSender,
  83. uint256 value,
  84. bytes calldata msgData
  85. ) external returns (bytes memory hookData);
  86. /**
  87. * @dev Called by the smart account after execution
  88. * @param hookData the data that was returned by the `preCheck` function
  89. *
  90. * MAY validate the `hookData` to validate transaction context of the `preCheck` function
  91. */
  92. function postCheck(bytes calldata hookData) external;
  93. }
  94. struct Execution {
  95. address target;
  96. uint256 value;
  97. bytes callData;
  98. }
  99. /**
  100. * @dev ERC-7579 Execution.
  101. *
  102. * Accounts should implement this interface so that the Entrypoint and ERC-7579 modules can execute operations.
  103. */
  104. interface IERC7579Execution {
  105. /**
  106. * @dev Executes a transaction on behalf of the account.
  107. * @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
  108. * @param executionCalldata The encoded execution call data
  109. *
  110. * MUST ensure adequate authorization control: e.g. onlyEntryPointOrSelf if used with ERC-4337
  111. * If a mode is requested that is not supported by the Account, it MUST revert
  112. */
  113. function execute(bytes32 mode, bytes calldata executionCalldata) external;
  114. /**
  115. * @dev Executes a transaction on behalf of the account.
  116. * This function is intended to be called by Executor Modules
  117. * @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
  118. * @param executionCalldata The encoded execution call data
  119. * @return returnData An array with the returned data of each executed subcall
  120. *
  121. * MUST ensure adequate authorization control: i.e. onlyExecutorModule
  122. * If a mode is requested that is not supported by the Account, it MUST revert
  123. */
  124. function executeFromExecutor(
  125. bytes32 mode,
  126. bytes calldata executionCalldata
  127. ) external returns (bytes[] memory returnData);
  128. }
  129. /**
  130. * @dev ERC-7579 Account Config.
  131. *
  132. * Accounts should implement this interface to expose information that identifies the account, supported modules and capabilities.
  133. */
  134. interface IERC7579AccountConfig {
  135. /**
  136. * @dev Returns the account id of the smart account
  137. * @return accountImplementationId the account id of the smart account
  138. *
  139. * MUST return a non-empty string
  140. * The accountId SHOULD be structured like so:
  141. * "vendorname.accountname.semver"
  142. * The id SHOULD be unique across all smart accounts
  143. */
  144. function accountId() external view returns (string memory accountImplementationId);
  145. /**
  146. * @dev Function to check if the account supports a certain execution mode (see above)
  147. * @param encodedMode the encoded mode
  148. *
  149. * MUST return true if the account supports the mode and false otherwise
  150. */
  151. function supportsExecutionMode(bytes32 encodedMode) external view returns (bool);
  152. /**
  153. * @dev Function to check if the account supports a certain module typeId
  154. * @param moduleTypeId the module type ID according to the ERC-7579 spec
  155. *
  156. * MUST return true if the account supports the module type and false otherwise
  157. */
  158. function supportsModule(uint256 moduleTypeId) external view returns (bool);
  159. }
  160. /**
  161. * @dev ERC-7579 Module Config.
  162. *
  163. * Accounts should implement this interface to allow installing and uninstalling modules.
  164. */
  165. interface IERC7579ModuleConfig {
  166. event ModuleInstalled(uint256 moduleTypeId, address module);
  167. event ModuleUninstalled(uint256 moduleTypeId, address module);
  168. /**
  169. * @dev Installs a Module of a certain type on the smart account
  170. * @param moduleTypeId the module type ID according to the ERC-7579 spec
  171. * @param module the module address
  172. * @param initData arbitrary data that may be required on the module during `onInstall`
  173. * initialization.
  174. *
  175. * MUST implement authorization control
  176. * MUST call `onInstall` on the module with the `initData` parameter if provided
  177. * MUST emit ModuleInstalled event
  178. * MUST revert if the module is already installed or the initialization on the module failed
  179. */
  180. function installModule(uint256 moduleTypeId, address module, bytes calldata initData) external;
  181. /**
  182. * @dev Uninstalls a Module of a certain type on the smart account
  183. * @param moduleTypeId the module type ID according the ERC-7579 spec
  184. * @param module the module address
  185. * @param deInitData arbitrary data that may be required on the module during `onInstall`
  186. * initialization.
  187. *
  188. * MUST implement authorization control
  189. * MUST call `onUninstall` on the module with the `deInitData` parameter if provided
  190. * MUST emit ModuleUninstalled event
  191. * MUST revert if the module is not installed or the deInitialization on the module failed
  192. */
  193. function uninstallModule(uint256 moduleTypeId, address module, bytes calldata deInitData) external;
  194. /**
  195. * @dev Returns whether a module is installed on the smart account
  196. * @param moduleTypeId the module type ID according the ERC-7579 spec
  197. * @param module the module address
  198. * @param additionalContext arbitrary data that may be required to determine if the module is installed
  199. *
  200. * MUST return true if the module is installed and false otherwise
  201. */
  202. function isModuleInstalled(
  203. uint256 moduleTypeId,
  204. address module,
  205. bytes calldata additionalContext
  206. ) external view returns (bool);
  207. }