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