Skip to content

Commit

Permalink
(treasury): start making vault master copy
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed Feb 27, 2024
1 parent c3da860 commit 43b15aa
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
69 changes: 53 additions & 16 deletions src/treasury/standardTreasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {}
}
53 changes: 53 additions & 0 deletions src/treasury/standardVault.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 43b15aa

Please sign in to comment.