tempo.ts 0.6.1 → 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.
Files changed (113) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/README.md +6 -2
  3. package/dist/ox/Transaction.js +1 -1
  4. package/dist/ox/Transaction.js.map +1 -1
  5. package/dist/server/Handler.d.ts +346 -0
  6. package/dist/server/Handler.d.ts.map +1 -0
  7. package/dist/server/Handler.js +441 -0
  8. package/dist/server/Handler.js.map +1 -0
  9. package/dist/server/Kv.d.ts +16 -0
  10. package/dist/server/Kv.d.ts.map +1 -0
  11. package/dist/server/Kv.js +25 -0
  12. package/dist/server/Kv.js.map +1 -0
  13. package/dist/server/index.d.ts +3 -0
  14. package/dist/server/index.d.ts.map +1 -0
  15. package/dist/server/index.js +3 -0
  16. package/dist/server/index.js.map +1 -0
  17. package/dist/server/internal/requestListener.d.ts +124 -0
  18. package/dist/server/internal/requestListener.d.ts.map +1 -0
  19. package/dist/server/internal/requestListener.js +174 -0
  20. package/dist/server/internal/requestListener.js.map +1 -0
  21. package/dist/viem/Actions/account.d.ts +40 -0
  22. package/dist/viem/Actions/account.d.ts.map +1 -0
  23. package/dist/viem/Actions/account.js +87 -0
  24. package/dist/viem/Actions/account.js.map +1 -0
  25. package/dist/viem/Actions/amm.d.ts +51 -1245
  26. package/dist/viem/Actions/amm.d.ts.map +1 -1
  27. package/dist/viem/Actions/amm.js +15 -478
  28. package/dist/viem/Actions/amm.js.map +1 -1
  29. package/dist/viem/Actions/index.d.ts +1 -0
  30. package/dist/viem/Actions/index.d.ts.map +1 -1
  31. package/dist/viem/Actions/index.js +1 -0
  32. package/dist/viem/Actions/index.js.map +1 -1
  33. package/dist/viem/Actions/reward.d.ts +0 -1067
  34. package/dist/viem/Actions/reward.d.ts.map +1 -1
  35. package/dist/viem/Actions/reward.js +4 -212
  36. package/dist/viem/Actions/reward.js.map +1 -1
  37. package/dist/viem/Decorator.d.ts +28 -263
  38. package/dist/viem/Decorator.d.ts.map +1 -1
  39. package/dist/viem/Decorator.js +2 -10
  40. package/dist/viem/Decorator.js.map +1 -1
  41. package/dist/viem/Storage.d.ts +23 -0
  42. package/dist/viem/Storage.d.ts.map +1 -0
  43. package/dist/viem/Storage.js +47 -0
  44. package/dist/viem/Storage.js.map +1 -0
  45. package/dist/viem/Transport.d.ts +10 -1
  46. package/dist/viem/Transport.d.ts.map +1 -1
  47. package/dist/viem/Transport.js +22 -3
  48. package/dist/viem/Transport.js.map +1 -1
  49. package/dist/viem/internal/utils.d.ts +6 -0
  50. package/dist/viem/internal/utils.d.ts.map +1 -1
  51. package/dist/viem/internal/utils.js +24 -0
  52. package/dist/viem/internal/utils.js.map +1 -1
  53. package/dist/wagmi/Actions/amm.d.ts +0 -225
  54. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  55. package/dist/wagmi/Actions/amm.js +0 -248
  56. package/dist/wagmi/Actions/amm.js.map +1 -1
  57. package/dist/wagmi/Actions/reward.d.ts +0 -110
  58. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  59. package/dist/wagmi/Actions/reward.js +0 -121
  60. package/dist/wagmi/Actions/reward.js.map +1 -1
  61. package/dist/wagmi/Connector.d.ts +6 -17
  62. package/dist/wagmi/Connector.d.ts.map +1 -1
  63. package/dist/wagmi/Connector.js +17 -43
  64. package/dist/wagmi/Connector.js.map +1 -1
  65. package/dist/wagmi/Hooks/amm.d.ts +0 -236
  66. package/dist/wagmi/Hooks/amm.d.ts.map +1 -1
  67. package/dist/wagmi/Hooks/amm.js +0 -285
  68. package/dist/wagmi/Hooks/amm.js.map +1 -1
  69. package/dist/wagmi/Hooks/reward.d.ts +0 -88
  70. package/dist/wagmi/Hooks/reward.d.ts.map +1 -1
  71. package/dist/wagmi/Hooks/reward.js +0 -103
  72. package/dist/wagmi/Hooks/reward.js.map +1 -1
  73. package/dist/wagmi/KeyManager.d.ts +57 -0
  74. package/dist/wagmi/KeyManager.d.ts.map +1 -0
  75. package/dist/wagmi/KeyManager.js +101 -0
  76. package/dist/wagmi/KeyManager.js.map +1 -0
  77. package/dist/wagmi/index.d.ts +1 -0
  78. package/dist/wagmi/index.d.ts.map +1 -1
  79. package/dist/wagmi/index.js +1 -0
  80. package/dist/wagmi/index.js.map +1 -1
  81. package/package.json +8 -2
  82. package/src/ox/Transaction.ts +1 -1
  83. package/src/ox/e2e.test.ts +7 -0
  84. package/src/server/Handler.test.ts +566 -0
  85. package/src/server/Handler.ts +577 -0
  86. package/src/server/Kv.ts +40 -0
  87. package/src/server/index.ts +2 -0
  88. package/src/server/internal/requestListener.ts +285 -0
  89. package/src/viem/Actions/account.test.ts +414 -0
  90. package/src/viem/Actions/account.ts +108 -0
  91. package/src/viem/Actions/amm.test.ts +10 -284
  92. package/src/viem/Actions/amm.ts +88 -768
  93. package/src/viem/Actions/index.ts +1 -0
  94. package/src/viem/Actions/reward.test.ts +4 -212
  95. package/src/viem/Actions/reward.ts +4 -291
  96. package/src/viem/Decorator.test.ts +1 -0
  97. package/src/viem/Decorator.ts +32 -294
  98. package/src/viem/Storage.ts +88 -0
  99. package/src/viem/Transport.ts +40 -2
  100. package/src/viem/e2e.test.ts +106 -3
  101. package/src/viem/internal/utils.ts +21 -0
  102. package/src/wagmi/Actions/amm.test.ts +7 -85
  103. package/src/wagmi/Actions/amm.ts +0 -346
  104. package/src/wagmi/Actions/reward.test.ts +0 -99
  105. package/src/wagmi/Actions/reward.ts +0 -203
  106. package/src/wagmi/Connector.test.ts +4 -1
  107. package/src/wagmi/Connector.ts +24 -58
  108. package/src/wagmi/Hooks/amm.test.ts +8 -200
  109. package/src/wagmi/Hooks/amm.ts +0 -443
  110. package/src/wagmi/Hooks/reward.test.ts +1 -142
  111. package/src/wagmi/Hooks/reward.ts +0 -196
  112. package/src/wagmi/KeyManager.ts +159 -0
  113. package/src/wagmi/index.ts +1 -0
