tempo.ts 0.0.0 → 0.0.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.
Files changed (153) hide show
  1. package/README.md +92 -0
  2. package/dist/chains.d.ts +1477 -0
  3. package/dist/chains.d.ts.map +1 -0
  4. package/dist/chains.js +43 -0
  5. package/dist/chains.js.map +1 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/internal/types.d.ts +284 -0
  11. package/dist/internal/types.d.ts.map +1 -0
  12. package/dist/internal/types.js +2 -0
  13. package/dist/internal/types.js.map +1 -0
  14. package/dist/ox/TokenId.d.ts +18 -0
  15. package/dist/ox/TokenId.d.ts.map +1 -0
  16. package/dist/ox/TokenId.js +29 -0
  17. package/dist/ox/TokenId.js.map +1 -0
  18. package/dist/ox/TokenRole.d.ts +11 -0
  19. package/dist/ox/TokenRole.d.ts.map +1 -0
  20. package/dist/ox/TokenRole.js +22 -0
  21. package/dist/ox/TokenRole.js.map +1 -0
  22. package/dist/ox/Transaction.d.ts +161 -0
  23. package/dist/ox/Transaction.d.ts.map +1 -0
  24. package/dist/ox/Transaction.js +117 -0
  25. package/dist/ox/Transaction.js.map +1 -0
  26. package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
  27. package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
  28. package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
  29. package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
  30. package/dist/ox/TransactionRequest.d.ts +62 -0
  31. package/dist/ox/TransactionRequest.d.ts.map +1 -0
  32. package/dist/ox/TransactionRequest.js +66 -0
  33. package/dist/ox/TransactionRequest.js.map +1 -0
  34. package/dist/ox/index.d.ts +5 -0
  35. package/dist/ox/index.d.ts.map +1 -0
  36. package/dist/ox/index.js +5 -0
  37. package/dist/ox/index.js.map +1 -0
  38. package/dist/prool/Instance.d.ts +92 -0
  39. package/dist/prool/Instance.d.ts.map +1 -0
  40. package/dist/prool/Instance.js +96 -0
  41. package/dist/prool/Instance.js.map +1 -0
  42. package/dist/prool/index.d.ts +2 -0
  43. package/dist/prool/index.d.ts.map +1 -0
  44. package/dist/prool/index.js +2 -0
  45. package/dist/prool/index.js.map +1 -0
  46. package/dist/viem/abis.d.ts +2058 -0
  47. package/dist/viem/abis.d.ts.map +1 -0
  48. package/dist/viem/abis.js +1599 -0
  49. package/dist/viem/abis.js.map +1 -0
  50. package/dist/viem/actions/amm.d.ts +2091 -0
  51. package/dist/viem/actions/amm.d.ts.map +1 -0
  52. package/dist/viem/actions/amm.js +876 -0
  53. package/dist/viem/actions/amm.js.map +1 -0
  54. package/dist/viem/actions/fee.d.ts +727 -0
  55. package/dist/viem/actions/fee.d.ts.map +1 -0
  56. package/dist/viem/actions/fee.js +230 -0
  57. package/dist/viem/actions/fee.js.map +1 -0
  58. package/dist/viem/actions/index.d.ts +5 -0
  59. package/dist/viem/actions/index.d.ts.map +1 -0
  60. package/dist/viem/actions/index.js +5 -0
  61. package/dist/viem/actions/index.js.map +1 -0
  62. package/dist/viem/actions/policy.d.ts +1900 -0
  63. package/dist/viem/actions/policy.d.ts.map +1 -0
  64. package/dist/viem/actions/policy.js +841 -0
  65. package/dist/viem/actions/policy.js.map +1 -0
  66. package/dist/viem/actions/token.d.ts +13759 -0
  67. package/dist/viem/actions/token.d.ts.map +1 -0
  68. package/dist/viem/actions/token.js +2579 -0
  69. package/dist/viem/actions/token.js.map +1 -0
  70. package/dist/viem/addresses.d.ts +8 -0
  71. package/dist/viem/addresses.d.ts.map +1 -0
  72. package/dist/viem/addresses.js +8 -0
  73. package/dist/viem/addresses.js.map +1 -0
  74. package/dist/viem/chain.d.ts +341 -0
  75. package/dist/viem/chain.d.ts.map +1 -0
  76. package/dist/viem/chain.js +22 -0
  77. package/dist/viem/chain.js.map +1 -0
  78. package/dist/viem/client.d.ts +27 -0
  79. package/dist/viem/client.d.ts.map +1 -0
  80. package/dist/viem/client.js +28 -0
  81. package/dist/viem/client.js.map +1 -0
  82. package/dist/viem/decorator.d.ts +1636 -0
  83. package/dist/viem/decorator.d.ts.map +1 -0
  84. package/dist/viem/decorator.js +95 -0
  85. package/dist/viem/decorator.js.map +1 -0
  86. package/dist/viem/formatters.d.ts +4 -0
  87. package/dist/viem/formatters.d.ts.map +1 -0
  88. package/dist/viem/formatters.js +69 -0
  89. package/dist/viem/formatters.js.map +1 -0
  90. package/dist/viem/index.d.ts +10 -0
  91. package/dist/viem/index.d.ts.map +1 -0
  92. package/dist/viem/index.js +10 -0
  93. package/dist/viem/index.js.map +1 -0
  94. package/dist/viem/transaction.d.ts +54 -0
  95. package/dist/viem/transaction.d.ts.map +1 -0
  96. package/dist/viem/transaction.js +108 -0
  97. package/dist/viem/transaction.js.map +1 -0
  98. package/dist/viem/transport.d.ts +16 -0
  99. package/dist/viem/transport.d.ts.map +1 -0
  100. package/dist/viem/transport.js +33 -0
  101. package/dist/viem/transport.js.map +1 -0
  102. package/dist/viem/types.d.ts +10 -0
  103. package/dist/viem/types.d.ts.map +1 -0
  104. package/dist/viem/types.js +2 -0
  105. package/dist/viem/types.js.map +1 -0
  106. package/dist/viem/utils.d.ts +8 -0
  107. package/dist/viem/utils.d.ts.map +1 -0
  108. package/dist/viem/utils.js +9 -0
  109. package/dist/viem/utils.js.map +1 -0
  110. package/package.json +100 -2
  111. package/src/chains.ts +46 -0
  112. package/src/index.ts +1 -0
  113. package/src/internal/types.ts +414 -0
  114. package/src/ox/TokenId.test.ts +29 -0
  115. package/src/ox/TokenId.ts +35 -0
  116. package/src/ox/TokenRole.test.ts +20 -0
  117. package/src/ox/TokenRole.ts +27 -0
  118. package/src/ox/Transaction.test.ts +257 -0
  119. package/src/ox/Transaction.ts +247 -0
  120. package/src/ox/TransactionEnvelopeFeeToken.test.ts +1119 -0
  121. package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
  122. package/src/ox/TransactionRequest.ts +100 -0
  123. package/src/ox/index.ts +4 -0
  124. package/src/prool/Instance.test.ts +43 -0
  125. package/src/prool/Instance.ts +190 -0
  126. package/src/prool/index.ts +1 -0
  127. package/src/prool/internal/chain.json +106 -0
  128. package/src/prool/internal/consensus.toml +32 -0
  129. package/src/viem/abis.ts +1606 -0
  130. package/src/viem/actions/amm.test.ts +425 -0
  131. package/src/viem/actions/amm.ts +1308 -0
  132. package/src/viem/actions/fee.test.ts +281 -0
  133. package/src/viem/actions/fee.ts +362 -0
  134. package/src/viem/actions/index.ts +4 -0
  135. package/src/viem/actions/policy.test.ts +514 -0
  136. package/src/viem/actions/policy.ts +1284 -0
  137. package/src/viem/actions/token.test.ts +2172 -0
  138. package/src/viem/actions/token.ts +3830 -0
  139. package/src/viem/addresses.ts +10 -0
  140. package/src/viem/chain.ts +27 -0
  141. package/src/viem/client.bench-d.ts +8 -0
  142. package/src/viem/client.test.ts +152 -0
  143. package/src/viem/client.ts +91 -0
  144. package/src/viem/decorator.bench-d.ts +11 -0
  145. package/src/viem/decorator.test.ts +35 -0
  146. package/src/viem/decorator.ts +1914 -0
  147. package/src/viem/e2e.test.ts +410 -0
  148. package/src/viem/formatters.ts +100 -0
  149. package/src/viem/index.ts +9 -0
  150. package/src/viem/transaction.ts +253 -0
  151. package/src/viem/transport.ts +47 -0
  152. package/src/viem/types.ts +55 -0
  153. package/src/viem/utils.ts +37 -0
