creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/modules/commons/Implementation.sol": {
        "content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.8.18;\n\n/**\n * @dev Allows modules to access the implementation slot\n */\ncontract Implementation {\n  /**\n   * @notice Updates the Wallet implementation\n   * @param _imp New implementation address\n   * @dev The wallet implementation is stored on the storage slot\n   *   defined by the address of the wallet itself\n   *   WARNING updating this value may break the wallet and users\n   *   must be confident that the new implementation is safe.\n   */\n  function _setImplementation(address _imp) internal {\n    assembly {\n      sstore(address(), _imp)\n    }\n  }\n\n  /**\n   * @notice Returns the Wallet implementation\n   * @return _imp The address of the current Wallet implementation\n   */\n  function _getImplementation() internal view returns (address _imp) {\n    assembly {\n      _imp := sload(address())\n    }\n  }\n}\n"
      },
      "contracts/modules/commons/ModuleStorage.sol": {
        "content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.8.18;\n\n\nlibrary ModuleStorage {\n  function writeBytes32(bytes32 _key, bytes32 _val) internal {\n    assembly { sstore(_key, _val) }\n  }\n\n  function readBytes32(bytes32 _key) internal view returns (bytes32 val) {\n    assembly { val := sload(_key) }\n  }\n\n  function writeBytes32Map(bytes32 _key, bytes32 _subKey, bytes32 _val) internal {\n    bytes32 key = keccak256(abi.encode(_key, _subKey));\n    assembly { sstore(key, _val) }\n  }\n\n  function readBytes32Map(bytes32 _key, bytes32 _subKey) internal view returns (bytes32 val) {\n    bytes32 key = keccak256(abi.encode(_key, _subKey));\n    assembly { val := sload(key) }\n  }\n}\n"
      },
      "contracts/tools/MigratorToDuo.sol": {
        "content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.8.18;\n\nimport \"../modules/commons/Implementation.sol\";\nimport \"../modules/commons/ModuleStorage.sol\";\n\n\ninterface SimpleImplementation {\n  function imageHash() external view returns (bytes32);\n  function externalImageHash() external view returns (bytes32);\n}\n\ncontract MigratorToDuo is Implementation {\n  //                        EXTERNAL_IMAGE_HASH_KEY = keccak256(\"org.sequence.module.auth.upgradable.image.hash.external\");\n  bytes32 internal constant EXTERNAL_IMAGE_HASH_KEY = bytes32(0x8c8764b3a50fee69c9bee6e956047501f434fb0e2349c75844a401a7f2a020d2);\n\n  //                        IMAGE_HASH_KEY = keccak256(\"org.arcadeum.module.auth.upgradable.image.hash\");\n  bytes32 internal constant IMAGE_HASH_KEY = bytes32(0xea7157fa25e3aa17d0ae2d5280fa4e24d421c61842aa85e45194e1145aa72bf8);\n\n  address public immutable IMPLEMENTATION;\n  address public immutable TARGET;\n  bytes32 public immutable IMAGE_HASH;\n  bytes32 public immutable EXTERNAL_IMAGE_HASH;\n\n  error NotTarget();\n  error ImageHashIsZero();\n  error ExternalImageHashIsZero();\n  error ImplementationNotDeployed();\n  error FailedImageHashUpdate();\n  error FailedExternalImageHashUpdate();\n\n  event ImageHashUpdated(bytes32 _imageHash);\n  event ExternalImageHashUpdated(bytes32 _imageHash);\n  event Patched(address indexed _implementation, bytes32 indexed _imageHash, bytes32 indexed _externalImageHash);\n\n  constructor(\n    address _mainModuleUpgradableDuo,\n    address _target,\n    bytes32 _imageHash,\n    bytes32 _externalImageHash\n  ) {\n    if (_imageHash == bytes32(0)) {\n      revert ImageHashIsZero();\n    }\n\n    if (_externalImageHash == bytes32(0)) {\n      revert ExternalImageHashIsZero();\n    }\n\n    IMPLEMENTATION = _mainModuleUpgradableDuo;\n    TARGET = _target;\n    IMAGE_HASH = _imageHash;\n    EXTERNAL_IMAGE_HASH = _externalImageHash;\n  }\n\n  function migrate() external {\n    if (address(this) != TARGET) {\n      revert NotTarget();\n    }\n\n    if (IMPLEMENTATION.code.length == 0) {\n      revert ImplementationNotDeployed();\n    }\n\n    _setImplementation(IMPLEMENTATION);\n\n    ModuleStorage.writeBytes32(IMAGE_HASH_KEY, IMAGE_HASH);\n    ModuleStorage.writeBytes32(EXTERNAL_IMAGE_HASH_KEY, EXTERNAL_IMAGE_HASH);\n\n    emit ImageHashUpdated(IMAGE_HASH);\n    emit ExternalImageHashUpdated(EXTERNAL_IMAGE_HASH);\n\n    if (IMAGE_HASH != SimpleImplementation(address(this)).imageHash()) {\n      revert FailedImageHashUpdate();\n    }\n\n    if (EXTERNAL_IMAGE_HASH != SimpleImplementation(address(this)).externalImageHash()) {\n      revert FailedExternalImageHashUpdate();\n    }\n\n    emit Patched(IMPLEMENTATION, IMAGE_HASH, EXTERNAL_IMAGE_HASH);\n  }\n}"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 500000
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}