@@ -219,11 +219,16 @@ function resolveSolidityConfig(
219
219
220
220
// user provided an array of versions or a single version
221
221
if ( Array . isArray ( solidityConfig ) ) {
222
+ const defaultSolidityConfig = {
223
+ compilers : solidityConfig . map ( ( version ) => ( { version } ) ) ,
224
+ } ;
222
225
return {
223
226
profiles : {
224
- default : resolveBuildProfileConfig ( {
225
- compilers : solidityConfig . map ( ( version ) => ( { version } ) ) ,
226
- } ) ,
227
+ default : resolveBuildProfileConfig ( defaultSolidityConfig ) ,
228
+ production : resolveBuildProfileConfig (
229
+ copyFromDefault ( defaultSolidityConfig ) ,
230
+ true ,
231
+ ) ,
227
232
} ,
228
233
npmFilesToBuild : [ ] ,
229
234
} ;
@@ -234,6 +239,10 @@ function resolveSolidityConfig(
234
239
return {
235
240
profiles : {
236
241
default : resolveBuildProfileConfig ( solidityConfig ) ,
242
+ production : resolveBuildProfileConfig (
243
+ copyFromDefault ( solidityConfig ) ,
244
+ true ,
245
+ ) ,
237
246
} ,
238
247
npmFilesToBuild : solidityConfig . npmFilesToBuild ?? [ ] ,
239
248
} ;
@@ -242,28 +251,23 @@ function resolveSolidityConfig(
242
251
// user provided a build profiles config
243
252
const profiles : Record < string , SolidityBuildProfileConfig > = { } ;
244
253
245
- // TODO: Merge the profiles
246
254
for ( const [ profileName , profile ] of Object . entries (
247
255
solidityConfig . profiles ,
248
256
) ) {
249
- const isolated = profile . isolated ?? profileName === "production" ;
250
- const preferWasm = profile . preferWasm ?? profileName === "production" ;
251
-
252
- profiles [ profileName ] = resolveBuildProfileConfig ( {
253
- ...profile ,
254
- isolated,
255
- preferWasm,
256
- } ) ;
257
+ profiles [ profileName ] = resolveBuildProfileConfig (
258
+ profile ,
259
+ profileName === "production" ,
260
+ ) ;
257
261
}
258
262
259
- // This will generate default build profiles (e.g. production) when they are not specified in the config, cloning from 'default', which is always present
263
+ // This will generate default build profiles (e.g. production) when they are
264
+ // not specified in the config, cloning from 'default', which is always present
260
265
for ( const profile of DEFAULT_BUILD_PROFILES ) {
261
266
if ( ! ( profile in profiles ) ) {
262
- profiles [ profile ] = {
263
- ...profiles . default ,
264
- isolated : profile === "production" ,
265
- preferWasm : profile === "production" ,
266
- } ;
267
+ profiles [ profile ] = resolveBuildProfileConfig (
268
+ copyFromDefault ( solidityConfig . profiles . default ) ,
269
+ profile === "production" ,
270
+ ) ;
267
271
}
268
272
}
269
273
@@ -277,33 +281,39 @@ function resolveBuildProfileConfig(
277
281
solidityConfig :
278
282
| SingleVersionSolidityUserConfig
279
283
| MultiVersionSolidityUserConfig ,
284
+ production : boolean = false ,
280
285
) : SolidityBuildProfileConfig {
281
286
if ( "version" in solidityConfig ) {
282
287
return {
283
- compilers : [ resolveSolcConfig ( solidityConfig ) ] ,
288
+ compilers : [ resolveSolcConfig ( solidityConfig , production ) ] ,
284
289
overrides : { } ,
285
- isolated : solidityConfig . isolated ?? false ,
286
- preferWasm : solidityConfig . preferWasm ?? false ,
290
+ isolated : solidityConfig . isolated ?? production ,
291
+ preferWasm : solidityConfig . preferWasm ?? production ,
287
292
} ;
288
293
}
289
294
290
295
return {
291
- compilers : solidityConfig . compilers . map ( resolveSolcConfig ) ,
296
+ compilers : solidityConfig . compilers . map ( ( compiler ) =>
297
+ resolveSolcConfig ( compiler , production ) ,
298
+ ) ,
292
299
overrides : Object . fromEntries (
293
300
Object . entries ( solidityConfig . overrides ?? { } ) . map (
294
301
( [ userSourceName , override ] ) => [
295
302
userSourceName ,
296
- resolveSolcConfig ( override ) ,
303
+ resolveSolcConfig ( override , production ) ,
297
304
] ,
298
305
) ,
299
306
) ,
300
- isolated : solidityConfig . isolated ?? false ,
301
- preferWasm : solidityConfig . preferWasm ?? false ,
307
+ isolated : solidityConfig . isolated ?? production ,
308
+ preferWasm : solidityConfig . preferWasm ?? production ,
302
309
} ;
303
310
}
304
311
305
- function resolveSolcConfig ( solcConfig : SolcUserConfig ) : SolcConfig {
306
- const DEFAULT_SOLC_CONFIG_SETTINGS : SolcConfig [ "settings" ] = {
312
+ function resolveSolcConfig (
313
+ solcConfig : SolcUserConfig ,
314
+ production : boolean = false ,
315
+ ) : SolcConfig {
316
+ const defaultSolcConfigSettings : SolcConfig [ "settings" ] = {
307
317
outputSelection : {
308
318
"*" : {
309
319
"" : [ "ast" ] ,
@@ -318,11 +328,25 @@ function resolveSolcConfig(solcConfig: SolcUserConfig): SolcConfig {
318
328
} ,
319
329
} ;
320
330
331
+ if ( production ) {
332
+ defaultSolcConfigSettings . optimizer = {
333
+ enabled : true ,
334
+ runs : 200 ,
335
+ } ;
336
+ }
337
+
321
338
return {
322
339
version : solcConfig . version ,
323
- settings : deepMerge (
324
- DEFAULT_SOLC_CONFIG_SETTINGS ,
325
- solcConfig . settings ?? { } ,
326
- ) ,
340
+ settings : deepMerge ( defaultSolcConfigSettings , solcConfig . settings ?? { } ) ,
341
+ } ;
342
+ }
343
+
344
+ function copyFromDefault <
345
+ T extends SingleVersionSolidityUserConfig | MultiVersionSolidityUserConfig ,
346
+ > ( defaultSolidityConfig : T ) : T {
347
+ return {
348
+ ...defaultSolidityConfig ,
349
+ isolated : undefined ,
350
+ preferWasm : undefined ,
327
351
} ;
328
352
}
0 commit comments