@zama-fhe/react-sdk 1.0.0-alpha.10

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/dist/index.js ADDED
@@ -0,0 +1,1151 @@
1
+ "use client";
2
+ import { ZamaSDK, ReadonlyToken, DecryptionFailedError, sortByBlockNumber, parseActivityFeed, extractEncryptedHandles, applyDecryptedValues, totalSupplyContract, getWrapFeeContract, getUnwrapFeeContract, getBatchTransferFeeContract, getFeeRecipientContract } from '@zama-fhe/sdk';
3
+ export { ApprovalFailedError, BATCH_SWAP_ABI, ChromeSessionStorage, CredentialExpiredError, CredentialsManager, DEPLOYMENT_COORDINATOR_ABI, DecryptionFailedError, ENCRYPTION_ABI, ERC165_ABI, ERC20_ABI, ERC20_METADATA_ABI, ERC7984_INTERFACE_ID, ERC7984_WRAPPER_INTERFACE_ID, EncryptionFailedError, FEE_MANAGER_ABI, HardhatConfig, IndexedDBStorage, InvalidCredentialsError, MainnetConfig, MemoryStorage, NoCiphertextError, ReadonlyToken, RelayerRequestFailedError, RelayerWeb, SepoliaConfig, SigningFailedError, SigningRejectedError, TOKEN_TOPICS, TRANSFER_BATCHER_ABI, Token, Topics, TransactionRevertedError, WRAPPER_ABI, ZERO_HANDLE, ZamaError, ZamaErrorCode, ZamaSDK, ZamaSDKEvents, allowanceContract, applyDecryptedValues, approveContract, balanceOfContract, chromeSessionStorage, clearPendingUnshield, confidentialBalanceOfContract, confidentialBatchTransferContract, confidentialTotalSupplyContract, confidentialTransferContract, confidentialTransferFromContract, decimalsContract, decodeConfidentialTransfer, decodeOnChainEvent, decodeOnChainEvents, decodeUnwrapRequested, decodeUnwrappedFinalized, decodeUnwrappedStarted, decodeWrapped, deploymentCoordinatorContract, extractEncryptedHandles, finalizeUnwrapContract, findUnwrapRequested, findWrapped, getBatchTransferFeeContract, getFeeRecipientContract, getUnwrapFeeContract, getWrapFeeContract, getWrapperContract, indexedDBStorage, isConfidentialTokenContract, isConfidentialWrapperContract, isFinalizeUnwrapOperatorContract, isOperatorContract, loadPendingUnshield, matchZamaError, nameContract, parseActivityFeed, rateContract, savePendingUnshield, setFinalizeUnwrapOperatorContract, setOperatorContract, sortByBlockNumber, supportsInterfaceContract, symbolContract, totalSupplyContract, underlyingContract, unwrapContract, unwrapFromBalanceContract, wrapContract, wrapETHContract, wrapperExistsContract } from '@zama-fhe/sdk';
4
+ import { createContext, useRef, useEffect, useMemo, useContext } from 'react';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import { useMutation, useQueryClient, useQuery, useQueries, skipToken, useSuspenseQuery } from '@tanstack/react-query';
7
+
8
+ // src/provider.tsx
9
+ var NO_PROVIDER = /* @__PURE__ */ Symbol("no-provider");
10
+ var ZamaSDKContext = createContext(NO_PROVIDER);
11
+ function ZamaProvider({
12
+ children,
13
+ relayer,
14
+ signer,
15
+ storage,
16
+ sessionStorage,
17
+ credentialDurationDays,
18
+ onEvent
19
+ }) {
20
+ const onEventRef = useRef(onEvent);
21
+ useEffect(() => {
22
+ onEventRef.current = onEvent;
23
+ });
24
+ const sdk = useMemo(
25
+ () => signer ? new ZamaSDK({
26
+ relayer,
27
+ signer,
28
+ storage,
29
+ sessionStorage,
30
+ credentialDurationDays,
31
+ onEvent: onEventRef.current
32
+ }) : null,
33
+ [relayer, signer, storage, sessionStorage, credentialDurationDays]
34
+ );
35
+ useEffect(() => () => sdk?.dispose(), [sdk]);
36
+ return /* @__PURE__ */ jsx(ZamaSDKContext.Provider, { value: sdk, children });
37
+ }
38
+ function useZamaSDK() {
39
+ const context = useContext(ZamaSDKContext);
40
+ if (context === NO_PROVIDER) {
41
+ throw new Error(
42
+ "useZamaSDK must be used within a <ZamaProvider>. Wrap your component tree in <ZamaProvider relayer={\u2026} signer={\u2026} storage={\u2026}>."
43
+ );
44
+ }
45
+ if (!context) {
46
+ throw new Error(
47
+ "useZamaSDK requires a connected signer. Either pass a `signer` prop to <ZamaProvider> or use useReadonlyZamaSDK() for read-only mode."
48
+ );
49
+ }
50
+ return context;
51
+ }
52
+ function useReadonlyZamaSDK() {
53
+ const context = useContext(ZamaSDKContext);
54
+ return context === NO_PROVIDER ? null : context;
55
+ }
56
+ function encryptMutationOptions(sdk) {
57
+ return {
58
+ mutationKey: ["encrypt"],
59
+ mutationFn: (params) => sdk.relayer.encrypt(params)
60
+ };
61
+ }
62
+ function useEncrypt() {
63
+ const sdk = useZamaSDK();
64
+ return useMutation(encryptMutationOptions(sdk));
65
+ }
66
+
67
+ // src/relayer/decryption-cache.ts
68
+ var decryptionKeys = {
69
+ value: (handle) => ["decryptedValue", handle]
70
+ };
71
+
72
+ // src/relayer/use-user-decrypt.ts
73
+ function useUserDecrypt() {
74
+ const sdk = useZamaSDK();
75
+ const queryClient = useQueryClient();
76
+ return useMutation({
77
+ mutationFn: (params) => sdk.relayer.userDecrypt(params),
78
+ onSuccess: (data) => {
79
+ for (const [handle, value] of Object.entries(data)) {
80
+ queryClient.setQueryData(decryptionKeys.value(handle), value);
81
+ }
82
+ }
83
+ });
84
+ }
85
+ function usePublicDecrypt() {
86
+ const sdk = useZamaSDK();
87
+ const queryClient = useQueryClient();
88
+ return useMutation({
89
+ mutationFn: (handles) => sdk.relayer.publicDecrypt(handles),
90
+ onSuccess: (data) => {
91
+ for (const [handle, value] of Object.entries(data.clearValues)) {
92
+ queryClient.setQueryData(decryptionKeys.value(handle), value);
93
+ }
94
+ }
95
+ });
96
+ }
97
+ function useGenerateKeypair() {
98
+ const sdk = useZamaSDK();
99
+ return useMutation({
100
+ mutationFn: () => sdk.relayer.generateKeypair()
101
+ });
102
+ }
103
+ function useCreateEIP712() {
104
+ const sdk = useZamaSDK();
105
+ return useMutation({
106
+ mutationFn: ({ publicKey, contractAddresses, startTimestamp, durationDays }) => sdk.relayer.createEIP712(publicKey, contractAddresses, startTimestamp, durationDays)
107
+ });
108
+ }
109
+ function useCreateDelegatedUserDecryptEIP712() {
110
+ const sdk = useZamaSDK();
111
+ return useMutation({
112
+ mutationFn: ({
113
+ publicKey,
114
+ contractAddresses,
115
+ delegatorAddress,
116
+ startTimestamp,
117
+ durationDays
118
+ }) => sdk.relayer.createDelegatedUserDecryptEIP712(
119
+ publicKey,
120
+ contractAddresses,
121
+ delegatorAddress,
122
+ startTimestamp,
123
+ durationDays
124
+ )
125
+ });
126
+ }
127
+ function useDelegatedUserDecrypt() {
128
+ const sdk = useZamaSDK();
129
+ return useMutation({
130
+ mutationFn: (params) => sdk.relayer.delegatedUserDecrypt(params)
131
+ });
132
+ }
133
+ function useRequestZKProofVerification() {
134
+ const sdk = useZamaSDK();
135
+ return useMutation({
136
+ mutationFn: (zkProof) => sdk.relayer.requestZKProofVerification(zkProof)
137
+ });
138
+ }
139
+ var publicKeyQueryKeys = {
140
+ /** Match the public key query. */
141
+ all: ["publicKey"]
142
+ };
143
+ function publicKeyQueryOptions(sdk) {
144
+ return {
145
+ queryKey: publicKeyQueryKeys.all,
146
+ queryFn: () => sdk.relayer.getPublicKey(),
147
+ staleTime: Infinity
148
+ };
149
+ }
150
+ function usePublicKey() {
151
+ const sdk = useZamaSDK();
152
+ return useQuery(publicKeyQueryOptions(sdk));
153
+ }
154
+ var publicParamsQueryKeys = {
155
+ /** Match all public params queries. */
156
+ all: ["publicParams"],
157
+ /** Match public params query for a specific bit size. */
158
+ bits: (bits) => ["publicParams", bits]
159
+ };
160
+ function publicParamsQueryOptions(sdk, bits) {
161
+ return {
162
+ queryKey: publicParamsQueryKeys.bits(bits),
163
+ queryFn: () => sdk.relayer.getPublicParams(bits),
164
+ staleTime: Infinity
165
+ };
166
+ }
167
+ function usePublicParams(bits) {
168
+ const sdk = useZamaSDK();
169
+ return useQuery(publicParamsQueryOptions(sdk, bits));
170
+ }
171
+ function useUserDecryptFlow(config) {
172
+ const sdk = useZamaSDK();
173
+ const queryClient = useQueryClient();
174
+ const callbacks = config?.callbacks;
175
+ return useMutation({
176
+ mutationKey: ["userDecryptFlow"],
177
+ mutationFn: async ({ handles, durationDays = 1 }) => {
178
+ const keypair = await sdk.relayer.generateKeypair();
179
+ callbacks?.onKeypairGenerated?.();
180
+ const contractAddresses = [...new Set(handles.map((h) => h.contractAddress))];
181
+ const startTimestamp = Math.floor(Date.now() / 1e3);
182
+ const eip712 = await sdk.relayer.createEIP712(
183
+ keypair.publicKey,
184
+ contractAddresses,
185
+ startTimestamp,
186
+ durationDays
187
+ );
188
+ callbacks?.onEIP712Created?.();
189
+ const signature = await sdk.signer.signTypedData(eip712);
190
+ callbacks?.onSigned?.(signature);
191
+ const signerAddress = await sdk.signer.getAddress();
192
+ const allResults = {};
193
+ const handlesByContract = /* @__PURE__ */ new Map();
194
+ for (const h of handles) {
195
+ const list = handlesByContract.get(h.contractAddress) ?? [];
196
+ list.push(h.handle);
197
+ handlesByContract.set(h.contractAddress, list);
198
+ }
199
+ for (const [contractAddress, contractHandles] of handlesByContract) {
200
+ const result = await sdk.relayer.userDecrypt({
201
+ handles: contractHandles,
202
+ contractAddress,
203
+ signedContractAddresses: contractAddresses,
204
+ privateKey: keypair.privateKey,
205
+ publicKey: keypair.publicKey,
206
+ signature,
207
+ signerAddress,
208
+ startTimestamp,
209
+ durationDays
210
+ });
211
+ Object.assign(allResults, result);
212
+ }
213
+ callbacks?.onDecrypted?.(allResults);
214
+ return allResults;
215
+ },
216
+ onSuccess: (data) => {
217
+ for (const [handle, value] of Object.entries(data)) {
218
+ queryClient.setQueryData(decryptionKeys.value(handle), value);
219
+ }
220
+ }
221
+ });
222
+ }
223
+ function useUserDecryptedValue(handle) {
224
+ return useQuery({
225
+ queryKey: decryptionKeys.value(handle ?? ""),
226
+ queryFn: () => void 0,
227
+ enabled: false
228
+ });
229
+ }
230
+ function useUserDecryptedValues(handles) {
231
+ const results = useQueries({
232
+ queries: handles.map((handle) => ({
233
+ queryKey: decryptionKeys.value(handle),
234
+ queryFn: () => void 0,
235
+ enabled: false
236
+ }))
237
+ });
238
+ const data = {};
239
+ for (let i = 0; i < handles.length; i++) {
240
+ data[handles[i]] = results[i].data;
241
+ }
242
+ return {
243
+ data,
244
+ results
245
+ };
246
+ }
247
+ function useToken(config) {
248
+ const sdk = useZamaSDK();
249
+ return useMemo(
250
+ () => sdk.createToken(config.tokenAddress, config.wrapperAddress),
251
+ [sdk, config.tokenAddress, config.wrapperAddress]
252
+ );
253
+ }
254
+ function useReadonlyToken(address) {
255
+ const sdk = useZamaSDK();
256
+ return useMemo(() => sdk.createReadonlyToken(address), [sdk, address]);
257
+ }
258
+
259
+ // src/token/balance-query-keys.ts
260
+ var confidentialBalanceQueryKeys = {
261
+ /** Match all single-token balance queries. */
262
+ all: ["confidentialBalance"],
263
+ /** Match balance queries for a specific token (any owner). */
264
+ token: (tokenAddress) => ["confidentialBalance", tokenAddress],
265
+ /** Match balance query for a specific token + owner. */
266
+ owner: (tokenAddress, owner) => ["confidentialBalance", tokenAddress, owner]
267
+ };
268
+ var confidentialBalancesQueryKeys = {
269
+ /** Match all batch balance queries. */
270
+ all: ["confidentialBalances"],
271
+ /** Match batch balance query for a specific token set + owner. */
272
+ tokens: (tokenAddresses, owner) => ["confidentialBalances", tokenAddresses, owner]
273
+ };
274
+ var confidentialHandleQueryKeys = {
275
+ /** Match all single-token handle queries. */
276
+ all: ["confidentialHandle"],
277
+ /** Match handle queries for a specific token (any owner). */
278
+ token: (tokenAddress) => ["confidentialHandle", tokenAddress],
279
+ /** Match handle query for a specific token + owner. */
280
+ owner: (tokenAddress, owner) => ["confidentialHandle", tokenAddress, owner]
281
+ };
282
+ var confidentialHandlesQueryKeys = {
283
+ /** Match all batch handle queries. */
284
+ all: ["confidentialHandles"],
285
+ /** Match batch handle query for a specific token set + owner. */
286
+ tokens: (tokenAddresses, owner) => ["confidentialHandles", tokenAddresses, owner]
287
+ };
288
+ var wagmiBalancePredicates = {
289
+ /** Match all wagmi balance queries. */
290
+ balanceOf: (query) => Array.isArray(query.queryKey) && query.queryKey.some(
291
+ (key) => typeof key === "object" && key !== null && "functionName" in key && key.functionName === "balanceOf"
292
+ )};
293
+
294
+ // src/token/use-confidential-balance.ts
295
+ var DEFAULT_HANDLE_REFETCH_INTERVAL = 1e4;
296
+ function useConfidentialBalance(config, options) {
297
+ const { tokenAddress, handleRefetchInterval } = config;
298
+ const token = useReadonlyToken(tokenAddress);
299
+ const addressQuery = useQuery({
300
+ queryKey: ["zama", "signer-address", tokenAddress],
301
+ queryFn: () => token.signer.getAddress()
302
+ });
303
+ const signerAddress = addressQuery.data;
304
+ const ownerKey = signerAddress ?? "";
305
+ const handleQuery = useQuery({
306
+ queryKey: confidentialHandleQueryKeys.owner(tokenAddress, ownerKey),
307
+ queryFn: () => token.confidentialBalanceOf(),
308
+ enabled: !!signerAddress,
309
+ refetchInterval: handleRefetchInterval ?? DEFAULT_HANDLE_REFETCH_INTERVAL
310
+ });
311
+ const handle = handleQuery.data;
312
+ const balanceQuery = useQuery({
313
+ queryKey: [...confidentialBalanceQueryKeys.owner(tokenAddress, ownerKey), handle ?? ""],
314
+ queryFn: () => token.decryptBalance(handle),
315
+ enabled: !!signerAddress && !!handle,
316
+ staleTime: Infinity,
317
+ ...options
318
+ });
319
+ return { ...balanceQuery, handleQuery };
320
+ }
321
+ var DEFAULT_HANDLE_REFETCH_INTERVAL2 = 1e4;
322
+ function useConfidentialBalances(config, options) {
323
+ const { tokenAddresses, handleRefetchInterval, maxConcurrency } = config;
324
+ const sdk = useZamaSDK();
325
+ const addressQuery = useQuery({
326
+ queryKey: ["zama", "signer-address"],
327
+ queryFn: () => sdk.signer.getAddress()
328
+ });
329
+ const signerAddress = addressQuery.data;
330
+ const ownerKey = signerAddress ?? "";
331
+ const tokens = useMemo(
332
+ () => tokenAddresses.map((addr) => sdk.createReadonlyToken(addr)),
333
+ [sdk, tokenAddresses]
334
+ );
335
+ const handlesQuery = useQuery({
336
+ queryKey: confidentialHandlesQueryKeys.tokens(tokenAddresses, ownerKey),
337
+ queryFn: () => Promise.all(tokens.map((t) => t.confidentialBalanceOf())),
338
+ enabled: tokenAddresses.length > 0 && !!signerAddress,
339
+ refetchInterval: handleRefetchInterval ?? DEFAULT_HANDLE_REFETCH_INTERVAL2
340
+ });
341
+ const handles = handlesQuery.data;
342
+ const handlesKey = handles?.join(",") ?? "";
343
+ const balancesQuery = useQuery({
344
+ queryKey: [...confidentialBalancesQueryKeys.tokens(tokenAddresses, ownerKey), handlesKey],
345
+ queryFn: async () => {
346
+ const perTokenErrors = /* @__PURE__ */ new Map();
347
+ const raw = await ReadonlyToken.batchDecryptBalances(tokens, {
348
+ handles,
349
+ maxConcurrency,
350
+ onError: (error, address) => {
351
+ perTokenErrors.set(address, error);
352
+ return 0n;
353
+ }
354
+ });
355
+ const balances = /* @__PURE__ */ new Map();
356
+ const errors = /* @__PURE__ */ new Map();
357
+ for (let i = 0; i < tokens.length; i++) {
358
+ const tokenAddr = tokens[i].address;
359
+ const originalAddr = tokenAddresses[i];
360
+ const tokenError = perTokenErrors.get(tokenAddr);
361
+ if (tokenError) {
362
+ errors.set(originalAddr, tokenError);
363
+ } else {
364
+ const balance = raw.get(tokenAddr);
365
+ if (balance !== void 0) balances.set(originalAddr, balance);
366
+ }
367
+ }
368
+ if (errors.size === tokens.length && tokens.length > 0) {
369
+ throw errors.values().next().value ?? new DecryptionFailedError("All token balance decryptions failed");
370
+ }
371
+ return {
372
+ balances,
373
+ errors,
374
+ isPartialError: errors.size > 0
375
+ };
376
+ },
377
+ enabled: tokenAddresses.length > 0 && !!signerAddress && !!handles,
378
+ staleTime: Infinity,
379
+ ...options
380
+ });
381
+ return { ...balancesQuery, handlesQuery };
382
+ }
383
+ var isAllowedQueryKeys = {
384
+ all: ["zama", "isAllowed"]
385
+ };
386
+ function isAllowedQueryOptions(sdk) {
387
+ return {
388
+ queryKey: isAllowedQueryKeys.all,
389
+ queryFn: () => sdk.isAllowed()
390
+ };
391
+ }
392
+ function useIsAllowed() {
393
+ const sdk = useZamaSDK();
394
+ return useQuery(isAllowedQueryOptions(sdk));
395
+ }
396
+
397
+ // src/token/use-allow.ts
398
+ function allowMutationOptions(sdk) {
399
+ return {
400
+ mutationKey: ["allow"],
401
+ mutationFn: async (tokenAddresses) => {
402
+ await sdk.allow(...tokenAddresses);
403
+ }
404
+ };
405
+ }
406
+ function useAllow() {
407
+ const sdk = useZamaSDK();
408
+ const queryClient = useQueryClient();
409
+ return useMutation({
410
+ ...allowMutationOptions(sdk),
411
+ onSuccess: () => {
412
+ queryClient.invalidateQueries({ queryKey: isAllowedQueryKeys.all });
413
+ }
414
+ });
415
+ }
416
+ function revokeMutationOptions(sdk) {
417
+ return {
418
+ mutationKey: ["revoke"],
419
+ mutationFn: async (tokenAddresses) => {
420
+ await sdk.revoke(...tokenAddresses);
421
+ }
422
+ };
423
+ }
424
+ function useRevoke() {
425
+ const sdk = useZamaSDK();
426
+ const queryClient = useQueryClient();
427
+ return useMutation({
428
+ ...revokeMutationOptions(sdk),
429
+ onSuccess: () => {
430
+ queryClient.invalidateQueries({ queryKey: isAllowedQueryKeys.all });
431
+ }
432
+ });
433
+ }
434
+ function revokeSessionMutationOptions(sdk) {
435
+ return {
436
+ mutationKey: ["revokeSession"],
437
+ mutationFn: async () => {
438
+ await sdk.revokeSession();
439
+ }
440
+ };
441
+ }
442
+ function useRevokeSession() {
443
+ const sdk = useZamaSDK();
444
+ const queryClient = useQueryClient();
445
+ return useMutation({
446
+ ...revokeSessionMutationOptions(sdk),
447
+ onSuccess: () => {
448
+ queryClient.invalidateQueries({ queryKey: isAllowedQueryKeys.all });
449
+ }
450
+ });
451
+ }
452
+ function confidentialTransferMutationOptions(token) {
453
+ return {
454
+ mutationKey: ["confidentialTransfer", token.address],
455
+ mutationFn: ({ to, amount, callbacks }) => token.confidentialTransfer(to, amount, callbacks)
456
+ };
457
+ }
458
+ function useConfidentialTransfer(config, options) {
459
+ const token = useToken(config);
460
+ const queryClient = useQueryClient();
461
+ return useMutation({
462
+ mutationKey: ["confidentialTransfer", config.tokenAddress],
463
+ mutationFn: ({ to, amount, callbacks }) => token.confidentialTransfer(to, amount, callbacks),
464
+ ...options,
465
+ onMutate: config.optimistic ? async (variables, mutationContext) => {
466
+ const balanceKey = confidentialBalanceQueryKeys.token(config.tokenAddress);
467
+ await queryClient.cancelQueries({ queryKey: balanceKey });
468
+ const previous = queryClient.getQueriesData({ queryKey: balanceKey });
469
+ for (const [key, value] of previous) {
470
+ if (value !== void 0) {
471
+ queryClient.setQueryData(key, value - variables.amount);
472
+ }
473
+ }
474
+ return options?.onMutate?.(variables, mutationContext) ?? config.tokenAddress;
475
+ } : options?.onMutate,
476
+ onError: (error, variables, onMutateResult, context) => {
477
+ if (config.optimistic) {
478
+ queryClient.invalidateQueries({
479
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
480
+ });
481
+ }
482
+ options?.onError?.(error, variables, onMutateResult, context);
483
+ },
484
+ onSuccess: (data, variables, onMutateResult, context) => {
485
+ context.client.invalidateQueries({
486
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
487
+ });
488
+ context.client.invalidateQueries({
489
+ queryKey: confidentialHandlesQueryKeys.all
490
+ });
491
+ context.client.resetQueries({
492
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
493
+ });
494
+ context.client.invalidateQueries({
495
+ queryKey: confidentialBalancesQueryKeys.all
496
+ });
497
+ options?.onSuccess?.(data, variables, onMutateResult, context);
498
+ }
499
+ });
500
+ }
501
+ function confidentialTransferFromMutationOptions(token) {
502
+ return {
503
+ mutationKey: ["confidentialTransferFrom", token.address],
504
+ mutationFn: ({ from, to, amount, callbacks }) => token.confidentialTransferFrom(from, to, amount, callbacks)
505
+ };
506
+ }
507
+ function useConfidentialTransferFrom(config, options) {
508
+ const token = useToken(config);
509
+ return useMutation({
510
+ mutationKey: ["confidentialTransferFrom", config.tokenAddress],
511
+ mutationFn: ({ from, to, amount, callbacks }) => token.confidentialTransferFrom(from, to, amount, callbacks),
512
+ ...options,
513
+ onSuccess: (data, variables, onMutateResult, context) => {
514
+ context.client.invalidateQueries({
515
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
516
+ });
517
+ context.client.invalidateQueries({
518
+ queryKey: confidentialHandlesQueryKeys.all
519
+ });
520
+ context.client.resetQueries({
521
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
522
+ });
523
+ context.client.invalidateQueries({
524
+ queryKey: confidentialBalancesQueryKeys.all
525
+ });
526
+ options?.onSuccess?.(data, variables, onMutateResult, context);
527
+ }
528
+ });
529
+ }
530
+ var confidentialIsApprovedQueryKeys = {
531
+ /** Match all approval queries. */
532
+ all: ["confidentialIsApproved"],
533
+ /** Match approval queries for a specific token. */
534
+ token: (tokenAddress) => ["confidentialIsApproved", tokenAddress],
535
+ /** Match approval queries for a specific token + spender pair. */
536
+ spender: (tokenAddress, spender, holder) => ["confidentialIsApproved", tokenAddress, spender, holder ?? ""]
537
+ };
538
+ function confidentialIsApprovedQueryOptions(token, spender, holder) {
539
+ return {
540
+ queryKey: confidentialIsApprovedQueryKeys.spender(token.address, spender, holder),
541
+ queryFn: () => token.isApproved(spender, holder),
542
+ staleTime: 3e4
543
+ };
544
+ }
545
+ function useConfidentialIsApproved(config, options) {
546
+ const { spender, holder, ...tokenConfig } = config;
547
+ const token = useToken(tokenConfig);
548
+ return useQuery({
549
+ ...spender ? confidentialIsApprovedQueryOptions(token, spender, holder) : {
550
+ queryKey: confidentialIsApprovedQueryKeys.spender(config.tokenAddress, "", holder),
551
+ queryFn: skipToken
552
+ },
553
+ ...options
554
+ });
555
+ }
556
+ function useConfidentialIsApprovedSuspense(config) {
557
+ const { spender, holder, ...tokenConfig } = config;
558
+ const token = useToken(tokenConfig);
559
+ return useSuspenseQuery(
560
+ confidentialIsApprovedQueryOptions(token, spender, holder)
561
+ );
562
+ }
563
+
564
+ // src/token/use-confidential-approve.ts
565
+ function confidentialApproveMutationOptions(token) {
566
+ return {
567
+ mutationKey: ["confidentialApprove", token.address],
568
+ mutationFn: ({ spender, until }) => token.approve(spender, until)
569
+ };
570
+ }
571
+ function useConfidentialApprove(config, options) {
572
+ const token = useToken(config);
573
+ return useMutation({
574
+ mutationKey: ["confidentialApprove", config.tokenAddress],
575
+ mutationFn: ({ spender, until }) => token.approve(spender, until),
576
+ ...options,
577
+ onSuccess: (data, variables, onMutateResult, context) => {
578
+ context.client.invalidateQueries({
579
+ queryKey: confidentialIsApprovedQueryKeys.token(config.tokenAddress)
580
+ });
581
+ options?.onSuccess?.(data, variables, onMutateResult, context);
582
+ }
583
+ });
584
+ }
585
+ function shieldMutationOptions(token) {
586
+ return {
587
+ mutationKey: ["shield", token.address],
588
+ mutationFn: async ({ amount, fees, approvalStrategy, to, callbacks }) => token.shield(amount, { fees, approvalStrategy, to, callbacks })
589
+ };
590
+ }
591
+ function useShield(config, options) {
592
+ const token = useToken(config);
593
+ const queryClient = useQueryClient();
594
+ return useMutation({
595
+ mutationKey: ["shield", config.tokenAddress],
596
+ mutationFn: async ({ amount, fees, approvalStrategy, to, callbacks }) => token.shield(amount, { fees, approvalStrategy, to, callbacks }),
597
+ ...options,
598
+ onMutate: config.optimistic ? async (variables, mutationContext) => {
599
+ const balanceKey = confidentialBalanceQueryKeys.token(config.tokenAddress);
600
+ await queryClient.cancelQueries({ queryKey: balanceKey });
601
+ const previous = queryClient.getQueriesData({ queryKey: balanceKey });
602
+ for (const [key, value] of previous) {
603
+ if (value !== void 0) {
604
+ queryClient.setQueryData(key, value + variables.amount);
605
+ }
606
+ }
607
+ return options?.onMutate?.(variables, mutationContext) ?? config.tokenAddress;
608
+ } : options?.onMutate,
609
+ onError: (error, variables, onMutateResult, context) => {
610
+ if (config.optimistic) {
611
+ queryClient.invalidateQueries({
612
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
613
+ });
614
+ }
615
+ options?.onError?.(error, variables, onMutateResult, context);
616
+ },
617
+ onSuccess: (data, variables, onMutateResult, context) => {
618
+ context.client.invalidateQueries({
619
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
620
+ });
621
+ context.client.invalidateQueries({
622
+ queryKey: confidentialHandlesQueryKeys.all
623
+ });
624
+ context.client.resetQueries({
625
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
626
+ });
627
+ context.client.invalidateQueries({
628
+ queryKey: confidentialBalancesQueryKeys.all
629
+ });
630
+ context.client.invalidateQueries({
631
+ predicate: wagmiBalancePredicates.balanceOf
632
+ });
633
+ options?.onSuccess?.(data, variables, onMutateResult, context);
634
+ }
635
+ });
636
+ }
637
+ function shieldETHMutationOptions(token) {
638
+ return {
639
+ mutationKey: ["shieldETH", token.address],
640
+ mutationFn: ({ amount, value }) => token.shieldETH(amount, value)
641
+ };
642
+ }
643
+ function useShieldETH(config, options) {
644
+ const token = useToken(config);
645
+ return useMutation({
646
+ mutationKey: ["shieldETH", config.tokenAddress],
647
+ mutationFn: ({ amount, value }) => token.shieldETH(amount, value),
648
+ ...options,
649
+ onSuccess: (data, variables, onMutateResult, context) => {
650
+ context.client.invalidateQueries({
651
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
652
+ });
653
+ context.client.invalidateQueries({
654
+ queryKey: confidentialHandlesQueryKeys.all
655
+ });
656
+ context.client.resetQueries({
657
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
658
+ });
659
+ context.client.invalidateQueries({
660
+ queryKey: confidentialBalancesQueryKeys.all
661
+ });
662
+ options?.onSuccess?.(data, variables, onMutateResult, context);
663
+ }
664
+ });
665
+ }
666
+ function unwrapMutationOptions(token) {
667
+ return {
668
+ mutationKey: ["unwrap", token.address],
669
+ mutationFn: ({ amount }) => token.unwrap(amount)
670
+ };
671
+ }
672
+ function useUnwrap(config, options) {
673
+ const token = useToken(config);
674
+ return useMutation({
675
+ mutationKey: ["unwrap", config.tokenAddress],
676
+ mutationFn: ({ amount }) => token.unwrap(amount),
677
+ ...options,
678
+ onSuccess: (data, variables, onMutateResult, context) => {
679
+ context.client.invalidateQueries({
680
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
681
+ });
682
+ context.client.invalidateQueries({
683
+ queryKey: confidentialHandlesQueryKeys.all
684
+ });
685
+ context.client.resetQueries({
686
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
687
+ });
688
+ context.client.invalidateQueries({
689
+ queryKey: confidentialBalancesQueryKeys.all
690
+ });
691
+ options?.onSuccess?.(data, variables, onMutateResult, context);
692
+ }
693
+ });
694
+ }
695
+ function unwrapAllMutationOptions(token) {
696
+ return {
697
+ mutationKey: ["unwrapAll", token.address],
698
+ mutationFn: () => token.unwrapAll()
699
+ };
700
+ }
701
+ function useUnwrapAll(config, options) {
702
+ const token = useToken(config);
703
+ return useMutation({
704
+ mutationKey: ["unwrapAll", config.tokenAddress],
705
+ mutationFn: () => token.unwrapAll(),
706
+ ...options,
707
+ onSuccess: (data, variables, onMutateResult, context) => {
708
+ context.client.invalidateQueries({
709
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
710
+ });
711
+ context.client.invalidateQueries({
712
+ queryKey: confidentialHandlesQueryKeys.all
713
+ });
714
+ context.client.resetQueries({
715
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
716
+ });
717
+ context.client.invalidateQueries({
718
+ queryKey: confidentialBalancesQueryKeys.all
719
+ });
720
+ options?.onSuccess?.(data, variables, onMutateResult, context);
721
+ }
722
+ });
723
+ }
724
+ var underlyingAllowanceQueryKeys = {
725
+ /** Match all underlying allowance queries. */
726
+ all: ["underlyingAllowance"],
727
+ /** Match allowance query for a specific token + wrapper pair. */
728
+ token: (tokenAddress, wrapper) => ["underlyingAllowance", tokenAddress, wrapper]
729
+ };
730
+ function underlyingAllowanceQueryOptions(token, wrapperAddress) {
731
+ return {
732
+ queryKey: underlyingAllowanceQueryKeys.token(token.address, wrapperAddress),
733
+ queryFn: () => token.allowance(wrapperAddress),
734
+ staleTime: 3e4
735
+ };
736
+ }
737
+ function useUnderlyingAllowance(config, options) {
738
+ const { tokenAddress, wrapperAddress } = config;
739
+ const token = useReadonlyToken(tokenAddress);
740
+ return useQuery({
741
+ ...underlyingAllowanceQueryOptions(token, wrapperAddress),
742
+ ...options
743
+ });
744
+ }
745
+ function useUnderlyingAllowanceSuspense(config) {
746
+ const { tokenAddress, wrapperAddress } = config;
747
+ const token = useReadonlyToken(tokenAddress);
748
+ return useSuspenseQuery(underlyingAllowanceQueryOptions(token, wrapperAddress));
749
+ }
750
+
751
+ // src/token/use-finalize-unwrap.ts
752
+ function finalizeUnwrapMutationOptions(token) {
753
+ return {
754
+ mutationKey: ["finalizeUnwrap", token.address],
755
+ mutationFn: ({ burnAmountHandle }) => token.finalizeUnwrap(burnAmountHandle)
756
+ };
757
+ }
758
+ function useFinalizeUnwrap(config, options) {
759
+ const token = useToken(config);
760
+ return useMutation({
761
+ mutationKey: ["finalizeUnwrap", config.tokenAddress],
762
+ mutationFn: ({ burnAmountHandle }) => token.finalizeUnwrap(burnAmountHandle),
763
+ ...options,
764
+ onSuccess: (data, variables, onMutateResult, context) => {
765
+ context.client.invalidateQueries({
766
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
767
+ });
768
+ context.client.invalidateQueries({
769
+ queryKey: confidentialHandlesQueryKeys.all
770
+ });
771
+ context.client.resetQueries({
772
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
773
+ });
774
+ context.client.invalidateQueries({
775
+ queryKey: confidentialBalancesQueryKeys.all
776
+ });
777
+ context.client.invalidateQueries({
778
+ queryKey: underlyingAllowanceQueryKeys.all
779
+ });
780
+ context.client.invalidateQueries({ predicate: wagmiBalancePredicates.balanceOf });
781
+ options?.onSuccess?.(data, variables, onMutateResult, context);
782
+ }
783
+ });
784
+ }
785
+ function unshieldMutationOptions(token) {
786
+ return {
787
+ mutationKey: ["unshield", token.address],
788
+ mutationFn: ({ amount, callbacks }) => token.unshield(amount, callbacks)
789
+ };
790
+ }
791
+ function useUnshield(config, options) {
792
+ const token = useToken(config);
793
+ return useMutation({
794
+ mutationKey: ["unshield", config.tokenAddress],
795
+ mutationFn: ({ amount, callbacks }) => token.unshield(amount, callbacks),
796
+ ...options,
797
+ onSuccess: (data, variables, onMutateResult, context) => {
798
+ context.client.invalidateQueries({
799
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
800
+ });
801
+ context.client.invalidateQueries({
802
+ queryKey: confidentialHandlesQueryKeys.all
803
+ });
804
+ context.client.resetQueries({
805
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
806
+ });
807
+ context.client.invalidateQueries({
808
+ queryKey: confidentialBalancesQueryKeys.all
809
+ });
810
+ context.client.invalidateQueries({
811
+ queryKey: underlyingAllowanceQueryKeys.all
812
+ });
813
+ context.client.invalidateQueries({
814
+ predicate: wagmiBalancePredicates.balanceOf
815
+ });
816
+ options?.onSuccess?.(data, variables, onMutateResult, context);
817
+ }
818
+ });
819
+ }
820
+ function unshieldAllMutationOptions(token) {
821
+ return {
822
+ mutationKey: ["unshieldAll", token.address],
823
+ mutationFn: (params) => token.unshieldAll(params?.callbacks)
824
+ };
825
+ }
826
+ function useUnshieldAll(config, options) {
827
+ const token = useToken(config);
828
+ return useMutation({
829
+ mutationKey: ["unshieldAll", config.tokenAddress],
830
+ mutationFn: (params) => token.unshieldAll(params?.callbacks),
831
+ ...options,
832
+ onSuccess: (data, variables, onMutateResult, context) => {
833
+ context.client.invalidateQueries({
834
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
835
+ });
836
+ context.client.invalidateQueries({
837
+ queryKey: confidentialHandlesQueryKeys.all
838
+ });
839
+ context.client.resetQueries({
840
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
841
+ });
842
+ context.client.invalidateQueries({
843
+ queryKey: confidentialBalancesQueryKeys.all
844
+ });
845
+ context.client.invalidateQueries({
846
+ queryKey: underlyingAllowanceQueryKeys.all
847
+ });
848
+ context.client.invalidateQueries({
849
+ predicate: wagmiBalancePredicates.balanceOf
850
+ });
851
+ options?.onSuccess?.(data, variables, onMutateResult, context);
852
+ }
853
+ });
854
+ }
855
+ function resumeUnshieldMutationOptions(token) {
856
+ return {
857
+ mutationKey: ["resumeUnshield", token.address],
858
+ mutationFn: ({ unwrapTxHash, callbacks }) => token.resumeUnshield(unwrapTxHash, callbacks)
859
+ };
860
+ }
861
+ function useResumeUnshield(config, options) {
862
+ const token = useToken(config);
863
+ return useMutation({
864
+ mutationKey: ["resumeUnshield", config.tokenAddress],
865
+ mutationFn: ({ unwrapTxHash, callbacks }) => token.resumeUnshield(unwrapTxHash, callbacks),
866
+ ...options,
867
+ onSuccess: (data, variables, onMutateResult, context) => {
868
+ context.client.invalidateQueries({
869
+ queryKey: confidentialHandleQueryKeys.token(config.tokenAddress)
870
+ });
871
+ context.client.invalidateQueries({
872
+ queryKey: confidentialHandlesQueryKeys.all
873
+ });
874
+ context.client.resetQueries({
875
+ queryKey: confidentialBalanceQueryKeys.token(config.tokenAddress)
876
+ });
877
+ context.client.invalidateQueries({
878
+ queryKey: confidentialBalancesQueryKeys.all
879
+ });
880
+ context.client.invalidateQueries({
881
+ queryKey: underlyingAllowanceQueryKeys.all
882
+ });
883
+ context.client.invalidateQueries({
884
+ predicate: wagmiBalancePredicates.balanceOf
885
+ });
886
+ options?.onSuccess?.(data, variables, onMutateResult, context);
887
+ }
888
+ });
889
+ }
890
+ var wrapperDiscoveryQueryKeys = {
891
+ /** Match all wrapper discovery queries. */
892
+ all: ["wrapperDiscovery"],
893
+ /** Match wrapper discovery queries for a specific token. */
894
+ token: (tokenAddress) => ["wrapperDiscovery", tokenAddress],
895
+ /** Match wrapper discovery query for a specific token + coordinator pair. */
896
+ tokenCoordinator: (tokenAddress, coordinatorAddress) => ["wrapperDiscovery", tokenAddress, coordinatorAddress]
897
+ };
898
+ function wrapperDiscoveryQueryOptions(token, coordinatorAddress) {
899
+ return {
900
+ queryKey: wrapperDiscoveryQueryKeys.tokenCoordinator(token.address, coordinatorAddress),
901
+ queryFn: () => token.discoverWrapper(coordinatorAddress),
902
+ staleTime: Infinity
903
+ };
904
+ }
905
+ function useWrapperDiscovery(config, options) {
906
+ const { tokenAddress, coordinatorAddress } = config;
907
+ const token = useReadonlyToken(tokenAddress);
908
+ return useQuery({
909
+ ...coordinatorAddress ? wrapperDiscoveryQueryOptions(token, coordinatorAddress) : {
910
+ queryKey: wrapperDiscoveryQueryKeys.tokenCoordinator(tokenAddress, ""),
911
+ queryFn: skipToken
912
+ },
913
+ ...options
914
+ });
915
+ }
916
+ function useWrapperDiscoverySuspense(config) {
917
+ const { tokenAddress, coordinatorAddress } = config;
918
+ const token = useReadonlyToken(tokenAddress);
919
+ return useSuspenseQuery(
920
+ wrapperDiscoveryQueryOptions(token, coordinatorAddress)
921
+ );
922
+ }
923
+ var metadataQueryKeys = {
924
+ /** Match all token metadata queries. */
925
+ all: ["tokenMetadata"],
926
+ /** Match metadata query for a specific token. */
927
+ token: (tokenAddress) => ["tokenMetadata", tokenAddress]
928
+ };
929
+ function metadataQueryOptions(token) {
930
+ return {
931
+ queryKey: metadataQueryKeys.token(token.address),
932
+ queryFn: async () => {
933
+ const [name, symbol, decimals] = await Promise.all([
934
+ token.name(),
935
+ token.symbol(),
936
+ token.decimals()
937
+ ]);
938
+ return { name, symbol, decimals };
939
+ },
940
+ staleTime: Infinity
941
+ };
942
+ }
943
+ function useMetadata(tokenAddress, options) {
944
+ const token = useReadonlyToken(tokenAddress);
945
+ return useQuery({
946
+ ...metadataQueryOptions(token),
947
+ ...options
948
+ });
949
+ }
950
+ function useMetadataSuspense(tokenAddress) {
951
+ const token = useReadonlyToken(tokenAddress);
952
+ return useSuspenseQuery(metadataQueryOptions(token));
953
+ }
954
+ var activityFeedQueryKeys = {
955
+ /** Match all activity feed queries. */
956
+ all: ["activityFeed"],
957
+ /** Match activity feed queries for a specific token. */
958
+ token: (tokenAddress) => ["activityFeed", tokenAddress]
959
+ };
960
+ function useActivityFeed(config) {
961
+ const { tokenAddress, userAddress, logs, decrypt: decryptOpt } = config;
962
+ const token = useReadonlyToken(tokenAddress);
963
+ const decrypt = decryptOpt ?? true;
964
+ const enabled = logs !== void 0 && userAddress !== void 0;
965
+ return useQuery({
966
+ queryKey: [
967
+ ...activityFeedQueryKeys.token(tokenAddress),
968
+ userAddress ?? "",
969
+ logs?.map((l) => `${l.transactionHash ?? ""}:${l.logIndex ?? ""}`).join(",") ?? ""
970
+ ],
971
+ queryFn: async () => {
972
+ if (!logs || !userAddress) return [];
973
+ const items = sortByBlockNumber(parseActivityFeed(logs, userAddress));
974
+ if (!decrypt) return items;
975
+ const handles = extractEncryptedHandles(items);
976
+ if (handles.length === 0) return items;
977
+ const decryptedMap = await token.decryptHandles(handles, userAddress);
978
+ return applyDecryptedValues(items, decryptedMap);
979
+ },
980
+ enabled,
981
+ staleTime: Infinity
982
+ });
983
+ }
984
+ function approveUnderlyingMutationOptions(token) {
985
+ return {
986
+ mutationKey: ["approveUnderlying", token.address],
987
+ mutationFn: ({ amount }) => token.approveUnderlying(amount)
988
+ };
989
+ }
990
+ function useApproveUnderlying(config, options) {
991
+ const token = useToken(config);
992
+ return useMutation({
993
+ mutationKey: ["approveUnderlying", config.tokenAddress],
994
+ mutationFn: ({ amount }) => token.approveUnderlying(amount),
995
+ ...options,
996
+ onSuccess: (data, variables, onMutateResult, context) => {
997
+ context.client.invalidateQueries({
998
+ queryKey: underlyingAllowanceQueryKeys.all
999
+ });
1000
+ options?.onSuccess?.(data, variables, onMutateResult, context);
1001
+ }
1002
+ });
1003
+ }
1004
+ var isConfidentialQueryKeys = {
1005
+ /** Match all confidential interface queries. */
1006
+ all: ["isConfidential"],
1007
+ /** Match confidential interface query for a specific token. */
1008
+ token: (tokenAddress) => ["isConfidential", tokenAddress]
1009
+ };
1010
+ var isWrapperQueryKeys = {
1011
+ /** Match all wrapper interface queries. */
1012
+ all: ["isWrapper"],
1013
+ /** Match wrapper interface query for a specific token. */
1014
+ token: (tokenAddress) => ["isWrapper", tokenAddress]
1015
+ };
1016
+ function isConfidentialQueryOptions(token) {
1017
+ return {
1018
+ queryKey: isConfidentialQueryKeys.token(token.address),
1019
+ queryFn: () => token.isConfidential(),
1020
+ staleTime: Infinity
1021
+ };
1022
+ }
1023
+ function isWrapperQueryOptions(token) {
1024
+ return {
1025
+ queryKey: isWrapperQueryKeys.token(token.address),
1026
+ queryFn: () => token.isWrapper(),
1027
+ staleTime: Infinity
1028
+ };
1029
+ }
1030
+ function useIsConfidential(tokenAddress, options) {
1031
+ const token = useReadonlyToken(tokenAddress);
1032
+ return useQuery({
1033
+ ...isConfidentialQueryOptions(token),
1034
+ ...options
1035
+ });
1036
+ }
1037
+ function useIsConfidentialSuspense(tokenAddress) {
1038
+ const token = useReadonlyToken(tokenAddress);
1039
+ return useSuspenseQuery(isConfidentialQueryOptions(token));
1040
+ }
1041
+ function useIsWrapper(tokenAddress, options) {
1042
+ const token = useReadonlyToken(tokenAddress);
1043
+ return useQuery({
1044
+ ...isWrapperQueryOptions(token),
1045
+ ...options
1046
+ });
1047
+ }
1048
+ function useIsWrapperSuspense(tokenAddress) {
1049
+ const token = useReadonlyToken(tokenAddress);
1050
+ return useSuspenseQuery(isWrapperQueryOptions(token));
1051
+ }
1052
+ var totalSupplyQueryKeys = {
1053
+ /** Match all total supply queries. */
1054
+ all: ["totalSupply"],
1055
+ /** Match total supply query for a specific token. */
1056
+ token: (tokenAddress) => ["totalSupply", tokenAddress]
1057
+ };
1058
+ function totalSupplyQueryOptions(token) {
1059
+ return {
1060
+ queryKey: totalSupplyQueryKeys.token(token.address),
1061
+ queryFn: () => token.signer.readContract(totalSupplyContract(token.address)),
1062
+ staleTime: 3e4
1063
+ };
1064
+ }
1065
+ function useTotalSupply(tokenAddress, options) {
1066
+ const token = useReadonlyToken(tokenAddress);
1067
+ return useQuery({
1068
+ ...totalSupplyQueryOptions(token),
1069
+ ...options
1070
+ });
1071
+ }
1072
+ function useTotalSupplySuspense(tokenAddress) {
1073
+ const token = useReadonlyToken(tokenAddress);
1074
+ return useSuspenseQuery(totalSupplyQueryOptions(token));
1075
+ }
1076
+ var feeQueryKeys = {
1077
+ /** Match shield fee query for given parameters. */
1078
+ shieldFee: (feeManagerAddress, amount, from, to) => ["shieldFee", feeManagerAddress, ...amount !== void 0 ? [amount, from, to] : []],
1079
+ /** Match unshield fee query for given parameters. */
1080
+ unshieldFee: (feeManagerAddress, amount, from, to) => [
1081
+ "unshieldFee",
1082
+ feeManagerAddress,
1083
+ ...amount !== void 0 ? [amount, from, to] : []
1084
+ ],
1085
+ /** Match batch transfer fee query for a specific fee manager. */
1086
+ batchTransferFee: (feeManagerAddress) => ["batchTransferFee", feeManagerAddress],
1087
+ /** Match fee recipient query for a specific fee manager. */
1088
+ feeRecipient: (feeManagerAddress) => ["feeRecipient", feeManagerAddress]
1089
+ };
1090
+ function shieldFeeQueryOptions(signer, config) {
1091
+ const { feeManagerAddress, amount, from, to } = config;
1092
+ return {
1093
+ queryKey: feeQueryKeys.shieldFee(feeManagerAddress, amount.toString(), from, to),
1094
+ queryFn: () => signer.readContract(getWrapFeeContract(feeManagerAddress, amount, from, to)),
1095
+ staleTime: 3e4
1096
+ };
1097
+ }
1098
+ function unshieldFeeQueryOptions(signer, config) {
1099
+ const { feeManagerAddress, amount, from, to } = config;
1100
+ return {
1101
+ queryKey: feeQueryKeys.unshieldFee(feeManagerAddress, amount.toString(), from, to),
1102
+ queryFn: () => signer.readContract(getUnwrapFeeContract(feeManagerAddress, amount, from, to)),
1103
+ staleTime: 3e4
1104
+ };
1105
+ }
1106
+ function batchTransferFeeQueryOptions(signer, feeManagerAddress) {
1107
+ return {
1108
+ queryKey: feeQueryKeys.batchTransferFee(feeManagerAddress),
1109
+ queryFn: () => signer.readContract(getBatchTransferFeeContract(feeManagerAddress)),
1110
+ staleTime: 3e4
1111
+ };
1112
+ }
1113
+ function feeRecipientQueryOptions(signer, feeManagerAddress) {
1114
+ return {
1115
+ queryKey: feeQueryKeys.feeRecipient(feeManagerAddress),
1116
+ queryFn: () => signer.readContract(getFeeRecipientContract(feeManagerAddress)),
1117
+ staleTime: 3e4
1118
+ };
1119
+ }
1120
+ function useShieldFee(config, options) {
1121
+ const sdk = useZamaSDK();
1122
+ return useQuery({
1123
+ ...shieldFeeQueryOptions(sdk.signer, config),
1124
+ ...options
1125
+ });
1126
+ }
1127
+ function useUnshieldFee(config, options) {
1128
+ const sdk = useZamaSDK();
1129
+ return useQuery({
1130
+ ...unshieldFeeQueryOptions(sdk.signer, config),
1131
+ ...options
1132
+ });
1133
+ }
1134
+ function useBatchTransferFee(feeManagerAddress, options) {
1135
+ const sdk = useZamaSDK();
1136
+ return useQuery({
1137
+ ...batchTransferFeeQueryOptions(sdk.signer, feeManagerAddress),
1138
+ ...options
1139
+ });
1140
+ }
1141
+ function useFeeRecipient(feeManagerAddress, options) {
1142
+ const sdk = useZamaSDK();
1143
+ return useQuery({
1144
+ ...feeRecipientQueryOptions(sdk.signer, feeManagerAddress),
1145
+ ...options
1146
+ });
1147
+ }
1148
+
1149
+ export { ZamaProvider, activityFeedQueryKeys, allowMutationOptions, approveUnderlyingMutationOptions, batchTransferFeeQueryOptions, confidentialApproveMutationOptions, confidentialBalanceQueryKeys, confidentialBalancesQueryKeys, confidentialHandleQueryKeys, confidentialHandlesQueryKeys, confidentialIsApprovedQueryKeys, confidentialIsApprovedQueryOptions, confidentialTransferFromMutationOptions, confidentialTransferMutationOptions, decryptionKeys, encryptMutationOptions, feeQueryKeys, feeRecipientQueryOptions, finalizeUnwrapMutationOptions, isAllowedQueryKeys, isAllowedQueryOptions, isConfidentialQueryKeys, isConfidentialQueryOptions, isWrapperQueryKeys, isWrapperQueryOptions, metadataQueryKeys, metadataQueryOptions, publicKeyQueryKeys, publicKeyQueryOptions, publicParamsQueryKeys, publicParamsQueryOptions, resumeUnshieldMutationOptions, revokeMutationOptions, revokeSessionMutationOptions, shieldETHMutationOptions, shieldFeeQueryOptions, shieldMutationOptions, totalSupplyQueryKeys, totalSupplyQueryOptions, underlyingAllowanceQueryKeys, underlyingAllowanceQueryOptions, unshieldAllMutationOptions, unshieldFeeQueryOptions, unshieldMutationOptions, unwrapAllMutationOptions, unwrapMutationOptions, useActivityFeed, useAllow, useApproveUnderlying, useBatchTransferFee, useConfidentialApprove, useConfidentialBalance, useConfidentialBalances, useConfidentialIsApproved, useConfidentialIsApprovedSuspense, useConfidentialTransfer, useConfidentialTransferFrom, useCreateDelegatedUserDecryptEIP712, useCreateEIP712, useDelegatedUserDecrypt, useEncrypt, useFeeRecipient, useFinalizeUnwrap, useGenerateKeypair, useIsAllowed, useIsConfidential, useIsConfidentialSuspense, useIsWrapper, useIsWrapperSuspense, useMetadata, useMetadataSuspense, usePublicDecrypt, usePublicKey, usePublicParams, useReadonlyToken, useReadonlyZamaSDK, useRequestZKProofVerification, useResumeUnshield, useRevoke, useRevokeSession, useShield, useShieldETH, useShieldFee, useToken, useTotalSupply, useTotalSupplySuspense, useUnderlyingAllowance, useUnderlyingAllowanceSuspense, useUnshield, useUnshieldAll, useUnshieldFee, useUnwrap, useUnwrapAll, useUserDecrypt, useUserDecryptFlow, useUserDecryptedValue, useUserDecryptedValues, useWrapperDiscovery, useWrapperDiscoverySuspense, useZamaSDK, wrapperDiscoveryQueryKeys, wrapperDiscoveryQueryOptions };
1150
+ //# sourceMappingURL=index.js.map
1151
+ //# sourceMappingURL=index.js.map