@@ -0,0 +1,876 @@
1
+ import { parseEventLogs, } from 'viem';
2
+ import { readContract, watchContractEvent, writeContract, writeContractSync, } from 'viem/actions';
3
+ import * as TokenId from "../../ox/TokenId.js";
4
+ import { feeAmmAbi } from "../abis.js";
5
+ import { feeManagerAddress } from "../addresses.js";
6
+ import { defineCall } from "../utils.js";
7
+ /**
8
+ * Gets the pool ID for a token pair.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createClient, http } from 'viem'
13
+ * import { tempo } from 'tempo.ts/chains'
14
+ * import * as actions from 'tempo.ts/viem/actions'
15
+ *
16
+ * const client = createClient({
17
+ * chain: tempo,
18
+ * transport: http(),
19
+ * })
20
+ *
21
+ * const poolId = await actions.amm.getPoolId(client, {
22
+ * userToken: '0x...',
23
+ * validatorToken: '0x...',
24
+ * })
25
+ * ```
26
+ *
27
+ * @param client - Client.
28
+ * @param parameters - Parameters.
29
+ * @returns The pool ID.
30
+ */
31
+ export async function getPoolId(client, parameters) {
32
+ return readContract(client, {
33
+ ...parameters,
34
+ ...getPoolId.call(parameters),
35
+ });
36
+ }
37
+ (function (getPoolId) {
38
+ /**
39
+ * Defines a call to the `getPoolId` function.
40
+ *
41
+ * @param args - Arguments.
42
+ * @returns The call.
43
+ */
44
+ function call(args) {
45
+ const { userToken, validatorToken } = args;
46
+ return defineCall({
47
+ address: feeManagerAddress,
48
+ abi: feeAmmAbi,
49
+ args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
50
+ functionName: 'getPoolId',
51
+ });
52
+ }
53
+ getPoolId.call = call;
54
+ })(getPoolId || (getPoolId = {}));
55
+ /**
56
+ * Gets the reserves for a liquidity pool.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { createClient, http } from 'viem'
61
+ * import { tempo } from 'tempo.ts/chains'
62
+ * import * as actions from 'tempo.ts/viem/actions'
63
+ *
64
+ * const client = createClient({
65
+ * chain: tempo,
66
+ * transport: http(),
67
+ * })
68
+ *
69
+ * const pool = await actions.amm.getPool(client, {
70
+ * userToken: '0x...',
71
+ * validatorToken: '0x...',
72
+ * })
73
+ * ```
74
+ *
75
+ * @param client - Client.
76
+ * @param parameters - Parameters.
77
+ * @returns The pool reserves.
78
+ */
79
+ export async function getPool(client, parameters) {
80
+ return readContract(client, {
81
+ ...parameters,
82
+ ...getPool.call(parameters),
83
+ });
84
+ }
85
+ (function (getPool) {
86
+ /**
87
+ * Defines a call to the `getPool` function.
88
+ *
89
+ * @param args - Arguments.
90
+ * @returns The call.
91
+ */
92
+ function call(args) {
93
+ const { userToken, validatorToken } = args;
94
+ return defineCall({
95
+ address: feeManagerAddress,
96
+ abi: feeAmmAbi,
97
+ args: [TokenId.toAddress(userToken), TokenId.toAddress(validatorToken)],
98
+ functionName: 'getPool',
99
+ });
100
+ }
101
+ getPool.call = call;
102
+ })(getPool || (getPool = {}));
103
+ /**
104
+ * Gets the total supply of LP tokens for a pool.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import { createClient, http } from 'viem'
109
+ * import { tempo } from 'tempo.ts/chains'
110
+ * import * as actions from 'tempo.ts/viem/actions'
111
+ *
112
+ * const client = createClient({
113
+ * chain: tempo,
114
+ * transport: http(),
115
+ * })
116
+ *
117
+ * const poolId = await actions.amm.getPoolId(client, {
118
+ * userToken: '0x...',
119
+ * validatorToken: '0x...',
120
+ * })
121
+ *
122
+ * const totalSupply = await actions.amm.getTotalSupply(client, { poolId })
123
+ * ```
124
+ *
125
+ * @param client - Client.
126
+ * @param parameters - Parameters.
127
+ * @returns The total supply of LP tokens.
128
+ */
129
+ export async function getTotalSupply(client, parameters) {
130
+ return readContract(client, {
131
+ ...parameters,
132
+ ...getTotalSupply.call(parameters),
133
+ });
134
+ }
135
+ (function (getTotalSupply) {
136
+ /**
137
+ * Defines a call to the `totalSupply` function.
138
+ *
139
+ * @param args - Arguments.
140
+ * @returns The call.
141
+ */
142
+ function call(args) {
143
+ const { poolId } = args;
144
+ return defineCall({
145
+ address: feeManagerAddress,
146
+ abi: feeAmmAbi,
147
+ args: [poolId],
148
+ functionName: 'totalSupply',
149
+ });
150
+ }
151
+ getTotalSupply.call = call;
152
+ })(getTotalSupply || (getTotalSupply = {}));
153
+ /**
154
+ * Gets the LP token balance for an account in a specific pool.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { createClient, http } from 'viem'
159
+ * import { tempo } from 'tempo.ts/chains'
160
+ * import * as actions from 'tempo.ts/viem/actions'
161
+ *
162
+ * const client = createClient({
163
+ * chain: tempo,
164
+ * transport: http(),
165
+ * })
166
+ *
167
+ * const poolId = await actions.amm.getPoolId(client, {
168
+ * userToken: '0x...',
169
+ * validatorToken: '0x...',
170
+ * })
171
+ *
172
+ * const balance = await actions.amm.getLiquidityBalance(client, {
173
+ * poolId,
174
+ * address: '0x...',
175
+ * })
176
+ * ```
177
+ *
178
+ * @param client - Client.
179
+ * @param parameters - Parameters.
180
+ * @returns The LP token balance.
181
+ */
182
+ export async function getLiquidityBalance(client, parameters) {
183
+ return readContract(client, {
184
+ ...parameters,
185
+ ...getLiquidityBalance.call(parameters),
186
+ });
187
+ }
188
+ (function (getLiquidityBalance) {
189
+ /**
190
+ * Defines a call to the `liquidityBalances` function.
191
+ *
192
+ * @param args - Arguments.
193
+ * @returns The call.
194
+ */
195
+ function call(args) {
196
+ const { address, poolId } = args;
197
+ return defineCall({
198
+ address: feeManagerAddress,
199
+ abi: feeAmmAbi,
200
+ args: [poolId, address],
201
+ functionName: 'liquidityBalances',
202
+ });
203
+ }
204
+ getLiquidityBalance.call = call;
205
+ })(getLiquidityBalance || (getLiquidityBalance = {}));
206
+ /**
207
+ * Performs a rebalance swap from validator token to user token.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * import { createClient, http } from 'viem'
212
+ * import { tempo } from 'tempo.ts/chains'
213
+ * import * as actions from 'tempo.ts/viem/actions'
214
+ * import { privateKeyToAccount } from 'viem/accounts'
215
+ *
216
+ * const client = createClient({
217
+ * account: privateKeyToAccount('0x...'),
218
+ * chain: tempo,
219
+ * transport: http(),
220
+ * })
221
+ *
222
+ * const hash = await actions.amm.rebalanceSwap(client, {
223
+ * userToken: '0x...',
224
+ * validatorToken: '0x...',
225
+ * amountOut: 100n,
226
+ * to: '0x...',
227
+ * })
228
+ * ```
229
+ *
230
+ * @param client - Client.
231
+ * @param parameters - Parameters.
232
+ * @returns The transaction hash.
233
+ */
234
+ export async function rebalanceSwap(client, parameters) {
235
+ return rebalanceSwap.inner(writeContract, client, parameters);
236
+ }
237
+ (function (rebalanceSwap) {
238
+ /** @internal */
239
+ async function inner(action, client, parameters) {
240
+ const call = rebalanceSwap.call(parameters);
241
+ return (await action(client, {
242
+ ...parameters,
243
+ ...call,
244
+ }));
245
+ }
246
+ rebalanceSwap.inner = inner;
247
+ /**
248
+ * Defines a call to the `rebalanceSwap` function.
249
+ *
250
+ * Can be passed as a parameter to:
251
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
252
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
253
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * import { createClient, http, walletActions } from 'viem'
258
+ * import { tempo } from 'tempo.ts/chains'
259
+ * import * as actions from 'tempo.ts/viem/actions'
260
+ *
261
+ * const client = createClient({
262
+ * chain: tempo,
263
+ * transport: http(),
264
+ * }).extend(walletActions)
265
+ *
266
+ * const { result } = await client.sendCalls({
267
+ * calls: [
268
+ * actions.amm.rebalanceSwap.call({
269
+ * userToken: '0x20c0...beef',
270
+ * validatorToken: '0x20c0...babe',
271
+ * amountOut: 100n,
272
+ * to: '0xfeed...fede',
273
+ * }),
274
+ * actions.amm.rebalanceSwap.call({
275
+ * userToken: '0x20c0...babe',
276
+ * validatorToken: '0x20c0...babe',
277
+ * amountOut: 100n,
278
+ * to: '0xfeed...fede',
279
+ * }),
280
+ * ]
281
+ * })
282
+ * ```
283
+ *
284
+ * @param args - Arguments.
285
+ * @returns The call.
286
+ */
287
+ function call(args) {
288
+ const { userToken, validatorToken, amountOut, to } = args;
289
+ return defineCall({
290
+ address: feeManagerAddress,
291
+ abi: feeAmmAbi,
292
+ functionName: 'rebalanceSwap',
293
+ args: [
294
+ TokenId.toAddress(userToken),
295
+ TokenId.toAddress(validatorToken),
296
+ amountOut,
297
+ to,
298
+ ],
299
+ });
300
+ }
301
+ rebalanceSwap.call = call;
302
+ /**
303
+ * Extracts the `RebalanceSwap` event from logs.
304
+ *
305
+ * @param logs - The logs.
306
+ * @returns The `RebalanceSwap` event.
307
+ */
308
+ function extractEvent(logs) {
309
+ const [log] = parseEventLogs({
310
+ abi: feeAmmAbi,
311
+ logs,
312
+ eventName: 'RebalanceSwap',
313
+ strict: true,
314
+ });
315
+ if (!log)
316
+ throw new Error('`RebalanceSwap` event not found.');
317
+ return log;
318
+ }
319
+ rebalanceSwap.extractEvent = extractEvent;
320
+ })(rebalanceSwap || (rebalanceSwap = {}));
321
+ /**
322
+ * Performs a rebalance swap from validator token to user token.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * import { createClient, http } from 'viem'
327
+ * import { tempo } from 'tempo.ts/chains'
328
+ * import * as actions from 'tempo.ts/viem/actions'
329
+ * import { privateKeyToAccount } from 'viem/accounts'
330
+ *
331
+ * const client = createClient({
332
+ * account: privateKeyToAccount('0x...'),
333
+ * chain: tempo,
334
+ * transport: http(),
335
+ * })
336
+ *
337
+ * const result = await actions.amm.rebalanceSwapSync(client, {
338
+ * userToken: '0x...',
339
+ * validatorToken: '0x...',
340
+ * amountOut: 100n,
341
+ * to: '0x...',
342
+ * })
343
+ * ```
344
+ *
345
+ * @param client - Client.
346
+ * @param parameters - Parameters.
347
+ * @returns The transaction receipt and event data.
348
+ */
349
+ export async function rebalanceSwapSync(client, parameters) {
350
+ const receipt = await rebalanceSwap.inner(writeContractSync, client, parameters);
351
+ const { args } = rebalanceSwap.extractEvent(receipt.logs);
352
+ return {
353
+ ...args,
354
+ receipt,
355
+ };
356
+ }
357
+ /**
358
+ * Adds liquidity to a pool.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * import { createClient, http } from 'viem'
363
+ * import { tempo } from 'tempo.ts/chains'
364
+ * import * as actions from 'tempo.ts/viem/actions'
365
+ * import { privateKeyToAccount } from 'viem/accounts'
366
+ *
367
+ * const client = createClient({
368
+ * account: privateKeyToAccount('0x...'),
369
+ * chain: tempo,
370
+ * transport: http(),
371
+ * })
372
+ *
373
+ * const hash = await actions.amm.mint(client, {
374
+ * userToken: {
375
+ * address: '0x20c0...beef',
376
+ * amount: 100n,
377
+ * },
378
+ * validatorToken: {
379
+ * address: '0x20c0...babe',
380
+ * amount: 100n,
381
+ * },
382
+ * to: '0xfeed...fede',
383
+ * })
384
+ * ```
385
+ *
386
+ * @param client - Client.
387
+ * @param parameters - Parameters.
388
+ * @returns The transaction hash.
389
+ */
390
+ export async function mint(client, parameters) {
391
+ return mint.inner(writeContract, client, parameters);
392
+ }
393
+ (function (mint) {
394
+ /** @internal */
395
+ async function inner(action, client, parameters) {
396
+ const call = mint.call(parameters);
397
+ return (await action(client, {
398
+ ...parameters,
399
+ ...call,
400
+ }));
401
+ }
402
+ mint.inner = inner;
403
+ /**
404
+ * Defines a call to the `mint` function.
405
+ *
406
+ * Can be passed as a parameter to:
407
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
408
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
409
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * import { createClient, http, walletActions } from 'viem'
414
+ * import { tempo } from 'tempo.ts/chains'
415
+ * import * as actions from 'tempo.ts/viem/actions'
416
+ *
417
+ * const client = createClient({
418
+ * chain: tempo,
419
+ * transport: http(),
420
+ * }).extend(walletActions)
421
+ *
422
+ * const { result } = await client.sendCalls({
423
+ * calls: [
424
+ * actions.amm.mint.call({
425
+ * userToken: {
426
+ * address: '0x20c0...beef',
427
+ * amount: 100n,
428
+ * },
429
+ * validatorToken: {
430
+ * address: '0x20c0...babe',
431
+ * amount: 100n,
432
+ * },
433
+ * to: '0xfeed...fede',
434
+ * }),
435
+ * actions.amm.mint.call({
436
+ * userToken: {
437
+ * address: '0x20c0...babe',
438
+ * amount: 100n,
439
+ * },
440
+ * validatorToken: {
441
+ * address: '0x20c0...babe',
442
+ * amount: 100n,
443
+ * },
444
+ * to: '0xfeed...fede',
445
+ * }),
446
+ * ]
447
+ * })
448
+ * ```
449
+ *
450
+ * @param args - Arguments.
451
+ * @returns The call.
452
+ */
453
+ function call(args) {
454
+ const { to, userToken, validatorToken } = args;
455
+ return defineCall({
456
+ address: feeManagerAddress,
457
+ abi: feeAmmAbi,
458
+ functionName: 'mint',
459
+ args: [
460
+ TokenId.toAddress(userToken.address),
461
+ TokenId.toAddress(validatorToken.address),
462
+ userToken.amount,
463
+ validatorToken.amount,
464
+ to,
465
+ ],
466
+ });
467
+ }
468
+ mint.call = call;
469
+ /**
470
+ * Extracts the `Mint` event from logs.
471
+ *
472
+ * @param logs - The logs.
473
+ * @returns The `Mint` event.
474
+ */
475
+ function extractEvent(logs) {
476
+ const [log] = parseEventLogs({
477
+ abi: feeAmmAbi,
478
+ logs,
479
+ eventName: 'Mint',
480
+ strict: true,
481
+ });
482
+ if (!log)
483
+ throw new Error('`Mint` event not found.');
484
+ return log;
485
+ }
486
+ mint.extractEvent = extractEvent;
487
+ })(mint || (mint = {}));
488
+ /**
489
+ * Adds liquidity to a pool.
490
+ *
491
+ * @example
492
+ * ```ts
493
+ * import { createClient, http } from 'viem'
494
+ * import { tempo } from 'tempo.ts/chains'
495
+ * import * as actions from 'tempo.ts/viem/actions'
496
+ * import { privateKeyToAccount } from 'viem/accounts'
497
+ *
498
+ * const client = createClient({
499
+ * account: privateKeyToAccount('0x...'),
500
+ * chain: tempo,
501
+ * transport: http(),
502
+ * })
503
+ *
504
+ * const hash = await actions.amm.mint(client, {
505
+ * userToken: {
506
+ * address: '0x20c0...beef',
507
+ * amount: 100n,
508
+ * },
509
+ * validatorToken: {
510
+ * address: '0x20c0...babe',
511
+ * amount: 100n,
512
+ * },
513
+ * to: '0xfeed...fede',
514
+ * })
515
+ * ```
516
+ *
517
+ * @param client - Client.
518
+ * @param parameters - Parameters.
519
+ * @returns The transaction receipt and event data.
520
+ */
521
+ export async function mintSync(client, parameters) {
522
+ const receipt = await mint.inner(writeContractSync, client, parameters);
523
+ const { args } = mint.extractEvent(receipt.logs);
524
+ return {
525
+ ...args,
526
+ receipt,
527
+ };
528
+ }
529
+ /**
530
+ * Removes liquidity from a pool.
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * import { createClient, http } from 'viem'
535
+ * import { tempo } from 'tempo.ts/chains'
536
+ * import * as actions from 'tempo.ts/viem/actions'
537
+ * import { privateKeyToAccount } from 'viem/accounts'
538
+ *
539
+ * const client = createClient({
540
+ * account: privateKeyToAccount('0x...'),
541
+ * chain: tempo,
542
+ * transport: http(),
543
+ * })
544
+ *
545
+ * const hash = await actions.amm.burn(client, {
546
+ * userToken: '0x20c0...beef',
547
+ * validatorToken: '0x20c0...babe',
548
+ * liquidity: 50n,
549
+ * to: '0xfeed...fede',
550
+ * })
551
+ * ```
552
+ *
553
+ * @param client - Client.
554
+ * @param parameters - Parameters.
555
+ * @returns The transaction hash.
556
+ */
557
+ export async function burn(client, parameters) {
558
+ return burn.inner(writeContract, client, parameters);
559
+ }
560
+ (function (burn) {
561
+ /** @internal */
562
+ async function inner(action, client, parameters) {
563
+ const call = burn.call(parameters);
564
+ return (await action(client, {
565
+ ...parameters,
566
+ ...call,
567
+ }));
568
+ }
569
+ burn.inner = inner;
570
+ /**
571
+ * Defines a call to the `burn` function.
572
+ *
573
+ * Can be passed as a parameter to:
574
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
575
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
576
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
577
+ *
578
+ * @example
579
+ * ```ts
580
+ * import { createClient, http, walletActions } from 'viem'
581
+ * import { tempo } from 'tempo.ts/chains'
582
+ * import * as actions from 'tempo.ts/viem/actions'
583
+ *
584
+ * const client = createClient({
585
+ * chain: tempo,
586
+ * transport: http(),
587
+ * }).extend(walletActions)
588
+ *
589
+ * const { result } = await client.sendCalls({
590
+ * calls: [
591
+ * actions.amm.burn.call({
592
+ * liquidity: 100n,
593
+ * to: '0xfeed...fede',
594
+ * userToken: '0x20c0...beef',
595
+ * validatorToken: '0x20c0...babe',
596
+ * }),
597
+ * actions.amm.burn.call({
598
+ * liquidity: 100n,
599
+ * to: '0xfeed...fede',
600
+ * userToken: '0x20c0...babe',
601
+ * validatorToken: '0x20c0...babe',
602
+ * }),
603
+ * ]
604
+ * })
605
+ * ```
606
+ *
607
+ * @param args - Arguments.
608
+ * @returns The call.
609
+ */
610
+ function call(args) {
611
+ const { liquidity, to, userToken, validatorToken } = args;
612
+ return defineCall({
613
+ address: feeManagerAddress,
614
+ abi: feeAmmAbi,
615
+ functionName: 'burn',
616
+ args: [
617
+ TokenId.toAddress(userToken),
618
+ TokenId.toAddress(validatorToken),
619
+ liquidity,
620
+ to,
621
+ ],
622
+ });
623
+ }
624
+ burn.call = call;
625
+ /**
626
+ * Extracts the `Burn` event from logs.
627
+ *
628
+ * @param logs - The logs.
629
+ * @returns The `Burn` event.
630
+ */
631
+ function extractEvent(logs) {
632
+ const [log] = parseEventLogs({
633
+ abi: feeAmmAbi,
634
+ logs,
635
+ eventName: 'Burn',
636
+ strict: true,
637
+ });
638
+ if (!log)
639
+ throw new Error('`Burn` event not found.');
640
+ return log;
641
+ }
642
+ burn.extractEvent = extractEvent;
643
+ })(burn || (burn = {}));
644
+ /**
645
+ * Removes liquidity from a pool.
646
+ *
647
+ * @example
648
+ * ```ts
649
+ * import { createClient, http } from 'viem'
650
+ * import { tempo } from 'tempo.ts/chains'
651
+ * import * as actions from 'tempo.ts/viem/actions'
652
+ * import { privateKeyToAccount } from 'viem/accounts'
653
+ *
654
+ * const client = createClient({
655
+ * account: privateKeyToAccount('0x...'),
656
+ * chain: tempo,
657
+ * transport: http(),
658
+ * })
659
+ *
660
+ * const result = await actions.amm.burnSync(client, {
661
+ * userToken: '0x20c0...beef',
662
+ * validatorToken: '0x20c0...babe',
663
+ * liquidity: 50n,
664
+ * to: '0xfeed...fede',
665
+ * })
666
+ * ```
667
+ *
668
+ * @param client - Client.
669
+ * @param parameters - Parameters.
670
+ * @returns The transaction receipt and event data.
671
+ */
672
+ export async function burnSync(client, parameters) {
673
+ const receipt = await burn.inner(writeContractSync, client, parameters);
674
+ const { args } = burn.extractEvent(receipt.logs);
675
+ return {
676
+ ...args,
677
+ receipt,
678
+ };
679
+ }
680
+ /**
681
+ * Watches for rebalance swap events.
682
+ *
683
+ * @example
684
+ * ```ts
685
+ * import { createClient, http } from 'viem'
686
+ * import { tempo } from 'tempo.ts/chains'
687
+ * import * as actions from 'tempo.ts/viem/actions'
688
+ *
689
+ * const client = createClient({
690
+ * chain: tempo,
691
+ * transport: http(),
692
+ * })
693
+ *
694
+ * const unwatch = actions.amm.watchRebalanceSwap(client, {
695
+ * onRebalanceSwap: (args, log) => {
696
+ * console.log('Rebalance swap:', args)
697
+ * },
698
+ * })
699
+ * ```
700
+ *
701
+ * @param client - Client.
702
+ * @param parameters - Parameters.
703
+ * @returns A function to unsubscribe from the event.
704
+ */
705
+ export function watchRebalanceSwap(client, parameters) {
706
+ const { onRebalanceSwap, userToken, validatorToken, ...rest } = parameters;
707
+ return watchContractEvent(client, {
708
+ ...rest,
709
+ address: feeManagerAddress,
710
+ abi: feeAmmAbi,
711
+ eventName: 'RebalanceSwap',
712
+ args: userToken !== undefined && validatorToken !== undefined
713
+ ? {
714
+ userToken: TokenId.toAddress(userToken),
715
+ validatorToken: TokenId.toAddress(validatorToken),
716
+ }
717
+ : undefined,
718
+ onLogs: (logs) => {
719
+ for (const log of logs)
720
+ onRebalanceSwap(log.args, log);
721
+ },
722
+ strict: true,
723
+ });
724
+ }
725
+ /**
726
+ * Watches for fee swap events.
727
+ *
728
+ * @example
729
+ * ```ts
730
+ * import { createClient, http } from 'viem'
731
+ * import { tempo } from 'tempo.ts/chains'
732
+ * import * as actions from 'tempo.ts/viem/actions'
733
+ *
734
+ * const client = createClient({
735
+ * chain: tempo,
736
+ * transport: http(),
737
+ * })
738
+ *
739
+ * const unwatch = actions.amm.watchFeeSwap(client, {
740
+ * onFeeSwap: (args, log) => {
741
+ * console.log('Fee swap:', args)
742
+ * },
743
+ * })
744
+ * ```
745
+ *
746
+ * @param client - Client.
747
+ * @param parameters - Parameters.
748
+ * @returns A function to unsubscribe from the event.
749
+ */
750
+ export function watchFeeSwap(client, parameters) {
751
+ const { onFeeSwap, userToken, validatorToken, ...rest } = parameters;
752
+ return watchContractEvent(client, {
753
+ ...rest,
754
+ address: feeManagerAddress,
755
+ abi: feeAmmAbi,
756
+ eventName: 'FeeSwap',
757
+ args: userToken !== undefined && validatorToken !== undefined
758
+ ? {
759
+ userToken: TokenId.toAddress(userToken),
760
+ validatorToken: TokenId.toAddress(validatorToken),
761
+ }
762
+ : undefined,
763
+ onLogs: (logs) => {
764
+ for (const log of logs)
765
+ onFeeSwap(log.args, log);
766
+ },
767
+ strict: true,
768
+ });
769
+ }
770
+ /**
771
+ * Watches for liquidity mint events.
772
+ *
773
+ * @example
774
+ * ```ts
775
+ * import { createClient, http } from 'viem'
776
+ * import { tempo } from 'tempo.ts/chains'
777
+ * import * as actions from 'tempo.ts/viem/actions'
778
+ *
779
+ * const client = createClient({
780
+ * chain: tempo,
781
+ * transport: http(),
782
+ * })
783
+ *
784
+ * const unwatch = actions.amm.watchMint(client, {
785
+ * onMint: (args, log) => {
786
+ * console.log('Liquidity added:', args)
787
+ * },
788
+ * })
789
+ * ```
790
+ *
791
+ * @param client - Client.
792
+ * @param parameters - Parameters.
793
+ * @returns A function to unsubscribe from the event.
794
+ */
795
+ export function watchMint(client, parameters) {
796
+ const { onMint, sender, userToken, validatorToken, ...rest } = parameters;
797
+ return watchContractEvent(client, {
798
+ ...rest,
799
+ address: feeManagerAddress,
800
+ abi: feeAmmAbi,
801
+ eventName: 'Mint',
802
+ args: {
803
+ ...(sender !== undefined && {
804
+ sender: TokenId.toAddress(sender),
805
+ }),
806
+ ...(userToken !== undefined && {
807
+ userToken: TokenId.toAddress(userToken),
808
+ }),
809
+ ...(validatorToken !== undefined && {
810
+ validatorToken: TokenId.toAddress(validatorToken),
811
+ }),
812
+ },
813
+ onLogs: (logs) => {
814
+ for (const log of logs)
815
+ onMint({
816
+ liquidity: log.args.liquidity,
817
+ sender: log.args.sender,
818
+ userToken: {
819
+ address: log.args.userToken,
820
+ amount: log.args.amountUserToken,
821
+ },
822
+ validatorToken: {
823
+ address: log.args.validatorToken,
824
+ amount: log.args.amountValidatorToken,
825
+ },
826
+ }, log);
827
+ },
828
+ strict: true,
829
+ });
830
+ }
831
+ /**
832
+ * Watches for liquidity burn events.
833
+ *
834
+ * @example
835
+ * ```ts
836
+ * import { createClient, http } from 'viem'
837
+ * import { tempo } from 'tempo.ts/chains'
838
+ * import * as actions from 'tempo.ts/viem/actions'
839
+ *
840
+ * const client = createClient({
841
+ * chain: tempo,
842
+ * transport: http(),
843
+ * })
844
+ *
845
+ * const unwatch = actions.amm.watchBurn(client, {
846
+ * onBurn: (args, log) => {
847
+ * console.log('Liquidity removed:', args)
848
+ * },
849
+ * })
850
+ * ```
851
+ *
852
+ * @param client - Client.
853
+ * @param parameters - Parameters.
854
+ * @returns A function to unsubscribe from the event.
855
+ */
856
+ export function watchBurn(client, parameters) {
857
+ const { onBurn, userToken, validatorToken, ...rest } = parameters;
858
+ return watchContractEvent(client, {
859
+ ...rest,
860
+ address: feeManagerAddress,
861
+ abi: feeAmmAbi,
862
+ eventName: 'Burn',
863
+ args: userToken !== undefined && validatorToken !== undefined
864
+ ? {
865
+ userToken: TokenId.toAddress(userToken),
866
+ validatorToken: TokenId.toAddress(validatorToken),
867
+ }
868
+ : undefined,
869
+ onLogs: (logs) => {
870
+ for (const log of logs)
871
+ onBurn(log.args, log);
872
+ },
873
+ strict: true,
874
+ });
875
+ }
876
+ //# sourceMappingURL=amm.js.map