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

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