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,2579 @@
1
+ import * as Hex from 'ox/Hex';
2
+ import * as Signature from 'ox/Signature';
3
+ import { encodeFunctionData, parseEventLogs, } from 'viem';
4
+ import { parseAccount } from 'viem/accounts';
5
+ import { multicall, readContract, sendTransaction, sendTransactionSync, watchContractEvent, writeContract, writeContractSync, } from 'viem/actions';
6
+ import * as TokenId from "../../ox/TokenId.js";
7
+ import * as TokenRole from "../../ox/TokenRole.js";
8
+ import { tip20Abi, tip20FactoryAbi } from "../abis.js";
9
+ import { tip20FactoryAddress, usdAddress } from "../addresses.js";
10
+ import { defineCall } from "../utils.js";
11
+ const transferPolicy = {
12
+ 0: 'always-reject',
13
+ 1: 'always-allow',
14
+ };
15
+ /**
16
+ * Approves a spender to transfer TIP20 tokens on behalf of the caller.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { createClient, http } from 'viem'
21
+ * import { tempo } from 'tempo.ts/chains'
22
+ * import * as actions from 'tempo.ts/viem/actions'
23
+ * import { privateKeyToAccount } from 'viem/accounts'
24
+ *
25
+ * const client = createClient({
26
+ * account: privateKeyToAccount('0x...'),
27
+ * chain: tempo,
28
+ * transport: http(),
29
+ * })
30
+ *
31
+ * const result = await actions.token.approve(client, {
32
+ * spender: '0x...',
33
+ * amount: 100n,
34
+ * })
35
+ * ```
36
+ *
37
+ * @param client - Client.
38
+ * @param parameters - Parameters.
39
+ * @returns The transaction hash.
40
+ */
41
+ export async function approve(client, parameters) {
42
+ const { token = usdAddress, ...rest } = parameters;
43
+ return approve.inner(writeContract, client, parameters, { ...rest, token });
44
+ }
45
+ (function (approve) {
46
+ /** @internal */
47
+ async function inner(action, client, parameters, args) {
48
+ const call = approve.call(args);
49
+ return (await action(client, {
50
+ ...parameters,
51
+ ...call,
52
+ }));
53
+ }
54
+ approve.inner = inner;
55
+ /**
56
+ * Defines a call to the `approve` function.
57
+ *
58
+ * Can be passed as a parameter to:
59
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
60
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
61
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { createClient, http, walletActions } from 'viem'
66
+ * import { tempo } from 'tempo.ts/chains'
67
+ * import * as actions from 'tempo.ts/viem/actions'
68
+ *
69
+ * const client = createClient({
70
+ * chain: tempo,
71
+ * transport: http(),
72
+ * }).extend(walletActions)
73
+ *
74
+ * const { result } = await client.sendCalls({
75
+ * calls: [
76
+ * actions.token.approve.call({
77
+ * spender: '0x20c0...beef',
78
+ * amount: 100n,
79
+ * token: '0x20c0...babe',
80
+ * }),
81
+ * ]
82
+ * })
83
+ * ```
84
+ *
85
+ * @param args - Arguments.
86
+ * @returns The call.
87
+ */
88
+ function call(args) {
89
+ const { spender, amount, token = usdAddress } = args;
90
+ return defineCall({
91
+ address: TokenId.toAddress(token),
92
+ abi: tip20Abi,
93
+ functionName: 'approve',
94
+ args: [spender, amount],
95
+ });
96
+ }
97
+ approve.call = call;
98
+ function extractEvent(logs) {
99
+ const [log] = parseEventLogs({
100
+ abi: tip20Abi,
101
+ logs,
102
+ eventName: 'Approval',
103
+ });
104
+ if (!log)
105
+ throw new Error('`Approval` event not found.');
106
+ return log;
107
+ }
108
+ approve.extractEvent = extractEvent;
109
+ })(approve || (approve = {}));
110
+ /**
111
+ * Approves a spender to transfer TIP20 tokens on behalf of the caller.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import { createClient, http } from 'viem'
116
+ * import { tempo } from 'tempo.ts/chains'
117
+ * import * as actions from 'tempo.ts/viem/actions'
118
+ * import { privateKeyToAccount } from 'viem/accounts'
119
+ *
120
+ * const client = createClient({
121
+ * account: privateKeyToAccount('0x...'),
122
+ * chain: tempo,
123
+ * transport: http(),
124
+ * })
125
+ *
126
+ * const result = await actions.token.approveSync(client, {
127
+ * spender: '0x...',
128
+ * amount: 100n,
129
+ * })
130
+ * ```
131
+ *
132
+ * @param client - Client.
133
+ * @param parameters - Parameters.
134
+ * @returns The transaction receipt and event data.
135
+ */
136
+ export async function approveSync(client, parameters) {
137
+ const { token = usdAddress, ...rest } = parameters;
138
+ const receipt = await approve.inner(writeContractSync, client, parameters, {
139
+ ...rest,
140
+ token,
141
+ });
142
+ const { args } = approve.extractEvent(receipt.logs);
143
+ return {
144
+ ...args,
145
+ receipt,
146
+ };
147
+ }
148
+ /**
149
+ * Burns TIP20 tokens from a blocked address.
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * import { createClient, http } from 'viem'
154
+ * import { tempo } from 'tempo.ts/chains'
155
+ * import * as actions from 'tempo.ts/viem/actions'
156
+ * import { privateKeyToAccount } from 'viem/accounts'
157
+ *
158
+ * const client = createClient({
159
+ * account: privateKeyToAccount('0x...'),
160
+ * chain: tempo,
161
+ * transport: http(),
162
+ * })
163
+ *
164
+ * const result = await actions.token.burnBlocked(client, {
165
+ * from: '0x...',
166
+ * amount: 100n,
167
+ * token: '0x...',
168
+ * })
169
+ * ```
170
+ *
171
+ * @param client - Client.
172
+ * @param parameters - Parameters.
173
+ * @returns The transaction hash.
174
+ */
175
+ export async function burnBlocked(client, parameters) {
176
+ return burnBlocked.inner(writeContract, client, parameters);
177
+ }
178
+ (function (burnBlocked) {
179
+ /** @internal */
180
+ async function inner(action, client, parameters) {
181
+ const call = burnBlocked.call(parameters);
182
+ return (await action(client, {
183
+ ...parameters,
184
+ ...call,
185
+ }));
186
+ }
187
+ burnBlocked.inner = inner;
188
+ /**
189
+ * Defines a call to the `burnBlocked` function.
190
+ *
191
+ * Can be passed as a parameter to:
192
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
193
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
194
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * import { createClient, http, walletActions } from 'viem'
199
+ * import { tempo } from 'tempo.ts/chains'
200
+ * import * as actions from 'tempo.ts/viem/actions'
201
+ *
202
+ * const client = createClient({
203
+ * chain: tempo,
204
+ * transport: http(),
205
+ * }).extend(walletActions)
206
+ *
207
+ * const { result } = await client.sendCalls({
208
+ * calls: [
209
+ * actions.token.burnBlocked.call({
210
+ * from: '0x20c0...beef',
211
+ * amount: 100n,
212
+ * token: '0x20c0...babe',
213
+ * }),
214
+ * ]
215
+ * })
216
+ * ```
217
+ *
218
+ * @param args - Arguments.
219
+ * @returns The call.
220
+ */
221
+ function call(args) {
222
+ const { from, amount, token } = args;
223
+ return defineCall({
224
+ address: TokenId.toAddress(token),
225
+ abi: tip20Abi,
226
+ functionName: 'burnBlocked',
227
+ args: [from, amount],
228
+ });
229
+ }
230
+ burnBlocked.call = call;
231
+ /**
232
+ * Extracts the event from the logs.
233
+ *
234
+ * @param logs - Logs.
235
+ * @returns The event.
236
+ */
237
+ function extractEvent(logs) {
238
+ const [log] = parseEventLogs({
239
+ abi: tip20Abi,
240
+ logs,
241
+ eventName: 'BurnBlocked',
242
+ });
243
+ if (!log)
244
+ throw new Error('`BurnBlocked` event not found.');
245
+ return log;
246
+ }
247
+ burnBlocked.extractEvent = extractEvent;
248
+ })(burnBlocked || (burnBlocked = {}));
249
+ /**
250
+ * Burns TIP20 tokens from a blocked address.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * import { createClient, http } from 'viem'
255
+ * import { tempo } from 'tempo.ts/chains'
256
+ * import * as actions from 'tempo.ts/viem/actions'
257
+ * import { privateKeyToAccount } from 'viem/accounts'
258
+ *
259
+ * const client = createClient({
260
+ * account: privateKeyToAccount('0x...'),
261
+ * chain: tempo,
262
+ * transport: http(),
263
+ * })
264
+ *
265
+ * const result = await actions.token.burnBlockedSync(client, {
266
+ * from: '0x...',
267
+ * amount: 100n,
268
+ * token: '0x...',
269
+ * })
270
+ * ```
271
+ *
272
+ * @param client - Client.
273
+ * @param parameters - Parameters.
274
+ * @returns The transaction receipt and event data.
275
+ */
276
+ export async function burnBlockedSync(client, parameters) {
277
+ const receipt = await burnBlocked.inner(writeContractSync, client, parameters);
278
+ const { args } = burnBlocked.extractEvent(receipt.logs);
279
+ return {
280
+ ...args,
281
+ receipt,
282
+ };
283
+ }
284
+ /**
285
+ * Burns TIP20 tokens from the caller's balance.
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * import { createClient, http } from 'viem'
290
+ * import { tempo } from 'tempo.ts/chains'
291
+ * import * as actions from 'tempo.ts/viem/actions'
292
+ * import { privateKeyToAccount } from 'viem/accounts'
293
+ *
294
+ * const client = createClient({
295
+ * account: privateKeyToAccount('0x...'),
296
+ * chain: tempo,
297
+ * transport: http(),
298
+ * })
299
+ *
300
+ * const result = await actions.token.burn(client, {
301
+ * amount: 100n,
302
+ * token: '0x...',
303
+ * })
304
+ * ```
305
+ *
306
+ * @param client - Client.
307
+ * @param parameters - Parameters.
308
+ * @returns The transaction hash.
309
+ */
310
+ export async function burn(client, parameters) {
311
+ return burn.inner(writeContract, client, parameters);
312
+ }
313
+ (function (burn) {
314
+ /** @internal */
315
+ async function inner(action, client, parameters) {
316
+ const call = burn.call(parameters);
317
+ return (await action(client, {
318
+ ...parameters,
319
+ ...call,
320
+ }));
321
+ }
322
+ burn.inner = inner;
323
+ /**
324
+ * Defines a call to the `burn` or `burnWithMemo` function.
325
+ *
326
+ * Can be passed as a parameter to:
327
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
328
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
329
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * import { createClient, http, walletActions } from 'viem'
334
+ * import { tempo } from 'tempo.ts/chains'
335
+ * import * as actions from 'tempo.ts/viem/actions'
336
+ *
337
+ * const client = createClient({
338
+ * chain: tempo,
339
+ * transport: http(),
340
+ * }).extend(walletActions)
341
+ *
342
+ * const { result } = await client.sendCalls({
343
+ * calls: [
344
+ * actions.token.burn.call({
345
+ * amount: 100n,
346
+ * token: '0x20c0...babe',
347
+ * }),
348
+ * ]
349
+ * })
350
+ * ```
351
+ *
352
+ * @param args - Arguments.
353
+ * @returns The call.
354
+ */
355
+ function call(args) {
356
+ const { amount, memo, token } = args;
357
+ const callArgs = memo
358
+ ? {
359
+ functionName: 'burnWithMemo',
360
+ args: [amount, Hex.padLeft(memo, 32)],
361
+ }
362
+ : {
363
+ functionName: 'burn',
364
+ args: [amount],
365
+ };
366
+ return defineCall({
367
+ address: TokenId.toAddress(token),
368
+ abi: tip20Abi,
369
+ ...callArgs,
370
+ });
371
+ }
372
+ burn.call = call;
373
+ /**
374
+ * Extracts the event from the logs.
375
+ *
376
+ * @param logs - Logs.
377
+ * @returns The event.
378
+ */
379
+ function extractEvent(logs) {
380
+ const [log] = parseEventLogs({
381
+ abi: tip20Abi,
382
+ logs,
383
+ eventName: 'Burn',
384
+ });
385
+ if (!log)
386
+ throw new Error('`Burn` event not found.');
387
+ return log;
388
+ }
389
+ burn.extractEvent = extractEvent;
390
+ })(burn || (burn = {}));
391
+ /**
392
+ * Burns TIP20 tokens from the caller's balance.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * import { createClient, http } from 'viem'
397
+ * import { tempo } from 'tempo.ts/chains'
398
+ * import * as actions from 'tempo.ts/viem/actions'
399
+ * import { privateKeyToAccount } from 'viem/accounts'
400
+ *
401
+ * const client = createClient({
402
+ * account: privateKeyToAccount('0x...'),
403
+ * chain: tempo,
404
+ * transport: http(),
405
+ * })
406
+ *
407
+ * const result = await actions.token.burnSync(client, {
408
+ * amount: 100n,
409
+ * token: '0x...',
410
+ * })
411
+ * ```
412
+ *
413
+ * @param client - Client.
414
+ * @param parameters - Parameters.
415
+ * @returns The transaction receipt and event data.
416
+ */
417
+ export async function burnSync(client, parameters) {
418
+ const receipt = await burn.inner(writeContractSync, client, parameters);
419
+ const { args } = burn.extractEvent(receipt.logs);
420
+ return {
421
+ ...args,
422
+ receipt,
423
+ };
424
+ }
425
+ /**
426
+ * Changes the transfer policy ID for a TIP20 token.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * import { createClient, http } from 'viem'
431
+ * import { tempo } from 'tempo.ts/chains'
432
+ * import * as actions from 'tempo.ts/viem/actions'
433
+ * import { privateKeyToAccount } from 'viem/accounts'
434
+ *
435
+ * const client = createClient({
436
+ * account: privateKeyToAccount('0x...'),
437
+ * chain: tempo,
438
+ * transport: http(),
439
+ * })
440
+ *
441
+ * const result = await actions.token.changeTransferPolicy(client, {
442
+ * token: '0x...',
443
+ * policyId: 1n,
444
+ * })
445
+ * ```
446
+ *
447
+ * @param client - Client.
448
+ * @param parameters - Parameters.
449
+ * @returns The transaction hash.
450
+ */
451
+ export async function changeTransferPolicy(client, parameters) {
452
+ return changeTransferPolicy.inner(writeContract, client, parameters);
453
+ }
454
+ (function (changeTransferPolicy) {
455
+ /** @internal */
456
+ async function inner(action, client, parameters) {
457
+ const call = changeTransferPolicy.call(parameters);
458
+ return (await action(client, {
459
+ ...parameters,
460
+ ...call,
461
+ }));
462
+ }
463
+ changeTransferPolicy.inner = inner;
464
+ /**
465
+ * Defines a call to the `changeTransferPolicyId` function.
466
+ *
467
+ * Can be passed as a parameter to:
468
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
469
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
470
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * import { createClient, http, walletActions } from 'viem'
475
+ * import { tempo } from 'tempo.ts/chains'
476
+ * import * as actions from 'tempo.ts/viem/actions'
477
+ *
478
+ * const client = createClient({
479
+ * chain: tempo,
480
+ * transport: http(),
481
+ * }).extend(walletActions)
482
+ *
483
+ * const { result } = await client.sendCalls({
484
+ * calls: [
485
+ * actions.token.changeTransferPolicy.call({
486
+ * token: '0x20c0...babe',
487
+ * policyId: 1n,
488
+ * }),
489
+ * ]
490
+ * })
491
+ * ```
492
+ *
493
+ * @param args - Arguments.
494
+ * @returns The call.
495
+ */
496
+ function call(args) {
497
+ const { token, policyId } = args;
498
+ return defineCall({
499
+ address: TokenId.toAddress(token),
500
+ abi: tip20Abi,
501
+ functionName: 'changeTransferPolicyId',
502
+ args: [policyId],
503
+ });
504
+ }
505
+ changeTransferPolicy.call = call;
506
+ /**
507
+ * Extracts the event from the logs.
508
+ *
509
+ * @param logs - Logs.
510
+ * @returns The event.
511
+ */
512
+ function extractEvent(logs) {
513
+ const [log] = parseEventLogs({
514
+ abi: tip20Abi,
515
+ logs,
516
+ eventName: 'TransferPolicyUpdate',
517
+ });
518
+ if (!log)
519
+ throw new Error('`TransferPolicyUpdate` event not found.');
520
+ return log;
521
+ }
522
+ changeTransferPolicy.extractEvent = extractEvent;
523
+ })(changeTransferPolicy || (changeTransferPolicy = {}));
524
+ /**
525
+ * Changes the transfer policy ID for a TIP20 token.
526
+ *
527
+ * @example
528
+ * ```ts
529
+ * import { createClient, http } from 'viem'
530
+ * import { tempo } from 'tempo.ts/chains'
531
+ * import * as actions from 'tempo.ts/viem/actions'
532
+ * import { privateKeyToAccount } from 'viem/accounts'
533
+ *
534
+ * const client = createClient({
535
+ * account: privateKeyToAccount('0x...'),
536
+ * chain: tempo,
537
+ * transport: http(),
538
+ * })
539
+ *
540
+ * const result = await actions.token.changeTransferPolicySync(client, {
541
+ * token: '0x...',
542
+ * policyId: 1n,
543
+ * })
544
+ * ```
545
+ *
546
+ * @param client - Client.
547
+ * @param parameters - Parameters.
548
+ * @returns The transaction receipt and event data.
549
+ */
550
+ export async function changeTransferPolicySync(client, parameters) {
551
+ const receipt = await changeTransferPolicy.inner(writeContractSync, client, parameters);
552
+ const { args } = changeTransferPolicy.extractEvent(receipt.logs);
553
+ return {
554
+ ...args,
555
+ receipt,
556
+ };
557
+ }
558
+ /**
559
+ * Creates a new TIP20 token.
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * import { createClient, http } from 'viem'
564
+ * import { tempo } from 'tempo.ts/chains'
565
+ * import * as actions from 'tempo.ts/viem/actions'
566
+ * import { privateKeyToAccount } from 'viem/accounts'
567
+ *
568
+ * const client = createClient({
569
+ * account: privateKeyToAccount('0x...'),
570
+ * chain: tempo,
571
+ * transport: http(),
572
+ * })
573
+ *
574
+ * const result = await actions.token.create(client, {
575
+ * name: 'My Token',
576
+ * symbol: 'MTK',
577
+ * currency: 'USD',
578
+ * })
579
+ * ```
580
+ *
581
+ * @param client - Client.
582
+ * @param parameters - Parameters.
583
+ * @returns The transaction hash.
584
+ */
585
+ export async function create(client, parameters) {
586
+ return create.inner(writeContract, client, parameters);
587
+ }
588
+ (function (create) {
589
+ /** @internal */
590
+ async function inner(action, client, parameters) {
591
+ const { account = client.account, admin: admin_ = client.account, chain = client.chain, ...rest } = parameters;
592
+ const admin = admin_ ? parseAccount(admin_) : undefined;
593
+ if (!admin)
594
+ throw new Error('admin is required.');
595
+ const call = create.call({ ...rest, admin: admin.address });
596
+ return (await action(client, {
597
+ ...parameters,
598
+ account,
599
+ chain,
600
+ ...call,
601
+ }));
602
+ }
603
+ create.inner = inner;
604
+ /**
605
+ * Defines a call to the `createToken` function.
606
+ *
607
+ * Can be passed as a parameter to:
608
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
609
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
610
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
611
+ *
612
+ * @example
613
+ * ```ts
614
+ * import { createClient, http, walletActions } from 'viem'
615
+ * import { tempo } from 'tempo.ts/chains'
616
+ * import * as actions from 'tempo.ts/viem/actions'
617
+ *
618
+ * const client = createClient({
619
+ * chain: tempo,
620
+ * transport: http(),
621
+ * }).extend(walletActions)
622
+ *
623
+ * const { result } = await client.sendCalls({
624
+ * calls: [
625
+ * actions.token.create.call({
626
+ * name: 'My Token',
627
+ * symbol: 'MTK',
628
+ * currency: 'USD',
629
+ * admin: '0xfeed...fede',
630
+ * }),
631
+ * ]
632
+ * })
633
+ * ```
634
+ *
635
+ * @param args - Arguments.
636
+ * @returns The call.
637
+ */
638
+ function call(args) {
639
+ const { name, symbol, currency, admin } = args;
640
+ return defineCall({
641
+ address: tip20FactoryAddress,
642
+ abi: tip20FactoryAbi,
643
+ args: [name, symbol, currency, admin],
644
+ functionName: 'createToken',
645
+ });
646
+ }
647
+ create.call = call;
648
+ /**
649
+ * Extracts the `TokenCreated` event from logs.
650
+ *
651
+ * @param logs - The logs.
652
+ * @returns The `TokenCreated` event.
653
+ */
654
+ function extractEvent(logs) {
655
+ const [log] = parseEventLogs({
656
+ abi: tip20FactoryAbi,
657
+ logs,
658
+ eventName: 'TokenCreated',
659
+ strict: true,
660
+ });
661
+ if (!log)
662
+ throw new Error('`TokenCreated` event not found.');
663
+ return log;
664
+ }
665
+ create.extractEvent = extractEvent;
666
+ })(create || (create = {}));
667
+ /**
668
+ * Creates a new TIP20 token.
669
+ *
670
+ * @example
671
+ * ```ts
672
+ * import { createClient, http } from 'viem'
673
+ * import { tempo } from 'tempo.ts/chains'
674
+ * import * as actions from 'tempo.ts/viem/actions'
675
+ * import { privateKeyToAccount } from 'viem/accounts'
676
+ *
677
+ * const client = createClient({
678
+ * account: privateKeyToAccount('0x...'),
679
+ * chain: tempo,
680
+ * transport: http(),
681
+ * })
682
+ *
683
+ * const result = await actions.token.createSync(client, {
684
+ * name: 'My Token',
685
+ * symbol: 'MTK',
686
+ * currency: 'USD',
687
+ * })
688
+ * ```
689
+ *
690
+ * @param client - Client.
691
+ * @param parameters - Parameters.
692
+ * @returns The transaction receipt and event data.
693
+ */
694
+ export async function createSync(client, parameters) {
695
+ const receipt = await create.inner(writeContractSync, client, parameters);
696
+ const { args } = create.extractEvent(receipt.logs);
697
+ return {
698
+ ...args,
699
+ receipt,
700
+ };
701
+ }
702
+ /**
703
+ * Gets TIP20 token allowance.
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * import { createClient, http } from 'viem'
708
+ * import { tempo } from 'tempo.ts/chains'
709
+ * import * as actions from 'tempo.ts/viem/actions'
710
+ * import { privateKeyToAccount } from 'viem/accounts'
711
+ *
712
+ * const client = createClient({
713
+ * account: privateKeyToAccount('0x...'),
714
+ * chain: tempo,
715
+ * transport: http(),
716
+ * })
717
+ *
718
+ * const allowance = await actions.token.getAllowance(client, {
719
+ * spender: '0x...',
720
+ * })
721
+ * ```
722
+ *
723
+ * @param client - Client.
724
+ * @param parameters - Parameters.
725
+ * @returns The token allowance.
726
+ */
727
+ export async function getAllowance(client, parameters) {
728
+ const { account = client.account, ...rest } = parameters;
729
+ const address = account ? parseAccount(account).address : undefined;
730
+ if (!address)
731
+ throw new Error('account is required.');
732
+ return readContract(client, {
733
+ ...rest,
734
+ ...getAllowance.call({ account: address, ...rest }),
735
+ });
736
+ }
737
+ (function (getAllowance) {
738
+ /**
739
+ * Defines a call to the `allowance` function.
740
+ *
741
+ * @param args - Arguments.
742
+ * @returns The call.
743
+ */
744
+ function call(args) {
745
+ const { account, spender, token = usdAddress } = args;
746
+ return defineCall({
747
+ address: TokenId.toAddress(token),
748
+ abi: tip20Abi,
749
+ functionName: 'allowance',
750
+ args: [account, spender],
751
+ });
752
+ }
753
+ getAllowance.call = call;
754
+ })(getAllowance || (getAllowance = {}));
755
+ /**
756
+ * Gets TIP20 token balance for an address.
757
+ *
758
+ * @example
759
+ * ```ts
760
+ * import { createClient, http } from 'viem'
761
+ * import { tempo } from 'tempo.ts/chains'
762
+ * import * as actions from 'tempo.ts/viem/actions'
763
+ * import { privateKeyToAccount } from 'viem/accounts'
764
+ *
765
+ * const client = createClient({
766
+ * account: privateKeyToAccount('0x...'),
767
+ * chain: tempo,
768
+ * transport: http(),
769
+ * })
770
+ *
771
+ * const balance = await actions.token.getBalance(client, {
772
+ * token: '0x...',
773
+ * })
774
+ * ```
775
+ *
776
+ * @param client - Client.
777
+ * @param parameters - Parameters.
778
+ * @returns The token balance.
779
+ */
780
+ export async function getBalance(client, ...parameters) {
781
+ const { account = client.account, ...rest } = parameters[0] ?? {};
782
+ const address = account ? parseAccount(account).address : undefined;
783
+ if (!address)
784
+ throw new Error('account is required.');
785
+ return readContract(client, {
786
+ ...rest,
787
+ ...getBalance.call({ account: address, ...rest }),
788
+ });
789
+ }
790
+ (function (getBalance) {
791
+ /**
792
+ * Defines a call to the `balanceOf` function.
793
+ *
794
+ * @param args - Arguments.
795
+ * @returns The call.
796
+ */
797
+ function call(args) {
798
+ const { account, token = usdAddress } = args;
799
+ return defineCall({
800
+ address: TokenId.toAddress(token),
801
+ abi: tip20Abi,
802
+ functionName: 'balanceOf',
803
+ args: [account],
804
+ });
805
+ }
806
+ getBalance.call = call;
807
+ })(getBalance || (getBalance = {}));
808
+ /**
809
+ * Gets TIP20 token metadata including name, symbol, currency, decimals, and total supply.
810
+ *
811
+ * @example
812
+ * ```ts
813
+ * import { createClient, http } from 'viem'
814
+ * import { tempo } from 'tempo.ts/chains'
815
+ * import * as actions from 'tempo.ts/viem/actions'
816
+ * import { privateKeyToAccount } from 'viem/accounts'
817
+ *
818
+ * const client = createClient({
819
+ * account: privateKeyToAccount('0x...'),
820
+ * chain: tempo,
821
+ * transport: http(),
822
+ * })
823
+ *
824
+ * const metadata = await actions.token.getMetadata(client, {
825
+ * token: '0x...',
826
+ * })
827
+ * ```
828
+ *
829
+ * @param client - Client.
830
+ * @param parameters - Parameters.
831
+ * @returns The token metadata.
832
+ */
833
+ export async function getMetadata(client, parameters = {}) {
834
+ const { token = usdAddress, ...rest } = parameters;
835
+ const address = TokenId.toAddress(token);
836
+ const abi = tip20Abi;
837
+ return multicall(client, {
838
+ ...rest,
839
+ contracts: [
840
+ {
841
+ address,
842
+ abi,
843
+ functionName: 'currency',
844
+ },
845
+ {
846
+ address,
847
+ abi,
848
+ functionName: 'decimals',
849
+ },
850
+ {
851
+ address,
852
+ abi,
853
+ functionName: 'name',
854
+ },
855
+ {
856
+ address,
857
+ abi,
858
+ functionName: 'paused',
859
+ },
860
+ {
861
+ address,
862
+ abi,
863
+ functionName: 'supplyCap',
864
+ },
865
+ {
866
+ address,
867
+ abi,
868
+ functionName: 'symbol',
869
+ },
870
+ {
871
+ address,
872
+ abi,
873
+ functionName: 'totalSupply',
874
+ },
875
+ {
876
+ address,
877
+ abi,
878
+ functionName: 'transferPolicyId',
879
+ },
880
+ ],
881
+ allowFailure: false,
882
+ deployless: true,
883
+ }).then(([currency, decimals, name, paused, supplyCap, symbol, totalSupply, transferPolicyId,]) => ({
884
+ name,
885
+ symbol,
886
+ currency,
887
+ decimals,
888
+ totalSupply,
889
+ paused,
890
+ supplyCap,
891
+ transferPolicy: transferPolicy[Number(transferPolicyId)],
892
+ }));
893
+ }
894
+ /**
895
+ * Grants a role for a TIP20 token.
896
+ *
897
+ * @example
898
+ * ```ts
899
+ * import { createClient, http } from 'viem'
900
+ * import { tempo } from 'tempo.ts/chains'
901
+ * import * as actions from 'tempo.ts/viem/actions'
902
+ * import { privateKeyToAccount } from 'viem/accounts'
903
+ *
904
+ * const client = createClient({
905
+ * account: privateKeyToAccount('0x...'),
906
+ * chain: tempo,
907
+ * transport: http(),
908
+ * })
909
+ *
910
+ * const result = await actions.token.grantRoles(client, {
911
+ * token: '0x...',
912
+ * to: '0x...',
913
+ * roles: ['minter'],
914
+ * })
915
+ * ```
916
+ *
917
+ * @param client - Client.
918
+ * @param parameters - Parameters.
919
+ * @returns The transaction hash.
920
+ */
921
+ export async function grantRoles(client, parameters) {
922
+ return grantRoles.inner(sendTransaction, client, parameters);
923
+ }
924
+ (function (grantRoles) {
925
+ /** @internal */
926
+ async function inner(action, client, parameters) {
927
+ return (await action(client, {
928
+ ...parameters,
929
+ calls: parameters.roles.map((role) => {
930
+ const call = grantRoles.call({ ...parameters, role });
931
+ return {
932
+ ...call,
933
+ data: encodeFunctionData(call),
934
+ };
935
+ }),
936
+ }));
937
+ }
938
+ grantRoles.inner = inner;
939
+ /**
940
+ * Defines a call to the `grantRole` function.
941
+ *
942
+ * Can be passed as a parameter to:
943
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
944
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
945
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
946
+ *
947
+ * @example
948
+ * ```ts
949
+ * import { createClient, http, walletActions } from 'viem'
950
+ * import { tempo } from 'tempo.ts/chains'
951
+ * import * as actions from 'tempo.ts/viem/actions'
952
+ *
953
+ * const client = createClient({
954
+ * chain: tempo,
955
+ * transport: http(),
956
+ * }).extend(walletActions)
957
+ *
958
+ * const { result } = await client.sendCalls({
959
+ * calls: [
960
+ * actions.token.grantRoles.call({
961
+ * token: '0x20c0...babe',
962
+ * to: '0x20c0...beef',
963
+ * role: 'minter',
964
+ * }),
965
+ * ]
966
+ * })
967
+ * ```
968
+ *
969
+ * @param args - Arguments.
970
+ * @returns The call.
971
+ */
972
+ function call(args) {
973
+ const { token, to, role } = args;
974
+ const roleHash = TokenRole.serialize(role);
975
+ return defineCall({
976
+ address: TokenId.toAddress(token),
977
+ abi: tip20Abi,
978
+ functionName: 'grantRole',
979
+ args: [roleHash, to],
980
+ });
981
+ }
982
+ grantRoles.call = call;
983
+ /**
984
+ * Extracts the events from the logs.
985
+ *
986
+ * @param logs - Logs.
987
+ * @returns The events.
988
+ */
989
+ function extractEvents(logs) {
990
+ const events = parseEventLogs({
991
+ abi: tip20Abi,
992
+ logs,
993
+ eventName: 'RoleMembershipUpdated',
994
+ });
995
+ if (events.length === 0)
996
+ throw new Error('`RoleMembershipUpdated` events not found.');
997
+ return events;
998
+ }
999
+ grantRoles.extractEvents = extractEvents;
1000
+ })(grantRoles || (grantRoles = {}));
1001
+ /**
1002
+ * Grants a role for a TIP20 token.
1003
+ *
1004
+ * @example
1005
+ * ```ts
1006
+ * import { createClient, http } from 'viem'
1007
+ * import { tempo } from 'tempo.ts/chains'
1008
+ * import * as actions from 'tempo.ts/viem/actions'
1009
+ * import { privateKeyToAccount } from 'viem/accounts'
1010
+ *
1011
+ * const client = createClient({
1012
+ * account: privateKeyToAccount('0x...'),
1013
+ * chain: tempo,
1014
+ * transport: http(),
1015
+ * })
1016
+ *
1017
+ * const result = await actions.token.grantRolesSync(client, {
1018
+ * token: '0x...',
1019
+ * to: '0x...',
1020
+ * roles: ['minter'],
1021
+ * })
1022
+ * ```
1023
+ *
1024
+ * @param client - Client.
1025
+ * @param parameters - Parameters.
1026
+ * @returns The transaction receipt and event data.
1027
+ */
1028
+ export async function grantRolesSync(client, parameters) {
1029
+ const receipt = await grantRoles.inner(sendTransactionSync, client, parameters);
1030
+ const events = grantRoles.extractEvents(receipt.logs);
1031
+ const value = events.map((event) => event.args);
1032
+ return {
1033
+ receipt,
1034
+ value,
1035
+ };
1036
+ }
1037
+ /**
1038
+ * Mints TIP20 tokens to an address.
1039
+ *
1040
+ * @example
1041
+ * ```ts
1042
+ * import { createClient, http } from 'viem'
1043
+ * import { tempo } from 'tempo.ts/chains'
1044
+ * import * as actions from 'tempo.ts/viem/actions'
1045
+ * import { privateKeyToAccount } from 'viem/accounts'
1046
+ *
1047
+ * const client = createClient({
1048
+ * account: privateKeyToAccount('0x...'),
1049
+ * chain: tempo,
1050
+ * transport: http(),
1051
+ * })
1052
+ *
1053
+ * const result = await actions.token.mint(client, {
1054
+ * to: '0x...',
1055
+ * amount: 100n,
1056
+ * token: '0x...',
1057
+ * })
1058
+ * ```
1059
+ *
1060
+ * @param client - Client.
1061
+ * @param parameters - Parameters.
1062
+ * @returns The transaction hash.
1063
+ */
1064
+ export async function mint(client, parameters) {
1065
+ return mint.inner(writeContract, client, parameters);
1066
+ }
1067
+ (function (mint) {
1068
+ /** @internal */
1069
+ async function inner(action, client, parameters) {
1070
+ const call = mint.call(parameters);
1071
+ return (await action(client, {
1072
+ ...parameters,
1073
+ gas: 30000n,
1074
+ ...call,
1075
+ }));
1076
+ }
1077
+ mint.inner = inner;
1078
+ /**
1079
+ * Defines a call to the `mint` or `mintWithMemo` function.
1080
+ *
1081
+ * Can be passed as a parameter to:
1082
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1083
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1084
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1085
+ *
1086
+ * @example
1087
+ * ```ts
1088
+ * import { createClient, http, walletActions } from 'viem'
1089
+ * import { tempo } from 'tempo.ts/chains'
1090
+ * import * as actions from 'tempo.ts/viem/actions'
1091
+ *
1092
+ * const client = createClient({
1093
+ * chain: tempo,
1094
+ * transport: http(),
1095
+ * }).extend(walletActions)
1096
+ *
1097
+ * const { result } = await client.sendCalls({
1098
+ * calls: [
1099
+ * actions.token.mint.call({
1100
+ * to: '0x20c0...beef',
1101
+ * amount: 100n,
1102
+ * token: '0x20c0...babe',
1103
+ * }),
1104
+ * ]
1105
+ * })
1106
+ * ```
1107
+ *
1108
+ * @param args - Arguments.
1109
+ * @returns The call.
1110
+ */
1111
+ function call(args) {
1112
+ const { to, amount, memo, token } = args;
1113
+ const callArgs = memo
1114
+ ? {
1115
+ functionName: 'mintWithMemo',
1116
+ args: [to, amount, Hex.padLeft(memo, 32)],
1117
+ }
1118
+ : {
1119
+ functionName: 'mint',
1120
+ args: [to, amount],
1121
+ };
1122
+ return defineCall({
1123
+ address: TokenId.toAddress(token),
1124
+ abi: tip20Abi,
1125
+ ...callArgs,
1126
+ });
1127
+ }
1128
+ mint.call = call;
1129
+ /**
1130
+ * Extracts the event from the logs.
1131
+ *
1132
+ * @param logs - Logs.
1133
+ * @returns The event.
1134
+ */
1135
+ function extractEvent(logs) {
1136
+ const [log] = parseEventLogs({
1137
+ abi: tip20Abi,
1138
+ logs,
1139
+ eventName: 'Mint',
1140
+ });
1141
+ if (!log)
1142
+ throw new Error('`Mint` event not found.');
1143
+ return log;
1144
+ }
1145
+ mint.extractEvent = extractEvent;
1146
+ })(mint || (mint = {}));
1147
+ /**
1148
+ * Mints TIP20 tokens to an address.
1149
+ *
1150
+ * @example
1151
+ * ```ts
1152
+ * import { createClient, http } from 'viem'
1153
+ * import { tempo } from 'tempo.ts/chains'
1154
+ * import * as actions from 'tempo.ts/viem/actions'
1155
+ * import { privateKeyToAccount } from 'viem/accounts'
1156
+ *
1157
+ * const client = createClient({
1158
+ * account: privateKeyToAccount('0x...'),
1159
+ * chain: tempo,
1160
+ * transport: http(),
1161
+ * })
1162
+ *
1163
+ * const result = await actions.token.mintSync(client, {
1164
+ * to: '0x...',
1165
+ * amount: 100n,
1166
+ * token: '0x...',
1167
+ * })
1168
+ * ```
1169
+ *
1170
+ * @param client - Client.
1171
+ * @param parameters - Parameters.
1172
+ * @returns The transaction receipt and event data.
1173
+ */
1174
+ export async function mintSync(client, parameters) {
1175
+ const receipt = await mint.inner(writeContractSync, client, parameters);
1176
+ const { args } = mint.extractEvent(receipt.logs);
1177
+ return {
1178
+ ...args,
1179
+ receipt,
1180
+ };
1181
+ }
1182
+ /**
1183
+ * Pauses a TIP20 token.
1184
+ *
1185
+ * @example
1186
+ * ```ts
1187
+ * import { createClient, http } from 'viem'
1188
+ * import { tempo } from 'tempo.ts/chains'
1189
+ * import * as actions from 'tempo.ts/viem/actions'
1190
+ * import { privateKeyToAccount } from 'viem/accounts'
1191
+ *
1192
+ * const client = createClient({
1193
+ * account: privateKeyToAccount('0x...'),
1194
+ * chain: tempo,
1195
+ * transport: http(),
1196
+ * })
1197
+ *
1198
+ * const result = await actions.token.pause(client, {
1199
+ * token: '0x...',
1200
+ * })
1201
+ * ```
1202
+ *
1203
+ * @param client - Client.
1204
+ * @param parameters - Parameters.
1205
+ * @returns The transaction hash.
1206
+ */
1207
+ export async function pause(client, parameters) {
1208
+ return pause.inner(writeContract, client, parameters);
1209
+ }
1210
+ (function (pause) {
1211
+ /** @internal */
1212
+ async function inner(action, client, parameters) {
1213
+ const call = pause.call(parameters);
1214
+ return (await action(client, {
1215
+ ...parameters,
1216
+ ...call,
1217
+ }));
1218
+ }
1219
+ pause.inner = inner;
1220
+ /**
1221
+ * Defines a call to the `pause` function.
1222
+ *
1223
+ * Can be passed as a parameter to:
1224
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1225
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1226
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1227
+ *
1228
+ * @example
1229
+ * ```ts
1230
+ * import { createClient, http, walletActions } from 'viem'
1231
+ * import { tempo } from 'tempo.ts/chains'
1232
+ * import * as actions from 'tempo.ts/viem/actions'
1233
+ *
1234
+ * const client = createClient({
1235
+ * chain: tempo,
1236
+ * transport: http(),
1237
+ * }).extend(walletActions)
1238
+ *
1239
+ * const { result } = await client.sendCalls({
1240
+ * calls: [
1241
+ * actions.token.pause.call({
1242
+ * token: '0x20c0...babe',
1243
+ * }),
1244
+ * ]
1245
+ * })
1246
+ * ```
1247
+ *
1248
+ * @param args - Arguments.
1249
+ * @returns The call.
1250
+ */
1251
+ function call(args) {
1252
+ const { token } = args;
1253
+ return defineCall({
1254
+ address: TokenId.toAddress(token),
1255
+ abi: tip20Abi,
1256
+ functionName: 'pause',
1257
+ args: [],
1258
+ });
1259
+ }
1260
+ pause.call = call;
1261
+ /**
1262
+ * Extracts the event from the logs.
1263
+ *
1264
+ * @param logs - Logs.
1265
+ * @returns The event.
1266
+ */
1267
+ function extractEvent(logs) {
1268
+ const [log] = parseEventLogs({
1269
+ abi: tip20Abi,
1270
+ logs,
1271
+ eventName: 'PauseStateUpdate',
1272
+ });
1273
+ if (!log)
1274
+ throw new Error('`PauseStateUpdate` event not found.');
1275
+ return log;
1276
+ }
1277
+ pause.extractEvent = extractEvent;
1278
+ })(pause || (pause = {}));
1279
+ /**
1280
+ * Pauses a TIP20 token.
1281
+ *
1282
+ * @example
1283
+ * ```ts
1284
+ * import { createClient, http } from 'viem'
1285
+ * import { tempo } from 'tempo.ts/chains'
1286
+ * import * as actions from 'tempo.ts/viem/actions'
1287
+ * import { privateKeyToAccount } from 'viem/accounts'
1288
+ *
1289
+ * const client = createClient({
1290
+ * account: privateKeyToAccount('0x...'),
1291
+ * chain: tempo,
1292
+ * transport: http(),
1293
+ * })
1294
+ *
1295
+ * const result = await actions.token.pauseSync(client, {
1296
+ * token: '0x...',
1297
+ * })
1298
+ * ```
1299
+ *
1300
+ * @param client - Client.
1301
+ * @param parameters - Parameters.
1302
+ * @returns The transaction receipt and event data.
1303
+ */
1304
+ export async function pauseSync(client, parameters) {
1305
+ const receipt = await pause.inner(writeContractSync, client, parameters);
1306
+ const { args } = pause.extractEvent(receipt.logs);
1307
+ return {
1308
+ ...args,
1309
+ receipt,
1310
+ };
1311
+ }
1312
+ /**
1313
+ * Approves a spender using a signed permit.
1314
+ *
1315
+ * @example
1316
+ * ```ts
1317
+ * import { createClient, http } from 'viem'
1318
+ * import { tempo } from 'tempo.ts/chains'
1319
+ * import * as actions from 'tempo.ts/viem/actions'
1320
+ * import { privateKeyToAccount } from 'viem/accounts'
1321
+ *
1322
+ * const client = createClient({
1323
+ * account: privateKeyToAccount('0x...'),
1324
+ * chain: tempo,
1325
+ * transport: http(),
1326
+ * })
1327
+ *
1328
+ * const result = await actions.token.permit(client, {
1329
+ * owner: '0x...',
1330
+ * spender: '0x...',
1331
+ * value: 100n,
1332
+ * deadline: 1234567890n,
1333
+ * signature: { r: 0n, s: 0n, yParity: 0 },
1334
+ * })
1335
+ * ```
1336
+ *
1337
+ * @param client - Client.
1338
+ * @param parameters - Parameters.
1339
+ * @returns The transaction hash.
1340
+ */
1341
+ export async function permit(client, parameters) {
1342
+ return permit.inner(writeContract, client, parameters);
1343
+ }
1344
+ (function (permit) {
1345
+ /** @internal */
1346
+ async function inner(action, client, parameters) {
1347
+ const call = permit.call(parameters);
1348
+ return (await action(client, {
1349
+ ...parameters,
1350
+ ...call,
1351
+ }));
1352
+ }
1353
+ permit.inner = inner;
1354
+ /**
1355
+ * Defines a call to the `permit` function.
1356
+ *
1357
+ * Can be passed as a parameter to:
1358
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1359
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1360
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1361
+ *
1362
+ * @example
1363
+ * ```ts
1364
+ * import { createClient, http, walletActions } from 'viem'
1365
+ * import { tempo } from 'tempo.ts/chains'
1366
+ * import * as actions from 'tempo.ts/viem/actions'
1367
+ *
1368
+ * const client = createClient({
1369
+ * chain: tempo,
1370
+ * transport: http(),
1371
+ * }).extend(walletActions)
1372
+ *
1373
+ * const { result } = await client.sendCalls({
1374
+ * calls: [
1375
+ * actions.token.permit.call({
1376
+ * owner: '0x20c0...beef',
1377
+ * spender: '0x20c0...babe',
1378
+ * value: 100n,
1379
+ * deadline: 1234567890n,
1380
+ * signature: { r: 0n, s: 0n, yParity: 0 },
1381
+ * token: '0x20c0...cafe',
1382
+ * }),
1383
+ * ]
1384
+ * })
1385
+ * ```
1386
+ *
1387
+ * @param args - Arguments.
1388
+ * @returns The call.
1389
+ */
1390
+ function call(args) {
1391
+ const { owner, spender, value, deadline, signature, token = usdAddress, } = args;
1392
+ const { r, s, yParity } = Signature.from(signature);
1393
+ const v = Signature.yParityToV(yParity);
1394
+ return defineCall({
1395
+ address: TokenId.toAddress(token),
1396
+ abi: tip20Abi,
1397
+ functionName: 'permit',
1398
+ args: [
1399
+ owner,
1400
+ spender,
1401
+ value,
1402
+ deadline,
1403
+ v,
1404
+ Hex.trimLeft(Hex.fromNumber(r)),
1405
+ Hex.trimLeft(Hex.fromNumber(s)),
1406
+ ],
1407
+ });
1408
+ }
1409
+ permit.call = call;
1410
+ /**
1411
+ * Extracts the event from the logs.
1412
+ *
1413
+ * @param logs - Logs.
1414
+ * @returns The event.
1415
+ */
1416
+ function extractEvent(logs) {
1417
+ const [log] = parseEventLogs({
1418
+ abi: tip20Abi,
1419
+ logs,
1420
+ eventName: 'Approval',
1421
+ });
1422
+ if (!log)
1423
+ throw new Error('`Approval` event not found.');
1424
+ return log;
1425
+ }
1426
+ permit.extractEvent = extractEvent;
1427
+ })(permit || (permit = {}));
1428
+ /**
1429
+ * Approves a spender using a signed permit.
1430
+ *
1431
+ * @example
1432
+ * ```ts
1433
+ * import { createClient, http } from 'viem'
1434
+ * import { tempo } from 'tempo.ts/chains'
1435
+ * import * as actions from 'tempo.ts/viem/actions'
1436
+ * import { privateKeyToAccount } from 'viem/accounts'
1437
+ *
1438
+ * const client = createClient({
1439
+ * account: privateKeyToAccount('0x...'),
1440
+ * chain: tempo,
1441
+ * transport: http(),
1442
+ * })
1443
+ *
1444
+ * const result = await actions.token.permitSync(client, {
1445
+ * owner: '0x...',
1446
+ * spender: '0x...',
1447
+ * value: 100n,
1448
+ * deadline: 1234567890n,
1449
+ * signature: { r: 0n, s: 0n, yParity: 0 },
1450
+ * })
1451
+ * ```
1452
+ *
1453
+ * @param client - Client.
1454
+ * @param parameters - Parameters.
1455
+ * @returns The transaction receipt and event data.
1456
+ */
1457
+ export async function permitSync(client, parameters) {
1458
+ const receipt = await permit.inner(writeContractSync, client, parameters);
1459
+ const { args } = permit.extractEvent(receipt.logs);
1460
+ return {
1461
+ ...args,
1462
+ receipt,
1463
+ };
1464
+ }
1465
+ /**
1466
+ * Renounces a role for a TIP20 token.
1467
+ *
1468
+ * @example
1469
+ * ```ts
1470
+ * import { createClient, http } from 'viem'
1471
+ * import { tempo } from 'tempo.ts/chains'
1472
+ * import * as actions from 'tempo.ts/viem/actions'
1473
+ * import { privateKeyToAccount } from 'viem/accounts'
1474
+ *
1475
+ * const client = createClient({
1476
+ * account: privateKeyToAccount('0x...'),
1477
+ * chain: tempo,
1478
+ * transport: http(),
1479
+ * })
1480
+ *
1481
+ * const result = await actions.token.renounceRoles(client, {
1482
+ * token: '0x...',
1483
+ * roles: ['minter'],
1484
+ * })
1485
+ * ```
1486
+ *
1487
+ * @param client - Client.
1488
+ * @param parameters - Parameters.
1489
+ * @returns The transaction hash.
1490
+ */
1491
+ export async function renounceRoles(client, parameters) {
1492
+ return renounceRoles.inner(sendTransaction, client, parameters);
1493
+ }
1494
+ (function (renounceRoles) {
1495
+ /** @internal */
1496
+ async function inner(action, client, parameters) {
1497
+ return (await action(client, {
1498
+ ...parameters,
1499
+ calls: parameters.roles.map((role) => {
1500
+ const call = renounceRoles.call({ ...parameters, role });
1501
+ return {
1502
+ ...call,
1503
+ data: encodeFunctionData(call),
1504
+ };
1505
+ }),
1506
+ }));
1507
+ }
1508
+ renounceRoles.inner = inner;
1509
+ /**
1510
+ * Defines a call to the `renounceRole` function.
1511
+ *
1512
+ * Can be passed as a parameter to:
1513
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1514
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1515
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1516
+ *
1517
+ * @example
1518
+ * ```ts
1519
+ * import { createClient, http, walletActions } from 'viem'
1520
+ * import { tempo } from 'tempo.ts/chains'
1521
+ * import * as actions from 'tempo.ts/viem/actions'
1522
+ *
1523
+ * const client = createClient({
1524
+ * chain: tempo,
1525
+ * transport: http(),
1526
+ * }).extend(walletActions)
1527
+ *
1528
+ * const { result } = await client.sendCalls({
1529
+ * calls: [
1530
+ * actions.token.renounceRoles.call({
1531
+ * token: '0x20c0...babe',
1532
+ * role: 'minter',
1533
+ * }),
1534
+ * ]
1535
+ * })
1536
+ * ```
1537
+ *
1538
+ * @param args - Arguments.
1539
+ * @returns The call.
1540
+ */
1541
+ function call(args) {
1542
+ const { token, role } = args;
1543
+ const roleHash = TokenRole.serialize(role);
1544
+ return defineCall({
1545
+ address: TokenId.toAddress(token),
1546
+ abi: tip20Abi,
1547
+ functionName: 'renounceRole',
1548
+ args: [roleHash],
1549
+ });
1550
+ }
1551
+ renounceRoles.call = call;
1552
+ /**
1553
+ * Extracts the events from the logs.
1554
+ *
1555
+ * @param logs - Logs.
1556
+ * @returns The events.
1557
+ */
1558
+ function extractEvents(logs) {
1559
+ const events = parseEventLogs({
1560
+ abi: tip20Abi,
1561
+ logs,
1562
+ eventName: 'RoleMembershipUpdated',
1563
+ });
1564
+ if (events.length === 0)
1565
+ throw new Error('`RoleMembershipUpdated` events not found.');
1566
+ return events;
1567
+ }
1568
+ renounceRoles.extractEvents = extractEvents;
1569
+ })(renounceRoles || (renounceRoles = {}));
1570
+ /**
1571
+ * Renounces a role for a TIP20 token.
1572
+ *
1573
+ * @example
1574
+ * ```ts
1575
+ * import { createClient, http } from 'viem'
1576
+ * import { tempo } from 'tempo.ts/chains'
1577
+ * import * as actions from 'tempo.ts/viem/actions'
1578
+ * import { privateKeyToAccount } from 'viem/accounts'
1579
+ *
1580
+ * const client = createClient({
1581
+ * account: privateKeyToAccount('0x...'),
1582
+ * chain: tempo,
1583
+ * transport: http(),
1584
+ * })
1585
+ *
1586
+ * const result = await actions.token.renounceRolesSync(client, {
1587
+ * token: '0x...',
1588
+ * roles: ['minter'],
1589
+ * })
1590
+ * ```
1591
+ *
1592
+ * @param client - Client.
1593
+ * @param parameters - Parameters.
1594
+ * @returns The transaction receipt and event data.
1595
+ */
1596
+ export async function renounceRolesSync(client, parameters) {
1597
+ const receipt = await renounceRoles.inner(sendTransactionSync, client, parameters);
1598
+ const events = renounceRoles.extractEvents(receipt.logs);
1599
+ const value = events.map((event) => event.args);
1600
+ return {
1601
+ receipt,
1602
+ value,
1603
+ };
1604
+ }
1605
+ /**
1606
+ * Revokes a role for a TIP20 token.
1607
+ *
1608
+ * @example
1609
+ * ```ts
1610
+ * import { createClient, http } from 'viem'
1611
+ * import { tempo } from 'tempo.ts/chains'
1612
+ * import * as actions from 'tempo.ts/viem/actions'
1613
+ * import { privateKeyToAccount } from 'viem/accounts'
1614
+ *
1615
+ * const client = createClient({
1616
+ * account: privateKeyToAccount('0x...'),
1617
+ * chain: tempo,
1618
+ * transport: http(),
1619
+ * })
1620
+ *
1621
+ * const result = await actions.token.revokeRoles(client, {
1622
+ * token: '0x...',
1623
+ * from: '0x...',
1624
+ * roles: ['minter'],
1625
+ * })
1626
+ * ```
1627
+ *
1628
+ * @param client - Client.
1629
+ * @param parameters - Parameters.
1630
+ * @returns The transaction hash.
1631
+ */
1632
+ export async function revokeRoles(client, parameters) {
1633
+ return revokeRoles.inner(sendTransaction, client, parameters);
1634
+ }
1635
+ (function (revokeRoles) {
1636
+ /** @internal */
1637
+ async function inner(action, client, parameters) {
1638
+ return (await action(client, {
1639
+ ...parameters,
1640
+ calls: parameters.roles.map((role) => {
1641
+ const call = revokeRoles.call({ ...parameters, role });
1642
+ return {
1643
+ ...call,
1644
+ data: encodeFunctionData(call),
1645
+ };
1646
+ }),
1647
+ }));
1648
+ }
1649
+ revokeRoles.inner = inner;
1650
+ /**
1651
+ * Defines a call to the `revokeRole` function.
1652
+ *
1653
+ * Can be passed as a parameter to:
1654
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1655
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1656
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1657
+ *
1658
+ * @example
1659
+ * ```ts
1660
+ * import { createClient, http, walletActions } from 'viem'
1661
+ * import { tempo } from 'tempo.ts/chains'
1662
+ * import * as actions from 'tempo.ts/viem/actions'
1663
+ *
1664
+ * const client = createClient({
1665
+ * chain: tempo,
1666
+ * transport: http(),
1667
+ * }).extend(walletActions)
1668
+ *
1669
+ * const { result } = await client.sendCalls({
1670
+ * calls: [
1671
+ * actions.token.revokeRoles.call({
1672
+ * token: '0x20c0...babe',
1673
+ * from: '0x20c0...beef',
1674
+ * role: 'minter',
1675
+ * }),
1676
+ * ]
1677
+ * })
1678
+ * ```
1679
+ *
1680
+ * @param args - Arguments.
1681
+ * @returns The call.
1682
+ */
1683
+ function call(args) {
1684
+ const { token, from, role } = args;
1685
+ const roleHash = TokenRole.serialize(role);
1686
+ return defineCall({
1687
+ address: TokenId.toAddress(token),
1688
+ abi: tip20Abi,
1689
+ functionName: 'revokeRole',
1690
+ args: [roleHash, from],
1691
+ });
1692
+ }
1693
+ revokeRoles.call = call;
1694
+ /**
1695
+ * Extracts the events from the logs.
1696
+ *
1697
+ * @param logs - Logs.
1698
+ * @returns The events.
1699
+ */
1700
+ function extractEvents(logs) {
1701
+ const events = parseEventLogs({
1702
+ abi: tip20Abi,
1703
+ logs,
1704
+ eventName: 'RoleMembershipUpdated',
1705
+ });
1706
+ if (events.length === 0)
1707
+ throw new Error('`RoleMembershipUpdated` events not found.');
1708
+ return events;
1709
+ }
1710
+ revokeRoles.extractEvents = extractEvents;
1711
+ })(revokeRoles || (revokeRoles = {}));
1712
+ /**
1713
+ * Revokes a role for a TIP20 token.
1714
+ *
1715
+ * @example
1716
+ * ```ts
1717
+ * import { createClient, http } from 'viem'
1718
+ * import { tempo } from 'tempo.ts/chains'
1719
+ * import * as actions from 'tempo.ts/viem/actions'
1720
+ * import { privateKeyToAccount } from 'viem/accounts'
1721
+ *
1722
+ * const client = createClient({
1723
+ * account: privateKeyToAccount('0x...'),
1724
+ * chain: tempo,
1725
+ * transport: http(),
1726
+ * })
1727
+ *
1728
+ * const result = await actions.token.revokeRolesSync(client, {
1729
+ * token: '0x...',
1730
+ * from: '0x...',
1731
+ * roles: ['minter'],
1732
+ * })
1733
+ * ```
1734
+ *
1735
+ * @param client - Client.
1736
+ * @param parameters - Parameters.
1737
+ * @returns The transaction receipt and event data.
1738
+ */
1739
+ export async function revokeRolesSync(client, parameters) {
1740
+ const receipt = await revokeRoles.inner(sendTransactionSync, client, parameters);
1741
+ const events = revokeRoles.extractEvents(receipt.logs);
1742
+ const value = events.map((event) => event.args);
1743
+ return {
1744
+ receipt,
1745
+ value,
1746
+ };
1747
+ }
1748
+ /**
1749
+ * Sets the supply cap for a TIP20 token.
1750
+ *
1751
+ * @example
1752
+ * ```ts
1753
+ * import { createClient, http } from 'viem'
1754
+ * import { tempo } from 'tempo.ts/chains'
1755
+ * import * as actions from 'tempo.ts/viem/actions'
1756
+ * import { privateKeyToAccount } from 'viem/accounts'
1757
+ *
1758
+ * const client = createClient({
1759
+ * account: privateKeyToAccount('0x...'),
1760
+ * chain: tempo,
1761
+ * transport: http(),
1762
+ * })
1763
+ *
1764
+ * const result = await actions.token.setSupplyCap(client, {
1765
+ * token: '0x...',
1766
+ * supplyCap: 1000000n,
1767
+ * })
1768
+ * ```
1769
+ *
1770
+ * @param client - Client.
1771
+ * @param parameters - Parameters.
1772
+ * @returns The transaction hash.
1773
+ */
1774
+ export async function setSupplyCap(client, parameters) {
1775
+ return setSupplyCap.inner(writeContract, client, parameters);
1776
+ }
1777
+ (function (setSupplyCap) {
1778
+ /** @internal */
1779
+ async function inner(action, client, parameters) {
1780
+ const call = setSupplyCap.call(parameters);
1781
+ return (await action(client, {
1782
+ ...parameters,
1783
+ ...call,
1784
+ }));
1785
+ }
1786
+ setSupplyCap.inner = inner;
1787
+ /**
1788
+ * Defines a call to the `setSupplyCap` function.
1789
+ *
1790
+ * Can be passed as a parameter to:
1791
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1792
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1793
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1794
+ *
1795
+ * @example
1796
+ * ```ts
1797
+ * import { createClient, http, walletActions } from 'viem'
1798
+ * import { tempo } from 'tempo.ts/chains'
1799
+ * import * as actions from 'tempo.ts/viem/actions'
1800
+ *
1801
+ * const client = createClient({
1802
+ * chain: tempo,
1803
+ * transport: http(),
1804
+ * }).extend(walletActions)
1805
+ *
1806
+ * const { result } = await client.sendCalls({
1807
+ * calls: [
1808
+ * actions.token.setSupplyCap.call({
1809
+ * token: '0x20c0...babe',
1810
+ * supplyCap: 1000000n,
1811
+ * }),
1812
+ * ]
1813
+ * })
1814
+ * ```
1815
+ *
1816
+ * @param args - Arguments.
1817
+ * @returns The call.
1818
+ */
1819
+ function call(args) {
1820
+ const { token, supplyCap } = args;
1821
+ return defineCall({
1822
+ address: TokenId.toAddress(token),
1823
+ abi: tip20Abi,
1824
+ functionName: 'setSupplyCap',
1825
+ args: [supplyCap],
1826
+ });
1827
+ }
1828
+ setSupplyCap.call = call;
1829
+ /**
1830
+ * Extracts the event from the logs.
1831
+ *
1832
+ * @param logs - Logs.
1833
+ * @returns The event.
1834
+ */
1835
+ function extractEvent(logs) {
1836
+ const [log] = parseEventLogs({
1837
+ abi: tip20Abi,
1838
+ logs,
1839
+ eventName: 'SupplyCapUpdate',
1840
+ });
1841
+ if (!log)
1842
+ throw new Error('`SupplyCapUpdate` event not found.');
1843
+ return log;
1844
+ }
1845
+ setSupplyCap.extractEvent = extractEvent;
1846
+ })(setSupplyCap || (setSupplyCap = {}));
1847
+ /**
1848
+ * Sets the supply cap for a TIP20 token.
1849
+ *
1850
+ * @example
1851
+ * ```ts
1852
+ * import { createClient, http } from 'viem'
1853
+ * import { tempo } from 'tempo.ts/chains'
1854
+ * import * as actions from 'tempo.ts/viem/actions'
1855
+ * import { privateKeyToAccount } from 'viem/accounts'
1856
+ *
1857
+ * const client = createClient({
1858
+ * account: privateKeyToAccount('0x...'),
1859
+ * chain: tempo,
1860
+ * transport: http(),
1861
+ * })
1862
+ *
1863
+ * const result = await actions.token.setSupplyCapSync(client, {
1864
+ * token: '0x...',
1865
+ * supplyCap: 1000000n,
1866
+ * })
1867
+ * ```
1868
+ *
1869
+ * @param client - Client.
1870
+ * @param parameters - Parameters.
1871
+ * @returns The transaction receipt and event data.
1872
+ */
1873
+ export async function setSupplyCapSync(client, parameters) {
1874
+ const receipt = await setSupplyCap.inner(writeContractSync, client, parameters);
1875
+ const { args } = setSupplyCap.extractEvent(receipt.logs);
1876
+ return {
1877
+ ...args,
1878
+ receipt,
1879
+ };
1880
+ }
1881
+ /**
1882
+ * Sets the admin role for a specific role in a TIP20 token.
1883
+ *
1884
+ * @example
1885
+ * ```ts
1886
+ * import { createClient, http } from 'viem'
1887
+ * import { tempo } from 'tempo.ts/chains'
1888
+ * import * as actions from 'tempo.ts/viem/actions'
1889
+ * import { privateKeyToAccount } from 'viem/accounts'
1890
+ *
1891
+ * const client = createClient({
1892
+ * account: privateKeyToAccount('0x...'),
1893
+ * chain: tempo,
1894
+ * transport: http(),
1895
+ * })
1896
+ *
1897
+ * const result = await actions.token.setRoleAdmin(client, {
1898
+ * token: '0x...',
1899
+ * role: 'minter',
1900
+ * adminRole: 'admin',
1901
+ * })
1902
+ * ```
1903
+ *
1904
+ * @param client - Client.
1905
+ * @param parameters - Parameters.
1906
+ * @returns The transaction hash.
1907
+ */
1908
+ export async function setRoleAdmin(client, parameters) {
1909
+ return setRoleAdmin.inner(writeContract, client, parameters);
1910
+ }
1911
+ (function (setRoleAdmin) {
1912
+ /** @internal */
1913
+ async function inner(action, client, parameters) {
1914
+ const call = setRoleAdmin.call(parameters);
1915
+ return (await action(client, {
1916
+ ...parameters,
1917
+ ...call,
1918
+ }));
1919
+ }
1920
+ setRoleAdmin.inner = inner;
1921
+ /**
1922
+ * Defines a call to the `setRoleAdmin` function.
1923
+ *
1924
+ * Can be passed as a parameter to:
1925
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1926
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1927
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1928
+ *
1929
+ * @example
1930
+ * ```ts
1931
+ * import { createClient, http, walletActions } from 'viem'
1932
+ * import { tempo } from 'tempo.ts/chains'
1933
+ * import * as actions from 'tempo.ts/viem/actions'
1934
+ *
1935
+ * const client = createClient({
1936
+ * chain: tempo,
1937
+ * transport: http(),
1938
+ * }).extend(walletActions)
1939
+ *
1940
+ * const { result } = await client.sendCalls({
1941
+ * calls: [
1942
+ * actions.token.setRoleAdmin.call({
1943
+ * token: '0x20c0...babe',
1944
+ * role: 'minter',
1945
+ * adminRole: 'admin',
1946
+ * }),
1947
+ * ]
1948
+ * })
1949
+ * ```
1950
+ *
1951
+ * @param args - Arguments.
1952
+ * @returns The call.
1953
+ */
1954
+ function call(args) {
1955
+ const { token, role, adminRole } = args;
1956
+ const roleHash = TokenRole.serialize(role);
1957
+ const adminRoleHash = TokenRole.serialize(adminRole);
1958
+ return defineCall({
1959
+ address: TokenId.toAddress(token),
1960
+ abi: tip20Abi,
1961
+ functionName: 'setRoleAdmin',
1962
+ args: [roleHash, adminRoleHash],
1963
+ });
1964
+ }
1965
+ setRoleAdmin.call = call;
1966
+ /**
1967
+ * Extracts the event from the logs.
1968
+ *
1969
+ * @param logs - Logs.
1970
+ * @returns The event.
1971
+ */
1972
+ function extractEvent(logs) {
1973
+ const [log] = parseEventLogs({
1974
+ abi: tip20Abi,
1975
+ logs,
1976
+ eventName: 'RoleAdminUpdated',
1977
+ });
1978
+ if (!log)
1979
+ throw new Error('`RoleAdminUpdated` event not found.');
1980
+ return log;
1981
+ }
1982
+ setRoleAdmin.extractEvent = extractEvent;
1983
+ })(setRoleAdmin || (setRoleAdmin = {}));
1984
+ /**
1985
+ * Sets the admin role for a specific role in a TIP20 token.
1986
+ *
1987
+ * @example
1988
+ * ```ts
1989
+ * import { createClient, http } from 'viem'
1990
+ * import { tempo } from 'tempo.ts/chains'
1991
+ * import * as actions from 'tempo.ts/viem/actions'
1992
+ * import { privateKeyToAccount } from 'viem/accounts'
1993
+ *
1994
+ * const client = createClient({
1995
+ * account: privateKeyToAccount('0x...'),
1996
+ * chain: tempo,
1997
+ * transport: http(),
1998
+ * })
1999
+ *
2000
+ * const result = await actions.token.setRoleAdminSync(client, {
2001
+ * token: '0x...',
2002
+ * role: 'minter',
2003
+ * adminRole: 'admin',
2004
+ * })
2005
+ * ```
2006
+ *
2007
+ * @param client - Client.
2008
+ * @param parameters - Parameters.
2009
+ * @returns The transaction receipt and event data.
2010
+ */
2011
+ export async function setRoleAdminSync(client, parameters) {
2012
+ const receipt = await setRoleAdmin.inner(writeContractSync, client, parameters);
2013
+ const { args } = setRoleAdmin.extractEvent(receipt.logs);
2014
+ return {
2015
+ ...args,
2016
+ receipt,
2017
+ };
2018
+ }
2019
+ /**
2020
+ * Transfers TIP20 tokens to another address.
2021
+ *
2022
+ * @example
2023
+ * ```ts
2024
+ * import { createClient, http } from 'viem'
2025
+ * import { tempo } from 'tempo.ts/chains'
2026
+ * import * as actions from 'tempo.ts/viem/actions'
2027
+ * import { privateKeyToAccount } from 'viem/accounts'
2028
+ *
2029
+ * const client = createClient({
2030
+ * account: privateKeyToAccount('0x...'),
2031
+ * chain: tempo,
2032
+ * transport: http(),
2033
+ * })
2034
+ *
2035
+ * const result = await actions.token.transfer(client, {
2036
+ * to: '0x...',
2037
+ * amount: 100n,
2038
+ * })
2039
+ * ```
2040
+ *
2041
+ * @param client - Client.
2042
+ * @param parameters - Parameters.
2043
+ * @returns The transaction hash.
2044
+ */
2045
+ export async function transfer(client, parameters) {
2046
+ return transfer.inner(writeContract, client, parameters);
2047
+ }
2048
+ (function (transfer) {
2049
+ /** @internal */
2050
+ async function inner(action, client, parameters) {
2051
+ const call = transfer.call(parameters);
2052
+ return (await action(client, {
2053
+ ...parameters,
2054
+ ...call,
2055
+ }));
2056
+ }
2057
+ transfer.inner = inner;
2058
+ /**
2059
+ * Defines a call to the `transfer`, `transferFrom`, `transferWithMemo`, or `transferFromWithMemo` function.
2060
+ *
2061
+ * Can be passed as a parameter to:
2062
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2063
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2064
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2065
+ *
2066
+ * @example
2067
+ * ```ts
2068
+ * import { createClient, http, walletActions } from 'viem'
2069
+ * import { tempo } from 'tempo.ts/chains'
2070
+ * import * as actions from 'tempo.ts/viem/actions'
2071
+ *
2072
+ * const client = createClient({
2073
+ * chain: tempo,
2074
+ * transport: http(),
2075
+ * }).extend(walletActions)
2076
+ *
2077
+ * const { result } = await client.sendCalls({
2078
+ * calls: [
2079
+ * actions.token.transfer.call({
2080
+ * to: '0x20c0...beef',
2081
+ * amount: 100n,
2082
+ * token: '0x20c0...babe',
2083
+ * }),
2084
+ * ]
2085
+ * })
2086
+ * ```
2087
+ *
2088
+ * @param args - Arguments.
2089
+ * @returns The call.
2090
+ */
2091
+ function call(args) {
2092
+ const { amount, from, memo, token = usdAddress, to } = args;
2093
+ const callArgs = (() => {
2094
+ if (memo && from)
2095
+ return {
2096
+ functionName: 'transferFromWithMemo',
2097
+ args: [from, to, amount, Hex.padLeft(memo, 32)],
2098
+ };
2099
+ if (memo)
2100
+ return {
2101
+ functionName: 'transferWithMemo',
2102
+ args: [to, amount, Hex.padLeft(memo, 32)],
2103
+ };
2104
+ if (from)
2105
+ return {
2106
+ functionName: 'transferFrom',
2107
+ args: [from, to, amount],
2108
+ };
2109
+ return {
2110
+ functionName: 'transfer',
2111
+ args: [to, amount],
2112
+ };
2113
+ })();
2114
+ return defineCall({
2115
+ address: TokenId.toAddress(token),
2116
+ abi: tip20Abi,
2117
+ ...callArgs,
2118
+ });
2119
+ }
2120
+ transfer.call = call;
2121
+ /**
2122
+ * Extracts the event from the logs.
2123
+ *
2124
+ * @param logs - Logs.
2125
+ * @returns The event.
2126
+ */
2127
+ function extractEvent(logs) {
2128
+ const [log] = parseEventLogs({
2129
+ abi: tip20Abi,
2130
+ logs,
2131
+ eventName: 'Transfer',
2132
+ });
2133
+ if (!log)
2134
+ throw new Error('`Transfer` event not found.');
2135
+ return log;
2136
+ }
2137
+ transfer.extractEvent = extractEvent;
2138
+ })(transfer || (transfer = {}));
2139
+ /**
2140
+ * Transfers TIP20 tokens to another address.
2141
+ *
2142
+ * @example
2143
+ * ```ts
2144
+ * import { createClient, http } from 'viem'
2145
+ * import { tempo } from 'tempo.ts/chains'
2146
+ * import * as actions from 'tempo.ts/viem/actions'
2147
+ * import { privateKeyToAccount } from 'viem/accounts'
2148
+ *
2149
+ * const client = createClient({
2150
+ * account: privateKeyToAccount('0x...'),
2151
+ * chain: tempo,
2152
+ * transport: http(),
2153
+ * })
2154
+ *
2155
+ * const result = await actions.token.transferSync(client, {
2156
+ * to: '0x...',
2157
+ * amount: 100n,
2158
+ * })
2159
+ * ```
2160
+ *
2161
+ * @param client - Client.
2162
+ * @param parameters - Parameters.
2163
+ * @returns The transaction receipt and event data.
2164
+ */
2165
+ export async function transferSync(client, parameters) {
2166
+ const receipt = await transfer.inner(writeContractSync, client, parameters);
2167
+ const { args } = transfer.extractEvent(receipt.logs);
2168
+ return {
2169
+ ...args,
2170
+ receipt,
2171
+ };
2172
+ }
2173
+ /**
2174
+ * Unpauses a TIP20 token.
2175
+ *
2176
+ * @example
2177
+ * ```ts
2178
+ * import { createClient, http } from 'viem'
2179
+ * import { tempo } from 'tempo.ts/chains'
2180
+ * import * as actions from 'tempo.ts/viem/actions'
2181
+ * import { privateKeyToAccount } from 'viem/accounts'
2182
+ *
2183
+ * const client = createClient({
2184
+ * account: privateKeyToAccount('0x...'),
2185
+ * chain: tempo,
2186
+ * transport: http(),
2187
+ * })
2188
+ *
2189
+ * const result = await actions.token.unpause(client, {
2190
+ * token: '0x...',
2191
+ * })
2192
+ * ```
2193
+ *
2194
+ * @param client - Client.
2195
+ * @param parameters - Parameters.
2196
+ * @returns The transaction hash.
2197
+ */
2198
+ export async function unpause(client, parameters) {
2199
+ return unpause.inner(writeContract, client, parameters);
2200
+ }
2201
+ (function (unpause) {
2202
+ /** @internal */
2203
+ async function inner(action, client, parameters) {
2204
+ const call = unpause.call(parameters);
2205
+ return (await action(client, {
2206
+ ...parameters,
2207
+ ...call,
2208
+ }));
2209
+ }
2210
+ unpause.inner = inner;
2211
+ /**
2212
+ * Defines a call to the `unpause` function.
2213
+ *
2214
+ * Can be passed as a parameter to:
2215
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2216
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2217
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2218
+ *
2219
+ * @example
2220
+ * ```ts
2221
+ * import { createClient, http, walletActions } from 'viem'
2222
+ * import { tempo } from 'tempo.ts/chains'
2223
+ * import * as actions from 'tempo.ts/viem/actions'
2224
+ *
2225
+ * const client = createClient({
2226
+ * chain: tempo,
2227
+ * transport: http(),
2228
+ * }).extend(walletActions)
2229
+ *
2230
+ * const { result } = await client.sendCalls({
2231
+ * calls: [
2232
+ * actions.token.unpause.call({
2233
+ * token: '0x20c0...babe',
2234
+ * }),
2235
+ * ]
2236
+ * })
2237
+ * ```
2238
+ *
2239
+ * @param args - Arguments.
2240
+ * @returns The call.
2241
+ */
2242
+ function call(args) {
2243
+ const { token } = args;
2244
+ return defineCall({
2245
+ address: TokenId.toAddress(token),
2246
+ abi: tip20Abi,
2247
+ functionName: 'unpause',
2248
+ args: [],
2249
+ });
2250
+ }
2251
+ unpause.call = call;
2252
+ /**
2253
+ * Extracts the event from the logs.
2254
+ *
2255
+ * @param logs - Logs.
2256
+ * @returns The event.
2257
+ */
2258
+ function extractEvent(logs) {
2259
+ const [log] = parseEventLogs({
2260
+ abi: tip20Abi,
2261
+ logs,
2262
+ eventName: 'PauseStateUpdate',
2263
+ });
2264
+ if (!log)
2265
+ throw new Error('`PauseStateUpdate` event not found.');
2266
+ return log;
2267
+ }
2268
+ unpause.extractEvent = extractEvent;
2269
+ })(unpause || (unpause = {}));
2270
+ /**
2271
+ * Unpauses a TIP20 token.
2272
+ *
2273
+ * @example
2274
+ * ```ts
2275
+ * import { createClient, http } from 'viem'
2276
+ * import { tempo } from 'tempo.ts/chains'
2277
+ * import * as actions from 'tempo.ts/viem/actions'
2278
+ * import { privateKeyToAccount } from 'viem/accounts'
2279
+ *
2280
+ * const client = createClient({
2281
+ * account: privateKeyToAccount('0x...'),
2282
+ * chain: tempo,
2283
+ * transport: http(),
2284
+ * })
2285
+ *
2286
+ * const result = await actions.token.unpauseSync(client, {
2287
+ * token: '0x...',
2288
+ * })
2289
+ * ```
2290
+ *
2291
+ * @param client - Client.
2292
+ * @param parameters - Parameters.
2293
+ * @returns The transaction receipt and event data.
2294
+ */
2295
+ export async function unpauseSync(client, parameters) {
2296
+ const receipt = await unpause.inner(writeContractSync, client, parameters);
2297
+ const { args } = unpause.extractEvent(receipt.logs);
2298
+ return {
2299
+ ...args,
2300
+ receipt,
2301
+ };
2302
+ }
2303
+ /**
2304
+ * Watches for TIP20 token approval events.
2305
+ *
2306
+ * @example
2307
+ * ```ts
2308
+ * import { createClient, http } from 'viem'
2309
+ * import { tempo } from 'tempo.ts/chains'
2310
+ * import * as actions from 'tempo.ts/viem/actions'
2311
+ *
2312
+ * const client = createClient({
2313
+ * chain: tempo,
2314
+ * transport: http(),
2315
+ * })
2316
+ *
2317
+ * const unwatch = actions.token.watchApprove(client, {
2318
+ * onApproval: (args, log) => {
2319
+ * console.log('Approval:', args)
2320
+ * },
2321
+ * })
2322
+ * ```
2323
+ *
2324
+ * @param client - Client.
2325
+ * @param parameters - Parameters.
2326
+ * @returns A function to unsubscribe from the event.
2327
+ */
2328
+ export function watchApprove(client, parameters) {
2329
+ const { onApproval, token = usdAddress, ...rest } = parameters;
2330
+ return watchContractEvent(client, {
2331
+ ...rest,
2332
+ address: TokenId.toAddress(token),
2333
+ abi: tip20Abi,
2334
+ eventName: 'Approval',
2335
+ onLogs: (logs) => {
2336
+ for (const log of logs)
2337
+ onApproval(log.args, log);
2338
+ },
2339
+ strict: true,
2340
+ });
2341
+ }
2342
+ /**
2343
+ * Watches for TIP20 token burn events.
2344
+ *
2345
+ * @example
2346
+ * ```ts
2347
+ * import { createClient, http } from 'viem'
2348
+ * import { tempo } from 'tempo.ts/chains'
2349
+ * import * as actions from 'tempo.ts/viem/actions'
2350
+ *
2351
+ * const client = createClient({
2352
+ * chain: tempo,
2353
+ * transport: http(),
2354
+ * })
2355
+ *
2356
+ * const unwatch = actions.token.watchBurn(client, {
2357
+ * onBurn: (args, log) => {
2358
+ * console.log('Burn:', args)
2359
+ * },
2360
+ * })
2361
+ * ```
2362
+ *
2363
+ * @param client - Client.
2364
+ * @param parameters - Parameters.
2365
+ * @returns A function to unsubscribe from the event.
2366
+ */
2367
+ export function watchBurn(client, parameters) {
2368
+ const { onBurn, token = usdAddress, ...rest } = parameters;
2369
+ return watchContractEvent(client, {
2370
+ ...rest,
2371
+ address: TokenId.toAddress(token),
2372
+ abi: tip20Abi,
2373
+ eventName: 'Burn',
2374
+ onLogs: (logs) => {
2375
+ for (const log of logs)
2376
+ onBurn(log.args, log);
2377
+ },
2378
+ strict: true,
2379
+ });
2380
+ }
2381
+ /**
2382
+ * Watches for new TIP20 tokens created.
2383
+ *
2384
+ * @example
2385
+ * ```ts
2386
+ * import { createClient, http } from 'viem'
2387
+ * import { tempo } from 'tempo.ts/chains'
2388
+ * import * as actions from 'tempo.ts/viem/actions'
2389
+ *
2390
+ * const client = createClient({
2391
+ * chain: tempo,
2392
+ * transport: http(),
2393
+ * })
2394
+ *
2395
+ * const unwatch = actions.token.watchCreate(client, {
2396
+ * onTokenCreated: (args, log) => {
2397
+ * console.log('Token created:', args)
2398
+ * },
2399
+ * })
2400
+ * ```
2401
+ *
2402
+ * @param client - Client.
2403
+ * @param parameters - Parameters.
2404
+ * @returns A function to unsubscribe from the event.
2405
+ */
2406
+ export function watchCreate(client, parameters) {
2407
+ const { onTokenCreated, ...rest } = parameters;
2408
+ return watchContractEvent(client, {
2409
+ ...rest,
2410
+ address: tip20FactoryAddress,
2411
+ abi: tip20FactoryAbi,
2412
+ eventName: 'TokenCreated',
2413
+ onLogs: (logs) => {
2414
+ for (const log of logs)
2415
+ onTokenCreated(log.args, log);
2416
+ },
2417
+ strict: true,
2418
+ });
2419
+ }
2420
+ /**
2421
+ * Watches for TIP20 token mint events.
2422
+ *
2423
+ * @example
2424
+ * ```ts
2425
+ * import { createClient, http } from 'viem'
2426
+ * import { tempo } from 'tempo.ts/chains'
2427
+ * import * as actions from 'tempo.ts/viem/actions'
2428
+ *
2429
+ * const client = createClient({
2430
+ * chain: tempo,
2431
+ * transport: http(),
2432
+ * })
2433
+ *
2434
+ * const unwatch = actions.token.watchMint(client, {
2435
+ * onMint: (args, log) => {
2436
+ * console.log('Mint:', args)
2437
+ * },
2438
+ * })
2439
+ * ```
2440
+ *
2441
+ * @param client - Client.
2442
+ * @param parameters - Parameters.
2443
+ * @returns A function to unsubscribe from the event.
2444
+ */
2445
+ export function watchMint(client, parameters) {
2446
+ const { onMint, token = usdAddress, ...rest } = parameters;
2447
+ return watchContractEvent(client, {
2448
+ ...rest,
2449
+ address: TokenId.toAddress(token),
2450
+ abi: tip20Abi,
2451
+ eventName: 'Mint',
2452
+ onLogs: (logs) => {
2453
+ for (const log of logs)
2454
+ onMint(log.args, log);
2455
+ },
2456
+ strict: true,
2457
+ });
2458
+ }
2459
+ /**
2460
+ * Watches for TIP20 token role admin updates.
2461
+ *
2462
+ * @example
2463
+ * ```ts
2464
+ * import { createClient, http } from 'viem'
2465
+ * import { tempo } from 'tempo.ts/chains'
2466
+ * import * as actions from 'tempo.ts/viem/actions'
2467
+ *
2468
+ * const client = createClient({
2469
+ * chain: tempo,
2470
+ * transport: http(),
2471
+ * })
2472
+ *
2473
+ * const unwatch = actions.token.watchAdminRole(client, {
2474
+ * onRoleAdminUpdated: (args, log) => {
2475
+ * console.log('Role admin updated:', args)
2476
+ * },
2477
+ * })
2478
+ * ```
2479
+ *
2480
+ * @param client - Client.
2481
+ * @param parameters - Parameters.
2482
+ * @returns A function to unsubscribe from the event.
2483
+ */
2484
+ export function watchAdminRole(client, parameters) {
2485
+ const { onRoleAdminUpdated, token = usdAddress, ...rest } = parameters;
2486
+ return watchContractEvent(client, {
2487
+ ...rest,
2488
+ address: TokenId.toAddress(token),
2489
+ abi: tip20Abi,
2490
+ eventName: 'RoleAdminUpdated',
2491
+ onLogs: (logs) => {
2492
+ for (const log of logs)
2493
+ onRoleAdminUpdated(log.args, log);
2494
+ },
2495
+ strict: true,
2496
+ });
2497
+ }
2498
+ /**
2499
+ * Watches for TIP20 token role membership updates.
2500
+ *
2501
+ * @example
2502
+ * ```ts
2503
+ * import { createClient, http } from 'viem'
2504
+ * import { tempo } from 'tempo.ts/chains'
2505
+ * import * as actions from 'tempo.ts/viem/actions'
2506
+ *
2507
+ * const client = createClient({
2508
+ * chain: tempo,
2509
+ * transport: http(),
2510
+ * })
2511
+ *
2512
+ * const unwatch = actions.token.watchRole(client, {
2513
+ * onRoleUpdated: (args, log) => {
2514
+ * console.log('Role updated:', args)
2515
+ * },
2516
+ * })
2517
+ * ```
2518
+ *
2519
+ * @param client - Client.
2520
+ * @param parameters - Parameters.
2521
+ * @returns A function to unsubscribe from the event.
2522
+ */
2523
+ export function watchRole(client, parameters) {
2524
+ const { onRoleUpdated, token = usdAddress, ...rest } = parameters;
2525
+ return watchContractEvent(client, {
2526
+ ...rest,
2527
+ address: TokenId.toAddress(token),
2528
+ abi: tip20Abi,
2529
+ eventName: 'RoleMembershipUpdated',
2530
+ onLogs: (logs) => {
2531
+ for (const log of logs) {
2532
+ const type = log.args.hasRole ? 'granted' : 'revoked';
2533
+ onRoleUpdated({ ...log.args, type }, log);
2534
+ }
2535
+ },
2536
+ strict: true,
2537
+ });
2538
+ }
2539
+ /**
2540
+ * Watches for TIP20 token transfer events.
2541
+ *
2542
+ * @example
2543
+ * ```ts
2544
+ * import { createClient, http } from 'viem'
2545
+ * import { tempo } from 'tempo.ts/chains'
2546
+ * import * as actions from 'tempo.ts/viem/actions'
2547
+ *
2548
+ * const client = createClient({
2549
+ * account: privateKeyToAccount('0x...'),
2550
+ * chain: tempo,
2551
+ * transport: http(),
2552
+ * })
2553
+ *
2554
+ * const unwatch = actions.token.watchTransfer(client, {
2555
+ * onTransfer: (args, log) => {
2556
+ * console.log('Transfer:', args)
2557
+ * },
2558
+ * })
2559
+ * ```
2560
+ *
2561
+ * @param client - Client.
2562
+ * @param parameters - Parameters.
2563
+ * @returns A function to unsubscribe from the event.
2564
+ */
2565
+ export function watchTransfer(client, parameters) {
2566
+ const { onTransfer, token = usdAddress, ...rest } = parameters;
2567
+ return watchContractEvent(client, {
2568
+ ...rest,
2569
+ address: TokenId.toAddress(token),
2570
+ abi: tip20Abi,
2571
+ eventName: 'Transfer',
2572
+ onLogs: (logs) => {
2573
+ for (const log of logs)
2574
+ onTransfer(log.args, log);
2575
+ },
2576
+ strict: true,
2577
+ });
2578
+ }
2579
+ //# sourceMappingURL=token.js.map