11const  utils  =  require ( './utils.js' ) 
22const  sanitize  =  require ( './sanitize' ) 
33
4- async  function  migrateDAO  ( {  arcVersion,  web3,  spinner,  confirm,  opts,  migrationParams,  logTx,  previousMigration,  customAbisLocation,  restart,  getState,  setState,  cleanState,  sendTx,  getArcVersionNumber } )  { 
4+ async  function  migrateDAO  ( {  arcVersion,  web3,  spinner,  confirm,  opts,  migrationParams,  logTx,  previousMigration,  customAbisLocation,  restart,  getState,  setState,  cleanState,  sendTx,  getArcVersionNumber,  optimizedAbis  } )  { 
55  const  network  =  await  web3 . eth . net . getNetworkType ( ) 
66  if  ( restart )  { 
77    cleanState ( network ) 
88  } 
99
10+   let  contractsDir  =  'contracts' 
11+   if  ( optimizedAbis )  { 
12+     contractsDir  =  'contracts-optimized' 
13+   } 
14+ 
1015  let  deploymentState  =  getState ( network ) 
1116
1217  // sanitize the parameters 
@@ -46,49 +51,49 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
4651  }  =  base [ arcVersion ] 
4752
4853  const  daoCreator  =  new  web3 . eth . Contract ( 
49-     require ( `./contracts /${ arcVersion }  ) . abi , 
54+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
5055    DaoCreator , 
5156    opts 
5257  ) 
5358
5459  const  uController  =  getArcVersionNumber ( arcVersion )  <  34  ? new  web3 . eth . Contract ( 
55-     require ( `./contracts /${ arcVersion }  ) . abi , 
60+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
5661    UController , 
5762    opts 
5863  )  : null 
5964
6065  const  schemeRegistrar  =  new  web3 . eth . Contract ( 
61-     require ( `./contracts /${ arcVersion }  ) . abi , 
66+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
6267    SchemeRegistrar , 
6368    opts 
6469  ) 
6570
6671  const  contributionReward  =  new  web3 . eth . Contract ( 
67-     require ( `./contracts /${ arcVersion }  ) . abi , 
72+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
6873    ContributionReward , 
6974    opts 
7075  ) 
7176
7277  const  genericScheme  =  new  web3 . eth . Contract ( 
73-     getArcVersionNumber ( arcVersion )  >=  24  &&  getArcVersionNumber ( arcVersion )  <  34  ? require ( `./contracts /${ arcVersion }  ) . abi  : require ( `./contracts /${ arcVersion }  ) . abi , 
78+     getArcVersionNumber ( arcVersion )  >=  24  &&  getArcVersionNumber ( arcVersion )  <  34  ? utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi  : utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
7479    getArcVersionNumber ( arcVersion )  >=  24  &&  getArcVersionNumber ( arcVersion )  <  34  ? UGenericScheme  : GenericScheme , 
7580    opts 
7681  ) 
7782
7883  const  globalConstraintRegistrar  =  new  web3 . eth . Contract ( 
79-     require ( `./contracts /${ arcVersion }  ) . abi , 
84+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
8085    GlobalConstraintRegistrar , 
8186    opts 
8287  ) 
8388
8489  const  upgradeScheme  =  new  web3 . eth . Contract ( 
85-     require ( `./contracts /${ arcVersion }  ) . abi , 
90+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
8691    UpgradeScheme , 
8792    opts 
8893  ) 
8994
9095  const  genesisProtocol  =  new  web3 . eth . Contract ( 
91-     require ( `./contracts /${ arcVersion }  ) . abi , 
96+     utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
9297    GenesisProtocol , 
9398    opts 
9499  ) 
@@ -172,19 +177,19 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
172177    } 
173178
174179    avatar  =  new  web3 . eth . Contract ( 
175-       require ( `./contracts /${ arcVersion }  ) . abi , 
180+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
176181      deploymentState . Avatar , 
177182      opts 
178183    ) 
179184
180185    daoToken  =  new  web3 . eth . Contract ( 
181-       require ( `./contracts /${ arcVersion }  ) . abi , 
186+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
182187      await  avatar . methods . nativeToken ( ) . call ( ) , 
183188      opts 
184189    ) 
185190
186191    reputation  =  new  web3 . eth . Contract ( 
187-       require ( `./contracts /${ arcVersion }  ) . abi , 
192+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
188193      await  avatar . methods . nativeReputation ( ) . call ( ) , 
189194      opts 
190195    ) 
@@ -194,7 +199,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
194199    }  else  { 
195200      spinner . start ( 'Deploying Controller' ) 
196201      controller  =  new  web3 . eth . Contract ( 
197-         require ( `./contracts /${ arcVersion }  ) . abi , 
202+         utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
198203        await  avatar . methods . owner ( ) . call ( ) , 
199204        opts 
200205      ) 
@@ -203,11 +208,11 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
203208  }  else  { 
204209    if  ( deploymentState . DAOToken  ===  undefined )  { 
205210      let  {  receipt,  result }  =  await  sendTx ( new  web3 . eth . Contract ( 
206-         require ( `./contracts /${ arcVersion }  ) . abi , 
211+         utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
207212        undefined , 
208213        opts 
209214      ) . deploy ( { 
210-         data : require ( `./contracts /${ arcVersion }  ) . bytecode , 
215+         data : utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . bytecode , 
211216        arguments : [ tokenName ,  tokenSymbol ,  0 ] 
212217      } ) ,  'Deploying DAO Token' ) 
213218      daoToken  =  result 
@@ -217,18 +222,18 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
217222      setState ( deploymentState ,  network ) 
218223    } 
219224    daoToken  =  new  web3 . eth . Contract ( 
220-       require ( `./contracts /${ arcVersion }  ) . abi , 
225+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
221226      deploymentState . DAOToken , 
222227      opts 
223228    ) 
224229
225230    if  ( deploymentState . Reputation  ===  undefined )  { 
226231      let  {  receipt,  result }  =  await  sendTx ( new  web3 . eth . Contract ( 
227-         require ( `./contracts /${ arcVersion }  ) . abi , 
232+         utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
228233        undefined , 
229234        opts 
230235      ) . deploy ( { 
231-         data : require ( `./contracts /${ arcVersion }  ) . bytecode 
236+         data : utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . bytecode 
232237      } ) ,  'Deploying Reputation' ) 
233238      reputation  =  result 
234239      await  logTx ( receipt ,  `${ reputation . options . address }  ) 
@@ -237,18 +242,18 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
237242      setState ( deploymentState ,  network ) 
238243    } 
239244    reputation  =  new  web3 . eth . Contract ( 
240-       require ( `./contracts /${ arcVersion }  ) . abi , 
245+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
241246      deploymentState . Reputation , 
242247      opts 
243248    ) 
244249
245250    if  ( deploymentState . Avatar  ===  undefined )  { 
246251      let  {  receipt,  result }  =  await  sendTx ( new  web3 . eth . Contract ( 
247-         require ( `./contracts /${ arcVersion }  ) . abi , 
252+         utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
248253        undefined , 
249254        opts 
250255      ) . deploy ( { 
251-         data : require ( `./contracts /${ arcVersion }  ) . bytecode , 
256+         data : utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . bytecode , 
252257        arguments : [ orgName ,  daoToken . options . address ,  reputation . options . address ] 
253258      } ) ,  'Deploying Avatar.' ) 
254259      avatar  =  result 
@@ -258,7 +263,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
258263      setState ( deploymentState ,  network ) 
259264    } 
260265    avatar  =  new  web3 . eth . Contract ( 
261-       require ( `./contracts /${ arcVersion }  ) . abi , 
266+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
262267      deploymentState . Avatar , 
263268      opts 
264269    ) 
@@ -305,11 +310,11 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
305310    }  else  { 
306311      if  ( deploymentState . Controller  ===  undefined )  { 
307312        let  {  receipt,  result }  =  await  sendTx ( new  web3 . eth . Contract ( 
308-           require ( `./contracts /${ arcVersion }  ) . abi , 
313+           utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
309314          undefined , 
310315          opts 
311316        ) . deploy ( { 
312-           data : require ( `./contracts /${ arcVersion }  ) . bytecode , 
317+           data : utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . bytecode , 
313318          arguments : [ avatar . options . address ] 
314319        } ) ,  'Deploying Controller' ) 
315320        controller  =  result 
@@ -319,15 +324,15 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
319324        setState ( deploymentState ,  network ) 
320325      } 
321326      controller  =  new  web3 . eth . Contract ( 
322-         require ( `./contracts /${ arcVersion }  ) . abi , 
327+         utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
323328        deploymentState . Controller , 
324329        opts 
325330      ) 
326331    } 
327332
328333    if  ( migrationParams . noTrack  !==  true  &&  getArcVersionNumber ( arcVersion )  >=  29  &&  deploymentState . trackedDAO  !==  true )  { 
329334      const  daoTracker  =  new  web3 . eth . Contract ( 
330-         require ( `./contracts /${ arcVersion }  ) . abi , 
335+         utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
331336        DAOTracker , 
332337        opts 
333338      ) 
@@ -370,7 +375,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
370375
371376  if  ( network  ===  'private' )  { 
372377    const  daoRegistry  =  new  web3 . eth . Contract ( 
373-       require ( `./contracts /${ arcVersion }  ) . abi , 
378+       utils . importAbi ( `./${ contractsDir } ${ arcVersion }  ) . abi , 
374379      DAORegistry , 
375380      opts 
376381    ) 
@@ -654,7 +659,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
654659      const  path  =  require ( 'path' ) 
655660      let  contractJson 
656661      if  ( standAlone . fromArc )  { 
657-         contractJson  =  require ( `./contracts /${ standAlone . arcVersion  ? standAlone . arcVersion  : arcVersion } ${ standAlone . name }  ) 
662+         contractJson  =  utils . importAbi ( `./${ contractsDir } ${ standAlone . arcVersion  ? standAlone . arcVersion  : arcVersion } ${ standAlone . name }  ) 
658663      }  else  { 
659664        contractJson  =  require ( path . resolve ( `${ customAbisLocation } ${ standAlone . name }  ) ) 
660665      } 
@@ -728,7 +733,7 @@ async function migrateDAO ({ arcVersion, web3, spinner, confirm, opts, migration
728733      const  path  =  require ( 'path' ) 
729734      let  contractJson 
730735      if  ( customeScheme . fromArc )  { 
731-         contractJson  =  require ( `./contracts /${ customeScheme . arcVersion  ? customeScheme . arcVersion  : arcVersion } ${ customeScheme . name }  ) 
736+         contractJson  =  utils . importAbi ( `./${ contractsDir } ${ customeScheme . arcVersion  ? customeScheme . arcVersion  : arcVersion } ${ customeScheme . name }  ) 
732737      }  else  { 
733738        contractJson  =  require ( path . resolve ( `${ customAbisLocation } ${ customeScheme . name }  ) ) 
734739      } 
0 commit comments