-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFactory.sol
141 lines (116 loc) · 4.02 KB
/
Factory.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.21;
import {LiquidityPool} from "../LiquidityPool.sol";
import {TrancheToken} from "../token/Tranche.sol";
import {RestrictionManager} from "../token/RestrictionManager.sol";
import {Auth} from "./Auth.sol";
interface RootLike {
function escrow() external view returns (address);
}
interface LiquidityPoolFactoryLike {
function newLiquidityPool(
uint64 poolId,
bytes16 trancheId,
address currency,
address trancheToken,
address investmentManager,
address[] calldata wards
) external returns (address);
}
/// @title Liquidity Pool Factory
/// @dev Utility for deploying new liquidity pool contracts
contract LiquidityPoolFactory is Auth {
address public immutable root;
constructor(address _root) {
root = _root;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function newLiquidityPool(
uint64 poolId,
bytes16 trancheId,
address currency,
address trancheToken,
address investmentManager,
address[] calldata wards
) public auth returns (address) {
LiquidityPool liquidityPool = new LiquidityPool(poolId, trancheId, currency, trancheToken, investmentManager);
liquidityPool.rely(root);
for (uint256 i = 0; i < wards.length; i++) {
liquidityPool.rely(wards[i]);
}
liquidityPool.deny(address(this));
return address(liquidityPool);
}
}
interface TrancheTokenFactoryLike {
function newTrancheToken(
uint64 poolId,
bytes16 trancheId,
string memory name,
string memory symbol,
uint8 decimals,
address[] calldata restrictionManagerWards
) external returns (address);
}
/// @title Tranche Token Factory
/// @dev Utility for deploying new tranche token contracts
/// Ensures the addresses are deployed at a deterministic address
/// based on the pool id and tranche id.
contract TrancheTokenFactory is Auth {
address public immutable root;
constructor(address _root) {
root = _root;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function newTrancheToken(
uint64 poolId,
bytes16 trancheId,
string memory name,
string memory symbol,
uint8 decimals,
address[] calldata trancheTokenWards
) public auth returns (address) {
// Salt is hash(poolId + trancheId)
// same tranche token address on every evm chain
bytes32 salt = keccak256(abi.encodePacked(poolId, trancheId));
TrancheToken token = new TrancheToken{salt: salt}(decimals);
token.file("name", name);
token.file("symbol", symbol);
token.rely(root);
for (uint256 i = 0; i < trancheTokenWards.length; i++) {
token.rely(trancheTokenWards[i]);
}
token.deny(address(this));
return address(token);
}
}
interface RestrictionManagerFactoryLike {
function newRestrictionManager(address token, address[] calldata restrictionManagerWards)
external
returns (address);
}
/// @title Restriction Manager Factory
/// @dev Utility for deploying new restriction manager contracts
contract RestrictionManagerFactory is Auth {
address immutable root;
constructor(address _root) {
root = _root;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function newRestrictionManager(address token, address[] calldata restrictionManagerWards)
public
returns (address restrictionManager)
{
RestrictionManager restrictionManager = new RestrictionManager(token);
restrictionManager.updateMember(RootLike(root).escrow(), type(uint256).max);
restrictionManager.rely(root);
for (uint256 i = 0; i < restrictionManagerWards.length; i++) {
restrictionManager.rely(restrictionManagerWards[i]);
}
restrictionManager.deny(address(this));
return (address(restrictionManager));
}
}