@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,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Contracts Module
|
|
3
|
+
*
|
|
4
|
+
* Universal L3 smart contract interaction layer.
|
|
5
|
+
* Works across all templates (ISO, Healthcare, Retail, etc.)
|
|
6
|
+
*/
|
|
7
|
+
import { ethers } from 'ethers';
|
|
8
|
+
import type { VaritySDK } from '../../core/VaritySDK';
|
|
9
|
+
import type { TransactionReceipt } from '../../core/types';
|
|
10
|
+
export interface TxOptions {
|
|
11
|
+
gasLimit?: bigint;
|
|
12
|
+
maxFeePerGas?: bigint;
|
|
13
|
+
maxPriorityFeePerGas?: bigint;
|
|
14
|
+
value?: bigint;
|
|
15
|
+
nonce?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ContractCall {
|
|
18
|
+
contractName: string;
|
|
19
|
+
method: string;
|
|
20
|
+
args: any[];
|
|
21
|
+
}
|
|
22
|
+
export interface MultiCall {
|
|
23
|
+
method: string;
|
|
24
|
+
args: any[];
|
|
25
|
+
}
|
|
26
|
+
export interface ContractConfig {
|
|
27
|
+
constructorArgs: any[];
|
|
28
|
+
options?: TxOptions;
|
|
29
|
+
}
|
|
30
|
+
export interface EventCallback {
|
|
31
|
+
(...args: any[]): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ContractsModule - Universal smart contract interaction
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Read from contract
|
|
39
|
+
* const merchant = await sdk.contracts.call(
|
|
40
|
+
* 'MerchantRegistry',
|
|
41
|
+
* 'getMerchant',
|
|
42
|
+
* [merchantId]
|
|
43
|
+
* )
|
|
44
|
+
*
|
|
45
|
+
* // Write to contract
|
|
46
|
+
* const receipt = await sdk.contracts.send(
|
|
47
|
+
* 'MerchantRegistry',
|
|
48
|
+
* 'registerMerchant',
|
|
49
|
+
* [businessName, owner, repId]
|
|
50
|
+
* )
|
|
51
|
+
*
|
|
52
|
+
* // Listen to events
|
|
53
|
+
* await sdk.contracts.listen('MerchantRegistry', 'MerchantRegistered', (event) => {
|
|
54
|
+
* console.log('New merchant:', event.merchantId)
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare class ContractsModule {
|
|
59
|
+
private sdk;
|
|
60
|
+
private contracts;
|
|
61
|
+
private eventListeners;
|
|
62
|
+
private static readonly ABI_REGISTRY;
|
|
63
|
+
constructor(sdk: VaritySDK);
|
|
64
|
+
/**
|
|
65
|
+
* Get or create contract instance
|
|
66
|
+
*/
|
|
67
|
+
private getContractInstance;
|
|
68
|
+
/**
|
|
69
|
+
* Call contract method (read-only)
|
|
70
|
+
*
|
|
71
|
+
* @param contractName - Contract name
|
|
72
|
+
* @param method - Method name
|
|
73
|
+
* @param args - Method arguments
|
|
74
|
+
* @returns Method return value
|
|
75
|
+
*/
|
|
76
|
+
call(contractName: string, method: string, args?: any[]): Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* Send contract transaction (write)
|
|
79
|
+
*
|
|
80
|
+
* @param contractName - Contract name
|
|
81
|
+
* @param method - Method name
|
|
82
|
+
* @param args - Method arguments
|
|
83
|
+
* @param options - Transaction options
|
|
84
|
+
* @returns Transaction receipt
|
|
85
|
+
*/
|
|
86
|
+
send(contractName: string, method: string, args?: any[], options?: TxOptions): Promise<TransactionReceipt>;
|
|
87
|
+
/**
|
|
88
|
+
* Estimate gas for transaction
|
|
89
|
+
*
|
|
90
|
+
* @param contractName - Contract name
|
|
91
|
+
* @param method - Method name
|
|
92
|
+
* @param args - Method arguments
|
|
93
|
+
* @returns Estimated gas
|
|
94
|
+
*/
|
|
95
|
+
estimateGas(contractName: string, method: string, args?: any[]): Promise<bigint>;
|
|
96
|
+
/**
|
|
97
|
+
* Deploy new sovereign contract instance
|
|
98
|
+
*
|
|
99
|
+
* @param template - Template type (e.g., 'iso', 'healthcare')
|
|
100
|
+
* @param config - Deployment configuration
|
|
101
|
+
* @returns Deployed contract address
|
|
102
|
+
*/
|
|
103
|
+
deploySovereignContract(template: string, config: ContractConfig): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Get contract address by name
|
|
106
|
+
*
|
|
107
|
+
* @param contractName - Contract name
|
|
108
|
+
* @returns Contract address
|
|
109
|
+
*/
|
|
110
|
+
getContractAddress(contractName: string): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Get contract instance
|
|
113
|
+
*
|
|
114
|
+
* @param contractName - Contract name
|
|
115
|
+
* @returns Contract instance
|
|
116
|
+
*/
|
|
117
|
+
getContract(contractName: string): Promise<ethers.Contract>;
|
|
118
|
+
/**
|
|
119
|
+
* Listen to contract events
|
|
120
|
+
*
|
|
121
|
+
* @param contractName - Contract name
|
|
122
|
+
* @param eventName - Event name
|
|
123
|
+
* @param callback - Event callback
|
|
124
|
+
*/
|
|
125
|
+
listen(contractName: string, eventName: string, callback: EventCallback): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Stop listening to contract events
|
|
128
|
+
*
|
|
129
|
+
* @param contractName - Contract name
|
|
130
|
+
* @param eventName - Event name
|
|
131
|
+
*/
|
|
132
|
+
stopListening(contractName: string, eventName: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Batch call multiple read-only methods
|
|
135
|
+
*
|
|
136
|
+
* @param calls - Array of contract calls
|
|
137
|
+
* @returns Array of results
|
|
138
|
+
*/
|
|
139
|
+
batchCall(calls: ContractCall[]): Promise<any[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Multicall on single contract
|
|
142
|
+
*
|
|
143
|
+
* @param contractName - Contract name
|
|
144
|
+
* @param calls - Array of method calls
|
|
145
|
+
* @returns Array of results
|
|
146
|
+
*/
|
|
147
|
+
multicall(contractName: string, calls: MultiCall[]): Promise<any[]>;
|
|
148
|
+
/**
|
|
149
|
+
* Register custom contract ABI
|
|
150
|
+
*
|
|
151
|
+
* @param contractName - Contract name
|
|
152
|
+
* @param abi - Contract ABI
|
|
153
|
+
*/
|
|
154
|
+
registerABI(contractName: string, abi: any): void;
|
|
155
|
+
/**
|
|
156
|
+
* Clear cached contract instances
|
|
157
|
+
*/
|
|
158
|
+
clearCache(): void;
|
|
159
|
+
/**
|
|
160
|
+
* Remove all event listeners
|
|
161
|
+
*/
|
|
162
|
+
removeAllListeners(): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=ContractsModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractsModule.d.ts","sourceRoot":"","sources":["../../../src/modules/contracts/ContractsModule.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,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|
+
* Varity SDK - Contracts Module
|
|
3
|
+
*
|
|
4
|
+
* Universal L3 smart contract interaction layer.
|
|
5
|
+
* Works across all templates (ISO, Healthcare, Retail, etc.)
|
|
6
|
+
*/
|
|
7
|
+
import { ethers } from 'ethers';
|
|
8
|
+
// Import all contract ABIs
|
|
9
|
+
import MerchantRegistryABI from '../../contracts/abis/iso/MerchantRegistry.json';
|
|
10
|
+
import TransactionVaultABI from '../../contracts/abis/iso/TransactionVault.json';
|
|
11
|
+
import RepPerformanceABI from '../../contracts/abis/iso/RepPerformance.json';
|
|
12
|
+
import ResidualCalculatorABI from '../../contracts/abis/iso/ResidualCalculator.json';
|
|
13
|
+
import AccessControlRegistryABI from '../../contracts/abis/iso/AccessControlRegistry.json';
|
|
14
|
+
import DataProofRegistryABI from '../../contracts/abis/iso/DataProofRegistry.json';
|
|
15
|
+
import VarityWalletFactoryABI from '../../contracts/abis/iso/VarityWalletFactory.json';
|
|
16
|
+
/**
|
|
17
|
+
* ContractsModule - Universal smart contract interaction
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Read from contract
|
|
22
|
+
* const merchant = await sdk.contracts.call(
|
|
23
|
+
* 'MerchantRegistry',
|
|
24
|
+
* 'getMerchant',
|
|
25
|
+
* [merchantId]
|
|
26
|
+
* )
|
|
27
|
+
*
|
|
28
|
+
* // Write to contract
|
|
29
|
+
* const receipt = await sdk.contracts.send(
|
|
30
|
+
* 'MerchantRegistry',
|
|
31
|
+
* 'registerMerchant',
|
|
32
|
+
* [businessName, owner, repId]
|
|
33
|
+
* )
|
|
34
|
+
*
|
|
35
|
+
* // Listen to events
|
|
36
|
+
* await sdk.contracts.listen('MerchantRegistry', 'MerchantRegistered', (event) => {
|
|
37
|
+
* console.log('New merchant:', event.merchantId)
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class ContractsModule {
|
|
42
|
+
constructor(sdk) {
|
|
43
|
+
this.contracts = new Map();
|
|
44
|
+
this.eventListeners = new Map();
|
|
45
|
+
this.sdk = sdk;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get or create contract instance
|
|
49
|
+
*/
|
|
50
|
+
getContractInstance(contractName, withSigner = false) {
|
|
51
|
+
const cacheKey = `${contractName}:${withSigner}`;
|
|
52
|
+
if (this.contracts.has(cacheKey)) {
|
|
53
|
+
return this.contracts.get(cacheKey);
|
|
54
|
+
}
|
|
55
|
+
const abi = ContractsModule.ABI_REGISTRY[contractName];
|
|
56
|
+
if (!abi) {
|
|
57
|
+
throw new Error(`Contract ABI not found for "${contractName}". ` +
|
|
58
|
+
`Available contracts: ${Object.keys(ContractsModule.ABI_REGISTRY).join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
const address = this.sdk.getContractAddress(contractName);
|
|
61
|
+
const provider = this.sdk.getProvider();
|
|
62
|
+
const contract = new ethers.Contract(address, abi, withSigner ? this.sdk.getSigner() : provider);
|
|
63
|
+
this.contracts.set(cacheKey, contract);
|
|
64
|
+
return contract;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Call contract method (read-only)
|
|
68
|
+
*
|
|
69
|
+
* @param contractName - Contract name
|
|
70
|
+
* @param method - Method name
|
|
71
|
+
* @param args - Method arguments
|
|
72
|
+
* @returns Method return value
|
|
73
|
+
*/
|
|
74
|
+
async call(contractName, method, args = []) {
|
|
75
|
+
const contract = this.getContractInstance(contractName, false);
|
|
76
|
+
if (!contract[method]) {
|
|
77
|
+
throw new Error(`Method "${method}" not found on contract "${contractName}"`);
|
|
78
|
+
}
|
|
79
|
+
return await contract[method](...args);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Send contract transaction (write)
|
|
83
|
+
*
|
|
84
|
+
* @param contractName - Contract name
|
|
85
|
+
* @param method - Method name
|
|
86
|
+
* @param args - Method arguments
|
|
87
|
+
* @param options - Transaction options
|
|
88
|
+
* @returns Transaction receipt
|
|
89
|
+
*/
|
|
90
|
+
async send(contractName, method, args = [], options) {
|
|
91
|
+
const contract = this.getContractInstance(contractName, true);
|
|
92
|
+
if (!contract[method]) {
|
|
93
|
+
throw new Error(`Method "${method}" not found on contract "${contractName}"`);
|
|
94
|
+
}
|
|
95
|
+
const tx = await contract[method](...args, options || {});
|
|
96
|
+
const receipt = await tx.wait();
|
|
97
|
+
return {
|
|
98
|
+
hash: receipt.hash,
|
|
99
|
+
blockNumber: receipt.blockNumber,
|
|
100
|
+
gasUsed: receipt.gasUsed,
|
|
101
|
+
status: receipt.status,
|
|
102
|
+
logs: receipt.logs
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Estimate gas for transaction
|
|
107
|
+
*
|
|
108
|
+
* @param contractName - Contract name
|
|
109
|
+
* @param method - Method name
|
|
110
|
+
* @param args - Method arguments
|
|
111
|
+
* @returns Estimated gas
|
|
112
|
+
*/
|
|
113
|
+
async estimateGas(contractName, method, args = []) {
|
|
114
|
+
const contract = this.getContractInstance(contractName, true);
|
|
115
|
+
if (!contract[method]) {
|
|
116
|
+
throw new Error(`Method "${method}" not found on contract "${contractName}"`);
|
|
117
|
+
}
|
|
118
|
+
return await contract[method].estimateGas(...args);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Deploy new sovereign contract instance
|
|
122
|
+
*
|
|
123
|
+
* @param template - Template type (e.g., 'iso', 'healthcare')
|
|
124
|
+
* @param config - Deployment configuration
|
|
125
|
+
* @returns Deployed contract address
|
|
126
|
+
*/
|
|
127
|
+
async deploySovereignContract(template, config) {
|
|
128
|
+
// This would deploy a new instance of template contracts
|
|
129
|
+
// For example, a company deploying their own MerchantRegistry
|
|
130
|
+
throw new Error('Sovereign contract deployment not yet implemented');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get contract address by name
|
|
134
|
+
*
|
|
135
|
+
* @param contractName - Contract name
|
|
136
|
+
* @returns Contract address
|
|
137
|
+
*/
|
|
138
|
+
async getContractAddress(contractName) {
|
|
139
|
+
return this.sdk.getContractAddress(contractName);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get contract instance
|
|
143
|
+
*
|
|
144
|
+
* @param contractName - Contract name
|
|
145
|
+
* @returns Contract instance
|
|
146
|
+
*/
|
|
147
|
+
async getContract(contractName) {
|
|
148
|
+
return this.getContractInstance(contractName, false);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Listen to contract events
|
|
152
|
+
*
|
|
153
|
+
* @param contractName - Contract name
|
|
154
|
+
* @param eventName - Event name
|
|
155
|
+
* @param callback - Event callback
|
|
156
|
+
*/
|
|
157
|
+
async listen(contractName, eventName, callback) {
|
|
158
|
+
const contract = this.getContractInstance(contractName, false);
|
|
159
|
+
const listenerId = `${contractName}:${eventName}`;
|
|
160
|
+
// Remove existing listener if any
|
|
161
|
+
if (this.eventListeners.has(listenerId)) {
|
|
162
|
+
await this.stopListening(contractName, eventName);
|
|
163
|
+
}
|
|
164
|
+
contract.on(eventName, callback);
|
|
165
|
+
this.eventListeners.set(listenerId, { contract, eventName, callback });
|
|
166
|
+
console.log(`✅ Listening to ${contractName}.${eventName}`);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Stop listening to contract events
|
|
170
|
+
*
|
|
171
|
+
* @param contractName - Contract name
|
|
172
|
+
* @param eventName - Event name
|
|
173
|
+
*/
|
|
174
|
+
async stopListening(contractName, eventName) {
|
|
175
|
+
const listenerId = `${contractName}:${eventName}`;
|
|
176
|
+
const listener = this.eventListeners.get(listenerId);
|
|
177
|
+
if (listener) {
|
|
178
|
+
listener.contract.off(eventName, listener.callback);
|
|
179
|
+
this.eventListeners.delete(listenerId);
|
|
180
|
+
console.log(`✅ Stopped listening to ${contractName}.${eventName}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Batch call multiple read-only methods
|
|
185
|
+
*
|
|
186
|
+
* @param calls - Array of contract calls
|
|
187
|
+
* @returns Array of results
|
|
188
|
+
*/
|
|
189
|
+
async batchCall(calls) {
|
|
190
|
+
const promises = calls.map(call => this.call(call.contractName, call.method, call.args));
|
|
191
|
+
return await Promise.all(promises);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Multicall on single contract
|
|
195
|
+
*
|
|
196
|
+
* @param contractName - Contract name
|
|
197
|
+
* @param calls - Array of method calls
|
|
198
|
+
* @returns Array of results
|
|
199
|
+
*/
|
|
200
|
+
async multicall(contractName, calls) {
|
|
201
|
+
const contract = this.getContractInstance(contractName, false);
|
|
202
|
+
const promises = calls.map(call => contract[call.method](...call.args));
|
|
203
|
+
return await Promise.all(promises);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Register custom contract ABI
|
|
207
|
+
*
|
|
208
|
+
* @param contractName - Contract name
|
|
209
|
+
* @param abi - Contract ABI
|
|
210
|
+
*/
|
|
211
|
+
registerABI(contractName, abi) {
|
|
212
|
+
ContractsModule.ABI_REGISTRY[contractName] = abi;
|
|
213
|
+
console.log(`✅ Registered ABI for ${contractName}`);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Clear cached contract instances
|
|
217
|
+
*/
|
|
218
|
+
clearCache() {
|
|
219
|
+
this.contracts.clear();
|
|
220
|
+
console.log('✅ Contract cache cleared');
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Remove all event listeners
|
|
224
|
+
*/
|
|
225
|
+
async removeAllListeners() {
|
|
226
|
+
for (const [listenerId, listener] of this.eventListeners.entries()) {
|
|
227
|
+
listener.contract.off(listener.eventName, listener.callback);
|
|
228
|
+
}
|
|
229
|
+
this.eventListeners.clear();
|
|
230
|
+
console.log('✅ All event listeners removed');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Contract ABI registry
|
|
234
|
+
ContractsModule.ABI_REGISTRY = {
|
|
235
|
+
MerchantRegistry: MerchantRegistryABI.abi,
|
|
236
|
+
TransactionVault: TransactionVaultABI.abi,
|
|
237
|
+
RepPerformance: RepPerformanceABI.abi,
|
|
238
|
+
ResidualCalculator: ResidualCalculatorABI.abi,
|
|
239
|
+
AccessControlRegistry: AccessControlRegistryABI.abi,
|
|
240
|
+
DataProofRegistry: DataProofRegistryABI.abi,
|
|
241
|
+
VarityWalletFactory: VarityWalletFactoryABI.abi
|
|
242
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/contracts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,YAAY,EACV,SAAS,EACT,YAAY,EACZ,SAAS,EACT,cAAc,EACd,aAAa,EACd,MAAM,mBAAmB,CAAA"}
|