tempo.ts 0.7.0 → 0.7.2
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 +38 -0
- package/dist/server/Handler.d.ts +12 -2
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +21 -3
- package/dist/server/Handler.js.map +1 -1
- package/dist/viem/Actions/amm.d.ts +1213 -51
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +452 -0
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +225 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +248 -0
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Hooks/amm.d.ts +236 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
- package/dist/wagmi/Hooks/amm.js +285 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -1
- package/package.json +1 -1
- package/src/server/Handler.test.ts +223 -0
- package/src/server/Handler.ts +41 -3
- package/src/viem/Actions/amm.ts +672 -0
- package/src/wagmi/Actions/amm.ts +346 -0
- package/src/wagmi/Hooks/amm.ts +443 -0
package/src/wagmi/Hooks/amm.ts
CHANGED
|
@@ -154,6 +154,157 @@ 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
|
+
|
|
157
308
|
/**
|
|
158
309
|
* Hook for adding liquidity to a pool.
|
|
159
310
|
*
|
|
@@ -315,6 +466,251 @@ export declare namespace useMintSync {
|
|
|
315
466
|
>
|
|
316
467
|
}
|
|
317
468
|
|
|
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
|
+
|
|
318
714
|
/**
|
|
319
715
|
* Hook for watching liquidity mint events.
|
|
320
716
|
*
|
|
@@ -361,3 +757,50 @@ export declare namespace useWatchMint {
|
|
|
361
757
|
ConfigParameter<config> & { enabled?: boolean | undefined }
|
|
362
758
|
>
|
|
363
759
|
}
|
|
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
|
+
}
|