jaelis-node 1.10.0 → 2.0.0

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 (173) hide show
  1. package/README.md +146 -445
  2. package/bin/jaelis-node.js +79 -504
  3. package/lib/index.js +31 -2840
  4. package/lib/node.js +271 -0
  5. package/lib/rpc.js +315 -0
  6. package/lib/storage.js +198 -0
  7. package/lib/sync.js +366 -0
  8. package/package.json +19 -53
  9. package/config/default.json +0 -74
  10. package/config/mainnet.json +0 -30
  11. package/config/testnet.json +0 -26
  12. package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +0 -454
  13. package/lib/JAELIS-VM/lib/adapters/index.js +0 -411
  14. package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +0 -457
  15. package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +0 -1097
  16. package/lib/JAELIS-VM/lib/execution/engine.js +0 -1183
  17. package/lib/JAELIS-VM/lib/index.js +0 -440
  18. package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +0 -543
  19. package/lib/JAELIS-VM/lib/serialization/serializer.js +0 -819
  20. package/lib/JAELIS-VM/lib/state/state-manager.js +0 -1116
  21. package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +0 -1222
  22. package/lib/JAELIS-VM/lib/unified/cross-chain-deploy.js +0 -1678
  23. package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +0 -836
  24. package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +0 -1127
  25. package/lib/JAELIS-VM/lib/unified/index.js +0 -456
  26. package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +0 -1150
  27. package/lib/JAELIS-VM/lib/unified/unified-compiler.js +0 -1350
  28. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +0 -12
  29. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +0 -17
  30. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +0 -28
  31. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +0 -12
  32. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +0 -17
  33. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +0 -28
  34. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  35. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  36. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  37. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  38. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  39. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  40. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  41. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  42. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  43. package/lib/JAELIS-VM/node_modules/.package-lock.json +0 -127
  44. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +0 -1
  45. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
  46. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
  47. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
  48. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +0 -17
  49. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +0 -1
  50. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
  51. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
  52. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
  53. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +0 -17
  54. package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +0 -21
  55. package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +0 -5
  56. package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +0 -11
  57. package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +0 -60
  58. package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +0 -1
  59. package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +0 -50
  60. package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +0 -198
  61. package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +0 -21
  62. package/lib/JAELIS-VM/node_modules/cbor-x/README.md +0 -380
  63. package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +0 -11
  64. package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +0 -73
  65. package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +0 -11
  66. package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +0 -2
  67. package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +0 -1300
  68. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +0 -1244
  69. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +0 -1
  70. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +0 -2509
  71. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +0 -1
  72. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +0 -2
  73. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +0 -1
  74. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +0 -2508
  75. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +0 -1
  76. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +0 -2
  77. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +0 -1
  78. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +0 -2629
  79. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +0 -1
  80. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +0 -3343
  81. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +0 -1
  82. package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +0 -1
  83. package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +0 -1231
  84. package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +0 -79
  85. package/lib/JAELIS-VM/node_modules/cbor-x/index.js +0 -3
  86. package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +0 -85
  87. package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +0 -24
  88. package/lib/JAELIS-VM/node_modules/cbor-x/package.json +0 -94
  89. package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +0 -88
  90. package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +0 -61
  91. package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +0 -19
  92. package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +0 -201
  93. package/lib/JAELIS-VM/node_modules/detect-libc/README.md +0 -163
  94. package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +0 -14
  95. package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +0 -313
  96. package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +0 -39
  97. package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +0 -51
  98. package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +0 -24
  99. package/lib/JAELIS-VM/node_modules/detect-libc/package.json +0 -44
  100. package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +0 -21
  101. package/lib/JAELIS-VM/node_modules/msgpackr/README.md +0 -372
  102. package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +0 -11
  103. package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +0 -67
  104. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +0 -2407
  105. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +0 -1
  106. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +0 -2
  107. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +0 -1
  108. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +0 -2406
  109. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +0 -1
  110. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +0 -2
  111. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +0 -1
  112. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +0 -3320
  113. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +0 -1
  114. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +0 -4540
  115. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +0 -1
  116. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +0 -1250
  117. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +0 -1
  118. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +0 -91
  119. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +0 -91
  120. package/lib/JAELIS-VM/node_modules/msgpackr/index.js +0 -5
  121. package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +0 -87
  122. package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +0 -25
  123. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +0 -1
  124. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +0 -1
  125. package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +0 -1141
  126. package/lib/JAELIS-VM/node_modules/msgpackr/package.json +0 -104
  127. package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +0 -88
  128. package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +0 -57
  129. package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +0 -815
  130. package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +0 -3
  131. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +0 -2
  132. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +0 -2
  133. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +0 -1221
  134. package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +0 -21
  135. package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +0 -5
  136. package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +0 -13
  137. package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +0 -63
  138. package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +0 -1
  139. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  140. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  141. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  142. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  143. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  144. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  145. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  146. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  147. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  148. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  149. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  150. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +0 -82
  151. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  152. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +0 -6
  153. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +0 -236
  154. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  155. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  156. package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +0 -50
  157. package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +0 -274
  158. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  159. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  160. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +0 -77
  161. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  162. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +0 -224
  163. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  164. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  165. package/lib/JAELIS-VM/package-lock.json +0 -284
  166. package/lib/JAELIS-VM/package.json +0 -38
  167. package/lib/JAELIS-VM/test/comprehensive.test.js +0 -267
  168. package/lib/JAELIS-VM/test/cross-chain-test.js +0 -470
  169. package/lib/JAELIS-VM/test/unified-vm-test.js +0 -459
  170. package/lib/JAELIS-VM/test/unified.test.js +0 -166
  171. package/lib/JAELIS-VM/test/vm.test.js +0 -599
  172. package/lib/settlement-server.js +0 -999
  173. package/lib/vm/index.js +0 -397
