stylus-toolkit 0.1.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.
- package/.claude/settings.local.json +20 -0
- package/CHANGELOG.md +30 -0
- package/CONTRIBUTING.md +50 -0
- package/LICENSE +21 -0
- package/README.md +132 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +62 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/benchmark.d.ts +3 -0
- package/dist/commands/benchmark.d.ts.map +1 -0
- package/dist/commands/benchmark.js +18 -0
- package/dist/commands/benchmark.js.map +1 -0
- package/dist/commands/config.d.ts +9 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +63 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +115 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/profile.d.ts +3 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +160 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/compiler/rust-compiler.d.ts +12 -0
- package/dist/compiler/rust-compiler.d.ts.map +1 -0
- package/dist/compiler/rust-compiler.js +141 -0
- package/dist/compiler/rust-compiler.js.map +1 -0
- package/dist/compiler/solidity-compiler.d.ts +10 -0
- package/dist/compiler/solidity-compiler.d.ts.map +1 -0
- package/dist/compiler/solidity-compiler.js +160 -0
- package/dist/compiler/solidity-compiler.js.map +1 -0
- package/dist/exporter/exporter.d.ts +13 -0
- package/dist/exporter/exporter.d.ts.map +1 -0
- package/dist/exporter/exporter.js +322 -0
- package/dist/exporter/exporter.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/profiler/comparator.d.ts +10 -0
- package/dist/profiler/comparator.d.ts.map +1 -0
- package/dist/profiler/comparator.js +96 -0
- package/dist/profiler/comparator.js.map +1 -0
- package/dist/profiler/gas-profiler.d.ts +11 -0
- package/dist/profiler/gas-profiler.d.ts.map +1 -0
- package/dist/profiler/gas-profiler.js +143 -0
- package/dist/profiler/gas-profiler.js.map +1 -0
- package/dist/storage/results-store.d.ts +16 -0
- package/dist/storage/results-store.d.ts.map +1 -0
- package/dist/storage/results-store.js +107 -0
- package/dist/storage/results-store.js.map +1 -0
- package/dist/templates/generator.d.ts +11 -0
- package/dist/templates/generator.d.ts.map +1 -0
- package/dist/templates/generator.js +135 -0
- package/dist/templates/generator.js.map +1 -0
- package/dist/templates/templates.d.ts +2 -0
- package/dist/templates/templates.d.ts.map +1 -0
- package/dist/templates/templates.js +324 -0
- package/dist/templates/templates.js.map +1 -0
- package/dist/types/index.d.ts +115 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/config.d.ts +15 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +77 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/file-system.d.ts +14 -0
- package/dist/utils/file-system.d.ts.map +1 -0
- package/dist/utils/file-system.js +84 -0
- package/dist/utils/file-system.js.map +1 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +76 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ResultExporter = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const json2csv_1 = require("json2csv");
|
|
9
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
10
|
+
const file_system_1 = require("../utils/file-system");
|
|
11
|
+
const logger_1 = require("../utils/logger");
|
|
12
|
+
class ResultExporter {
|
|
13
|
+
async export(comparison, options) {
|
|
14
|
+
const outputDir = options.outputPath || file_system_1.FileSystem.getProjectRoot();
|
|
15
|
+
switch (options.format) {
|
|
16
|
+
case 'json':
|
|
17
|
+
return await this.exportJson(comparison, outputDir, options.includeRawData);
|
|
18
|
+
case 'csv':
|
|
19
|
+
return await this.exportCsv(comparison, outputDir);
|
|
20
|
+
case 'html':
|
|
21
|
+
return await this.exportHtml(comparison, outputDir);
|
|
22
|
+
default:
|
|
23
|
+
throw new Error(`Unsupported export format: ${options.format}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async exportJson(comparison, outputDir, includeRawData) {
|
|
27
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
28
|
+
const filename = `gas-profile-${comparison.contractName}-${timestamp}.json`;
|
|
29
|
+
const filepath = path_1.default.join(outputDir, filename);
|
|
30
|
+
const data = includeRawData
|
|
31
|
+
? this.serializeComparison(comparison)
|
|
32
|
+
: this.createSummaryData(comparison);
|
|
33
|
+
await file_system_1.FileSystem.writeJson(filepath, data);
|
|
34
|
+
logger_1.logger.success(`JSON export saved to ${filename}`);
|
|
35
|
+
return filepath;
|
|
36
|
+
}
|
|
37
|
+
async exportCsv(comparison, outputDir) {
|
|
38
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
39
|
+
const filename = `gas-profile-${comparison.contractName}-${timestamp}.csv`;
|
|
40
|
+
const filepath = path_1.default.join(outputDir, filename);
|
|
41
|
+
const records = this.createCsvRecords(comparison);
|
|
42
|
+
const parser = new json2csv_1.Parser({
|
|
43
|
+
fields: [
|
|
44
|
+
'Metric',
|
|
45
|
+
'Rust (Gas)',
|
|
46
|
+
'Solidity (Gas)',
|
|
47
|
+
'Savings (Gas)',
|
|
48
|
+
'Savings (%)',
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
const csv = parser.parse(records);
|
|
52
|
+
await file_system_1.FileSystem.writeFile(filepath, csv);
|
|
53
|
+
logger_1.logger.success(`CSV export saved to ${filename}`);
|
|
54
|
+
return filepath;
|
|
55
|
+
}
|
|
56
|
+
async exportHtml(comparison, outputDir) {
|
|
57
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
58
|
+
const filename = `gas-profile-${comparison.contractName}-${timestamp}.html`;
|
|
59
|
+
const filepath = path_1.default.join(outputDir, filename);
|
|
60
|
+
const html = this.generateHtml(comparison);
|
|
61
|
+
await file_system_1.FileSystem.writeFile(filepath, html);
|
|
62
|
+
logger_1.logger.success(`HTML export saved to ${filename}`);
|
|
63
|
+
return filepath;
|
|
64
|
+
}
|
|
65
|
+
createSummaryData(comparison) {
|
|
66
|
+
return {
|
|
67
|
+
contract: comparison.contractName,
|
|
68
|
+
timestamp: comparison.timestamp,
|
|
69
|
+
deployment: {
|
|
70
|
+
rust: comparison.rustProfile.deploymentGas,
|
|
71
|
+
solidity: comparison.solidityProfile.deploymentGas,
|
|
72
|
+
savings: {
|
|
73
|
+
absolute: comparison.savings.deploymentSavings.absolute,
|
|
74
|
+
percentage: comparison.savings.deploymentSavings.percentage,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
functions: Array.from(comparison.savings.functionSavings.values()).map((f) => ({
|
|
78
|
+
name: f.functionName,
|
|
79
|
+
rust: f.rustGas,
|
|
80
|
+
solidity: f.solidityGas,
|
|
81
|
+
savings: {
|
|
82
|
+
absolute: f.absolute,
|
|
83
|
+
percentage: f.percentage,
|
|
84
|
+
},
|
|
85
|
+
})),
|
|
86
|
+
totalAverage: comparison.savings.totalAvgSavings,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
createCsvRecords(comparison) {
|
|
90
|
+
const records = [];
|
|
91
|
+
records.push({
|
|
92
|
+
Metric: 'Deployment',
|
|
93
|
+
'Rust (Gas)': comparison.rustProfile.deploymentGas,
|
|
94
|
+
'Solidity (Gas)': comparison.solidityProfile.deploymentGas,
|
|
95
|
+
'Savings (Gas)': comparison.savings.deploymentSavings.absolute,
|
|
96
|
+
'Savings (%)': comparison.savings.deploymentSavings.percentage.toFixed(2),
|
|
97
|
+
});
|
|
98
|
+
for (const [functionName, savings] of comparison.savings.functionSavings) {
|
|
99
|
+
records.push({
|
|
100
|
+
Metric: functionName,
|
|
101
|
+
'Rust (Gas)': savings.rustGas,
|
|
102
|
+
'Solidity (Gas)': savings.solidityGas,
|
|
103
|
+
'Savings (Gas)': savings.absolute,
|
|
104
|
+
'Savings (%)': savings.percentage.toFixed(2),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (comparison.savings.functionSavings.size > 0) {
|
|
108
|
+
records.push({
|
|
109
|
+
Metric: 'Average Total',
|
|
110
|
+
'Rust (Gas)': '-',
|
|
111
|
+
'Solidity (Gas)': '-',
|
|
112
|
+
'Savings (Gas)': comparison.savings.totalAvgSavings.absolute,
|
|
113
|
+
'Savings (%)': comparison.savings.totalAvgSavings.percentage.toFixed(2),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return records;
|
|
117
|
+
}
|
|
118
|
+
generateHtml(comparison) {
|
|
119
|
+
const template = this.getHtmlTemplate();
|
|
120
|
+
const compiled = handlebars_1.default.compile(template);
|
|
121
|
+
const data = {
|
|
122
|
+
contractName: comparison.contractName,
|
|
123
|
+
timestamp: new Date(comparison.timestamp).toLocaleString(),
|
|
124
|
+
deployment: {
|
|
125
|
+
rust: comparison.rustProfile.deploymentGas.toLocaleString(),
|
|
126
|
+
solidity: comparison.solidityProfile.deploymentGas.toLocaleString(),
|
|
127
|
+
savingsGas: comparison.savings.deploymentSavings.absolute.toLocaleString(),
|
|
128
|
+
savingsPercent: comparison.savings.deploymentSavings.percentage.toFixed(2),
|
|
129
|
+
positive: comparison.savings.deploymentSavings.absolute > 0,
|
|
130
|
+
},
|
|
131
|
+
functions: Array.from(comparison.savings.functionSavings.values()).map((f) => ({
|
|
132
|
+
name: f.functionName,
|
|
133
|
+
rust: f.rustGas.toLocaleString(),
|
|
134
|
+
solidity: f.solidityGas.toLocaleString(),
|
|
135
|
+
savingsGas: f.absolute.toLocaleString(),
|
|
136
|
+
savingsPercent: f.percentage.toFixed(2),
|
|
137
|
+
positive: f.absolute > 0,
|
|
138
|
+
})),
|
|
139
|
+
hasFunctions: comparison.savings.functionSavings.size > 0,
|
|
140
|
+
totalAverage: {
|
|
141
|
+
savingsGas: comparison.savings.totalAvgSavings.absolute.toLocaleString(),
|
|
142
|
+
savingsPercent: comparison.savings.totalAvgSavings.percentage.toFixed(2),
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
return compiled(data);
|
|
146
|
+
}
|
|
147
|
+
getHtmlTemplate() {
|
|
148
|
+
return `<!DOCTYPE html>
|
|
149
|
+
<html lang="en">
|
|
150
|
+
<head>
|
|
151
|
+
<meta charset="UTF-8">
|
|
152
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
153
|
+
<title>Gas Profile - {{contractName}}</title>
|
|
154
|
+
<style>
|
|
155
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
156
|
+
body {
|
|
157
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
158
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
159
|
+
padding: 40px 20px;
|
|
160
|
+
min-height: 100vh;
|
|
161
|
+
}
|
|
162
|
+
.container {
|
|
163
|
+
max-width: 1000px;
|
|
164
|
+
margin: 0 auto;
|
|
165
|
+
background: white;
|
|
166
|
+
border-radius: 12px;
|
|
167
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
168
|
+
overflow: hidden;
|
|
169
|
+
}
|
|
170
|
+
.header {
|
|
171
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
172
|
+
color: white;
|
|
173
|
+
padding: 40px;
|
|
174
|
+
text-align: center;
|
|
175
|
+
}
|
|
176
|
+
.header h1 { font-size: 2.5em; margin-bottom: 10px; }
|
|
177
|
+
.header p { opacity: 0.9; font-size: 1.1em; }
|
|
178
|
+
.content { padding: 40px; }
|
|
179
|
+
.section { margin-bottom: 40px; }
|
|
180
|
+
.section h2 {
|
|
181
|
+
font-size: 1.8em;
|
|
182
|
+
margin-bottom: 20px;
|
|
183
|
+
color: #333;
|
|
184
|
+
border-bottom: 3px solid #667eea;
|
|
185
|
+
padding-bottom: 10px;
|
|
186
|
+
}
|
|
187
|
+
table {
|
|
188
|
+
width: 100%;
|
|
189
|
+
border-collapse: collapse;
|
|
190
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
191
|
+
}
|
|
192
|
+
th, td {
|
|
193
|
+
padding: 15px;
|
|
194
|
+
text-align: left;
|
|
195
|
+
border-bottom: 1px solid #e0e0e0;
|
|
196
|
+
}
|
|
197
|
+
th {
|
|
198
|
+
background: #f5f5f5;
|
|
199
|
+
font-weight: 600;
|
|
200
|
+
color: #555;
|
|
201
|
+
text-transform: uppercase;
|
|
202
|
+
font-size: 0.85em;
|
|
203
|
+
letter-spacing: 0.5px;
|
|
204
|
+
}
|
|
205
|
+
tr:hover { background: #f9f9f9; }
|
|
206
|
+
.positive { color: #10b981; font-weight: 600; }
|
|
207
|
+
.negative { color: #ef4444; font-weight: 600; }
|
|
208
|
+
.highlight {
|
|
209
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
210
|
+
color: white;
|
|
211
|
+
font-weight: bold;
|
|
212
|
+
}
|
|
213
|
+
.footer {
|
|
214
|
+
text-align: center;
|
|
215
|
+
padding: 20px;
|
|
216
|
+
color: #666;
|
|
217
|
+
font-size: 0.9em;
|
|
218
|
+
border-top: 1px solid #e0e0e0;
|
|
219
|
+
}
|
|
220
|
+
</style>
|
|
221
|
+
</head>
|
|
222
|
+
<body>
|
|
223
|
+
<div class="container">
|
|
224
|
+
<div class="header">
|
|
225
|
+
<h1>⚡ Gas Profile Report</h1>
|
|
226
|
+
<p>{{contractName}} - {{timestamp}}</p>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
<div class="content">
|
|
230
|
+
<div class="section">
|
|
231
|
+
<h2>Deployment Gas</h2>
|
|
232
|
+
<table>
|
|
233
|
+
<thead>
|
|
234
|
+
<tr>
|
|
235
|
+
<th>Language</th>
|
|
236
|
+
<th>Gas Used</th>
|
|
237
|
+
<th>Savings</th>
|
|
238
|
+
<th>Percentage</th>
|
|
239
|
+
</tr>
|
|
240
|
+
</thead>
|
|
241
|
+
<tbody>
|
|
242
|
+
<tr>
|
|
243
|
+
<td><strong>Rust (Stylus)</strong></td>
|
|
244
|
+
<td>{{deployment.rust}}</td>
|
|
245
|
+
<td rowspan="2" class="{{#if deployment.positive}}positive{{else}}negative{{/if}}">
|
|
246
|
+
{{deployment.savingsGas}} gas
|
|
247
|
+
</td>
|
|
248
|
+
<td rowspan="2" class="{{#if deployment.positive}}positive{{else}}negative{{/if}}">
|
|
249
|
+
{{deployment.savingsPercent}}%
|
|
250
|
+
</td>
|
|
251
|
+
</tr>
|
|
252
|
+
<tr>
|
|
253
|
+
<td><strong>Solidity</strong></td>
|
|
254
|
+
<td>{{deployment.solidity}}</td>
|
|
255
|
+
</tr>
|
|
256
|
+
</tbody>
|
|
257
|
+
</table>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
{{#if hasFunctions}}
|
|
261
|
+
<div class="section">
|
|
262
|
+
<h2>Function Gas Comparison</h2>
|
|
263
|
+
<table>
|
|
264
|
+
<thead>
|
|
265
|
+
<tr>
|
|
266
|
+
<th>Function</th>
|
|
267
|
+
<th>Rust</th>
|
|
268
|
+
<th>Solidity</th>
|
|
269
|
+
<th>Savings (Gas)</th>
|
|
270
|
+
<th>Savings (%)</th>
|
|
271
|
+
</tr>
|
|
272
|
+
</thead>
|
|
273
|
+
<tbody>
|
|
274
|
+
{{#each functions}}
|
|
275
|
+
<tr>
|
|
276
|
+
<td><strong>{{name}}</strong></td>
|
|
277
|
+
<td>{{rust}}</td>
|
|
278
|
+
<td>{{solidity}}</td>
|
|
279
|
+
<td class="{{#if positive}}positive{{else}}negative{{/if}}">{{savingsGas}}</td>
|
|
280
|
+
<td class="{{#if positive}}positive{{else}}negative{{/if}}">{{savingsPercent}}%</td>
|
|
281
|
+
</tr>
|
|
282
|
+
{{/each}}
|
|
283
|
+
<tr class="highlight">
|
|
284
|
+
<td><strong>Average Total</strong></td>
|
|
285
|
+
<td>-</td>
|
|
286
|
+
<td>-</td>
|
|
287
|
+
<td>{{totalAverage.savingsGas}}</td>
|
|
288
|
+
<td>{{totalAverage.savingsPercent}}%</td>
|
|
289
|
+
</tr>
|
|
290
|
+
</tbody>
|
|
291
|
+
</table>
|
|
292
|
+
</div>
|
|
293
|
+
{{/if}}
|
|
294
|
+
</div>
|
|
295
|
+
|
|
296
|
+
<div class="footer">
|
|
297
|
+
Generated by Stylus Toolkit | Arbitrum Stylus Development
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
</body>
|
|
301
|
+
</html>`;
|
|
302
|
+
}
|
|
303
|
+
serializeComparison(comparison) {
|
|
304
|
+
return {
|
|
305
|
+
...comparison,
|
|
306
|
+
rustProfile: {
|
|
307
|
+
...comparison.rustProfile,
|
|
308
|
+
functionGas: Array.from(comparison.rustProfile.functionGas.entries()),
|
|
309
|
+
},
|
|
310
|
+
solidityProfile: {
|
|
311
|
+
...comparison.solidityProfile,
|
|
312
|
+
functionGas: Array.from(comparison.solidityProfile.functionGas.entries()),
|
|
313
|
+
},
|
|
314
|
+
savings: {
|
|
315
|
+
...comparison.savings,
|
|
316
|
+
functionSavings: Array.from(comparison.savings.functionSavings.entries()),
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.ResultExporter = ResultExporter;
|
|
322
|
+
//# sourceMappingURL=exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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U,CAAC,OAAO,CAAC,CAAC,CAAC;aACzE;SACF,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAEO,eAAe;QACrB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAyJH,CAAC;IACP,CAAC;IAEO,mBAAmB,CAAC,UAA4B;QACtD,OAAO;YACL,GAAG,UAAU;YACb,WAAW,EAAE;gBACX,GAAG,UAAU,CAAC,WAAW;gBACzB,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aACtE;YACD,eAAe,EAAE;gBACf,GAAG,UAAU,CAAC,eAAe;gBAC7B,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aAC1E;YACD,OAAO,EAAE;gBACP,GAAG,UAAU,CAAC,OAAO;gBACrB,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;aAC1E;SACF,CAAC;IACJ,CAAC;CACF;AA3VD,wCA2VC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { RustCompiler } from './compiler/rust-compiler';
|
|
3
|
+
export { SolidityCompiler } from './compiler/solidity-compiler';
|
|
4
|
+
export { GasProfiler } from './profiler/gas-profiler';
|
|
5
|
+
export { GasComparator } from './profiler/comparator';
|
|
6
|
+
export { ResultsStore } from './storage/results-store';
|
|
7
|
+
export { ResultExporter } from './exporter/exporter';
|
|
8
|
+
export { FileSystem } from './utils/file-system';
|
|
9
|
+
export { logger } from './utils/logger';
|
|
10
|
+
export { config } from './utils/config';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.config = exports.logger = exports.FileSystem = exports.ResultExporter = exports.ResultsStore = exports.GasComparator = exports.GasProfiler = exports.SolidityCompiler = exports.RustCompiler = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
var rust_compiler_1 = require("./compiler/rust-compiler");
|
|
20
|
+
Object.defineProperty(exports, "RustCompiler", { enumerable: true, get: function () { return rust_compiler_1.RustCompiler; } });
|
|
21
|
+
var solidity_compiler_1 = require("./compiler/solidity-compiler");
|
|
22
|
+
Object.defineProperty(exports, "SolidityCompiler", { enumerable: true, get: function () { return solidity_compiler_1.SolidityCompiler; } });
|
|
23
|
+
var gas_profiler_1 = require("./profiler/gas-profiler");
|
|
24
|
+
Object.defineProperty(exports, "GasProfiler", { enumerable: true, get: function () { return gas_profiler_1.GasProfiler; } });
|
|
25
|
+
var comparator_1 = require("./profiler/comparator");
|
|
26
|
+
Object.defineProperty(exports, "GasComparator", { enumerable: true, get: function () { return comparator_1.GasComparator; } });
|
|
27
|
+
var results_store_1 = require("./storage/results-store");
|
|
28
|
+
Object.defineProperty(exports, "ResultsStore", { enumerable: true, get: function () { return results_store_1.ResultsStore; } });
|
|
29
|
+
var exporter_1 = require("./exporter/exporter");
|
|
30
|
+
Object.defineProperty(exports, "ResultExporter", { enumerable: true, get: function () { return exporter_1.ResultExporter; } });
|
|
31
|
+
var file_system_1 = require("./utils/file-system");
|
|
32
|
+
Object.defineProperty(exports, "FileSystem", { enumerable: true, get: function () { return file_system_1.FileSystem; } });
|
|
33
|
+
var logger_1 = require("./utils/logger");
|
|
34
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
35
|
+
var config_1 = require("./utils/config");
|
|
36
|
+
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,0DAAwD;AAA/C,6GAAA,YAAY,OAAA;AACrB,kEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AACpB,oDAAsD;AAA7C,2GAAA,aAAa,OAAA;AACtB,yDAAuD;AAA9C,6GAAA,YAAY,OAAA;AACrB,gDAAqD;AAA5C,0GAAA,cAAc,OAAA;AACvB,mDAAiD;AAAxC,yGAAA,UAAU,OAAA;AACnB,yCAAwC;AAA/B,gGAAA,MAAM,OAAA;AACf,yCAAwC;AAA/B,gGAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GasProfile, ComparisonResult } from '../types';
|
|
2
|
+
export declare class GasComparator {
|
|
3
|
+
compare(rustProfile: GasProfile, solidityProfile: GasProfile): ComparisonResult;
|
|
4
|
+
private calculateSavings;
|
|
5
|
+
private calculateDeploymentSavings;
|
|
6
|
+
private calculateFunctionSavings;
|
|
7
|
+
private calculateTotalAvgSavings;
|
|
8
|
+
generateSummary(comparison: ComparisonResult): string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=comparator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../../src/profiler/comparator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gBAAgB,EAGjB,MAAM,UAAU,CAAC;AAElB,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,GAAG,gBAAgB;IAY/E,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,0BAA0B;IAUlC,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,wBAAwB;IAmBhC,eAAe,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM;CAwCtD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GasComparator = void 0;
|
|
4
|
+
class GasComparator {
|
|
5
|
+
compare(rustProfile, solidityProfile) {
|
|
6
|
+
const savings = this.calculateSavings(rustProfile, solidityProfile);
|
|
7
|
+
return {
|
|
8
|
+
contractName: rustProfile.contractName,
|
|
9
|
+
rustProfile,
|
|
10
|
+
solidityProfile,
|
|
11
|
+
savings,
|
|
12
|
+
timestamp: new Date().toISOString(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
calculateSavings(rustProfile, solidityProfile) {
|
|
16
|
+
const deploymentSavings = this.calculateDeploymentSavings(rustProfile.deploymentGas, solidityProfile.deploymentGas);
|
|
17
|
+
const functionSavings = this.calculateFunctionSavings(rustProfile.functionGas, solidityProfile.functionGas);
|
|
18
|
+
const totalAvgSavings = this.calculateTotalAvgSavings(functionSavings);
|
|
19
|
+
return {
|
|
20
|
+
deploymentSavings,
|
|
21
|
+
functionSavings,
|
|
22
|
+
totalAvgSavings,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
calculateDeploymentSavings(rustGas, solidityGas) {
|
|
26
|
+
const absolute = solidityGas - rustGas;
|
|
27
|
+
const percentage = solidityGas > 0 ? (absolute / solidityGas) * 100 : 0;
|
|
28
|
+
return {
|
|
29
|
+
absolute,
|
|
30
|
+
percentage,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
calculateFunctionSavings(rustFunctions, solidityFunctions) {
|
|
34
|
+
const savingsMap = new Map();
|
|
35
|
+
for (const [functionName, rustData] of rustFunctions) {
|
|
36
|
+
const solidityData = solidityFunctions.get(functionName);
|
|
37
|
+
if (solidityData) {
|
|
38
|
+
const absolute = solidityData.avgGas - rustData.avgGas;
|
|
39
|
+
const percentage = solidityData.avgGas > 0 ? (absolute / solidityData.avgGas) * 100 : 0;
|
|
40
|
+
savingsMap.set(functionName, {
|
|
41
|
+
functionName,
|
|
42
|
+
absolute,
|
|
43
|
+
percentage,
|
|
44
|
+
rustGas: rustData.avgGas,
|
|
45
|
+
solidityGas: solidityData.avgGas,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return savingsMap;
|
|
50
|
+
}
|
|
51
|
+
calculateTotalAvgSavings(functionSavings) {
|
|
52
|
+
if (functionSavings.size === 0) {
|
|
53
|
+
return { absolute: 0, percentage: 0 };
|
|
54
|
+
}
|
|
55
|
+
let totalAbsolute = 0;
|
|
56
|
+
let totalPercentage = 0;
|
|
57
|
+
for (const savings of functionSavings.values()) {
|
|
58
|
+
totalAbsolute += savings.absolute;
|
|
59
|
+
totalPercentage += savings.percentage;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
absolute: totalAbsolute / functionSavings.size,
|
|
63
|
+
percentage: totalPercentage / functionSavings.size,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
generateSummary(comparison) {
|
|
67
|
+
const lines = [];
|
|
68
|
+
lines.push('Gas Comparison Summary');
|
|
69
|
+
lines.push('='.repeat(60));
|
|
70
|
+
lines.push('');
|
|
71
|
+
lines.push(`Contract: ${comparison.contractName}`);
|
|
72
|
+
lines.push(`Timestamp: ${comparison.timestamp}`);
|
|
73
|
+
lines.push('');
|
|
74
|
+
lines.push('Deployment Gas:');
|
|
75
|
+
lines.push(` Rust: ${comparison.rustProfile.deploymentGas.toLocaleString()} gas`);
|
|
76
|
+
lines.push(` Solidity: ${comparison.solidityProfile.deploymentGas.toLocaleString()} gas`);
|
|
77
|
+
lines.push(` Savings: ${comparison.savings.deploymentSavings.absolute.toLocaleString()} gas (${comparison.savings.deploymentSavings.percentage.toFixed(2)}%)`);
|
|
78
|
+
lines.push('');
|
|
79
|
+
if (comparison.savings.functionSavings.size > 0) {
|
|
80
|
+
lines.push('Function Gas Comparison:');
|
|
81
|
+
lines.push('');
|
|
82
|
+
for (const [functionName, savings] of comparison.savings.functionSavings) {
|
|
83
|
+
lines.push(` ${functionName}:`);
|
|
84
|
+
lines.push(` Rust: ${savings.rustGas.toLocaleString()} gas`);
|
|
85
|
+
lines.push(` Solidity: ${savings.solidityGas.toLocaleString()} gas`);
|
|
86
|
+
lines.push(` Savings: ${savings.absolute.toLocaleString()} gas (${savings.percentage.toFixed(2)}%)`);
|
|
87
|
+
lines.push('');
|
|
88
|
+
}
|
|
89
|
+
lines.push('Average Total Savings:');
|
|
90
|
+
lines.push(` ${comparison.savings.totalAvgSavings.absolute.toLocaleString()} gas (${comparison.savings.totalAvgSavings.percentage.toFixed(2)}%)`);
|
|
91
|
+
}
|
|
92
|
+
return lines.join('\n');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.GasComparator = GasComparator;
|
|
96
|
+
//# sourceMappingURL=comparator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.js","sourceRoot":"","sources":["../../src/profiler/comparator.ts"],"names":[],"mappings":";;;AAOA,MAAa,aAAa;IACxB,OAAO,CAAC,WAAuB,EAAE,eAA2B;QAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QAEpE,OAAO;YACL,YAAY,EAAE,WAAW,CAAC,YAAY;YACtC,WAAW;YACX,eAAe;YACf,OAAO;YACP,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;IACJ,CAAC;IAEO,gBAAgB,CAAC,WAAuB,EAAE,eAA2B;QAC3E,MAAM,iBAAiB,GAAG,IAAI,CAAC,0BAA0B,CACvD,WAAW,CAAC,aAAa,EACzB,eAAe,CAAC,aAAa,CAC9B,CAAC;QAEF,MAAM,eAAe,GAAG,IAAI,CAAC,wBAAwB,CACnD,WAAW,CAAC,WAAW,EACvB,eAAe,CAAC,WAAW,CAC5B,CAAC;QAEF,MAAM,eAA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@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CompilationResult, GasProfile } from '../types';
|
|
2
|
+
export declare class GasProfiler {
|
|
3
|
+
private provider;
|
|
4
|
+
private signer;
|
|
5
|
+
constructor(rpcUrl: string, privateKey?: string);
|
|
6
|
+
profileContract(compilation: CompilationResult, testCases?: Map<string, any[][]>): Promise<GasProfile>;
|
|
7
|
+
private measureDeploymentGas;
|
|
8
|
+
private measureFunctionGas;
|
|
9
|
+
estimateGas(contractAddress: string, abi: any[], functionName: string, args: any[]): Promise<number>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=gas-profiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-profiler.d.ts","sourceRoot":"","sources":["../../src/profiler/gas-profiler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAA6B,MAAM,UAAU,CAAC;AAEpF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;IAUzC,eAAe,CACnB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,GAC/B,OAAO,CAAC,UAAU,CAAC;YAgCR,oBAAoB;YAgDpB,kBAAkB;IA8E1B,WAAW,CACf,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,GAAG,EAAE,EACV,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,GAAG,EAAE,GACV,OAAO,CAAC,MAAM,CAAC;CAOnB"}
|