@@ -220,486 +220,7 @@ export namespace getLiquidityBalance {
220
220
  }
221
221
 
222
222
  /**
223
- * Performs a rebalance swap from validator token to user token.
224
- *
225
- * @example
226
- * ```ts
227
- * import { createClient, http } from 'viem'
228
- * import { tempo } from 'tempo.ts/chains'
229
- * import { Actions } from 'tempo.ts/viem'
230
- * import { privateKeyToAccount } from 'viem/accounts'
231
- *
232
- * const client = createClient({
233
- * account: privateKeyToAccount('0x...'),
234
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
235
- * transport: http(),
236
- * })
237
- *
238
- * const hash = await Actions.amm.rebalanceSwap(client, {
239
- * userToken: '0x...',
240
- * validatorToken: '0x...',
241
- * amountOut: 100n,
242
- * to: '0x...',
243
- * })
244
- * ```
245
- *
246
- * @param client - Client.
247
- * @param parameters - Parameters.
248
- * @returns The transaction hash.
249
- */
250
- export async function rebalanceSwap<
251
- chain extends Chain | undefined,
252
- account extends Account | undefined,
253
- >(
254
- client: Client<Transport, chain, account>,
255
- parameters: rebalanceSwap.Parameters<chain, account>,
256
- ): Promise<rebalanceSwap.ReturnValue> {
257
- return rebalanceSwap.inner(writeContract, client, parameters)
258
- }
259
-
260
- export namespace rebalanceSwap {
261
- export type Parameters<
262
- chain extends Chain | undefined = Chain | undefined,
263
- account extends Account | undefined = Account | undefined,
264
- > = WriteParameters<chain, account> & Args
265
-
266
- export type Args = {
267
- /** Amount of user token to receive. */
268
- amountOut: bigint
269
- /** Address to send the user token to. */
270
- to: Address
271
- /** Address or ID of the user token. */
272
- userToken: TokenId.TokenIdOrAddress
273
- /** Address or ID of the validator token. */
274
- validatorToken: TokenId.TokenIdOrAddress
275
- }
276
-
277
- export type ReturnValue = WriteContractReturnType
278
-
279
- /** @internal */
280
- export async function inner<
281
- action extends typeof writeContract | typeof writeContractSync,
282
- chain extends Chain | undefined,
283
- account extends Account | undefined,
284
- >(
285
- action: action,
286
- client: Client<Transport, chain, account>,
287
- parameters: rebalanceSwap.Parameters<chain, account>,
288
- ): Promise<ReturnType<action>> {
289
- const { userToken, validatorToken, amountOut, to, ...rest } = parameters
290
- const call = rebalanceSwap.call({
291
- userToken,
292
- validatorToken,
293
- amountOut,
294
- to,
295
- })
296
- return (await action(client, {
297
- ...rest,
298
- ...call,
299
- } as never)) as never
300
- }
301
-
302
- /**
303
- * Defines a call to the `rebalanceSwap` function.
304
- *
305
- * Can be passed as a parameter to:
306
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
307
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
308
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
309
- *
310
- * @example
311
- * ```ts
312
- * import { createClient, http, walletActions } from 'viem'
313
- * import { tempo } from 'tempo.ts/chains'
314
- * import { Actions } from 'tempo.ts/viem'
315
- *
316
- * const client = createClient({
317
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
318
- * transport: http(),
319
- * }).extend(walletActions)
320
- *
321
- * const { result } = await client.sendCalls({
322
- * calls: [
323
- * actions.amm.rebalanceSwap.call({
324
- * userToken: '0x20c0...beef',
325
- * validatorToken: '0x20c0...babe',
326
- * amountOut: 100n,
327
- * to: '0xfeed...fede',
328
- * }),
329
- * actions.amm.rebalanceSwap.call({
330
- * userToken: '0x20c0...babe',
331
- * validatorToken: '0x20c0...babe',
332
- * amountOut: 100n,
333
- * to: '0xfeed...fede',
334
- * }),
335
- * ]
336
- * })
337
- * ```
338
- *
339
- * @param args - Arguments.
340
- * @returns The call.
341
- */
342
- export function call(args: Args) {
343
- const { userToken, validatorToken, amountOut, to } = args
344
- return defineCall({
345
- address: Addresses.feeManager,
346
- abi: Abis.feeAmm,
347
- functionName: 'rebalanceSwap',
348
- args: [
349
- TokenId.toAddress(userToken),
350
- TokenId.toAddress(validatorToken),
351
- amountOut,
352
- to,
353
- ],
354
- })
355
- }
356
-
357
- /**
358
- * Extracts the `RebalanceSwap` event from logs.
359
- *
360
- * @param logs - The logs.
361
- * @returns The `RebalanceSwap` event.
362
- */
363
- export function extractEvent(logs: Log[]) {
364
- const [log] = parseEventLogs({
365
- abi: Abis.feeAmm,
366
- logs,
367
- eventName: 'RebalanceSwap',
368
- strict: true,
369
- })
370
- if (!log) throw new Error('`RebalanceSwap` event not found.')
371
- return log
372
- }
373
- }
374
-
375
- /**
376
- * Performs a rebalance swap from validator token to user token.
377
- *
378
- * @example
379
- * ```ts
380
- * import { createClient, http } from 'viem'
381
- * import { tempo } from 'tempo.ts/chains'
382
- * import { Actions } from 'tempo.ts/viem'
383
- * import { privateKeyToAccount } from 'viem/accounts'
384
- *
385
- * const client = createClient({
386
- * account: privateKeyToAccount('0x...'),
387
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
388
- * transport: http(),
389
- * })
390
- *
391
- * const result = await Actions.amm.rebalanceSwapSync(client, {
392
- * userToken: '0x...',
393
- * validatorToken: '0x...',
394
- * amountOut: 100n,
395
- * to: '0x...',
396
- * })
397
- * ```
398
- *
399
- * @param client - Client.
400
- * @param parameters - Parameters.
401
- * @returns The transaction receipt and event data.
402
- */
403
- export async function rebalanceSwapSync<
404
- chain extends Chain | undefined,
405
- account extends Account | undefined,
406
- >(
407
- client: Client<Transport, chain, account>,
408
- parameters: rebalanceSwapSync.Parameters<chain, account>,
409
- ): Promise<rebalanceSwapSync.ReturnValue> {
410
- const { throwOnReceiptRevert = true, ...rest } = parameters
411
- const receipt = await rebalanceSwap.inner(writeContractSync, client, {
412
- ...rest,
413
- throwOnReceiptRevert,
414
- } as never)
415
- const { args } = rebalanceSwap.extractEvent(receipt.logs)
416
- return {
417
- ...args,
418
- receipt,
419
- } as never
420
- }
421
-
422
- export namespace rebalanceSwapSync {
423
- export type Parameters<
424
- chain extends Chain | undefined = Chain | undefined,
425
- account extends Account | undefined = Account | undefined,
426
- > = rebalanceSwap.Parameters<chain, account>
427
-
428
- export type Args = rebalanceSwap.Args
429
-
430
- export type ReturnValue = Compute<
431
- GetEventArgs<
432
- typeof Abis.feeAmm,
433
- 'RebalanceSwap',
434
- { IndexedOnly: false; Required: true }
435
- > & {
436
- /** Transaction receipt. */
437
- receipt: TransactionReceipt
438
- }
439
- >
440
- }
441
-
442
- /**
443
- * Adds liquidity to a pool.
444
- *
445
- * @example
446
- * ```ts
447
- * import { createClient, http } from 'viem'
448
- * import { tempo } from 'tempo.ts/chains'
449
- * import { Actions } from 'tempo.ts/viem'
450
- * import { privateKeyToAccount } from 'viem/accounts'
451
- *
452
- * const client = createClient({
453
- * account: privateKeyToAccount('0x...'),
454
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
455
- * transport: http(),
456
- * })
457
- *
458
- * const hash = await Actions.amm.mint(client, {
459
- * userToken: {
460
- * address: '0x20c0...beef',
461
- * amount: 100n,
462
- * },
463
- * validatorToken: {
464
- * address: '0x20c0...babe',
465
- * amount: 100n,
466
- * },
467
- * to: '0xfeed...fede',
468
- * })
469
- * ```
470
- *
471
- * @param client - Client.
472
- * @param parameters - Parameters.
473
- * @returns The transaction hash.
474
- */
475
- export async function mint<
476
- chain extends Chain | undefined,
477
- account extends Account | undefined,
478
- >(
479
- client: Client<Transport, chain, account>,
480
- parameters: mint.Parameters<chain, account>,
481
- ): Promise<mint.ReturnValue> {
482
- return mint.inner(writeContract, client, parameters)
483
- }
484
-
485
- export namespace mint {
486
- export type Parameters<
487
- chain extends Chain | undefined = Chain | undefined,
488
- account extends Account | undefined = Account | undefined,
489
- > = WriteParameters<chain, account> & Args
490
-
491
- export type Args = {
492
- /** Address to mint LP tokens to. */
493
- to: Address
494
- /** User token address and amount. */
495
- userToken: {
496
- /** Address or ID of the user token. */
497
- address: TokenId.TokenIdOrAddress
498
- /** Amount of user token to add. */
499
- amount?: bigint | undefined
500
- }
501
- /** Validator token address and amount. */
502
- validatorToken: {
503
- /** Address or ID of the validator token. */
504
- address: TokenId.TokenIdOrAddress
505
- /** Amount of validator token to add. */
506
- amount: bigint
507
- }
508
- }
509
-
510
- export type ReturnValue = WriteContractReturnType
511
-
512
- /** @internal */
513
- export async function inner<
514
- action extends typeof writeContract | typeof writeContractSync,
515
- chain extends Chain | undefined,
516
- account extends Account | undefined,
517
- >(
518
- action: action,
519
- client: Client<Transport, chain, account>,
520
- parameters: mint.Parameters<chain, account>,
521
- ): Promise<ReturnType<action>> {
522
- const { to, userToken, validatorToken, ...rest } = parameters
523
- const call = mint.call({ to, userToken, validatorToken })
524
- return (await action(client, {
525
- ...rest,
526
- ...call,
527
- } as never)) as never
528
- }
529
-
530
- /**
531
- * Defines a call to the `mint` function.
532
- *
533
- * Can be passed as a parameter to:
534
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
535
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
536
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
537
- *
538
- * @example
539
- * ```ts
540
- * import { createClient, http, walletActions } from 'viem'
541
- * import { tempo } from 'tempo.ts/chains'
542
- * import { Actions } from 'tempo.ts/viem'
543
- *
544
- * const client = createClient({
545
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
546
- * transport: http(),
547
- * }).extend(walletActions)
548
- *
549
- * const { result } = await client.sendCalls({
550
- * calls: [
551
- * actions.amm.mint.call({
552
- * userToken: {
553
- * address: '0x20c0...beef',
554
- * amount: 100n,
555
- * },
556
- * validatorToken: {
557
- * address: '0x20c0...babe',
558
- * amount: 100n,
559
- * },
560
- * to: '0xfeed...fede',
561
- * }),
562
- * actions.amm.mint.call({
563
- * userToken: {
564
- * address: '0x20c0...babe',
565
- * amount: 100n,
566
- * },
567
- * validatorToken: {
568
- * address: '0x20c0...babe',
569
- * amount: 100n,
570
- * },
571
- * to: '0xfeed...fede',
572
- * }),
573
- * ]
574
- * })
575
- * ```
576
- *
577
- * @param args - Arguments.
578
- * @returns The call.
579
- */
580
- export function call(args: Args) {
581
- const { to, userToken, validatorToken } = args
582
- const callArgs = (() => {
583
- if (userToken.amount)
584
- return {
585
- functionName: 'mint',
586
- args: [
587
- TokenId.toAddress(userToken.address),
588
- TokenId.toAddress(validatorToken.address),
589
- userToken.amount,
590
- validatorToken.amount,
591
- to,
592
- ],
593
- } as const
594
- return {
595
- functionName: 'mintWithValidatorToken',
596
- args: [
597
- TokenId.toAddress(userToken.address),
598
- TokenId.toAddress(validatorToken.address),
599
- validatorToken.amount,
600
- to,
601
- ],
602
- } as const
603
- })()
604
- return defineCall({
605
- address: Addresses.feeManager,
606
- abi: Abis.feeAmm,
607
- ...callArgs,
608
- })
609
- }
610
-
611
- /**
612
- * Extracts the `Mint` event from logs.
613
- *
614
- * @param logs - The logs.
615
- * @returns The `Mint` event.
616
- */
617
- export function extractEvent(logs: Log[]) {
618
- const [log] = parseEventLogs({
619
- abi: Abis.feeAmm,
620
- logs,
621
- eventName: 'Mint',
622
- strict: true,
623
- })
624
- if (!log) throw new Error('`Mint` event not found.')
625
- return log
626
- }
627
- }
628
-
629
- /**
630
- * Adds liquidity to a pool.
631
- *
632
- * @example
633
- * ```ts
634
- * import { createClient, http } from 'viem'
635
- * import { tempo } from 'tempo.ts/chains'
636
- * import { Actions } from 'tempo.ts/viem'
637
- * import { privateKeyToAccount } from 'viem/accounts'
638
- *
639
- * const client = createClient({
640
- * account: privateKeyToAccount('0x...'),
641
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
642
- * transport: http(),
643
- * })
644
- *
645
- * const hash = await Actions.amm.mint(client, {
646
- * userToken: {
647
- * address: '0x20c0...beef',
648
- * amount: 100n,
649
- * },
650
- * validatorToken: {
651
- * address: '0x20c0...babe',
652
- * amount: 100n,
653
- * },
654
- * to: '0xfeed...fede',
655
- * })
656
- * ```
657
- *
658
- * @param client - Client.
659
- * @param parameters - Parameters.
660
- * @returns The transaction receipt and event data.
661
- */
662
- export async function mintSync<
663
- chain extends Chain | undefined,
664
- account extends Account | undefined,
665
- >(
666
- client: Client<Transport, chain, account>,
667
- parameters: mintSync.Parameters<chain, account>,
668
- ): Promise<mintSync.ReturnValue> {
669
- const { throwOnReceiptRevert = true, ...rest } = parameters
670
- const receipt = await mint.inner(writeContractSync, client, {
671
- ...rest,
672
- throwOnReceiptRevert,
673
- } as never)
674
- const { args } = mint.extractEvent(receipt.logs)
675
- return {
676
- ...args,
677
- receipt,
678
- } as never
679
- }
680
-
681
- export namespace mintSync {
682
- export type Parameters<
683
- chain extends Chain | undefined = Chain | undefined,
684
- account extends Account | undefined = Account | undefined,
685
- > = mint.Parameters<chain, account>
686
-
687
- export type Args = mint.Args
688
-
689
- export type ReturnValue = Compute<
690
- GetEventArgs<
691
- typeof Abis.feeAmm,
692
- 'Mint',
693
- { IndexedOnly: false; Required: true }
694
- > & {
695
- /** Transaction receipt. */
696
- receipt: TransactionReceipt
697
- }
698
- >
699
- }
700
-
701
- /**
702
- * Removes liquidity from a pool.
223
+ * Adds liquidity to a pool.
703
224
  *
704
225
  * @example
705
226
  * ```ts
@@ -714,10 +235,15 @@ export namespace mintSync {
714
235
  * transport: http(),
715
236
  * })
716
237
  *
717
- * const hash = await Actions.amm.burn(client, {
718
- * userToken: '0x20c0...beef',
719
- * validatorToken: '0x20c0...babe',
720
- * liquidity: 50n,
238
+ * const hash = await Actions.amm.mint(client, {
239
+ * userToken: {
240
+ * address: '0x20c0...beef',
241
+ * amount: 100n,
242
+ * },
243
+ * validatorToken: {
244
+ * address: '0x20c0...babe',
245
+ * amount: 100n,
246
+ * },
721
247
  * to: '0xfeed...fede',
722
248
  * })
723
249
  * ```
@@ -726,31 +252,31 @@ export namespace mintSync {
726
252
  * @param parameters - Parameters.
727
253
  * @returns The transaction hash.
728
254
  */
