@aintivirus-ai/mixer-sdk 1.0.0

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.
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ /**
3
+ * Hook for admin functions (EVM or Solana)
4
+ * Use this hook when you need to perform admin operations
5
+ * Requires OPERATOR_ROLE or ADMIN_ROLE
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.useAdmin = useAdmin;
9
+ const react_1 = require("react");
10
+ const types_1 = require("../types");
11
+ const evm_1 = require("../evm");
12
+ const solana_1 = require("../solana");
13
+ const wagmi_1 = require("wagmi");
14
+ const utils_1 = require("./utils");
15
+ /**
16
+ * Hook for admin functions
17
+ * Only initializes what's needed for admin operations
18
+ */
19
+ function useAdmin(config) {
20
+ // EVM setup
21
+ const { isConnected: evmConnected } = (0, wagmi_1.useAccount)();
22
+ const { data: walletClient } = (0, wagmi_1.useWalletClient)();
23
+ const publicClient = (0, wagmi_1.usePublicClient)();
24
+ const evmSDK = (0, react_1.useMemo)(() => {
25
+ if (!config.evm?.factoryAddress) {
26
+ return null;
27
+ }
28
+ if (!publicClient) {
29
+ return null;
30
+ }
31
+ try {
32
+ const provider = (0, utils_1.createEthersProviderFromViem)(publicClient);
33
+ const signerOrProvider = walletClient
34
+ ? (0, utils_1.createEthersSignerFromViem)(walletClient, publicClient)
35
+ : provider;
36
+ return new evm_1.AintiVirusEVM(config.evm.factoryAddress, config.evm.tokenAddress || "0x0000000000000000000000000000000000000000", signerOrProvider);
37
+ }
38
+ catch (error) {
39
+ console.error("Failed to initialize AintiVirusEVM:", error);
40
+ return null;
41
+ }
42
+ }, [
43
+ config.evm?.factoryAddress,
44
+ config.evm?.tokenAddress,
45
+ walletClient,
46
+ publicClient,
47
+ ]);
48
+ const isEVMReady = !!evmSDK && evmConnected;
49
+ // Solana setup
50
+ const solanaSDK = (0, react_1.useMemo)(() => {
51
+ if (!config.solana?.factoryProgramId ||
52
+ !config.solana?.mixerProgramId ||
53
+ !config.solana?.stakingProgramId) {
54
+ return null;
55
+ }
56
+ if (!config.solanaWallet || !config.solanaConnection) {
57
+ return null;
58
+ }
59
+ try {
60
+ return new solana_1.AintiVirusSolana(config.solana.factoryProgramId, config.solana.mixerProgramId, config.solana.stakingProgramId, config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
61
+ }
62
+ catch (error) {
63
+ console.error("Failed to initialize AintiVirusSolana:", error);
64
+ return null;
65
+ }
66
+ }, [
67
+ config.solana?.factoryProgramId,
68
+ config.solana?.mixerProgramId,
69
+ config.solana?.stakingProgramId,
70
+ config.solana?.tokenMint,
71
+ config.solanaWallet,
72
+ config.solanaConnection,
73
+ ]);
74
+ const isSolanaReady = !!solanaSDK && !!config.solanaWallet?.publicKey;
75
+ // Admin functions
76
+ const setFeeRate = (0, react_1.useCallback)(async (chainType, feeRate) => {
77
+ if (chainType === types_1.ChainType.EVM) {
78
+ if (!evmSDK) {
79
+ throw new Error("EVM SDK not initialized");
80
+ }
81
+ const factory = evmSDK.getFactory();
82
+ const tx = await factory.setFeeRate(feeRate);
83
+ const receipt = await tx.wait();
84
+ return {
85
+ txHash: receipt.hash,
86
+ blockNumber: receipt.blockNumber,
87
+ blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
88
+ };
89
+ }
90
+ else if (chainType === types_1.ChainType.SOLANA) {
91
+ if (!solanaSDK) {
92
+ throw new Error("Solana SDK not initialized");
93
+ }
94
+ return solanaSDK.setFeeRate(feeRate);
95
+ }
96
+ throw new Error(`Unsupported chain type: ${chainType}`);
97
+ }, [evmSDK, solanaSDK]);
98
+ const setStakingSeasonPeriod = (0, react_1.useCallback)(async (chainType, period) => {
99
+ if (chainType === types_1.ChainType.EVM) {
100
+ if (!evmSDK) {
101
+ throw new Error("EVM SDK not initialized");
102
+ }
103
+ const factory = evmSDK.getFactory();
104
+ const tx = await factory.setStakingSeasonPeriod(period);
105
+ const receipt = await tx.wait();
106
+ return {
107
+ txHash: receipt.hash,
108
+ blockNumber: receipt.blockNumber,
109
+ blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
110
+ };
111
+ }
112
+ else if (chainType === types_1.ChainType.SOLANA) {
113
+ if (!solanaSDK) {
114
+ throw new Error("Solana SDK not initialized");
115
+ }
116
+ return solanaSDK.setStakingSeasonPeriod(period);
117
+ }
118
+ throw new Error(`Unsupported chain type: ${chainType}`);
119
+ }, [evmSDK, solanaSDK]);
120
+ const startStakeSeason = (0, react_1.useCallback)(async (chainType) => {
121
+ if (chainType === types_1.ChainType.EVM) {
122
+ if (!evmSDK) {
123
+ throw new Error("EVM SDK not initialized");
124
+ }
125
+ const factory = evmSDK.getFactory();
126
+ const tx = await factory.startStakeSeason();
127
+ const receipt = await tx.wait();
128
+ return {
129
+ txHash: receipt.hash,
130
+ blockNumber: receipt.blockNumber,
131
+ blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
132
+ };
133
+ }
134
+ else if (chainType === types_1.ChainType.SOLANA) {
135
+ if (!solanaSDK) {
136
+ throw new Error("Solana SDK not initialized");
137
+ }
138
+ return solanaSDK.startStakeSeason();
139
+ }
140
+ throw new Error(`Unsupported chain type: ${chainType}`);
141
+ }, [evmSDK, solanaSDK]);
142
+ const setVerifier = (0, react_1.useCallback)(async (chainType, verifierAddress) => {
143
+ if (chainType === types_1.ChainType.EVM) {
144
+ if (!evmSDK) {
145
+ throw new Error("EVM SDK not initialized");
146
+ }
147
+ const factory = evmSDK.getFactory();
148
+ const tx = await factory.setVerifier(verifierAddress);
149
+ const receipt = await tx.wait();
150
+ return {
151
+ txHash: receipt.hash,
152
+ blockNumber: receipt.blockNumber,
153
+ blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
154
+ };
155
+ }
156
+ else if (chainType === types_1.ChainType.SOLANA) {
157
+ if (!solanaSDK) {
158
+ throw new Error("Solana SDK not initialized");
159
+ }
160
+ return solanaSDK.setVerifier(verifierAddress);
161
+ }
162
+ throw new Error(`Unsupported chain type: ${chainType}`);
163
+ }, [evmSDK, solanaSDK]);
164
+ const setHasher = (0, react_1.useCallback)(async (chainType, hasherAddress) => {
165
+ if (chainType === types_1.ChainType.EVM) {
166
+ if (!evmSDK) {
167
+ throw new Error("EVM SDK not initialized");
168
+ }
169
+ const factory = evmSDK.getFactory();
170
+ const tx = await factory.setHasher(hasherAddress);
171
+ const receipt = await tx.wait();
172
+ return {
173
+ txHash: receipt.hash,
174
+ blockNumber: receipt.blockNumber,
175
+ blockTime: (await evmSDK.getProvider().getBlock(receipt.blockNumber))?.timestamp,
176
+ };
177
+ }
178
+ else if (chainType === types_1.ChainType.SOLANA) {
179
+ if (!solanaSDK) {
180
+ throw new Error("Solana SDK not initialized");
181
+ }
182
+ return solanaSDK.setHasher(hasherAddress);
183
+ }
184
+ throw new Error(`Unsupported chain type: ${chainType}`);
185
+ }, [evmSDK, solanaSDK]);
186
+ return {
187
+ setFeeRate,
188
+ setStakingSeasonPeriod,
189
+ startStakeSeason,
190
+ setVerifier,
191
+ setHasher,
192
+ isEVMReady,
193
+ isSolanaReady,
194
+ };
195
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Unified hook for AintiVirus Mixer
3
+ * Supports both EVM and Solana chains with unified API
4
+ *
5
+ * Configure both chains at initialization, then use chain type parameter for each function call
6
+ */
7
+ import { ChainType, EVMHookConfig, SolanaHookConfig } from "../types";
8
+ import { Wallet } from "@coral-xyz/anchor";
9
+ import { Connection } from "@solana/web3.js";
10
+ import { AintiVirusEVM } from "../evm";
11
+ import { AintiVirusSolana } from "../solana";
12
+ import { AssetMode, WithdrawalProof, TransactionResult } from "../types";
13
+ /**
14
+ * Unified hook configuration
15
+ */
16
+ export interface UnifiedHookConfig {
17
+ evm?: EVMHookConfig;
18
+ solana?: SolanaHookConfig;
19
+ solanaWallet?: Wallet;
20
+ solanaConnection?: Connection;
21
+ }
22
+ /**
23
+ * Unified hook return type
24
+ */
25
+ export interface UseAintiVirusReturn {
26
+ deposit: (chainType: ChainType, amount: bigint, commitment: bigint) => Promise<TransactionResult>;
27
+ withdraw: (chainType: ChainType, proof: WithdrawalProof, amount: bigint, mode: AssetMode) => Promise<TransactionResult>;
28
+ stake: (chainType: ChainType, amount: bigint) => Promise<TransactionResult>;
29
+ unstake: (chainType: ChainType) => Promise<TransactionResult>;
30
+ claim: (chainType: ChainType, seasonId: bigint) => Promise<TransactionResult>;
31
+ getCurrentSeason: (chainType: ChainType) => Promise<bigint | null>;
32
+ getMixer: (chainType: ChainType, mode: AssetMode, amount: bigint) => Promise<string | null>;
33
+ mixerExists: (chainType: ChainType, mode: AssetMode, amount: bigint) => Promise<boolean>;
34
+ calculateDepositAmount: (chainType: ChainType, amount: bigint) => Promise<bigint | null>;
35
+ isEVMReady: boolean;
36
+ isSolanaReady: boolean;
37
+ evmAddress?: string;
38
+ solanaAddress?: string;
39
+ evmSDK: AintiVirusEVM | null;
40
+ solanaSDK: AintiVirusSolana | null;
41
+ }
42
+ /**
43
+ * Main unified hook that supports both EVM and Solana
44
+ *
45
+ * @param config - Configuration object with both EVM and Solana configs
46
+ * @returns Unified API with chain type parameter for each function
47
+ */
48
+ export declare function useAintiVirus(config: UnifiedHookConfig): UseAintiVirusReturn;
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ /**
3
+ * Unified hook for AintiVirus Mixer
4
+ * Supports both EVM and Solana chains with unified API
5
+ *
6
+ * Configure both chains at initialization, then use chain type parameter for each function call
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.useAintiVirus = useAintiVirus;
10
+ const react_1 = require("react");
11
+ const types_1 = require("../types");
12
+ const evm_1 = require("../evm");
13
+ const solana_1 = require("../solana");
14
+ const wagmi_1 = require("wagmi");
15
+ const utils_1 = require("./utils");
16
+ /**
17
+ * Main unified hook that supports both EVM and Solana
18
+ *
19
+ * @param config - Configuration object with both EVM and Solana configs
20
+ * @returns Unified API with chain type parameter for each function
21
+ */
22
+ function useAintiVirus(config) {
23
+ // EVM setup
24
+ const { address: evmAddress, isConnected: evmConnected } = (0, wagmi_1.useAccount)();
25
+ const { data: walletClient } = (0, wagmi_1.useWalletClient)();
26
+ const publicClient = (0, wagmi_1.usePublicClient)();
27
+ const evmSDK = (0, react_1.useMemo)(() => {
28
+ if (!config.evm?.factoryAddress) {
29
+ return null;
30
+ }
31
+ if (!publicClient) {
32
+ return null;
33
+ }
34
+ try {
35
+ const provider = (0, utils_1.createEthersProviderFromViem)(publicClient);
36
+ const signerOrProvider = walletClient
37
+ ? (0, utils_1.createEthersSignerFromViem)(walletClient, publicClient)
38
+ : provider;
39
+ return new evm_1.AintiVirusEVM(config.evm.factoryAddress, config.evm.tokenAddress || "0x0000000000000000000000000000000000000000", signerOrProvider);
40
+ }
41
+ catch (error) {
42
+ console.error("Failed to initialize AintiVirusEVM:", error);
43
+ return null;
44
+ }
45
+ }, [
46
+ config.evm?.factoryAddress,
47
+ config.evm?.tokenAddress,
48
+ walletClient,
49
+ publicClient,
50
+ ]);
51
+ const isEVMReady = !!evmSDK && evmConnected;
52
+ // Solana setup
53
+ const solanaSDK = (0, react_1.useMemo)(() => {
54
+ if (!config.solana?.factoryProgramId ||
55
+ !config.solana?.mixerProgramId ||
56
+ !config.solana?.stakingProgramId) {
57
+ return null;
58
+ }
59
+ if (!config.solanaWallet || !config.solanaConnection) {
60
+ return null;
61
+ }
62
+ try {
63
+ return new solana_1.AintiVirusSolana(config.solana.factoryProgramId, config.solana.mixerProgramId, config.solana.stakingProgramId, config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
64
+ }
65
+ catch (error) {
66
+ console.error("Failed to initialize AintiVirusSolana:", error);
67
+ return null;
68
+ }
69
+ }, [
70
+ config.solana?.factoryProgramId,
71
+ config.solana?.mixerProgramId,
72
+ config.solana?.stakingProgramId,
73
+ config.solana?.tokenMint,
74
+ config.solanaWallet,
75
+ config.solanaConnection,
76
+ ]);
77
+ const isSolanaReady = !!solanaSDK && !!config.solanaWallet?.publicKey;
78
+ const solanaAddress = config.solanaWallet?.publicKey?.toString();
79
+ // Deposit function
80
+ const deposit = (0, react_1.useCallback)(async (chainType, amount, commitment) => {
81
+ if (chainType === types_1.ChainType.EVM) {
82
+ if (!evmSDK) {
83
+ throw new Error("EVM SDK not initialized");
84
+ }
85
+ return evmSDK.depositEth(amount, commitment);
86
+ }
87
+ else if (chainType === types_1.ChainType.SOLANA) {
88
+ if (!solanaSDK) {
89
+ throw new Error("Solana SDK not initialized");
90
+ }
91
+ return solanaSDK.depositSol(amount, commitment);
92
+ }
93
+ throw new Error(`Unsupported chain type: ${chainType}`);
94
+ }, [evmSDK, solanaSDK]);
95
+ // Withdraw function
96
+ const withdraw = (0, react_1.useCallback)(async (chainType, proof, amount, mode) => {
97
+ if (chainType === types_1.ChainType.EVM) {
98
+ if (!evmSDK) {
99
+ throw new Error("EVM SDK not initialized");
100
+ }
101
+ return evmSDK.withdraw(proof, amount, mode);
102
+ }
103
+ else if (chainType === types_1.ChainType.SOLANA) {
104
+ if (!solanaSDK) {
105
+ throw new Error("Solana SDK not initialized");
106
+ }
107
+ // Solana withdraw needs instruction data and nullifier hash
108
+ // This is a simplified version - you may need to adjust based on your Solana implementation
109
+ const nullifierHash = proof.pubSignals[0];
110
+ // Create empty buffer for instruction data (placeholder)
111
+ const instructionData = new Uint8Array(0);
112
+ return solanaSDK.withdraw(instructionData, nullifierHash, amount, mode);
113
+ }
114
+ throw new Error(`Unsupported chain type: ${chainType}`);
115
+ }, [evmSDK, solanaSDK]);
116
+ // Stake function
117
+ const stake = (0, react_1.useCallback)(async (chainType, amount) => {
118
+ if (chainType === types_1.ChainType.EVM) {
119
+ if (!evmSDK) {
120
+ throw new Error("EVM SDK not initialized");
121
+ }
122
+ return evmSDK.stakeEther(amount);
123
+ }
124
+ else if (chainType === types_1.ChainType.SOLANA) {
125
+ if (!solanaSDK) {
126
+ throw new Error("Solana SDK not initialized");
127
+ }
128
+ return solanaSDK.stakeSol(amount);
129
+ }
130
+ throw new Error(`Unsupported chain type: ${chainType}`);
131
+ }, [evmSDK, solanaSDK]);
132
+ // Unstake function
133
+ const unstake = (0, react_1.useCallback)(async (chainType) => {
134
+ if (chainType === types_1.ChainType.EVM) {
135
+ if (!evmSDK) {
136
+ throw new Error("EVM SDK not initialized");
137
+ }
138
+ return evmSDK.unstakeEth();
139
+ }
140
+ else if (chainType === types_1.ChainType.SOLANA) {
141
+ if (!solanaSDK) {
142
+ throw new Error("Solana SDK not initialized");
143
+ }
144
+ return solanaSDK.unstakeSol();
145
+ }
146
+ throw new Error(`Unsupported chain type: ${chainType}`);
147
+ }, [evmSDK, solanaSDK]);
148
+ // Claim function
149
+ const claim = (0, react_1.useCallback)(async (chainType, seasonId) => {
150
+ if (chainType === types_1.ChainType.EVM) {
151
+ if (!evmSDK) {
152
+ throw new Error("EVM SDK not initialized");
153
+ }
154
+ return evmSDK.claimEth(seasonId);
155
+ }
156
+ else if (chainType === types_1.ChainType.SOLANA) {
157
+ if (!solanaSDK) {
158
+ throw new Error("Solana SDK not initialized");
159
+ }
160
+ return solanaSDK.claimSol(seasonId);
161
+ }
162
+ throw new Error(`Unsupported chain type: ${chainType}`);
163
+ }, [evmSDK, solanaSDK]);
164
+ // Get current season
165
+ const getCurrentSeason = (0, react_1.useCallback)(async (chainType) => {
166
+ if (chainType === types_1.ChainType.EVM) {
167
+ if (!evmSDK)
168
+ return null;
169
+ return evmSDK.getCurrentStakeSeason();
170
+ }
171
+ else if (chainType === types_1.ChainType.SOLANA) {
172
+ if (!solanaSDK)
173
+ return null;
174
+ return solanaSDK.getCurrentStakeSeason();
175
+ }
176
+ return null;
177
+ }, [evmSDK, solanaSDK]);
178
+ // Get mixer
179
+ const getMixer = (0, react_1.useCallback)(async (chainType, mode, amount) => {
180
+ if (chainType === types_1.ChainType.EVM) {
181
+ if (!evmSDK)
182
+ return null;
183
+ return evmSDK.getMixer(mode, amount);
184
+ }
185
+ else if (chainType === types_1.ChainType.SOLANA) {
186
+ if (!solanaSDK)
187
+ return null;
188
+ const mixer = await solanaSDK.getMixer(mode, amount);
189
+ return mixer.toString();
190
+ }
191
+ return null;
192
+ }, [evmSDK, solanaSDK]);
193
+ // Check if mixer exists
194
+ const mixerExists = (0, react_1.useCallback)(async (chainType, mode, amount) => {
195
+ if (chainType === types_1.ChainType.EVM) {
196
+ if (!evmSDK)
197
+ return false;
198
+ return evmSDK.mixerExists(mode, amount);
199
+ }
200
+ else if (chainType === types_1.ChainType.SOLANA) {
201
+ if (!solanaSDK)
202
+ return false;
203
+ return solanaSDK.mixerExists(mode, amount);
204
+ }
205
+ return false;
206
+ }, [evmSDK, solanaSDK]);
207
+ // Calculate deposit amount
208
+ const calculateDepositAmount = (0, react_1.useCallback)(async (chainType, amount) => {
209
+ if (chainType === types_1.ChainType.EVM) {
210
+ if (!evmSDK)
211
+ return null;
212
+ return evmSDK.calculateDepositAmount(amount);
213
+ }
214
+ else if (chainType === types_1.ChainType.SOLANA) {
215
+ // Solana doesn't have fee calculation in the same way
216
+ // Return amount as-is or implement fee calculation if needed
217
+ return amount;
218
+ }
219
+ return null;
220
+ }, [evmSDK, solanaSDK]);
221
+ return {
222
+ deposit,
223
+ withdraw,
224
+ stake,
225
+ unstake,
226
+ claim,
227
+ getCurrentSeason,
228
+ getMixer,
229
+ mixerExists,
230
+ calculateDepositAmount,
231
+ isEVMReady,
232
+ isSolanaReady,
233
+ evmAddress: evmAddress,
234
+ solanaAddress,
235
+ evmSDK,
236
+ solanaSDK,
237
+ };
238
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Hook for claiming rewards (EVM or Solana)
3
+ * Use this hook when you only need claim functionality
4
+ */
5
+ import { ChainType, EVMHookConfig, SolanaHookConfig } from "../types";
6
+ import { Wallet } from "@coral-xyz/anchor";
7
+ import { Connection } from "@solana/web3.js";
8
+ import { TransactionResult } from "../types";
9
+ /**
10
+ * Hook configuration for claiming
11
+ */
12
+ export interface ClaimHookConfig {
13
+ evm?: EVMHookConfig;
14
+ solana?: SolanaHookConfig;
15
+ solanaWallet?: Wallet;
16
+ solanaConnection?: Connection;
17
+ }
18
+ /**
19
+ * Claim hook return type
20
+ */
21
+ export interface UseClaimReturn {
22
+ claim: (chainType: ChainType, seasonId: bigint) => Promise<TransactionResult>;
23
+ getCurrentSeason: (chainType: ChainType) => Promise<bigint | null>;
24
+ isEVMReady: boolean;
25
+ isSolanaReady: boolean;
26
+ }
27
+ /**
28
+ * Hook for claiming rewards
29
+ * Only initializes what's needed for claiming
30
+ */
31
+ export declare function useClaim(config: ClaimHookConfig): UseClaimReturn;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ /**
3
+ * Hook for claiming rewards (EVM or Solana)
4
+ * Use this hook when you only need claim functionality
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.useClaim = useClaim;
8
+ const react_1 = require("react");
9
+ const types_1 = require("../types");
10
+ const evm_1 = require("../evm");
11
+ const solana_1 = require("../solana");
12
+ const wagmi_1 = require("wagmi");
13
+ const utils_1 = require("./utils");
14
+ /**
15
+ * Hook for claiming rewards
16
+ * Only initializes what's needed for claiming
17
+ */
18
+ function useClaim(config) {
19
+ // EVM setup
20
+ const { isConnected: evmConnected } = (0, wagmi_1.useAccount)();
21
+ const { data: walletClient } = (0, wagmi_1.useWalletClient)();
22
+ const publicClient = (0, wagmi_1.usePublicClient)();
23
+ const evmSDK = (0, react_1.useMemo)(() => {
24
+ if (!config.evm?.factoryAddress) {
25
+ return null;
26
+ }
27
+ if (!publicClient) {
28
+ return null;
29
+ }
30
+ try {
31
+ const provider = (0, utils_1.createEthersProviderFromViem)(publicClient);
32
+ const signerOrProvider = walletClient
33
+ ? (0, utils_1.createEthersSignerFromViem)(walletClient, publicClient)
34
+ : provider;
35
+ return new evm_1.AintiVirusEVM(config.evm.factoryAddress, config.evm.tokenAddress || "0x0000000000000000000000000000000000000000", signerOrProvider);
36
+ }
37
+ catch (error) {
38
+ console.error("Failed to initialize AintiVirusEVM:", error);
39
+ return null;
40
+ }
41
+ }, [
42
+ config.evm?.factoryAddress,
43
+ config.evm?.tokenAddress,
44
+ walletClient,
45
+ publicClient,
46
+ ]);
47
+ const isEVMReady = !!evmSDK && evmConnected;
48
+ // Solana setup
49
+ const solanaSDK = (0, react_1.useMemo)(() => {
50
+ if (!config.solana?.factoryProgramId ||
51
+ !config.solana?.mixerProgramId ||
52
+ !config.solana?.stakingProgramId) {
53
+ return null;
54
+ }
55
+ if (!config.solanaWallet || !config.solanaConnection) {
56
+ return null;
57
+ }
58
+ try {
59
+ return new solana_1.AintiVirusSolana(config.solana.factoryProgramId, config.solana.mixerProgramId, config.solana.stakingProgramId, config.solanaWallet, config.solanaConnection, config.solana.tokenMint);
60
+ }
61
+ catch (error) {
62
+ console.error("Failed to initialize AintiVirusSolana:", error);
63
+ return null;
64
+ }
65
+ }, [
66
+ config.solana?.factoryProgramId,
67
+ config.solana?.mixerProgramId,
68
+ config.solana?.stakingProgramId,
69
+ config.solana?.tokenMint,
70
+ config.solanaWallet,
71
+ config.solanaConnection,
72
+ ]);
73
+ const isSolanaReady = !!solanaSDK && !!config.solanaWallet?.publicKey;
74
+ // Claim function
75
+ const claim = (0, react_1.useCallback)(async (chainType, seasonId) => {
76
+ if (chainType === types_1.ChainType.EVM) {
77
+ if (!evmSDK) {
78
+ throw new Error("EVM SDK not initialized");
79
+ }
80
+ return evmSDK.claimEth(seasonId);
81
+ }
82
+ else if (chainType === types_1.ChainType.SOLANA) {
83
+ if (!solanaSDK) {
84
+ throw new Error("Solana SDK not initialized");
85
+ }
86
+ return solanaSDK.claimSol(seasonId);
87
+ }
88
+ throw new Error(`Unsupported chain type: ${chainType}`);
89
+ }, [evmSDK, solanaSDK]);
90
+ // Get current season
91
+ const getCurrentSeason = (0, react_1.useCallback)(async (chainType) => {
92
+ if (chainType === types_1.ChainType.EVM) {
93
+ if (!evmSDK)
94
+ return null;
95
+ return evmSDK.getCurrentStakeSeason();
96
+ }
97
+ else if (chainType === types_1.ChainType.SOLANA) {
98
+ if (!solanaSDK)
99
+ return null;
100
+ return solanaSDK.getCurrentStakeSeason();
101
+ }
102
+ return null;
103
+ }, [evmSDK, solanaSDK]);
104
+ return {
105
+ claim,
106
+ getCurrentSeason,
107
+ isEVMReady,
108
+ isSolanaReady,
109
+ };
110
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Hook for deploying mixers (EVM or Solana)
3
+ * Use this hook when you need to deploy new mixer instances
4
+ */
5
+ import { ChainType, EVMHookConfig, SolanaHookConfig, AssetMode } from "../types";
6
+ import { Wallet } from "@coral-xyz/anchor";
7
+ import { Connection } from "@solana/web3.js";
8
+ import { TransactionResult } from "../types";
9
+ /**
10
+ * Hook configuration for deploy
11
+ */
12
+ export interface DeployHookConfig {
13
+ evm?: EVMHookConfig;
14
+ solana?: SolanaHookConfig;
15
+ solanaWallet?: Wallet;
16
+ solanaConnection?: Connection;
17
+ }
18
+ /**
19
+ * Deploy hook return type
20
+ */
21
+ export interface UseDeployReturn {
22
+ deployMixer: (chainType: ChainType, mode: AssetMode, amount: bigint) => Promise<TransactionResult & {
23
+ mixerAddress?: string;
24
+ }>;
25
+ isEVMReady: boolean;
26
+ isSolanaReady: boolean;
27
+ }
28
+ /**
29
+ * Hook for deploying mixers
30
+ * Only initializes what's needed for deployment
31
+ */
32
+ export declare function useDeploy(config: DeployHookConfig): UseDeployReturn;