@varity-labs/sdk 2.0.0-alpha.1
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/LICENSE +31 -0
- package/README.md +253 -0
- package/dist/analytics/index.d.ts +7 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics/tracker.d.ts +128 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +203 -0
- package/dist/blockchain/BlockchainService.d.ts +100 -0
- package/dist/blockchain/BlockchainService.d.ts.map +1 -0
- package/dist/blockchain/BlockchainService.js +188 -0
- package/dist/blockchain/NFTLicensingService.d.ts +69 -0
- package/dist/blockchain/NFTLicensingService.d.ts.map +1 -0
- package/dist/blockchain/NFTLicensingService.js +136 -0
- package/dist/blockchain/RevenueSplitService.d.ts +71 -0
- package/dist/blockchain/RevenueSplitService.d.ts.map +1 -0
- package/dist/blockchain/RevenueSplitService.js +111 -0
- package/dist/blockchain/index.d.ts +48 -0
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +46 -0
- package/dist/blockchain/types.d.ts +63 -0
- package/dist/blockchain/types.d.ts.map +1 -0
- package/dist/blockchain/types.js +6 -0
- package/dist/chains/arbitrum.d.ts +89 -0
- package/dist/chains/arbitrum.d.ts.map +1 -0
- package/dist/chains/arbitrum.js +134 -0
- package/dist/chains/base.d.ts +84 -0
- package/dist/chains/base.d.ts.map +1 -0
- package/dist/chains/base.js +131 -0
- package/dist/chains/index.d.ts +36 -0
- package/dist/chains/index.d.ts.map +1 -0
- package/dist/chains/index.js +32 -0
- package/dist/chains/registry.d.ts +113 -0
- package/dist/chains/registry.d.ts.map +1 -0
- package/dist/chains/registry.js +201 -0
- package/dist/chains/varityL3.d.ts +81 -0
- package/dist/chains/varityL3.d.ts.map +1 -0
- package/dist/chains/varityL3.js +125 -0
- package/dist/cli/commands/clone.d.ts +8 -0
- package/dist/cli/commands/clone.d.ts.map +1 -0
- package/dist/cli/commands/clone.js +391 -0
- package/dist/cli/commands/dev.d.ts +8 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +40 -0
- package/dist/cli/commands/generate.d.ts +8 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +303 -0
- package/dist/cli/commands/init.d.ts +8 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +317 -0
- package/dist/cli/commands/validate.d.ts +8 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +69 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +33 -0
- package/dist/cli/utils/logger.d.ts +17 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +35 -0
- package/dist/cli/utils/prompts.d.ts +21 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +103 -0
- package/dist/contracts/abis/iso/AccessControlRegistry.json +1468 -0
- package/dist/contracts/abis/iso/DataProofRegistry.json +797 -0
- package/dist/contracts/abis/iso/MerchantRegistry.json +1237 -0
- package/dist/contracts/abis/iso/RepPerformance.json +1351 -0
- package/dist/contracts/abis/iso/ResidualCalculator.json +1118 -0
- package/dist/contracts/abis/iso/TransactionVault.json +1588 -0
- package/dist/contracts/abis/iso/VarityWalletFactory.json +475 -0
- package/dist/contracts/addresses.d.ts +88 -0
- package/dist/contracts/addresses.d.ts.map +1 -0
- package/dist/contracts/addresses.js +94 -0
- package/dist/contracts/index.d.ts +7 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +6 -0
- package/dist/core/VaritySDK.d.ts +177 -0
- package/dist/core/VaritySDK.d.ts.map +1 -0
- package/dist/core/VaritySDK.js +325 -0
- package/dist/core/config.d.ts +120 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +187 -0
- package/dist/core/credentials-proxy.d.ts +157 -0
- package/dist/core/credentials-proxy.d.ts.map +1 -0
- package/dist/core/credentials-proxy.js +345 -0
- package/dist/core/credentials.d.ts +219 -0
- package/dist/core/credentials.d.ts.map +1 -0
- package/dist/core/credentials.js +345 -0
- package/dist/core/template-loader.d.ts +15 -0
- package/dist/core/template-loader.d.ts.map +1 -0
- package/dist/core/template-loader.js +380 -0
- package/dist/core/template.d.ts +321 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +189 -0
- package/dist/core/types.d.ts +572 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +52 -0
- package/dist/dev/dev-server.d.ts +16 -0
- package/dist/dev/dev-server.d.ts.map +1 -0
- package/dist/dev/dev-server.js +119 -0
- package/dist/generators/contracts/generator.d.ts +21 -0
- package/dist/generators/contracts/generator.d.ts.map +1 -0
- package/dist/generators/contracts/generator.js +252 -0
- package/dist/generators/tests/generator.d.ts +20 -0
- package/dist/generators/tests/generator.d.ts.map +1 -0
- package/dist/generators/tests/generator.js +375 -0
- package/dist/generators/types/generator.d.ts +19 -0
- package/dist/generators/types/generator.d.ts.map +1 -0
- package/dist/generators/types/generator.js +165 -0
- package/dist/generators/ui/component-generator.d.ts +20 -0
- package/dist/generators/ui/component-generator.d.ts.map +1 -0
- package/dist/generators/ui/component-generator.js +749 -0
- package/dist/generators/ui/dashboard-generator.d.ts +20 -0
- package/dist/generators/ui/dashboard-generator.d.ts.map +1 -0
- package/dist/generators/ui/dashboard-generator.js +349 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/modules/analytics/AnalyticsModule.d.ts +349 -0
- package/dist/modules/analytics/AnalyticsModule.d.ts.map +1 -0
- package/dist/modules/analytics/AnalyticsModule.js +274 -0
- package/dist/modules/analytics/index.d.ts +3 -0
- package/dist/modules/analytics/index.d.ts.map +1 -0
- package/dist/modules/analytics/index.js +1 -0
- package/dist/modules/auth/AccessKeyModule.d.ts +189 -0
- package/dist/modules/auth/AccessKeyModule.d.ts.map +1 -0
- package/dist/modules/auth/AccessKeyModule.js +322 -0
- package/dist/modules/auth/AuthModule.d.ts +133 -0
- package/dist/modules/auth/AuthModule.d.ts.map +1 -0
- package/dist/modules/auth/AuthModule.js +214 -0
- package/dist/modules/auth/index.d.ts +8 -0
- package/dist/modules/auth/index.d.ts.map +1 -0
- package/dist/modules/auth/index.js +6 -0
- package/dist/modules/cache/CacheModule.d.ts +279 -0
- package/dist/modules/cache/CacheModule.d.ts.map +1 -0
- package/dist/modules/cache/CacheModule.js +493 -0
- package/dist/modules/cache/index.d.ts +3 -0
- package/dist/modules/cache/index.d.ts.map +1 -0
- package/dist/modules/cache/index.js +1 -0
- package/dist/modules/compute/ComputeModule.d.ts +226 -0
- package/dist/modules/compute/ComputeModule.d.ts.map +1 -0
- package/dist/modules/compute/ComputeModule.js +379 -0
- package/dist/modules/compute/index.d.ts +6 -0
- package/dist/modules/compute/index.d.ts.map +1 -0
- package/dist/modules/compute/index.js +4 -0
- package/dist/modules/contracts/ContractsModule.d.ts +164 -0
- package/dist/modules/contracts/ContractsModule.d.ts.map +1 -0
- package/dist/modules/contracts/ContractsModule.js +242 -0
- package/dist/modules/contracts/index.d.ts +6 -0
- package/dist/modules/contracts/index.d.ts.map +1 -0
- package/dist/modules/contracts/index.js +4 -0
- package/dist/modules/export/ExportModule.d.ts +346 -0
- package/dist/modules/export/ExportModule.d.ts.map +1 -0
- package/dist/modules/export/ExportModule.js +432 -0
- package/dist/modules/export/index.d.ts +3 -0
- package/dist/modules/export/index.d.ts.map +1 -0
- package/dist/modules/export/index.js +1 -0
- package/dist/modules/forecasting/ForecastingModule.d.ts +579 -0
- package/dist/modules/forecasting/ForecastingModule.d.ts.map +1 -0
- package/dist/modules/forecasting/ForecastingModule.js +310 -0
- package/dist/modules/forecasting/index.d.ts +3 -0
- package/dist/modules/forecasting/index.d.ts.map +1 -0
- package/dist/modules/forecasting/index.js +1 -0
- package/dist/modules/monitoring/MonitoringModule.d.ts +359 -0
- package/dist/modules/monitoring/MonitoringModule.d.ts.map +1 -0
- package/dist/modules/monitoring/MonitoringModule.js +483 -0
- package/dist/modules/monitoring/index.d.ts +3 -0
- package/dist/modules/monitoring/index.d.ts.map +1 -0
- package/dist/modules/monitoring/index.js +1 -0
- package/dist/modules/notifications/NotificationsModule.d.ts +336 -0
- package/dist/modules/notifications/NotificationsModule.d.ts.map +1 -0
- package/dist/modules/notifications/NotificationsModule.js +418 -0
- package/dist/modules/notifications/index.d.ts +3 -0
- package/dist/modules/notifications/index.d.ts.map +1 -0
- package/dist/modules/notifications/index.js +1 -0
- package/dist/modules/oracle/OracleModule.d.ts +110 -0
- package/dist/modules/oracle/OracleModule.d.ts.map +1 -0
- package/dist/modules/oracle/OracleModule.js +151 -0
- package/dist/modules/oracle/index.d.ts +6 -0
- package/dist/modules/oracle/index.d.ts.map +1 -0
- package/dist/modules/oracle/index.js +4 -0
- package/dist/modules/storage/S3Module.d.ts +377 -0
- package/dist/modules/storage/S3Module.d.ts.map +1 -0
- package/dist/modules/storage/S3Module.js +680 -0
- package/dist/modules/storage/StorageModule.d.ts +157 -0
- package/dist/modules/storage/StorageModule.d.ts.map +1 -0
- package/dist/modules/storage/StorageModule.js +302 -0
- package/dist/modules/storage/adapters/AdapterFactory.d.ts +100 -0
- package/dist/modules/storage/adapters/AdapterFactory.d.ts.map +1 -0
- package/dist/modules/storage/adapters/AdapterFactory.js +209 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.d.ts +94 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.js +263 -0
- package/dist/modules/storage/adapters/IStorageAdapter.d.ts +287 -0
- package/dist/modules/storage/adapters/IStorageAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/IStorageAdapter.js +81 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.d.ts +187 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.js +430 -0
- package/dist/modules/storage/adapters/index.d.ts +12 -0
- package/dist/modules/storage/adapters/index.d.ts.map +1 -0
- package/dist/modules/storage/adapters/index.js +12 -0
- package/dist/modules/storage/index.d.ts +16 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +15 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.d.ts +227 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.d.ts.map +1 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.js +367 -0
- package/dist/modules/storage/tiering/CostOptimizer.d.ts +248 -0
- package/dist/modules/storage/tiering/CostOptimizer.d.ts.map +1 -0
- package/dist/modules/storage/tiering/CostOptimizer.js +356 -0
- package/dist/modules/storage/tiering/MetadataStore.d.ts +287 -0
- package/dist/modules/storage/tiering/MetadataStore.d.ts.map +1 -0
- package/dist/modules/storage/tiering/MetadataStore.js +535 -0
- package/dist/modules/storage/tiering/TieringEngine.d.ts +237 -0
- package/dist/modules/storage/tiering/TieringEngine.d.ts.map +1 -0
- package/dist/modules/storage/tiering/TieringEngine.js +419 -0
- package/dist/modules/storage/tiering/example.d.ts +8 -0
- package/dist/modules/storage/tiering/example.d.ts.map +1 -0
- package/dist/modules/storage/tiering/example.js +250 -0
- package/dist/modules/storage/tiering/index.d.ts +17 -0
- package/dist/modules/storage/tiering/index.d.ts.map +1 -0
- package/dist/modules/storage/tiering/index.js +13 -0
- package/dist/modules/webhooks/WebhooksModule.d.ts +476 -0
- package/dist/modules/webhooks/WebhooksModule.d.ts.map +1 -0
- package/dist/modules/webhooks/WebhooksModule.js +359 -0
- package/dist/modules/webhooks/index.d.ts +3 -0
- package/dist/modules/webhooks/index.d.ts.map +1 -0
- package/dist/modules/webhooks/index.js +1 -0
- package/dist/modules/zk/ZKModule.d.ts +153 -0
- package/dist/modules/zk/ZKModule.d.ts.map +1 -0
- package/dist/modules/zk/ZKModule.js +262 -0
- package/dist/modules/zk/index.d.ts +7 -0
- package/dist/modules/zk/index.d.ts.map +1 -0
- package/dist/modules/zk/index.js +4 -0
- package/dist/thirdweb/BridgeClient.d.ts +228 -0
- package/dist/thirdweb/BridgeClient.d.ts.map +1 -0
- package/dist/thirdweb/BridgeClient.js +160 -0
- package/dist/thirdweb/EngineClient.d.ts +396 -0
- package/dist/thirdweb/EngineClient.d.ts.map +1 -0
- package/dist/thirdweb/EngineClient.js +386 -0
- package/dist/thirdweb/GatewayClient.d.ts +190 -0
- package/dist/thirdweb/GatewayClient.d.ts.map +1 -0
- package/dist/thirdweb/GatewayClient.js +257 -0
- package/dist/thirdweb/NebulaClient.d.ts +292 -0
- package/dist/thirdweb/NebulaClient.d.ts.map +1 -0
- package/dist/thirdweb/NebulaClient.js +180 -0
- package/dist/thirdweb/StorageClient.d.ts +445 -0
- package/dist/thirdweb/StorageClient.d.ts.map +1 -0
- package/dist/thirdweb/StorageClient.js +405 -0
- package/dist/thirdweb/ThirdwebWrapper.d.ts +236 -0
- package/dist/thirdweb/ThirdwebWrapper.d.ts.map +1 -0
- package/dist/thirdweb/ThirdwebWrapper.js +332 -0
- package/dist/thirdweb/index.d.ts +21 -0
- package/dist/thirdweb/index.d.ts.map +1 -0
- package/dist/thirdweb/index.js +28 -0
- package/dist/thirdweb/varity-chain.d.ts +48 -0
- package/dist/thirdweb/varity-chain.d.ts.map +1 -0
- package/dist/thirdweb/varity-chain.js +64 -0
- package/dist/thirdweb/x402Client.d.ts +319 -0
- package/dist/thirdweb/x402Client.d.ts.map +1 -0
- package/dist/thirdweb/x402Client.js +223 -0
- package/dist/tracking/gasTracker.d.ts +158 -0
- package/dist/tracking/gasTracker.d.ts.map +1 -0
- package/dist/tracking/gasTracker.js +227 -0
- package/dist/tracking/index.d.ts +10 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/index.js +8 -0
- package/dist/tracking/types.d.ts +327 -0
- package/dist/tracking/types.d.ts.map +1 -0
- package/dist/tracking/types.js +8 -0
- package/dist/ui/components/ChartWidget.d.ts +36 -0
- package/dist/ui/components/ChartWidget.d.ts.map +1 -0
- package/dist/ui/components/ChartWidget.js +82 -0
- package/dist/ui/components/DashboardLayout.d.ts +41 -0
- package/dist/ui/components/DashboardLayout.d.ts.map +1 -0
- package/dist/ui/components/DashboardLayout.js +102 -0
- package/dist/ui/components/DataTable.d.ts +49 -0
- package/dist/ui/components/DataTable.d.ts.map +1 -0
- package/dist/ui/components/DataTable.js +96 -0
- package/dist/ui/components/EntityForm.d.ts +60 -0
- package/dist/ui/components/EntityForm.d.ts.map +1 -0
- package/dist/ui/components/EntityForm.js +182 -0
- package/dist/ui/components/KPICard.d.ts +29 -0
- package/dist/ui/components/KPICard.d.ts.map +1 -0
- package/dist/ui/components/KPICard.js +61 -0
- package/dist/ui/components/Modal.d.ts +34 -0
- package/dist/ui/components/Modal.d.ts.map +1 -0
- package/dist/ui/components/Modal.js +30 -0
- package/dist/ui/components/index.d.ts +18 -0
- package/dist/ui/components/index.d.ts.map +1 -0
- package/dist/ui/components/index.js +11 -0
- package/dist/validation/template-validator.d.ts +25 -0
- package/dist/validation/template-validator.d.ts.map +1 -0
- package/dist/validation/template-validator.js +305 -0
- package/package.json +102 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development Server
|
|
3
|
+
*
|
|
4
|
+
* Hot-reload development mode with file watching
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import chokidar from 'chokidar';
|
|
9
|
+
import { Logger } from '../cli/utils/logger';
|
|
10
|
+
import { generateContracts } from '../generators/contracts/generator';
|
|
11
|
+
import { generateTypes } from '../generators/types/generator';
|
|
12
|
+
/**
|
|
13
|
+
* Start development server with hot-reload
|
|
14
|
+
*/
|
|
15
|
+
export async function startDevServer(options) {
|
|
16
|
+
Logger.success('Development server started!');
|
|
17
|
+
Logger.newline();
|
|
18
|
+
// Initial generation
|
|
19
|
+
await regenerateAll(options);
|
|
20
|
+
if (options.watch) {
|
|
21
|
+
Logger.info('👀 Watching for changes...');
|
|
22
|
+
Logger.code(' Press Ctrl+C to stop');
|
|
23
|
+
Logger.newline();
|
|
24
|
+
// Watch template file
|
|
25
|
+
const watcher = chokidar.watch(options.templatePath, {
|
|
26
|
+
persistent: true,
|
|
27
|
+
ignoreInitial: true
|
|
28
|
+
});
|
|
29
|
+
watcher.on('change', async (filePath) => {
|
|
30
|
+
Logger.newline();
|
|
31
|
+
Logger.warn(`Template changed: ${filePath}`);
|
|
32
|
+
await regenerateAll(options);
|
|
33
|
+
Logger.success('✓ Regeneration complete');
|
|
34
|
+
Logger.newline();
|
|
35
|
+
Logger.info('👀 Watching for changes...');
|
|
36
|
+
});
|
|
37
|
+
watcher.on('error', (error) => {
|
|
38
|
+
Logger.error(`Watcher error: ${error.message}`);
|
|
39
|
+
});
|
|
40
|
+
// Keep process alive
|
|
41
|
+
process.on('SIGINT', () => {
|
|
42
|
+
Logger.newline();
|
|
43
|
+
Logger.info('Stopping development server...');
|
|
44
|
+
watcher.close();
|
|
45
|
+
process.exit(0);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
Logger.info('Watch mode disabled. Run with --watch to enable.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Regenerate all generated files
|
|
54
|
+
*/
|
|
55
|
+
async function regenerateAll(options) {
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
try {
|
|
58
|
+
// Generate contracts
|
|
59
|
+
Logger.step(1, 3, 'Generating contracts...');
|
|
60
|
+
const contractResult = await generateContracts({
|
|
61
|
+
templatePath: options.templatePath,
|
|
62
|
+
outputPath: options.contractsPath,
|
|
63
|
+
includeTests: true
|
|
64
|
+
});
|
|
65
|
+
if (!contractResult.success) {
|
|
66
|
+
Logger.error('Contract generation failed:');
|
|
67
|
+
contractResult.errors.forEach(error => Logger.error(` ${error}`));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
Logger.success(` Generated ${contractResult.contracts.length} contracts`);
|
|
71
|
+
// Generate types
|
|
72
|
+
Logger.step(2, 3, 'Generating types...');
|
|
73
|
+
const abiDir = path.join(path.dirname(options.contractsPath), 'abis');
|
|
74
|
+
if (fs.existsSync(abiDir)) {
|
|
75
|
+
const typeResult = await generateTypes({
|
|
76
|
+
abiDir,
|
|
77
|
+
outputPath: path.join(path.dirname(options.contractsPath), 'types')
|
|
78
|
+
});
|
|
79
|
+
if (typeResult.success) {
|
|
80
|
+
Logger.success(` Generated ${typeResult.types.length} type files`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
Logger.warn(' No ABIs found, skipping type generation');
|
|
85
|
+
}
|
|
86
|
+
// Validation
|
|
87
|
+
Logger.step(3, 3, 'Validating output...');
|
|
88
|
+
const validation = validateGeneration(contractResult);
|
|
89
|
+
if (validation.valid) {
|
|
90
|
+
Logger.success(' Validation passed');
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
Logger.warn(' Validation warnings:');
|
|
94
|
+
validation.warnings.forEach(warning => Logger.warn(` ${warning}`));
|
|
95
|
+
}
|
|
96
|
+
const duration = Date.now() - startTime;
|
|
97
|
+
Logger.newline();
|
|
98
|
+
Logger.success(`✨ All done in ${duration}ms`);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
Logger.error(`Regeneration failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Validate generated files
|
|
106
|
+
*/
|
|
107
|
+
function validateGeneration(contractResult) {
|
|
108
|
+
const warnings = [];
|
|
109
|
+
if (contractResult.contracts.length === 0) {
|
|
110
|
+
warnings.push('No contracts were generated');
|
|
111
|
+
}
|
|
112
|
+
if (contractResult.tests.length === 0) {
|
|
113
|
+
warnings.push('No test files were generated');
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
valid: warnings.length === 0,
|
|
117
|
+
warnings
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates Solidity smart contracts from template configuration
|
|
5
|
+
*/
|
|
6
|
+
export interface GenerateContractsOptions {
|
|
7
|
+
templatePath: string;
|
|
8
|
+
outputPath: string;
|
|
9
|
+
includeTests?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface GenerateContractsResult {
|
|
12
|
+
contracts: string[];
|
|
13
|
+
tests: string[];
|
|
14
|
+
success: boolean;
|
|
15
|
+
errors: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate smart contracts from template configuration
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateContracts(options: GenerateContractsOptions): Promise<GenerateContractsResult>;
|
|
21
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/contracts/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CA8ElC"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates Solidity smart contracts from template configuration
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import Handlebars from 'handlebars';
|
|
9
|
+
/**
|
|
10
|
+
* Generate smart contracts from template configuration
|
|
11
|
+
*/
|
|
12
|
+
export async function generateContracts(options) {
|
|
13
|
+
const result = {
|
|
14
|
+
contracts: [],
|
|
15
|
+
tests: [],
|
|
16
|
+
success: false,
|
|
17
|
+
errors: []
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
// Load template configuration
|
|
21
|
+
const templatePath = path.resolve(options.templatePath);
|
|
22
|
+
if (!fs.existsSync(templatePath)) {
|
|
23
|
+
throw new Error(`Template file not found: ${templatePath}`);
|
|
24
|
+
}
|
|
25
|
+
const templateContent = fs.readFileSync(templatePath, 'utf-8');
|
|
26
|
+
const template = JSON.parse(templateContent);
|
|
27
|
+
// Create output directory
|
|
28
|
+
const outputPath = path.resolve(options.outputPath);
|
|
29
|
+
if (!fs.existsSync(outputPath)) {
|
|
30
|
+
fs.mkdirSync(outputPath, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
// Load Handlebars template
|
|
33
|
+
const templatesDir = path.join(__dirname, 'templates');
|
|
34
|
+
const registryTemplate = fs.readFileSync(path.join(templatesDir, 'registry.sol.hbs'), 'utf-8');
|
|
35
|
+
const compiledTemplate = Handlebars.compile(registryTemplate);
|
|
36
|
+
// Generate contracts for each entity
|
|
37
|
+
for (const entity of template.entities) {
|
|
38
|
+
try {
|
|
39
|
+
const contractCode = generateContractForEntity(entity, template, compiledTemplate);
|
|
40
|
+
const contractName = getContractNameForEntity(entity);
|
|
41
|
+
const contractFile = path.join(outputPath, `${contractName}.sol`);
|
|
42
|
+
fs.writeFileSync(contractFile, contractCode);
|
|
43
|
+
result.contracts.push(contractFile);
|
|
44
|
+
// Generate test file if requested
|
|
45
|
+
if (options.includeTests) {
|
|
46
|
+
const testCode = generateTestForEntity(entity, template, contractName);
|
|
47
|
+
const testFile = path.join(path.dirname(outputPath), 'test', `${contractName}.test.ts`);
|
|
48
|
+
// Create test directory if needed
|
|
49
|
+
const testDir = path.dirname(testFile);
|
|
50
|
+
if (!fs.existsSync(testDir)) {
|
|
51
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
fs.writeFileSync(testFile, testCode);
|
|
54
|
+
result.tests.push(testFile);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
result.errors.push(`Failed to generate contract for entity ${entity.name}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
result.success = result.errors.length === 0;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
result.errors.push(`Failed to generate contracts: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate contract code for a single entity
|
|
70
|
+
*/
|
|
71
|
+
function generateContractForEntity(entity, template, compiledTemplate) {
|
|
72
|
+
const contractName = getContractNameForEntity(entity);
|
|
73
|
+
const entityStructName = capitalize(entity.name);
|
|
74
|
+
const entityDisplayName = entity.displayName || capitalize(entity.name);
|
|
75
|
+
const entityNameLower = entity.name.toLowerCase();
|
|
76
|
+
// Find ID field
|
|
77
|
+
const idField = entity.fields.find(f => f.name === entity.idField) || entity.fields[0];
|
|
78
|
+
const idFieldType = mapTypeToSolidity(idField.type);
|
|
79
|
+
// Prepare template data
|
|
80
|
+
const templateData = {
|
|
81
|
+
contractName,
|
|
82
|
+
entityName: entity.name,
|
|
83
|
+
entityStructName,
|
|
84
|
+
entityDisplayName,
|
|
85
|
+
entityNameLower,
|
|
86
|
+
description: entity.description || `${entityDisplayName} registry contract`,
|
|
87
|
+
templateName: template.name,
|
|
88
|
+
timestamp: new Date().toISOString(),
|
|
89
|
+
idField: entity.idField,
|
|
90
|
+
idFieldType,
|
|
91
|
+
fields: entity.fields.map(field => ({
|
|
92
|
+
name: field.name,
|
|
93
|
+
type: mapTypeToSolidity(field.type),
|
|
94
|
+
description: field.description || field.name
|
|
95
|
+
})),
|
|
96
|
+
createParams: entity.fields
|
|
97
|
+
.filter(f => f.required && !['createdAt', 'isActive'].includes(f.name))
|
|
98
|
+
.map(field => ({
|
|
99
|
+
name: field.name,
|
|
100
|
+
type: mapTypeToSolidity(field.type),
|
|
101
|
+
description: field.description || field.name,
|
|
102
|
+
isMemory: needsMemoryKeyword(field.type)
|
|
103
|
+
})),
|
|
104
|
+
fieldAssignments: entity.fields.map(field => ({
|
|
105
|
+
name: field.name,
|
|
106
|
+
value: getFieldAssignmentValue(field)
|
|
107
|
+
})),
|
|
108
|
+
updateParams: [
|
|
109
|
+
{
|
|
110
|
+
name: entity.idField,
|
|
111
|
+
type: idFieldType,
|
|
112
|
+
description: `The ${entity.name} ID`,
|
|
113
|
+
isMemory: false
|
|
114
|
+
},
|
|
115
|
+
...entity.fields
|
|
116
|
+
.filter(f => !['createdAt', 'isActive', entity.idField].includes(f.name))
|
|
117
|
+
.map(field => ({
|
|
118
|
+
name: field.name,
|
|
119
|
+
type: mapTypeToSolidity(field.type),
|
|
120
|
+
description: field.description || field.name,
|
|
121
|
+
isMemory: needsMemoryKeyword(field.type)
|
|
122
|
+
}))
|
|
123
|
+
],
|
|
124
|
+
updateAssignments: entity.fields
|
|
125
|
+
.filter(f => !['createdAt', 'isActive', entity.idField].includes(f.name))
|
|
126
|
+
.map(field => ({
|
|
127
|
+
name: field.name,
|
|
128
|
+
value: field.name
|
|
129
|
+
})),
|
|
130
|
+
generateId: idFieldType === 'bytes32'
|
|
131
|
+
? `keccak256(abi.encodePacked(${entity.fields.filter(f => f.name !== entity.idField && f.required).map(f => f.name).join(', ')}, block.timestamp))`
|
|
132
|
+
: '_${entityNameLower}Counter.current()'
|
|
133
|
+
};
|
|
134
|
+
return compiledTemplate(templateData);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Generate test file for entity contract
|
|
138
|
+
*/
|
|
139
|
+
function generateTestForEntity(entity, template, contractName) {
|
|
140
|
+
const entityDisplayName = entity.displayName || capitalize(entity.name);
|
|
141
|
+
return `import { expect } from "chai"
|
|
142
|
+
import { ethers } from "hardhat"
|
|
143
|
+
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"
|
|
144
|
+
|
|
145
|
+
describe("${contractName}", function () {
|
|
146
|
+
async function deploy${contractName}Fixture() {
|
|
147
|
+
const [owner, manager, user] = await ethers.getSigners()
|
|
148
|
+
|
|
149
|
+
const Contract = await ethers.getContractFactory("${contractName}")
|
|
150
|
+
const contract = await Contract.deploy()
|
|
151
|
+
|
|
152
|
+
// Grant manager role
|
|
153
|
+
const MANAGER_ROLE = await contract.MANAGER_ROLE()
|
|
154
|
+
await contract.grantRole(MANAGER_ROLE, manager.address)
|
|
155
|
+
|
|
156
|
+
return { contract, owner, manager, user }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
describe("Deployment", function () {
|
|
160
|
+
it("Should deploy successfully", async function () {
|
|
161
|
+
const { contract, owner } = await loadFixture(deploy${contractName}Fixture)
|
|
162
|
+
expect(await contract.hasRole(await contract.DEFAULT_ADMIN_ROLE(), owner.address)).to.be.true
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
describe("Create ${entityDisplayName}", function () {
|
|
167
|
+
it("Should create new ${entity.name}", async function () {
|
|
168
|
+
const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
|
|
169
|
+
|
|
170
|
+
// TODO: Add test parameters based on entity fields
|
|
171
|
+
// const tx = await contract.connect(manager).create${entityDisplayName}(...)
|
|
172
|
+
// expect(tx).to.emit(contract, "${entityDisplayName}Created")
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it("Should fail if not manager", async function () {
|
|
176
|
+
const { contract, user } = await loadFixture(deploy${contractName}Fixture)
|
|
177
|
+
|
|
178
|
+
// TODO: Add test logic
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
describe("Read ${entityDisplayName}", function () {
|
|
183
|
+
it("Should read ${entity.name} data", async function () {
|
|
184
|
+
const { contract } = await loadFixture(deploy${contractName}Fixture)
|
|
185
|
+
|
|
186
|
+
// TODO: Add test logic
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
describe("Update ${entityDisplayName}", function () {
|
|
191
|
+
it("Should update ${entity.name}", async function () {
|
|
192
|
+
const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
|
|
193
|
+
|
|
194
|
+
// TODO: Add test logic
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
describe("Deactivate ${entityDisplayName}", function () {
|
|
199
|
+
it("Should deactivate ${entity.name}", async function () {
|
|
200
|
+
const { contract, owner } = await loadFixture(deploy${contractName}Fixture)
|
|
201
|
+
|
|
202
|
+
// TODO: Add test logic
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
`;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Get contract name for entity
|
|
210
|
+
*/
|
|
211
|
+
function getContractNameForEntity(entity) {
|
|
212
|
+
const baseName = capitalize(entity.name);
|
|
213
|
+
return `${baseName}Registry`;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Map template field types to Solidity types
|
|
217
|
+
*/
|
|
218
|
+
function mapTypeToSolidity(type) {
|
|
219
|
+
const typeMap = {
|
|
220
|
+
'string': 'string',
|
|
221
|
+
'number': 'uint256',
|
|
222
|
+
'boolean': 'bool',
|
|
223
|
+
'address': 'address',
|
|
224
|
+
'bytes': 'bytes',
|
|
225
|
+
'bytes32': 'bytes32'
|
|
226
|
+
};
|
|
227
|
+
return typeMap[type] || 'string';
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check if type needs memory keyword
|
|
231
|
+
*/
|
|
232
|
+
function needsMemoryKeyword(type) {
|
|
233
|
+
return ['string', 'bytes'].includes(type);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Get field assignment value
|
|
237
|
+
*/
|
|
238
|
+
function getFieldAssignmentValue(field) {
|
|
239
|
+
if (field.name === 'createdAt') {
|
|
240
|
+
return 'block.timestamp';
|
|
241
|
+
}
|
|
242
|
+
if (field.name === 'isActive') {
|
|
243
|
+
return 'true';
|
|
244
|
+
}
|
|
245
|
+
return field.name;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Capitalize first letter
|
|
249
|
+
*/
|
|
250
|
+
function capitalize(str) {
|
|
251
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
252
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates comprehensive test suites for smart contracts
|
|
5
|
+
*/
|
|
6
|
+
export interface GenerateTestsOptions {
|
|
7
|
+
templatePath: string;
|
|
8
|
+
contractsPath: string;
|
|
9
|
+
outputPath: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GenerateTestsResult {
|
|
12
|
+
tests: string[];
|
|
13
|
+
success: boolean;
|
|
14
|
+
errors: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate test suites for contracts
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateTests(options: GenerateTestsOptions): Promise<GenerateTestsResult>;
|
|
20
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/tests/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAyD9B"}
|