wagmi 3.1.4 → 3.3.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.
Files changed (56) hide show
  1. package/dist/esm/exports/tempo.js +9 -0
  2. package/dist/esm/exports/tempo.js.map +1 -0
  3. package/dist/esm/tempo/hooks/amm.js +485 -0
  4. package/dist/esm/tempo/hooks/amm.js.map +1 -0
  5. package/dist/esm/tempo/hooks/dex.js +1020 -0
  6. package/dist/esm/tempo/hooks/dex.js.map +1 -0
  7. package/dist/esm/tempo/hooks/faucet.js +76 -0
  8. package/dist/esm/tempo/hooks/faucet.js.map +1 -0
  9. package/dist/esm/tempo/hooks/fee.js +155 -0
  10. package/dist/esm/tempo/hooks/fee.js.map +1 -0
  11. package/dist/esm/tempo/hooks/index.js +11 -0
  12. package/dist/esm/tempo/hooks/index.js.map +1 -0
  13. package/dist/esm/tempo/hooks/nonce.js +85 -0
  14. package/dist/esm/tempo/hooks/nonce.js.map +1 -0
  15. package/dist/esm/tempo/hooks/policy.js +545 -0
  16. package/dist/esm/tempo/hooks/policy.js.map +1 -0
  17. package/dist/esm/tempo/hooks/reward.js +385 -0
  18. package/dist/esm/tempo/hooks/reward.js.map +1 -0
  19. package/dist/esm/tempo/hooks/token.js +1730 -0
  20. package/dist/esm/tempo/hooks/token.js.map +1 -0
  21. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  22. package/dist/esm/version.js +1 -1
  23. package/dist/types/exports/tempo.d.ts +4 -0
  24. package/dist/types/exports/tempo.d.ts.map +1 -0
  25. package/dist/types/tempo/hooks/amm.d.ts +384 -0
  26. package/dist/types/tempo/hooks/amm.d.ts.map +1 -0
  27. package/dist/types/tempo/hooks/dex.d.ts +841 -0
  28. package/dist/types/tempo/hooks/dex.d.ts.map +1 -0
  29. package/dist/types/tempo/hooks/faucet.d.ts +70 -0
  30. package/dist/types/tempo/hooks/faucet.d.ts.map +1 -0
  31. package/dist/types/tempo/hooks/fee.d.ts +123 -0
  32. package/dist/types/tempo/hooks/fee.d.ts.map +1 -0
  33. package/dist/types/tempo/hooks/index.d.ts +10 -0
  34. package/dist/types/tempo/hooks/index.d.ts.map +1 -0
  35. package/dist/types/tempo/hooks/nonce.d.ts +60 -0
  36. package/dist/types/tempo/hooks/nonce.d.ts.map +1 -0
  37. package/dist/types/tempo/hooks/policy.d.ts +422 -0
  38. package/dist/types/tempo/hooks/policy.d.ts.map +1 -0
  39. package/dist/types/tempo/hooks/reward.d.ts +304 -0
  40. package/dist/types/tempo/hooks/reward.d.ts.map +1 -0
  41. package/dist/types/tempo/hooks/token.d.ts +1387 -0
  42. package/dist/types/tempo/hooks/token.d.ts.map +1 -0
  43. package/dist/types/version.d.ts +1 -1
  44. package/package.json +12 -4
  45. package/src/exports/tempo.ts +17 -0
  46. package/src/tempo/hooks/amm.ts +776 -0
  47. package/src/tempo/hooks/dex.ts +1737 -0
  48. package/src/tempo/hooks/faucet.ts +142 -0
  49. package/src/tempo/hooks/fee.ts +264 -0
  50. package/src/tempo/hooks/index.ts +10 -0
  51. package/src/tempo/hooks/nonce.ts +126 -0
  52. package/src/tempo/hooks/policy.ts +907 -0
  53. package/src/tempo/hooks/reward.ts +668 -0
  54. package/src/tempo/hooks/token.ts +2979 -0
  55. package/src/version.ts +1 -1
  56. package/tempo/package.json +5 -0
