@@ -10,45 +10,63 @@ import {
10
10
getCurrentStage ,
11
11
saveContractDeployment ,
12
12
stageAlreadyFinished ,
13
- trackFinishedStage
13
+ trackFinishedStage ,
14
+ saveDeferredTransactionData ,
15
+ writeTransactionToOutputs ,
16
+ getAccounts ,
14
17
} from "@utils/index" ;
15
18
16
- import { initializeManagerCore } from "@utils/deploys/deployUtils" ;
19
+ import { Account } from "@utils/types" ;
20
+ import { InstanceGetter } from "@utils/instanceGetter" ;
17
21
18
22
import { DEPENDENCY } from "../deployments/utils/dependencies" ;
19
23
import { CONTRACT_NAMES } from "../deployments/constants/002_delegated_manager_system" ;
20
24
21
25
const {
26
+ CONTROLLER ,
22
27
SET_TOKEN_CREATOR ,
23
28
ISSUANCE_MODULE ,
24
29
STREAMING_FEE_MODULE ,
25
30
TRADE_MODULE ,
26
31
} = DEPENDENCY ;
27
32
33
+ let owner : Account ;
34
+ let instanceGetter : InstanceGetter ;
35
+
28
36
const CURRENT_STAGE = getCurrentStage ( __filename ) ;
29
37
30
38
const func : DeployFunction = trackFinishedStage ( CURRENT_STAGE , async function ( bre : HRE ) {
31
39
const {
32
40
deploy,
33
41
deployer,
42
+ rawTx,
43
+ networkConstant
34
44
} = await prepareDeployment ( bre ) ;
35
45
46
+ [ owner ] = await getAccounts ( ) ;
47
+ instanceGetter = new InstanceGetter ( owner . wallet ) ;
48
+
36
49
await deployManagerCore ( ) ;
37
50
const managerCoreAddress = await getContractAddress ( CONTRACT_NAMES . MANAGER_CORE ) ;
38
51
52
+ const controllerAddress = await findDependency ( CONTROLLER ) ;
39
53
const setTokenCreatorAddress = await findDependency ( SET_TOKEN_CREATOR ) ;
40
54
await deployDelegatedManagerFactory ( ) ;
41
-
42
- await initializeManagerCore ( CONTRACT_NAMES . DELEGATED_MANAGER_FACTORY , bre ) ;
55
+ const delegatedManagerFactoryAddress = await getContractAddress ( CONTRACT_NAMES . DELEGATED_MANAGER_FACTORY ) ;
43
56
44
57
const issuanceModuleAddress = await findDependency ( ISSUANCE_MODULE ) ;
45
58
await deployIssuanceExtension ( ) ;
59
+ const issuanceExtensionAddress = await getContractAddress ( CONTRACT_NAMES . ISSUANCE_EXTENSION ) ;
46
60
47
61
const streamingFeeModuleAddress = await findDependency ( STREAMING_FEE_MODULE ) ;
48
62
await deployStreamingFeeSplitExtension ( ) ;
63
+ const streamingFeeSplitExtensionAddress = await getContractAddress ( CONTRACT_NAMES . STREAMING_FEE_SPLIT_EXTENSION ) ;
49
64
50
65
const tradeModuleAddress = await findDependency ( TRADE_MODULE ) ;
51
66
await deployTradeExtension ( ) ;
67
+ const tradeExtensionAddress = await getContractAddress ( CONTRACT_NAMES . TRADE_EXTENSION ) ;
68
+
69
+ await initializeManagerCore ( ) ;
52
70
53
71
//
54
72
// Helper Functions
@@ -73,7 +91,7 @@ const func: DeployFunction = trackFinishedStage(CURRENT_STAGE, async function (b
73
91
async function deployDelegatedManagerFactory ( ) : Promise < void > {
74
92
const checkDelegatedManagerFactoryAddress = await getContractAddress ( CONTRACT_NAMES . DELEGATED_MANAGER_FACTORY ) ;
75
93
if ( checkDelegatedManagerFactoryAddress === "" ) {
76
- const constructorArgs = [ managerCoreAddress , setTokenCreatorAddress ] ;
94
+ const constructorArgs = [ managerCoreAddress , controllerAddress , setTokenCreatorAddress ] ;
77
95
const delegatedManagerFactoryDeploy = await deploy (
78
96
CONTRACT_NAMES . DELEGATED_MANAGER_FACTORY ,
79
97
{ from : deployer , args : constructorArgs , log : true }
@@ -141,6 +159,33 @@ const func: DeployFunction = trackFinishedStage(CURRENT_STAGE, async function (b
141
159
} ) ;
142
160
}
143
161
}
162
+
163
+ async function initializeManagerCore ( ) : Promise < void > {
164
+ const managerCoreInstance = await instanceGetter . getManagerCore ( managerCoreAddress ) ;
165
+ if ( ! await managerCoreInstance . isInitialized ( ) ) {
166
+ const data = managerCoreInstance . interface . encodeFunctionData (
167
+ "initialize" ,
168
+ [ [ issuanceExtensionAddress , streamingFeeSplitExtensionAddress , tradeExtensionAddress ] , [ delegatedManagerFactoryAddress ] ]
169
+ ) ;
170
+ const description = "Initialized ManagerCore with DelegatedManagerFactory, IssuanceExtension, StreamingFeeSplitExtension, and TradeExtension" ;
171
+
172
+ if ( ( networkConstant === "production" || process . env . TESTING_PRODUCTION ) ) {
173
+ await saveDeferredTransactionData ( {
174
+ data,
175
+ description,
176
+ contractName : "ManagerCore" ,
177
+ } ) ;
178
+ } else {
179
+ const initializeTransaction : any = await rawTx ( {
180
+ from : deployer ,
181
+ to : managerCoreAddress ,
182
+ data,
183
+ log : true ,
184
+ } ) ;
185
+ await writeTransactionToOutputs ( initializeTransaction . transactionHash , description ) ;
186
+ }
187
+ }
188
+ }
144
189
} ) ;
145
190
146
191
func . skip = stageAlreadyFinished ( CURRENT_STAGE ) ;
0 commit comments