evm-contracts-tools 0.0.47 → 0.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/evm-contract-call/evm-contract-call.js +1 -1
  2. package/dist/evm-contract-deployment-abi/evm-contract-deployment-abi.js +2 -0
  3. package/dist/evm-contract-deployment-address/evm-contract-deployment-address.js +2 -0
  4. package/dist/evm-contract-deployment-bytecode/evm-contract-deployment-bytecode.js +2 -0
  5. package/dist/evm-contract-deployment-compiler-output/evm-contract-deployment-compiler-output.js +2 -0
  6. package/dist/evm-contract-deployment-networks/evm-contract-deployment-networks.js +1 -1
  7. package/dist/evm-contract-deployment-versions/evm-contract-deployment-versions.js +1 -1
  8. package/dist/evm-contract-deployments-dir/evm-contract-deployments-dir.js +1 -1
  9. package/dist/evm-contracts-tools/evm-contracts-tools.js +1 -1
  10. package/dist/libevm-contract-call/libevm-contract-call.js +1 -1
  11. package/dist/libevm-contract-deployment-abi/libevm-contract-deployment-abi.js +1 -1
  12. package/dist/libevm-contract-deployment-address/libevm-contract-deployment-address.js +2 -0
  13. package/dist/libevm-contract-deployment-bytecode/libevm-contract-deployment-bytecode.js +2 -0
  14. package/dist/libevm-contract-deployment-networks/libevm-contract-deployment-networks.js +1 -1
  15. package/dist/libevm-contract-deployment-versions/libevm-contract-deployment-versions.js +1 -1
  16. package/dist/libevm-contract-deployments-dir/libevm-contract-deployments-dir.js +1 -1
  17. package/evm-contract-deployment-abi +19 -21
  18. package/evm-contract-deployment-address +11 -11
  19. package/evm-contract-deployment-bytecode +18 -20
  20. package/evm-contract-deployment-compiler-output +19 -22
  21. package/evm-contract-deployments-dir +24 -34
  22. package/libevm-contract-call +0 -18
  23. package/libevm-contract-deployment +650 -0
  24. package/libevm-contract-deployment-abi +13 -32
  25. package/libevm-contract-deployment-address +20 -37
  26. package/libevm-contract-deployment-bytecode +13 -33
  27. package/libevm-contract-deployment-compiler-output +41 -458
  28. package/libevm-contract-deployment-networks +28 -72
  29. package/libevm-contract-deployment-versions +26 -50
  30. package/libevm-contract-deployments-dir +13 -21
  31. package/package.json +14 -11
