draft-IERC7579.sol 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. */
  48. function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) external returns (uint256);
  49. /**
  50. * @dev Validates a signature using ERC-1271
  51. * @param sender the address that sent the ERC-1271 request to the smart account
  52. * @param hash the hash of the ERC-1271 request
  53. * @param signature the signature of the ERC-1271 request
  54. *
  55. * MUST return the ERC-1271 `MAGIC_VALUE` if the signature is valid
  56. * MUST NOT modify state
  57. */
  58. function isValidSignatureWithSender(
  59. address sender,
  60. bytes32 hash,
  61. bytes calldata signature
  62. ) external view returns (bytes4);
  63. }
  64. /**
  65. * @dev ERC-7579 Hooks module (type 4).
  66. *
  67. * A module that implements logic to execute before and after the account executes a user operation,
  68. * either individually or batched.
  69. */
  70. interface IERC7579Hook is IERC7579Module {
  71. /**
  72. * @dev Called by the smart account before execution
  73. * @param msgSender the address that called the smart account
  74. * @param value the value that was sent to the smart account
  75. * @param msgData the data that was sent to the smart account
  76. *
  77. * MAY return arbitrary data in the `hookData` return value
  78. */
  79. function preCheck(
  80. address msgSender,
  81. uint256 value,
  82. bytes calldata msgData
  83. ) external returns (bytes memory hookData);
  84. /**
  85. * @dev Called by the smart account after execution
  86. * @param hookData the data that was returned by the `preCheck` function
  87. *
  88. * MAY validate the `hookData` to validate transaction context of the `preCheck` function
  89. */
  90. function postCheck(bytes calldata hookData) external;
  91. }
  92. struct Execution {
  93. address target;
  94. uint256 value;
  95. bytes callData;
  96. }
  97. /**
  98. * @dev ERC-7579 Execution.
  99. *
  100. * Accounts should implement this interface so that the Entrypoint and ERC-7579 modules can execute operations.
  101. */
  102. interface IERC7579Execution {
  103. /**
  104. * @dev Executes a transaction on behalf of the account.
  105. * @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
  106. * @param executionCalldata The encoded execution call data
  107. *
  108. * MUST ensure adequate authorization control: e.g. onlyEntryPointOrSelf if used with ERC-4337
  109. * If a mode is requested that is not supported by the Account, it MUST revert
  110. */
  111. function execute(bytes32 mode, bytes calldata executionCalldata) external;
  112. /**
  113. * @dev Executes a transaction on behalf of the account.
  114. * This function is intended to be called by Executor Modules
  115. * @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
  116. * @param executionCalldata The encoded execution call data
  117. *
  118. * MUST ensure adequate authorization control: i.e. onlyExecutorModule
  119. * If a mode is requested that is not supported by the Account, it MUST revert
  120. */
  121. function executeFromExecutor(
  122. bytes32 mode,
  123. bytes calldata executionCalldata
  124. ) external returns (bytes[] memory returnData);
  125. }
  126. /**
  127. * @dev ERC-7579 Account Config.
  128. *
  129. * Accounts should implement this interface to exposes information that identifies the account, supported modules and capabilities.
  130. */
  131. interface IERC7579AccountConfig {
  132. /**
  133. * @dev Returns the account id of the smart account
  134. * @return accountImplementationId the account id of the smart account
  135. *
  136. * MUST return a non-empty string
  137. * The accountId SHOULD be structured like so:
  138. * "vendorname.accountname.semver"
  139. * The id SHOULD be unique across all smart accounts
  140. */
  141. function accountId() external view returns (string memory accountImplementationId);
  142. /**
  143. * @dev Function to check if the account supports a certain execution mode (see above)
  144. * @param encodedMode the encoded mode
  145. *
  146. * MUST return true if the account supports the mode and false otherwise
  147. */
  148. function supportsExecutionMode(bytes32 encodedMode) external view returns (bool);
  149. /**
  150. * @dev Function to check if the account supports a certain module typeId
  151. * @param moduleTypeId the module type ID according to the ERC-7579 spec
  152. *
  153. * MUST return true if the account supports the module type and false otherwise
  154. */
  155. function supportsModule(uint256 moduleTypeId) external view returns (bool);
  156. }
  157. /**
  158. * @dev ERC-7579 Module Config.
  159. *
  160. * Accounts should implement this interface to allows installing and uninstalling modules.
  161. */
  162. interface IERC7579ModuleConfig {
  163. event ModuleInstalled(uint256 moduleTypeId, address module);
  164. event ModuleUninstalled(uint256 moduleTypeId, address module);
  165. /**
  166. * @dev Installs a Module of a certain type on the smart account
  167. * @param moduleTypeId the module type ID according to the ERC-7579 spec
  168. * @param module the module address
  169. * @param initData arbitrary data that may be required on the module during `onInstall`
  170. * initialization.
  171. *
  172. * MUST implement authorization control
  173. * MUST call `onInstall` on the module with the `initData` parameter if provided
  174. * MUST emit ModuleInstalled event
  175. * MUST revert if the module is already installed or the initialization on the module failed
  176. */
  177. function installModule(uint256 moduleTypeId, address module, bytes calldata initData) external;
  178. /**
  179. * @dev Uninstalls a Module of a certain type on the smart account
  180. * @param moduleTypeId the module type ID according the ERC-7579 spec
  181. * @param module the module address
  182. * @param deInitData arbitrary data that may be required on the module during `onInstall`
  183. * initialization.
  184. *
  185. * MUST implement authorization control
  186. * MUST call `onUninstall` on the module with the `deInitData` parameter if provided
  187. * MUST emit ModuleUninstalled event
  188. * MUST revert if the module is not installed or the deInitialization on the module failed
  189. */
  190. function uninstallModule(uint256 moduleTypeId, address module, bytes calldata deInitData) external;
  191. /**
  192. * @dev Returns whether a module is installed on the smart account
  193. * @param moduleTypeId the module type ID according the ERC-7579 spec
  194. * @param module the module address
  195. * @param additionalContext arbitrary data that may be required to determine if the module is installed
  196. *
  197. * MUST return true if the module is installed and false otherwise
  198. */
  199. function isModuleInstalled(
  200. uint256 moduleTypeId,
  201. address module,
  202. bytes calldata additionalContext
  203. ) external view returns (bool);
  204. }