-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathSetTokenCreator.sol
112 lines (92 loc) · 3.99 KB
/
SetTokenCreator.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Copyright 2020 Set Labs Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";
import "hardhat/console.sol";
import { IController } from "../interfaces/IController.sol";
import { SetToken } from "./SetToken.sol";
import { AddressArrayUtils } from "../lib/AddressArrayUtils.sol";
/**
* @title SetTokenCreator
* @author Set Protocol
*
* SetTokenCreator is a smart contract used to deploy new SetToken contracts. The SetTokenCreator
* is a Factory contract that is enabled by the controller to create and register new SetTokens.
*/
contract SetTokenCreator {
using AddressArrayUtils for address[];
/* ============ Events ============ */
event SetTokenCreated(address indexed _setToken, address _manager, string _name, string _symbol);
/* ============ State Variables ============ */
// Instance of the controller smart contract
IController public controller;
/* ============ Functions ============ */
/**
* @param _controller Instance of the controller
*/
constructor(IController _controller) public {
controller = _controller;
}
/**
* Creates a SetToken smart contract and registers the SetToken with the controller. The SetTokens are composed
* of positions that are instantiated as DEFAULT (positionState = 0) state.
*
* @param _components List of addresses of components for initial Positions
* @param _units List of units. Each unit is the # of components per 10^18 of a SetToken
* @param _modules List of modules to enable. All modules must be approved by the Controller
* @param _manager Address of the manager
* @param _name Name of the SetToken
* @param _symbol Symbol of the SetToken
* @return address Address of the newly created SetToken
*/
function create(
address[] memory _components,
int256[] memory _units,
address[] memory _modules,
address _manager,
string memory _name,
string memory _symbol
)
external
returns (address)
{
require(_components.length > 0, "Must have at least 1 component");
require(_components.length == _units.length, "Component and unit lengths must be the same");
require(!_components.hasDuplicate(), "Components must not have a duplicate");
require(_modules.length > 0, "Must have at least 1 module");
require(_manager != address(0), "Manager must not be empty");
for (uint256 i = 0; i < _components.length; i++) {
require(_components[i] != address(0), "Component must not be null address");
require(_units[i] > 0, "Units must be greater than 0");
}
for (uint256 j = 0; j < _modules.length; j++) {
require(controller.isModule(_modules[j]), "Must be enabled module");
}
// Creates a new SetToken instance
SetToken setToken = new SetToken(
_components,
_units,
_modules,
controller,
_manager,
_name,
_symbol
);
console.log("Test: ", address(setToken));
// Registers Set with controller
controller.addSet(address(setToken));
emit SetTokenCreated(address(setToken), _manager, _name, _symbol);
return address(setToken);
}
}