@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,386 @@
1
+ /**
2
+ * thirdweb Engine Client
3
+ *
4
+ * Production-grade transaction management infrastructure
5
+ * Replaces custom transaction queues with thirdweb's managed service
6
+ *
7
+ * Features:
8
+ * - Automatic transaction queueing and execution
9
+ * - Gas price optimization
10
+ * - Automatic retry with exponential backoff
11
+ * - Webhook notifications for transaction events
12
+ * - Multi-chain support
13
+ * - Production-ready scalability
14
+ */
15
+ /**
16
+ * thirdweb Engine Client
17
+ *
18
+ * Manages blockchain transactions through thirdweb's production infrastructure
19
+ */
20
+ export class EngineClient {
21
+ constructor(config) {
22
+ this.url = config.url.replace(/\/$/, ''); // Remove trailing slash
23
+ this.accessToken = config.accessToken;
24
+ this.backendWalletAddress = config.backendWalletAddress;
25
+ }
26
+ /**
27
+ * Send a transaction through Engine
28
+ *
29
+ * Automatically queues, optimizes gas, and retries failed transactions.
30
+ *
31
+ * @param params - Transaction parameters
32
+ * @returns Transaction result with queue ID
33
+ *
34
+ * @example Basic transaction
35
+ * ```typescript
36
+ * import { EngineClient, varityL3Testnet } from '@varity-labs/sdk';
37
+ * import { prepareContractCall } from 'thirdweb';
38
+ *
39
+ * const engine = new EngineClient({
40
+ * url: 'https://engine.varity.so',
41
+ * accessToken: process.env.ENGINE_ACCESS_TOKEN,
42
+ * backendWalletAddress: '0x...'
43
+ * });
44
+ *
45
+ * // Prepare transaction
46
+ * const tx = prepareContractCall({
47
+ * contract,
48
+ * method: 'function transfer(address to, uint256 amount)',
49
+ * params: [recipientAddress, amount]
50
+ * });
51
+ *
52
+ * // Send through Engine
53
+ * const result = await engine.sendTransaction({
54
+ * chain: varityL3Testnet,
55
+ * to: contract.address,
56
+ * data: tx.data,
57
+ * value: '0'
58
+ * });
59
+ *
60
+ * console.log('Queue ID:', result.queueId);
61
+ * ```
62
+ *
63
+ * @example With webhook notifications
64
+ * ```typescript
65
+ * const result = await engine.sendTransaction({
66
+ * chain: varityL3Testnet,
67
+ * to: contractAddress,
68
+ * data: encodedData,
69
+ * webhookUrl: 'https://myapp.com/api/webhook/engine'
70
+ * });
71
+ *
72
+ * // Your webhook will receive status updates:
73
+ * // { queueId, status: 'mined', transactionHash, blockNumber }
74
+ * ```
75
+ *
76
+ * @example With gas limit
77
+ * ```typescript
78
+ * const result = await engine.sendTransaction({
79
+ * chain: varityL3Testnet,
80
+ * to: contractAddress,
81
+ * data: encodedData,
82
+ * gasLimit: '500000' // Override estimated gas
83
+ * });
84
+ * ```
85
+ */
86
+ async sendTransaction(params) {
87
+ const response = await this.request('/transaction/write', {
88
+ method: 'POST',
89
+ body: JSON.stringify({
90
+ chainId: params.chain.id,
91
+ toAddress: params.to,
92
+ data: params.data,
93
+ value: params.value || '0',
94
+ gasLimit: params.gasLimit,
95
+ backendWalletAddress: this.backendWalletAddress,
96
+ webhookUrl: params.webhookUrl,
97
+ }),
98
+ });
99
+ return {
100
+ queueId: response.result.queueId,
101
+ status: 'queued',
102
+ timestamp: new Date(),
103
+ };
104
+ }
105
+ /**
106
+ * Deploy a contract through Engine
107
+ *
108
+ * Deploys smart contracts with automatic gas optimization and retry logic.
109
+ *
110
+ * @param params - Deployment parameters
111
+ * @returns Deployment result with queue ID
112
+ *
113
+ * @example Deploy ERC-721 NFT contract
114
+ * ```typescript
115
+ * import { EngineClient, varityL3Testnet } from '@varity-labs/sdk';
116
+ * import NFTContractABI from './abis/NFTContract.json';
117
+ * import NFTContractBytecode from './bytecode/NFTContract.json';
118
+ *
119
+ * const engine = new EngineClient({
120
+ * url: 'https://engine.varity.so',
121
+ * accessToken: process.env.ENGINE_ACCESS_TOKEN
122
+ * });
123
+ *
124
+ * const result = await engine.deployContract({
125
+ * chain: varityL3Testnet,
126
+ * abi: NFTContractABI,
127
+ * bytecode: NFTContractBytecode.bytecode,
128
+ * constructorArgs: [
129
+ * 'My NFT Collection', // name
130
+ * 'MNFT', // symbol
131
+ * '0x...' // owner address
132
+ * ]
133
+ * });
134
+ *
135
+ * console.log('Deploying contract, Queue ID:', result.queueId);
136
+ * ```
137
+ *
138
+ * @example Deploy ERC-20 token
139
+ * ```typescript
140
+ * const result = await engine.deployContract({
141
+ * chain: varityL3Testnet,
142
+ * abi: ERC20ABI,
143
+ * bytecode: ERC20Bytecode.bytecode,
144
+ * constructorArgs: [
145
+ * 'My Token', // name
146
+ * 'MTK', // symbol
147
+ * ethers.utils.parseEther('1000000') // initial supply
148
+ * ],
149
+ * webhookUrl: 'https://myapp.com/api/webhook/deployment'
150
+ * });
151
+ * ```
152
+ *
153
+ * @example Deploy and wait for completion
154
+ * ```typescript
155
+ * const deployment = await engine.deployContract({
156
+ * chain: varityL3Testnet,
157
+ * abi: ContractABI,
158
+ * bytecode: ContractBytecode.bytecode,
159
+ * constructorArgs: []
160
+ * });
161
+ *
162
+ * // Wait for deployment to complete
163
+ * const completed = await engine.waitForTransaction(deployment.queueId);
164
+ * console.log('Contract deployed at:', completed.transactionHash);
165
+ * ```
166
+ */
167
+ async deployContract(params) {
168
+ const response = await this.request('/contract/deploy', {
169
+ method: 'POST',
170
+ body: JSON.stringify({
171
+ chainId: params.chain.id,
172
+ abi: params.abi,
173
+ bytecode: params.bytecode,
174
+ constructorArgs: params.constructorArgs || [],
175
+ backendWalletAddress: this.backendWalletAddress,
176
+ webhookUrl: params.webhookUrl,
177
+ }),
178
+ });
179
+ return {
180
+ queueId: response.result.queueId,
181
+ status: 'queued',
182
+ timestamp: new Date(),
183
+ };
184
+ }
185
+ /**
186
+ * Get transaction status
187
+ */
188
+ async getTransactionStatus(queueId) {
189
+ const response = await this.request(`/transaction/status/${queueId}`);
190
+ return {
191
+ queueId,
192
+ transactionHash: response.result.transactionHash,
193
+ status: response.result.status,
194
+ blockNumber: response.result.blockNumber,
195
+ errorMessage: response.result.errorMessage,
196
+ timestamp: new Date(response.result.timestamp),
197
+ };
198
+ }
199
+ /**
200
+ * Wait for transaction to be mined
201
+ *
202
+ * Polls Engine API until transaction is confirmed or fails.
203
+ *
204
+ * @param queueId - Engine queue ID from sendTransaction or deployContract
205
+ * @param options - Optional polling configuration
206
+ * @returns Completed transaction result
207
+ *
208
+ * @example Basic usage
209
+ * ```typescript
210
+ * import { EngineClient } from '@varity-labs/sdk';
211
+ *
212
+ * const engine = new EngineClient({ url, accessToken });
213
+ *
214
+ * // Send transaction
215
+ * const tx = await engine.sendTransaction({ ... });
216
+ *
217
+ * // Wait for confirmation (default: poll every 2s, timeout 5min)
218
+ * const result = await engine.waitForTransaction(tx.queueId);
219
+ * console.log('Transaction mined:', result.transactionHash);
220
+ * console.log('Block number:', result.blockNumber);
221
+ * ```
222
+ *
223
+ * @example With custom polling interval
224
+ * ```typescript
225
+ * // Poll every 5 seconds instead of default 2 seconds
226
+ * const result = await engine.waitForTransaction(queueId, {
227
+ * pollInterval: 5000, // 5 seconds
228
+ * timeout: 600000 // 10 minutes
229
+ * });
230
+ * ```
231
+ *
232
+ * @example With error handling
233
+ * ```typescript
234
+ * try {
235
+ * const result = await engine.waitForTransaction(queueId);
236
+ * console.log('Success:', result.transactionHash);
237
+ * } catch (error) {
238
+ * if (error.message.includes('timed out')) {
239
+ * console.error('Transaction took too long');
240
+ * } else if (error.message.includes('errored')) {
241
+ * console.error('Transaction failed:', error.message);
242
+ * }
243
+ * }
244
+ * ```
245
+ */
246
+ async waitForTransaction(queueId, options) {
247
+ const pollInterval = options?.pollInterval || 2000;
248
+ const timeout = options?.timeout || 300000;
249
+ const startTime = Date.now();
250
+ while (Date.now() - startTime < timeout) {
251
+ const status = await this.getTransactionStatus(queueId);
252
+ if (status.status === 'mined') {
253
+ return status;
254
+ }
255
+ if (status.status === 'errored' || status.status === 'cancelled') {
256
+ throw new Error(`Transaction ${queueId} ${status.status}: ${status.errorMessage || 'Unknown error'}`);
257
+ }
258
+ // Wait before polling again
259
+ await new Promise(resolve => setTimeout(resolve, pollInterval));
260
+ }
261
+ throw new Error(`Transaction ${queueId} timed out after ${timeout}ms`);
262
+ }
263
+ /**
264
+ * Cancel a queued transaction
265
+ */
266
+ async cancelTransaction(queueId) {
267
+ await this.request(`/transaction/cancel/${queueId}`, {
268
+ method: 'POST',
269
+ });
270
+ }
271
+ /**
272
+ * Get backend wallet balance
273
+ */
274
+ async getWalletBalance(chainId, walletAddress) {
275
+ const address = walletAddress || this.backendWalletAddress;
276
+ if (!address) {
277
+ throw new Error('Wallet address required');
278
+ }
279
+ const response = await this.request(`/backend-wallet/${chainId}/get-balance?walletAddress=${address}`);
280
+ return response.result.balance;
281
+ }
282
+ /**
283
+ * Get all backend wallets
284
+ */
285
+ async getBackendWallets() {
286
+ const response = await this.request('/backend-wallet/get-all');
287
+ return response.result.wallets;
288
+ }
289
+ /**
290
+ * Get transaction nonce for a wallet
291
+ */
292
+ async getNonce(chainId, walletAddress) {
293
+ const address = walletAddress || this.backendWalletAddress;
294
+ if (!address) {
295
+ throw new Error('Wallet address required');
296
+ }
297
+ const response = await this.request(`/backend-wallet/${chainId}/get-nonce?walletAddress=${address}`);
298
+ return response.result.nonce;
299
+ }
300
+ /**
301
+ * Make HTTP request to Engine API
302
+ */
303
+ async request(endpoint, options) {
304
+ const url = `${this.url}${endpoint}`;
305
+ const response = await fetch(url, {
306
+ ...options,
307
+ headers: {
308
+ 'Content-Type': 'application/json',
309
+ Authorization: `Bearer ${this.accessToken}`,
310
+ ...options?.headers,
311
+ },
312
+ });
313
+ if (!response.ok) {
314
+ const error = await response.json().catch(() => ({ error: response.statusText }));
315
+ throw new Error(`Engine request failed: ${error.error || error.message || 'Unknown error'}`);
316
+ }
317
+ return response.json();
318
+ }
319
+ }
320
+ /**
321
+ * Create Engine client instance
322
+ *
323
+ * Factory function for creating EngineClient instances.
324
+ *
325
+ * @param config - Engine configuration
326
+ * @returns Configured Engine client
327
+ *
328
+ * @example Basic setup
329
+ * ```typescript
330
+ * import { createEngineClient } from '@varity-labs/sdk';
331
+ *
332
+ * const engine = createEngineClient({
333
+ * url: 'https://engine.varity.so',
334
+ * accessToken: process.env.ENGINE_ACCESS_TOKEN
335
+ * });
336
+ *
337
+ * // Now use engine client
338
+ * const result = await engine.sendTransaction({ ... });
339
+ * ```
340
+ *
341
+ * @example With backend wallet
342
+ * ```typescript
343
+ * const engine = createEngineClient({
344
+ * url: 'https://engine.varity.so',
345
+ * accessToken: process.env.ENGINE_ACCESS_TOKEN,
346
+ * backendWalletAddress: '0x...' // Default wallet for all transactions
347
+ * });
348
+ * ```
349
+ *
350
+ * @example Self-hosted Engine
351
+ * ```typescript
352
+ * const engine = createEngineClient({
353
+ * url: 'https://my-engine.example.com',
354
+ * accessToken: process.env.MY_ENGINE_TOKEN
355
+ * });
356
+ * ```
357
+ */
358
+ export function createEngineClient(config) {
359
+ return new EngineClient(config);
360
+ }
361
+ /**
362
+ * Webhook handler helper
363
+ *
364
+ * Use this to handle Engine webhook notifications in your backend
365
+ */
366
+ export function parseEngineWebhook(payload) {
367
+ return {
368
+ queueId: payload.queueId,
369
+ status: payload.status,
370
+ transactionHash: payload.transactionHash,
371
+ blockNumber: payload.blockNumber,
372
+ errorMessage: payload.errorMessage,
373
+ timestamp: payload.timestamp,
374
+ };
375
+ }
376
+ /**
377
+ * Verify Engine webhook signature (if configured)
378
+ */
379
+ export function verifyEngineWebhook(payload, signature, secret) {
380
+ // Implement HMAC verification
381
+ // This is a placeholder - actual implementation would use crypto.subtle or similar
382
+ // to verify HMAC-SHA256 signature
383
+ // For now, return true (webhook verification can be implemented based on Engine's spec)
384
+ console.warn('Engine webhook verification not implemented - please implement HMAC verification');
385
+ return true;
386
+ }
@@ -0,0 +1,190 @@
1
+ /**
2
+ * thirdweb Gateway Client
3
+ *
4
+ * Production-grade RPC infrastructure powered by thirdweb
5
+ * Provides reliable, fast, and scalable blockchain node access
6
+ *
7
+ * Features:
8
+ * - High-performance RPC endpoints
9
+ * - Automatic failover and load balancing
10
+ * - Request rate limiting and throttling
11
+ * - Chain-specific optimizations
12
+ * - Analytics and monitoring
13
+ * - WebSocket support for real-time data
14
+ */
15
+ import type { Chain } from 'thirdweb';
16
+ /**
17
+ * Gateway configuration
18
+ */
19
+ export interface GatewayConfig {
20
+ /**
21
+ * API key for authenticated requests (optional)
22
+ */
23
+ apiKey?: string;
24
+ /**
25
+ * Custom gateway URL (optional)
26
+ */
27
+ gatewayUrl?: string;
28
+ /**
29
+ * Request timeout in milliseconds
30
+ */
31
+ timeout?: number;
32
+ /**
33
+ * Enable request retries
34
+ */
35
+ enableRetries?: boolean;
36
+ /**
37
+ * Maximum number of retries
38
+ */
39
+ maxRetries?: number;
40
+ }
41
+ /**
42
+ * RPC request options
43
+ */
44
+ export interface RPCRequestOptions {
45
+ /**
46
+ * RPC method
47
+ */
48
+ method: string;
49
+ /**
50
+ * Method parameters
51
+ */
52
+ params?: any[];
53
+ /**
54
+ * Request timeout (overrides global setting)
55
+ */
56
+ timeout?: number;
57
+ }
58
+ /**
59
+ * RPC response
60
+ */
61
+ export interface RPCResponse<T = any> {
62
+ /**
63
+ * Result data
64
+ */
65
+ result: T;
66
+ /**
67
+ * Request ID
68
+ */
69
+ id: number;
70
+ /**
71
+ * JSON-RPC version
72
+ */
73
+ jsonrpc: string;
74
+ }
75
+ /**
76
+ * Gateway statistics
77
+ */
78
+ export interface GatewayStats {
79
+ /**
80
+ * Total requests made
81
+ */
82
+ totalRequests: number;
83
+ /**
84
+ * Successful requests
85
+ */
86
+ successfulRequests: number;
87
+ /**
88
+ * Failed requests
89
+ */
90
+ failedRequests: number;
91
+ /**
92
+ * Average response time (ms)
93
+ */
94
+ averageResponseTime: number;
95
+ /**
96
+ * Requests per minute
97
+ */
98
+ requestsPerMinute: number;
99
+ /**
100
+ * Error rate (percentage)
101
+ */
102
+ errorRate: number;
103
+ }
104
+ /**
105
+ * WebSocket connection options
106
+ */
107
+ export interface WebSocketOptions {
108
+ /**
109
+ * Chain to connect to
110
+ */
111
+ chain: Chain;
112
+ /**
113
+ * Event handlers
114
+ */
115
+ onMessage?: (data: any) => void;
116
+ onError?: (error: Error) => void;
117
+ onConnect?: () => void;
118
+ onDisconnect?: () => void;
119
+ /**
120
+ * Auto-reconnect on disconnect
121
+ */
122
+ autoReconnect?: boolean;
123
+ }
124
+ /**
125
+ * thirdweb Gateway Client
126
+ *
127
+ * Production RPC infrastructure for blockchain applications
128
+ */
129
+ export declare class GatewayClient {
130
+ private apiKey?;
131
+ private gatewayUrl;
132
+ private timeout;
133
+ private enableRetries;
134
+ private maxRetries;
135
+ private stats;
136
+ private requestId;
137
+ constructor(config?: GatewayConfig);
138
+ /**
139
+ * Get RPC URL for a specific chain
140
+ */
141
+ getRpcUrl(chain: Chain | number): string;
142
+ /**
143
+ * Get WebSocket URL for a specific chain
144
+ */
145
+ getWebSocketUrl(chain: Chain | number): string;
146
+ /**
147
+ * Make an RPC request
148
+ */
149
+ request<T = any>(chain: Chain | number, options: RPCRequestOptions): Promise<RPCResponse<T>>;
150
+ /**
151
+ * Batch multiple RPC requests
152
+ */
153
+ batchRequest<T = any>(chain: Chain | number, requests: RPCRequestOptions[]): Promise<RPCResponse<T>[]>;
154
+ /**
155
+ * Create a WebSocket connection
156
+ */
157
+ connectWebSocket(options: WebSocketOptions): WebSocket;
158
+ /**
159
+ * Subscribe to new blocks
160
+ */
161
+ subscribeToBlocks(chain: Chain | number, callback: (block: any) => void): Promise<() => void>;
162
+ /**
163
+ * Subscribe to contract events
164
+ */
165
+ subscribeToLogs(chain: Chain | number, filter: {
166
+ address?: string;
167
+ topics?: string[];
168
+ }, callback: (log: any) => void): Promise<() => void>;
169
+ /**
170
+ * Get gateway statistics
171
+ */
172
+ getStats(): GatewayStats;
173
+ /**
174
+ * Reset statistics
175
+ */
176
+ resetStats(): void;
177
+ /**
178
+ * Make HTTP request with retry logic
179
+ */
180
+ private makeRequest;
181
+ /**
182
+ * Update statistics
183
+ */
184
+ private updateStats;
185
+ }
186
+ /**
187
+ * Create Gateway client instance
188
+ */
189
+ export declare function createGatewayClient(config?: GatewayConfig): GatewayClient;
190
+ //# sourceMappingURL=GatewayClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GatewayClient.d.ts","sourceRoot":"","sources":["../../src/thirdweb/GatewayClient.ts"],"names":[],"mappings":"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"}