tempo.ts 0.12.0 → 0.13.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 (123) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +28 -34
  3. package/package.json +2 -28
  4. package/dist/wagmi/Actions/amm.d.ts +0 -418
  5. package/dist/wagmi/Actions/amm.d.ts.map +0 -1
  6. package/dist/wagmi/Actions/amm.js +0 -462
  7. package/dist/wagmi/Actions/amm.js.map +0 -1
  8. package/dist/wagmi/Actions/dex.d.ts +0 -864
  9. package/dist/wagmi/Actions/dex.d.ts.map +0 -1
  10. package/dist/wagmi/Actions/dex.js +0 -968
  11. package/dist/wagmi/Actions/dex.js.map +0 -1
  12. package/dist/wagmi/Actions/faucet.d.ts +0 -66
  13. package/dist/wagmi/Actions/faucet.d.ts.map +0 -1
  14. package/dist/wagmi/Actions/faucet.js +0 -64
  15. package/dist/wagmi/Actions/faucet.js.map +0 -1
  16. package/dist/wagmi/Actions/fee.d.ts +0 -111
  17. package/dist/wagmi/Actions/fee.d.ts.map +0 -1
  18. package/dist/wagmi/Actions/fee.js +0 -126
  19. package/dist/wagmi/Actions/fee.js.map +0 -1
  20. package/dist/wagmi/Actions/index.d.ts +0 -9
  21. package/dist/wagmi/Actions/index.d.ts.map +0 -1
  22. package/dist/wagmi/Actions/index.js +0 -9
  23. package/dist/wagmi/Actions/index.js.map +0 -1
  24. package/dist/wagmi/Actions/nonce.d.ts +0 -77
  25. package/dist/wagmi/Actions/nonce.d.ts.map +0 -1
  26. package/dist/wagmi/Actions/nonce.js +0 -87
  27. package/dist/wagmi/Actions/nonce.js.map +0 -1
  28. package/dist/wagmi/Actions/policy.d.ts +0 -480
  29. package/dist/wagmi/Actions/policy.d.ts.map +0 -1
  30. package/dist/wagmi/Actions/policy.js +0 -530
  31. package/dist/wagmi/Actions/policy.js.map +0 -1
  32. package/dist/wagmi/Actions/reward.d.ts +0 -346
  33. package/dist/wagmi/Actions/reward.d.ts.map +0 -1
  34. package/dist/wagmi/Actions/reward.js +0 -382
  35. package/dist/wagmi/Actions/reward.js.map +0 -1
  36. package/dist/wagmi/Actions/token.d.ts +0 -1546
  37. package/dist/wagmi/Actions/token.d.ts.map +0 -1
  38. package/dist/wagmi/Actions/token.js +0 -1712
  39. package/dist/wagmi/Actions/token.js.map +0 -1
  40. package/dist/wagmi/Connector.d.ts +0 -91
  41. package/dist/wagmi/Connector.d.ts.map +0 -1
  42. package/dist/wagmi/Connector.js +0 -473
  43. package/dist/wagmi/Connector.js.map +0 -1
  44. package/dist/wagmi/Hooks/amm.d.ts +0 -411
  45. package/dist/wagmi/Hooks/amm.d.ts.map +0 -1
  46. package/dist/wagmi/Hooks/amm.js +0 -494
  47. package/dist/wagmi/Hooks/amm.js.map +0 -1
  48. package/dist/wagmi/Hooks/dex.d.ts +0 -773
  49. package/dist/wagmi/Hooks/dex.d.ts.map +0 -1
  50. package/dist/wagmi/Hooks/dex.js +0 -921
  51. package/dist/wagmi/Hooks/dex.js.map +0 -1
  52. package/dist/wagmi/Hooks/faucet.d.ts +0 -71
  53. package/dist/wagmi/Hooks/faucet.d.ts.map +0 -1
  54. package/dist/wagmi/Hooks/faucet.js +0 -76
  55. package/dist/wagmi/Hooks/faucet.js.map +0 -1
  56. package/dist/wagmi/Hooks/fee.d.ts +0 -97
  57. package/dist/wagmi/Hooks/fee.d.ts.map +0 -1
  58. package/dist/wagmi/Hooks/fee.js +0 -109
  59. package/dist/wagmi/Hooks/fee.js.map +0 -1
  60. package/dist/wagmi/Hooks/index.d.ts +0 -9
  61. package/dist/wagmi/Hooks/index.d.ts.map +0 -1
  62. package/dist/wagmi/Hooks/index.js +0 -9
  63. package/dist/wagmi/Hooks/index.js.map +0 -1
  64. package/dist/wagmi/Hooks/nonce.d.ts +0 -59
  65. package/dist/wagmi/Hooks/nonce.d.ts.map +0 -1
  66. package/dist/wagmi/Hooks/nonce.js +0 -75
  67. package/dist/wagmi/Hooks/nonce.js.map +0 -1
  68. package/dist/wagmi/Hooks/policy.d.ts +0 -423
  69. package/dist/wagmi/Hooks/policy.d.ts.map +0 -1
  70. package/dist/wagmi/Hooks/policy.js +0 -510
  71. package/dist/wagmi/Hooks/policy.js.map +0 -1
  72. package/dist/wagmi/Hooks/reward.d.ts +0 -305
  73. package/dist/wagmi/Hooks/reward.d.ts.map +0 -1
  74. package/dist/wagmi/Hooks/reward.js +0 -368
  75. package/dist/wagmi/Hooks/reward.js.map +0 -1
  76. package/dist/wagmi/Hooks/token.d.ts +0 -1388
  77. package/dist/wagmi/Hooks/token.d.ts.map +0 -1
  78. package/dist/wagmi/Hooks/token.js +0 -1657
  79. package/dist/wagmi/Hooks/token.js.map +0 -1
  80. package/dist/wagmi/KeyManager.d.ts +0 -60
  81. package/dist/wagmi/KeyManager.d.ts.map +0 -1
  82. package/dist/wagmi/KeyManager.js +0 -106
  83. package/dist/wagmi/KeyManager.js.map +0 -1
  84. package/dist/wagmi/index.d.ts +0 -5
  85. package/dist/wagmi/index.d.ts.map +0 -1
  86. package/dist/wagmi/index.js +0 -5
  87. package/dist/wagmi/index.js.map +0 -1
  88. package/src/wagmi/Actions/amm.test.ts +0 -208
  89. package/src/wagmi/Actions/amm.ts +0 -690
  90. package/src/wagmi/Actions/dex.test.ts +0 -1482
  91. package/src/wagmi/Actions/dex.ts +0 -1540
  92. package/src/wagmi/Actions/faucet.ts +0 -89
  93. package/src/wagmi/Actions/fee.test.ts +0 -63
  94. package/src/wagmi/Actions/fee.ts +0 -211
  95. package/src/wagmi/Actions/index.ts +0 -8
  96. package/src/wagmi/Actions/nonce.test.ts +0 -82
  97. package/src/wagmi/Actions/nonce.ts +0 -139
  98. package/src/wagmi/Actions/policy.test.ts +0 -461
  99. package/src/wagmi/Actions/policy.ts +0 -817
  100. package/src/wagmi/Actions/reward.test.ts +0 -216
  101. package/src/wagmi/Actions/reward.ts +0 -613
  102. package/src/wagmi/Actions/token.test.ts +0 -1309
  103. package/src/wagmi/Actions/token.ts +0 -2644
  104. package/src/wagmi/Connector.test.ts +0 -56
  105. package/src/wagmi/Connector.ts +0 -670
  106. package/src/wagmi/Hooks/amm.test.ts +0 -564
  107. package/src/wagmi/Hooks/amm.ts +0 -796
  108. package/src/wagmi/Hooks/dex.test.ts +0 -992
  109. package/src/wagmi/Hooks/dex.ts +0 -1598
  110. package/src/wagmi/Hooks/faucet.ts +0 -144
  111. package/src/wagmi/Hooks/fee.test.ts +0 -166
  112. package/src/wagmi/Hooks/fee.ts +0 -206
  113. package/src/wagmi/Hooks/index.ts +0 -8
  114. package/src/wagmi/Hooks/nonce.test.ts +0 -142
  115. package/src/wagmi/Hooks/nonce.ts +0 -117
  116. package/src/wagmi/Hooks/policy.test.ts +0 -665
  117. package/src/wagmi/Hooks/policy.ts +0 -873
  118. package/src/wagmi/Hooks/reward.test.ts +0 -249
  119. package/src/wagmi/Hooks/reward.ts +0 -645
  120. package/src/wagmi/Hooks/token.test.ts +0 -1183
  121. package/src/wagmi/Hooks/token.ts +0 -2906
  122. package/src/wagmi/KeyManager.ts +0 -172
  123. package/src/wagmi/index.ts +0 -7
