@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,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blockchain Service for Varity SDK
|
|
3
|
+
*
|
|
4
|
+
* Core blockchain integration using thirdweb v5.
|
|
5
|
+
* Production patterns extracted from generic-template-dashboard.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - thirdweb v5 function-based API
|
|
9
|
+
* - Contract reading via readContract
|
|
10
|
+
* - Transaction submission via Engine
|
|
11
|
+
* - Multi-chain support
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { BlockchainService } from '@varity-labs/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const service = new BlockchainService({
|
|
18
|
+
* rpcUrl: "https://rpc-varity-testnet-rroe52pwjp.t.conduit.xyz",
|
|
19
|
+
* chainId: 33529
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const isConnected = await service.isConnected();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import type { BlockchainServiceOptions } from './types';
|
|
26
|
+
export declare class BlockchainService {
|
|
27
|
+
private client;
|
|
28
|
+
private chain;
|
|
29
|
+
private contracts;
|
|
30
|
+
private abis;
|
|
31
|
+
constructor(options: BlockchainServiceOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Check if connected to blockchain
|
|
34
|
+
*
|
|
35
|
+
* Production Pattern: Extracted from lines 143-145
|
|
36
|
+
*/
|
|
37
|
+
isConnected(): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Get the latest block number
|
|
40
|
+
*
|
|
41
|
+
* Production Pattern: Extracted from lines 147-153
|
|
42
|
+
*/
|
|
43
|
+
getBlockNumber(): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the chain ID
|
|
46
|
+
*
|
|
47
|
+
* Production Pattern: Extracted from lines 155-161
|
|
48
|
+
*/
|
|
49
|
+
getChainId(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Load contract ABI
|
|
52
|
+
*
|
|
53
|
+
* @param contractName - Name of the contract
|
|
54
|
+
* @param abi - Contract ABI
|
|
55
|
+
*
|
|
56
|
+
* Production Pattern: Extracted from lines 79-114
|
|
57
|
+
*/
|
|
58
|
+
loadContractABI(contractName: string, abi: any[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Initialize a contract instance
|
|
61
|
+
*
|
|
62
|
+
* @param contractName - Name of the contract
|
|
63
|
+
* @param address - Contract address
|
|
64
|
+
*
|
|
65
|
+
* Production Pattern: Extracted from lines 116-140
|
|
66
|
+
*/
|
|
67
|
+
initializeContract(contractName: string, address: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get a cached contract instance
|
|
70
|
+
*/
|
|
71
|
+
getContract(contractName: string): any | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Read from a contract (thirdweb v5 pattern)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const balance = await service.readContract(
|
|
78
|
+
* 'ToolLicenseNFT',
|
|
79
|
+
* 'balanceOf',
|
|
80
|
+
* [walletAddress, toolId]
|
|
81
|
+
* );
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
readContract<T = any>(contractName: string, functionName: string, args?: any[]): Promise<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Format USDC amount (6 decimals) to human-readable
|
|
87
|
+
*
|
|
88
|
+
* @param amount - Amount in smallest unit (e.g., 100_000_000)
|
|
89
|
+
* @returns Formatted string (e.g., "100.00 USDC")
|
|
90
|
+
*/
|
|
91
|
+
formatUSDC(amount: bigint): string;
|
|
92
|
+
/**
|
|
93
|
+
* Parse human-readable USDC to smallest unit
|
|
94
|
+
*
|
|
95
|
+
* @param amountStr - Amount as string (e.g., "100.50")
|
|
96
|
+
* @returns Amount in smallest unit (6 decimals)
|
|
97
|
+
*/
|
|
98
|
+
parseUSDC(amountStr: string): bigint;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=BlockchainService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockchainService.d.ts","sourceRoot":"","sources":["../../src/blockchain/BlockchainService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,OAAO,KAAK,EAAkB,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExE,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,IAAI,CAAqB;gBAErB,OAAO,EAAE,wBAAwB;IAkB7C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAWrC;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAsBvC;;;;OAIG;IACH,UAAU,IAAI,MAAM;IAIpB;;;;;;;OAOG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAIvD;;;;;;;OAOG;IACH,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAyB/D;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAIlD;;;;;;;;;;;OAWG;IACG,YAAY,CAAC,CAAC,GAAG,GAAG,EACxB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,IAAI,GAAE,GAAG,EAAO,GACf,OAAO,CAAC,CAAC,CAAC;IAoBb;;;;;OAKG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAKlC;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAIrC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blockchain Service for Varity SDK
|
|
3
|
+
*
|
|
4
|
+
* Core blockchain integration using thirdweb v5.
|
|
5
|
+
* Production patterns extracted from generic-template-dashboard.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - thirdweb v5 function-based API
|
|
9
|
+
* - Contract reading via readContract
|
|
10
|
+
* - Transaction submission via Engine
|
|
11
|
+
* - Multi-chain support
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { BlockchainService } from '@varity-labs/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const service = new BlockchainService({
|
|
18
|
+
* rpcUrl: "https://rpc-varity-testnet-rroe52pwjp.t.conduit.xyz",
|
|
19
|
+
* chainId: 33529
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const isConnected = await service.isConnected();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { createThirdwebClient, getContract, defineChain } from 'thirdweb';
|
|
26
|
+
import { readContract } from 'thirdweb';
|
|
27
|
+
export class BlockchainService {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
const { rpcUrl, chainId, engineUrl, engineAccessToken, backendWallet } = options;
|
|
30
|
+
// Create thirdweb client
|
|
31
|
+
this.client = createThirdwebClient({
|
|
32
|
+
clientId: process.env.THIRDWEB_CLIENT_ID || '',
|
|
33
|
+
});
|
|
34
|
+
// Define chain
|
|
35
|
+
this.chain = defineChain({
|
|
36
|
+
id: chainId,
|
|
37
|
+
rpc: rpcUrl,
|
|
38
|
+
});
|
|
39
|
+
this.contracts = new Map();
|
|
40
|
+
this.abis = new Map();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if connected to blockchain
|
|
44
|
+
*
|
|
45
|
+
* Production Pattern: Extracted from lines 143-145
|
|
46
|
+
*/
|
|
47
|
+
async isConnected() {
|
|
48
|
+
try {
|
|
49
|
+
// Try to get the latest block number
|
|
50
|
+
const block = await this.getBlockNumber();
|
|
51
|
+
return block > 0;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Connection check failed:', error);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the latest block number
|
|
60
|
+
*
|
|
61
|
+
* Production Pattern: Extracted from lines 147-153
|
|
62
|
+
*/
|
|
63
|
+
async getBlockNumber() {
|
|
64
|
+
try {
|
|
65
|
+
// Use thirdweb to get block number
|
|
66
|
+
const response = await fetch(this.chain.rpc, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: { 'Content-Type': 'application/json' },
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
jsonrpc: '2.0',
|
|
71
|
+
method: 'eth_blockNumber',
|
|
72
|
+
params: [],
|
|
73
|
+
id: 1,
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
const data = await response.json();
|
|
77
|
+
return parseInt(data.result, 16);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('Failed to get block number:', error);
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the chain ID
|
|
86
|
+
*
|
|
87
|
+
* Production Pattern: Extracted from lines 155-161
|
|
88
|
+
*/
|
|
89
|
+
getChainId() {
|
|
90
|
+
return this.chain.id;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Load contract ABI
|
|
94
|
+
*
|
|
95
|
+
* @param contractName - Name of the contract
|
|
96
|
+
* @param abi - Contract ABI
|
|
97
|
+
*
|
|
98
|
+
* Production Pattern: Extracted from lines 79-114
|
|
99
|
+
*/
|
|
100
|
+
loadContractABI(contractName, abi) {
|
|
101
|
+
this.abis.set(contractName, abi);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Initialize a contract instance
|
|
105
|
+
*
|
|
106
|
+
* @param contractName - Name of the contract
|
|
107
|
+
* @param address - Contract address
|
|
108
|
+
*
|
|
109
|
+
* Production Pattern: Extracted from lines 116-140
|
|
110
|
+
*/
|
|
111
|
+
initializeContract(contractName, address) {
|
|
112
|
+
// Check if zero address
|
|
113
|
+
if (address === '0x0000000000000000000000000000000000000000') {
|
|
114
|
+
console.warn(`Skipping ${contractName} - not deployed yet`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Get ABI
|
|
118
|
+
const abi = this.abis.get(contractName);
|
|
119
|
+
if (!abi) {
|
|
120
|
+
console.warn(`No ABI found for ${contractName}`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// Create contract instance using thirdweb
|
|
124
|
+
const contract = getContract({
|
|
125
|
+
client: this.client,
|
|
126
|
+
chain: this.chain,
|
|
127
|
+
address,
|
|
128
|
+
abi,
|
|
129
|
+
});
|
|
130
|
+
this.contracts.set(contractName, contract);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get a cached contract instance
|
|
134
|
+
*/
|
|
135
|
+
getContract(contractName) {
|
|
136
|
+
return this.contracts.get(contractName);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Read from a contract (thirdweb v5 pattern)
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const balance = await service.readContract(
|
|
144
|
+
* 'ToolLicenseNFT',
|
|
145
|
+
* 'balanceOf',
|
|
146
|
+
* [walletAddress, toolId]
|
|
147
|
+
* );
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
async readContract(contractName, functionName, args = []) {
|
|
151
|
+
const contract = this.getContract(contractName);
|
|
152
|
+
if (!contract) {
|
|
153
|
+
throw new Error(`Contract ${contractName} not initialized`);
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const result = await readContract({
|
|
157
|
+
contract,
|
|
158
|
+
method: functionName,
|
|
159
|
+
params: args,
|
|
160
|
+
});
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error(`Error reading from ${contractName}.${functionName}:`, error);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Format USDC amount (6 decimals) to human-readable
|
|
170
|
+
*
|
|
171
|
+
* @param amount - Amount in smallest unit (e.g., 100_000_000)
|
|
172
|
+
* @returns Formatted string (e.g., "100.00 USDC")
|
|
173
|
+
*/
|
|
174
|
+
formatUSDC(amount) {
|
|
175
|
+
const usdcValue = Number(amount) / 1000000;
|
|
176
|
+
return `${usdcValue.toFixed(2)} USDC`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Parse human-readable USDC to smallest unit
|
|
180
|
+
*
|
|
181
|
+
* @param amountStr - Amount as string (e.g., "100.50")
|
|
182
|
+
* @returns Amount in smallest unit (6 decimals)
|
|
183
|
+
*/
|
|
184
|
+
parseUSDC(amountStr) {
|
|
185
|
+
const usdcDecimal = parseFloat(amountStr);
|
|
186
|
+
return BigInt(Math.round(usdcDecimal * 1000000));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NFT Licensing Service for Varity SDK
|
|
3
|
+
*
|
|
4
|
+
* ERC-1155 NFT-based licensing system using thirdweb v5.
|
|
5
|
+
* Production patterns extracted from generic-template-dashboard (lines 218-280).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BlockchainService, NFTLicensingService } from '@varity-labs/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const blockchain = new BlockchainService({ rpcUrl: "...", chainId: 33529 });
|
|
12
|
+
* const licensing = new NFTLicensingService(blockchain);
|
|
13
|
+
*
|
|
14
|
+
* const hasLicense = await licensing.hasLicense("0x...", 1);
|
|
15
|
+
* console.log(`User has license: ${hasLicense}`);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { BlockchainService } from './BlockchainService';
|
|
19
|
+
import type { NFTLicenseMetadata, LicenseInfo } from './types';
|
|
20
|
+
export declare class NFTLicensingService {
|
|
21
|
+
private blockchain;
|
|
22
|
+
private nftContractName;
|
|
23
|
+
constructor(blockchainService: BlockchainService, nftContractName?: string);
|
|
24
|
+
/**
|
|
25
|
+
* Check if customer owns license NFT for a specific tool
|
|
26
|
+
*
|
|
27
|
+
* @param customerWallet - Customer's wallet address
|
|
28
|
+
* @param toolId - The tool's ID
|
|
29
|
+
* @returns True if customer owns the license NFT
|
|
30
|
+
*
|
|
31
|
+
* Production Pattern: Extracted from lines 220-246
|
|
32
|
+
*/
|
|
33
|
+
hasLicense(customerWallet: string, toolId: number): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Get all tool IDs that the user has licenses for
|
|
36
|
+
*
|
|
37
|
+
* @param customerWallet - Customer's wallet address
|
|
38
|
+
* @returns List of tool IDs the user has licenses for
|
|
39
|
+
*
|
|
40
|
+
* Production Pattern: Extracted from lines 248-280
|
|
41
|
+
*/
|
|
42
|
+
getUserLicenses(customerWallet: string): Promise<number[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Get tool metadata including price and details
|
|
45
|
+
*
|
|
46
|
+
* @param toolId - The tool's unique ID
|
|
47
|
+
* @returns NFTLicenseMetadata object, or null if not found
|
|
48
|
+
*
|
|
49
|
+
* Production Pattern: Extracted from lines 186-216
|
|
50
|
+
*/
|
|
51
|
+
getToolMetadata(toolId: number): Promise<NFTLicenseMetadata | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Get detailed license information for a user's NFT
|
|
54
|
+
*
|
|
55
|
+
* @param customerWallet - Customer's wallet address
|
|
56
|
+
* @param toolId - The tool's ID
|
|
57
|
+
* @returns LicenseInfo object, or null if not found
|
|
58
|
+
*/
|
|
59
|
+
getLicenseInfo(customerWallet: string, toolId: number): Promise<LicenseInfo | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Get list of all active tool IDs from the marketplace
|
|
62
|
+
*
|
|
63
|
+
* @returns List of active tool IDs
|
|
64
|
+
*
|
|
65
|
+
* Production Pattern: Extracted from lines 165-184
|
|
66
|
+
*/
|
|
67
|
+
getActiveTools(): Promise<number[]>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=NFTLicensingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NFTLicensingService.d.ts","sourceRoot":"","sources":["../../src/blockchain/NFTLicensingService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,eAAe,CAAS;gBAG9B,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,GAAE,MAAyB;IAM5C;;;;;;;;OAQG;IACG,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmB1E;;;;;;;OAOG;IACG,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA8BhE;;;;;;;OAOG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAwBzE;;;;;;OAMG;IACG,cAAc,CAClB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAuB9B;;;;;;OAMG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAc1C"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NFT Licensing Service for Varity SDK
|
|
3
|
+
*
|
|
4
|
+
* ERC-1155 NFT-based licensing system using thirdweb v5.
|
|
5
|
+
* Production patterns extracted from generic-template-dashboard (lines 218-280).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BlockchainService, NFTLicensingService } from '@varity-labs/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const blockchain = new BlockchainService({ rpcUrl: "...", chainId: 33529 });
|
|
12
|
+
* const licensing = new NFTLicensingService(blockchain);
|
|
13
|
+
*
|
|
14
|
+
* const hasLicense = await licensing.hasLicense("0x...", 1);
|
|
15
|
+
* console.log(`User has license: ${hasLicense}`);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class NFTLicensingService {
|
|
19
|
+
constructor(blockchainService, nftContractName = 'ToolLicenseNFT') {
|
|
20
|
+
this.blockchain = blockchainService;
|
|
21
|
+
this.nftContractName = nftContractName;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if customer owns license NFT for a specific tool
|
|
25
|
+
*
|
|
26
|
+
* @param customerWallet - Customer's wallet address
|
|
27
|
+
* @param toolId - The tool's ID
|
|
28
|
+
* @returns True if customer owns the license NFT
|
|
29
|
+
*
|
|
30
|
+
* Production Pattern: Extracted from lines 220-246
|
|
31
|
+
*/
|
|
32
|
+
async hasLicense(customerWallet, toolId) {
|
|
33
|
+
try {
|
|
34
|
+
// Call balanceOf(address, uint256) - ERC-1155 function
|
|
35
|
+
const balance = await this.blockchain.readContract(this.nftContractName, 'balanceOf', [customerWallet, BigInt(toolId)]);
|
|
36
|
+
return balance > 0n;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error(`Error checking license for wallet ${customerWallet}, tool ${toolId}:`, error);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get all tool IDs that the user has licenses for
|
|
45
|
+
*
|
|
46
|
+
* @param customerWallet - Customer's wallet address
|
|
47
|
+
* @returns List of tool IDs the user has licenses for
|
|
48
|
+
*
|
|
49
|
+
* Production Pattern: Extracted from lines 248-280
|
|
50
|
+
*/
|
|
51
|
+
async getUserLicenses(customerWallet) {
|
|
52
|
+
try {
|
|
53
|
+
// Get all active tools from marketplace
|
|
54
|
+
const toolIds = await this.blockchain.readContract('ToolMarketplace', 'getActiveTools', []);
|
|
55
|
+
// Check balance for each tool
|
|
56
|
+
const licenses = [];
|
|
57
|
+
for (const toolId of toolIds) {
|
|
58
|
+
const balance = await this.blockchain.readContract(this.nftContractName, 'balanceOf', [customerWallet, toolId]);
|
|
59
|
+
if (balance > 0n) {
|
|
60
|
+
licenses.push(Number(toolId));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return licenses;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error(`Error getting user licenses for wallet ${customerWallet}:`, error);
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get tool metadata including price and details
|
|
72
|
+
*
|
|
73
|
+
* @param toolId - The tool's unique ID
|
|
74
|
+
* @returns NFTLicenseMetadata object, or null if not found
|
|
75
|
+
*
|
|
76
|
+
* Production Pattern: Extracted from lines 186-216
|
|
77
|
+
*/
|
|
78
|
+
async getToolMetadata(toolId) {
|
|
79
|
+
try {
|
|
80
|
+
// Call getToolMetadata function
|
|
81
|
+
const metadata = await this.blockchain.readContract(this.nftContractName, 'getToolMetadata', [BigInt(toolId)]);
|
|
82
|
+
// Parse response
|
|
83
|
+
return {
|
|
84
|
+
toolId,
|
|
85
|
+
name: metadata[0] || '',
|
|
86
|
+
description: metadata[1] || '',
|
|
87
|
+
price: BigInt(metadata[2] || 0),
|
|
88
|
+
creator: metadata[3] || '',
|
|
89
|
+
isActive: metadata[4] || false,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(`Error getting tool metadata for tool ${toolId}:`, error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get detailed license information for a user's NFT
|
|
99
|
+
*
|
|
100
|
+
* @param customerWallet - Customer's wallet address
|
|
101
|
+
* @param toolId - The tool's ID
|
|
102
|
+
* @returns LicenseInfo object, or null if not found
|
|
103
|
+
*/
|
|
104
|
+
async getLicenseInfo(customerWallet, toolId) {
|
|
105
|
+
try {
|
|
106
|
+
// Get balance
|
|
107
|
+
const balance = await this.blockchain.readContract(this.nftContractName, 'balanceOf', [customerWallet, BigInt(toolId)]);
|
|
108
|
+
return {
|
|
109
|
+
toolId,
|
|
110
|
+
balance,
|
|
111
|
+
isValid: balance > 0n,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error(`Error getting license info for wallet ${customerWallet}, tool ${toolId}:`, error);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get list of all active tool IDs from the marketplace
|
|
121
|
+
*
|
|
122
|
+
* @returns List of active tool IDs
|
|
123
|
+
*
|
|
124
|
+
* Production Pattern: Extracted from lines 165-184
|
|
125
|
+
*/
|
|
126
|
+
async getActiveTools() {
|
|
127
|
+
try {
|
|
128
|
+
const toolIds = await this.blockchain.readContract('ToolMarketplace', 'getActiveTools', []);
|
|
129
|
+
return toolIds.map((id) => Number(id));
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error('Error getting active tools:', error);
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Revenue Split Service for Varity SDK
|
|
3
|
+
*
|
|
4
|
+
* Manages revenue distribution (70% creator, 30% platform).
|
|
5
|
+
* Production patterns extracted from generic-template-dashboard.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BlockchainService, RevenueSplitService } from '@varity-labs/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const blockchain = new BlockchainService({ rpcUrl: "...", chainId: 33529 });
|
|
12
|
+
* const revenue = new RevenueSplitService(blockchain);
|
|
13
|
+
*
|
|
14
|
+
* const [creatorAmount, platformAmount] = revenue.calculateSplit(100_000_000n); // 100 USDC
|
|
15
|
+
* console.log(`Creator: ${creatorAmount}, Platform: ${platformAmount}`);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { BlockchainService } from './BlockchainService';
|
|
19
|
+
import type { RevenueSplit, TransactionResult } from './types';
|
|
20
|
+
export declare class RevenueSplitService {
|
|
21
|
+
private blockchain;
|
|
22
|
+
private splitterContractName;
|
|
23
|
+
private platformPercentage;
|
|
24
|
+
private creatorPercentage;
|
|
25
|
+
constructor(blockchainService: BlockchainService, splitterContractName?: string, platformPercentage?: number);
|
|
26
|
+
/**
|
|
27
|
+
* Calculate creator and platform amounts from total
|
|
28
|
+
*
|
|
29
|
+
* @param totalAmount - Total amount in smallest unit (e.g., USDC with 6 decimals)
|
|
30
|
+
* @returns Tuple of [creatorAmount, platformAmount]
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const [creator, platform] = revenue.calculateSplit(100_000_000n); // 100 USDC
|
|
35
|
+
* // Returns: [70_000_000n, 30_000_000n] (70 USDC, 30 USDC)
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
calculateSplit(totalAmount: bigint): [bigint, bigint];
|
|
39
|
+
/**
|
|
40
|
+
* Distribute revenue for a tool purchase
|
|
41
|
+
*
|
|
42
|
+
* Note: Transaction submission requires thirdweb Engine setup
|
|
43
|
+
*
|
|
44
|
+
* @param toolId - The tool's ID
|
|
45
|
+
* @param amountUSDC - Amount in USDC (6 decimals)
|
|
46
|
+
* @returns TransactionResult if successful, null if error
|
|
47
|
+
*/
|
|
48
|
+
distributeRevenue(toolId: number, amountUSDC: bigint): Promise<TransactionResult | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Get revenue split configuration for a tool
|
|
51
|
+
*
|
|
52
|
+
* @param toolId - The tool's ID
|
|
53
|
+
* @returns RevenueSplit configuration, or null if not found
|
|
54
|
+
*/
|
|
55
|
+
getRevenueSplitConfig(toolId: number): Promise<RevenueSplit | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Format USDC amount to human-readable string
|
|
58
|
+
*
|
|
59
|
+
* @param amount - Amount in smallest unit
|
|
60
|
+
* @returns Formatted string (e.g., "100.00 USDC")
|
|
61
|
+
*/
|
|
62
|
+
formatUSDC(amount: bigint): string;
|
|
63
|
+
/**
|
|
64
|
+
* Parse human-readable USDC to smallest unit
|
|
65
|
+
*
|
|
66
|
+
* @param amountStr - Amount as string (e.g., "100.50")
|
|
67
|
+
* @returns Amount in smallest unit (6 decimals)
|
|
68
|
+
*/
|
|
69
|
+
parseUSDC(amountStr: string): bigint;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=RevenueSplitService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RevenueSplitService.d.ts","sourceRoot":"","sources":["../../src/blockchain/RevenueSplitService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE/D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,iBAAiB,CAAS;gBAGhC,iBAAiB,EAAE,iBAAiB,EACpC,oBAAoB,GAAE,MAA0B,EAChD,kBAAkB,GAAE,MAAW;IAQjC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAMrD;;;;;;;;OAQG;IACG,iBAAiB,CACrB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IA2BpC;;;;;OAKG;IACG,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAqBzE;;;;;OAKG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAIlC;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAGrC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Revenue Split Service for Varity SDK
|
|
3
|
+
*
|
|
4
|
+
* Manages revenue distribution (70% creator, 30% platform).
|
|
5
|
+
* Production patterns extracted from generic-template-dashboard.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BlockchainService, RevenueSplitService } from '@varity-labs/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const blockchain = new BlockchainService({ rpcUrl: "...", chainId: 33529 });
|
|
12
|
+
* const revenue = new RevenueSplitService(blockchain);
|
|
13
|
+
*
|
|
14
|
+
* const [creatorAmount, platformAmount] = revenue.calculateSplit(100_000_000n); // 100 USDC
|
|
15
|
+
* console.log(`Creator: ${creatorAmount}, Platform: ${platformAmount}`);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class RevenueSplitService {
|
|
19
|
+
constructor(blockchainService, splitterContractName = 'RevenueSplitter', platformPercentage = 30) {
|
|
20
|
+
this.blockchain = blockchainService;
|
|
21
|
+
this.splitterContractName = splitterContractName;
|
|
22
|
+
this.platformPercentage = platformPercentage;
|
|
23
|
+
this.creatorPercentage = 100 - platformPercentage;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Calculate creator and platform amounts from total
|
|
27
|
+
*
|
|
28
|
+
* @param totalAmount - Total amount in smallest unit (e.g., USDC with 6 decimals)
|
|
29
|
+
* @returns Tuple of [creatorAmount, platformAmount]
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const [creator, platform] = revenue.calculateSplit(100_000_000n); // 100 USDC
|
|
34
|
+
* // Returns: [70_000_000n, 30_000_000n] (70 USDC, 30 USDC)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
calculateSplit(totalAmount) {
|
|
38
|
+
const creatorAmount = (totalAmount * BigInt(this.creatorPercentage)) / 100n;
|
|
39
|
+
const platformAmount = totalAmount - creatorAmount; // Remainder goes to platform
|
|
40
|
+
return [creatorAmount, platformAmount];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Distribute revenue for a tool purchase
|
|
44
|
+
*
|
|
45
|
+
* Note: Transaction submission requires thirdweb Engine setup
|
|
46
|
+
*
|
|
47
|
+
* @param toolId - The tool's ID
|
|
48
|
+
* @param amountUSDC - Amount in USDC (6 decimals)
|
|
49
|
+
* @returns TransactionResult if successful, null if error
|
|
50
|
+
*/
|
|
51
|
+
async distributeRevenue(toolId, amountUSDC) {
|
|
52
|
+
try {
|
|
53
|
+
// Calculate split
|
|
54
|
+
const [creatorAmount, platformAmount] = this.calculateSplit(amountUSDC);
|
|
55
|
+
console.log(`Distributing revenue for tool ${toolId}: ` +
|
|
56
|
+
`Total=${amountUSDC}, Creator=${creatorAmount} (${this.creatorPercentage}%), ` +
|
|
57
|
+
`Platform=${platformAmount} (${this.platformPercentage}%)`);
|
|
58
|
+
// Note: Actual transaction submission would be done via thirdweb Engine
|
|
59
|
+
// This requires Engine setup with backend wallet and access token
|
|
60
|
+
console.warn('Transaction submission requires thirdweb Engine configuration');
|
|
61
|
+
return {
|
|
62
|
+
txHash: '0x0', // Placeholder
|
|
63
|
+
status: 1,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error(`Error distributing revenue for tool ${toolId}:`, error);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get revenue split configuration for a tool
|
|
73
|
+
*
|
|
74
|
+
* @param toolId - The tool's ID
|
|
75
|
+
* @returns RevenueSplit configuration, or null if not found
|
|
76
|
+
*/
|
|
77
|
+
async getRevenueSplitConfig(toolId) {
|
|
78
|
+
try {
|
|
79
|
+
// Call getRevenueSplit(uint256)
|
|
80
|
+
const splitData = await this.blockchain.readContract(this.splitterContractName, 'getRevenueSplit', [BigInt(toolId)]);
|
|
81
|
+
return {
|
|
82
|
+
creatorPercentage: Number(splitData[0]),
|
|
83
|
+
platformPercentage: Number(splitData[1]),
|
|
84
|
+
creatorAddress: splitData[2],
|
|
85
|
+
platformAddress: splitData[3],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(`Error getting revenue split config for tool ${toolId}:`, error);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Format USDC amount to human-readable string
|
|
95
|
+
*
|
|
96
|
+
* @param amount - Amount in smallest unit
|
|
97
|
+
* @returns Formatted string (e.g., "100.00 USDC")
|
|
98
|
+
*/
|
|
99
|
+
formatUSDC(amount) {
|
|
100
|
+
return this.blockchain.formatUSDC(amount);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Parse human-readable USDC to smallest unit
|
|
104
|
+
*
|
|
105
|
+
* @param amountStr - Amount as string (e.g., "100.50")
|
|
106
|
+
* @returns Amount in smallest unit (6 decimals)
|
|
107
|
+
*/
|
|
108
|
+
parseUSDC(amountStr) {
|
|
109
|
+
return this.blockchain.parseUSDC(amountStr);
|
|
110
|
+
}
|
|
111
|
+
}
|