draft-IERC7579.sol 8.5 KB

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