@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.
Files changed (295) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +253 -0
  3. package/dist/analytics/index.d.ts +7 -0
  4. package/dist/analytics/index.d.ts.map +1 -0
  5. package/dist/analytics/index.js +6 -0
  6. package/dist/analytics/tracker.d.ts +128 -0
  7. package/dist/analytics/tracker.d.ts.map +1 -0
  8. package/dist/analytics/tracker.js +203 -0
  9. package/dist/blockchain/BlockchainService.d.ts +100 -0
  10. package/dist/blockchain/BlockchainService.d.ts.map +1 -0
  11. package/dist/blockchain/BlockchainService.js +188 -0
  12. package/dist/blockchain/NFTLicensingService.d.ts +69 -0
  13. package/dist/blockchain/NFTLicensingService.d.ts.map +1 -0
  14. package/dist/blockchain/NFTLicensingService.js +136 -0
  15. package/dist/blockchain/RevenueSplitService.d.ts +71 -0
  16. package/dist/blockchain/RevenueSplitService.d.ts.map +1 -0
  17. package/dist/blockchain/RevenueSplitService.js +111 -0
  18. package/dist/blockchain/index.d.ts +48 -0
  19. package/dist/blockchain/index.d.ts.map +1 -0
  20. package/dist/blockchain/index.js +46 -0
  21. package/dist/blockchain/types.d.ts +63 -0
  22. package/dist/blockchain/types.d.ts.map +1 -0
  23. package/dist/blockchain/types.js +6 -0
  24. package/dist/chains/arbitrum.d.ts +89 -0
  25. package/dist/chains/arbitrum.d.ts.map +1 -0
  26. package/dist/chains/arbitrum.js +134 -0
  27. package/dist/chains/base.d.ts +84 -0
  28. package/dist/chains/base.d.ts.map +1 -0
  29. package/dist/chains/base.js +131 -0
  30. package/dist/chains/index.d.ts +36 -0
  31. package/dist/chains/index.d.ts.map +1 -0
  32. package/dist/chains/index.js +32 -0
  33. package/dist/chains/registry.d.ts +113 -0
  34. package/dist/chains/registry.d.ts.map +1 -0
  35. package/dist/chains/registry.js +201 -0
  36. package/dist/chains/varityL3.d.ts +81 -0
  37. package/dist/chains/varityL3.d.ts.map +1 -0
  38. package/dist/chains/varityL3.js +125 -0
  39. package/dist/cli/commands/clone.d.ts +8 -0
  40. package/dist/cli/commands/clone.d.ts.map +1 -0
  41. package/dist/cli/commands/clone.js +391 -0
  42. package/dist/cli/commands/dev.d.ts +8 -0
  43. package/dist/cli/commands/dev.d.ts.map +1 -0
  44. package/dist/cli/commands/dev.js +40 -0
  45. package/dist/cli/commands/generate.d.ts +8 -0
  46. package/dist/cli/commands/generate.d.ts.map +1 -0
  47. package/dist/cli/commands/generate.js +303 -0
  48. package/dist/cli/commands/init.d.ts +8 -0
  49. package/dist/cli/commands/init.d.ts.map +1 -0
  50. package/dist/cli/commands/init.js +317 -0
  51. package/dist/cli/commands/validate.d.ts +8 -0
  52. package/dist/cli/commands/validate.d.ts.map +1 -0
  53. package/dist/cli/commands/validate.js +69 -0
  54. package/dist/cli/index.d.ts +8 -0
  55. package/dist/cli/index.d.ts.map +1 -0
  56. package/dist/cli/index.js +33 -0
  57. package/dist/cli/utils/logger.d.ts +17 -0
  58. package/dist/cli/utils/logger.d.ts.map +1 -0
  59. package/dist/cli/utils/logger.js +35 -0
  60. package/dist/cli/utils/prompts.d.ts +21 -0
  61. package/dist/cli/utils/prompts.d.ts.map +1 -0
  62. package/dist/cli/utils/prompts.js +103 -0
  63. package/dist/contracts/abis/iso/AccessControlRegistry.json +1468 -0
  64. package/dist/contracts/abis/iso/DataProofRegistry.json +797 -0
  65. package/dist/contracts/abis/iso/MerchantRegistry.json +1237 -0
  66. package/dist/contracts/abis/iso/RepPerformance.json +1351 -0
  67. package/dist/contracts/abis/iso/ResidualCalculator.json +1118 -0
  68. package/dist/contracts/abis/iso/TransactionVault.json +1588 -0
  69. package/dist/contracts/abis/iso/VarityWalletFactory.json +475 -0
  70. package/dist/contracts/addresses.d.ts +88 -0
  71. package/dist/contracts/addresses.d.ts.map +1 -0
  72. package/dist/contracts/addresses.js +94 -0
  73. package/dist/contracts/index.d.ts +7 -0
  74. package/dist/contracts/index.d.ts.map +1 -0
  75. package/dist/contracts/index.js +6 -0
  76. package/dist/core/VaritySDK.d.ts +177 -0
  77. package/dist/core/VaritySDK.d.ts.map +1 -0
  78. package/dist/core/VaritySDK.js +325 -0
  79. package/dist/core/config.d.ts +120 -0
  80. package/dist/core/config.d.ts.map +1 -0
  81. package/dist/core/config.js +187 -0
  82. package/dist/core/credentials-proxy.d.ts +157 -0
  83. package/dist/core/credentials-proxy.d.ts.map +1 -0
  84. package/dist/core/credentials-proxy.js +345 -0
  85. package/dist/core/credentials.d.ts +219 -0
  86. package/dist/core/credentials.d.ts.map +1 -0
  87. package/dist/core/credentials.js +345 -0
  88. package/dist/core/template-loader.d.ts +15 -0
  89. package/dist/core/template-loader.d.ts.map +1 -0
  90. package/dist/core/template-loader.js +380 -0
  91. package/dist/core/template.d.ts +321 -0
  92. package/dist/core/template.d.ts.map +1 -0
  93. package/dist/core/template.js +189 -0
  94. package/dist/core/types.d.ts +572 -0
  95. package/dist/core/types.d.ts.map +1 -0
  96. package/dist/core/types.js +52 -0
  97. package/dist/dev/dev-server.d.ts +16 -0
  98. package/dist/dev/dev-server.d.ts.map +1 -0
  99. package/dist/dev/dev-server.js +119 -0
  100. package/dist/generators/contracts/generator.d.ts +21 -0
  101. package/dist/generators/contracts/generator.d.ts.map +1 -0
  102. package/dist/generators/contracts/generator.js +252 -0
  103. package/dist/generators/tests/generator.d.ts +20 -0
  104. package/dist/generators/tests/generator.d.ts.map +1 -0
  105. package/dist/generators/tests/generator.js +375 -0
  106. package/dist/generators/types/generator.d.ts +19 -0
  107. package/dist/generators/types/generator.d.ts.map +1 -0
  108. package/dist/generators/types/generator.js +165 -0
  109. package/dist/generators/ui/component-generator.d.ts +20 -0
  110. package/dist/generators/ui/component-generator.d.ts.map +1 -0
  111. package/dist/generators/ui/component-generator.js +749 -0
  112. package/dist/generators/ui/dashboard-generator.d.ts +20 -0
  113. package/dist/generators/ui/dashboard-generator.d.ts.map +1 -0
  114. package/dist/generators/ui/dashboard-generator.js +349 -0
  115. package/dist/index.d.ts +61 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +74 -0
  118. package/dist/modules/analytics/AnalyticsModule.d.ts +349 -0
  119. package/dist/modules/analytics/AnalyticsModule.d.ts.map +1 -0
  120. package/dist/modules/analytics/AnalyticsModule.js +274 -0
  121. package/dist/modules/analytics/index.d.ts +3 -0
  122. package/dist/modules/analytics/index.d.ts.map +1 -0
  123. package/dist/modules/analytics/index.js +1 -0
  124. package/dist/modules/auth/AccessKeyModule.d.ts +189 -0
  125. package/dist/modules/auth/AccessKeyModule.d.ts.map +1 -0
  126. package/dist/modules/auth/AccessKeyModule.js +322 -0
  127. package/dist/modules/auth/AuthModule.d.ts +133 -0
  128. package/dist/modules/auth/AuthModule.d.ts.map +1 -0
  129. package/dist/modules/auth/AuthModule.js +214 -0
  130. package/dist/modules/auth/index.d.ts +8 -0
  131. package/dist/modules/auth/index.d.ts.map +1 -0
  132. package/dist/modules/auth/index.js +6 -0
  133. package/dist/modules/cache/CacheModule.d.ts +279 -0
  134. package/dist/modules/cache/CacheModule.d.ts.map +1 -0
  135. package/dist/modules/cache/CacheModule.js +493 -0
  136. package/dist/modules/cache/index.d.ts +3 -0
  137. package/dist/modules/cache/index.d.ts.map +1 -0
  138. package/dist/modules/cache/index.js +1 -0
  139. package/dist/modules/compute/ComputeModule.d.ts +226 -0
  140. package/dist/modules/compute/ComputeModule.d.ts.map +1 -0
  141. package/dist/modules/compute/ComputeModule.js +379 -0
  142. package/dist/modules/compute/index.d.ts +6 -0
  143. package/dist/modules/compute/index.d.ts.map +1 -0
  144. package/dist/modules/compute/index.js +4 -0
  145. package/dist/modules/contracts/ContractsModule.d.ts +164 -0
  146. package/dist/modules/contracts/ContractsModule.d.ts.map +1 -0
  147. package/dist/modules/contracts/ContractsModule.js +242 -0
  148. package/dist/modules/contracts/index.d.ts +6 -0
  149. package/dist/modules/contracts/index.d.ts.map +1 -0
  150. package/dist/modules/contracts/index.js +4 -0
  151. package/dist/modules/export/ExportModule.d.ts +346 -0
  152. package/dist/modules/export/ExportModule.d.ts.map +1 -0
  153. package/dist/modules/export/ExportModule.js +432 -0
  154. package/dist/modules/export/index.d.ts +3 -0
  155. package/dist/modules/export/index.d.ts.map +1 -0
  156. package/dist/modules/export/index.js +1 -0
  157. package/dist/modules/forecasting/ForecastingModule.d.ts +579 -0
  158. package/dist/modules/forecasting/ForecastingModule.d.ts.map +1 -0
  159. package/dist/modules/forecasting/ForecastingModule.js +310 -0
  160. package/dist/modules/forecasting/index.d.ts +3 -0
  161. package/dist/modules/forecasting/index.d.ts.map +1 -0
  162. package/dist/modules/forecasting/index.js +1 -0
  163. package/dist/modules/monitoring/MonitoringModule.d.ts +359 -0
  164. package/dist/modules/monitoring/MonitoringModule.d.ts.map +1 -0
  165. package/dist/modules/monitoring/MonitoringModule.js +483 -0
  166. package/dist/modules/monitoring/index.d.ts +3 -0
  167. package/dist/modules/monitoring/index.d.ts.map +1 -0
  168. package/dist/modules/monitoring/index.js +1 -0
  169. package/dist/modules/notifications/NotificationsModule.d.ts +336 -0
  170. package/dist/modules/notifications/NotificationsModule.d.ts.map +1 -0
  171. package/dist/modules/notifications/NotificationsModule.js +418 -0
  172. package/dist/modules/notifications/index.d.ts +3 -0
  173. package/dist/modules/notifications/index.d.ts.map +1 -0
  174. package/dist/modules/notifications/index.js +1 -0
  175. package/dist/modules/oracle/OracleModule.d.ts +110 -0
  176. package/dist/modules/oracle/OracleModule.d.ts.map +1 -0
  177. package/dist/modules/oracle/OracleModule.js +151 -0
  178. package/dist/modules/oracle/index.d.ts +6 -0
  179. package/dist/modules/oracle/index.d.ts.map +1 -0
  180. package/dist/modules/oracle/index.js +4 -0
  181. package/dist/modules/storage/S3Module.d.ts +377 -0
  182. package/dist/modules/storage/S3Module.d.ts.map +1 -0
  183. package/dist/modules/storage/S3Module.js +680 -0
  184. package/dist/modules/storage/StorageModule.d.ts +157 -0
  185. package/dist/modules/storage/StorageModule.d.ts.map +1 -0
  186. package/dist/modules/storage/StorageModule.js +302 -0
  187. package/dist/modules/storage/adapters/AdapterFactory.d.ts +100 -0
  188. package/dist/modules/storage/adapters/AdapterFactory.d.ts.map +1 -0
  189. package/dist/modules/storage/adapters/AdapterFactory.js +209 -0
  190. package/dist/modules/storage/adapters/FilecoinAdapter.d.ts +94 -0
  191. package/dist/modules/storage/adapters/FilecoinAdapter.d.ts.map +1 -0
  192. package/dist/modules/storage/adapters/FilecoinAdapter.js +263 -0
  193. package/dist/modules/storage/adapters/IStorageAdapter.d.ts +287 -0
  194. package/dist/modules/storage/adapters/IStorageAdapter.d.ts.map +1 -0
  195. package/dist/modules/storage/adapters/IStorageAdapter.js +81 -0
  196. package/dist/modules/storage/adapters/MultiTierAdapter.d.ts +187 -0
  197. package/dist/modules/storage/adapters/MultiTierAdapter.d.ts.map +1 -0
  198. package/dist/modules/storage/adapters/MultiTierAdapter.js +430 -0
  199. package/dist/modules/storage/adapters/index.d.ts +12 -0
  200. package/dist/modules/storage/adapters/index.d.ts.map +1 -0
  201. package/dist/modules/storage/adapters/index.js +12 -0
  202. package/dist/modules/storage/index.d.ts +16 -0
  203. package/dist/modules/storage/index.d.ts.map +1 -0
  204. package/dist/modules/storage/index.js +15 -0
  205. package/dist/modules/storage/tiering/AccessAnalyzer.d.ts +227 -0
  206. package/dist/modules/storage/tiering/AccessAnalyzer.d.ts.map +1 -0
  207. package/dist/modules/storage/tiering/AccessAnalyzer.js +367 -0
  208. package/dist/modules/storage/tiering/CostOptimizer.d.ts +248 -0
  209. package/dist/modules/storage/tiering/CostOptimizer.d.ts.map +1 -0
  210. package/dist/modules/storage/tiering/CostOptimizer.js +356 -0
  211. package/dist/modules/storage/tiering/MetadataStore.d.ts +287 -0
  212. package/dist/modules/storage/tiering/MetadataStore.d.ts.map +1 -0
  213. package/dist/modules/storage/tiering/MetadataStore.js +535 -0
  214. package/dist/modules/storage/tiering/TieringEngine.d.ts +237 -0
  215. package/dist/modules/storage/tiering/TieringEngine.d.ts.map +1 -0
  216. package/dist/modules/storage/tiering/TieringEngine.js +419 -0
  217. package/dist/modules/storage/tiering/example.d.ts +8 -0
  218. package/dist/modules/storage/tiering/example.d.ts.map +1 -0
  219. package/dist/modules/storage/tiering/example.js +250 -0
  220. package/dist/modules/storage/tiering/index.d.ts +17 -0
  221. package/dist/modules/storage/tiering/index.d.ts.map +1 -0
  222. package/dist/modules/storage/tiering/index.js +13 -0
  223. package/dist/modules/webhooks/WebhooksModule.d.ts +476 -0
  224. package/dist/modules/webhooks/WebhooksModule.d.ts.map +1 -0
  225. package/dist/modules/webhooks/WebhooksModule.js +359 -0
  226. package/dist/modules/webhooks/index.d.ts +3 -0
  227. package/dist/modules/webhooks/index.d.ts.map +1 -0
  228. package/dist/modules/webhooks/index.js +1 -0
  229. package/dist/modules/zk/ZKModule.d.ts +153 -0
  230. package/dist/modules/zk/ZKModule.d.ts.map +1 -0
  231. package/dist/modules/zk/ZKModule.js +262 -0
  232. package/dist/modules/zk/index.d.ts +7 -0
  233. package/dist/modules/zk/index.d.ts.map +1 -0
  234. package/dist/modules/zk/index.js +4 -0
  235. package/dist/thirdweb/BridgeClient.d.ts +228 -0
  236. package/dist/thirdweb/BridgeClient.d.ts.map +1 -0
  237. package/dist/thirdweb/BridgeClient.js +160 -0
  238. package/dist/thirdweb/EngineClient.d.ts +396 -0
  239. package/dist/thirdweb/EngineClient.d.ts.map +1 -0
  240. package/dist/thirdweb/EngineClient.js +386 -0
  241. package/dist/thirdweb/GatewayClient.d.ts +190 -0
  242. package/dist/thirdweb/GatewayClient.d.ts.map +1 -0
  243. package/dist/thirdweb/GatewayClient.js +257 -0
  244. package/dist/thirdweb/NebulaClient.d.ts +292 -0
  245. package/dist/thirdweb/NebulaClient.d.ts.map +1 -0
  246. package/dist/thirdweb/NebulaClient.js +180 -0
  247. package/dist/thirdweb/StorageClient.d.ts +445 -0
  248. package/dist/thirdweb/StorageClient.d.ts.map +1 -0
  249. package/dist/thirdweb/StorageClient.js +405 -0
  250. package/dist/thirdweb/ThirdwebWrapper.d.ts +236 -0
  251. package/dist/thirdweb/ThirdwebWrapper.d.ts.map +1 -0
  252. package/dist/thirdweb/ThirdwebWrapper.js +332 -0
  253. package/dist/thirdweb/index.d.ts +21 -0
  254. package/dist/thirdweb/index.d.ts.map +1 -0
  255. package/dist/thirdweb/index.js +28 -0
  256. package/dist/thirdweb/varity-chain.d.ts +48 -0
  257. package/dist/thirdweb/varity-chain.d.ts.map +1 -0
  258. package/dist/thirdweb/varity-chain.js +64 -0
  259. package/dist/thirdweb/x402Client.d.ts +319 -0
  260. package/dist/thirdweb/x402Client.d.ts.map +1 -0
  261. package/dist/thirdweb/x402Client.js +223 -0
  262. package/dist/tracking/gasTracker.d.ts +158 -0
  263. package/dist/tracking/gasTracker.d.ts.map +1 -0
  264. package/dist/tracking/gasTracker.js +227 -0
  265. package/dist/tracking/index.d.ts +10 -0
  266. package/dist/tracking/index.d.ts.map +1 -0
  267. package/dist/tracking/index.js +8 -0
  268. package/dist/tracking/types.d.ts +327 -0
  269. package/dist/tracking/types.d.ts.map +1 -0
  270. package/dist/tracking/types.js +8 -0
  271. package/dist/ui/components/ChartWidget.d.ts +36 -0
  272. package/dist/ui/components/ChartWidget.d.ts.map +1 -0
  273. package/dist/ui/components/ChartWidget.js +82 -0
  274. package/dist/ui/components/DashboardLayout.d.ts +41 -0
  275. package/dist/ui/components/DashboardLayout.d.ts.map +1 -0
  276. package/dist/ui/components/DashboardLayout.js +102 -0
  277. package/dist/ui/components/DataTable.d.ts +49 -0
  278. package/dist/ui/components/DataTable.d.ts.map +1 -0
  279. package/dist/ui/components/DataTable.js +96 -0
  280. package/dist/ui/components/EntityForm.d.ts +60 -0
  281. package/dist/ui/components/EntityForm.d.ts.map +1 -0
  282. package/dist/ui/components/EntityForm.js +182 -0
  283. package/dist/ui/components/KPICard.d.ts +29 -0
  284. package/dist/ui/components/KPICard.d.ts.map +1 -0
  285. package/dist/ui/components/KPICard.js +61 -0
  286. package/dist/ui/components/Modal.d.ts +34 -0
  287. package/dist/ui/components/Modal.d.ts.map +1 -0
  288. package/dist/ui/components/Modal.js +30 -0
  289. package/dist/ui/components/index.d.ts +18 -0
  290. package/dist/ui/components/index.d.ts.map +1 -0
  291. package/dist/ui/components/index.js +11 -0
  292. package/dist/validation/template-validator.d.ts +25 -0
  293. package/dist/validation/template-validator.d.ts.map +1 -0
  294. package/dist/validation/template-validator.js +305 -0
  295. package/package.json +102 -0
