// SPDX-License-Identifier: UNLICENSED pragma solidity =0.8.18; import "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "./utils/security/IPausable.sol"; import "./ISOMA.sol"; /** * @notice Implementation of the {ISOMA} interface. Contains all the core SOMA contracts. */ contract SOMA is ISOMA, IPausable, PausableUpgradeable, ERC165Upgradeable { /** * @notice The name of the system. */ string public constant name = "SOMA Finance"; /** * @inheritdoc ISOMA * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ address public immutable override master; /** * @inheritdoc ISOMA * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ address public immutable override subMaster; /** * @inheritdoc ISOMA * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ address public immutable override access; /** * @inheritdoc ISOMA * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ address public immutable override guard; /** * @inheritdoc ISOMA * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ address public immutable override factory; /** * @inheritdoc ISOMA * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ address public immutable override token; /** * @inheritdoc ISOMA */ address public override mintTo; /** * @inheritdoc ISOMA */ address public override seizeTo; /** * @inheritdoc ISOMA */ bytes32 public override snapshotHash; /** * @inheritdoc ISOMA */ bytes32 public override snapshotVersion; /** * @inheritdoc ISOMA */ mapping(bytes32 => bytes32) public override versions; /** * @inheritdoc ISOMA */ mapping(bytes32 => bytes) public override snapshots; /** * @notice Constructor of the contract. * @param _snapshot The snapshot of the contracts. */ constructor(Snapshot memory _snapshot) { master = _snapshot.master; subMaster = _snapshot.subMaster; access = _snapshot.access; guard = _snapshot.guard; factory = _snapshot.factory; token = _snapshot.token; } /** * @notice The modifier that restricts a function caller to the master. */ modifier onlyMaster() { require(msg.sender == master, "SOMA: requires master key"); _; } /** * @notice The modifier that restricts a function caller to the master or subMaster. */ modifier onlyMasterOrSubMaster() { require(msg.sender == master || msg.sender == subMaster, "SOMA: requires master or sub master key"); _; } /** * @notice The initializer for SOMA. */ function initialize() external initializer { __ERC165_init(); __Pausable_init(); } /** * @inheritdoc ISOMA */ function __upgrade(bytes32 version) external override { bytes memory _snapshot = abi.encode(snapshot()); bytes32 hash = keccak256(_snapshot); require(hash != snapshotHash, "SOMA: INVALID_UPGRADE"); if (snapshots[hash].length == 0) { snapshots[hash] = _snapshot; } versions[hash] = version; versions[version] = hash; snapshotHash = hash; snapshotVersion = version; emit SOMAUpgraded(version, hash, _snapshot); } /** * @notice Checks if SOMA inherits a given contract interface. * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(ISOMA).interfaceId || interfaceId == type(IPausable).interfaceId || super.supportsInterface(interfaceId); } /** * @notice Returns a boolean indicating if the contracts are paused. */ function paused() public view virtual override(PausableUpgradeable, IPausable) returns (bool) { return super.paused(); } /** * @inheritdoc ISOMA */ function pause() external override(ISOMA, IPausable) onlyMasterOrSubMaster { _pause(); } /** * @inheritdoc ISOMA */ function unpause() external override(ISOMA, IPausable) onlyMasterOrSubMaster { _unpause(); } /** * @inheritdoc ISOMA */ function setMintTo(address _mintTo) external override onlyMaster { emit MintToUpdated(mintTo, _mintTo, msg.sender); mintTo = _mintTo; } /** * @inheritdoc ISOMA */ function setSeizeTo(address _seizeTo) external override onlyMaster { emit SeizeToUpdated(seizeTo, _seizeTo, msg.sender); seizeTo = _seizeTo; } /** * @inheritdoc ISOMA */ function snapshot() public view override returns (Snapshot memory _snapshot) { _snapshot.master = master; _snapshot.subMaster = subMaster; _snapshot.factory = factory; _snapshot.guard = guard; _snapshot.access = access; _snapshot.token = token; } }