token-gallery-contracts/contracts/DiamondERC1155.sol

81 lines
2.8 KiB
Solidity

// SPDX-License-Identifier: Proprietary
pragma solidity ^0.7.2;
pragma experimental ABIEncoderV2;
import "./LibDiamond.sol";
import "./LibControl.sol";
import "./LibSellable.sol";
import "./IDiamondCut.sol";
import "./IDiamondLoupe.sol";
import "./IMotherShip.sol";
import "./LibERC1155.sol";
import "./IERC165.sol";
import "./IERC173.sol";
import "./IERC1155.sol";
import "./IERC1155MetadataURI.sol";
contract DiamondERC1155 {
// to get around stack too deep bullshit
struct InitializationParameters {
address payable creator;
IMotherShip mothership;
address token;
bool isERC1363Token;
uint8 fee;
uint8 royalty;
string storeName;
string storeSymbol;
string baseURI;
address proxyRegistryAddress;
uint24 storeId;
bool sendRightAway;
}
constructor(IDiamondCut.FacetCut[] memory _diamondCut, InitializationParameters memory params) payable {
LibDiamond.diamondCut(_diamondCut, address(0), new bytes(0));
LibControl.controlStorage().mothership = params.mothership;
LibControl.controlStorage().creator = params.creator;
LibSellable.setPaymentToken(params.token, params.isERC1363Token);
LibSellable.setFee(params.fee);
LibSellable.setRoyalty(params.royalty);
LibSellable.setSendRightAWay(params.sendRightAway);
LibERC1155.initialize(params.storeName, params.storeSymbol, params.baseURI, params.proxyRegistryAddress, params.storeId);
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;
ds.supportedInterfaces[type(IERC165).interfaceId] = true;
ds.supportedInterfaces[type(IERC1155).interfaceId] = true;
ds.supportedInterfaces[type(IERC1155MetadataURI).interfaceId] = true;
}
// Find facet for function that is called and execute the
// function if a facet is found and return any value.
fallback() external payable {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
address facet = address(bytes20(ds.facetAddressAndSelectorPosition[msg.sig].facetAddress));
require(facet != address(0), "Diamond: Function does not exist");
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable {}
}