-
Notifications
You must be signed in to change notification settings - Fork 1
/
BasePortfolioFactory.sol
44 lines (36 loc) · 1.88 KB
/
BasePortfolioFactory.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {IBasePortfolio} from "./interfaces/IBasePortfolio.sol";
import {IERC20WithDecimals} from "./interfaces/IERC20WithDecimals.sol";
import {IProtocolConfig} from "./interfaces/IProtocolConfig.sol";
import {ProxyWrapper} from "./proxy/ProxyWrapper.sol";
import {Upgradeable} from "./access/Upgradeable.sol";
abstract contract BasePortfolioFactory is Upgradeable {
bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
IBasePortfolio public portfolioImplementation;
IBasePortfolio[] public portfolios;
IProtocolConfig public protocolConfig;
event PortfolioCreated(IBasePortfolio indexed newPortfolio, address indexed manager);
event PortfolioImplementationChanged(IBasePortfolio indexed newImplementation);
function initialize(IBasePortfolio _portfolioImplementation, IProtocolConfig _protocolConfig) external initializer {
__Upgradeable_init(msg.sender, _protocolConfig.pauserAddress());
portfolioImplementation = _portfolioImplementation;
protocolConfig = _protocolConfig;
}
function setPortfolioImplementation(IBasePortfolio newImplementation) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(
portfolioImplementation != newImplementation,
"BasePortfolioFactory: New portfolio implementation needs to be different"
);
portfolioImplementation = newImplementation;
emit PortfolioImplementationChanged(newImplementation);
}
function getPortfolios() external view returns (IBasePortfolio[] memory) {
return portfolios;
}
function _deployPortfolio(bytes memory initData) internal {
IBasePortfolio newPortfolio = IBasePortfolio(address(new ProxyWrapper(address(portfolioImplementation), initData)));
portfolios.push(newPortfolio);
emit PortfolioCreated(newPortfolio, msg.sender);
}
}