@@ -0,0 +1,142 @@
1
+ import type { UseMutationResult } from '@tanstack/react-query'
2
+ import type { Config, ResolvedRegister } from '@wagmi/core'
3
+ import { Actions } from '@wagmi/core/tempo'
4
+ import { useConfig } from '../../hooks/useConfig.js'
5
+ import type { ConfigParameter } from '../../types/properties.js'
6
+ import { type UseMutationParameters, useMutation } from '../../utils/query.js'
7
+
8
+ /**
9
+ * Hook for funding an account with an initial amount of set token(s)
10
+ * on Tempo's testnet.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { Hooks } from 'wagmi/tempo'
15
+ *
16
+ * function App() {
17
+ * const { mutate, isPending } = Hooks.faucet.useFund()
18
+ *
19
+ * return (
20
+ * <button
21
+ * onClick={() => mutate({ account: '0xdeadbeef...' })}
22
+ * disabled={isPending}
23
+ * >
24
+ * Fund Account
25
+ * </button>
26
+ * )
27
+ * }
28
+ * ```
29
+ *
30
+ * @param parameters - Parameters.
31
+ * @returns Mutation result.
32
+ */
33
+ export function useFund<
34
+ config extends Config = ResolvedRegister['config'],
35
+ context = unknown,
36
+ >(
37
+ parameters: useFund.Parameters<config, context> = {},
38
+ ): useFund.ReturnType<config, context> {
39
+ const { mutation } = parameters
40
+ const config = useConfig(parameters)
41
+ return useMutation({
42
+ ...mutation,
43
+ async mutationFn(variables) {
44
+ return Actions.faucet.fund(config, variables)
45
+ },
46
+ mutationKey: ['fund'],
47
+ })
48
+ }
49
+
50
+ export declare namespace useFund {
51
+ type Parameters<
52
+ config extends Config = Config,
53
+ context = unknown,
54
+ > = ConfigParameter<config> & {
55
+ mutation?:
56
+ | UseMutationParameters<
57
+ Actions.faucet.fund.ReturnValue,
58
+ Actions.faucet.fund.ErrorType,
59
+ Actions.faucet.fund.Parameters<config>,
60
+ context
61
+ >
62
+ | undefined
63
+ }
64
+
65
+ type ReturnType<
66
+ config extends Config = Config,
67
+ context = unknown,
68
+ > = UseMutationResult<
69
+ Actions.faucet.fund.ReturnValue,
70
+ Actions.faucet.fund.ErrorType,
71
+ Actions.faucet.fund.Parameters<config>,
72
+ context
73
+ >
74
+ }
75
+
76
+ /**
77
+ * Hook for funding an account with an initial amount of set token(s)
78
+ * on Tempo's testnet. Returns the transaction receipts.
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * import { Hooks } from 'wagmi/tempo'
83
+ *
84
+ * function App() {
85
+ * const { mutate, isPending } = Hooks.faucet.useFundSync()
86
+ *
87
+ * return (
88
+ * <button
89
+ * onClick={() => mutate({ account: '0xdeadbeef...' })}
90
+ * disabled={isPending}
91
+ * >
92
+ * Fund Account
93
+ * </button>
94
+ * )
95
+ * }
96
+ * ```
97
+ *
98
+ * @param parameters - Parameters.
99
+ * @returns Mutation result.
100
+ */
101
+ export function useFundSync<
102
+ config extends Config = ResolvedRegister['config'],
103
+ context = unknown,
104
+ >(
105
+ parameters: useFundSync.Parameters<config, context> = {},
106
+ ): useFundSync.ReturnType<config, context> {
107
+ const { mutation } = parameters
108
+ const config = useConfig(parameters)
109
+ return useMutation({
110
+ ...mutation,
111
+ async mutationFn(variables) {
112
+ return Actions.faucet.fundSync(config, variables)
113
+ },
114
+ mutationKey: ['fundSync'],
115
+ })
116
+ }
117
+
118
+ export declare namespace useFundSync {
119
+ type Parameters<
120
+ config extends Config = Config,
121
+ context = unknown,
122
+ > = ConfigParameter<config> & {
123
+ mutation?:
124
+ | UseMutationParameters<
125
+ Actions.faucet.fundSync.ReturnValue,
126
+ Actions.faucet.fundSync.ErrorType,
127
+ Actions.faucet.fundSync.Parameters<config>,
128
+ context
129
+ >
130
+ | undefined
131
+ }
132
+
133
+ type ReturnType<
134
+ config extends Config = Config,
135
+ context = unknown,
136
+ > = UseMutationResult<
137
+ Actions.faucet.fundSync.ReturnValue,
138
+ Actions.faucet.fundSync.ErrorType,
139
+ Actions.faucet.fundSync.Parameters<config>,
140
+ context
141
+ >
142
+ }
@@ -0,0 +1,264 @@
1
+ import type { UseMutationResult } from '@tanstack/react-query'
2
+ import type { Config, ResolvedRegister } from '@wagmi/core'
3
+ import type { ExactPartial, UnionCompute } from '@wagmi/core/internal'
4
+ import { Actions } from '@wagmi/core/tempo'
5
+ import { useEffect } from 'react'
6
+
7
+ import { useChainId } from '../../hooks/useChainId.js'
8
+ import { useConfig } from '../../hooks/useConfig.js'
9
+ import type { ConfigParameter, QueryParameter } from '../../types/properties.js'
10
+ import {
11
+ type UseMutationParameters,
12
+ type UseQueryReturnType,
13
+ useMutation,
14
+ useQuery,
15
+ } from '../../utils/query.js'
16
+
17
+ /**
18
+ * Hook for getting the user's default fee token.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import { Hooks } from 'wagmi/tempo'
23
+ *
24
+ * function App() {
25
+ * const { data, isLoading } = Hooks.fee.useUserToken({
26
+ * account: '0x20c...0055',
27
+ * })
28
+ *
29
+ * if (isLoading) return <div>Loading...</div>
30
+ * return <div>Token: {data?.address}</div>
31
+ * }
32
+ * ```
33
+ *
34
+ * @param parameters - Parameters.
35
+ * @returns Query result with token address and ID.
36
+ */
37
+ export function useUserToken<
38
+ config extends Config = ResolvedRegister['config'],
39
+ selectData = Actions.fee.getUserToken.ReturnValue,
40
+ >(
41
+ parameters: useUserToken.Parameters<config, selectData>,
42
+ ): useUserToken.ReturnValue<selectData> {
43
+ const config = useConfig(parameters)
44
+ const chainId = useChainId({ config })
45
+ const options = Actions.fee.getUserToken.queryOptions(config, {
46
+ ...parameters,
47
+ chainId: parameters.chainId ?? chainId,
48
+ } as never)
49
+ return useQuery(options) as never
50
+ }
51
+
52
+ export declare namespace useUserToken {
53
+ export type Parameters<
54
+ config extends Config = ResolvedRegister['config'],
55
+ selectData = Actions.fee.getUserToken.ReturnValue,
56
+ > = ConfigParameter<config> &
57
+ QueryParameter<
58
+ Actions.fee.getUserToken.ReturnValue,
59
+ Actions.fee.getUserToken.ErrorType,
60
+ selectData,
61
+ Actions.fee.getUserToken.QueryKey<config>
62
+ > &
63
+ Omit<
64
+ Actions.fee.getUserToken.queryOptions.Parameters<config, selectData>,
65
+ 'query'
66
+ >
67
+
68
+ export type ReturnValue<selectData = Actions.fee.getUserToken.ReturnValue> =
69
+ UseQueryReturnType<selectData, Error>
70
+ }
71
+
72
+ /**
73
+ * Hook for setting the user's default fee token.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * import { Hooks } from 'wagmi/tempo'
78
+ *
79
+ * function App() {
80
+ * const { mutate, isPending } = Hooks.fee.useSetUserToken()
81
+ *
82
+ * return (
83
+ * <button
84
+ * onClick={() => mutate({ token: '0x20c...0055' })}
85
+ * disabled={isPending}
86
+ * >
87
+ * Set Token
88
+ * </button>
89
+ * )
90
+ * }
91
+ * ```
92
+ *
93
+ * @param parameters - Parameters.
94
+ * @returns Mutation result.
95
+ */
96
+ export function useSetUserToken<
97
+ config extends Config = ResolvedRegister['config'],
98
+ context = unknown,
99
+ >(
100
+ parameters: useSetUserToken.Parameters<config, context> = {},
101
+ ): useSetUserToken.ReturnType<config, context> {
102
+ const { mutation } = parameters
103
+ const config = useConfig(parameters)
104
+ return useMutation({
105
+ ...mutation,
106
+ async mutationFn(variables) {
107
+ return Actions.fee.setUserToken(config, variables as never)
108
+ },
109
+ mutationKey: ['setUserToken'],
110
+ }) as never
111
+ }
112
+
113
+ export declare namespace useSetUserToken {
114
+ type Parameters<
115
+ config extends Config = Config,
116
+ context = unknown,
117
+ > = ConfigParameter<config> & {
118
+ mutation?:
119
+ | UseMutationParameters<
120
+ Actions.fee.setUserToken.ReturnValue,
121
+ Actions.fee.setUserToken.ErrorType,
122
+ Actions.fee.setUserToken.Parameters<config>,
123
+ context
124
+ >
125
+ | undefined
126
+ }
127
+
128
+ type ReturnType<
129
+ config extends Config = Config,
130
+ context = unknown,
131
+ > = UseMutationResult<
132
+ Actions.fee.setUserToken.ReturnValue,
133
+ Actions.fee.setUserToken.ErrorType,
134
+ Actions.fee.setUserToken.Parameters<config>,
135
+ context
136
+ >
137
+ }
138
+
139
+ /**
140
+ * Hook for setting the user's default fee token.
141
+ *
142
+ * Note: This is a synchronous hook that waits for the transaction
143
+ * to be included on a block before returning a response.
144
+ *
145
+ * @example
146
+ * ```tsx
147
+ * import { Hooks } from 'wagmi/tempo'
148
+ *
149
+ * function App() {
150
+ * const { mutate, isPending } = Hooks.fee.useSetUserTokenSync()
151
+ *
152
+ * return (
153
+ * <button
154
+ * onClick={() => mutate({ token: '0x20c...0055' })}
155
+ * disabled={isPending}
156
+ * >
157
+ * Set Token
158
+ * </button>
159
+ * )
160
+ * }
161
+ * ```
162
+ *
163
+ * @param parameters - Parameters.
164
+ * @returns Mutation result.
165
+ */
166
+ export function useSetUserTokenSync<
167
+ config extends Config = ResolvedRegister['config'],
168
+ context = unknown,
169
+ >(
170
+ parameters: useSetUserTokenSync.Parameters<config, context> = {},
171
+ ): useSetUserTokenSync.ReturnType<config, context> {
172
+ const { mutation } = parameters
173
+ const config = useConfig(parameters)
174
+ return useMutation({
175
+ ...mutation,
176
+ async mutationFn(variables) {
177
+ return Actions.fee.setUserTokenSync(config, variables as never)
178
+ },
179
+ mutationKey: ['setUserTokenSync'],
180
+ }) as never
181
+ }
182
+
183
+ export declare namespace useSetUserTokenSync {
184
+ type Parameters<
185
+ config extends Config = Config,
186
+ context = unknown,
187
+ > = ConfigParameter<config> & {
188
+ mutation?:
189
+ | UseMutationParameters<
190
+ Actions.fee.setUserTokenSync.ReturnValue,
191
+ Actions.fee.setUserTokenSync.ErrorType,
192
+ Actions.fee.setUserTokenSync.Parameters<config>,
193
+ context
194
+ >
195
+ | undefined
196
+ }
197
+
198
+ type ReturnType<
199
+ config extends Config = Config,
200
+ context = unknown,
201
+ > = UseMutationResult<
202
+ Actions.fee.setUserTokenSync.ReturnValue,
203
+ Actions.fee.setUserTokenSync.ErrorType,
204
+ Actions.fee.setUserTokenSync.Parameters<config>,
205
+ context
206
+ >
207
+ }
208
+
209
+ /**
210
+ * Hook for watching user token set events.
211
+ *
212
+ * @example
213
+ * ```tsx
214
+ * import { Hooks } from 'wagmi/tempo'
215
+ *
216
+ * function App() {
217
+ * Hooks.fee.useWatchSetUserToken({
218
+ * onUserTokenSet(args) {
219
+ * console.log('User token set:', args)
220
+ * },
221
+ * })
222
+ *
223
+ * return <div>Watching for user token changes...</div>
224
+ * }
225
+ * ```
226
+ *
227
+ * @param parameters - Parameters.
228
+ */
229
+ export function useWatchSetUserToken<
230
+ config extends Config = ResolvedRegister['config'],
231
+ >(parameters: useWatchSetUserToken.Parameters<config> = {}) {
232
+ const { enabled = true, onUserTokenSet, ...rest } = parameters
233
+
234
+ const config = useConfig({ config: parameters.config })
235
+ const configChainId = useChainId({ config })
236
+ const chainId = parameters.chainId ?? configChainId
237
+
238
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rest.x is explicitly listed
239
+ useEffect(() => {
240
+ if (!enabled) return
241
+ if (!onUserTokenSet) return
242
+ return Actions.fee.watchSetUserToken(config, {
243
+ ...rest,
244
+ chainId,
245
+ onUserTokenSet,
246
+ })
247
+ }, [
248
+ config,
249
+ enabled,
250
+ chainId,
251
+ onUserTokenSet,
252
+ rest.fromBlock,
253
+ rest.onError,
254
+ rest.poll,
255
+ rest.pollingInterval,
256
+ ])
257
+ }
258
+
259
+ export declare namespace useWatchSetUserToken {
260
+ type Parameters<config extends Config = Config> = UnionCompute<
261
+ ExactPartial<Actions.fee.watchSetUserToken.Parameters<config>> &
262
+ ConfigParameter<config> & { enabled?: boolean | undefined }
263
+ >
264
+ }
@@ -0,0 +1,10 @@
1
+ /** biome-ignore-all lint/performance/noReExportAll: entrypoint */
2
+ // biome-ignore lint/performance/noBarrelFile: stable
3
+ export * as amm from './amm.js'
4
+ export * as dex from './dex.js'
5
+ export * as faucet from './faucet.js'
6
+ export * as fee from './fee.js'
7
+ export * as nonce from './nonce.js'
8
+ export * as policy from './policy.js'
9
+ export * as reward from './reward.js'
10
+ export * as token from './token.js'
@@ -0,0 +1,126 @@
1
+ import type { Config, ResolvedRegister } from '@wagmi/core'
2
+ import type { ExactPartial, UnionCompute } from '@wagmi/core/internal'
3
+ import { Actions } from '@wagmi/core/tempo'
4
+ import { useEffect } from 'react'
5
+
6
+ import { useChainId } from '../../hooks/useChainId.js'
7
+ import { useConfig } from '../../hooks/useConfig.js'
8
+ import type { ConfigParameter, QueryParameter } from '../../types/properties.js'
9
+ import { type UseQueryReturnType, useQuery } from '../../utils/query.js'
10
+
11
+ /**
12
+ * Hook for getting the nonce for an account and nonce key.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { Hooks } from 'wagmi/tempo'
17
+ *
18
+ * function App() {
19
+ * const { data, isLoading } = Hooks.nonce.useNonce({
20
+ * account: '0x...',
21
+ * nonceKey: 1n,
22
+ * })
23
+ *
24
+ * if (isLoading) return <div>Loading...</div>
25
+ * return <div>Nonce: {data?.toString()}</div>
26
+ * }
27
+ * ```
28
+ *
29
+ * @param parameters - Parameters.
30
+ * @returns Query result with nonce value.
31
+ */
32
+ export function useNonce<
33
+ config extends Config = ResolvedRegister['config'],
34
+ selectData = Actions.nonce.getNonce.ReturnValue,
35
+ >(
36
+ parameters: useNonce.Parameters<config, selectData> = {},
37
+ ): useNonce.ReturnValue<selectData> {
38
+ const config = useConfig(parameters)
39
+ const chainId = useChainId({ config })
40
+ const options = Actions.nonce.getNonce.queryOptions(config, {
41
+ ...parameters,
42
+ chainId: parameters.chainId ?? chainId,
43
+ } as never)
44
+ return useQuery(options) as never
45
+ }
46
+
47
+ export declare namespace useNonce {
48
+ export type Parameters<
49
+ config extends Config = ResolvedRegister['config'],
50
+ selectData = Actions.nonce.getNonce.ReturnValue,
51
+ > = ConfigParameter<config> &
52
+ QueryParameter<
53
+ Actions.nonce.getNonce.ReturnValue,
54
+ Actions.nonce.getNonce.ErrorType,
55
+ selectData,
56
+ Actions.nonce.getNonce.QueryKey<config>
57
+ > &
58
+ ExactPartial<
59
+ Omit<
60
+ Actions.nonce.getNonce.queryOptions.Parameters<config, selectData>,
61
+ 'query'
62
+ >
63
+ >
64
+
65
+ export type ReturnValue<selectData = Actions.nonce.getNonce.ReturnValue> =
66
+ UseQueryReturnType<selectData, Error>
67
+ }
68
+
69
+ /**
70
+ * Hook for watching nonce incremented events.
71
+ *
72
+ * @deprecated This function has been deprecated post-AllegroModerato. It will be removed in a future version.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * import { Hooks } from 'wagmi/tempo'
77
+ *
78
+ * function App() {
79
+ * Hooks.nonce.useWatchNonceIncremented({
80
+ * onNonceIncremented(args, log) {
81
+ * console.log('Nonce incremented:', args)
82
+ * },
83
+ * })
84
+ *
85
+ * return <div>Watching for nonce increments...</div>
86
+ * }
87
+ * ```
88
+ *
89
+ * @param parameters - Parameters.
90
+ */
91
+ export function useWatchNonceIncremented<
92
+ config extends Config = ResolvedRegister['config'],
93
+ >(parameters: useWatchNonceIncremented.Parameters<config> = {}) {
94
+ const { enabled = true, onNonceIncremented, ...rest } = parameters
95
+
96
+ const config = useConfig({ config: parameters.config })
97
+ const configChainId = useChainId({ config })
98
+ const chainId = parameters.chainId ?? configChainId
99
+
100
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rest.x is explicitly listed
101
+ useEffect(() => {
102
+ if (!enabled) return
103
+ if (!onNonceIncremented) return
104
+ return Actions.nonce.watchNonceIncremented(config, {
105
+ ...rest,
106
+ chainId,
107
+ onNonceIncremented,
108
+ })
109
+ }, [
110
+ config,
111
+ enabled,
112
+ chainId,
113
+ onNonceIncremented,
114
+ rest.fromBlock,
115
+ rest.onError,
116
+ rest.poll,
117
+ rest.pollingInterval,
118
+ ])
119
+ }
120
+
121
+ export declare namespace useWatchNonceIncremented {
122
+ type Parameters<config extends Config = Config> = UnionCompute<
123
+ ExactPartial<Actions.nonce.watchNonceIncremented.Parameters<config>> &
124
+ ConfigParameter<config> & { enabled?: boolean | undefined }
125
+ >
126
+ }