-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutomatedLineOfCreditFactory.sol
More file actions
85 lines (76 loc) · 3.73 KB
/
AutomatedLineOfCreditFactory.sol
File metadata and controls
85 lines (76 loc) · 3.73 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IAutomatedLineOfCredit} from "./interfaces/IAutomatedLineOfCredit.sol";
import {PortfolioFactory} from "./PortfolioFactory.sol";
import {ITransferController} from "./interfaces/ITransferController.sol";
import {IDepositController} from "./interfaces/IDepositController.sol";
import {IWithdrawController} from "./interfaces/IWithdrawController.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
contract AutomatedLineOfCreditFactory is PortfolioFactory {
using Address for address;
struct ControllersData {
/// @dev Implementation of the controller applied when calling deposit-related functions
address depositControllerImplementation;
/// @dev Encoded args with initialize method selector from deposit controller
bytes depositControllerInitData;
/// @dev Implementation of the controller applied when calling withdraw-related functions
address withdrawControllerImplementation;
/// @dev Encoded args with initialize method selector from withdraw controller
bytes withdrawControllerInitData;
/// @dev Implementation of the controller used when calling transfer-related functions
address transferControllerImplementation;
/// @dev Encoded args with initialize method selector from transfer controller
bytes transferControllerInitData;
}
function createPortfolio(
uint256 _duration,
IERC20Metadata _asset,
uint256 _maxSize,
IAutomatedLineOfCredit.InterestRateParameters calldata _interestRateParameters,
ControllersData calldata controllersData,
string calldata name,
string calldata symbol
) external virtual onlyRole(MANAGER_ROLE) {
_createPortfolio(_duration, _asset, _maxSize, _interestRateParameters, controllersData, name, symbol);
}
function _createPortfolio(
uint256 _duration,
IERC20Metadata _asset,
uint256 _maxSize,
IAutomatedLineOfCredit.InterestRateParameters calldata _interestRateParameters,
ControllersData calldata controllersData,
string calldata name,
string calldata symbol
) internal {
IAutomatedLineOfCredit.Controllers memory controllers = setupControllers(controllersData);
bytes memory initCalldata = abi.encodeWithSelector(
IAutomatedLineOfCredit.initialize.selector,
protocolConfig,
_duration,
_asset,
msg.sender,
_maxSize,
_interestRateParameters,
controllers,
name,
symbol
);
_deployPortfolio(initCalldata);
}
function setupControllers(ControllersData memory controllersData) internal returns (IAutomatedLineOfCredit.Controllers memory) {
address depositController = Clones.clone(controllersData.depositControllerImplementation);
depositController.functionCall(controllersData.depositControllerInitData);
address withdrawController = Clones.clone(controllersData.withdrawControllerImplementation);
withdrawController.functionCall(controllersData.withdrawControllerInitData);
address transferController = Clones.clone(controllersData.transferControllerImplementation);
transferController.functionCall(controllersData.transferControllerInitData);
return
IAutomatedLineOfCredit.Controllers(
IDepositController(depositController),
IWithdrawController(withdrawController),
ITransferController(transferController)
);
}
}