@@ -1,144 +0,0 @@
1
- import type { UseMutationResult } from '@tanstack/react-query'
2
- import type { Config, ResolvedRegister } from '@wagmi/core'
3
- import type { BaseErrorType } from 'viem'
4
- import { useConfig } from 'wagmi'
5
- import type { ConfigParameter } from 'wagmi/internal'
6
- import { type UseMutationParameters, useMutation } from 'wagmi/query'
7
-
8
- import { fund, fundSync } from '../Actions/faucet.js'
9
-
10
- /**
11
- * Hook for funding an account with an initial amount of set token(s)
12
- * on Tempo's testnet.
13
- *
14
- * @example
15
- * ```tsx
16
- * import { Hooks } from 'tempo.ts/wagmi'
17
- *
18
- * function App() {
19
- * const { mutate, isPending } = Hooks.faucet.useFund()
20
- *
21
- * return (
22
- * <button
23
- * onClick={() => mutate({ account: '0xdeadbeef...' })}
24
- * disabled={isPending}
25
- * >
26
- * Fund Account
27
- * </button>
28
- * )
29
- * }
30
- * ```
31
- *
32
- * @param parameters - Parameters.
33
- * @returns Mutation result.
34
- */
35
- export function useFund<
36
- config extends Config = ResolvedRegister['config'],
37
- context = unknown,
38
- >(
39
- parameters: useFund.Parameters<config, context> = {},
40
- ): useFund.ReturnType<config, context> {
41
- const { mutation } = parameters
42
- const config = useConfig(parameters)
43
- return useMutation({
44
- ...mutation,
45
- async mutationFn(variables) {
46
- return fund(config, variables)
47
- },
48
- mutationKey: ['fund'],
49
- })
50
- }
51
-
52
- export declare namespace useFund {
53
- type Parameters<
54
- config extends Config = Config,
55
- context = unknown,
56
- > = ConfigParameter<config> & {
57
- mutation?:
58
- | UseMutationParameters<
59
- fund.ReturnValue,
60
- BaseErrorType,
61
- fund.Parameters<config>,
62
- context
63
- >
64
- | undefined
65
- }
66
-
67
- type ReturnType<
68
- config extends Config = Config,
69
- context = unknown,
70
- > = UseMutationResult<
71
- fund.ReturnValue,
72
- BaseErrorType,
73
- fund.Parameters<config>,
74
- context
75
- >
76
- }
77
-
78
- /**
79
- * Hook for funding an account with an initial amount of set token(s)
80
- * on Tempo's testnet. Returns the transaction receipts.
81
- *
82
- * @example
83
- * ```tsx
84
- * import { Hooks } from 'tempo.ts/wagmi'
85
- *
86
- * function App() {
87
- * const { mutate, isPending } = Hooks.faucet.useFundSync()
88
- *
89
- * return (
90
- * <button
91
- * onClick={() => mutate({ account: '0xdeadbeef...' })}
92
- * disabled={isPending}
93
- * >
94
- * Fund Account
95
- * </button>
96
- * )
97
- * }
98
- * ```
99
- *
100
- * @param parameters - Parameters.
101
- * @returns Mutation result.
102
- */
103
- export function useFundSync<
104
- config extends Config = ResolvedRegister['config'],
105
- context = unknown,
106
- >(
107
- parameters: useFundSync.Parameters<config, context> = {},
108
- ): useFundSync.ReturnType<config, context> {
109
- const { mutation } = parameters
110
- const config = useConfig(parameters)
111
- return useMutation({
112
- ...mutation,
113
- async mutationFn(variables) {
114
- return fundSync(config, variables)
115
- },
116
- mutationKey: ['fundSync'],
117
- })
118
- }
119
-
120
- export declare namespace useFundSync {
121
- type Parameters<
122
- config extends Config = Config,
123
- context = unknown,
124
- > = ConfigParameter<config> & {
125
- mutation?:
126
- | UseMutationParameters<
127
- fundSync.ReturnValue,
128
- BaseErrorType,
129
- fundSync.Parameters<config>,
130
- context
131
- >
132
- | undefined
133
- }
134
-
135
- type ReturnType<
136
- config extends Config = Config,
137
- context = unknown,
138
- > = UseMutationResult<
139
- fundSync.ReturnValue,
140
- BaseErrorType,
141
- fundSync.Parameters<config>,
142
- context
143
- >
144
- }
@@ -1,166 +0,0 @@
1
- import type { Account } from 'viem'
2
- import { describe, expect, test, vi } from 'vitest'
3
- import { useConnect } from 'wagmi'
4
- import { accounts } from '../../../test/viem/config.js'
5
- import { config, renderHook } from '../../../test/wagmi/config.js'
6
- import { useSetUserToken, useSetUserTokenSync, useUserToken } from './fee.js'
7
-
8
- describe('useUserToken', () => {
9
- test('default', async () => {
10
- let account: Account | undefined
11
-
12
- const { result, rerender } = await renderHook(() =>
13
- useUserToken({ account }),
14
- )
15
-
16
- await vi.waitFor(() => result.current.fetchStatus === 'fetching')
17
-
18
- expect(result.current).toMatchInlineSnapshot(`
19
- {
20
- "data": undefined,
21
- "dataUpdatedAt": 0,
22
- "error": null,
23
- "errorUpdateCount": 0,
24
- "errorUpdatedAt": 0,
25
- "failureCount": 0,
26
- "failureReason": null,
27
- "fetchStatus": "idle",
28
- "isEnabled": false,
29
- "isError": false,
30
- "isFetched": false,
31
- "isFetchedAfterMount": false,
32
- "isFetching": false,
33
- "isInitialLoading": false,
34
- "isLoading": false,
35
- "isLoadingError": false,
36
- "isPaused": false,
37
- "isPending": true,
38
- "isPlaceholderData": false,
39
- "isRefetchError": false,
40
- "isRefetching": false,
41
- "isStale": false,
42
- "isSuccess": false,
43
- "promise": Promise {
44
- "reason": [Error: experimental_prefetchInRender feature flag is not enabled],
45
- "status": "rejected",
46
- },
47
- "queryKey": [
48
- "getUserToken",
49
- {
50
- "account": undefined,
51
- "chainId": 1337,
52
- },
53
- ],
54
- "refetch": [Function],
55
- "status": "pending",
56
- }
57
- `)
58
-
59
- account = accounts[0]
60
- rerender()
61
-
62
- await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
63
- timeout: 5_000,
64
- })
65
-
66
- expect(result.current).toMatchInlineSnapshot(`
67
- {
68
- "data": {
69
- "address": "0x20C0000000000000000000000000000000000001",
70
- "id": 1n,
71
- },
72
- "dataUpdatedAt": 1675209600000,
73
- "error": null,
74
- "errorUpdateCount": 0,
75
- "errorUpdatedAt": 0,
76
- "failureCount": 0,
77
- "failureReason": null,
78
- "fetchStatus": "idle",
79
- "isEnabled": true,
80
- "isError": false,
81
- "isFetched": true,
82
- "isFetchedAfterMount": true,
83
- "isFetching": false,
84
- "isInitialLoading": false,
85
- "isLoading": false,
86
- "isLoadingError": false,
87
- "isPaused": false,
88
- "isPending": false,
89
- "isPlaceholderData": false,
90
- "isRefetchError": false,
91
- "isRefetching": false,
92
- "isStale": true,
93
- "isSuccess": true,
94
- "promise": Promise {
95
- "reason": [Error: experimental_prefetchInRender feature flag is not enabled],
96
- "status": "rejected",
97
- },
98
- "queryKey": [
99
- "getUserToken",
100
- {
101
- "account": {
102
- "address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
103
- "keyType": "secp256k1",
104
- "publicKey": "0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5",
105
- "sign": [Function],
106
- "signAuthorization": [Function],
107
- "signKeyAuthorization": [Function],
108
- "signMessage": [Function],
109
- "signTransaction": [Function],
110
- "signTypedData": [Function],
111
- "source": "root",
112
- "type": "local",
113
- },
114
- "chainId": 1337,
115
- },
116
- ],
117
- "refetch": [Function],
118
- "status": "success",
119
- }
120
- `)
121
- })
122
- })
123
-
124
- describe.skip('useSetUserToken', () => {
125
- test('default', async () => {
126
- const { result } = await renderHook(() => ({
127
- connect: useConnect(),
128
- setUserToken: useSetUserToken(),
129
- }))
130
-
131
- await result.current.connect.connectAsync({
132
- connector: config.connectors[0]!,
133
- })
134
-
135
- const hash = await result.current.setUserToken.mutateAsync({
136
- token: '0x20C0000000000000000000000000000000000001',
137
- })
138
- expect(hash).toBeDefined()
139
-
140
- await vi.waitFor(() =>
141
- expect(result.current.setUserToken.isSuccess).toBeTruthy(),
142
- )
143
- })
144
- })
145
-
146
- describe('useSetUserTokenSync', () => {
147
- test('default', async () => {
148
- const { result } = await renderHook(() => ({
149
- connect: useConnect(),
150
- setUserToken: useSetUserTokenSync(),
151
- }))
152
-
153
- await result.current.connect.connectAsync({
154
- connector: config.connectors[0]!,
155
- })
156
-
157
- const data = await result.current.setUserToken.mutateAsync({
158
- token: '0x20C0000000000000000000000000000000000001',
159
- })
160
- expect(data).toBeDefined()
161
-
162
- await vi.waitFor(() =>
163
- expect(result.current.setUserToken.isSuccess).toBeTruthy(),
164
- )
165
- })
166
- })
@@ -1,206 +0,0 @@
1
- import type { DefaultError } from '@tanstack/query-core'
2
- import type { UseMutationResult } from '@tanstack/react-query'
3
- import type { Config, ResolvedRegister } from '@wagmi/core'
4
- import { useChainId, useConfig } from 'wagmi'
5
- import type { ConfigParameter, QueryParameter } from 'wagmi/internal'
6
- import {
7
- type UseMutationParameters,
8
- type UseQueryReturnType,
9
- useMutation,
10
- useQuery,
11
- } from 'wagmi/query'
12
-
13
- import { getUserToken, setUserToken, setUserTokenSync } from '../Actions/fee.js'
14
-
15
- /**
16
- * Hook for getting the user's default fee token.
17
- *
18
- * @example
19
- * ```tsx
20
- * import { Hooks } from 'tempo.ts/wagmi'
21
- *
22
- * function App() {
23
- * const { data, isLoading } = Hooks.fee.useUserToken({
24
- * account: '0x20c...0055',
25
- * })
26
- *
27
- * if (isLoading) return <div>Loading...</div>
28
- * return <div>Token: {data?.address}</div>
29
- * }
30
- * ```
31
- *
32
- * @param parameters - Parameters.
33
- * @returns Query result with token address and ID.
34
- */
35
- export function useUserToken<
36
- config extends Config = ResolvedRegister['config'],
37
- selectData = getUserToken.ReturnValue,
38
- >(parameters: useUserToken.Parameters<config, selectData>) {
39
- const { account, query = {} } = parameters
40
-
41
- const config = useConfig(parameters)
42
- const chainId = useChainId({ config })
43
-
44
- const options = getUserToken.queryOptions(config, {
45
- ...parameters,
46
- chainId: parameters.chainId ?? chainId,
47
- query: undefined,
48
- })
49
- const enabled = Boolean(account && (query.enabled ?? true))
50
-
51
- return useQuery({ ...query, ...options, enabled })
52
- }
53
-
54
- export declare namespace useUserToken {
55
- export type Parameters<
56
- config extends Config = ResolvedRegister['config'],
57
- selectData = getUserToken.ReturnValue,
58
- > = ConfigParameter<config> &
59
- QueryParameter<
60
- getUserToken.ReturnValue,
61
- DefaultError,
62
- selectData,
63
- getUserToken.QueryKey<config>
64
- > &
65
- Omit<getUserToken.queryOptions.Parameters<config, selectData>, 'query'>
66
-
67
- export type ReturnValue<selectData = getUserToken.ReturnValue> =
68
- UseQueryReturnType<selectData, Error>
69
- }
70
-
71
- /**
72
- * Hook for setting the user's default fee token.
73
- *
74
- * @example
75
- * ```tsx
76
- * import { Hooks } from 'tempo.ts/wagmi'
77
- *
78
- * function App() {
79
- * const { mutate, isPending } = Hooks.fee.useSetUserToken()
80
- *
81
- * return (
82
- * <button
83
- * onClick={() => mutate({ token: '0x20c...0055' })}
84
- * disabled={isPending}
85
- * >
86
- * Set Token
87
- * </button>
88
- * )
89
- * }
90
- * ```
91
- *
92
- * @param parameters - Parameters.
93
- * @returns Mutation result.
94
- */
95
- export function useSetUserToken<
96
- config extends Config = ResolvedRegister['config'],
97
- context = unknown,
98
- >(
99
- parameters: useSetUserToken.Parameters<config, context> = {},
100
- ): useSetUserToken.ReturnType<config, context> {
101
- const { mutation } = parameters
102
- const config = useConfig(parameters)
103
- return useMutation({
104
- ...mutation,
105
- async mutationFn(variables) {
106
- return setUserToken(config, variables as never)
107
- },
108
- mutationKey: ['setUserTokenSync'],
109
- }) as never
110
- }
111
-
112
- export declare namespace useSetUserToken {
113
- type Parameters<
114
- config extends Config = Config,
115
- context = unknown,
116
- > = ConfigParameter<config> & {
117
- mutation?:
118
- | UseMutationParameters<
119
- setUserToken.ReturnValue,
120
- setUserToken.ErrorType,
121
- setUserToken.Parameters<config>,
122
- context
123
- >
124
- | undefined
125
- }
126
-
127
- type ReturnType<
128
- config extends Config = Config,
129
- context = unknown,
130
- > = UseMutationResult<
131
- setUserToken.ReturnValue,
132
- setUserToken.ErrorType,
133
- setUserToken.Parameters<config>,
134
- context
135
- >
136
- }
137
-
138
- /**
139
- * Hook for setting the user's default fee token.
140
- *
141
- * Note: This is a synchronous hook that waits for the transaction
142
- * to be included on a block before returning a response.
143
- *
144
- * @example
145
- * ```tsx
146
- * import { Hooks } from 'tempo.ts/wagmi'
147
- *
148
- * function App() {
149
- * const { mutate, isPending } = Hooks.fee.useSetUserTokenSync()
150
- *
151
- * return (
152
- * <button
153
- * onClick={() => mutate({ token: '0x20c...0055' })}
154
- * disabled={isPending}
155
- * >
156
- * Set Token
157
- * </button>
158
- * )
159
- * }
160
- * ```
161
- *
162
- * @param parameters - Parameters.
163
- * @returns Mutation result.
164
- */
165
- export function useSetUserTokenSync<
166
- config extends Config = ResolvedRegister['config'],
167
- context = unknown,
168
- >(
169
- parameters: useSetUserTokenSync.Parameters<config, context> = {},
170
- ): useSetUserTokenSync.ReturnType<config, context> {
171
- const { mutation } = parameters
172
- const config = useConfig(parameters)
173
- return useMutation({
174
- ...mutation,
175
- async mutationFn(variables) {
176
- return setUserTokenSync(config, variables as never)
177
- },
178
- mutationKey: ['setUserTokenSync'],
179
- }) as never
180
- }
181
-
182
- export declare namespace useSetUserTokenSync {
183
- type Parameters<
184
- config extends Config = Config,
185
- context = unknown,
186
- > = ConfigParameter<config> & {
187
- mutation?:
188
- | UseMutationParameters<
189
- setUserTokenSync.ReturnValue,
190
- setUserTokenSync.ErrorType,
191
- setUserTokenSync.Parameters<config>,
192
- context
193
- >
194
- | undefined
195
- }
196
-
197
- type ReturnType<
198
- config extends Config = Config,
199
- context = unknown,
200
- > = UseMutationResult<
201
- setUserTokenSync.ReturnValue,
202
- setUserTokenSync.ErrorType,
203
- setUserTokenSync.Parameters<config>,
204
- context
205
- >
206
- }
@@ -1,8 +0,0 @@
1
- export * as amm from './amm.js'
2
- export * as dex from './dex.js'
3
- export * as faucet from './faucet.js'
4
- export * as fee from './fee.js'
5
- export * as nonce from './nonce.js'
6
- export * as policy from './policy.js'
7
- export * as reward from './reward.js'
8
- export * as token from './token.js'
@@ -1,142 +0,0 @@
1
- import type { Address } from 'viem'
2
- import { describe, expect, test, vi } from 'vitest'
3
- import { useConnect } from 'wagmi'
4
- import { accounts } from '../../../test/viem/config.js'
5
- import { config, renderHook } from '../../../test/wagmi/config.js'
6
- import * as hooks from './nonce.js'
7
- import * as tokenHooks from './token.js'
8
-
9
- const { useNonce } = hooks
10
-
11
- const account = accounts[0]
12
- const account2 = accounts[1]
13
-
14
- describe('useNonce', () => {
15
- test('default', async () => {
16
- let testAccount: Address | undefined
17
- let testNonceKey: bigint | undefined
18
-
19
- const { result, rerender } = await renderHook(() =>
20
- useNonce({ account: testAccount, nonceKey: testNonceKey }),
21
- )
22
-
23
- await vi.waitFor(() => result.current.fetchStatus === 'fetching')
24
-
25
- // Should be disabled when account is undefined
26
- expect(result.current.data).toBeUndefined()
27
- expect(result.current.isPending).toBe(true)
28
- expect(result.current.isEnabled).toBe(false)
29
-
30
- // Set account and nonceKey
31
- testAccount = account.address
32
- testNonceKey = 1n
33
- rerender()
34
-
35
- await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
36
- timeout: 5_000,
37
- })
38
-
39
- // Should now be enabled and have data
40
- expect(result.current.isEnabled).toBe(true)
41
- expect(result.current.data).toBe(0n)
42
- })
43
-
44
- test('reactivity: account parameter', async () => {
45
- let testAccount: Address | undefined
46
-
47
- const { result, rerender } = await renderHook(() =>
48
- useNonce({ account: testAccount, nonceKey: 1n }),
49
- )
50
-
51
- await vi.waitFor(() => result.current.fetchStatus === 'fetching')
52
-
53
- // Should be disabled when account is undefined
54
- expect(result.current.isEnabled).toBe(false)
55
-
56
- // Set account
57
- testAccount = account.address
58
- rerender()
59
-
60
- await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
61
- timeout: 5_000,
62
- })
63
-
64
- expect(result.current.isEnabled).toBe(true)
65
- expect(result.current.data).toBe(0n)
66
- })
67
-
68
- test('reactivity: nonceKey parameter', async () => {
69
- let testNonceKey: bigint | undefined
70
-
71
- const { result, rerender } = await renderHook(() =>
72
- useNonce({ account: account.address, nonceKey: testNonceKey }),
73
- )
74
-
75
- await vi.waitFor(() => result.current.fetchStatus === 'fetching')
76
-
77
- // Should be disabled when nonceKey is undefined
78
- expect(result.current.isEnabled).toBe(false)
79
-
80
- // Set nonceKey
81
- testNonceKey = 1n
82
- rerender()
83
-
84
- await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
85
- timeout: 5_000,
86
- })
87
-
88
- expect(result.current.isEnabled).toBe(true)
89
- expect(result.current.data).toBe(0n)
90
- })
91
- })
92
-
93
- describe('useWatchNonceIncremented', () => {
94
- test('default', async () => {
95
- const { result: connectResult } = await renderHook(() => ({
96
- connect: useConnect(),
97
- transferSync: tokenHooks.useTransferSync(),
98
- }))
99
-
100
- await connectResult.current.connect.connectAsync({
101
- connector: config.connectors[0]!,
102
- })
103
-
104
- const events: any[] = []
105
- await renderHook(() =>
106
- hooks.useWatchNonceIncremented({
107
- onNonceIncremented(args) {
108
- events.push(args)
109
- },
110
- args: {
111
- account: account.address,
112
- nonceKey: 5n,
113
- },
114
- }),
115
- )
116
-
117
- // Have to manually set nonce because eth_FillTransaction does not support nonce keys
118
- await connectResult.current.transferSync.mutateAsync({
119
- to: account2.address,
120
- amount: 1n,
121
- token: 1n,
122
- nonceKey: 5n,
123
- nonce: 0,
124
- })
125
-
126
- await connectResult.current.transferSync.mutateAsync({
127
- to: account2.address,
128
- amount: 1n,
129
- token: 1n,
130
- nonceKey: 5n,
131
- nonce: 1,
132
- })
133
-
134
- await vi.waitUntil(() => events.length >= 2)
135
-
136
- expect(events).toHaveLength(2)
137
- expect(events[0]?.account).toBe(account.address)
138
- expect(events[0]?.nonceKey).toBe(5n)
139
- expect(events[0]?.newNonce).toBe(1n)
140
- expect(events[1]?.newNonce).toBe(2n)
141
- })
142
- })