diff --git a/src/hub/Hub.sol b/src/hub/Hub.sol index 9cced90..4f0e1df 100644 --- a/src/hub/Hub.sol +++ b/src/hub/Hub.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.13; -import "openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol"; -import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; -import "openzeppelin-contracts/contracts/utils/Create2.sol"; +import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/utils/Create2.sol"; import "../migration/IHub.sol"; import "../migration/IToken.sol"; import "../circles/Circles.sol"; diff --git a/src/treasury/standardTreasury.sol b/src/treasury/standardTreasury.sol index 5dab59b..60dc22a 100644 --- a/src/treasury/standardTreasury.sol +++ b/src/treasury/standardTreasury.sol @@ -2,14 +2,33 @@ pragma solidity >=0.8.13; import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; +import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; +import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol"; import "../proxy/ProxyFactory.sol"; +import "../hub/MetadataDefinitions.sol"; + +contract standardTreasury is ERC165, IERC1155Receiver, ProxyFactory { + // Constants + + /** + * @dev The call prefix for the setup function on the vault contract + */ + bytes4 public constant STANDARD_VAULT_SETUP_CALLPREFIX = bytes4(keccak256("setup(address)")); -contract standardTreasury is ERC1155Holder, ProxyFactory { // State variables address public immutable hub; - // modifier + /** + * @notice Mapping of group address to vault address + * @dev The vault is the contract that holds the group's collateral + * todo: we could use deterministic vault addresses as to not store them + * but then we still need to check whether the correct code has been deployed + * so we might as well deploy and store the addresses? + */ + mapping(address => address) public vaults; + + // Modifiers modifier onlyHub() { require(msg.sender == hub, "Treasury: caller is not the hub"); @@ -23,23 +42,41 @@ contract standardTreasury is ERC1155Holder, ProxyFactory { hub = _hub; } - function onERC1155Received(address, address, uint256, uint256, bytes memory) - public - virtual - override - onlyHub - returns (bytes4) - { + // Public functions + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { + return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId); + } + + function onERC1155Received( + address, /*_operator*/ + address, /*_from*/ + uint256, /*_id*/ + uint256, /*_value*/ + bytes memory /*_data*/ + ) public virtual override onlyHub returns (bytes4) { return this.onERC1155Received.selector; } - function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) - public - virtual - override - onlyHub - returns (bytes4) - { + function onERC1155BatchReceived( + address _operator, + address _from, + uint256[] memory _ids, + uint256[] memory _values, + bytes memory _data + ) public virtual override onlyHub returns (bytes4) { + MetadataDefinitions.Metadata memory metadata = abi.decode(_data, (MetadataDefinitions.Metadata)); + require(metadata.metadataType == MetadataDefinitions.MetadataType.GroupMint, "Treasury: Invalid metadata type"); + MetadataDefinitions.GroupMintMetadata memory groupMintMetadata = + abi.decode(metadata.metadata, (MetadataDefinitions.GroupMintMetadata)); + return this.onERC1155BatchReceived.selector; } + + // Internal functions + + function _getVault(address _group) internal returns (address) {} } diff --git a/src/treasury/standardVault.sol b/src/treasury/standardVault.sol index 8b13789..779e09a 100644 --- a/src/treasury/standardVault.sol +++ b/src/treasury/standardVault.sol @@ -1 +1,54 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity >=0.8.13; +import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; +import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol"; + +contract standardVault is ERC165, IERC1155Receiver { + // State variables + + address public standardTreasury; + + // Constructor + + constructor() { + standardTreasury = address(1); + } + + // External functions + + function setup(address _standardTreasury) external { + require(standardTreasury == address(0), "Vault contract has already been setup."); + require(_standardTreasury != address(0), "Treasury address must not be zero address"); + standardTreasury = _standardTreasury; + } + + // Public functions + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { + return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId); + } + + function onERC1155Received( + address, /*_operator*/ + address, /*_from*/ + uint256, /*_id*/ + uint256, /*_value*/ + bytes memory /*_data*/ + ) public virtual override returns (bytes4) { + return this.onERC1155Received.selector; + } + + function onERC1155BatchReceived( + address, /*_operator*/ + address, /*_from*/ + uint256[] memory, /*_ids*/ + uint256[] memory, /*_values*/ + bytes memory /*_data*/ + ) public virtual override returns (bytes4) { + return this.onERC1155BatchReceived.selector; + } +}