tempo.ts 0.11.0 → 0.12.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 (196) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/viem/Abis.d.ts +0 -2649
  75. package/dist/viem/Abis.d.ts.map +0 -1
  76. package/dist/viem/Abis.js +0 -1677
  77. package/dist/viem/Abis.js.map +0 -1
  78. package/dist/viem/Account.d.ts +0 -244
  79. package/dist/viem/Account.d.ts.map +0 -1
  80. package/dist/viem/Account.js +0 -382
  81. package/dist/viem/Account.js.map +0 -1
  82. package/dist/viem/Actions/amm.d.ts +0 -1991
  83. package/dist/viem/Actions/amm.d.ts.map +0 -1
  84. package/dist/viem/Actions/amm.js +0 -814
  85. package/dist/viem/Actions/amm.js.map +0 -1
  86. package/dist/viem/Actions/dex.d.ts +0 -3900
  87. package/dist/viem/Actions/dex.d.ts.map +0 -1
  88. package/dist/viem/Actions/dex.js +0 -1414
  89. package/dist/viem/Actions/dex.js.map +0 -1
  90. package/dist/viem/Actions/faucet.d.ts +0 -69
  91. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  92. package/dist/viem/Actions/faucet.js +0 -73
  93. package/dist/viem/Actions/faucet.js.map +0 -1
  94. package/dist/viem/Actions/fee.d.ts +0 -360
  95. package/dist/viem/Actions/fee.d.ts.map +0 -1
  96. package/dist/viem/Actions/fee.js +0 -237
  97. package/dist/viem/Actions/fee.js.map +0 -1
  98. package/dist/viem/Actions/nonce.d.ts +0 -257
  99. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  100. package/dist/viem/Actions/nonce.js +0 -228
  101. package/dist/viem/Actions/nonce.js.map +0 -1
  102. package/dist/viem/Actions/policy.d.ts +0 -1680
  103. package/dist/viem/Actions/policy.d.ts.map +0 -1
  104. package/dist/viem/Actions/policy.js +0 -875
  105. package/dist/viem/Actions/policy.js.map +0 -1
  106. package/dist/viem/Actions/reward.d.ts +0 -2422
  107. package/dist/viem/Actions/reward.d.ts.map +0 -1
  108. package/dist/viem/Actions/reward.js +0 -651
  109. package/dist/viem/Actions/reward.js.map +0 -1
  110. package/dist/viem/Actions/token.d.ts +0 -16007
  111. package/dist/viem/Actions/token.d.ts.map +0 -1
  112. package/dist/viem/Actions/token.js +0 -2936
  113. package/dist/viem/Actions/token.js.map +0 -1
  114. package/dist/viem/Addresses.d.ts +0 -9
  115. package/dist/viem/Addresses.d.ts.map +0 -1
  116. package/dist/viem/Addresses.js +0 -9
  117. package/dist/viem/Addresses.js.map +0 -1
  118. package/dist/viem/Chain.d.ts +0 -451
  119. package/dist/viem/Chain.d.ts.map +0 -1
  120. package/dist/viem/Chain.js +0 -96
  121. package/dist/viem/Chain.js.map +0 -1
  122. package/dist/viem/Formatters.d.ts +0 -10
  123. package/dist/viem/Formatters.d.ts.map +0 -1
  124. package/dist/viem/Formatters.js +0 -104
  125. package/dist/viem/Formatters.js.map +0 -1
  126. package/dist/viem/Storage.d.ts +0 -24
  127. package/dist/viem/Storage.d.ts.map +0 -1
  128. package/dist/viem/Storage.js +0 -68
  129. package/dist/viem/Storage.js.map +0 -1
  130. package/dist/viem/Transaction.d.ts +0 -76
  131. package/dist/viem/Transaction.d.ts.map +0 -1
  132. package/dist/viem/Transaction.js +0 -176
  133. package/dist/viem/Transaction.js.map +0 -1
  134. package/dist/viem/Transport.d.ts +0 -33
  135. package/dist/viem/Transport.d.ts.map +0 -1
  136. package/dist/viem/Transport.js +0 -138
  137. package/dist/viem/Transport.js.map +0 -1
  138. package/dist/viem/WebAuthnP256.d.ts +0 -82
  139. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  140. package/dist/viem/WebAuthnP256.js +0 -97
  141. package/dist/viem/WebAuthnP256.js.map +0 -1
  142. package/dist/viem/WebCryptoP256.d.ts +0 -2
  143. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  144. package/dist/viem/WebCryptoP256.js +0 -2
  145. package/dist/viem/WebCryptoP256.js.map +0 -1
  146. package/dist/viem/internal/types.d.ts +0 -20
  147. package/dist/viem/internal/types.d.ts.map +0 -1
  148. package/dist/viem/internal/types.js +0 -2
  149. package/dist/viem/internal/types.js.map +0 -1
  150. package/dist/viem/internal/utils.d.ts +0 -14
  151. package/dist/viem/internal/utils.d.ts.map +0 -1
  152. package/dist/viem/internal/utils.js +0 -33
  153. package/dist/viem/internal/utils.js.map +0 -1
  154. package/src/chains.ts +0 -54
  155. package/src/viem/Abis.ts +0 -1688
  156. package/src/viem/Account.test.ts +0 -444
  157. package/src/viem/Account.ts +0 -601
  158. package/src/viem/Actions/account.test.ts +0 -414
  159. package/src/viem/Actions/account.ts +0 -106
  160. package/src/viem/Actions/amm.test.ts +0 -381
  161. package/src/viem/Actions/amm.ts +0 -1227
  162. package/src/viem/Actions/dex.test.ts +0 -1549
  163. package/src/viem/Actions/dex.ts +0 -2150
  164. package/src/viem/Actions/faucet.ts +0 -121
  165. package/src/viem/Actions/fee.test.ts +0 -259
  166. package/src/viem/Actions/fee.ts +0 -372
  167. package/src/viem/Actions/index.ts +0 -9
  168. package/src/viem/Actions/nonce.test.ts +0 -206
  169. package/src/viem/Actions/nonce.ts +0 -347
  170. package/src/viem/Actions/policy.test.ts +0 -534
  171. package/src/viem/Actions/policy.ts +0 -1335
  172. package/src/viem/Actions/reward.test.ts +0 -434
  173. package/src/viem/Actions/reward.ts +0 -944
  174. package/src/viem/Actions/token.test.ts +0 -3029
  175. package/src/viem/Actions/token.ts +0 -4458
  176. package/src/viem/Addresses.ts +0 -9
  177. package/src/viem/Chain.bench-d.ts +0 -12
  178. package/src/viem/Chain.test.ts +0 -168
  179. package/src/viem/Chain.ts +0 -157
  180. package/src/viem/Decorator.bench-d.ts +0 -11
  181. package/src/viem/Decorator.test.ts +0 -39
  182. package/src/viem/Decorator.ts +0 -3179
  183. package/src/viem/Formatters.ts +0 -164
  184. package/src/viem/P256.ts +0 -1
  185. package/src/viem/Secp256k1.ts +0 -1
  186. package/src/viem/Storage.ts +0 -110
  187. package/src/viem/TokenIds.ts +0 -1
  188. package/src/viem/Transaction.ts +0 -382
  189. package/src/viem/Transport.ts +0 -191
  190. package/src/viem/WebAuthnP256.ts +0 -146
  191. package/src/viem/WebCryptoP256.ts +0 -1
  192. package/src/viem/e2e.test.ts +0 -1602
  193. package/src/viem/index.ts +0 -30
  194. package/src/viem/internal/types.ts +0 -69
  195. package/src/viem/internal/utils.ts +0 -58
  196. package/src/wagmi/internal/types.ts +0 -16
