Skip to content

Commit 2a8a4c8

Browse files
authored
Fix: Resolve Upgradability Issue (#655)
* Fix: Turn TransactionForwarder into upgradeable version * Fix: Remove Reverter from OrchestratorFactory constructor * Script: Extend verifyDeployment function * Fix: Remove typo in contract titles
1 parent ec3131a commit 2a8a4c8

File tree

12 files changed

+293
-53
lines changed

12 files changed

+293
-53
lines changed

script/deploymentScript/DeploymentScript.s.sol

Lines changed: 243 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@ import "forge-std/Script.sol";
77
import {ModuleBeaconDeployer_v1} from
88
"script/deploymentSuite/ModuleBeaconDeployer_v1.s.sol";
99

10-
// Constants
10+
// Interfaces
11+
import {IDeterministicFactory_v1} from
12+
"@df/interfaces/IDeterministicFactory_v1.sol";
13+
14+
// Contracts
1115
import {Governor_v1} from "@ex/governance/Governor_v1.sol";
1216
import {FeeManager_v1} from "@ex/fees/FeeManager_v1.sol";
17+
import {TransactionForwarder_v1} from
18+
"@ex/forwarder/TransactionForwarder_v1.sol";
1319
import {ModuleFactory_v1} from "src/factories/ModuleFactory_v1.sol";
1420
import {OrchestratorFactory_v1} from "src/factories/OrchestratorFactory_v1.sol";
15-
import {IDeterministicFactory_v1} from
16-
"@df/interfaces/IDeterministicFactory_v1.sol";
21+
import {
22+
InverterBeacon_v1,
23+
IInverterBeacon_v1
24+
} from "src/proxies/InverterBeacon_v1.sol";
25+
import {Orchestrator_v1} from "src/orchestrator/Orchestrator_v1.sol";
26+
import {Module_v1} from "src/modules/base/Module_v1.sol";
27+
import {Ownable} from "@oz/access/Ownable.sol";
28+
import {EIP712} from "@oz/utils/cryptography/EIP712.sol";
1729

1830
/**
1931
* @title Inverter Deployment Script
@@ -26,6 +38,7 @@ import {IDeterministicFactory_v1} from
2638
* @author Inverter Network
2739
*/
2840
contract DeploymentScript is ModuleBeaconDeployer_v1 {
41+
// Contracts
2942
address public inverterReverter;
3043

3144
address public governor;
@@ -35,6 +48,14 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
3548
address public moduleFactory;
3649
address public orchestratorFactory;
3750

51+
// Beacons
52+
address public governorBeacon;
53+
address public forwarderBeacon;
54+
address public feeManagerBeacon;
55+
56+
address public moduleFactoryBeacon;
57+
address public orchestratorFactoryBeacon;
58+
3859
function run()
3960
public
4061
virtual
@@ -67,7 +88,8 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
6788
);
6889
console2.log(" Deploy External Contracts");
6990

70-
governor = proxyAndBeaconDeployer.deployBeaconAndSetupProxy(
91+
(governorBeacon, governor) = proxyAndBeaconDeployer
92+
.deployBeaconAndSetupProxy(
7193
governorMetadata.title,
7294
inverterReverter,
7395
communityMultisig,
@@ -77,7 +99,8 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
7799
governorMetadata.patchVersion
78100
);
79101

80-
forwarder = proxyAndBeaconDeployer.deployBeaconAndSetupProxy(
102+
(forwarderBeacon, forwarder) = proxyAndBeaconDeployer
103+
.deployBeaconAndSetupProxy(
81104
forwarderMetadata.title,
82105
inverterReverter,
83106
governor,
@@ -87,7 +110,8 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
87110
forwarderMetadata.patchVersion
88111
);
89112

90-
feeManager = proxyAndBeaconDeployer.deployBeaconAndSetupProxy(
113+
(feeManagerBeacon, feeManager) = proxyAndBeaconDeployer
114+
.deployBeaconAndSetupProxy(
91115
feeManagerMetadata.title,
92116
inverterReverter,
93117
governor,
@@ -106,7 +130,8 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
106130
);
107131
console2.log(" Deploy Factory Contracts");
108132

109-
moduleFactory = proxyAndBeaconDeployer.deployBeaconAndSetupProxy(
133+
(moduleFactoryBeacon, moduleFactory) = proxyAndBeaconDeployer
134+
.deployBeaconAndSetupProxy(
110135
moduleFactoryMetadata.title,
111136
inverterReverter,
112137
governor,
@@ -116,7 +141,8 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
116141
moduleFactoryMetadata.patchVersion
117142
);
118143

119-
orchestratorFactory = proxyAndBeaconDeployer.deployBeaconAndSetupProxy(
144+
(orchestratorFactoryBeacon, orchestratorFactory) =
145+
proxyAndBeaconDeployer.deployBeaconAndSetupProxy(
120146
orchestratorFactoryMetadata.title,
121147
inverterReverter,
122148
governor,
@@ -164,6 +190,10 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
164190
);
165191
console2.log("\t... FeeManager initialized");
166192

193+
// TransactionForwarder
194+
TransactionForwarder_v1(forwarder).init();
195+
console2.log("\t... TransactionForwarder initialized");
196+
167197
// ModuleFactory
168198
ModuleFactory_v1(moduleFactory).init(
169199
governor, initialMetadataRegistration, initialBeaconRegistration
@@ -183,51 +213,246 @@ contract DeploymentScript is ModuleBeaconDeployer_v1 {
183213

184214
// ------------------------------------------------------------------------
185215
// In order to verify that the deployment was successful, we
186-
// verify that the core contracts have been initialized correctly.
216+
// verify that the contracts have been initialized correctly and all
217+
// important values have been set as expected.
218+
219+
verifyDeployment();
220+
221+
// ------------------------------------------------------------------------
222+
}
223+
224+
function verifyDeployment() public {
225+
// ------------------------------------------------------------------------
226+
// >>> Governor
187227

188-
// Governor
228+
// Verify that the Community Multisig is set correctly
189229
require(
190230
Governor_v1(governor).hasRole(
191231
Governor_v1(governor).COMMUNITY_MULTISIG_ROLE(),
192232
communityMultisig
193233
) == true,
194-
"Deployment failed - Governor not initialized correctly, Community Multisig is not set."
234+
"Deployment failed - Governor not initialized correctly, Community Multisig is not set correctly."
195235
);
236+
237+
// Verify that the Team Multisig is set correctly
196238
require(
197239
Governor_v1(governor).hasRole(
198240
Governor_v1(governor).TEAM_MULTISIG_ROLE(), teamMultisig
199241
) == true,
200-
"Deployment failed - Governor not initialized correctly, Team Multisig is not set."
242+
"Deployment failed - Governor not initialized correctly, Team Multisig is not set correctly."
201243
);
244+
245+
// Verify that Module Factory is linked correctly
202246
require(
203247
Governor_v1(governor).getModuleFactory() == moduleFactory,
204-
"Deployment failed - Governor not initialized correctly, ModuleFactory is not set."
248+
"Deployment failed - Governor not initialized correctly, ModuleFactory is not correct."
205249
);
250+
251+
// Verify that Fee Manager is linked correctly
206252
require(
207253
Governor_v1(governor).getFeeManager() == feeManager,
208-
"Deployment failed - Governor not initialized correctly, FeeManager is not set."
254+
"Deployment failed - Governor not initialized correctly, FeeManager is not correct."
255+
);
256+
257+
// Verify that the Timelock Period is set correctly
258+
require(
259+
Governor_v1(governor).timelockPeriod() == governor_timelockPeriod,
260+
"Deployment failed - Governor not initialized correctly, Timelock Period is not correct."
261+
);
262+
263+
// Verify that the Reverter is linked correctly
264+
require(
265+
IInverterBeacon_v1(governorBeacon).getReverterAddress()
266+
== inverterReverter,
267+
"Deployment failed - Governor Beacon not initialized correctly, Reverter is not correct."
209268
);
210269

211-
// ModuleFactory
270+
// ------------------------------------------------------------------------
271+
// >>> ModuleFactory
272+
273+
// Verify that the ModuleFactory is owned by the Governor
212274
require(
213275
ModuleFactory_v1(moduleFactory).owner() == governor,
214276
"Deployment failed - ModuleFactory not initialized correctly, not owned by Governor."
215277
);
216278

217-
// OrchestratorFactory
279+
// Verify that the TransactionForwarder is linked correctly
280+
require(
281+
ModuleFactory_v1(moduleFactory).trustedForwarder() == forwarder,
282+
"Deployment failed - ModuleFactory not initialized correctly, Forwarder is not correct."
283+
);
284+
285+
// Verify that the Reverter is linked correctly
286+
require(
287+
ModuleFactory_v1(moduleFactory).reverter() == inverterReverter,
288+
"Deployment failed - ModuleFactory not initialized correctly, Reverter is not correct."
289+
);
290+
291+
// Verify that the Reverter is linked correctly
292+
require(
293+
IInverterBeacon_v1(moduleFactoryBeacon).getReverterAddress()
294+
== inverterReverter,
295+
"Deployment failed - ModuleFactory Beacon not initialized correctly, Reverter is not correct."
296+
);
297+
298+
// ------------------------------------------------------------------------
299+
// >>> OrchestratorFactory
300+
301+
// Verify that the ModuleFactory is linked correctly
218302
require(
219303
OrchestratorFactory_v1(orchestratorFactory).moduleFactory()
220304
== moduleFactory,
221-
"Deployment failed - OrchestratorFactory not initialized correctly, ModuleFactory is not set."
305+
"Deployment failed - OrchestratorFactory not initialized correctly, ModuleFactory is not correct."
306+
);
307+
308+
// Verify that the TransactionForwarder is linked correctly
309+
require(
310+
OrchestratorFactory_v1(orchestratorFactory).trustedForwarder()
311+
== forwarder,
312+
"Deployment failed - OrchestratorFactory not initialized correctly, Forwarder is not correct."
222313
);
223314

224-
// FeeManager
315+
// Verify that the Reverter is linked correctly
316+
require(
317+
IInverterBeacon_v1(orchestratorFactoryBeacon).getReverterAddress()
318+
== inverterReverter,
319+
"Deployment failed - OrchestratorFactory Beacon not initialized correctly, Reverter is not correct."
320+
);
321+
322+
// ------------------------------------------------------------------------
323+
// >>> FeeManager
324+
325+
// Verify that the FeeManager is owned by the Governor
225326
require(
226327
FeeManager_v1(feeManager).owner() == governor,
227328
"Deployment failed - FeeManager not initialized correctly, not owned by Governor."
228329
);
229330

331+
// Verify that the Treasury is set correctly
332+
require(
333+
FeeManager_v1(feeManager).getDefaultProtocolTreasury() == treasury,
334+
"Deployment failed - FeeManager not initialized correctly, Treasury is not correct."
335+
);
336+
337+
// Verify that the Default Collateral Fee is set correctly
338+
require(
339+
FeeManager_v1(feeManager).getDefaultCollateralFee()
340+
== feeManager_defaultCollateralFee,
341+
"Deployment failed - FeeManager not initialized correctly, Default Collateral Fee is not correct."
342+
);
343+
344+
// Verify that the Default Issuance Fee is set correctly
345+
require(
346+
FeeManager_v1(feeManager).getDefaultIssuanceFee()
347+
== feeManager_defaultIssuanceFee,
348+
"Deployment failed - FeeManager not initialized correctly, Default Issuance Fee is not correct."
349+
);
350+
351+
// Verify that the Reverter is linked correctly
352+
require(
353+
IInverterBeacon_v1(feeManagerBeacon).getReverterAddress()
354+
== inverterReverter,
355+
"Deployment failed - FeeManager Beacon not initialized correctly, Reverter is not correct."
356+
);
357+
230358
// ------------------------------------------------------------------------
359+
// >>> TransactionForwarder
360+
361+
// Verify that the TransactionForwarder has been initialized correctly
362+
(
363+
,
364+
string memory _name,
365+
string memory _version,
366+
uint _chainId,
367+
address _verifyingContract,
368+
,
369+
) = EIP712(forwarder).eip712Domain();
370+
require(
371+
_chainId == block.chainid
372+
&& keccak256(abi.encodePacked(_version))
373+
== keccak256(abi.encodePacked("1"))
374+
&& keccak256(abi.encodePacked(_name))
375+
== keccak256(abi.encodePacked("Inverter TransactionForwarder_v1"))
376+
&& _verifyingContract == forwarder,
377+
"Deployment failed - TransactionForwarder not initialized correctly."
378+
);
379+
380+
// Verify that the Reverter is linked correctly
381+
require(
382+
IInverterBeacon_v1(forwarderBeacon).getReverterAddress()
383+
== inverterReverter,
384+
"Deployment failed - TransactionForwarder Beacon not initialized correctly, Reverter is not correct."
385+
);
386+
387+
// ------------------------------------------------------------------------
388+
// >>> Orchestrator
389+
390+
// Verify that the Orchestrator Beacon is owned by the Governor
391+
require(
392+
Ownable(address(orchestratorBeacon)).owner() == governor,
393+
"Deployment failed - Orchestrator Beacon not initialized correctly, not owned by Governor."
394+
);
395+
396+
// Verify that the TransactionForwarder is linked correctly in the Orchestrator
397+
require(
398+
Orchestrator_v1(orchestratorBeacon.getImplementationAddress())
399+
.trustedForwarder() == forwarder,
400+
"Deployment failed - Orchestrator Beacon not initialized correctly, Forwarder is not correct."
401+
);
402+
403+
// Verify that the Orchestrator Beacon references the right version
404+
(
405+
uint _orchestratorMajor,
406+
uint _orchestratorMinor,
407+
uint _orchestratorPatch
408+
) = orchestratorBeacon.version();
409+
require(
410+
_orchestratorMajor == orchestratorMetadata.majorVersion
411+
&& _orchestratorMinor == orchestratorMetadata.minorVersion
412+
&& _orchestratorPatch == orchestratorMetadata.patchVersion,
413+
"Deployment failed - Orchestrator Beacon not initialized correctly, version is not correct."
414+
);
415+
416+
// Verify that the Reverter is linked correctly
417+
require(
418+
orchestratorBeacon.getReverterAddress() == inverterReverter,
419+
"Deployment failed - Orchestrator Beacon not initialized correctly, Reverter is not correct."
420+
);
421+
422+
// ------------------------------------------------------------------------
423+
// >>> Modules
424+
425+
for (uint i; i < initialMetadataRegistration.length; i++) {
426+
// Verify that the Module Beacon is linked to the right metadata
427+
(IInverterBeacon_v1 _moduleBeacon,) = ModuleFactory_v1(
428+
moduleFactory
429+
).getBeaconAndId(initialMetadataRegistration[i]);
430+
require(
431+
_moduleBeacon == initialBeaconRegistration[i],
432+
"Deployment failed - Module Metadata doesn't match registration data."
433+
);
434+
435+
// Verify that the Module Beacon is owned by the Governor
436+
require(
437+
Ownable(address(_moduleBeacon)).owner() == governor,
438+
"Deployment failed - Module Beacon not initialized correctly, not owned by Governor."
439+
);
440+
441+
// Verify that the Module Beacon references the right version
442+
(uint _major, uint _minor, uint _patch) = _moduleBeacon.version();
443+
require(
444+
_major == initialMetadataRegistration[i].majorVersion
445+
&& _minor == initialMetadataRegistration[i].minorVersion
446+
&& _patch == initialMetadataRegistration[i].patchVersion,
447+
"Deployment failed - Module Beacon not initialized correctly, version is not correct."
448+
);
449+
450+
// Verify that the Reverter is linked correctly
451+
require(
452+
_moduleBeacon.getReverterAddress() == inverterReverter,
453+
"Deployment failed - Module Beacon not initialized correctly, Reverter is not correct."
454+
);
455+
}
231456
}
232457

233458
modifier verifyRequiredParameters() {

script/deploymentSuite/ProxyAndBeaconDeployer_v1.s.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ contract ProxyAndBeaconDeployer_v1 is Script, ProtocolConstants_v1 {
3535
uint majorVersion,
3636
uint minorVersion,
3737
uint patchVersion
38-
) external returns (address proxy) {
38+
) external returns (address beacon, address proxy) {
3939
// Deploy the beacon.
40-
address beaconAddress = deployInverterBeacon(
40+
beacon = deployInverterBeacon(
4141
implementationName,
4242
reverter,
4343
owner,
@@ -54,7 +54,7 @@ contract ProxyAndBeaconDeployer_v1 is Script, ProtocolConstants_v1 {
5454
vm.getCode(
5555
"InverterBeaconProxy_v1.sol:InverterBeaconProxy_v1"
5656
),
57-
abi.encode(InverterBeacon_v1(beaconAddress))
57+
abi.encode(InverterBeacon_v1(beacon))
5858
)
5959
);
6060
}

script/deploymentSuite/SingletonDeployer_v1.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ contract SingletonDeployer_v1 is ProtocolConstants_v1 {
150150
"OrchestratorFactory_v1",
151151
abi.encodePacked(
152152
vm.getCode("OrchestratorFactory_v1.sol:OrchestratorFactory_v1"),
153-
abi.encode(impl_ext_InverterReverter_v1, transactionForwarder)
153+
abi.encode(transactionForwarder)
154154
)
155155
);
156156

0 commit comments

Comments
 (0)