@@ -1,440 +0,0 @@
1
- /**
2
- * JAELIS UNIVERSAL VIRTUAL MACHINE (JVM)
3
- *
4
- * TRUE CROSS-CHAIN INTEROPERABILITY
5
- *
6
- * Architecture:
7
- * ┌─────────────────────────────────────────────────────────────────┐
8
- * │ JAELIS UNIVERSAL VM │
9
- * ├─────────────────────────────────────────────────────────────────┤
10
- * │ Frontend Compilers (Source → JIR) │
11
- * │ ┌─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐ │
12
- * │ │Solidity │ Rust │ Move │ FunC │ Cairo │ WASM │ │
13
- * │ │ (EVM) │ (SVM) │(Aptos) │ (TON) │(Stark) │(Cosmos) │ │
14
- * │ └────┬────┴────┬────┴────┬────┴────┬────┴────┬────┴────┬────┘ │
15
- * │ │ │ │ │ │ │ │
16
- * │ └─────────┴─────────┴────┬────┴─────────┴─────────┘ │
17
- * │ │ │
18
- * │ ┌─────────────────────────────▼─────────────────────────────┐ │
19
- * │ │ JAELIS INTERMEDIATE REPRESENTATION (JIR) │ │
20
- * │ │ │ │
21
- * │ │ • WASM 3.0 Core (64-bit addressing, GC, threads) │ │
22
- * │ │ • Extended opcodes for blockchain operations │ │
23
- * │ │ • Account model abstraction layer │ │
24
- * │ │ • Cross-VM state management │ │
25
- * │ └─────────────────────────────┬─────────────────────────────┘ │
26
- * │ │ │
27
- * │ ┌─────────────────────────────▼─────────────────────────────┐ │
28
- * │ │ EXECUTION ENGINE │ │
29
- * │ │ │ │
30
- * │ │ • Interpreter (development/debugging) │ │
31
- * │ │ • AOT Compiler (production, 10x faster) │ │
32
- * │ │ • JIT Compiler (hot paths optimization) │ │
33
- * │ └─────────────────────────────┬─────────────────────────────┘ │
34
- * │ │ │
35
- * │ ┌─────────────────────────────▼─────────────────────────────┐ │
36
- * │ │ SERIALIZATION LAYER │ │
37
- * │ │ │ │
38
- * │ │ • CBOR-X (3-10x faster than JSON) │ │
39
- * │ │ • MessagePack (37% smaller than JSON) │ │
40
- * │ │ • Wincode-style zero-copy deserialization │ │
41
- * │ └───────────────────────────────────────────────────────────┘ │
42
- * └─────────────────────────────────────────────────────────────────┘
43
- *
44
- * @version 0.1.0
45
- * @author Mario Papaleo - JAELIS Foundation
46
- * @patent PATENT PENDING - Universal Multi-Chain Virtual Machine
47
- */
48
-
49
- const EventEmitter = require('events');
50
- const path = require('path');
51
-
52
- // Fast serialization
53
- let cborx, msgpackr;
54
- try {
55
- cborx = require('cbor-x');
56
- msgpackr = require('msgpackr');
57
- } catch (e) {
58
- // Will use fallback JSON if not installed
59
- }
60
-
61
- // Import VM components
62
- const JIRCompiler = require('./compiler/jir-compiler');
63
- const ExecutionEngine = require('./execution/engine');
64
- const StateManager = require('./state/state-manager');
65
- const Serializer = require('./serialization/serializer');
66
- const BytecodeTranslator = require('./translator/bytecode-translator');
67
-
68
- /**
69
- * JAELIS Universal Virtual Machine
70
- *
71
- * Supports execution of bytecode from ANY blockchain:
72
- * - EVM (Ethereum, BSC, Polygon, Arbitrum, etc.)
73
- * - SVM (Solana BPF/sBPF)
74
- * - Move (Aptos, Sui, Movement)
75
- * - TVM (TON)
76
- * - WASM (Cosmos, Polkadot, NEAR)
77
- * - Cairo (Starknet)
78
- * - Bitcoin Script
79
- */
80
- class JaelisUniversalVM extends EventEmitter {
81
- constructor(config = {}) {
82
- super();
83
-
84
- this.config = {
85
- // Execution mode: 'interpreter' | 'aot' | 'jit'
86
- executionMode: config.executionMode || 'interpreter',
87
-
88
- // Memory limits (WASM 3.0 supports 64-bit!)
89
- maxMemory: config.maxMemory || 1024 * 1024 * 1024, // 1GB default
90
- maxStack: config.maxStack || 1024 * 1024 * 64, // 64MB stack
91
- maxHeap: config.maxHeap || 1024 * 1024 * 512, // 512MB heap
92
-
93
- // Serialization
94
- serializer: config.serializer || 'cbor', // 'cbor' | 'msgpack' | 'json'
95
-
96
- // Gas/Lode metering
97
- meteringEnabled: config.meteringEnabled !== false,
98
- maxInstructions: config.maxInstructions || 100000000, // 100M instructions
99
-
100
- // Debug
101
- debug: config.debug || false,
102
- trace: config.trace || false,
103
-
104
- ...config
105
- };
106
-
107
- // Core components
108
- this.compiler = new JIRCompiler(this.config);
109
- this.engine = new ExecutionEngine(this.config);
110
- this.state = new StateManager(this.config);
111
- this.serializer = new Serializer(this.config);
112
- this.translator = new BytecodeTranslator(this.config);
113
-
114
- // Supported source VMs
115
- this.supportedVMs = {
116
- evm: { name: 'Ethereum Virtual Machine', chains: ['ethereum', 'bsc', 'polygon', 'arbitrum', 'optimism', 'base', 'avalanche'] },
117
- svm: { name: 'Solana Virtual Machine', chains: ['solana'] },
118
- move: { name: 'Move Virtual Machine', chains: ['aptos', 'sui', 'movement'] },
119
- tvm: { name: 'TON Virtual Machine', chains: ['ton'] },
120
- wasm: { name: 'WebAssembly', chains: ['cosmos', 'polkadot', 'near'] },
121
- cairo: { name: 'Cairo VM', chains: ['starknet'] },
122
- bitcoin: { name: 'Bitcoin Script', chains: ['bitcoin', 'litecoin'] }
123
- };
124
-
125
- // Metrics
126
- this.metrics = {
127
- executionsTotal: 0,
128
- executionsByVM: new Map(),
129
- bytesProcessed: 0,
130
- instructionsExecuted: 0,
131
- averageExecutionTime: 0
132
- };
133
-
134
- // Program cache
135
- this.programCache = new Map();
136
-
137
- console.log('═══════════════════════════════════════════════════════════════');
138
- console.log(' JAELIS UNIVERSAL VIRTUAL MACHINE v0.1.0');
139
- console.log('═══════════════════════════════════════════════════════════════');
140
- console.log(' Core: WASM 3.0 (64-bit addressing, GC, threads)');
141
- console.log(` Mode: ${this.config.executionMode.toUpperCase()}`);
142
- console.log(` Serialization: ${this.config.serializer.toUpperCase()} (3-10x faster than JSON)`);
143
- console.log(' Supported VMs:');
144
- for (const [id, vm] of Object.entries(this.supportedVMs)) {
145
- console.log(` • ${vm.name} (${id.toUpperCase()})`);
146
- }
147
- console.log('═══════════════════════════════════════════════════════════════');
148
- }
149
-
150
- /**
151
- * Compile source code to JIR (JAELIS Intermediate Representation)
152
- *
153
- * @param {string} sourceCode - Source code in any supported language
154
- * @param {string} sourceVM - Source VM type ('evm', 'svm', 'move', etc.)
155
- * @param {object} options - Compilation options
156
- * @returns {object} Compiled JIR module
157
- */
158
- async compile(sourceCode, sourceVM, options = {}) {
159
- const startTime = Date.now();
160
-
161
- if (!this.supportedVMs[sourceVM]) {
162
- throw new Error(`Unsupported source VM: ${sourceVM}. Supported: ${Object.keys(this.supportedVMs).join(', ')}`);
163
- }
164
-
165
- console.log(`[JVM] Compiling ${sourceVM.toUpperCase()} code to JIR...`);
166
-
167
- // Step 1: Parse source code to AST
168
- const ast = await this.compiler.parse(sourceCode, sourceVM);
169
-
170
- // Step 2: Semantic analysis
171
- const analyzed = await this.compiler.analyze(ast, sourceVM);
172
-
173
- // Step 3: Generate JIR (JAELIS Intermediate Representation)
174
- const jir = await this.compiler.generateJIR(analyzed, sourceVM, options);
175
-
176
- // Step 4: Optimize JIR
177
- const optimizedJIR = await this.compiler.optimize(jir, options.optimizationLevel || 2);
178
-
179
- // Step 5: Cache compiled module
180
- const moduleId = this._generateModuleId(sourceCode, sourceVM);
181
- this.programCache.set(moduleId, optimizedJIR);
182
-
183
- const compileTime = Date.now() - startTime;
184
- console.log(`[JVM] Compilation complete in ${compileTime}ms`);
185
- console.log(`[JVM] Module ID: ${moduleId.substring(0, 16)}...`);
186
- console.log(`[JVM] JIR size: ${optimizedJIR.bytecode.length} bytes`);
187
-
188
- return {
189
- moduleId,
190
- jir: optimizedJIR,
191
- sourceVM,
192
- compileTime,
193
- metadata: {
194
- functions: optimizedJIR.functions?.length || 0,
195
- imports: optimizedJIR.imports?.length || 0,
196
- exports: optimizedJIR.exports?.length || 0
197
- }
198
- };
199
- }
200
-
201
- /**
202
- * Deploy bytecode from any VM
203
- *
204
- * @param {Buffer|string} bytecode - Compiled bytecode from source VM
205
- * @param {string} sourceVM - Source VM type
206
- * @param {object} options - Deployment options
207
- */
208
- async deployBytecode(bytecode, sourceVM, options = {}) {
209
- console.log(`[JVM] Deploying ${sourceVM.toUpperCase()} bytecode...`);
210
-
211
- // Step 1: Translate bytecode to JIR
212
- const jir = await this.translator.translateToJIR(bytecode, sourceVM);
213
-
214
- // Step 2: Validate JIR
215
- const validation = await this.compiler.validate(jir);
216
- if (!validation.valid) {
217
- throw new Error(`Invalid bytecode: ${validation.errors.join(', ')}`);
218
- }
219
-
220
- // Step 3: Generate contract address
221
- const address = this._generateContractAddress(bytecode, options.deployer);
222
-
223
- // Step 4: Store in state
224
- await this.state.storeContract(address, {
225
- jir,
226
- sourceVM,
227
- bytecode: Buffer.from(bytecode),
228
- deployedAt: Date.now(),
229
- deployer: options.deployer || '0x0'
230
- });
231
-
232
- console.log(`[JVM] Contract deployed at: ${address}`);
233
-
234
- return {
235
- address,
236
- sourceVM,
237
- jirSize: jir.bytecode.length,
238
- originalSize: bytecode.length
239
- };
240
- }
241
-
242
- /**
243
- * Execute a function call
244
- *
245
- * @param {string} address - Contract address
246
- * @param {string} functionName - Function to call
247
- * @param {array} args - Function arguments
248
- * @param {object} context - Execution context (msg.sender, value, etc.)
249
- */
250
- async execute(address, functionName, args = [], context = {}) {
251
- const startTime = Date.now();
252
- this.metrics.executionsTotal++;
253
-
254
- console.log(`[JVM] Executing ${functionName} on ${address.substring(0, 10)}...`);
255
-
256
- // Step 1: Load contract
257
- const contract = await this.state.getContract(address);
258
- if (!contract) {
259
- throw new Error(`Contract not found: ${address}`);
260
- }
261
-
262
- // Step 2: Setup execution context
263
- const execContext = {
264
- caller: context.from || context.caller || '0x0',
265
- value: context.value || 0,
266
- gasLimit: context.gasLimit || this.config.maxInstructions,
267
- blockNumber: context.blockNumber || 0,
268
- timestamp: context.timestamp || Date.now(),
269
- chainId: context.chainId || 4545, // JAELIS testnet
270
- ...context
271
- };
272
-
273
- // Step 3: Serialize arguments (fast!)
274
- const serializedArgs = this.serializer.serialize(args);
275
-
276
- // Step 4: Execute on engine
277
- const result = await this.engine.execute(contract.jir, functionName, serializedArgs, execContext);
278
-
279
- // Step 5: Deserialize result
280
- const deserializedResult = this.serializer.deserialize(result.returnData);
281
-
282
- // Step 6: Update metrics
283
- const executionTime = Date.now() - startTime;
284
- this.metrics.instructionsExecuted += result.instructionsUsed || 0;
285
- this._updateMetrics(contract.sourceVM, executionTime);
286
-
287
- console.log(`[JVM] Execution complete in ${executionTime}ms`);
288
- console.log(`[JVM] Instructions: ${result.instructionsUsed || 0}`);
289
- console.log(`[JVM] Lode: 0 (ZERO FEES!)`);
290
-
291
- return {
292
- success: result.success,
293
- returnValue: deserializedResult,
294
- executionTime,
295
- instructionsUsed: result.instructionsUsed || 0,
296
- lodeUsed: 0, // JAELIS is zero-fee!
297
- logs: result.logs || [],
298
- stateChanges: result.stateChanges || []
299
- };
300
- }
301
-
302
- /**
303
- * Cross-VM call - call a function on another VM's contract
304
- *
305
- * @param {string} fromAddress - Calling contract
306
- * @param {string} toAddress - Target contract
307
- * @param {string} functionName - Function to call
308
- * @param {array} args - Arguments (will be translated)
309
- */
310
- async crossVMCall(fromAddress, toAddress, functionName, args = [], context = {}) {
311
- console.log(`[JVM] Cross-VM call: ${fromAddress.substring(0, 10)}... → ${toAddress.substring(0, 10)}...`);
312
-
313
- const fromContract = await this.state.getContract(fromAddress);
314
- const toContract = await this.state.getContract(toAddress);
315
-
316
- if (!fromContract || !toContract) {
317
- throw new Error('Contract not found');
318
- }
319
-
320
- // Translate arguments between VM formats
321
- const translatedArgs = await this.translator.translateArguments(
322
- args,
323
- fromContract.sourceVM,
324
- toContract.sourceVM
325
- );
326
-
327
- // Execute on target
328
- const result = await this.execute(toAddress, functionName, translatedArgs, {
329
- ...context,
330
- crossVMCall: true,
331
- sourceVM: fromContract.sourceVM,
332
- targetVM: toContract.sourceVM
333
- });
334
-
335
- // Translate result back
336
- const translatedResult = await this.translator.translateResult(
337
- result.returnValue,
338
- toContract.sourceVM,
339
- fromContract.sourceVM
340
- );
341
-
342
- return {
343
- ...result,
344
- returnValue: translatedResult,
345
- crossVM: {
346
- from: fromContract.sourceVM,
347
- to: toContract.sourceVM
348
- }
349
- };
350
- }
351
-
352
- /**
353
- * Get VM statistics
354
- */
355
- getStats() {
356
- return {
357
- ...this.metrics,
358
- cachedPrograms: this.programCache.size,
359
- supportedVMs: Object.keys(this.supportedVMs),
360
- stateConnected: this.state?.isConnected?.() || false,
361
- config: {
362
- executionMode: this.config.executionMode,
363
- serializer: this.config.serializer,
364
- maxMemory: this.config.maxMemory
365
- }
366
- };
367
- }
368
-
369
- // ═══════════════════════════════════════════════════════════════
370
- // CORE STATEMANAGER CONNECTION (Patent Claim 7d)
371
- // ═══════════════════════════════════════════════════════════════
372
-
373
- /**
374
- * Connect VM's StateManager to Core StateManager for LevelDB persistence
375
- * Implements Patent Claim 7d: "unified state manager maintaining
376
- * consistent state across all virtual machine adapters"
377
- *
378
- * @param {Object} coreStateManager - Core's StateManager with LevelDB backend
379
- */
380
- connectCoreState(coreStateManager) {
381
- if (this.state && this.state.connectCoreState) {
382
- this.state.connectCoreState(coreStateManager);
383
- console.log('[JaelisUniversalVM] ✅ Connected to Core StateManager (LevelDB)');
384
- return true;
385
- }
386
- console.warn('[JaelisUniversalVM] StateManager does not support connectCoreState');
387
- return false;
388
- }
389
-
390
- /**
391
- * Check if VM is connected to persistent storage
392
- */
393
- isPersistenceConnected() {
394
- return this.state?.isConnected?.() || false;
395
- }
396
-
397
- // ═══════════════════════════════════════════════════════════════
398
- // PRIVATE METHODS
399
- // ═══════════════════════════════════════════════════════════════
400
-
401
- _generateModuleId(sourceCode, sourceVM) {
402
- const crypto = require('crypto');
403
- return crypto.createHash('sha256')
404
- .update(sourceCode + sourceVM + Date.now())
405
- .digest('hex');
406
- }
407
-
408
- _generateContractAddress(bytecode, deployer) {
409
- const crypto = require('crypto');
410
- const input = Buffer.concat([
411
- Buffer.from(deployer || '0x0'),
412
- Buffer.from(bytecode),
413
- Buffer.from(Date.now().toString())
414
- ]);
415
- return '0x' + crypto.createHash('sha256').update(input).digest('hex').substring(0, 40);
416
- }
417
-
418
- _updateMetrics(sourceVM, executionTime) {
419
- const count = this.metrics.executionsByVM.get(sourceVM) || 0;
420
- this.metrics.executionsByVM.set(sourceVM, count + 1);
421
-
422
- // Rolling average
423
- const total = this.metrics.executionsTotal;
424
- this.metrics.averageExecutionTime =
425
- (this.metrics.averageExecutionTime * (total - 1) + executionTime) / total;
426
- }
427
- }
428
-
429
- // Also export the NEW Unified VM (NO BRIDGES!)
430
- const { UnifiedJaelisVM, UnifiedCompiler, DynamicContractManager } = require('./unified');
431
-
432
- module.exports = {
433
- // Original VM (with adapters/translation)
434
- JaelisUniversalVM,
435
-
436
- // NEW Unified VM (NO BRIDGES, NO ADAPTERS!)
437
- UnifiedJaelisVM,
438
- UnifiedCompiler,
439
- DynamicContractManager
440
- };