114 lines
3.6 KiB
Solidity
114 lines
3.6 KiB
Solidity
|
// SPDX-License-Identifier: Proprietary
|
||
|
|
||
|
pragma solidity ^0.7.2;
|
||
|
pragma experimental ABIEncoderV2;
|
||
|
|
||
|
import "./IDiamondCut.sol";
|
||
|
import "./DiamondERC1155.sol";
|
||
|
import "./IMotherShip.sol";
|
||
|
|
||
|
contract ERC1155DiamondFactory is IMotherShip {
|
||
|
address public override manager;
|
||
|
address public override bridge;
|
||
|
address public override oracle;
|
||
|
address payable public override payout;
|
||
|
|
||
|
modifier onlyManager {
|
||
|
require(manager == msg.sender, "Not manager");
|
||
|
_;
|
||
|
}
|
||
|
|
||
|
event NewStore(address indexed operator, address indexed store, uint24 indexed id);
|
||
|
|
||
|
bool internal initialized = false;
|
||
|
DiamondERC1155.InitializationParameters public initParams;
|
||
|
IDiamondCut.FacetCut[] public diamondCut;
|
||
|
|
||
|
function initialize(IDiamondCut.FacetCut[] memory _diamondCut, DiamondERC1155.InitializationParameters memory _initParams) external onlyManager {
|
||
|
initialized = true;
|
||
|
initParams = _initParams;
|
||
|
initParams.mothership = this;
|
||
|
|
||
|
delete diamondCut;
|
||
|
|
||
|
for (uint256 i=0; i<_diamondCut.length; ++i) {
|
||
|
diamondCut.push(_diamondCut[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
Checking for duplicate name/symbol can be done at the application level.
|
||
|
*/
|
||
|
function newStore(string calldata _name, string calldata _symbol) external returns (address) {
|
||
|
require(initialized, "Not initialized");
|
||
|
|
||
|
DiamondERC1155.InitializationParameters memory ip = initParams;
|
||
|
|
||
|
ip.creator = msg.sender;
|
||
|
ip.storeName = _name;
|
||
|
ip.storeSymbol = _symbol;
|
||
|
|
||
|
DiamondERC1155 diamond = new DiamondERC1155(diamondCut, ip);
|
||
|
|
||
|
emit NewStore(msg.sender, address(diamond), ip.storeId);
|
||
|
|
||
|
initParams.storeId = initParams.storeId + 1;
|
||
|
|
||
|
return address(diamond);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
If you want to override what token is used, for ex. GeoCoin or the like.
|
||
|
*/
|
||
|
function newStore(string calldata _name, string calldata _symbol, string calldata _metadataURI, address _customToken, bool _isERC1363) external returns (address) {
|
||
|
require(initialized, "Not initialized");
|
||
|
|
||
|
DiamondERC1155.InitializationParameters memory ip = initParams;
|
||
|
|
||
|
ip.creator = msg.sender;
|
||
|
ip.storeName = _name;
|
||
|
ip.storeSymbol = _symbol;
|
||
|
ip.baseURI = _metadataURI;
|
||
|
ip.token = _customToken;
|
||
|
ip.isERC1363Token = _isERC1363;
|
||
|
|
||
|
DiamondERC1155 diamond = new DiamondERC1155(diamondCut, ip);
|
||
|
|
||
|
emit NewStore(msg.sender, address(diamond), ip.storeId);
|
||
|
|
||
|
initParams.storeId = initParams.storeId + 1;
|
||
|
|
||
|
return address(diamond);
|
||
|
}
|
||
|
|
||
|
constructor() {
|
||
|
manager = msg.sender;
|
||
|
payout = msg.sender; // change it later if u don't like it
|
||
|
emit ManagerTransferred(msg.sender, address(0), msg.sender);
|
||
|
}
|
||
|
|
||
|
function setManager(address _manager) external onlyManager {
|
||
|
require(_manager != address(0), "0 not allowed as manager");
|
||
|
emit ManagerTransferred(msg.sender, manager, _manager);
|
||
|
manager = _manager;
|
||
|
}
|
||
|
|
||
|
function setBridge(address _bridge) external onlyManager {
|
||
|
require(_bridge != address(0), "0 not allowed as bridge");
|
||
|
emit BridgeTransferred(msg.sender, bridge, _bridge);
|
||
|
bridge = _bridge;
|
||
|
}
|
||
|
|
||
|
function setOracle(address _oracle) external onlyManager {
|
||
|
require(_oracle != address(0), "0 not allowed as oracle");
|
||
|
emit OracleTransferred(msg.sender, oracle, _oracle);
|
||
|
oracle = _oracle;
|
||
|
}
|
||
|
|
||
|
function setPayout(address payable _payout) external onlyManager {
|
||
|
require(_payout != address(0), "0 not allowed as payout");
|
||
|
emit PayoutTransferred(msg.sender, payout, _payout);
|
||
|
payout = _payout;
|
||
|
}
|
||
|
}
|