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