@@ -1,1227 +0,0 @@
1
- import { PoolId, TokenId } from 'ox/tempo'
2
- import {
3
- type Account,
4
- type Address,
5
- type Chain,
6
- type Client,
7
- type ExtractAbiItem,
8
- type GetEventArgs,
9
- type Hex,
10
- type Log,
11
- type MulticallParameters,
12
- parseEventLogs,
13
- type ReadContractReturnType,
14
- type TransactionReceipt,
15
- type Transport,
16
- type Log as viem_Log,
17
- type WatchContractEventParameters,
18
- type WriteContractReturnType,
19
- } from 'viem'
20
- import {
21
- multicall,
22
- readContract,
23
- watchContractEvent,
24
- writeContract,
25
- writeContractSync,
26
- } from 'viem/actions'
27
- import type { Compute, OneOf, UnionOmit } from '../../internal/types.js'
28
- import * as Abis from '../Abis.js'
29
- import * as Addresses from '../Addresses.js'
30
- import type { ReadParameters, WriteParameters } from '../internal/types.js'
31
- import { defineCall } from '../internal/utils.js'
32
-
33
- /**
34
- * Gets the reserves for a liquidity pool.
35
- *
36
- * @example
37
- * ```ts
38
- * import { createClient, http } from 'viem'
39
- * import { tempo } from 'tempo.ts/chains'
40
- * import { Actions } from 'tempo.ts/viem'
41
- *
42
- * const client = createClient({
43
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
44
- * transport: http(),
45
- * })
46
- *
47
- * const pool = await Actions.amm.getPool(client, {
48
- * userToken: '0x...',
49
- * validatorToken: '0x...',
50
- * })
51
- * ```
52
- *
53
- * @param client - Client.
54
- * @param parameters - Parameters.
55
- * @returns The pool reserves.
56
- */
57
- export async function getPool<chain extends Chain | undefined>(
58
- client: Client<Transport, chain>,
59
- parameters: getPool.Parameters,
60
- ): Promise<getPool.ReturnValue> {
61
- const { userToken, validatorToken, ...rest } = parameters
62
- const [pool, totalSupply] = await multicall(client, {
63
- ...rest,
64
- contracts: getPool.calls({ userToken, validatorToken }),
65
- allowFailure: false,
66
- deployless: true,
67
- })
68
- return {
69
- reserveUserToken: pool.reserveUserToken,
70
- reserveValidatorToken: pool.reserveValidatorToken,
71
- totalSupply,
72
- }
73
- }
74
-
75
- export namespace getPool {
76
- export type Parameters = UnionOmit<
77
- MulticallParameters,
78
- 'allowFailure' | 'contracts' | 'deployless'
79
- > &
80
- Args
81
-
82
- export type Args = {
83
- /** Address or ID of the user token. */
84
- userToken: TokenId.TokenIdOrAddress
85
- /** Address or ID of the validator token. */
86
- validatorToken: TokenId.TokenIdOrAddress
87
- }
88
-
89
- export type ReturnValue = Compute<{
90
- /** Reserve of user token. */
91
- reserveUserToken: bigint
92
- /** Reserve of validator token. */
93
- reserveValidatorToken: bigint
94
- /** Total supply of LP tokens. */
95
- totalSupply: bigint
96
- }>
97
-
98
- /**
99
- * Defines calls to the `getPool` and `totalSupply` functions.
100
- *
101
- * @param args - Arguments.
102
- * @returns The calls.
103
- */
104
- export function calls(args: Args) {
105
- const { userToken, validatorToken } = args
106
- return [
107
- defineCall({
108
- address: Addresses.feeManager,
109
- abi: Abis.feeAmm,
110
- args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
111
- functionName: 'getPool',
112
- }),
113
- defineCall({
114
- address: Addresses.feeManager,
115
- abi: Abis.feeAmm,
116
- args: [PoolId.from({ userToken, validatorToken })],
117
- functionName: 'totalSupply',
118
- }),
119
- ] as const
120
- }
121
- }
122
-
123
- /**
124
- * Gets the LP token balance for an account in a specific pool.
125
- *
126
- * @example
127
- * ```ts
128
- * import { createClient, http } from 'viem'
129
- * import { tempo } from 'tempo.ts/chains'
130
- * import { Actions } from 'tempo.ts/viem'
131
- *
132
- * const client = createClient({
133
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
134
- * transport: http(),
135
- * })
136
- *
137
- * const poolId = await Actions.amm.getPoolId(client, {
138
- * userToken: '0x...',
139
- * validatorToken: '0x...',
140
- * })
141
- *
142
- * const balance = await Actions.amm.getLiquidityBalance(client, {
143
- * poolId,
144
- * address: '0x...',
145
- * })
146
- * ```
147
- *
148
- * @param client - Client.
149
- * @param parameters - Parameters.
150
- * @returns The LP token balance.
151
- */
152
- export async function getLiquidityBalance<chain extends Chain | undefined>(
153
- client: Client<Transport, chain>,
154
- parameters: getLiquidityBalance.Parameters,
155
- ): Promise<getLiquidityBalance.ReturnValue> {
156
- const { address, poolId, userToken, validatorToken, ...rest } = parameters
157
- return readContract(client, {
158
- ...rest,
159
- ...getLiquidityBalance.call({
160
- address,
161
- poolId,
162
- userToken,
163
- validatorToken,
164
- } as never),
165
- })
166
- }
167
-
168
- export namespace getLiquidityBalance {
169
- export type Parameters = ReadParameters & Args
170
-
171
- export type Args = {
172
- /** Address to check balance for. */
173
- address: Address
174
- } & OneOf<
175
- | {
176
- /** Pool ID. */
177
- poolId: Hex
178
- }
179
- | {
180
- /** User token. */
181
- userToken: TokenId.TokenIdOrAddress
182
- /** Validator token. */
183
- validatorToken: TokenId.TokenIdOrAddress
184
- }
185
- >
186
-
187
- export type ReturnValue = ReadContractReturnType<
188
- typeof Abis.feeAmm,
189
- 'liquidityBalances',
190
- never
191
- >
192
-
193
- /**
194
- * Defines a call to the `liquidityBalances` function.
195
- *
196
- * @param args - Arguments.
197
- * @returns The call.
198
- */
199
- export function call(args: Args) {
200
- const { address } = args
201
- const poolId = (() => {
202
- if ('poolId' in args && args.poolId) return args.poolId!
203
- if ('userToken' in args && 'validatorToken' in args)
204
- return PoolId.from({
205
- userToken: args.userToken,
206
- validatorToken: args.validatorToken,
207
- })
208
- throw new Error(
209
- '`poolId`, or `userToken` and `validatorToken` must be provided.',
210
- )
211
- })()
212
- return defineCall({
213
- address: Addresses.feeManager,
214
- abi: Abis.feeAmm,
215
- args: [poolId, address],
216
- functionName: 'liquidityBalances',
217
- })
218
- }
219
- }
220
-
221
- /**
222
- * Performs a rebalance swap from validator token to user token.
223
- *
224
- * @example
225
- * ```ts
226
- * import { createClient, http } from 'viem'
227
- * import { tempo } from 'tempo.ts/chains'
228
- * import { Actions } from 'tempo.ts/viem'
229
- * import { privateKeyToAccount } from 'viem/accounts'
230
- *
231
- * const client = createClient({
232
- * account: privateKeyToAccount('0x...'),
233
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
234
- * transport: http(),
235
- * })
236
- *
237
- * const hash = await Actions.amm.rebalanceSwap(client, {
238
- * userToken: '0x...',
239
- * validatorToken: '0x...',
240
- * amountOut: 100n,
241
- * to: '0x...',
242
- * })
243
- * ```
244
- *
245
- * @param client - Client.
246
- * @param parameters - Parameters.
247
- * @returns The transaction hash.
248
- */
249
- export async function rebalanceSwap<
250
- chain extends Chain | undefined,
251
- account extends Account | undefined,
252
- >(
253
- client: Client<Transport, chain, account>,
254
- parameters: rebalanceSwap.Parameters<chain, account>,
255
- ): Promise<rebalanceSwap.ReturnValue> {
256
- return rebalanceSwap.inner(writeContract, client, parameters)
257
- }
258
-
259
- export namespace rebalanceSwap {
260
- export type Parameters<
261
- chain extends Chain | undefined = Chain | undefined,
262
- account extends Account | undefined = Account | undefined,
263
- > = WriteParameters<chain, account> & Args
264
-
265
- export type Args = {
266
- /** Amount of user token to receive. */
267
- amountOut: bigint
268
- /** Address to send the user token to. */
269
- to: Address
270
- /** Address or ID of the user token. */
271
- userToken: TokenId.TokenIdOrAddress
272
- /** Address or ID of the validator token. */
273
- validatorToken: TokenId.TokenIdOrAddress
274
- }
275
-
276
- export type ReturnValue = WriteContractReturnType
277
-
278
- /** @internal */
279
- export async function inner<
280
- action extends typeof writeContract | typeof writeContractSync,
281
- chain extends Chain | undefined,
282
- account extends Account | undefined,
283
- >(
284
- action: action,
285
- client: Client<Transport, chain, account>,
286
- parameters: rebalanceSwap.Parameters<chain, account>,
287
- ): Promise<ReturnType<action>> {
288
- const { userToken, validatorToken, amountOut, to, ...rest } = parameters
289
- const call = rebalanceSwap.call({
290
- userToken,
291
- validatorToken,
292
- amountOut,
293
- to,
294
- })
295
- return (await action(client, {
296
- ...rest,
297
- ...call,
298
- } as never)) as never
299
- }
300
-
301
- /**
302
- * Defines a call to the `rebalanceSwap` function.
303
- *
304
- * Can be passed as a parameter to:
305
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
306
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
307
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
308
- *
309
- * @example
310
- * ```ts
311
- * import { createClient, http, walletActions } from 'viem'
312
- * import { tempo } from 'tempo.ts/chains'
313
- * import { Actions } from 'tempo.ts/viem'
314
- *
315
- * const client = createClient({
316
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
317
- * transport: http(),
318
- * }).extend(walletActions)
319
- *
320
- * const { result } = await client.sendCalls({
321
- * calls: [
322
- * actions.amm.rebalanceSwap.call({
323
- * userToken: '0x20c0...beef',
324
- * validatorToken: '0x20c0...babe',
325
- * amountOut: 100n,
326
- * to: '0xfeed...fede',
327
- * }),
328
- * actions.amm.rebalanceSwap.call({
329
- * userToken: '0x20c0...babe',
330
- * validatorToken: '0x20c0...babe',
331
- * amountOut: 100n,
332
- * to: '0xfeed...fede',
333
- * }),
334
- * ]
335
- * })
336
- * ```
337
- *
338
- * @param args - Arguments.
339
- * @returns The call.
340
- */
341
- export function call(args: Args) {
342
- const { userToken, validatorToken, amountOut, to } = args
343
- return defineCall({
344
- address: Addresses.feeManager,
345
- abi: Abis.feeAmm,
346
- functionName: 'rebalanceSwap',
347
- args: [
348
- TokenId.toAddress(userToken),
349
- TokenId.toAddress(validatorToken),
350
- amountOut,
351
- to,
352
- ],
353
- })
354
- }
355
-
356
- /**
357
- * Extracts the `RebalanceSwap` event from logs.
358
- *
359
- * @param logs - The logs.
360
- * @returns The `RebalanceSwap` event.
361
- */
362
- export function extractEvent(logs: Log[]) {
363
- const [log] = parseEventLogs({
364
- abi: Abis.feeAmm,
365
- logs,
366
- eventName: 'RebalanceSwap',
367
- strict: true,
368
- })
369
- if (!log) throw new Error('`RebalanceSwap` event not found.')
370
- return log
371
- }
372
- }
373
-
374
- /**
375
- * Performs a rebalance swap from validator token to user token.
376
- *
377
- * @example
378
- * ```ts
379
- * import { createClient, http } from 'viem'
380
- * import { tempo } from 'tempo.ts/chains'
381
- * import { Actions } from 'tempo.ts/viem'
382
- * import { privateKeyToAccount } from 'viem/accounts'
383
- *
384
- * const client = createClient({
385
- * account: privateKeyToAccount('0x...'),
386
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
387
- * transport: http(),
388
- * })
389
- *
390
- * const result = await Actions.amm.rebalanceSwapSync(client, {
391
- * userToken: '0x...',
392
- * validatorToken: '0x...',
393
- * amountOut: 100n,
394
- * to: '0x...',
395
- * })
396
- * ```
397
- *
398
- * @param client - Client.
399
- * @param parameters - Parameters.
400
- * @returns The transaction receipt and event data.
401
- */
402
- export async function rebalanceSwapSync<
403
- chain extends Chain | undefined,
404
- account extends Account | undefined,
405
- >(
406
- client: Client<Transport, chain, account>,
407
- parameters: rebalanceSwapSync.Parameters<chain, account>,
408
- ): Promise<rebalanceSwapSync.ReturnValue> {
409
- const { throwOnReceiptRevert = true, ...rest } = parameters
410
- const receipt = await rebalanceSwap.inner(writeContractSync, client, {
411
- ...rest,
412
- throwOnReceiptRevert,
413
- } as never)
414
- const { args } = rebalanceSwap.extractEvent(receipt.logs)
415
- return {
416
- ...args,
417
- receipt,
418
- } as never
419
- }
420
-
421
- export namespace rebalanceSwapSync {
422
- export type Parameters<
423
- chain extends Chain | undefined = Chain | undefined,
424
- account extends Account | undefined = Account | undefined,
425
- > = rebalanceSwap.Parameters<chain, account>
426
-
427
- export type Args = rebalanceSwap.Args
428
-
429
- export type ReturnValue = Compute<
430
- GetEventArgs<
431
- typeof Abis.feeAmm,
432
- 'RebalanceSwap',
433
- { IndexedOnly: false; Required: true }
434
- > & {
435
- /** Transaction receipt. */
436
- receipt: TransactionReceipt
437
- }
438
- >
439
- }
440
-
441
- /**
442
- * Adds liquidity to a pool.
443
- *
444
- * @example
445
- * ```ts
446
- * import { createClient, http } from 'viem'
447
- * import { tempo } from 'tempo.ts/chains'
448
- * import { Actions } from 'tempo.ts/viem'
449
- * import { privateKeyToAccount } from 'viem/accounts'
450
- *
451
- * const client = createClient({
452
- * account: privateKeyToAccount('0x...'),
453
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
454
- * transport: http(),
455
- * })
456
- *
457
- * const hash = await Actions.amm.mint(client, {
458
- * userTokenAddress: '0x20c0...beef',
459
- * validatorTokenAddress: '0x20c0...babe',
460
- * validatorTokenAmount: 100n,
461
- * to: '0xfeed...fede',
462
- * })
463
- * ```
464
- *
465
- * @param client - Client.
466
- * @param parameters - Parameters.
467
- * @returns The transaction hash.
468
- */
469
- export async function mint<
470
- chain extends Chain | undefined,
471
- account extends Account | undefined,
472
- >(
473
- client: Client<Transport, chain, account>,
474
- parameters: mint.Parameters<chain, account>,
475
- ): Promise<mint.ReturnValue> {
476
- return mint.inner(writeContract, client, parameters)
477
- }
478
-
479
- export namespace mint {
480
- export type Parameters<
481
- chain extends Chain | undefined = Chain | undefined,
482
- account extends Account | undefined = Account | undefined,
483
- > = WriteParameters<chain, account> & Args
484
-
485
- export type Args = {
486
- /** Address to mint LP tokens to. */
487
- to: Address
488
- /** User token address. */
489
- userTokenAddress: TokenId.TokenIdOrAddress
490
- /** Validator token address. */
491
- validatorTokenAddress: TokenId.TokenIdOrAddress
492
- /** Amount of validator token to add. */
493
- validatorTokenAmount: bigint
494
- }
495
-
496
- export type ReturnValue = WriteContractReturnType
497
-
498
- /** @internal */
499
- export async function inner<
500
- action extends typeof writeContract | typeof writeContractSync,
501
- chain extends Chain | undefined,
502
- account extends Account | undefined,
503
- >(
504
- action: action,
505
- client: Client<Transport, chain, account>,
506
- parameters: mint.Parameters<chain, account>,
507
- ): Promise<ReturnType<action>> {
508
- const {
509
- to,
510
- userTokenAddress,
511
- validatorTokenAddress,
512
- validatorTokenAmount,
513
- ...rest
514
- } = parameters
515
- const call = mint.call({
516
- to,
517
- userTokenAddress,
518
- validatorTokenAddress,
519
- validatorTokenAmount,
520
- })
521
- return (await action(client, {
522
- ...rest,
523
- ...call,
524
- } as never)) as never
525
- }
526
-
527
- /**
528
- * Defines a call to the `mint` function.
529
- *
530
- * Can be passed as a parameter to:
531
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
532
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
533
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
534
- *
535
- * @example
536
- * ```ts
537
- * import { createClient, http, walletActions } from 'viem'
538
- * import { tempo } from 'tempo.ts/chains'
539
- * import { Actions } from 'tempo.ts/viem'
540
- *
541
- * const client = createClient({
542
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
543
- * transport: http(),
544
- * }).extend(walletActions)
545
- *
546
- * const { result } = await client.sendCalls({
547
- * calls: [
548
- * actions.amm.mint.call({
549
- * userTokenAddress: '0x20c0...beef',
550
- * validatorTokenAddress: '0x20c0...babe',
551
- * validatorTokenAmount: 100n,
552
- * to: '0xfeed...fede',
553
- * }),
554
- * actions.amm.mint.call({
555
- * userTokenAddress: '0x20c0...babe',
556
- * validatorTokenAddress: '0x20c0...babe',
557
- * validatorTokenAmount: 100n,
558
- * to: '0xfeed...fede',
559
- * }),
560
- * ]
561
- * })
562
- * ```
563
- *
564
- * @param args - Arguments.
565
- * @returns The call.
566
- */
567
- export function call(args: Args) {
568
- const {
569
- to,
570
- userTokenAddress,
571
- validatorTokenAddress,
572
- validatorTokenAmount,
573
- } = args
574
- return defineCall({
575
- address: Addresses.feeManager,
576
- abi: Abis.feeAmm,
577
- functionName: 'mintWithValidatorToken',
578
- args: [
579
- TokenId.toAddress(userTokenAddress),
580
- TokenId.toAddress(validatorTokenAddress),
581
- validatorTokenAmount,
582
- to,
583
- ],
584
- })
585
- }
586
-
587
- /**
588
- * Extracts the `Mint` event from logs.
589
- *
590
- * @param logs - The logs.
591
- * @returns The `Mint` event.
592
- */
593
- export function extractEvent(logs: Log[]) {
594
- const [log] = parseEventLogs({
595
- abi: Abis.feeAmm,
596
- logs,
597
- eventName: 'Mint',
598
- strict: true,
599
- })
600
- if (!log) throw new Error('`Mint` event not found.')
601
- return log
602
- }
603
- }
604
-
605
- /**
606
- * Adds liquidity to a pool.
607
- *
608
- * @example
609
- * ```ts
610
- * import { createClient, http } from 'viem'
611
- * import { tempo } from 'tempo.ts/chains'
612
- * import { Actions } from 'tempo.ts/viem'
613
- * import { privateKeyToAccount } from 'viem/accounts'
614
- *
615
- * const client = createClient({
616
- * account: privateKeyToAccount('0x...'),
617
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
618
- * transport: http(),
619
- * })
620
- *
621
- * const hash = await Actions.amm.mint(client, {
622
- * userTokenAddress: '0x20c0...beef',
623
- * validatorTokenAddress: '0x20c0...babe',
624
- * validatorTokenAmount: 100n,
625
- * to: '0xfeed...fede',
626
- * })
627
- * ```
628
- *
629
- * @param client - Client.
630
- * @param parameters - Parameters.
631
- * @returns The transaction receipt and event data.
632
- */
633
- export async function mintSync<
634
- chain extends Chain | undefined,
635
- account extends Account | undefined,
636
- >(
637
- client: Client<Transport, chain, account>,
638
- parameters: mintSync.Parameters<chain, account>,
639
- ): Promise<mintSync.ReturnValue> {
640
- const { throwOnReceiptRevert = true, ...rest } = parameters
641
- const receipt = await mint.inner(writeContractSync, client, {
642
- ...rest,
643
- throwOnReceiptRevert,
644
- } as never)
645
- const { args } = mint.extractEvent(receipt.logs)
646
- return {
647
- ...args,
648
- receipt,
649
- } as never
650
- }
651
-
652
- export namespace mintSync {
653
- export type Parameters<
654
- chain extends Chain | undefined = Chain | undefined,
655
- account extends Account | undefined = Account | undefined,
656
- > = mint.Parameters<chain, account>
657
-
658
- export type Args = mint.Args
659
-
660
- export type ReturnValue = Compute<
661
- GetEventArgs<
662
- typeof Abis.feeAmm,
663
- 'Mint',
664
- { IndexedOnly: false; Required: true }
665
- > & {
666
- /** Transaction receipt. */
667
- receipt: TransactionReceipt
668
- }
669
- >
670
- }
671
-
672
- /**
673
- * Removes liquidity from a pool.
674
- *
675
- * @example
676
- * ```ts
677
- * import { createClient, http } from 'viem'
678
- * import { tempo } from 'tempo.ts/chains'
679
- * import { Actions } from 'tempo.ts/viem'
680
- * import { privateKeyToAccount } from 'viem/accounts'
681
- *
682
- * const client = createClient({
683
- * account: privateKeyToAccount('0x...'),
684
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
685
- * transport: http(),
686
- * })
687
- *
688
- * const hash = await Actions.amm.burn(client, {
689
- * userToken: '0x20c0...beef',
690
- * validatorToken: '0x20c0...babe',
691
- * liquidity: 50n,
692
- * to: '0xfeed...fede',
693
- * })
694
- * ```
695
- *
696
- * @param client - Client.
697
- * @param parameters - Parameters.
698
- * @returns The transaction hash.
699
- */
700
- export async function burn<
701
- chain extends Chain | undefined,
702
- account extends Account | undefined,
703
- >(
704
- client: Client<Transport, chain, account>,
705
- parameters: burn.Parameters<chain, account>,
706
- ): Promise<burn.ReturnValue> {
707
- return burn.inner(writeContract, client, parameters)
708
- }
709
-
710
- export namespace burn {
711
- export type Parameters<
712
- chain extends Chain | undefined = Chain | undefined,
713
- account extends Account | undefined = Account | undefined,
714
- > = WriteParameters<chain, account> & Args
715
-
716
- export type Args = {
717
- /** Amount of LP tokens to burn. */
718
- liquidity: bigint
719
- /** Address to send tokens to. */
720
- to: Address
721
- /** Address or ID of the user token. */
722
- userToken: TokenId.TokenIdOrAddress
723
- /** Address or ID of the validator token. */
724
- validatorToken: TokenId.TokenIdOrAddress
725
- }
726
-
727
- export type ReturnValue = WriteContractReturnType
728
-
729
- /** @internal */
730
- export async function inner<
731
- action extends typeof writeContract | typeof writeContractSync,
732
- chain extends Chain | undefined,
733
- account extends Account | undefined,
734
- >(
735
- action: action,
736
- client: Client<Transport, chain, account>,
737
- parameters: burn.Parameters<chain, account>,
738
- ): Promise<ReturnType<action>> {
739
- const { liquidity, to, userToken, validatorToken, ...rest } = parameters
740
- const call = burn.call({ liquidity, to, userToken, validatorToken })
741
- return (await action(client, {
742
- ...rest,
743
- ...call,
744
- } as never)) as never
745
- }
746
-
747
- /**
748
- * Defines a call to the `burn` function.
749
- *
750
- * Can be passed as a parameter to:
751
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
752
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
753
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
754
- *
755
- * @example
756
- * ```ts
757
- * import { createClient, http, walletActions } from 'viem'
758
- * import { tempo } from 'tempo.ts/chains'
759
- * import { Actions } from 'tempo.ts/viem'
760
- *
761
- * const client = createClient({
762
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
763
- * transport: http(),
764
- * }).extend(walletActions)
765
- *
766
- * const { result } = await client.sendCalls({
767
- * calls: [
768
- * actions.amm.burn.call({
769
- * liquidity: 100n,
770
- * to: '0xfeed...fede',
771
- * userToken: '0x20c0...beef',
772
- * validatorToken: '0x20c0...babe',
773
- * }),
774
- * actions.amm.burn.call({
775
- * liquidity: 100n,
776
- * to: '0xfeed...fede',
777
- * userToken: '0x20c0...babe',
778
- * validatorToken: '0x20c0...babe',
779
- * }),
780
- * ]
781
- * })
782
- * ```
783
- *
784
- * @param args - Arguments.
785
- * @returns The call.
786
- */
787
- export function call(args: Args) {
788
- const { liquidity, to, userToken, validatorToken } = args
789
- return defineCall({
790
- address: Addresses.feeManager,
791
- abi: Abis.feeAmm,
792
- functionName: 'burn',
793
- args: [
794
- TokenId.toAddress(userToken),
795
- TokenId.toAddress(validatorToken),
796
- liquidity,
797
- to,
798
- ],
799
- })
800
- }
801
-
802
- /**
803
- * Extracts the `Burn` event from logs.
804
- *
805
- * @param logs - The logs.
806
- * @returns The `Burn` event.
807
- */
808
- export function extractEvent(logs: Log[]) {
809
- const [log] = parseEventLogs({
810
- abi: Abis.feeAmm,
811
- logs,
812
- eventName: 'Burn',
813
- strict: true,
814
- })
815
- if (!log) throw new Error('`Burn` event not found.')
816
- return log
817
- }
818
- }
819
-
820
- /**
821
- * Removes liquidity from a pool.
822
- *
823
- * @example
824
- * ```ts
825
- * import { createClient, http } from 'viem'
826
- * import { tempo } from 'tempo.ts/chains'
827
- * import { Actions } from 'tempo.ts/viem'
828
- * import { privateKeyToAccount } from 'viem/accounts'
829
- *
830
- * const client = createClient({
831
- * account: privateKeyToAccount('0x...'),
832
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
833
- * transport: http(),
834
- * })
835
- *
836
- * const result = await Actions.amm.burnSync(client, {
837
- * userToken: '0x20c0...beef',
838
- * validatorToken: '0x20c0...babe',
839
- * liquidity: 50n,
840
- * to: '0xfeed...fede',
841
- * })
842
- * ```
843
- *
844
- * @param client - Client.
845
- * @param parameters - Parameters.
846
- * @returns The transaction receipt and event data.
847
- */
848
- export async function burnSync<
849
- chain extends Chain | undefined,
850
- account extends Account | undefined,
851
- >(
852
- client: Client<Transport, chain, account>,
853
- parameters: burnSync.Parameters<chain, account>,
854
- ): Promise<burnSync.ReturnValue> {
855
- const { throwOnReceiptRevert = true, ...rest } = parameters
856
- const receipt = await burn.inner(writeContractSync, client, {
857
- ...rest,
858
- throwOnReceiptRevert,
859
- } as never)
860
- const { args } = burn.extractEvent(receipt.logs)
861
- return {
862
- ...args,
863
- receipt,
864
- } as never
865
- }
866
-
867
- export namespace burnSync {
868
- export type Parameters<
869
- chain extends Chain | undefined = Chain | undefined,
870
- account extends Account | undefined = Account | undefined,
871
- > = burn.Parameters<chain, account>
872
-
873
- export type Args = burn.Args
874
-
875
- export type ReturnValue = Compute<
876
- GetEventArgs<
877
- typeof Abis.feeAmm,
878
- 'Burn',
879
- { IndexedOnly: false; Required: true }
880
- > & {
881
- /** Transaction receipt. */
882
- receipt: TransactionReceipt
883
- }
884
- >
885
- }
886
-
887
- /**
888
- * Watches for rebalance swap events.
889
- *
890
- * @example
891
- * ```ts
892
- * import { createClient, http } from 'viem'
893
- * import { tempo } from 'tempo.ts/chains'
894
- * import { Actions } from 'tempo.ts/viem'
895
- *
896
- * const client = createClient({
897
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
898
- * transport: http(),
899
- * })
900
- *
901
- * const unwatch = actions.amm.watchRebalanceSwap(client, {
902
- * onRebalanceSwap: (args, log) => {
903
- * console.log('Rebalance swap:', args)
904
- * },
905
- * })
906
- * ```
907
- *
908
- * @param client - Client.
909
- * @param parameters - Parameters.
910
- * @returns A function to unsubscribe from the event.
911
- */
912
- export function watchRebalanceSwap<
913
- chain extends Chain | undefined,
914
- account extends Account | undefined,
915
- >(
916
- client: Client<Transport, chain, account>,
917
- parameters: watchRebalanceSwap.Parameters,
918
- ) {
919
- const { onRebalanceSwap, userToken, validatorToken, ...rest } = parameters
920
- return watchContractEvent(client, {
921
- ...rest,
922
- address: Addresses.feeManager,
923
- abi: Abis.feeAmm,
924
- eventName: 'RebalanceSwap',
925
- args:
926
- userToken !== undefined && validatorToken !== undefined
927
- ? {
928
- userToken: TokenId.toAddress(userToken),
929
- validatorToken: TokenId.toAddress(validatorToken),
930
- }
931
- : undefined,
932
- onLogs: (logs) => {
933
- for (const log of logs) onRebalanceSwap(log.args, log)
934
- },
935
- strict: true,
936
- })
937
- }
938
-
939
- export declare namespace watchRebalanceSwap {
940
- export type Args = GetEventArgs<
941
- typeof Abis.feeAmm,
942
- 'RebalanceSwap',
943
- { IndexedOnly: false; Required: true }
944
- >
945
-
946
- export type Log = viem_Log<
947
- bigint,
948
- number,
949
- false,
950
- ExtractAbiItem<typeof Abis.feeAmm, 'RebalanceSwap'>,
951
- true
952
- >
953
-
954
- export type Parameters = UnionOmit<
955
- WatchContractEventParameters<typeof Abis.feeAmm, 'RebalanceSwap', true>,
956
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
957
- > & {
958
- /** Callback to invoke when a rebalance swap occurs. */
959
- onRebalanceSwap: (args: Args, log: Log) => void
960
- /** Address or ID of the user token to filter events. */
961
- userToken?: TokenId.TokenIdOrAddress | undefined
962
- /** Address or ID of the validator token to filter events. */
963
- validatorToken?: TokenId.TokenIdOrAddress | undefined
964
- }
965
- }
966
-
967
- /**
968
- * Watches for fee swap events.
969
- *
970
- * @example
971
- * ```ts
972
- * import { createClient, http } from 'viem'
973
- * import { tempo } from 'tempo.ts/chains'
974
- * import { Actions } from 'tempo.ts/viem'
975
- *
976
- * const client = createClient({
977
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
978
- * transport: http(),
979
- * })
980
- *
981
- * const unwatch = actions.amm.watchFeeSwap(client, {
982
- * onFeeSwap: (args, log) => {
983
- * console.log('Fee swap:', args)
984
- * },
985
- * })
986
- * ```
987
- *
988
- * @param client - Client.
989
- * @param parameters - Parameters.
990
- * @returns A function to unsubscribe from the event.
991
- */
992
- export function watchFeeSwap<
993
- chain extends Chain | undefined,
994
- account extends Account | undefined,
995
- >(
996
- client: Client<Transport, chain, account>,
997
- parameters: watchFeeSwap.Parameters,
998
- ) {
999
- const { onFeeSwap, userToken, validatorToken, ...rest } = parameters
1000
- return watchContractEvent(client, {
1001
- ...rest,
1002
- address: Addresses.feeManager,
1003
- abi: Abis.feeAmm,
1004
- eventName: 'FeeSwap',
1005
- args:
1006
- userToken !== undefined && validatorToken !== undefined
1007
- ? {
1008
- userToken: TokenId.toAddress(userToken),
1009
- validatorToken: TokenId.toAddress(validatorToken),
1010
- }
1011
- : undefined,
1012
- onLogs: (logs) => {
1013
- for (const log of logs) onFeeSwap(log.args, log)
1014
- },
1015
- strict: true,
1016
- })
1017
- }
1018
-
1019
- export declare namespace watchFeeSwap {
1020
- export type Args = GetEventArgs<
1021
- typeof Abis.feeAmm,
1022
- 'FeeSwap',
1023
- { IndexedOnly: false; Required: true }
1024
- >
1025
-
1026
- export type Log = viem_Log<
1027
- bigint,
1028
- number,
1029
- false,
1030
- ExtractAbiItem<typeof Abis.feeAmm, 'FeeSwap'>,
1031
- true
1032
- >
1033
-
1034
- export type Parameters = UnionOmit<
1035
- WatchContractEventParameters<typeof Abis.feeAmm, 'FeeSwap', true>,
1036
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1037
- > & {
1038
- /** Callback to invoke when a fee swap occurs. */
1039
- onFeeSwap: (args: Args, log: Log) => void
1040
- /** Address or ID of the user token to filter events. */
1041
- userToken?: TokenId.TokenIdOrAddress | undefined
1042
- /** Address or ID of the validator token to filter events. */
1043
- validatorToken?: TokenId.TokenIdOrAddress | undefined
1044
- }
1045
- }
1046
-
1047
- /**
1048
- * Watches for liquidity mint events.
1049
- *
1050
- * @example
1051
- * ```ts
1052
- * import { createClient, http } from 'viem'
1053
- * import { tempo } from 'tempo.ts/chains'
1054
- * import { Actions } from 'tempo.ts/viem'
1055
- *
1056
- * const client = createClient({
1057
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1058
- * transport: http(),
1059
- * })
1060
- *
1061
- * const unwatch = actions.amm.watchMint(client, {
1062
- * onMint: (args, log) => {
1063
- * console.log('Liquidity added:', args)
1064
- * },
1065
- * })
1066
- * ```
1067
- *
1068
- * @param client - Client.
1069
- * @param parameters - Parameters.
1070
- * @returns A function to unsubscribe from the event.
1071
- */
1072
- export function watchMint<
1073
- chain extends Chain | undefined,
1074
- account extends Account | undefined,
1075
- >(client: Client<Transport, chain, account>, parameters: watchMint.Parameters) {
1076
- const { onMint, sender, userToken, validatorToken, ...rest } = parameters
1077
- return watchContractEvent(client, {
1078
- ...rest,
1079
- address: Addresses.feeManager,
1080
- abi: Abis.feeAmm,
1081
- eventName: 'Mint',
1082
- args: {
1083
- ...(sender !== undefined && {
1084
- sender: TokenId.toAddress(sender),
1085
- }),
1086
- ...(userToken !== undefined && {
1087
- userToken: TokenId.toAddress(userToken),
1088
- }),
1089
- ...(validatorToken !== undefined && {
1090
- validatorToken: TokenId.toAddress(validatorToken),
1091
- }),
1092
- },
1093
- onLogs: (logs) => {
1094
- for (const log of logs)
1095
- onMint(
1096
- {
1097
- liquidity: log.args.liquidity,
1098
- sender: log.args.sender,
1099
- userToken: {
1100
- address: log.args.userToken,
1101
- amount: log.args.amountUserToken,
1102
- },
1103
- validatorToken: {
1104
- address: log.args.validatorToken,
1105
- amount: log.args.amountValidatorToken,
1106
- },
1107
- },
1108
- log,
1109
- )
1110
- },
1111
- strict: true,
1112
- })
1113
- }
1114
-
1115
- export declare namespace watchMint {
1116
- export type Args = {
1117
- liquidity: bigint
1118
- sender: Address
1119
- userToken: {
1120
- address: Address
1121
- amount: bigint
1122
- }
1123
- validatorToken: {
1124
- address: Address
1125
- amount: bigint
1126
- }
1127
- }
1128
-
1129
- export type Log = viem_Log<
1130
- bigint,
1131
- number,
1132
- false,
1133
- ExtractAbiItem<typeof Abis.feeAmm, 'Mint'>,
1134
- true
1135
- >
1136
-
1137
- export type Parameters = UnionOmit<
1138
- WatchContractEventParameters<typeof Abis.feeAmm, 'Mint', true>,
1139
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1140
- > & {
1141
- /** Callback to invoke when liquidity is added. */
1142
- onMint: (args: Args, log: Log) => void
1143
- /** Address or ID of the sender to filter events. */
1144
- sender?: TokenId.TokenIdOrAddress | undefined
1145
- /** Address or ID of the user token to filter events. */
1146
- userToken?: TokenId.TokenIdOrAddress | undefined
1147
- /** Address or ID of the validator token to filter events. */
1148
- validatorToken?: TokenId.TokenIdOrAddress | undefined
1149
- }
1150
- }
1151
-
1152
- /**
1153
- * Watches for liquidity burn events.
1154
- *
1155
- * @example
1156
- * ```ts
1157
- * import { createClient, http } from 'viem'
1158
- * import { tempo } from 'tempo.ts/chains'
1159
- * import { Actions } from 'tempo.ts/viem'
1160
- *
1161
- * const client = createClient({
1162
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1163
- * transport: http(),
1164
- * })
1165
- *
1166
- * const unwatch = actions.amm.watchBurn(client, {
1167
- * onBurn: (args, log) => {
1168
- * console.log('Liquidity removed:', args)
1169
- * },
1170
- * })
1171
- * ```
1172
- *
1173
- * @param client - Client.
1174
- * @param parameters - Parameters.
1175
- * @returns A function to unsubscribe from the event.
1176
- */
1177
- export function watchBurn<
1178
- chain extends Chain | undefined,
1179
- account extends Account | undefined,
1180
- >(client: Client<Transport, chain, account>, parameters: watchBurn.Parameters) {
1181
- const { onBurn, userToken, validatorToken, ...rest } = parameters
1182
- return watchContractEvent(client, {
1183
- ...rest,
1184
- address: Addresses.feeManager,
1185
- abi: Abis.feeAmm,
1186
- eventName: 'Burn',
1187
- args:
1188
- userToken !== undefined && validatorToken !== undefined
1189
- ? {
1190
- userToken: TokenId.toAddress(userToken),
1191
- validatorToken: TokenId.toAddress(validatorToken),
1192
- }
1193
- : undefined,
1194
- onLogs: (logs) => {
1195
- for (const log of logs) onBurn(log.args, log)
1196
- },
1197
- strict: true,
1198
- })
1199
- }
1200
-
1201
- export declare namespace watchBurn {
1202
- export type Args = GetEventArgs<
1203
- typeof Abis.feeAmm,
1204
- 'Burn',
1205
- { IndexedOnly: false; Required: true }
1206
- >
1207
-
1208
- export type Log = viem_Log<
1209
- bigint,
1210
- number,
1211
- false,
1212
- ExtractAbiItem<typeof Abis.feeAmm, 'Burn'>,
1213
- true
1214
- >
1215
-
1216
- export type Parameters = UnionOmit<
1217
- WatchContractEventParameters<typeof Abis.feeAmm, 'Burn', true>,
1218
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1219
- > & {
1220
- /** Callback to invoke when liquidity is removed. */
1221
- onBurn: (args: Args, log: Log) => void
1222
- /** Address or ID of the user token to filter events. */
1223
- userToken?: TokenId.TokenIdOrAddress | undefined
1224
- /** Address or ID of the validator token to filter events. */
1225
- validatorToken?: TokenId.TokenIdOrAddress | undefined
1226
- }
1227
- }