@@ -0,0 +1,650 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ /** ----------------------------------------------------------------
6
+ * libevm-contract-deployment
7
+ * ----------------------------------------------------------------
8
+ * Copyright ©
9
+ * Pellegrino Prevete
10
+ * 2025, 2026
11
+ *
12
+ * All rights reserved
13
+ * ----------------------------------------------------------------
14
+ *
15
+ * This program is free software: you can redistribute it and/or
16
+ * modify it under the terms of the GNU General Public License as
17
+ * published by the Free Software Foundation, either version 3 of
18
+ * the License, or (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the
26
+ * GNU General Public License
27
+ * along with this program.
28
+ * If not, see <https://www.gnu.org/licenses/>.
29
+ */
30
+
31
+ /* eslint-disable
32
+ no-unused-vars */
33
+ /* eslint-disable
34
+ no-useless-assignment */
35
+
36
+ /* EVM Contracts tools global variables */
37
+ /* global
38
+ call_type */
39
+ /* global
40
+ call_auth:
41
+ writable */
42
+
43
+ /* libEVM global variables */
44
+ /* global
45
+ api_key */
46
+ /* global
47
+ contract_abi:
48
+ writable */
49
+ /* global
50
+ contract_address */
51
+ /* global
52
+ contract_bytecode:
53
+ writable */
54
+ /* global
55
+ contract_compiler_output:
56
+ writable */
57
+ /* global
58
+ target_network:
59
+ writable */
60
+ /* global
61
+ target_networks:
62
+ writable */
63
+
64
+ const
65
+ _libcrash_module =
66
+ require(
67
+ "crash-js");
68
+ /* global
69
+ _basename */
70
+ const
71
+ _basename =
72
+ _libcrash_module._basename;
73
+ /* global
74
+ _chmod */
75
+ const
76
+ _chmod =
77
+ _libcrash_module._chmod;
78
+ /* global
79
+ _cp */
80
+ /* eslint-disable-next-line
81
+ no-global-assign */
82
+ const
83
+ _cp =
84
+ _libcrash_module._cp;
85
+ /* global
86
+ _dir_exists */
87
+ const
88
+ _dir_exists =
89
+ _libcrash_module._dir_exists;
90
+ /* global
91
+ _file_exists */
92
+ const
93
+ _file_exists =
94
+ _libcrash_module._file_exists;
95
+ /* global
96
+ _file_read */
97
+ /* eslint-disable-next-line
98
+ no-global-assign */
99
+ const
100
+ _file_read =
101
+ _libcrash_module._file_read;
102
+ /* global
103
+ _from_bash_ass_array */
104
+ /* eslint-disable-next-line
105
+ no-global-assign */
106
+ const
107
+ _from_bash_ass_array =
108
+ _libcrash_module._from_bash_ass_array;
109
+ /* global
110
+ _homedir_get */
111
+ /* eslint-disable-next-line
112
+ no-global-assign */
113
+ const
114
+ _homedir_get =
115
+ _libcrash_module._homedir_get;
116
+ /* global
117
+ _json_read */
118
+ /* eslint-disable-next-line
119
+ no-global-assign */
120
+ const
121
+ _json_read =
122
+ _libcrash_module._json_read;
123
+ /* global
124
+ _mkdir */
125
+ /* eslint-disable-next-line
126
+ no-global-assign */
127
+ const
128
+ _mkdir =
129
+ _libcrash_module._mkdir;
130
+ /* global
131
+ _msg_info */
132
+ /* eslint-disable-next-line
133
+ no-global-assign */
134
+ const
135
+ _msg_info =
136
+ _libcrash_module._msg_info;
137
+ /* global
138
+ _msg_error */
139
+ /* eslint-disable-next-line
140
+ no-global-assign */
141
+ const
142
+ _msg_error =
143
+ _libcrash_module._msg_error;
144
+ /* global
145
+ _override_set */
146
+ const
147
+ _override_set =
148
+ _libcrash_module._override_set;
149
+ /* global
150
+ _path_join */
151
+ /* eslint-disable-next-line
152
+ no-global-assign */
153
+ const
154
+ _path_join =
155
+ _libcrash_module._path_join;
156
+ /* global
157
+ _pwd */
158
+ const
159
+ _pwd =
160
+ _libcrash_module._pwd;
161
+ const
162
+ _evm_chains_info_module =
163
+ require(
164
+ "evm-chains-info");
165
+ /* global
166
+ _evm_chains_info */
167
+ const
168
+ _evm_chains_info =
169
+ _evm_chains_info_module._evm_chains_info;
170
+ const
171
+ _libevm_contract_deployments_dir_module =
172
+ require(
173
+ "./libevm-contract-deployments-dir");
174
+ /* global
175
+ _evm_contract_deployments_dir */
176
+ const
177
+ _evm_contract_deployments_dir =
178
+ _libevm_contract_deployments_dir_module._evm_contract_deployments_dir;
179
+ const
180
+ _libevm_contract_deployment_networks_module =
181
+ require(
182
+ "./libevm-contract-deployment-networks");
183
+ /* global
184
+ _evm_contract_deployment_networks */
185
+ const
186
+ _evm_contract_deployment_networks =
187
+ _libevm_contract_deployment_networks_module._evm_contract_deployment_networks;
188
+ const
189
+ _libevm_contract_deployment_versions_module =
190
+ require(
191
+ "./libevm-contract-deployment-versions");
192
+ /* global
193
+ _evm_contract_deployment_versions */
194
+ const
195
+ _evm_contract_deployment_versions =
196
+ _libevm_contract_deployment_versions_module._evm_contract_deployment_versions;
197
+
198
+ async function
199
+ _network_check(
200
+ _deployments,
201
+ _contract,
202
+ _target_network,
203
+ _target_network_id) {
204
+ let
205
+ _error_flag,
206
+ _msg,
207
+ _network_id;
208
+ _error_flag =
209
+ false;
210
+ _deployments_path =
211
+ _path_join( [
212
+ _deployments,
213
+ _contract ]);
214
+ const
215
+ _evm_contract_deployment_networks_args = [
216
+ _deployments_path,
217
+ "y", // Display all
218
+ "n", // Display safest
219
+ "n" // Display cheapest
220
+ ];
221
+ const
222
+ _networks =
223
+ await _evm_contract_deployment_networks.apply(
224
+ null,
225
+ _evm_contract_deployment_networks_args);
226
+ if ( _target_network_id != "" ) {
227
+ if ( ! _networks.includes(
228
+ _target_network_id) ) {
229
+ _msg =
230
+ "The contract does not result deployed on " +
231
+ `network with id '${_target_network_id}'.`;
232
+ _error_flag =
233
+ true;
234
+ }
235
+ }
236
+ else if ( _target_network != "" ) {
237
+ if ( ! _networks.includes(
238
+ _target_network) ) {
239
+ _msg =
240
+ "The contract does not result deployed on " +
241
+ `network '${_target_network}'.`;
242
+ _error_flag =
243
+ true;
244
+ }
245
+ }
246
+ else {
247
+ _msg =
248
+ "Provide one between a target network name " +
249
+ "or ID.";
250
+ _error_flag =
251
+ true;
252
+ }
253
+ if ( _error_flag ) {
254
+ _msg_error(
255
+ _msg,
256
+ 1);
257
+ }
258
+ if ( _target_network_id == "" ) {
259
+ _evm_chains_info_args = [
260
+ "get", // target command
261
+ "name", // input type
262
+ "id", // output type
263
+ "offline",
264
+ [ "system", // db types
265
+ "node" ],
266
+ "kirsh", // selection method, first
267
+ "n", // api keys
268
+ "n", // query all networks
269
+ _target_network,
270
+ [] // database paths
271
+ ];
272
+ _network_id =
273
+ await _evm_chains_info.apply(
274
+ null,
275
+ _evm_chains_info_args);
276
+ }
277
+ else if ( _target_network == "" ) {
278
+ _evm_chains_info_args = [
279
+ "get", // target command
280
+ "id" , // input type
281
+ "name", // output type
282
+ "offline",
283
+ [ "system", // db types
284
+ "node" ],
285
+ "kirsh", // selection method, first
286
+ "n", // api keys
287
+ "n", // query all networks
288
+ _target_network_id,
289
+ [] // database paths
290
+ ];
291
+ _target_network =
292
+ await _evm_chains_info(
293
+ _evm_chains_info_args);
294
+ }
295
+ if ( _target_network_id != "" ) {
296
+ if ( _target_network_id != _network_id ) {
297
+ _msg =
298
+ "Requested target network ID " +
299
+ `'${_target_network_id}' does ` +
300
+ `not correspond to '${_target_network}' ` +
301
+ `known ID '${_network_id}'.`;
302
+ _msg_error(
303
+ _msg,
304
+ 1);
305
+ }
306
+ }
307
+ }
308
+
309
+ async function
310
+ _user_deployments_init(
311
+ _app,
312
+ _deployments_dir) {
313
+ const
314
+ _user_defined =
315
+ "y";
316
+ const
317
+ _evm_contract_deployments_dir_args = [
318
+ _app,
319
+ _user_defined
320
+ ];
321
+ const
322
+ _system_deployments =
323
+ await _evm_contract_deployments_dir.apply(
324
+ null,
325
+ _evm_contract_deployments_dir_args);
326
+ _chmod(
327
+ _deployments_dir,
328
+ "0700");
329
+ const
330
+ _files =
331
+ await _ls(
332
+ _system_deployments);
333
+ for ( _file of _files ) {
334
+ _cp(
335
+ _file,
336
+ _deployments_dir);
337
+ }
338
+ return true;
339
+ }
340
+
341
+ async function
342
+ _user_deployments_check(
343
+ _app,
344
+ _deployments_dir) {
345
+ if ( ! _file_exists(
346
+ _deployments_dir) ) {
347
+ const
348
+ _user_deployments_init_args = [
349
+ _app,
350
+ _deployments_dir
351
+ ];
352
+ const
353
+ _initialized =
354
+ await _user_deployments_init.apply(
355
+ null,
356
+ _user_deployments_init_args);
357
+ }
358
+ }
359
+
360
+ async function
361
+ _deployments_dir_auto_detect() {
362
+ let
363
+ _deployments;
364
+ _deployments =
365
+ "";
366
+ const
367
+ _app =
368
+ target_app;
369
+ const
370
+ _app_type =
371
+ typeof(
372
+ _app);
373
+ if ( _app_type != "undefined" &&
374
+ _app != "" ) {
375
+ const
376
+ _user_defined =
377
+ user_defined;
378
+ const
379
+ _evm_contract_deployments_dir_args = [
380
+ _app,
381
+ _user_defined
382
+ ];
383
+ _deployments =
384
+ await _evm_contract_deployments_dir.apply(
385
+ null,
386
+ _evm_contract_deployments_dir_args);
387
+ }
388
+ _override_set(
389
+ "deployments",
390
+ "dir",
391
+ _deployments);
392
+ }
393
+
394
+ async function
395
+ _contract_version_auto_detect() {
396
+ let
397
+ _config,
398
+ _config_ext,
399
+ _deployments,
400
+ _found,
401
+ _net,
402
+ _network,
403
+ _network_id,
404
+ _networks,
405
+ _version,
406
+ _msg;
407
+ _networks =
408
+ [];
409
+ const
410
+ _contract =
411
+ target_contract;
412
+ _found =
413
+ false;
414
+ if ( configuration_format == "bash" ) {
415
+ _config_ext =
416
+ "sh";
417
+ }
418
+ else if ( configuration_format == "bash" ) {
419
+ _config_ext =
420
+ "json";
421
+ }
422
+ const
423
+ _contract_type =
424
+ typeof(
425
+ _contract);
426
+ if ( _contract != "" &&
427
+ _contract_type != "undefined" ) {
428
+ const
429
+ _deployments_dir_type =
430
+ typeof(
431
+ deployments_dir);
432
+ if ( _deployments_dir_type != "undefined" &&
433
+ deployments_dir != "" ) {
434
+ _deployments =
435
+ deployments_dir;
436
+ if ( 0 < target_networks.length ) {
437
+ _network =
438
+ target_networks[
439
+ 0];
440
+ }
441
+ if ( 0 < network_ids.length ) {
442
+ _network_id =
443
+ _network_ids[
444
+ 0];
445
+ }
446
+ const
447
+ _deployments_path =
448
+ _path_join( [
449
+ _deployments,
450
+ _contract ] );
451
+ if ( networks_all == "n" ) {
452
+ _networks.push(
453
+ _network,
454
+ _network_id);
455
+ }
456
+ else if ( networks_all == "y" ) {
457
+ const
458
+ _evm_contract_deployment_networks_args = [
459
+ _deployments_path,
460
+ "y", // Display all
461
+ "n", // Display safest
462
+ "n" // Display cheapest
463
+ ];
464
+ _networks_new =
465
+ await _evm_contract_deployment_networks.apply(
466
+ null,
467
+ _evm_contract_deployment_networks_args);
468
+ _networks =
469
+ _networks.concat(
470
+ _networks_new);
471
+ }
472
+ for ( _net of _networks ) {
473
+ _config =
474
+ _path_join( [
475
+ _deployments_path,
476
+ _net,
477
+ `config.${_config_ext}`
478
+ ]);
479
+ if ( _file_exists(
480
+ _config) ) {
481
+ _found =
482
+ true;
483
+ _msg =
484
+ `Found deployment configuration ` +
485
+ `at location '${_config}'.`;
486
+ _msg_info(
487
+ _msg);
488
+ break;
489
+ }
490
+ }
491
+ if ( ! _found ) {
492
+ _msg =
493
+ "No deployment configuration " +
494
+ "file found for network " +
495
+ `'${_network}' with ID ` +
496
+ `'${_network_id}'.`;
497
+ _msg_error(
498
+ _msg,
499
+ 1);
500
+ }
501
+ const
502
+ _evm_contract_deployment_versions_args = [
503
+ _config,
504
+ "y", // display highest
505
+ "n", // display lowest
506
+ configuration_format
507
+ ];
508
+ _version =
509
+ await _evm_contract_deployment_versions.apply(
510
+ null,
511
+ _evm_contract_deployment_versions_args);
512
+ }
513
+ else if ( _deployments_dir_type == "undefined" ||
514
+ deployments_dir == "" ) {
515
+ const
516
+ _msg =
517
+ "If no target application is specified " +
518
+ "then the user-defined deployments " +
519
+ "switch must be enabled with '-u' and " +
520
+ "a deployments directory must be specified " +
521
+ "with '-d'.";
522
+ _msg_error(
523
+ _msg,
524
+ 1);
525
+ }
526
+ }
527
+ _override_set(
528
+ "contract",
529
+ "version",
530
+ _version);
531
+ return true;
532
+ }
533
+
534
+ function
535
+ _networks_all_auto_detect() {
536
+ let
537
+ _networks_all;
538
+ _networks_all =
539
+ "n";
540
+ if ( target_networks.length < 1 &&
541
+ network_ids.length < 1 ) {
542
+ _networks_all =
543
+ "y";
544
+ }
545
+ _override_set(
546
+ "networks",
547
+ "all",
548
+ _networks_all);
549
+ }
550
+
551
+ async function
552
+ _target_app_auto_detect() {
553
+ let
554
+ _app;
555
+ _app =
556
+ "";
557
+ const
558
+ _dir_current_name =
559
+ _basename(
560
+ _pwd());
561
+ const
562
+ _user_defined =
563
+ user_defined;
564
+ const
565
+ _evm_contract_deployments_dir_args = [
566
+ _dir_current_name,
567
+ _user_defined
568
+ ];
569
+ const
570
+ _target_dir =
571
+ await _evm_contract_deployments_dir.apply(
572
+ null,
573
+ _evm_contract_deployments_dir_args);
574
+ if ( _dir_exists(
575
+ _target_dir) ) {
576
+ _app =
577
+ _dir_current_name;
578
+ }
579
+ else {
580
+ _msg =
581
+ `Directory '${_target_dir}' ` +
582
+ "not found.";
583
+ _msg_info(
584
+ _msg);
585
+ }
586
+ _override_set(
587
+ "target",
588
+ "app",
589
+ _app);
590
+ }
591
+
592
+ function
593
+ _configuration_format_get(
594
+ _config_file) {
595
+ let
596
+ _configuration_format;
597
+ if ( _config_file.endsWith(
598
+ ".sh") ) {
599
+ _configuration_format =
600
+ "bash";
601
+ }
602
+ else if ( _config_file.endsWith(
603
+ ".json") ) {
604
+ _configuration_format =
605
+ "json";
606
+ }
607
+ else {
608
+ const
609
+ _msg =
610
+ "Impossible determining " +
611
+ "configuration format from file " +
612
+ "extension, defaulting to 'json'.";
613
+ _msg_info(
614
+ _msg,
615
+ 0);
616
+ throw _msg;
617
+ }
618
+ return _configuration_format;
619
+ }
620
+
621
+ function
622
+ _configuration_format_auto_detect() {
623
+ const
624
+ _configuration_format =
625
+ _configuration_format_get(
626
+ config_file);
627
+ _override_set(
628
+ "configuration",
629
+ "format",
630
+ _configuration_format);
631
+ }
632
+
633
+ module.exports = {
634
+ _configuration_format_auto_detect:
635
+ _configuration_format_auto_detect,
636
+ _configuration_format_get:
637
+ _configuration_format_get,
638
+ _contract_version_auto_detect:
639
+ _contract_version_auto_detect,
640
+ _deployments_dir_auto_detect:
641
+ _deployments_dir_auto_detect,
642
+ _network_check:
643
+ _network_check,
644
+ _networks_all_auto_detect:
645
+ _networks_all_auto_detect,
646
+ _target_app_auto_detect:
647
+ _target_app_auto_detect,
648
+ _user_deployments_check:
649
+ _user_deployments_check,
650
+ };