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