729
- export async function burn<
255
+ export async function mint<
730
256
  chain extends Chain | undefined,
731
257
  account extends Account | undefined,
732
258
  >(
733
259
  client: Client<Transport, chain, account>,
734
- parameters: burn.Parameters<chain, account>,
735
- ): Promise<burn.ReturnValue> {
736
- return burn.inner(writeContract, client, parameters)
260
+ parameters: mint.Parameters<chain, account>,
261
+ ): Promise<mint.ReturnValue> {
262
+ return mint.inner(writeContract, client, parameters)
737
263
  }
738
264
 
739
- export namespace burn {
265
+ export namespace mint {
740
266
  export type Parameters<
741
267
  chain extends Chain | undefined = Chain | undefined,
742
268
  account extends Account | undefined = Account | undefined,
743
269
  > = WriteParameters<chain, account> & Args
744
270
 
745
271
  export type Args = {
746
- /** Amount of LP tokens to burn. */
747
- liquidity: bigint
748
- /** Address to send tokens to. */
272
+ /** Address to mint LP tokens to. */
749
273
  to: Address
750
- /** Address or ID of the user token. */
751
- userToken: TokenId.TokenIdOrAddress
752
- /** Address or ID of the validator token. */
753
- validatorToken: TokenId.TokenIdOrAddress
274
+ /** User token address. */
275
+ userTokenAddress: TokenId.TokenIdOrAddress
276
+ /** Validator token address. */
277
+ validatorTokenAddress: TokenId.TokenIdOrAddress
278
+ /** Amount of validator token to add. */
279
+ validatorTokenAmount: bigint
754
280
  }
755
281
 
756
282
  export type ReturnValue = WriteContractReturnType
@@ -763,10 +289,21 @@ export namespace burn {
763
289
  >(
764
290
  action: action,
765
291
  client: Client<Transport, chain, account>,
766
- parameters: burn.Parameters<chain, account>,
292
+ parameters: mint.Parameters<chain, account>,
767
293
  ): Promise<ReturnType<action>> {
768
- const { liquidity, to, userToken, validatorToken, ...rest } = parameters
769
- const call = burn.call({ liquidity, to, userToken, validatorToken })
294
+ const {
295
+ to,
296
+ userTokenAddress,
297
+ validatorTokenAddress,
298
+ validatorTokenAmount,
299
+ ...rest
300
+ } = parameters
301
+ const call = mint.call({
302
+ to,
303
+ userTokenAddress,
304
+ validatorTokenAddress,
305
+ validatorTokenAmount,
306
+ })
770
307
  return (await action(client, {
771
308
  ...rest,
772
309
  ...call,
@@ -774,7 +311,7 @@ export namespace burn {
774
311
  }
775
312
 
776
313
  /**
777
- * Defines a call to the `burn` function.
314
+ * Defines a call to the `mint` function.
778
315
  *
779
316
  * Can be passed as a parameter to:
780
317
  * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
@@ -794,17 +331,27 @@ export namespace burn {
794
331
  *
795
332
  * const { result } = await client.sendCalls({
796
333
  * calls: [
797
- * actions.amm.burn.call({
798
- * liquidity: 100n,
334
+ * actions.amm.mint.call({
335
+ * userToken: {
336
+ * address: '0x20c0...beef',
337
+ * amount: 100n,
338
+ * },
339
+ * validatorToken: {
340
+ * address: '0x20c0...babe',
341
+ * amount: 100n,
342
+ * },
799
343
  * to: '0xfeed...fede',
800
- * userToken: '0x20c0...beef',
801
- * validatorToken: '0x20c0...babe',
802
344
  * }),
803
- * actions.amm.burn.call({
804
- * liquidity: 100n,
345
+ * actions.amm.mint.call({
346
+ * userToken: {
347
+ * address: '0x20c0...babe',
348
+ * amount: 100n,
349
+ * },
350
+ * validatorToken: {
351
+ * address: '0x20c0...babe',
352
+ * amount: 100n,
353
+ * },
805
354
  * to: '0xfeed...fede',
806
- * userToken: '0x20c0...babe',
807
- * validatorToken: '0x20c0...babe',
808
355
  * }),
809
356
  * ]
810
357
  * })
@@ -814,40 +361,45 @@ export namespace burn {
814
361
  * @returns The call.
815
362
  */
816
363
  export function call(args: Args) {
817
- const { liquidity, to, userToken, validatorToken } = args
364
+ const {
365
+ to,
366
+ userTokenAddress,
367
+ validatorTokenAddress,
368
+ validatorTokenAmount,
369
+ } = args
818
370
  return defineCall({
819
371
  address: Addresses.feeManager,
820
372
  abi: Abis.feeAmm,
821
- functionName: 'burn',
373
+ functionName: 'mintWithValidatorToken',
822
374
  args: [
823
- TokenId.toAddress(userToken),
824
- TokenId.toAddress(validatorToken),
825
- liquidity,
375
+ TokenId.toAddress(userTokenAddress),
376
+ TokenId.toAddress(validatorTokenAddress),
377
+ validatorTokenAmount,
826
378
  to,
827
379
  ],
828
380
  })
829
381
  }
830
382
 
831
383
  /**
832
- * Extracts the `Burn` event from logs.
384
+ * Extracts the `Mint` event from logs.
833
385
  *
834
386
  * @param logs - The logs.
835
- * @returns The `Burn` event.
387
+ * @returns The `Mint` event.
836
388
  */
837
389
  export function extractEvent(logs: Log[]) {
838
390
  const [log] = parseEventLogs({
839
391
  abi: Abis.feeAmm,
840
392
  logs,
841
- eventName: 'Burn',
393
+ eventName: 'Mint',
842
394
  strict: true,
843
395
  })
844
- if (!log) throw new Error('`Burn` event not found.')
396
+ if (!log) throw new Error('`Mint` event not found.')
845
397
  return log
846
398
  }
847
399
  }
848
400
 
849
401
  /**
850
- * Removes liquidity from a pool.
402
+ * Adds liquidity to a pool.
851
403
  *
852
404
  * @example
853
405
  * ```ts
@@ -862,10 +414,15 @@ export namespace burn {
862
414
  * transport: http(),
863
415
  * })
864
416
  *
865
- * const result = await Actions.amm.burnSync(client, {
866
- * userToken: '0x20c0...beef',
867
- * validatorToken: '0x20c0...babe',
868
- * liquidity: 50n,
417
+ * const hash = await Actions.amm.mint(client, {
418
+ * userToken: {
419
+ * address: '0x20c0...beef',
420
+ * amount: 100n,
421
+ * },
422
+ * validatorToken: {
423
+ * address: '0x20c0...babe',
424
+ * amount: 100n,
425
+ * },
869
426
  * to: '0xfeed...fede',
870
427
  * })
871
428
  * ```
@@ -874,37 +431,37 @@ export namespace burn {
874
431
  * @param parameters - Parameters.
875
432
  * @returns The transaction receipt and event data.
876
433
  */
877
- export async function burnSync<
434
+ export async function mintSync<
878
435
  chain extends Chain | undefined,
879
436
  account extends Account | undefined,
880
437
  >(
881
438
  client: Client<Transport, chain, account>,
882
- parameters: burnSync.Parameters<chain, account>,
883
- ): Promise<burnSync.ReturnValue> {
439
+ parameters: mintSync.Parameters<chain, account>,
440
+ ): Promise<mintSync.ReturnValue> {
884
441
  const { throwOnReceiptRevert = true, ...rest } = parameters
885
- const receipt = await burn.inner(writeContractSync, client, {
442
+ const receipt = await mint.inner(writeContractSync, client, {
886
443
  ...rest,
887
444
  throwOnReceiptRevert,
888
445
  } as never)
889
- const { args } = burn.extractEvent(receipt.logs)
446
+ const { args } = mint.extractEvent(receipt.logs)
890
447
  return {
891
448
  ...args,
892
449
  receipt,
893
450
  } as never
894
451
  }
895
452
 
896
- export namespace burnSync {
453
+ export namespace mintSync {
897
454
  export type Parameters<
898
455
  chain extends Chain | undefined = Chain | undefined,
899
456
  account extends Account | undefined = Account | undefined,
900
- > = burn.Parameters<chain, account>
457
+ > = mint.Parameters<chain, account>
901
458
 
902
- export type Args = burn.Args
459
+ export type Args = mint.Args
903
460
 
904
461
  export type ReturnValue = Compute<
905
462
  GetEventArgs<
906
463
  typeof Abis.feeAmm,
907
- 'Burn',
464
+ 'Mint',
908
465
  { IndexedOnly: false; Required: true }
909
466
  > & {
910
467
  /** Transaction receipt. */
@@ -913,166 +470,6 @@ export namespace burnSync {
913
470
  >
914
471
  }
915
472
 
916
- /**
917
- * Watches for rebalance swap events.
918
- *
919
- * @example
920
- * ```ts
921
- * import { createClient, http } from 'viem'
922
- * import { tempo } from 'tempo.ts/chains'
923
- * import { Actions } from 'tempo.ts/viem'
924
- *
925
- * const client = createClient({
926
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
927
- * transport: http(),
928
- * })
929
- *
930
- * const unwatch = actions.amm.watchRebalanceSwap(client, {
931
- * onRebalanceSwap: (args, log) => {
932
- * console.log('Rebalance swap:', args)
933
- * },
934
- * })
935
- * ```
936
- *
937
- * @param client - Client.
938
- * @param parameters - Parameters.
939
- * @returns A function to unsubscribe from the event.
940
- */
941
- export function watchRebalanceSwap<
942
- chain extends Chain | undefined,
943
- account extends Account | undefined,
944
- >(
945
- client: Client<Transport, chain, account>,
946
- parameters: watchRebalanceSwap.Parameters,
947
- ) {
948
- const { onRebalanceSwap, userToken, validatorToken, ...rest } = parameters
949
- return watchContractEvent(client, {
950
- ...rest,
951
- address: Addresses.feeManager,
952
- abi: Abis.feeAmm,
953
- eventName: 'RebalanceSwap',
954
- args:
955
- userToken !== undefined && validatorToken !== undefined
956
- ? {
957
- userToken: TokenId.toAddress(userToken),
958
- validatorToken: TokenId.toAddress(validatorToken),
959
- }
960
- : undefined,
961
- onLogs: (logs) => {
962
- for (const log of logs) onRebalanceSwap(log.args, log)
963
- },
964
- strict: true,
965
- })
966
- }
967
-
968
- export declare namespace watchRebalanceSwap {
969
- export type Args = GetEventArgs<
970
- typeof Abis.feeAmm,
971
- 'RebalanceSwap',
972
- { IndexedOnly: false; Required: true }
973
- >
974
-
975
- export type Log = viem_Log<
976
- bigint,
977
- number,
978
- false,
979
- ExtractAbiItem<typeof Abis.feeAmm, 'RebalanceSwap'>,
980
- true
981
- >
982
-
983
- export type Parameters = UnionOmit<
984
- WatchContractEventParameters<typeof Abis.feeAmm, 'RebalanceSwap', true>,
985
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
986
- > & {
987
- /** Callback to invoke when a rebalance swap occurs. */
988
- onRebalanceSwap: (args: Args, log: Log) => void
989
- /** Address or ID of the user token to filter events. */
990
- userToken?: TokenId.TokenIdOrAddress | undefined
991
- /** Address or ID of the validator token to filter events. */
992
- validatorToken?: TokenId.TokenIdOrAddress | undefined
993
- }
994
- }
995
-
996
- /**
997
- * Watches for fee swap events.
998
- *
999
- * @example
1000
- * ```ts
1001
- * import { createClient, http } from 'viem'
1002
- * import { tempo } from 'tempo.ts/chains'
1003
- * import { Actions } from 'tempo.ts/viem'
1004
- *
1005
- * const client = createClient({
1006
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1007
- * transport: http(),
1008
- * })
1009
- *
1010
- * const unwatch = actions.amm.watchFeeSwap(client, {
1011
- * onFeeSwap: (args, log) => {
1012
- * console.log('Fee swap:', args)
1013
- * },
1014
- * })
1015
- * ```
1016
- *
1017
- * @param client - Client.
1018
- * @param parameters - Parameters.
1019
- * @returns A function to unsubscribe from the event.
1020
- */
1021
- export function watchFeeSwap<
1022
- chain extends Chain | undefined,
1023
- account extends Account | undefined,
1024
- >(
1025
- client: Client<Transport, chain, account>,
1026
- parameters: watchFeeSwap.Parameters,
1027
- ) {
1028
- const { onFeeSwap, userToken, validatorToken, ...rest } = parameters
1029
- return watchContractEvent(client, {
1030
- ...rest,
1031
- address: Addresses.feeManager,
1032
- abi: Abis.feeAmm,
1033
- eventName: 'FeeSwap',
1034
- args:
1035
- userToken !== undefined && validatorToken !== undefined
1036
- ? {
1037
- userToken: TokenId.toAddress(userToken),
1038
- validatorToken: TokenId.toAddress(validatorToken),
1039
- }
1040
- : undefined,
1041
- onLogs: (logs) => {
1042
- for (const log of logs) onFeeSwap(log.args, log)
1043
- },
1044
- strict: true,
1045
- })
1046
- }
1047
-
1048
- export declare namespace watchFeeSwap {
1049
- export type Args = GetEventArgs<
1050
- typeof Abis.feeAmm,
1051
- 'FeeSwap',
1052
- { IndexedOnly: false; Required: true }
1053
- >
1054
-
1055
- export type Log = viem_Log<
1056
- bigint,
1057
- number,
1058
- false,
1059
- ExtractAbiItem<typeof Abis.feeAmm, 'FeeSwap'>,
1060
- true
1061
- >
1062
-
1063
- export type Parameters = UnionOmit<
1064
- WatchContractEventParameters<typeof Abis.feeAmm, 'FeeSwap', true>,
1065
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1066
- > & {
1067
- /** Callback to invoke when a fee swap occurs. */
1068
- onFeeSwap: (args: Args, log: Log) => void
1069
- /** Address or ID of the user token to filter events. */
1070
- userToken?: TokenId.TokenIdOrAddress | undefined
1071
- /** Address or ID of the validator token to filter events. */
1072
- validatorToken?: TokenId.TokenIdOrAddress | undefined
1073
- }
1074
- }
1075
-
1076
473
  /**
1077
474
  * Watches for liquidity mint events.
1078
475
  *
@@ -1177,80 +574,3 @@ export declare namespace watchMint {
1177
574
  validatorToken?: TokenId.TokenIdOrAddress | undefined
1178
575
  }
1179
576
  }
1180
-
1181
- /**
1182
- * Watches for liquidity burn events.
1183
- *
1184
- * @example
1185
- * ```ts
1186
- * import { createClient, http } from 'viem'
1187
- * import { tempo } from 'tempo.ts/chains'
1188
- * import { Actions } from 'tempo.ts/viem'
1189
- *
1190
- * const client = createClient({
1191
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1192
- * transport: http(),
1193
- * })
1194
- *
1195
- * const unwatch = actions.amm.watchBurn(client, {
1196
- * onBurn: (args, log) => {
1197
- * console.log('Liquidity removed:', args)
1198
- * },
1199
- * })
1200
- * ```
1201
- *
1202
- * @param client - Client.
1203
- * @param parameters - Parameters.
1204
- * @returns A function to unsubscribe from the event.
1205
- */
1206
- export function watchBurn<
1207
- chain extends Chain | undefined,
1208
- account extends Account | undefined,
1209
- >(client: Client<Transport, chain, account>, parameters: watchBurn.Parameters) {
1210
- const { onBurn, userToken, validatorToken, ...rest } = parameters
1211
- return watchContractEvent(client, {
1212
- ...rest,
1213
- address: Addresses.feeManager,
1214
- abi: Abis.feeAmm,
1215
- eventName: 'Burn',
1216
- args:
1217
- userToken !== undefined && validatorToken !== undefined
1218
- ? {
1219
- userToken: TokenId.toAddress(userToken),
1220
- validatorToken: TokenId.toAddress(validatorToken),
1221
- }
1222
- : undefined,
1223
- onLogs: (logs) => {
1224
- for (const log of logs) onBurn(log.args, log)
1225
- },
1226
- strict: true,
1227
- })
1228
- }
1229
-
1230
- export declare namespace watchBurn {
1231
- export type Args = GetEventArgs<
1232
- typeof Abis.feeAmm,
1233
- 'Burn',
1234
- { IndexedOnly: false; Required: true }
1235
- >
1236
-
1237
- export type Log = viem_Log<
1238
- bigint,
1239
- number,
1240
- false,
1241
- ExtractAbiItem<typeof Abis.feeAmm, 'Burn'>,
1242
- true
1243
- >
1244
-
1245
- export type Parameters = UnionOmit<
1246
- WatchContractEventParameters<typeof Abis.feeAmm, 'Burn', true>,
1247
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1248
- > & {
1249
- /** Callback to invoke when liquidity is removed. */
1250
- onBurn: (args: Args, log: Log) => void
1251
- /** Address or ID of the user token to filter events. */
1252
- userToken?: TokenId.TokenIdOrAddress | undefined
1253
- /** Address or ID of the validator token to filter events. */
1254
- validatorToken?: TokenId.TokenIdOrAddress | undefined
1255
- }
1256
- }