draft-IERC7579.sol 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. interface IERC7579Module {
  11. /**
  12. * @dev This function is called by the smart account during installation of the module
  13. * @param data arbitrary data that may be required on the module during `onInstall` initialization
  14. *
  15. * MUST revert on error (e.g. if module is already enabled)
  16. */
  17. function onInstall(bytes calldata data) external;
  18. /**
  19. * @dev This function is called by the smart account during uninstallation of the module
  20. * @param data arbitrary data that may be required on the module during `onUninstall` de-initialization
  21. *
  22. * MUST revert on error
  23. */
  24. function onUninstall(bytes calldata data) external;
  25. /**
  26. * @dev Returns boolean value if module is a certain type
  27. * @param moduleTypeId the module type ID according the ERC-7579 spec
  28. *
  29. * MUST return true if the module is of the given type and false otherwise
  30. */
  31. function isModuleType(uint256 moduleTypeId) external view returns (bool);
  32. }
  33. interface IERC7579Validator is IERC7579Module {
  34. /**
  35. * @dev Validates a UserOperation
  36. * @param userOp the ERC-4337 PackedUserOperation
  37. * @param userOpHash the hash of the ERC-4337 PackedUserOperation
  38. *
  39. * MUST validate that the signature is a valid signature of the userOpHash
  40. * SHOULD return ERC-4337's SIG_VALIDATION_FAILED (and not revert) on signature mismatch
  41. */
  42. function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) external returns (uint256);
  43. /**
  44. * @dev Validates a signature using ERC-1271
  45. * @param sender the address that sent the ERC-1271 request to the smart account
  46. * @param hash the hash of the ERC-1271 request
  47. * @param signature the signature of the ERC-1271 request
  48. *
  49. * MUST return the ERC-1271 `MAGIC_VALUE` if the signature is valid
  50. * MUST NOT modify state
  51. */
  52. function isValidSignatureWithSender(
  53. address sender,
  54. bytes32 hash,
  55. bytes calldata signature
  56. ) external view returns (bytes4);
  57. }
  58. interface IERC7579Hook is IERC7579Module {
  59. /**
  60. * @dev Called by the smart account before execution
  61. * @param msgSender the address that called the smart account
  62. * @param value the value that was sent to the smart account
  63. * @param msgData the data that was sent to the smart account
  64. *
  65. * MAY return arbitrary data in the `hookData` return value
  66. */
  67. function preCheck(
  68. address msgSender,
  69. uint256 value,
  70. bytes calldata msgData
  71. ) external returns (bytes memory hookData);
  72. /**
  73. * @dev Called by the smart account after execution
  74. * @param hookData the data that was returned by the `preCheck` function
  75. *
  76. * MAY validate the `hookData` to validate transaction context of the `preCheck` function
  77. */
  78. function postCheck(bytes calldata hookData) external;
  79. }
  80. struct Execution {
  81. address target;
  82. uint256 value;
  83. bytes callData;
  84. }
  85. interface IERC7579Execution {
  86. /**
  87. * @dev Executes a transaction on behalf of the account.
  88. * @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
  89. * @param executionCalldata The encoded execution call data
  90. *
  91. * MUST ensure adequate authorization control: e.g. onlyEntryPointOrSelf if used with ERC-4337
  92. * If a mode is requested that is not supported by the Account, it MUST revert
  93. */
  94. function execute(bytes32 mode, bytes calldata executionCalldata) external;
  95. /**
  96. * @dev Executes a transaction on behalf of the account.
  97. * This function is intended to be called by Executor Modules
  98. * @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
  99. * @param executionCalldata The encoded execution call data
  100. *
  101. * MUST ensure adequate authorization control: i.e. onlyExecutorModule
  102. * If a mode is requested that is not supported by the Account, it MUST revert
  103. */
  104. function executeFromExecutor(
  105. bytes32 mode,
  106. bytes calldata executionCalldata
  107. ) external returns (bytes[] memory returnData);
  108. }
  109. interface IERC7579AccountConfig {
  110. /**
  111. * @dev Returns the account id of the smart account
  112. * @return accountImplementationId the account id of the smart account
  113. *
  114. * MUST return a non-empty string
  115. * The accountId SHOULD be structured like so:
  116. * "vendorname.accountname.semver"
  117. * The id SHOULD be unique across all smart accounts
  118. */
  119. function accountId() external view returns (string memory accountImplementationId);
  120. /**
  121. * @dev Function to check if the account supports a certain execution mode (see above)
  122. * @param encodedMode the encoded mode
  123. *
  124. * MUST return true if the account supports the mode and false otherwise
  125. */
  126. function supportsExecutionMode(bytes32 encodedMode) external view returns (bool);
  127. /**
  128. * @dev Function to check if the account supports a certain module typeId
  129. * @param moduleTypeId the module type ID according to the ERC-7579 spec
  130. *
  131. * MUST return true if the account supports the module type and false otherwise
  132. */
  133. function supportsModule(uint256 moduleTypeId) external view returns (bool);
  134. }
  135. interface IERC7579ModuleConfig {
  136. event ModuleInstalled(uint256 moduleTypeId, address module);
  137. event ModuleUninstalled(uint256 moduleTypeId, address module);
  138. /**
  139. * @dev Installs a Module of a certain type on the smart account
  140. * @param moduleTypeId the module type ID according to the ERC-7579 spec
  141. * @param module the module address
  142. * @param initData arbitrary data that may be required on the module during `onInstall`
  143. * initialization.
  144. *
  145. * MUST implement authorization control
  146. * MUST call `onInstall` on the module with the `initData` parameter if provided
  147. * MUST emit ModuleInstalled event
  148. * MUST revert if the module is already installed or the initialization on the module failed
  149. */
  150. function installModule(uint256 moduleTypeId, address module, bytes calldata initData) external;
  151. /**
  152. * @dev Uninstalls a Module of a certain type on the smart account
  153. * @param moduleTypeId the module type ID according the ERC-7579 spec
  154. * @param module the module address
  155. * @param deInitData arbitrary data that may be required on the module during `onInstall`
  156. * initialization.
  157. *
  158. * MUST implement authorization control
  159. * MUST call `onUninstall` on the module with the `deInitData` parameter if provided
  160. * MUST emit ModuleUninstalled event
  161. * MUST revert if the module is not installed or the deInitialization on the module failed
  162. */
  163. function uninstallModule(uint256 moduleTypeId, address module, bytes calldata deInitData) external;
  164. /**
  165. * @dev Returns whether a module is installed on the smart account
  166. * @param moduleTypeId the module type ID according the ERC-7579 spec
  167. * @param module the module address
  168. * @param additionalContext arbitrary data that may be required to determine if the module is installed
  169. *
  170. * MUST return true if the module is installed and false otherwise
  171. */
  172. function isModuleInstalled(
  173. uint256 moduleTypeId,
  174. address module,
  175. bytes calldata additionalContext
  176. ) external view returns (bool);
  177. }