tempo.ts 0.1.5 → 0.2.1

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 (297) hide show
  1. package/README.md +33 -2
  2. package/dist/chains.d.ts +509 -115
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +20 -9
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/Order.d.ts +92 -0
  7. package/dist/ox/Order.d.ts.map +1 -0
  8. package/dist/ox/Order.js +88 -0
  9. package/dist/ox/Order.js.map +1 -0
  10. package/dist/ox/OrdersFilters.d.ts +72 -0
  11. package/dist/ox/OrdersFilters.d.ts.map +1 -0
  12. package/dist/ox/OrdersFilters.js +100 -0
  13. package/dist/ox/OrdersFilters.js.map +1 -0
  14. package/dist/ox/Pagination.d.ts +128 -0
  15. package/dist/ox/Pagination.d.ts.map +1 -0
  16. package/dist/ox/Pagination.js +78 -0
  17. package/dist/ox/Pagination.js.map +1 -0
  18. package/dist/ox/PoolId.d.ts +18 -0
  19. package/dist/ox/PoolId.d.ts.map +1 -0
  20. package/dist/ox/PoolId.js +13 -0
  21. package/dist/ox/PoolId.js.map +1 -0
  22. package/dist/ox/RpcSchema.d.ts +32 -0
  23. package/dist/ox/RpcSchema.d.ts.map +1 -0
  24. package/dist/ox/RpcSchema.js +2 -0
  25. package/dist/ox/RpcSchema.js.map +1 -0
  26. package/dist/ox/SignatureEnvelope.d.ts +1 -1
  27. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  28. package/dist/ox/SignatureEnvelope.js.map +1 -1
  29. package/dist/{viem → ox}/Tick.d.ts +4 -0
  30. package/dist/ox/Tick.d.ts.map +1 -0
  31. package/dist/ox/Tick.js.map +1 -0
  32. package/dist/ox/Transaction.d.ts.map +1 -1
  33. package/dist/ox/Transaction.js +2 -1
  34. package/dist/ox/Transaction.js.map +1 -1
  35. package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
  36. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  37. package/dist/ox/TransactionEnvelopeAA.js +4 -2
  38. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  39. package/dist/ox/TransactionRequest.d.ts +4 -0
  40. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  41. package/dist/ox/TransactionRequest.js.map +1 -1
  42. package/dist/ox/index.d.ts +6 -0
  43. package/dist/ox/index.d.ts.map +1 -1
  44. package/dist/ox/index.js +6 -0
  45. package/dist/ox/index.js.map +1 -1
  46. package/dist/prool/Instance.d.ts.map +1 -1
  47. package/dist/prool/Instance.js +20 -4
  48. package/dist/prool/Instance.js.map +1 -1
  49. package/dist/viem/Abis.d.ts +1469 -1082
  50. package/dist/viem/Abis.d.ts.map +1 -1
  51. package/dist/viem/Abis.js +932 -671
  52. package/dist/viem/Abis.js.map +1 -1
  53. package/dist/viem/Account.d.ts +150 -0
  54. package/dist/viem/Account.d.ts.map +1 -0
  55. package/dist/viem/Account.js +221 -0
  56. package/dist/viem/Account.js.map +1 -0
  57. package/dist/viem/Actions/amm.d.ts +144 -161
  58. package/dist/viem/Actions/amm.d.ts.map +1 -1
  59. package/dist/viem/Actions/amm.js +109 -163
  60. package/dist/viem/Actions/amm.js.map +1 -1
  61. package/dist/viem/Actions/dex.d.ts +920 -664
  62. package/dist/viem/Actions/dex.d.ts.map +1 -1
  63. package/dist/viem/Actions/dex.js +129 -30
  64. package/dist/viem/Actions/dex.js.map +1 -1
  65. package/dist/viem/Actions/faucet.d.ts +34 -0
  66. package/dist/viem/Actions/faucet.d.ts.map +1 -0
  67. package/dist/viem/Actions/faucet.js +33 -0
  68. package/dist/viem/Actions/faucet.js.map +1 -0
  69. package/dist/viem/Actions/fee.d.ts +16 -30
  70. package/dist/viem/Actions/fee.d.ts.map +1 -1
  71. package/dist/viem/Actions/fee.js +13 -13
  72. package/dist/viem/Actions/fee.js.map +1 -1
  73. package/dist/viem/Actions/index.d.ts +2 -0
  74. package/dist/viem/Actions/index.d.ts.map +1 -1
  75. package/dist/viem/Actions/index.js +2 -0
  76. package/dist/viem/Actions/index.js.map +1 -1
  77. package/dist/viem/Actions/policy.d.ts +46 -46
  78. package/dist/viem/Actions/policy.js +46 -46
  79. package/dist/viem/Actions/reward.d.ts +3236 -0
  80. package/dist/viem/Actions/reward.d.ts.map +1 -0
  81. package/dist/viem/Actions/reward.js +725 -0
  82. package/dist/viem/Actions/reward.js.map +1 -0
  83. package/dist/viem/Actions/token.d.ts +4399 -2750
  84. package/dist/viem/Actions/token.d.ts.map +1 -1
  85. package/dist/viem/Actions/token.js +361 -482
  86. package/dist/viem/Actions/token.js.map +1 -1
  87. package/dist/viem/Addresses.d.ts +1 -2
  88. package/dist/viem/Addresses.d.ts.map +1 -1
  89. package/dist/viem/Addresses.js +1 -2
  90. package/dist/viem/Addresses.js.map +1 -1
  91. package/dist/viem/Chain.d.ts +38 -12
  92. package/dist/viem/Chain.d.ts.map +1 -1
  93. package/dist/viem/Chain.js +27 -18
  94. package/dist/viem/Chain.js.map +1 -1
  95. package/dist/viem/Decorator.d.ts +1009 -428
  96. package/dist/viem/Decorator.d.ts.map +1 -1
  97. package/dist/viem/Decorator.js +17 -5
  98. package/dist/viem/Decorator.js.map +1 -1
  99. package/dist/viem/Formatters.d.ts +8 -1
  100. package/dist/viem/Formatters.d.ts.map +1 -1
  101. package/dist/viem/Formatters.js +17 -0
  102. package/dist/viem/Formatters.js.map +1 -1
  103. package/dist/viem/P256.d.ts +2 -0
  104. package/dist/viem/P256.d.ts.map +1 -0
  105. package/dist/viem/P256.js +2 -0
  106. package/dist/viem/P256.js.map +1 -0
  107. package/dist/viem/Secp256k1.d.ts +2 -0
  108. package/dist/viem/Secp256k1.d.ts.map +1 -0
  109. package/dist/viem/Secp256k1.js +2 -0
  110. package/dist/viem/Secp256k1.js.map +1 -0
  111. package/dist/viem/TokenIds.d.ts +1 -2
  112. package/dist/viem/TokenIds.d.ts.map +1 -1
  113. package/dist/viem/TokenIds.js +1 -2
  114. package/dist/viem/TokenIds.js.map +1 -1
  115. package/dist/viem/Transaction.d.ts +1 -1
  116. package/dist/viem/Transaction.d.ts.map +1 -1
  117. package/dist/viem/Transaction.js +46 -5
  118. package/dist/viem/Transaction.js.map +1 -1
  119. package/dist/viem/WebAuthnP256.d.ts +79 -0
  120. package/dist/viem/WebAuthnP256.d.ts.map +1 -0
  121. package/dist/viem/WebAuthnP256.js +95 -0
  122. package/dist/viem/WebAuthnP256.js.map +1 -0
  123. package/dist/viem/WebCryptoP256.d.ts +2 -0
  124. package/dist/viem/WebCryptoP256.d.ts.map +1 -0
  125. package/dist/viem/WebCryptoP256.js +2 -0
  126. package/dist/viem/WebCryptoP256.js.map +1 -0
  127. package/dist/viem/index.d.ts +6 -3
  128. package/dist/viem/index.d.ts.map +1 -1
  129. package/dist/viem/index.js +6 -3
  130. package/dist/viem/index.js.map +1 -1
  131. package/dist/viem/internal/account.d.ts +24 -0
  132. package/dist/viem/internal/account.d.ts.map +1 -0
  133. package/dist/viem/internal/account.js +68 -0
  134. package/dist/viem/internal/account.js.map +1 -0
  135. package/dist/viem/internal/types.d.ts +10 -0
  136. package/dist/viem/internal/types.d.ts.map +1 -1
  137. package/dist/wagmi/Actions/amm.d.ts +428 -0
  138. package/dist/wagmi/Actions/amm.d.ts.map +1 -0
  139. package/dist/wagmi/Actions/amm.js +472 -0
  140. package/dist/wagmi/Actions/amm.js.map +1 -0
  141. package/dist/wagmi/Actions/dex.d.ts +908 -0
  142. package/dist/wagmi/Actions/dex.d.ts.map +1 -0
  143. package/dist/wagmi/Actions/dex.js +1023 -0
  144. package/dist/wagmi/Actions/dex.js.map +1 -0
  145. package/dist/wagmi/Actions/faucet.d.ts +35 -0
  146. package/dist/wagmi/Actions/faucet.d.ts.map +1 -0
  147. package/dist/wagmi/Actions/faucet.js +33 -0
  148. package/dist/wagmi/Actions/faucet.js.map +1 -0
  149. package/dist/wagmi/Actions/fee.d.ts +111 -0
  150. package/dist/wagmi/Actions/fee.d.ts.map +1 -0
  151. package/dist/wagmi/Actions/fee.js +126 -0
  152. package/dist/wagmi/Actions/fee.js.map +1 -0
  153. package/dist/wagmi/Actions/index.d.ts +7 -0
  154. package/dist/wagmi/Actions/index.d.ts.map +1 -0
  155. package/dist/wagmi/Actions/index.js +7 -0
  156. package/dist/wagmi/Actions/index.js.map +1 -0
  157. package/dist/wagmi/Actions/reward.d.ts +348 -0
  158. package/dist/wagmi/Actions/reward.d.ts.map +1 -0
  159. package/dist/wagmi/Actions/reward.js +388 -0
  160. package/dist/wagmi/Actions/reward.js.map +1 -0
  161. package/dist/wagmi/Actions/token.d.ts +1546 -0
  162. package/dist/wagmi/Actions/token.d.ts.map +1 -0
  163. package/dist/wagmi/Actions/token.js +1712 -0
  164. package/dist/wagmi/Actions/token.js.map +1 -0
  165. package/dist/wagmi/Connector.d.ts +81 -0
  166. package/dist/wagmi/Connector.d.ts.map +1 -0
  167. package/dist/wagmi/Connector.js +261 -0
  168. package/dist/wagmi/Connector.js.map +1 -0
  169. package/dist/wagmi/Hooks/amm.d.ts +421 -0
  170. package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
  171. package/dist/wagmi/Hooks/amm.js +504 -0
  172. package/dist/wagmi/Hooks/amm.js.map +1 -0
  173. package/dist/wagmi/Hooks/dex.d.ts +816 -0
  174. package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
  175. package/dist/wagmi/Hooks/dex.js +973 -0
  176. package/dist/wagmi/Hooks/dex.js.map +1 -0
  177. package/dist/wagmi/Hooks/faucet.d.ts +39 -0
  178. package/dist/wagmi/Hooks/faucet.d.ts.map +1 -0
  179. package/dist/wagmi/Hooks/faucet.js +40 -0
  180. package/dist/wagmi/Hooks/faucet.js.map +1 -0
  181. package/dist/wagmi/Hooks/fee.d.ts +97 -0
  182. package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
  183. package/dist/wagmi/Hooks/fee.js +109 -0
  184. package/dist/wagmi/Hooks/fee.js.map +1 -0
  185. package/dist/wagmi/Hooks/index.d.ts +7 -0
  186. package/dist/wagmi/Hooks/index.d.ts.map +1 -0
  187. package/dist/wagmi/Hooks/index.js +7 -0
  188. package/dist/wagmi/Hooks/index.js.map +1 -0
  189. package/dist/wagmi/Hooks/reward.d.ts +307 -0
  190. package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
  191. package/dist/wagmi/Hooks/reward.js +349 -0
  192. package/dist/wagmi/Hooks/reward.js.map +1 -0
  193. package/dist/wagmi/Hooks/token.d.ts +1388 -0
  194. package/dist/wagmi/Hooks/token.d.ts.map +1 -0
  195. package/dist/wagmi/Hooks/token.js +1657 -0
  196. package/dist/wagmi/Hooks/token.js.map +1 -0
  197. package/dist/wagmi/index.d.ts +4 -0
  198. package/dist/wagmi/index.d.ts.map +1 -0
  199. package/dist/wagmi/index.js +4 -0
  200. package/dist/wagmi/index.js.map +1 -0
  201. package/package.json +54 -10
  202. package/src/chains.ts +21 -9
  203. package/src/ox/Order.test.ts +78 -0
  204. package/src/ox/Order.ts +125 -0
  205. package/src/ox/OrdersFilters.test.ts +182 -0
  206. package/src/ox/OrdersFilters.ts +125 -0
  207. package/src/ox/Pagination.test.ts +162 -0
  208. package/src/ox/Pagination.ts +164 -0
  209. package/src/ox/PoolId.test.ts +33 -0
  210. package/src/ox/PoolId.ts +27 -0
  211. package/src/ox/RpcSchema.ts +35 -0
  212. package/src/ox/SignatureEnvelope.ts +3 -1
  213. package/src/{viem → ox}/Tick.test.ts +1 -1
  214. package/src/{viem → ox}/Tick.ts +5 -0
  215. package/src/ox/Transaction.test.ts +1 -1
  216. package/src/ox/Transaction.ts +2 -1
  217. package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
  218. package/src/ox/TransactionEnvelopeAA.ts +9 -7
  219. package/src/ox/TransactionRequest.ts +4 -0
  220. package/src/ox/index.ts +6 -0
  221. package/src/prool/Instance.ts +51 -37
  222. package/src/prool/internal/chain.json +104 -52
  223. package/src/tsconfig.json +9 -0
  224. package/src/viem/Abis.ts +972 -710
  225. package/src/viem/Account.ts +279 -0
  226. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
  227. package/src/viem/Actions/amm.test.ts +173 -169
  228. package/src/viem/Actions/amm.ts +131 -203
  229. package/src/viem/Actions/dex.test.ts +563 -484
  230. package/src/viem/Actions/dex.ts +203 -30
  231. package/src/viem/Actions/faucet.ts +50 -0
  232. package/src/viem/Actions/fee.test.ts +23 -34
  233. package/src/viem/Actions/fee.ts +20 -13
  234. package/src/viem/Actions/index.ts +2 -0
  235. package/src/viem/Actions/policy.test.ts +19 -33
  236. package/src/viem/Actions/policy.ts +46 -46
  237. package/src/viem/Actions/reward.test.ts +457 -0
  238. package/src/viem/Actions/reward.ts +999 -0
  239. package/src/viem/Actions/token.test.ts +453 -287
  240. package/src/viem/Actions/token.ts +605 -693
  241. package/src/viem/Addresses.ts +1 -2
  242. package/src/viem/Chain.bench-d.ts +12 -0
  243. package/src/viem/Chain.ts +70 -20
  244. package/src/viem/Decorator.bench-d.ts +1 -1
  245. package/src/viem/Decorator.test.ts +3 -1
  246. package/src/viem/Decorator.ts +1049 -442
  247. package/src/viem/Formatters.ts +31 -5
  248. package/src/viem/P256.ts +1 -0
  249. package/src/viem/Secp256k1.ts +1 -0
  250. package/src/viem/TokenIds.ts +1 -2
  251. package/src/viem/Transaction.ts +53 -7
  252. package/src/viem/WebAuthnP256.ts +140 -0
  253. package/src/viem/WebCryptoP256.ts +1 -0
  254. package/src/viem/e2e.test.ts +1126 -297
  255. package/src/viem/index.ts +6 -3
  256. package/src/viem/internal/account.ts +107 -0
  257. package/src/viem/internal/types.ts +9 -0
  258. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
  259. package/src/wagmi/Actions/amm.test.ts +198 -0
  260. package/src/wagmi/Actions/amm.ts +691 -0
  261. package/src/wagmi/Actions/dex.test.ts +1507 -0
  262. package/src/wagmi/Actions/dex.ts +1640 -0
  263. package/src/wagmi/Actions/faucet.ts +46 -0
  264. package/src/wagmi/Actions/fee.test.ts +63 -0
  265. package/src/wagmi/Actions/fee.ts +208 -0
  266. package/src/wagmi/Actions/index.ts +6 -0
  267. package/src/wagmi/Actions/reward.test.ts +210 -0
  268. package/src/wagmi/Actions/reward.ts +632 -0
  269. package/src/wagmi/Actions/token.test.ts +1308 -0
  270. package/src/wagmi/Actions/token.ts +2613 -0
  271. package/src/wagmi/Connector.test.ts +53 -0
  272. package/src/wagmi/Connector.ts +390 -0
  273. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
  274. package/src/wagmi/Hooks/amm.test.ts +424 -0
  275. package/src/wagmi/Hooks/amm.ts +806 -0
  276. package/src/wagmi/Hooks/dex.test.ts +1017 -0
  277. package/src/wagmi/Hooks/dex.ts +1685 -0
  278. package/src/wagmi/Hooks/faucet.ts +76 -0
  279. package/src/wagmi/Hooks/fee.test.ts +166 -0
  280. package/src/wagmi/Hooks/fee.ts +206 -0
  281. package/src/wagmi/Hooks/index.ts +6 -0
  282. package/src/wagmi/Hooks/reward.test.ts +219 -0
  283. package/src/wagmi/Hooks/reward.ts +672 -0
  284. package/src/wagmi/Hooks/token.test.ts +1670 -0
  285. package/src/wagmi/Hooks/token.ts +2906 -0
  286. package/src/wagmi/index.ts +3 -0
  287. package/src/wagmi/internal/types.ts +16 -0
  288. package/dist/viem/Client.d.ts +0 -27
  289. package/dist/viem/Client.d.ts.map +0 -1
  290. package/dist/viem/Client.js +0 -28
  291. package/dist/viem/Client.js.map +0 -1
  292. package/dist/viem/Tick.d.ts.map +0 -1
  293. package/dist/viem/Tick.js.map +0 -1
  294. package/src/viem/Client.bench-d.ts +0 -8
  295. package/src/viem/Client.test.ts +0 -178
  296. package/src/viem/Client.ts +0 -91
  297. /package/dist/{viem → ox}/Tick.js +0 -0
