/
MarketClientProxy.sol
191 lines (162 loc) · 5.42 KB
/
MarketClientProxy.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IAccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import { IMarketClientProxy } from "../../interfaces/IMarketClientProxy.sol";
import { IMarketController } from "../../interfaces/IMarketController.sol";
import { SeenConstants } from "../../domain/SeenConstants.sol";
import { MarketClientLib } from "./MarketClientLib.sol";
import { Proxy } from "./Proxy.sol";
/**
* @title MarketClientProxy
*
* @notice Delegates calls to a market client implementation contract,
* such that functions on it execute in the context (address, storage)
* of this proxy, allowing the implementation contract to be upgraded
* without losing the accumulated state data.
*
* Market clients are the contracts in the system that communicate with
* the MarketController as clients of the MarketDiamond rather than acting
* as facets of the MarketDiamond. They include SeenHausNFT, ItemsTicketer,
* and LotsTicketer.
*
* Each Market Client contract will be deployed behind its own proxy for
* future upgradability.
*
* @author Cliff Hall <cliff@futurescale.com> (https://twitter.com/seaofarrows)
*/
contract MarketClientProxy is IMarketClientProxy, SeenConstants, Proxy {
/**
* @dev Modifier that checks that the caller has a specific role.
*
* Reverts if caller doesn't have role.
*
* See: {AccessController.hasRole}
*/
modifier onlyRole(bytes32 role) {
require(MarketClientLib.hasRole(role), "Caller doesn't have role");
_;
}
constructor(
address _accessController,
address _marketController,
address _impl
) {
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Store the AccessController address
ps.accessController = IAccessControlUpgradeable(_accessController);
// Store the MarketController address
ps.marketController = IMarketController(_marketController);
// Store the implementation address
ps.implementation = _impl;
}
/**
* @dev Returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation()
internal
view
override
returns (address) {
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Return the current implementation address
return ps.implementation;
}
/**
* @dev Set the implementation address
*/
function setImplementation(address _impl)
external
onlyRole(UPGRADER)
override
{
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Store the implementation address
ps.implementation = _impl;
// Notify listeners about state change
emit Upgraded(_impl);
}
/**
* @dev Get the implementation address
*/
function getImplementation()
external
view
override
returns (address) {
return _implementation();
}
/**
* @notice Set the Seen.Haus AccessController
*
* Emits an AccessControllerAddressChanged event.
*
* @param _accessController - the Seen.Haus AccessController address
*/
function setAccessController(address _accessController)
external
onlyRole(UPGRADER)
override
{
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Store the AccessController address
ps.accessController = IAccessControlUpgradeable(_accessController);
// Notify listeners about state change
emit AccessControllerAddressChanged(_accessController);
}
/**
* @notice Gets the address of the Seen.Haus AccessController contract.
*
* @return the address of the AccessController contract
*/
function getAccessController()
public
view
override
returns(IAccessControlUpgradeable)
{
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Return the current AccessController address
return ps.accessController;
}
/**
* @notice Set the Seen.Haus MarketController
*
* Emits an MarketControllerAddressChanged event.
*
* @param _marketController - the Seen.Haus MarketController address
*/
function setMarketController(address _marketController)
external
onlyRole(UPGRADER)
override
{
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Store the MarketController address
ps.marketController = IMarketController(_marketController);
// Notify listeners about state change
emit MarketControllerAddressChanged(_marketController);
}
/**
* @notice Gets the address of the Seen.Haus MarketController contract.
*
* @return the address of the MarketController contract
*/
function getMarketController()
public
override
view
returns(IMarketController)
{
// Get the ProxyStorage struct
MarketClientLib.ProxyStorage storage ps = MarketClientLib.proxyStorage();
// Return the current MarketController address
return ps.marketController;
}
}