-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdeployer.sol
More file actions
132 lines (102 loc) · 3.44 KB
/
Copy pathdeployer.sol
File metadata and controls
132 lines (102 loc) · 3.44 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
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
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.6.12;
import { ShelfFabLike, CollectorFabLike, PileFabLike, TitleFabLike } from "./fabs/interfaces.sol";
import { FixedPoint } from "./../fixed_point.sol";
interface DependLike {
function depend(bytes32, address) external;
}
interface AuthLike {
function rely(address) external;
function deny(address) external;
}
interface NFTFeedLike {
function init() external;
}
interface FeedFabLike {
function newFeed() external returns(address);
}
interface FileLike {
function file(bytes32 name, uint value) external;
}
contract BorrowerDeployer is FixedPoint {
address public root;
TitleFabLike public titlefab;
ShelfFabLike public shelffab;
PileFabLike public pilefab;
CollectorFabLike public collectorFab;
FeedFabLike public feedFab;
address public title;
address public shelf;
address public pile;
address public collector;
address public currency;
address public feed;
string public titleName;
string public titleSymbol;
Fixed27 public discountRate;
address constant ZERO = address(0);
constructor (
address root_,
address titlefab_,
address shelffab_,
address pilefab_,
address collectorFab_,
address feedFab_,
address currency_,
string memory titleName_,
string memory titleSymbol_,
uint discountRate_
) public {
root = root_;
titlefab = TitleFabLike(titlefab_);
shelffab = ShelfFabLike(shelffab_);
pilefab = PileFabLike(pilefab_);
collectorFab = CollectorFabLike(collectorFab_);
feedFab = FeedFabLike(feedFab_);
currency = currency_;
titleName = titleName_;
titleSymbol = titleSymbol_;
discountRate = Fixed27(discountRate_);
}
function deployCollector() public {
require(collector == ZERO && address(shelf) != ZERO);
collector = collectorFab.newCollector(address(shelf), address(pile), address(feed));
AuthLike(collector).rely(root);
}
function deployPile() public {
require(pile == ZERO);
pile = pilefab.newPile();
AuthLike(pile).rely(root);
}
function deployTitle() public {
require(title == ZERO);
title = titlefab.newTitle(titleName, titleSymbol);
AuthLike(title).rely(root);
}
function deployShelf() public {
require(shelf == ZERO && title != ZERO && pile != ZERO && feed != ZERO);
shelf = shelffab.newShelf(currency, address(title), address(pile), address(feed));
AuthLike(shelf).rely(root);
}
function deployFeed() public {
feed = feedFab.newFeed();
AuthLike(feed).rely(root);
}
function deploy() public {
// ensures all required deploy methods were called
require(shelf != ZERO && collector != ZERO);
// shelf allowed to call
AuthLike(pile).rely(shelf);
DependLike(feed).depend("shelf", address(shelf));
DependLike(feed).depend("pile", address(pile));
// allow nftFeed to update rate groups
AuthLike(pile).rely(feed);
NFTFeedLike(feed).init();
DependLike(shelf).depend("subscriber", address(feed));
AuthLike(feed).rely(shelf);
AuthLike(title).rely(shelf);
// collector allowed to call
AuthLike(shelf).rely(collector);
FileLike(feed).file("discountRate", discountRate.value);
}
}