wagmi 3.1.4 → 3.2.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 +534 -0
  4. package/dist/esm/tempo/Hooks/amm.js.map +1 -0
  5. package/dist/esm/tempo/Hooks/dex.js +944 -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 +165 -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 +410 -0
  26. package/dist/types/tempo/Hooks/amm.d.ts.map +1 -0
  27. package/dist/types/tempo/Hooks/dex.d.ts +773 -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 +115 -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 +835 -0
  47. package/src/tempo/Hooks/dex.ts +1597 -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 +248 -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,944 @@
1
+ import { Actions } from '@wagmi/core/tempo';
2
+ import { useEffect } from 'react';
3
+ import { useChainId } from '../../hooks/useChainId.js';
4
+ import { useConfig } from '../../hooks/useConfig.js';
5
+ import { useMutation, useQuery, } from '../../utils/query.js';
6
+ /**
7
+ * Hook for buying a specific amount of tokens.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { Hooks } from 'wagmi/tempo'
12
+ *
13
+ * function App() {
14
+ * const { mutate, isPending } = Hooks.dex.useBuy()
15
+ *
16
+ * return (
17
+ * <button
18
+ * onClick={() => mutate({
19
+ * tokenIn: '0x20c...11',
20
+ * tokenOut: '0x20c...20',
21
+ * amountOut: parseUnits('100', 6),
22
+ * maxAmountIn: parseUnits('105', 6),
23
+ * })}
24
+ * disabled={isPending}
25
+ * >
26
+ * Buy Tokens
27
+ * </button>
28
+ * )
29
+ * }
30
+ * ```
31
+ *
32
+ * @param parameters - Parameters.
33
+ * @returns Mutation result.
34
+ */
35
+ export function useBuy(parameters = {}) {
36
+ const { mutation } = parameters;
37
+ const config = useConfig(parameters);
38
+ return useMutation({
39
+ ...mutation,
40
+ async mutationFn(variables) {
41
+ return Actions.dex.buy(config, variables);
42
+ },
43
+ mutationKey: ['buy'],
44
+ });
45
+ }
46
+ /**
47
+ * Hook for buying a specific amount of tokens.
48
+ *
49
+ * Note: This is a synchronous hook that waits for the transaction
50
+ * to be included on a block before returning a response.
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * import { Hooks } from 'wagmi/tempo'
55
+ *
56
+ * function App() {
57
+ * const { mutate, isPending } = Hooks.dex.useBuySync()
58
+ *
59
+ * return (
60
+ * <button
61
+ * onClick={() => mutate({
62
+ * tokenIn: '0x20c...11',
63
+ * tokenOut: '0x20c...20',
64
+ * amountOut: parseUnits('100', 6),
65
+ * maxAmountIn: parseUnits('105', 6),
66
+ * })}
67
+ * disabled={isPending}
68
+ * >
69
+ * Buy Tokens
70
+ * </button>
71
+ * )
72
+ * }
73
+ * ```
74
+ *
75
+ * @param parameters - Parameters.
76
+ * @returns Mutation result.
77
+ */
78
+ export function useBuySync(parameters = {}) {
79
+ const { mutation } = parameters;
80
+ const config = useConfig(parameters);
81
+ return useMutation({
82
+ ...mutation,
83
+ async mutationFn(variables) {
84
+ return Actions.dex.buySync(config, variables);
85
+ },
86
+ mutationKey: ['buySync'],
87
+ });
88
+ }
89
+ /**
90
+ * Hook for canceling an order from the orderbook.
91
+ *
92
+ * @example
93
+ * ```tsx
94
+ * import { Hooks } from 'wagmi/tempo'
95
+ *
96
+ * function App() {
97
+ * const { mutate, isPending } = Hooks.dex.useCancel()
98
+ *
99
+ * return (
100
+ * <button
101
+ * onClick={() => mutate({ orderId: 123n })}
102
+ * disabled={isPending}
103
+ * >
104
+ * Cancel Order
105
+ * </button>
106
+ * )
107
+ * }
108
+ * ```
109
+ *
110
+ * @param parameters - Parameters.
111
+ * @returns Mutation result.
112
+ */
113
+ export function useCancel(parameters = {}) {
114
+ const { mutation } = parameters;
115
+ const config = useConfig(parameters);
116
+ return useMutation({
117
+ ...mutation,
118
+ async mutationFn(variables) {
119
+ return Actions.dex.cancel(config, variables);
120
+ },
121
+ mutationKey: ['cancel'],
122
+ });
123
+ }
124
+ /**
125
+ * Hook for canceling an order from the orderbook.
126
+ *
127
+ * Note: This is a synchronous hook that waits for the transaction
128
+ * to be included on a block before returning a response.
129
+ *
130
+ * @example
131
+ * ```tsx
132
+ * import { Hooks } from 'wagmi/tempo'
133
+ *
134
+ * function App() {
135
+ * const { mutate, isPending } = Hooks.dex.useCancelSync()
136
+ *
137
+ * return (
138
+ * <button
139
+ * onClick={() => mutate({ orderId: 123n })}
140
+ * disabled={isPending}
141
+ * >
142
+ * Cancel Order
143
+ * </button>
144
+ * )
145
+ * }
146
+ * ```
147
+ *
148
+ * @param parameters - Parameters.
149
+ * @returns Mutation result.
150
+ */
151
+ export function useCancelSync(parameters = {}) {
152
+ const { mutation } = parameters;
153
+ const config = useConfig(parameters);
154
+ return useMutation({
155
+ ...mutation,
156
+ async mutationFn(variables) {
157
+ return Actions.dex.cancelSync(config, variables);
158
+ },
159
+ mutationKey: ['cancelSync'],
160
+ });
161
+ }
162
+ /**
163
+ * Hook for creating a new trading pair on the DEX.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * import { Hooks } from 'wagmi/tempo'
168
+ *
169
+ * function App() {
170
+ * const { mutate, isPending } = Hooks.dex.useCreatePair()
171
+ *
172
+ * return (
173
+ * <button
174
+ * onClick={() => mutate({ base: '0x20c...11' })}
175
+ * disabled={isPending}
176
+ * >
177
+ * Create Pair
178
+ * </button>
179
+ * )
180
+ * }
181
+ * ```
182
+ *
183
+ * @param parameters - Parameters.
184
+ * @returns Mutation result.
185
+ */
186
+ export function useCreatePair(parameters = {}) {
187
+ const { mutation } = parameters;
188
+ const config = useConfig(parameters);
189
+ return useMutation({
190
+ ...mutation,
191
+ async mutationFn(variables) {
192
+ return Actions.dex.createPair(config, variables);
193
+ },
194
+ mutationKey: ['createPair'],
195
+ });
196
+ }
197
+ /**
198
+ * Hook for creating a new trading pair on the DEX.
199
+ *
200
+ * Note: This is a synchronous hook that waits for the transaction
201
+ * to be included on a block before returning a response.
202
+ *
203
+ * @example
204
+ * ```tsx
205
+ * import { Hooks } from 'wagmi/tempo'
206
+ *
207
+ * function App() {
208
+ * const { mutate, isPending } = Hooks.dex.useCreatePairSync()
209
+ *
210
+ * return (
211
+ * <button
212
+ * onClick={() => mutate({ base: '0x20c...11' })}
213
+ * disabled={isPending}
214
+ * >
215
+ * Create Pair
216
+ * </button>
217
+ * )
218
+ * }
219
+ * ```
220
+ *
221
+ * @param parameters - Parameters.
222
+ * @returns Mutation result.
223
+ */
224
+ export function useCreatePairSync(parameters = {}) {
225
+ const { mutation } = parameters;
226
+ const config = useConfig(parameters);
227
+ return useMutation({
228
+ ...mutation,
229
+ async mutationFn(variables) {
230
+ return Actions.dex.createPairSync(config, variables);
231
+ },
232
+ mutationKey: ['createPairSync'],
233
+ });
234
+ }
235
+ /**
236
+ * Hook for getting a user's token balance on the DEX.
237
+ *
238
+ * @example
239
+ * ```tsx
240
+ * import { Hooks } from 'wagmi/tempo'
241
+ *
242
+ * function App() {
243
+ * const { data, isLoading } = Hooks.dex.useBalance({
244
+ * account: '0x...',
245
+ * token: '0x20c...11',
246
+ * })
247
+ *
248
+ * if (isLoading) return <div>Loading...</div>
249
+ * return <div>Balance: {data}</div>
250
+ * }
251
+ * ```
252
+ *
253
+ * @param parameters - Parameters.
254
+ * @returns Query result with the user's token balance on the DEX.
255
+ */
256
+ export function useBalance(parameters) {
257
+ const config = useConfig(parameters);
258
+ const chainId = useChainId({ config });
259
+ const options = Actions.dex.getBalance.queryOptions(config, {
260
+ ...parameters,
261
+ chainId: parameters.chainId ?? chainId,
262
+ });
263
+ return useQuery(options);
264
+ }
265
+ /**
266
+ * Hook for getting the quote for buying a specific amount of tokens.
267
+ *
268
+ * @example
269
+ * ```tsx
270
+ * import { Hooks } from 'wagmi/tempo'
271
+ *
272
+ * function App() {
273
+ * const { data, isLoading } = Hooks.dex.useBuyQuote({
274
+ * amountOut: parseUnits('100', 6),
275
+ * tokenIn: '0x20c...11',
276
+ * tokenOut: '0x20c...20',
277
+ * })
278
+ *
279
+ * if (isLoading) return <div>Loading...</div>
280
+ * return <div>Required Input: {data}</div>
281
+ * }
282
+ * ```
283
+ *
284
+ * @param parameters - Parameters.
285
+ * @returns Query result with the amount of tokenIn needed.
286
+ */
287
+ export function useBuyQuote(parameters) {
288
+ const config = useConfig(parameters);
289
+ const chainId = useChainId({ config });
290
+ const options = Actions.dex.getBuyQuote.queryOptions(config, {
291
+ ...parameters,
292
+ chainId: parameters.chainId ?? chainId,
293
+ });
294
+ return useQuery(options);
295
+ }
296
+ /**
297
+ * Hook for getting an order's details from the orderbook.
298
+ *
299
+ * @example
300
+ * ```tsx
301
+ * import { Hooks } from 'wagmi/tempo'
302
+ *
303
+ * function App() {
304
+ * const { data, isLoading } = Hooks.dex.useOrder({
305
+ * orderId: 123n,
306
+ * })
307
+ *
308
+ * if (isLoading) return <div>Loading...</div>
309
+ * return <div>Order: {JSON.stringify(data)}</div>
310
+ * }
311
+ * ```
312
+ *
313
+ * @param parameters - Parameters.
314
+ * @returns Query result with the order details.
315
+ */
316
+ export function useOrder(parameters) {
317
+ const config = useConfig(parameters);
318
+ const chainId = useChainId({ config });
319
+ const options = Actions.dex.getOrder.queryOptions(config, {
320
+ ...parameters,
321
+ chainId: parameters.chainId ?? chainId,
322
+ });
323
+ return useQuery(options);
324
+ }
325
+ /**
326
+ * Hook for getting orderbook information for a trading pair.
327
+ *
328
+ * @example
329
+ * ```tsx
330
+ * import { Hooks } from 'wagmi/tempo'
331
+ *
332
+ * function App() {
333
+ * const { data, isLoading } = Hooks.dex.useOrderbook({
334
+ * base: '0x20c...11',
335
+ * quote: '0x20c...20',
336
+ * })
337
+ *
338
+ * if (isLoading) return <div>Loading...</div>
339
+ * return <div>Orderbook: {JSON.stringify(data)}</div>
340
+ * }
341
+ * ```
342
+ *
343
+ * @param parameters - Parameters.
344
+ * @returns Query result with the orderbook information.
345
+ */
346
+ export function useOrderbook(parameters) {
347
+ const config = useConfig(parameters);
348
+ const chainId = useChainId({ config });
349
+ const options = Actions.dex.getOrderbook.queryOptions(config, {
350
+ ...parameters,
351
+ chainId: parameters.chainId ?? chainId,
352
+ });
353
+ return useQuery(options);
354
+ }
355
+ /**
356
+ * Hook for getting the tick level information at a specific tick.
357
+ *
358
+ * @example
359
+ * ```tsx
360
+ * import { Hooks } from 'wagmi/tempo'
361
+ * import { Tick } from 'viem/tempo'
362
+ *
363
+ * function App() {
364
+ * const { data, isLoading } = Hooks.dex.useTickLevel({
365
+ * base: '0x20c...11',
366
+ * tick: Tick.fromPrice('1.001'),
367
+ * isBid: true,
368
+ * })
369
+ *
370
+ * if (isLoading) return <div>Loading...</div>
371
+ * return <div>Tick Level: {JSON.stringify(data)}</div>
372
+ * }
373
+ * ```
374
+ *
375
+ * @param parameters - Parameters.
376
+ * @returns Query result with the tick level information.
377
+ */
378
+ export function useTickLevel(parameters) {
379
+ const config = useConfig(parameters);
380
+ const chainId = useChainId({ config });
381
+ const options = Actions.dex.getTickLevel.queryOptions(config, {
382
+ ...parameters,
383
+ chainId: parameters.chainId ?? chainId,
384
+ });
385
+ return useQuery(options);
386
+ }
387
+ /**
388
+ * Hook for getting the quote for selling a specific amount of tokens.
389
+ *
390
+ * @example
391
+ * ```tsx
392
+ * import { Hooks } from 'wagmi/tempo'
393
+ *
394
+ * function App() {
395
+ * const { data, isLoading } = Hooks.dex.useSellQuote({
396
+ * amountIn: parseUnits('100', 6),
397
+ * tokenIn: '0x20c...11',
398
+ * tokenOut: '0x20c...20',
399
+ * })
400
+ *
401
+ * if (isLoading) return <div>Loading...</div>
402
+ * return <div>Expected Output: {data}</div>
403
+ * }
404
+ * ```
405
+ *
406
+ * @param parameters - Parameters.
407
+ * @returns Query result with the amount of tokenOut received.
408
+ */
409
+ export function useSellQuote(parameters) {
410
+ const config = useConfig(parameters);
411
+ const chainId = useChainId({ config });
412
+ const options = Actions.dex.getSellQuote.queryOptions(config, {
413
+ ...parameters,
414
+ chainId: parameters.chainId ?? chainId,
415
+ });
416
+ return useQuery(options);
417
+ }
418
+ /**
419
+ * Hook for placing a limit order on the orderbook.
420
+ *
421
+ * @example
422
+ * ```tsx
423
+ * import { Hooks } from 'wagmi/tempo'
424
+ *
425
+ * function App() {
426
+ * const { mutate, isPending } = Hooks.dex.usePlace()
427
+ *
428
+ * return (
429
+ * <button
430
+ * onClick={() => mutate({
431
+ * amount: parseUnits('100', 6),
432
+ * tick: Tick.fromPrice('0.99'),
433
+ * token: '0x20c...11',
434
+ * type: 'buy',
435
+ * })}
436
+ * disabled={isPending}
437
+ * >
438
+ * Place Order
439
+ * </button>
440
+ * )
441
+ * }
442
+ * ```
443
+ *
444
+ * @param parameters - Parameters.
445
+ * @returns Mutation result.
446
+ */
447
+ export function usePlace(parameters = {}) {
448
+ const { mutation } = parameters;
449
+ const config = useConfig(parameters);
450
+ return useMutation({
451
+ ...mutation,
452
+ async mutationFn(variables) {
453
+ return Actions.dex.place(config, variables);
454
+ },
455
+ mutationKey: ['place'],
456
+ });
457
+ }
458
+ /**
459
+ * Hook for placing a flip order that automatically flips when filled.
460
+ *
461
+ * @example
462
+ * ```tsx
463
+ * import { Hooks } from 'wagmi/tempo'
464
+ *
465
+ * function App() {
466
+ * const { mutate, isPending } = Hooks.dex.usePlaceFlip()
467
+ *
468
+ * return (
469
+ * <button
470
+ * onClick={() => mutate({
471
+ * amount: parseUnits('100', 6),
472
+ * flipTick: Tick.fromPrice('1.01'),
473
+ * tick: Tick.fromPrice('0.99'),
474
+ * token: '0x20c...11',
475
+ * type: 'buy',
476
+ * })}
477
+ * disabled={isPending}
478
+ * >
479
+ * Place Flip Order
480
+ * </button>
481
+ * )
482
+ * }
483
+ * ```
484
+ *
485
+ * @param parameters - Parameters.
486
+ * @returns Mutation result.
487
+ */
488
+ export function usePlaceFlip(parameters = {}) {
489
+ const { mutation } = parameters;
490
+ const config = useConfig(parameters);
491
+ return useMutation({
492
+ ...mutation,
493
+ async mutationFn(variables) {
494
+ return Actions.dex.placeFlip(config, variables);
495
+ },
496
+ mutationKey: ['placeFlip'],
497
+ });
498
+ }
499
+ /**
500
+ * Hook for placing a flip order that automatically flips when filled.
501
+ *
502
+ * Note: This is a synchronous hook that waits for the transaction
503
+ * to be included on a block before returning a response.
504
+ *
505
+ * @example
506
+ * ```tsx
507
+ * import { Hooks } from 'wagmi/tempo'
508
+ *
509
+ * function App() {
510
+ * const { mutate, isPending } = Hooks.dex.usePlaceFlipSync()
511
+ *
512
+ * return (
513
+ * <button
514
+ * onClick={() => mutate({
515
+ * amount: parseUnits('100', 6),
516
+ * flipTick: Tick.fromPrice('1.01'),
517
+ * tick: Tick.fromPrice('0.99'),
518
+ * token: '0x20c...11',
519
+ * type: 'buy',
520
+ * })}
521
+ * disabled={isPending}
522
+ * >
523
+ * Place Flip Order
524
+ * </button>
525
+ * )
526
+ * }
527
+ * ```
528
+ *
529
+ * @param parameters - Parameters.
530
+ * @returns Mutation result.
531
+ */
532
+ export function usePlaceFlipSync(parameters = {}) {
533
+ const { mutation } = parameters;
534
+ const config = useConfig(parameters);
535
+ return useMutation({
536
+ ...mutation,
537
+ async mutationFn(variables) {
538
+ return Actions.dex.placeFlipSync(config, variables);
539
+ },
540
+ mutationKey: ['placeFlipSync'],
541
+ });
542
+ }
543
+ /**
544
+ * Hook for placing a limit order on the orderbook.
545
+ *
546
+ * Note: This is a synchronous hook that waits for the transaction
547
+ * to be included on a block before returning a response.
548
+ *
549
+ * @example
550
+ * ```tsx
551
+ * import { Hooks } from 'wagmi/tempo'
552
+ *
553
+ * function App() {
554
+ * const { mutate, isPending } = Hooks.dex.usePlaceSync()
555
+ *
556
+ * return (
557
+ * <button
558
+ * onClick={() => mutate({
559
+ * amount: parseUnits('100', 6),
560
+ * tick: Tick.fromPrice('0.99'),
561
+ * token: '0x20c...11',
562
+ * type: 'buy',
563
+ * })}
564
+ * disabled={isPending}
565
+ * >
566
+ * Place Order
567
+ * </button>
568
+ * )
569
+ * }
570
+ * ```
571
+ *
572
+ * @param parameters - Parameters.
573
+ * @returns Mutation result.
574
+ */
575
+ export function usePlaceSync(parameters = {}) {
576
+ const { mutation } = parameters;
577
+ const config = useConfig(parameters);
578
+ return useMutation({
579
+ ...mutation,
580
+ async mutationFn(variables) {
581
+ return Actions.dex.placeSync(config, variables);
582
+ },
583
+ mutationKey: ['placeSync'],
584
+ });
585
+ }
586
+ /**
587
+ * Hook for selling a specific amount of tokens.
588
+ *
589
+ * @example
590
+ * ```tsx
591
+ * import { Hooks } from 'wagmi/tempo'
592
+ *
593
+ * function App() {
594
+ * const { mutate, isPending } = Hooks.dex.useSell()
595
+ *
596
+ * return (
597
+ * <button
598
+ * onClick={() => mutate({
599
+ * amountIn: parseUnits('100', 6),
600
+ * minAmountOut: parseUnits('95', 6),
601
+ * tokenIn: '0x20c...11',
602
+ * tokenOut: '0x20c...20',
603
+ * })}
604
+ * disabled={isPending}
605
+ * >
606
+ * Sell Tokens
607
+ * </button>
608
+ * )
609
+ * }
610
+ * ```
611
+ *
612
+ * @param parameters - Parameters.
613
+ * @returns Mutation result.
614
+ */
615
+ export function useSell(parameters = {}) {
616
+ const { mutation } = parameters;
617
+ const config = useConfig(parameters);
618
+ return useMutation({
619
+ ...mutation,
620
+ async mutationFn(variables) {
621
+ return Actions.dex.sell(config, variables);
622
+ },
623
+ mutationKey: ['sell'],
624
+ });
625
+ }
626
+ /**
627
+ * Hook for selling a specific amount of tokens.
628
+ *
629
+ * Note: This is a synchronous hook that waits for the transaction
630
+ * to be included on a block before returning a response.
631
+ *
632
+ * @example
633
+ * ```tsx
634
+ * import { Hooks } from 'wagmi/tempo'
635
+ *
636
+ * function App() {
637
+ * const { mutate, isPending } = Hooks.dex.useSellSync()
638
+ *
639
+ * return (
640
+ * <button
641
+ * onClick={() => mutate({
642
+ * amountIn: parseUnits('100', 6),
643
+ * minAmountOut: parseUnits('95', 6),
644
+ * tokenIn: '0x20c...11',
645
+ * tokenOut: '0x20c...20',
646
+ * })}
647
+ * disabled={isPending}
648
+ * >
649
+ * Sell Tokens
650
+ * </button>
651
+ * )
652
+ * }
653
+ * ```
654
+ *
655
+ * @param parameters - Parameters.
656
+ * @returns Mutation result.
657
+ */
658
+ export function useSellSync(parameters = {}) {
659
+ const { mutation } = parameters;
660
+ const config = useConfig(parameters);
661
+ return useMutation({
662
+ ...mutation,
663
+ async mutationFn(variables) {
664
+ return Actions.dex.sellSync(config, variables);
665
+ },
666
+ mutationKey: ['sellSync'],
667
+ });
668
+ }
669
+ /**
670
+ * Hook for withdrawing tokens from the DEX to the caller's wallet.
671
+ *
672
+ * @example
673
+ * ```tsx
674
+ * import { Hooks } from 'wagmi/tempo'
675
+ *
676
+ * function App() {
677
+ * const { mutate, isPending } = Hooks.dex.useWithdraw()
678
+ *
679
+ * return (
680
+ * <button
681
+ * onClick={() => mutate({
682
+ * amount: 100n,
683
+ * token: '0x20c...11',
684
+ * })}
685
+ * disabled={isPending}
686
+ * >
687
+ * Withdraw
688
+ * </button>
689
+ * )
690
+ * }
691
+ * ```
692
+ *
693
+ * @param parameters - Parameters.
694
+ * @returns Mutation result.
695
+ */
696
+ export function useWithdraw(parameters = {}) {
697
+ const { mutation } = parameters;
698
+ const config = useConfig(parameters);
699
+ return useMutation({
700
+ ...mutation,
701
+ async mutationFn(variables) {
702
+ return Actions.dex.withdraw(config, variables);
703
+ },
704
+ mutationKey: ['withdraw'],
705
+ });
706
+ }
707
+ /**
708
+ * Hook for withdrawing tokens from the DEX to the caller's wallet.
709
+ *
710
+ * Note: This is a synchronous hook that waits for the transaction
711
+ * to be included on a block before returning a response.
712
+ *
713
+ * @example
714
+ * ```tsx
715
+ * import { Hooks } from 'wagmi/tempo'
716
+ *
717
+ * function App() {
718
+ * const { mutate, isPending } = Hooks.dex.useWithdrawSync()
719
+ *
720
+ * return (
721
+ * <button
722
+ * onClick={() => mutate({
723
+ * amount: 100n,
724
+ * token: '0x20c...11',
725
+ * })}
726
+ * disabled={isPending}
727
+ * >
728
+ * Withdraw
729
+ * </button>
730
+ * )
731
+ * }
732
+ * ```
733
+ *
734
+ * @param parameters - Parameters.
735
+ * @returns Mutation result.
736
+ */
737
+ export function useWithdrawSync(parameters = {}) {
738
+ const { mutation } = parameters;
739
+ const config = useConfig(parameters);
740
+ return useMutation({
741
+ ...mutation,
742
+ async mutationFn(variables) {
743
+ return Actions.dex.withdrawSync(config, variables);
744
+ },
745
+ mutationKey: ['withdrawSync'],
746
+ });
747
+ }
748
+ /**
749
+ * Hook for watching flip order placement events on the DEX.
750
+ *
751
+ * @example
752
+ * ```tsx
753
+ * import { Hooks } from 'wagmi/tempo'
754
+ *
755
+ * function App() {
756
+ * Hooks.dex.useWatchFlipOrderPlaced({
757
+ * onFlipOrderPlaced(args) {
758
+ * console.log('Flip order placed:', args)
759
+ * },
760
+ * })
761
+ *
762
+ * return <div>Watching for flip order placements...</div>
763
+ * }
764
+ * ```
765
+ *
766
+ * @param parameters - Parameters.
767
+ */
768
+ export function useWatchFlipOrderPlaced(parameters = {}) {
769
+ const { enabled = true, onFlipOrderPlaced, ...rest } = parameters;
770
+ const config = useConfig({ config: parameters.config });
771
+ const configChainId = useChainId({ config });
772
+ const chainId = parameters.chainId ?? configChainId;
773
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rest.x is explicitly listed
774
+ useEffect(() => {
775
+ if (!enabled)
776
+ return;
777
+ if (!onFlipOrderPlaced)
778
+ return;
779
+ return Actions.dex.watchFlipOrderPlaced(config, {
780
+ ...rest,
781
+ chainId,
782
+ onFlipOrderPlaced,
783
+ });
784
+ }, [
785
+ config,
786
+ enabled,
787
+ chainId,
788
+ onFlipOrderPlaced,
789
+ rest.fromBlock,
790
+ rest.maker,
791
+ rest.onError,
792
+ rest.poll,
793
+ rest.pollingInterval,
794
+ rest.token,
795
+ ]);
796
+ }
797
+ /**
798
+ * Hook for watching order cancellation events on the DEX.
799
+ *
800
+ * @example
801
+ * ```tsx
802
+ * import { Hooks } from 'wagmi/tempo'
803
+ *
804
+ * function App() {
805
+ * Hooks.dex.useWatchOrderCancelled({
806
+ * onOrderCancelled(args) {
807
+ * console.log('Order cancelled:', args)
808
+ * },
809
+ * })
810
+ *
811
+ * return <div>Watching for order cancellations...</div>
812
+ * }
813
+ * ```
814
+ *
815
+ * @param parameters - Parameters.
816
+ */
817
+ export function useWatchOrderCancelled(parameters = {}) {
818
+ const { enabled = true, onOrderCancelled, ...rest } = parameters;
819
+ const config = useConfig({ config: parameters.config });
820
+ const configChainId = useChainId({ config });
821
+ const chainId = parameters.chainId ?? configChainId;
822
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rest.x is explicitly listed
823
+ useEffect(() => {
824
+ if (!enabled)
825
+ return;
826
+ if (!onOrderCancelled)
827
+ return;
828
+ return Actions.dex.watchOrderCancelled(config, {
829
+ ...rest,
830
+ chainId,
831
+ onOrderCancelled,
832
+ });
833
+ }, [
834
+ config,
835
+ enabled,
836
+ chainId,
837
+ onOrderCancelled,
838
+ rest.fromBlock,
839
+ rest.onError,
840
+ rest.orderId,
841
+ rest.poll,
842
+ rest.pollingInterval,
843
+ ]);
844
+ }
845
+ /**
846
+ * Hook for watching order filled events on the DEX.
847
+ *
848
+ * @example
849
+ * ```tsx
850
+ * import { Hooks } from 'wagmi/tempo'
851
+ *
852
+ * function App() {
853
+ * Hooks.dex.useWatchOrderFilled({
854
+ * onOrderFilled(args) {
855
+ * console.log('Order filled:', args)
856
+ * },
857
+ * })
858
+ *
859
+ * return <div>Watching for order fills...</div>
860
+ * }
861
+ * ```
862
+ *
863
+ * @param parameters - Parameters.
864
+ */
865
+ export function useWatchOrderFilled(parameters = {}) {
866
+ const { enabled = true, onOrderFilled, ...rest } = parameters;
867
+ const config = useConfig({ config: parameters.config });
868
+ const configChainId = useChainId({ config });
869
+ const chainId = parameters.chainId ?? configChainId;
870
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rest.x is explicitly listed
871
+ useEffect(() => {
872
+ if (!enabled)
873
+ return;
874
+ if (!onOrderFilled)
875
+ return;
876
+ return Actions.dex.watchOrderFilled(config, {
877
+ ...rest,
878
+ chainId,
879
+ onOrderFilled,
880
+ });
881
+ }, [
882
+ config,
883
+ enabled,
884
+ chainId,
885
+ onOrderFilled,
886
+ rest.fromBlock,
887
+ rest.maker,
888
+ rest.onError,
889
+ rest.orderId,
890
+ rest.poll,
891
+ rest.pollingInterval,
892
+ rest.taker,
893
+ ]);
894
+ }
895
+ /**
896
+ * Hook for watching order placement events on the DEX.
897
+ *
898
+ * @example
899
+ * ```tsx
900
+ * import { Hooks } from 'wagmi/tempo'
901
+ *
902
+ * function App() {
903
+ * Hooks.dex.useWatchOrderPlaced({
904
+ * onOrderPlaced(args) {
905
+ * console.log('Order placed:', args)
906
+ * },
907
+ * })
908
+ *
909
+ * return <div>Watching for order placements...</div>
910
+ * }
911
+ * ```
912
+ *
913
+ * @param parameters - Parameters.
914
+ */
915
+ export function useWatchOrderPlaced(parameters = {}) {
916
+ const { enabled = true, onOrderPlaced, ...rest } = parameters;
917
+ const config = useConfig({ config: parameters.config });
918
+ const configChainId = useChainId({ config });
919
+ const chainId = parameters.chainId ?? configChainId;
920
+ // biome-ignore lint/correctness/useExhaustiveDependencies: rest.x is explicitly listed
921
+ useEffect(() => {
922
+ if (!enabled)
923
+ return;
924
+ if (!onOrderPlaced)
925
+ return;
926
+ return Actions.dex.watchOrderPlaced(config, {
927
+ ...rest,
928
+ chainId,
929
+ onOrderPlaced,
930
+ });
931
+ }, [
932
+ config,
933
+ enabled,
934
+ chainId,
935
+ onOrderPlaced,
936
+ rest.fromBlock,
937
+ rest.maker,
938
+ rest.onError,
939
+ rest.poll,
940
+ rest.pollingInterval,
941
+ rest.token,
942
+ ]);
943
+ }
944
+ //# sourceMappingURL=dex.js.map