tempo.ts 0.6.2 → 0.7.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.
- package/CHANGELOG.md +128 -0
- package/README.md +6 -2
- package/dist/ox/Transaction.js +1 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/server/Handler.d.ts +346 -0
- package/dist/server/Handler.d.ts.map +1 -0
- package/dist/server/Handler.js +441 -0
- package/dist/server/Handler.js.map +1 -0
- package/dist/server/Kv.d.ts +16 -0
- package/dist/server/Kv.d.ts.map +1 -0
- package/dist/server/Kv.js +25 -0
- package/dist/server/Kv.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/internal/requestListener.d.ts +124 -0
- package/dist/server/internal/requestListener.d.ts.map +1 -0
- package/dist/server/internal/requestListener.js +174 -0
- package/dist/server/internal/requestListener.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +51 -1245
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +15 -478
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/reward.d.ts +0 -1067
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/reward.js +4 -212
- package/dist/viem/Actions/reward.js.map +1 -1
- package/dist/viem/Decorator.d.ts +0 -263
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +0 -10
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Storage.d.ts +23 -0
- package/dist/viem/Storage.d.ts.map +1 -0
- package/dist/viem/Storage.js +47 -0
- package/dist/viem/Storage.js.map +1 -0
- package/dist/viem/Transport.d.ts +10 -1
- package/dist/viem/Transport.d.ts.map +1 -1
- package/dist/viem/Transport.js +22 -3
- package/dist/viem/Transport.js.map +1 -1
- package/dist/viem/internal/utils.d.ts +6 -0
- package/dist/viem/internal/utils.d.ts.map +1 -1
- package/dist/viem/internal/utils.js +24 -0
- package/dist/viem/internal/utils.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +0 -225
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +0 -248
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +0 -110
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +0 -121
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +6 -17
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +17 -43
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/amm.d.ts +0 -236
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
- package/dist/wagmi/Hooks/amm.js +0 -285
- package/dist/wagmi/Hooks/amm.js.map +1 -1
- package/dist/wagmi/Hooks/reward.d.ts +0 -88
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
- package/dist/wagmi/Hooks/reward.js +0 -103
- package/dist/wagmi/Hooks/reward.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +57 -0
- package/dist/wagmi/KeyManager.d.ts.map +1 -0
- package/dist/wagmi/KeyManager.js +101 -0
- package/dist/wagmi/KeyManager.js.map +1 -0
- package/dist/wagmi/index.d.ts +1 -0
- package/dist/wagmi/index.d.ts.map +1 -1
- package/dist/wagmi/index.js +1 -0
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +8 -2
- package/src/ox/Transaction.ts +1 -1
- package/src/ox/e2e.test.ts +7 -0
- package/src/server/Handler.test.ts +566 -0
- package/src/server/Handler.ts +577 -0
- package/src/server/Kv.ts +40 -0
- package/src/server/index.ts +2 -0
- package/src/server/internal/requestListener.ts +285 -0
- package/src/viem/Actions/amm.test.ts +10 -284
- package/src/viem/Actions/amm.ts +88 -768
- package/src/viem/Actions/reward.test.ts +4 -212
- package/src/viem/Actions/reward.ts +4 -291
- package/src/viem/Decorator.ts +0 -294
- package/src/viem/Storage.ts +88 -0
- package/src/viem/Transport.ts +40 -2
- package/src/viem/e2e.test.ts +106 -3
- package/src/viem/internal/utils.ts +21 -0
- package/src/wagmi/Actions/amm.test.ts +7 -85
- package/src/wagmi/Actions/amm.ts +0 -346
- package/src/wagmi/Actions/reward.test.ts +0 -99
- package/src/wagmi/Actions/reward.ts +0 -203
- package/src/wagmi/Connector.test.ts +4 -1
- package/src/wagmi/Connector.ts +24 -58
- package/src/wagmi/Hooks/amm.test.ts +8 -200
- package/src/wagmi/Hooks/amm.ts +0 -443
- package/src/wagmi/Hooks/reward.test.ts +1 -142
- package/src/wagmi/Hooks/reward.ts +0 -196
- package/src/wagmi/KeyManager.ts +159 -0
- package/src/wagmi/index.ts +1 -0
package/src/wagmi/Hooks/amm.ts
CHANGED
|
@@ -154,157 +154,6 @@ export declare namespace useLiquidityBalance {
|
|
|
154
154
|
> = UseQueryReturnType<selectData, Error>
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
/**
|
|
158
|
-
* Hook for performing a rebalance swap from validator token to user token.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```tsx
|
|
162
|
-
* import { Hooks } from 'tempo.ts/wagmi'
|
|
163
|
-
*
|
|
164
|
-
* function App() {
|
|
165
|
-
* const { mutate, isPending } = Hooks.amm.useRebalanceSwap()
|
|
166
|
-
*
|
|
167
|
-
* return (
|
|
168
|
-
* <button
|
|
169
|
-
* onClick={() =>
|
|
170
|
-
* mutate({
|
|
171
|
-
* userToken: '0x...',
|
|
172
|
-
* validatorToken: '0x...',
|
|
173
|
-
* amountOut: 100n,
|
|
174
|
-
* to: '0x...',
|
|
175
|
-
* })
|
|
176
|
-
* }
|
|
177
|
-
* disabled={isPending}
|
|
178
|
-
* >
|
|
179
|
-
* Rebalance Swap
|
|
180
|
-
* </button>
|
|
181
|
-
* )
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*
|
|
185
|
-
* @param parameters - Parameters.
|
|
186
|
-
* @returns Mutation result.
|
|
187
|
-
*/
|
|
188
|
-
export function useRebalanceSwap<
|
|
189
|
-
config extends Config = ResolvedRegister['config'],
|
|
190
|
-
context = unknown,
|
|
191
|
-
>(
|
|
192
|
-
parameters: useRebalanceSwap.Parameters<config, context> = {},
|
|
193
|
-
): useRebalanceSwap.ReturnType<config, context> {
|
|
194
|
-
const { mutation } = parameters
|
|
195
|
-
const config = useConfig(parameters)
|
|
196
|
-
return useMutation({
|
|
197
|
-
...mutation,
|
|
198
|
-
async mutationFn(variables) {
|
|
199
|
-
return Actions.rebalanceSwap(config, variables as never)
|
|
200
|
-
},
|
|
201
|
-
mutationKey: ['rebalanceSwap'],
|
|
202
|
-
}) as never
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export declare namespace useRebalanceSwap {
|
|
206
|
-
type Parameters<
|
|
207
|
-
config extends Config = Config,
|
|
208
|
-
context = unknown,
|
|
209
|
-
> = ConfigParameter<config> & {
|
|
210
|
-
mutation?:
|
|
211
|
-
| UseMutationParameters<
|
|
212
|
-
Actions.rebalanceSwap.ReturnValue,
|
|
213
|
-
DefaultError,
|
|
214
|
-
Actions.rebalanceSwap.Parameters<config>,
|
|
215
|
-
context
|
|
216
|
-
>
|
|
217
|
-
| undefined
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
type ReturnType<
|
|
221
|
-
config extends Config = Config,
|
|
222
|
-
context = unknown,
|
|
223
|
-
> = UseMutationResult<
|
|
224
|
-
Actions.rebalanceSwap.ReturnValue,
|
|
225
|
-
DefaultError,
|
|
226
|
-
Actions.rebalanceSwap.Parameters<config>,
|
|
227
|
-
context
|
|
228
|
-
>
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Hook for performing a rebalance swap from validator token to user token.
|
|
233
|
-
*
|
|
234
|
-
* Note: This is a synchronous hook that waits for the transaction
|
|
235
|
-
* to be included on a block before returning a response.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```tsx
|
|
239
|
-
* import { Hooks } from 'tempo.ts/wagmi'
|
|
240
|
-
*
|
|
241
|
-
* function App() {
|
|
242
|
-
* const { mutate, isPending } = Hooks.amm.useRebalanceSwapSync()
|
|
243
|
-
*
|
|
244
|
-
* return (
|
|
245
|
-
* <button
|
|
246
|
-
* onClick={() =>
|
|
247
|
-
* mutate({
|
|
248
|
-
* userToken: '0x...',
|
|
249
|
-
* validatorToken: '0x...',
|
|
250
|
-
* amountOut: 100n,
|
|
251
|
-
* to: '0x...',
|
|
252
|
-
* })
|
|
253
|
-
* }
|
|
254
|
-
* disabled={isPending}
|
|
255
|
-
* >
|
|
256
|
-
* Rebalance Swap
|
|
257
|
-
* </button>
|
|
258
|
-
* )
|
|
259
|
-
* }
|
|
260
|
-
* ```
|
|
261
|
-
*
|
|
262
|
-
* @param parameters - Parameters.
|
|
263
|
-
* @returns Mutation result.
|
|
264
|
-
*/
|
|
265
|
-
export function useRebalanceSwapSync<
|
|
266
|
-
config extends Config = ResolvedRegister['config'],
|
|
267
|
-
context = unknown,
|
|
268
|
-
>(
|
|
269
|
-
parameters: useRebalanceSwapSync.Parameters<config, context> = {},
|
|
270
|
-
): useRebalanceSwapSync.ReturnType<config, context> {
|
|
271
|
-
const { mutation } = parameters
|
|
272
|
-
const config = useConfig(parameters)
|
|
273
|
-
return useMutation({
|
|
274
|
-
...mutation,
|
|
275
|
-
async mutationFn(variables) {
|
|
276
|
-
return Actions.rebalanceSwapSync(config, variables as never)
|
|
277
|
-
},
|
|
278
|
-
mutationKey: ['rebalanceSwapSync'],
|
|
279
|
-
}) as never
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export declare namespace useRebalanceSwapSync {
|
|
283
|
-
type Parameters<
|
|
284
|
-
config extends Config = Config,
|
|
285
|
-
context = unknown,
|
|
286
|
-
> = ConfigParameter<config> & {
|
|
287
|
-
mutation?:
|
|
288
|
-
| UseMutationParameters<
|
|
289
|
-
Actions.rebalanceSwapSync.ReturnValue,
|
|
290
|
-
DefaultError,
|
|
291
|
-
Actions.rebalanceSwapSync.Parameters<config>,
|
|
292
|
-
context
|
|
293
|
-
>
|
|
294
|
-
| undefined
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
type ReturnType<
|
|
298
|
-
config extends Config = Config,
|
|
299
|
-
context = unknown,
|
|
300
|
-
> = UseMutationResult<
|
|
301
|
-
Actions.rebalanceSwapSync.ReturnValue,
|
|
302
|
-
DefaultError,
|
|
303
|
-
Actions.rebalanceSwapSync.Parameters<config>,
|
|
304
|
-
context
|
|
305
|
-
>
|
|
306
|
-
}
|
|
307
|
-
|
|
308
157
|
/**
|
|
309
158
|
* Hook for adding liquidity to a pool.
|
|
310
159
|
*
|
|
@@ -466,251 +315,6 @@ export declare namespace useMintSync {
|
|
|
466
315
|
>
|
|
467
316
|
}
|
|
468
317
|
|
|
469
|
-
/**
|
|
470
|
-
* Hook for removing liquidity from a pool.
|
|
471
|
-
*
|
|
472
|
-
* @example
|
|
473
|
-
* ```tsx
|
|
474
|
-
* import { Hooks } from 'tempo.ts/wagmi'
|
|
475
|
-
*
|
|
476
|
-
* function App() {
|
|
477
|
-
* const { mutate, isPending } = Hooks.amm.useBurn()
|
|
478
|
-
*
|
|
479
|
-
* return (
|
|
480
|
-
* <button
|
|
481
|
-
* onClick={() =>
|
|
482
|
-
* mutate({
|
|
483
|
-
* userToken: '0x20c0...beef',
|
|
484
|
-
* validatorToken: '0x20c0...babe',
|
|
485
|
-
* liquidity: 50n,
|
|
486
|
-
* to: '0xfeed...fede',
|
|
487
|
-
* })
|
|
488
|
-
* }
|
|
489
|
-
* disabled={isPending}
|
|
490
|
-
* >
|
|
491
|
-
* Remove Liquidity
|
|
492
|
-
* </button>
|
|
493
|
-
* )
|
|
494
|
-
* }
|
|
495
|
-
* ```
|
|
496
|
-
*
|
|
497
|
-
* @param parameters - Parameters.
|
|
498
|
-
* @returns Mutation result.
|
|
499
|
-
*/
|
|
500
|
-
export function useBurn<
|
|
501
|
-
config extends Config = ResolvedRegister['config'],
|
|
502
|
-
context = unknown,
|
|
503
|
-
>(
|
|
504
|
-
parameters: useBurn.Parameters<config, context> = {},
|
|
505
|
-
): useBurn.ReturnType<config, context> {
|
|
506
|
-
const { mutation } = parameters
|
|
507
|
-
const config = useConfig(parameters)
|
|
508
|
-
return useMutation({
|
|
509
|
-
...mutation,
|
|
510
|
-
async mutationFn(variables) {
|
|
511
|
-
return Actions.burn(config, variables as never)
|
|
512
|
-
},
|
|
513
|
-
mutationKey: ['burn'],
|
|
514
|
-
}) as never
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
export declare namespace useBurn {
|
|
518
|
-
type Parameters<
|
|
519
|
-
config extends Config = Config,
|
|
520
|
-
context = unknown,
|
|
521
|
-
> = ConfigParameter<config> & {
|
|
522
|
-
mutation?:
|
|
523
|
-
| UseMutationParameters<
|
|
524
|
-
Actions.burn.ReturnValue,
|
|
525
|
-
DefaultError,
|
|
526
|
-
Actions.burn.Parameters<config>,
|
|
527
|
-
context
|
|
528
|
-
>
|
|
529
|
-
| undefined
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
type ReturnType<
|
|
533
|
-
config extends Config = Config,
|
|
534
|
-
context = unknown,
|
|
535
|
-
> = UseMutationResult<
|
|
536
|
-
Actions.burn.ReturnValue,
|
|
537
|
-
DefaultError,
|
|
538
|
-
Actions.burn.Parameters<config>,
|
|
539
|
-
context
|
|
540
|
-
>
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Hook for removing liquidity from a pool.
|
|
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 'tempo.ts/wagmi'
|
|
552
|
-
*
|
|
553
|
-
* function App() {
|
|
554
|
-
* const { mutate, isPending } = Hooks.amm.useBurnSync()
|
|
555
|
-
*
|
|
556
|
-
* return (
|
|
557
|
-
* <button
|
|
558
|
-
* onClick={() =>
|
|
559
|
-
* mutate({
|
|
560
|
-
* userToken: '0x20c0...beef',
|
|
561
|
-
* validatorToken: '0x20c0...babe',
|
|
562
|
-
* liquidity: 50n,
|
|
563
|
-
* to: '0xfeed...fede',
|
|
564
|
-
* })
|
|
565
|
-
* }
|
|
566
|
-
* disabled={isPending}
|
|
567
|
-
* >
|
|
568
|
-
* Remove Liquidity
|
|
569
|
-
* </button>
|
|
570
|
-
* )
|
|
571
|
-
* }
|
|
572
|
-
* ```
|
|
573
|
-
*
|
|
574
|
-
* @param parameters - Parameters.
|
|
575
|
-
* @returns Mutation result.
|
|
576
|
-
*/
|
|
577
|
-
export function useBurnSync<
|
|
578
|
-
config extends Config = ResolvedRegister['config'],
|
|
579
|
-
context = unknown,
|
|
580
|
-
>(
|
|
581
|
-
parameters: useBurnSync.Parameters<config, context> = {},
|
|
582
|
-
): useBurnSync.ReturnType<config, context> {
|
|
583
|
-
const { mutation } = parameters
|
|
584
|
-
const config = useConfig(parameters)
|
|
585
|
-
return useMutation({
|
|
586
|
-
...mutation,
|
|
587
|
-
async mutationFn(variables) {
|
|
588
|
-
return Actions.burnSync(config, variables as never)
|
|
589
|
-
},
|
|
590
|
-
mutationKey: ['burnSync'],
|
|
591
|
-
}) as never
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export declare namespace useBurnSync {
|
|
595
|
-
type Parameters<
|
|
596
|
-
config extends Config = Config,
|
|
597
|
-
context = unknown,
|
|
598
|
-
> = ConfigParameter<config> & {
|
|
599
|
-
mutation?:
|
|
600
|
-
| UseMutationParameters<
|
|
601
|
-
Actions.burnSync.ReturnValue,
|
|
602
|
-
DefaultError,
|
|
603
|
-
Actions.burnSync.Parameters<config>,
|
|
604
|
-
context
|
|
605
|
-
>
|
|
606
|
-
| undefined
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
type ReturnType<
|
|
610
|
-
config extends Config = Config,
|
|
611
|
-
context = unknown,
|
|
612
|
-
> = UseMutationResult<
|
|
613
|
-
Actions.burnSync.ReturnValue,
|
|
614
|
-
DefaultError,
|
|
615
|
-
Actions.burnSync.Parameters<config>,
|
|
616
|
-
context
|
|
617
|
-
>
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Hook for watching rebalance swap events.
|
|
622
|
-
*
|
|
623
|
-
* @example
|
|
624
|
-
* ```tsx
|
|
625
|
-
* import { Hooks } from 'tempo.ts/wagmi'
|
|
626
|
-
*
|
|
627
|
-
* function App() {
|
|
628
|
-
* Hooks.amm.useWatchRebalanceSwap({
|
|
629
|
-
* onRebalanceSwap(args) {
|
|
630
|
-
* console.log('Rebalance swap:', args)
|
|
631
|
-
* },
|
|
632
|
-
* })
|
|
633
|
-
*
|
|
634
|
-
* return <div>Watching for rebalance swaps...</div>
|
|
635
|
-
* }
|
|
636
|
-
* ```
|
|
637
|
-
*
|
|
638
|
-
* @param parameters - Parameters.
|
|
639
|
-
*/
|
|
640
|
-
export function useWatchRebalanceSwap<
|
|
641
|
-
config extends Config = ResolvedRegister['config'],
|
|
642
|
-
>(parameters: useWatchRebalanceSwap.Parameters<config> = {}) {
|
|
643
|
-
const { enabled = true, onRebalanceSwap, ...rest } = parameters
|
|
644
|
-
|
|
645
|
-
const config = useConfig({ config: parameters.config })
|
|
646
|
-
const configChainId = useChainId({ config })
|
|
647
|
-
const chainId = parameters.chainId ?? configChainId
|
|
648
|
-
|
|
649
|
-
useEffect(() => {
|
|
650
|
-
if (!enabled) return
|
|
651
|
-
if (!onRebalanceSwap) return
|
|
652
|
-
return Actions.watchRebalanceSwap(config, {
|
|
653
|
-
...rest,
|
|
654
|
-
chainId,
|
|
655
|
-
onRebalanceSwap,
|
|
656
|
-
})
|
|
657
|
-
}, [config, enabled, onRebalanceSwap, rest, chainId])
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
export declare namespace useWatchRebalanceSwap {
|
|
661
|
-
type Parameters<config extends Config = Config> = UnionCompute<
|
|
662
|
-
ExactPartial<Actions.watchRebalanceSwap.Parameters<config>> &
|
|
663
|
-
ConfigParameter<config> & { enabled?: boolean | undefined }
|
|
664
|
-
>
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* Hook for watching fee swap events.
|
|
669
|
-
*
|
|
670
|
-
* @example
|
|
671
|
-
* ```tsx
|
|
672
|
-
* import { Hooks } from 'tempo.ts/wagmi'
|
|
673
|
-
*
|
|
674
|
-
* function App() {
|
|
675
|
-
* Hooks.amm.useWatchFeeSwap({
|
|
676
|
-
* onFeeSwap(args) {
|
|
677
|
-
* console.log('Fee swap:', args)
|
|
678
|
-
* },
|
|
679
|
-
* })
|
|
680
|
-
*
|
|
681
|
-
* return <div>Watching for fee swaps...</div>
|
|
682
|
-
* }
|
|
683
|
-
* ```
|
|
684
|
-
*
|
|
685
|
-
* @param parameters - Parameters.
|
|
686
|
-
*/
|
|
687
|
-
export function useWatchFeeSwap<
|
|
688
|
-
config extends Config = ResolvedRegister['config'],
|
|
689
|
-
>(parameters: useWatchFeeSwap.Parameters<config> = {}) {
|
|
690
|
-
const { enabled = true, onFeeSwap, ...rest } = parameters
|
|
691
|
-
|
|
692
|
-
const config = useConfig({ config: parameters.config })
|
|
693
|
-
const configChainId = useChainId({ config })
|
|
694
|
-
const chainId = parameters.chainId ?? configChainId
|
|
695
|
-
|
|
696
|
-
useEffect(() => {
|
|
697
|
-
if (!enabled) return
|
|
698
|
-
if (!onFeeSwap) return
|
|
699
|
-
return Actions.watchFeeSwap(config, {
|
|
700
|
-
...rest,
|
|
701
|
-
chainId,
|
|
702
|
-
onFeeSwap,
|
|
703
|
-
})
|
|
704
|
-
}, [config, enabled, onFeeSwap, rest, chainId])
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
export declare namespace useWatchFeeSwap {
|
|
708
|
-
type Parameters<config extends Config = Config> = UnionCompute<
|
|
709
|
-
ExactPartial<Actions.watchFeeSwap.Parameters<config>> &
|
|
710
|
-
ConfigParameter<config> & { enabled?: boolean | undefined }
|
|
711
|
-
>
|
|
712
|
-
}
|
|
713
|
-
|
|
714
318
|
/**
|
|
715
319
|
* Hook for watching liquidity mint events.
|
|
716
320
|
*
|
|
@@ -757,50 +361,3 @@ export declare namespace useWatchMint {
|
|
|
757
361
|
ConfigParameter<config> & { enabled?: boolean | undefined }
|
|
758
362
|
>
|
|
759
363
|
}
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Hook for watching liquidity burn events.
|
|
763
|
-
*
|
|
764
|
-
* @example
|
|
765
|
-
* ```tsx
|
|
766
|
-
* import { Hooks } from 'tempo.ts/wagmi'
|
|
767
|
-
*
|
|
768
|
-
* function App() {
|
|
769
|
-
* Hooks.amm.useWatchBurn({
|
|
770
|
-
* onBurn(args) {
|
|
771
|
-
* console.log('Liquidity removed:', args)
|
|
772
|
-
* },
|
|
773
|
-
* })
|
|
774
|
-
*
|
|
775
|
-
* return <div>Watching for liquidity removals...</div>
|
|
776
|
-
* }
|
|
777
|
-
* ```
|
|
778
|
-
*
|
|
779
|
-
* @param parameters - Parameters.
|
|
780
|
-
*/
|
|
781
|
-
export function useWatchBurn<
|
|
782
|
-
config extends Config = ResolvedRegister['config'],
|
|
783
|
-
>(parameters: useWatchBurn.Parameters<config> = {}) {
|
|
784
|
-
const { enabled = true, onBurn, ...rest } = parameters
|
|
785
|
-
|
|
786
|
-
const config = useConfig({ config: parameters.config })
|
|
787
|
-
const configChainId = useChainId({ config })
|
|
788
|
-
const chainId = parameters.chainId ?? configChainId
|
|
789
|
-
|
|
790
|
-
useEffect(() => {
|
|
791
|
-
if (!enabled) return
|
|
792
|
-
if (!onBurn) return
|
|
793
|
-
return Actions.watchBurn(config, {
|
|
794
|
-
...rest,
|
|
795
|
-
chainId,
|
|
796
|
-
onBurn,
|
|
797
|
-
})
|
|
798
|
-
}, [config, enabled, onBurn, rest, chainId])
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
export declare namespace useWatchBurn {
|
|
802
|
-
type Parameters<config extends Config = Config> = UnionCompute<
|
|
803
|
-
ExactPartial<Actions.watchBurn.Parameters<config>> &
|
|
804
|
-
ConfigParameter<config> & { enabled?: boolean | undefined }
|
|
805
|
-
>
|
|
806
|
-
}
|
|
@@ -1,125 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Address } from 'viem'
|
|
2
2
|
import { describe, expect, test, vi } from 'vitest'
|
|
3
3
|
import { useConnect } from 'wagmi'
|
|
4
4
|
import { config, renderHook, setupToken } from '../../../test/wagmi/config.js'
|
|
5
5
|
import * as hooks from './reward.js'
|
|
6
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
7
|
describe('useGetTotalPerSecond', () => {
|
|
124
8
|
test('default', async () => {
|
|
125
9
|
const { token } = await setupToken()
|
|
@@ -192,28 +76,3 @@ describe('useSetRecipientSync', () => {
|
|
|
192
76
|
)
|
|
193
77
|
})
|
|
194
78
|
})
|
|
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
|
-
})
|