@@ -0,0 +1,76 @@
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 } 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
+ }
@@ -0,0 +1,166 @@
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
+ "getHdKey": [Function],
104
+ "nonceManager": undefined,
105
+ "publicKey": "0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5",
106
+ "sign": [Function],
107
+ "signAuthorization": [Function],
108
+ "signMessage": [Function],
109
+ "signTransaction": [Function],
110
+ "signTypedData": [Function],
111
+ "source": "hd",
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
+ })
@@ -0,0 +1,206 @@
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)
107
+ },
108
+ mutationKey: ['setUserTokenSync'],
109
+ })
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)
177
+ },
178
+ mutationKey: ['setUserTokenSync'],
179
+ })
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
+ }
@@ -0,0 +1,6 @@
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 reward from './reward.js'
6
+ export * as token from './token.js'
@@ -0,0 +1,219 @@
1
+ import { type Address, parseUnits } from 'viem'
2
+ import { describe, expect, test, vi } from 'vitest'
3
+ import { useConnect } from 'wagmi'
4
+ import { config, renderHook, setupToken } from '../../../test/wagmi/config.js'
5
+ import * as hooks from './reward.js'
6
+
7
+ describe('useCancelSync', () => {
8
+ test('default', async () => {
9
+ const { result } = await renderHook(() => ({
10
+ cancel: hooks.useCancelSync(),
11
+ connect: useConnect(),
12
+ start: hooks.useStartSync(),
13
+ }))
14
+
15
+ await result.current.connect.connectAsync({
16
+ connector: config.connectors[0]!,
17
+ })
18
+
19
+ const { token } = await setupToken()
20
+
21
+ // Start a reward stream
22
+ const { id: streamId } = await result.current.start.mutateAsync({
23
+ amount: parseUnits('100', 6),
24
+ seconds: 3600,
25
+ token,
26
+ })
27
+
28
+ // Cancel the stream
29
+ await result.current.cancel.mutateAsync({
30
+ id: streamId,
31
+ token,
32
+ })
33
+
34
+ await vi.waitFor(() => expect(result.current.cancel.isSuccess).toBeTruthy())
35
+ })
36
+ })
37
+
38
+ describe('useGetStream', () => {
39
+ test('default', async () => {
40
+ const { result } = await renderHook(() => ({
41
+ connect: useConnect(),
42
+ getStream: hooks.useGetStream(),
43
+ startSync: hooks.useStartSync(),
44
+ }))
45
+
46
+ await result.current.connect.connectAsync({
47
+ connector: config.connectors[0]!,
48
+ })
49
+
50
+ const { token } = await setupToken()
51
+
52
+ const { id: streamId } = await result.current.startSync.mutateAsync({
53
+ amount: parseUnits('100', 6),
54
+ seconds: 10,
55
+ token,
56
+ })
57
+
58
+ // Update the hook to query the stream
59
+ const { result: streamResult } = await renderHook(() =>
60
+ hooks.useGetStream({
61
+ id: streamId,
62
+ token,
63
+ }),
64
+ )
65
+
66
+ await vi.waitFor(() => expect(streamResult.current.isSuccess).toBeTruthy())
67
+
68
+ expect(streamResult.current.data?.funder).toBeDefined()
69
+ expect(streamResult.current.data?.amountTotal).toBe(parseUnits('100', 6))
70
+ })
71
+
72
+ test('reactivity: id and token parameters', async () => {
73
+ const { result: setupResult } = await renderHook(() => ({
74
+ connect: useConnect(),
75
+ startSync: hooks.useStartSync(),
76
+ }))
77
+
78
+ await setupResult.current.connect.connectAsync({
79
+ connector: config.connectors[0]!,
80
+ })
81
+
82
+ const { token } = await setupToken()
83
+
84
+ const { id } = await setupResult.current.startSync.mutateAsync({
85
+ amount: parseUnits('100', 6),
86
+ seconds: 10,
87
+ token,
88
+ })
89
+
90
+ const { result, rerender } = await renderHook(
91
+ (props) =>
92
+ hooks.useGetStream({
93
+ id: props?.id,
94
+ token: props?.token,
95
+ }),
96
+ {
97
+ initialProps: {
98
+ id: undefined as bigint | undefined,
99
+ token: undefined as Address | undefined,
100
+ },
101
+ },
102
+ )
103
+
104
+ await vi.waitFor(() => result.current.fetchStatus === 'idle')
105
+
106
+ // Should be disabled when parameters are undefined
107
+ expect(result.current.data).toBeUndefined()
108
+ expect(result.current.isPending).toBe(true)
109
+ expect(result.current.isEnabled).toBe(false)
110
+
111
+ // Set parameters
112
+ rerender({ id, token })
113
+
114
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
115
+
116
+ // Should now be enabled and have data
117
+ expect(result.current.isEnabled).toBe(true)
118
+ expect(result.current.data).toBeDefined()
119
+ expect(result.current.data?.amountTotal).toBe(parseUnits('100', 6))
120
+ })
121
+ })
122
+
123
+ describe('useGetTotalPerSecond', () => {
124
+ test('default', async () => {
125
+ const { token } = await setupToken()
126
+
127
+ const { result } = await renderHook(() =>
128
+ hooks.useGetTotalPerSecond({
129
+ token,
130
+ }),
131
+ )
132
+
133
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
134
+
135
+ expect(result.current.data).toBe(0n)
136
+ })
137
+
138
+ test('reactivity: token parameter', async () => {
139
+ const { result, rerender } = await renderHook(
140
+ (props) =>
141
+ hooks.useGetTotalPerSecond({
142
+ token: props?.token,
143
+ }),
144
+ {
145
+ initialProps: {
146
+ token: undefined as Address | undefined,
147
+ },
148
+ },
149
+ )
150
+
151
+ await vi.waitFor(() => result.current.fetchStatus === 'idle')
152
+
153
+ // Should be disabled when token is undefined
154
+ expect(result.current.data).toBeUndefined()
155
+ expect(result.current.isPending).toBe(true)
156
+ expect(result.current.isEnabled).toBe(false)
157
+
158
+ // Setup token
159
+ const { token } = await setupToken()
160
+
161
+ // Set token
162
+ rerender({ token })
163
+
164
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
165
+
166
+ // Should now be enabled and have data
167
+ expect(result.current.isEnabled).toBe(true)
168
+ expect(result.current.data).toBe(0n)
169
+ })
170
+ })
171
+
172
+ describe('useSetRecipientSync', () => {
173
+ test('default', async () => {
174
+ const { result } = await renderHook(() => ({
175
+ connect: useConnect(),
176
+ setRecipient: hooks.useSetRecipientSync(),
177
+ }))
178
+
179
+ await result.current.connect.connectAsync({
180
+ connector: config.connectors[0]!,
181
+ })
182
+
183
+ const { token } = await setupToken()
184
+
185
+ await result.current.setRecipient.mutateAsync({
186
+ recipient: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
187
+ token,
188
+ })
189
+
190
+ await vi.waitFor(() =>
191
+ expect(result.current.setRecipient.isSuccess).toBeTruthy(),
192
+ )
193
+ })
194
+ })
195
+
196
+ describe('useStartSync', () => {
197
+ test('default', async () => {
198
+ const { result } = await renderHook(() => ({
199
+ connect: useConnect(),
200
+ start: hooks.useStartSync(),
201
+ }))
202
+
203
+ await result.current.connect.connectAsync({
204
+ connector: config.connectors[0]!,
205
+ })
206
+
207
+ const { token } = await setupToken()
208
+
209
+ const { id } = await result.current.start.mutateAsync({
210
+ amount: parseUnits('100', 6),
211
+ seconds: 10,
212
+ token,
213
+ })
214
+
215
+ expect(id).toBeGreaterThan(0n)
216
+
217
+ await vi.waitFor(() => expect(result.current.start.isSuccess).toBeTruthy())
218
+ })
219
+ })