@@ -0,0 +1,375 @@
1
+ /**
2
+ * Test Generator
3
+ *
4
+ * Generates comprehensive test suites for smart contracts
5
+ */
6
+ import * as fs from 'fs';
7
+ import * as path from 'path';
8
+ /**
9
+ * Generate test suites for contracts
10
+ */
11
+ export async function generateTests(options) {
12
+ const result = {
13
+ tests: [],
14
+ success: false,
15
+ errors: []
16
+ };
17
+ try {
18
+ // Load template configuration
19
+ const templatePath = path.resolve(options.templatePath);
20
+ if (!fs.existsSync(templatePath)) {
21
+ throw new Error(`Template file not found: ${templatePath}`);
22
+ }
23
+ const templateContent = fs.readFileSync(templatePath, 'utf-8');
24
+ const template = JSON.parse(templateContent);
25
+ // Create output directory
26
+ const outputPath = path.resolve(options.outputPath);
27
+ if (!fs.existsSync(outputPath)) {
28
+ fs.mkdirSync(outputPath, { recursive: true });
29
+ }
30
+ // Generate tests for each entity
31
+ for (const entity of template.entities) {
32
+ try {
33
+ const contractName = getContractNameForEntity(entity);
34
+ const testContent = generateTestSuite(entity, template, contractName);
35
+ const testFile = path.join(outputPath, `${contractName}.test.ts`);
36
+ fs.writeFileSync(testFile, testContent);
37
+ result.tests.push(testFile);
38
+ }
39
+ catch (error) {
40
+ result.errors.push(`Failed to generate test for entity ${entity.name}: ${error instanceof Error ? error.message : 'Unknown error'}`);
41
+ }
42
+ }
43
+ // Generate integration test suite
44
+ const integrationTest = generateIntegrationTestSuite(template);
45
+ const integrationTestFile = path.join(outputPath, 'integration.test.ts');
46
+ fs.writeFileSync(integrationTestFile, integrationTest);
47
+ result.tests.push(integrationTestFile);
48
+ result.success = result.errors.length === 0;
49
+ }
50
+ catch (error) {
51
+ result.errors.push(`Failed to generate tests: ${error instanceof Error ? error.message : 'Unknown error'}`);
52
+ }
53
+ return result;
54
+ }
55
+ /**
56
+ * Generate test suite for entity contract
57
+ */
58
+ function generateTestSuite(entity, template, contractName) {
59
+ const entityDisplayName = entity.displayName || capitalize(entity.name);
60
+ const entityNameLower = entity.name.toLowerCase();
61
+ // Find required fields for creation
62
+ const requiredFields = entity.fields.filter(f => f.required && !['createdAt', 'isActive'].includes(f.name));
63
+ // Generate sample test data
64
+ const testData = requiredFields.map(field => {
65
+ return `const test${capitalize(field.name)} = ${getTestValue(field.type)}`;
66
+ }).join('\n ');
67
+ const createParams = requiredFields.map(field => `test${capitalize(field.name)}`).join(', ');
68
+ return `import { expect } from "chai"
69
+ import { ethers } from "hardhat"
70
+ import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"
71
+ import type { ${contractName} } from "../typechain-types"
72
+
73
+ describe("${contractName}", function () {
74
+ /**
75
+ * Deployment fixture
76
+ */
77
+ async function deploy${contractName}Fixture() {
78
+ const [owner, manager, user, other] = await ethers.getSigners()
79
+
80
+ const Contract = await ethers.getContractFactory("${contractName}")
81
+ const contract = await Contract.deploy() as ${contractName}
82
+
83
+ // Grant manager role
84
+ const MANAGER_ROLE = await contract.MANAGER_ROLE()
85
+ await contract.grantRole(MANAGER_ROLE, manager.address)
86
+
87
+ return { contract, owner, manager, user, other, MANAGER_ROLE }
88
+ }
89
+
90
+ describe("Deployment", function () {
91
+ it("Should deploy successfully", async function () {
92
+ const { contract, owner } = await loadFixture(deploy${contractName}Fixture)
93
+
94
+ expect(await contract.hasRole(
95
+ await contract.DEFAULT_ADMIN_ROLE(),
96
+ owner.address
97
+ )).to.be.true
98
+ })
99
+
100
+ it("Should grant admin role to deployer", async function () {
101
+ const { contract, owner } = await loadFixture(deploy${contractName}Fixture)
102
+
103
+ const ADMIN_ROLE = await contract.ADMIN_ROLE()
104
+ expect(await contract.hasRole(ADMIN_ROLE, owner.address)).to.be.true
105
+ })
106
+
107
+ it("Should grant manager role correctly", async function () {
108
+ const { contract, manager, MANAGER_ROLE } = await loadFixture(deploy${contractName}Fixture)
109
+
110
+ expect(await contract.hasRole(MANAGER_ROLE, manager.address)).to.be.true
111
+ })
112
+ })
113
+
114
+ describe("Create ${entityDisplayName}", function () {
115
+ it("Should create new ${entityNameLower}", async function () {
116
+ const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
117
+
118
+ ${testData}
119
+
120
+ const tx = await contract.connect(manager).create${entityDisplayName}(
121
+ ${createParams}
122
+ )
123
+
124
+ await expect(tx).to.emit(contract, "${entityDisplayName}Created")
125
+
126
+ // Verify counter incremented
127
+ expect(await contract.get${entityDisplayName}Count()).to.equal(1)
128
+ })
129
+
130
+ it("Should fail if not manager", async function () {
131
+ const { contract, user } = await loadFixture(deploy${contractName}Fixture)
132
+
133
+ ${testData}
134
+
135
+ await expect(
136
+ contract.connect(user).create${entityDisplayName}(${createParams})
137
+ ).to.be.reverted
138
+ })
139
+
140
+ it("Should assign correct values to ${entityNameLower}", async function () {
141
+ const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
142
+
143
+ ${testData}
144
+
145
+ const tx = await contract.connect(manager).create${entityDisplayName}(
146
+ ${createParams}
147
+ )
148
+ await tx.wait()
149
+
150
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
151
+ const ${entityNameLower} = await contract.get${entityDisplayName}(${entityNameLower}Id)
152
+
153
+ expect(${entityNameLower}.isActive).to.be.true
154
+ expect(${entityNameLower}.createdAt).to.be.gt(0)
155
+ })
156
+ })
157
+
158
+ describe("Read ${entityDisplayName}", function () {
159
+ it("Should read ${entityNameLower} data correctly", async function () {
160
+ const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
161
+
162
+ ${testData}
163
+
164
+ const tx = await contract.connect(manager).create${entityDisplayName}(
165
+ ${createParams}
166
+ )
167
+ await tx.wait()
168
+
169
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
170
+ const ${entityNameLower} = await contract.get${entityDisplayName}(${entityNameLower}Id)
171
+
172
+ expect(${entityNameLower}.isActive).to.be.true
173
+ })
174
+
175
+ it("Should fail for non-existent ${entityNameLower}", async function () {
176
+ const { contract } = await loadFixture(deploy${contractName}Fixture)
177
+
178
+ await expect(
179
+ contract.get${entityDisplayName}("0x" + "0".repeat(64))
180
+ ).to.be.revertedWith("${entityDisplayName} not found or inactive")
181
+ })
182
+
183
+ it("Should return all ${entityNameLower} IDs", async function () {
184
+ const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
185
+
186
+ ${testData}
187
+
188
+ // Create multiple ${entityNameLower}s
189
+ await contract.connect(manager).create${entityDisplayName}(${createParams})
190
+ await contract.connect(manager).create${entityDisplayName}(${createParams})
191
+
192
+ const ids = await contract.getAll${entityDisplayName}Ids()
193
+ expect(ids.length).to.equal(2)
194
+ })
195
+ })
196
+
197
+ describe("Update ${entityDisplayName}", function () {
198
+ it("Should update ${entityNameLower} successfully", async function () {
199
+ const { contract, manager } = await loadFixture(deploy${contractName}Fixture)
200
+
201
+ ${testData}
202
+
203
+ // Create ${entityNameLower}
204
+ const createTx = await contract.connect(manager).create${entityDisplayName}(
205
+ ${createParams}
206
+ )
207
+ await createTx.wait()
208
+
209
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
210
+
211
+ // Update ${entityNameLower}
212
+ const updateTx = await contract.connect(manager).update${entityDisplayName}(
213
+ ${entityNameLower}Id,
214
+ ${createParams}
215
+ )
216
+
217
+ await expect(updateTx).to.emit(contract, "${entityDisplayName}Updated")
218
+ })
219
+
220
+ it("Should fail if not manager", async function () {
221
+ const { contract, manager, user } = await loadFixture(deploy${contractName}Fixture)
222
+
223
+ ${testData}
224
+
225
+ const tx = await contract.connect(manager).create${entityDisplayName}(
226
+ ${createParams}
227
+ )
228
+ await tx.wait()
229
+
230
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
231
+
232
+ await expect(
233
+ contract.connect(user).update${entityDisplayName}(
234
+ ${entityNameLower}Id,
235
+ ${createParams}
236
+ )
237
+ ).to.be.reverted
238
+ })
239
+ })
240
+
241
+ describe("Deactivate ${entityDisplayName}", function () {
242
+ it("Should deactivate ${entityNameLower} successfully", async function () {
243
+ const { contract, manager, owner } = await loadFixture(deploy${contractName}Fixture)
244
+
245
+ ${testData}
246
+
247
+ const tx = await contract.connect(manager).create${entityDisplayName}(
248
+ ${createParams}
249
+ )
250
+ await tx.wait()
251
+
252
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
253
+
254
+ const deactivateTx = await contract.connect(owner).deactivate${entityDisplayName}(
255
+ ${entityNameLower}Id
256
+ )
257
+
258
+ await expect(deactivateTx).to.emit(contract, "${entityDisplayName}Deactivated")
259
+
260
+ expect(await contract.is${entityDisplayName}Active(${entityNameLower}Id)).to.be.false
261
+ })
262
+
263
+ it("Should fail if not admin", async function () {
264
+ const { contract, manager, user } = await loadFixture(deploy${contractName}Fixture)
265
+
266
+ ${testData}
267
+
268
+ const tx = await contract.connect(manager).create${entityDisplayName}(
269
+ ${createParams}
270
+ )
271
+ await tx.wait()
272
+
273
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
274
+
275
+ await expect(
276
+ contract.connect(user).deactivate${entityDisplayName}(${entityNameLower}Id)
277
+ ).to.be.reverted
278
+ })
279
+
280
+ it("Should fail for already inactive ${entityNameLower}", async function () {
281
+ const { contract, manager, owner } = await loadFixture(deploy${contractName}Fixture)
282
+
283
+ ${testData}
284
+
285
+ const tx = await contract.connect(manager).create${entityDisplayName}(
286
+ ${createParams}
287
+ )
288
+ await tx.wait()
289
+
290
+ const ${entityNameLower}Id = await contract.${entityNameLower}Ids(0)
291
+
292
+ await contract.connect(owner).deactivate${entityDisplayName}(${entityNameLower}Id)
293
+
294
+ await expect(
295
+ contract.connect(owner).deactivate${entityDisplayName}(${entityNameLower}Id)
296
+ ).to.be.revertedWith("${entityDisplayName} already inactive")
297
+ })
298
+ })
299
+
300
+ describe("Access Control", function () {
301
+ it("Should respect role-based access control", async function () {
302
+ const { contract, user, MANAGER_ROLE } = await loadFixture(deploy${contractName}Fixture)
303
+
304
+ expect(await contract.hasRole(MANAGER_ROLE, user.address)).to.be.false
305
+ })
306
+
307
+ it("Should allow admin to grant manager role", async function () {
308
+ const { contract, owner, other, MANAGER_ROLE } = await loadFixture(deploy${contractName}Fixture)
309
+
310
+ await contract.connect(owner).grantRole(MANAGER_ROLE, other.address)
311
+ expect(await contract.hasRole(MANAGER_ROLE, other.address)).to.be.true
312
+ })
313
+ })
314
+ })
315
+ `;
316
+ }
317
+ /**
318
+ * Generate integration test suite
319
+ */
320
+ function generateIntegrationTestSuite(template) {
321
+ const contractNames = template.entities.map(e => getContractNameForEntity(e));
322
+ return `import { expect } from "chai"
323
+ import { ethers } from "hardhat"
324
+
325
+ describe("Integration Tests", function () {
326
+ describe("Multi-Contract Interactions", function () {
327
+ it("Should deploy all contracts successfully", async function () {
328
+ const [owner] = await ethers.getSigners()
329
+
330
+ ${contractNames.map(name => `
331
+ const ${name} = await ethers.getContractFactory("${name}")
332
+ const ${name.toLowerCase()} = await ${name}.deploy()
333
+ expect(await ${name.toLowerCase()}.hasRole(
334
+ await ${name.toLowerCase()}.DEFAULT_ADMIN_ROLE(),
335
+ owner.address
336
+ )).to.be.true`).join('\n')}
337
+ })
338
+ })
339
+
340
+ describe("Template Configuration", function () {
341
+ it("Should validate template structure", async function () {
342
+ // Add template-specific integration tests here
343
+ expect(true).to.be.true
344
+ })
345
+ })
346
+ })
347
+ `;
348
+ }
349
+ /**
350
+ * Get contract name for entity
351
+ */
352
+ function getContractNameForEntity(entity) {
353
+ const baseName = capitalize(entity.name);
354
+ return `${baseName}Registry`;
355
+ }
356
+ /**
357
+ * Get test value for field type
358
+ */
359
+ function getTestValue(type) {
360
+ const testValues = {
361
+ 'string': '"Test Value"',
362
+ 'number': '12345',
363
+ 'boolean': 'true',
364
+ 'address': 'ethers.ZeroAddress',
365
+ 'bytes': '"0x1234"',
366
+ 'bytes32': 'ethers.ZeroHash'
367
+ };
368
+ return testValues[type] || '"Test Value"';
369
+ }
370
+ /**
371
+ * Capitalize first letter
372
+ */
373
+ function capitalize(str) {
374
+ return str.charAt(0).toUpperCase() + str.slice(1);
375
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * TypeScript Type Generator
3
+ *
4
+ * Generates TypeScript type definitions from contract ABIs
5
+ */
6
+ export interface GenerateTypesOptions {
7
+ abiDir: string;
8
+ outputPath: string;
9
+ }
10
+ export interface GenerateTypesResult {
11
+ types: string[];
12
+ success: boolean;
13
+ errors: string[];
14
+ }
15
+ /**
16
+ * Generate TypeScript types from contract ABIs
17
+ */
18
+ export declare function generateTypes(options: GenerateTypesOptions): Promise<GenerateTypesResult>;
19
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/types/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,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,CAgE9B"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * TypeScript Type Generator
3
+ *
4
+ * Generates TypeScript type definitions from contract ABIs
5
+ */
6
+ import * as fs from 'fs';
7
+ import * as path from 'path';
8
+ /**
9
+ * Generate TypeScript types from contract ABIs
10
+ */
11
+ export async function generateTypes(options) {
12
+ const result = {
13
+ types: [],
14
+ success: false,
15
+ errors: []
16
+ };
17
+ try {
18
+ // Check if ABI directory exists
19
+ if (!fs.existsSync(options.abiDir)) {
20
+ throw new Error(`ABI directory not found: ${options.abiDir}`);
21
+ }
22
+ // Create output directory
23
+ const outputPath = path.resolve(options.outputPath);
24
+ if (!fs.existsSync(outputPath)) {
25
+ fs.mkdirSync(outputPath, { recursive: true });
26
+ }
27
+ // Find all ABI files
28
+ const abiFiles = findABIFiles(options.abiDir);
29
+ if (abiFiles.length === 0) {
30
+ result.errors.push('No ABI files found in directory');
31
+ return result;
32
+ }
33
+ // Generate types for each ABI
34
+ for (const abiFile of abiFiles) {
35
+ try {
36
+ const abiContent = fs.readFileSync(abiFile, 'utf-8');
37
+ const abi = JSON.parse(abiContent);
38
+ const contractName = path.basename(abiFile, '.json');
39
+ const typeDefinition = generateTypeDefinitionFromABI(contractName, abi);
40
+ const typeFile = path.join(outputPath, `${contractName}.ts`);
41
+ fs.writeFileSync(typeFile, typeDefinition);
42
+ result.types.push(typeFile);
43
+ }
44
+ catch (error) {
45
+ result.errors.push(`Failed to generate types for ${abiFile}: ${error instanceof Error ? error.message : 'Unknown error'}`);
46
+ }
47
+ }
48
+ // Generate index file
49
+ const indexContent = generateIndexFile(result.types, outputPath);
50
+ const indexFile = path.join(outputPath, 'index.ts');
51
+ fs.writeFileSync(indexFile, indexContent);
52
+ result.types.push(indexFile);
53
+ result.success = result.errors.length === 0;
54
+ }
55
+ catch (error) {
56
+ result.errors.push(`Failed to generate types: ${error instanceof Error ? error.message : 'Unknown error'}`);
57
+ }
58
+ return result;
59
+ }
60
+ /**
61
+ * Find all ABI JSON files in directory
62
+ */
63
+ function findABIFiles(dir) {
64
+ const files = [];
65
+ function scanDirectory(currentDir) {
66
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
67
+ for (const entry of entries) {
68
+ const fullPath = path.join(currentDir, entry.name);
69
+ if (entry.isDirectory()) {
70
+ scanDirectory(fullPath);
71
+ }
72
+ else if (entry.isFile() && entry.name.endsWith('.json')) {
73
+ files.push(fullPath);
74
+ }
75
+ }
76
+ }
77
+ scanDirectory(dir);
78
+ return files;
79
+ }
80
+ /**
81
+ * Generate TypeScript type definition from ABI
82
+ */
83
+ function generateTypeDefinitionFromABI(contractName, abi) {
84
+ // Extract function signatures
85
+ const functions = abi.filter(item => item.type === 'function');
86
+ const events = abi.filter(item => item.type === 'event');
87
+ // Generate function interface
88
+ const functionSignatures = functions.map(fn => {
89
+ const inputs = fn.inputs.map((input) => `${input.name}: ${mapABITypeToTypeScript(input.type)}`).join(', ');
90
+ const outputs = fn.outputs && fn.outputs.length > 0
91
+ ? mapABITypeToTypeScript(fn.outputs[0].type)
92
+ : 'void';
93
+ return ` ${fn.name}(${inputs}): Promise<${outputs}>`;
94
+ }).join('\n');
95
+ // Generate event interface
96
+ const eventSignatures = events.map(event => {
97
+ const inputs = event.inputs.map((input) => `${input.name}: ${mapABITypeToTypeScript(input.type)}`).join(', ');
98
+ return ` ${event.name}: { ${inputs} }`;
99
+ }).join('\n');
100
+ return `/**
101
+ * TypeScript definitions for ${contractName}
102
+ * Generated from contract ABI
103
+ */
104
+
105
+ import { ethers } from 'ethers'
106
+
107
+ export interface ${contractName}Functions {
108
+ ${functionSignatures}
109
+ }
110
+
111
+ export interface ${contractName}Events {
112
+ ${eventSignatures}
113
+ }
114
+
115
+ export type ${contractName} = ethers.Contract & ${contractName}Functions
116
+
117
+ export const ${contractName}ABI = ${JSON.stringify(abi, null, 2)}
118
+ `;
119
+ }
120
+ /**
121
+ * Map Solidity ABI types to TypeScript types
122
+ */
123
+ function mapABITypeToTypeScript(abiType) {
124
+ if (abiType.startsWith('uint') || abiType.startsWith('int')) {
125
+ return 'bigint';
126
+ }
127
+ if (abiType === 'address') {
128
+ return 'string';
129
+ }
130
+ if (abiType === 'bool') {
131
+ return 'boolean';
132
+ }
133
+ if (abiType === 'string') {
134
+ return 'string';
135
+ }
136
+ if (abiType.startsWith('bytes')) {
137
+ return 'string';
138
+ }
139
+ if (abiType.endsWith('[]')) {
140
+ const baseType = abiType.slice(0, -2);
141
+ return `${mapABITypeToTypeScript(baseType)}[]`;
142
+ }
143
+ return 'any';
144
+ }
145
+ /**
146
+ * Generate index.ts file that exports all types
147
+ */
148
+ function generateIndexFile(typeFiles, outputPath) {
149
+ const exports = typeFiles
150
+ .filter(file => !file.endsWith('index.ts'))
151
+ .map(file => {
152
+ const basename = path.basename(file, '.ts');
153
+ return `export * from './${basename}'`;
154
+ })
155
+ .join('\n');
156
+ return `/**
157
+ * Auto-generated type definitions
158
+ *
159
+ * Import contract types:
160
+ * import { MyContract } from './types'
161
+ */
162
+
163
+ ${exports}
164
+ `;
165
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * UI Component Generator
3
+ *
4
+ * Generates CRUD React components from template entity definitions
5
+ */
6
+ export interface GenerateUIOptions {
7
+ templatePath: string;
8
+ outputPath: string;
9
+ componentsPath?: string;
10
+ }
11
+ export interface GenerateUIResult {
12
+ components: string[];
13
+ success: boolean;
14
+ errors: string[];
15
+ }
16
+ /**
17
+ * Generate UI components from template configuration
18
+ */
19
+ export declare function generateUIComponents(options: GenerateUIOptions): Promise<GenerateUIResult>;
20
+ //# sourceMappingURL=component-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-generator.d.ts","sourceRoot":"","sources":["../../../src/generators/ui/component-generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,gBAAgB,CAAC,CA4E3B"}