-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProjectFactory.sol
106 lines (89 loc) · 3.68 KB
/
ProjectFactory.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;
import {IHomeFi} from "./interfaces/IHomeFi.sol";
import {Project} from "./Project.sol";
import {IProjectFactory} from "./interfaces/IProjectFactory.sol";
import {ClonesUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
import {Initializable, ERC2771ContextUpgradeable} from "@openzeppelin/contracts-upgradeable/metatx/ERC2771ContextUpgradeable.sol";
/**
* @title ProjectFactory for HomeFi v2.5.0
* @dev This contract is used by HomeFi to create cheap clones of Project contract underlying
*/
contract ProjectFactory is
IProjectFactory,
Initializable,
ERC2771ContextUpgradeable
{
/*******************************************************************************
* -------------------------PUBLIC STORED PROPERTIES-------------------------- *
*******************************************************************************/
/// @inheritdoc IProjectFactory
address public override underlying;
/// @inheritdoc IProjectFactory
address public override homeFi;
/*******************************************************************************
* ---------------------------------MODIFIERS--------------------------------- *
*******************************************************************************/
modifier nonZero(address _address) {
// Ensure an address is not the zero address (0x00)
require(_address != address(0), "PF::0 address");
_;
}
/*******************************************************************************
* ---------------------------EXTERNAL TRANSACTIONS--------------------------- *
*******************************************************************************/
/// @inheritdoc IProjectFactory
function initialize(address _underlying, address _homeFi)
external
override
initializer
nonZero(_underlying)
nonZero(_homeFi)
{
// Store details
underlying = _underlying;
homeFi = _homeFi;
}
/// @inheritdoc IProjectFactory
function changeProjectImplementation(address _underlying)
external
override
nonZero(_underlying)
{
// Revert if sender is not HomeFi admin
require(
_msgSender() == IHomeFi(homeFi).admin(),
"ProjectFactory::!Owner"
);
// Update details
underlying = _underlying;
}
/*******************************************************************************
* ------------------------------EXTERNAL VIEWS------------------------------- *
*******************************************************************************/
/// @inheritdoc IProjectFactory
function createProject(address _currency, address _sender)
external
override
returns (address _clone)
{
// Revert if sender is not HomeFi
require(_msgSender() == homeFi, "PF::!HomeFiContract");
// Create clone of Project implementation
_clone = ClonesUpgradeable.clone(underlying);
// Initialize project
Project(_clone).initialize(_currency, _sender, homeFi);
}
/*******************************************************************************
* -------------------------------PUBLIC VIEWS-------------------------------- *
*******************************************************************************/
/// @inheritdoc IProjectFactory
function isTrustedForwarder(address _forwarder)
public
view
override(ERC2771ContextUpgradeable, IProjectFactory)
returns (bool)
{
return IHomeFi(homeFi).isTrustedForwarder(_forwarder);
}
}