tempo.ts 0.11.1 → 0.12.1

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 (228) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +3 -13
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/chains.d.ts +0 -73
  75. package/dist/chains.d.ts.map +0 -1
  76. package/dist/chains.js +0 -51
  77. package/dist/chains.js.map +0 -1
  78. package/dist/viem/Abis.d.ts +0 -2649
  79. package/dist/viem/Abis.d.ts.map +0 -1
  80. package/dist/viem/Abis.js +0 -1677
  81. package/dist/viem/Abis.js.map +0 -1
  82. package/dist/viem/Account.d.ts +0 -244
  83. package/dist/viem/Account.d.ts.map +0 -1
  84. package/dist/viem/Account.js +0 -382
  85. package/dist/viem/Account.js.map +0 -1
  86. package/dist/viem/Actions/account.d.ts +0 -40
  87. package/dist/viem/Actions/account.d.ts.map +0 -1
  88. package/dist/viem/Actions/account.js +0 -86
  89. package/dist/viem/Actions/account.js.map +0 -1
  90. package/dist/viem/Actions/amm.d.ts +0 -1991
  91. package/dist/viem/Actions/amm.d.ts.map +0 -1
  92. package/dist/viem/Actions/amm.js +0 -814
  93. package/dist/viem/Actions/amm.js.map +0 -1
  94. package/dist/viem/Actions/dex.d.ts +0 -3900
  95. package/dist/viem/Actions/dex.d.ts.map +0 -1
  96. package/dist/viem/Actions/dex.js +0 -1414
  97. package/dist/viem/Actions/dex.js.map +0 -1
  98. package/dist/viem/Actions/faucet.d.ts +0 -69
  99. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  100. package/dist/viem/Actions/faucet.js +0 -73
  101. package/dist/viem/Actions/faucet.js.map +0 -1
  102. package/dist/viem/Actions/fee.d.ts +0 -360
  103. package/dist/viem/Actions/fee.d.ts.map +0 -1
  104. package/dist/viem/Actions/fee.js +0 -237
  105. package/dist/viem/Actions/fee.js.map +0 -1
  106. package/dist/viem/Actions/index.d.ts +0 -10
  107. package/dist/viem/Actions/index.d.ts.map +0 -1
  108. package/dist/viem/Actions/index.js +0 -10
  109. package/dist/viem/Actions/index.js.map +0 -1
  110. package/dist/viem/Actions/nonce.d.ts +0 -257
  111. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  112. package/dist/viem/Actions/nonce.js +0 -228
  113. package/dist/viem/Actions/nonce.js.map +0 -1
  114. package/dist/viem/Actions/policy.d.ts +0 -1680
  115. package/dist/viem/Actions/policy.d.ts.map +0 -1
  116. package/dist/viem/Actions/policy.js +0 -875
  117. package/dist/viem/Actions/policy.js.map +0 -1
  118. package/dist/viem/Actions/reward.d.ts +0 -2422
  119. package/dist/viem/Actions/reward.d.ts.map +0 -1
  120. package/dist/viem/Actions/reward.js +0 -651
  121. package/dist/viem/Actions/reward.js.map +0 -1
  122. package/dist/viem/Actions/token.d.ts +0 -16007
  123. package/dist/viem/Actions/token.d.ts.map +0 -1
  124. package/dist/viem/Actions/token.js +0 -2936
  125. package/dist/viem/Actions/token.js.map +0 -1
  126. package/dist/viem/Addresses.d.ts +0 -9
  127. package/dist/viem/Addresses.d.ts.map +0 -1
  128. package/dist/viem/Addresses.js +0 -9
  129. package/dist/viem/Addresses.js.map +0 -1
  130. package/dist/viem/Chain.d.ts +0 -451
  131. package/dist/viem/Chain.d.ts.map +0 -1
  132. package/dist/viem/Chain.js +0 -96
  133. package/dist/viem/Chain.js.map +0 -1
  134. package/dist/viem/Decorator.d.ts +0 -2783
  135. package/dist/viem/Decorator.d.ts.map +0 -1
  136. package/dist/viem/Decorator.js +0 -137
  137. package/dist/viem/Decorator.js.map +0 -1
  138. package/dist/viem/Formatters.d.ts +0 -10
  139. package/dist/viem/Formatters.d.ts.map +0 -1
  140. package/dist/viem/Formatters.js +0 -104
  141. package/dist/viem/Formatters.js.map +0 -1
  142. package/dist/viem/P256.d.ts +0 -2
  143. package/dist/viem/P256.d.ts.map +0 -1
  144. package/dist/viem/P256.js +0 -2
  145. package/dist/viem/P256.js.map +0 -1
  146. package/dist/viem/Secp256k1.d.ts +0 -2
  147. package/dist/viem/Secp256k1.d.ts.map +0 -1
  148. package/dist/viem/Secp256k1.js +0 -2
  149. package/dist/viem/Secp256k1.js.map +0 -1
  150. package/dist/viem/Storage.d.ts +0 -24
  151. package/dist/viem/Storage.d.ts.map +0 -1
  152. package/dist/viem/Storage.js +0 -68
  153. package/dist/viem/Storage.js.map +0 -1
  154. package/dist/viem/TokenIds.d.ts +0 -2
  155. package/dist/viem/TokenIds.d.ts.map +0 -1
  156. package/dist/viem/TokenIds.js +0 -2
  157. package/dist/viem/TokenIds.js.map +0 -1
  158. package/dist/viem/Transaction.d.ts +0 -76
  159. package/dist/viem/Transaction.d.ts.map +0 -1
  160. package/dist/viem/Transaction.js +0 -176
  161. package/dist/viem/Transaction.js.map +0 -1
  162. package/dist/viem/Transport.d.ts +0 -33
  163. package/dist/viem/Transport.d.ts.map +0 -1
  164. package/dist/viem/Transport.js +0 -138
  165. package/dist/viem/Transport.js.map +0 -1
  166. package/dist/viem/WebAuthnP256.d.ts +0 -82
  167. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  168. package/dist/viem/WebAuthnP256.js +0 -97
  169. package/dist/viem/WebAuthnP256.js.map +0 -1
  170. package/dist/viem/WebCryptoP256.d.ts +0 -2
  171. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  172. package/dist/viem/WebCryptoP256.js +0 -2
  173. package/dist/viem/WebCryptoP256.js.map +0 -1
  174. package/dist/viem/index.d.ts +0 -26
  175. package/dist/viem/index.d.ts.map +0 -1
  176. package/dist/viem/index.js +0 -17
  177. package/dist/viem/index.js.map +0 -1
  178. package/dist/viem/internal/types.d.ts +0 -20
  179. package/dist/viem/internal/types.d.ts.map +0 -1
  180. package/dist/viem/internal/types.js +0 -2
  181. package/dist/viem/internal/types.js.map +0 -1
  182. package/dist/viem/internal/utils.d.ts +0 -14
  183. package/dist/viem/internal/utils.d.ts.map +0 -1
  184. package/dist/viem/internal/utils.js +0 -33
  185. package/dist/viem/internal/utils.js.map +0 -1
  186. package/src/chains.ts +0 -54
  187. package/src/viem/Abis.ts +0 -1688
  188. package/src/viem/Account.test.ts +0 -444
  189. package/src/viem/Account.ts +0 -601
  190. package/src/viem/Actions/account.test.ts +0 -414
  191. package/src/viem/Actions/account.ts +0 -106
  192. package/src/viem/Actions/amm.test.ts +0 -381
  193. package/src/viem/Actions/amm.ts +0 -1227
  194. package/src/viem/Actions/dex.test.ts +0 -1549
  195. package/src/viem/Actions/dex.ts +0 -2150
  196. package/src/viem/Actions/faucet.ts +0 -121
  197. package/src/viem/Actions/fee.test.ts +0 -259
  198. package/src/viem/Actions/fee.ts +0 -372
  199. package/src/viem/Actions/index.ts +0 -9
  200. package/src/viem/Actions/nonce.test.ts +0 -206
  201. package/src/viem/Actions/nonce.ts +0 -347
  202. package/src/viem/Actions/policy.test.ts +0 -534
  203. package/src/viem/Actions/policy.ts +0 -1335
  204. package/src/viem/Actions/reward.test.ts +0 -434
  205. package/src/viem/Actions/reward.ts +0 -944
  206. package/src/viem/Actions/token.test.ts +0 -3029
  207. package/src/viem/Actions/token.ts +0 -4458
  208. package/src/viem/Addresses.ts +0 -9
  209. package/src/viem/Chain.bench-d.ts +0 -12
  210. package/src/viem/Chain.test.ts +0 -168
  211. package/src/viem/Chain.ts +0 -157
  212. package/src/viem/Decorator.bench-d.ts +0 -11
  213. package/src/viem/Decorator.test.ts +0 -39
  214. package/src/viem/Decorator.ts +0 -3179
  215. package/src/viem/Formatters.ts +0 -164
  216. package/src/viem/P256.ts +0 -1
  217. package/src/viem/Secp256k1.ts +0 -1
  218. package/src/viem/Storage.ts +0 -110
  219. package/src/viem/TokenIds.ts +0 -1
  220. package/src/viem/Transaction.ts +0 -382
  221. package/src/viem/Transport.ts +0 -191
  222. package/src/viem/WebAuthnP256.ts +0 -146
  223. package/src/viem/WebCryptoP256.ts +0 -1
  224. package/src/viem/e2e.test.ts +0 -1602
  225. package/src/viem/index.ts +0 -30
  226. package/src/viem/internal/types.ts +0 -69
  227. package/src/viem/internal/utils.ts +0 -58
  228. package/src/wagmi/internal/types.ts +0 -16
@@ -1,4458 +0,0 @@
1
- import * as Hex from 'ox/Hex'
2
- import { TokenId, TokenRole } from 'ox/tempo'
3
- import {
4
- type Account,
5
- type Address,
6
- type BaseErrorType,
7
- type Chain,
8
- type Client,
9
- type ExtractAbiItem,
10
- encodeFunctionData,
11
- type GetEventArgs,
12
- type Log,
13
- parseEventLogs,
14
- type ReadContractReturnType,
15
- type SendTransactionSyncParameters,
16
- type TransactionReceipt,
17
- type Transport,
18
- type Log as viem_Log,
19
- type WatchContractEventParameters,
20
- type WatchContractEventReturnType,
21
- type WriteContractReturnType,
22
- } from 'viem'
23
- import { parseAccount } from 'viem/accounts'
24
- import {
25
- multicall,
26
- readContract,
27
- sendTransaction,
28
- sendTransactionSync,
29
- watchContractEvent,
30
- writeContract,
31
- writeContractSync,
32
- } from 'viem/actions'
33
- import type { Compute, OneOf, UnionOmit } from '../../internal/types.js'
34
- import * as Abis from '../Abis.js'
35
- import * as Addresses from '../Addresses.js'
36
- import type {
37
- GetAccountParameter,
38
- ReadParameters,
39
- WriteParameters,
40
- } from '../internal/types.js'
41
- import { defineCall } from '../internal/utils.js'
42
-
43
- /**
44
- * Approves a spender to transfer TIP20 tokens on behalf of the caller.
45
- *
46
- * @example
47
- * ```ts
48
- * import { createClient, http } from 'viem'
49
- * import { tempo } from 'tempo.ts/chains'
50
- * import { Actions } from 'tempo.ts/viem'
51
- * import { privateKeyToAccount } from 'viem/accounts'
52
- *
53
- * const client = createClient({
54
- * account: privateKeyToAccount('0x...'),
55
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
56
- * transport: http(),
57
- * })
58
- *
59
- * const result = await Actions.token.approve(client, {
60
- * spender: '0x...',
61
- * amount: 100n,
62
- * })
63
- * ```
64
- *
65
- * @param client - Client.
66
- * @param parameters - Parameters.
67
- * @returns The transaction hash.
68
- */
69
- export async function approve<
70
- chain extends Chain | undefined,
71
- account extends Account | undefined,
72
- >(
73
- client: Client<Transport, chain, account>,
74
- parameters: approve.Parameters<chain, account>,
75
- ): Promise<approve.ReturnValue> {
76
- const { token, ...rest } = parameters
77
- return approve.inner(writeContract, client, parameters, { ...rest, token })
78
- }
79
-
80
- export namespace approve {
81
- export type Parameters<
82
- chain extends Chain | undefined = Chain | undefined,
83
- account extends Account | undefined = Account | undefined,
84
- > = WriteParameters<chain, account> & Args
85
-
86
- export type Args = {
87
- /** Amount of tokens to approve. */
88
- amount: bigint
89
- /** Address of the spender. */
90
- spender: Address
91
- /** Address or ID of the TIP20 token. */
92
- token: TokenId.TokenIdOrAddress
93
- }
94
-
95
- export type ReturnValue = WriteContractReturnType
96
-
97
- // TODO: exhaustive error type
98
- export type ErrorType = BaseErrorType
99
-
100
- /** @internal */
101
- export async function inner<
102
- action extends typeof writeContract | typeof writeContractSync,
103
- chain extends Chain | undefined,
104
- account extends Account | undefined,
105
- >(
106
- action: action,
107
- client: Client<Transport, chain, account>,
108
- parameters: approve.Parameters<chain, account>,
109
- args: Args,
110
- ): Promise<ReturnType<action>> {
111
- const call = approve.call(args)
112
- return (await action(client, {
113
- ...parameters,
114
- ...call,
115
- } as never)) as never
116
- }
117
-
118
- /**
119
- * Defines a call to the `approve` function.
120
- *
121
- * Can be passed as a parameter to:
122
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
123
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
124
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
125
- *
126
- * @example
127
- * ```ts
128
- * import { createClient, http, walletActions } from 'viem'
129
- * import { tempo } from 'tempo.ts/chains'
130
- * import { Actions } from 'tempo.ts/viem'
131
- *
132
- * const client = createClient({
133
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
134
- * transport: http(),
135
- * }).extend(walletActions)
136
- *
137
- * const { result } = await client.sendCalls({
138
- * calls: [
139
- * actions.token.approve.call({
140
- * spender: '0x20c0...beef',
141
- * amount: 100n,
142
- * token: '0x20c0...babe',
143
- * }),
144
- * ]
145
- * })
146
- * ```
147
- *
148
- * @param args - Arguments.
149
- * @returns The call.
150
- */
151
- export function call(args: Args) {
152
- const { spender, amount, token } = args
153
- return defineCall({
154
- address: TokenId.toAddress(token),
155
- abi: Abis.tip20,
156
- functionName: 'approve',
157
- args: [spender, amount],
158
- })
159
- }
160
-
161
- export function extractEvent(logs: Log[]) {
162
- const [log] = parseEventLogs({
163
- abi: Abis.tip20,
164
- logs,
165
- eventName: 'Approval',
166
- })
167
- if (!log) throw new Error('`Approval` event not found.')
168
- return log
169
- }
170
- }
171
-
172
- /**
173
- * Approves a spender to transfer TIP20 tokens on behalf of the caller.
174
- *
175
- * @example
176
- * ```ts
177
- * import { createClient, http } from 'viem'
178
- * import { tempo } from 'tempo.ts/chains'
179
- * import { Actions } from 'tempo.ts/viem'
180
- * import { privateKeyToAccount } from 'viem/accounts'
181
- *
182
- * const client = createClient({
183
- * account: privateKeyToAccount('0x...'),
184
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
185
- * transport: http(),
186
- * })
187
- *
188
- * const result = await Actions.token.approveSync(client, {
189
- * spender: '0x...',
190
- * amount: 100n,
191
- * })
192
- * ```
193
- *
194
- * @param client - Client.
195
- * @param parameters - Parameters.
196
- * @returns The transaction receipt and event data.
197
- */
198
- export async function approveSync<
199
- chain extends Chain | undefined,
200
- account extends Account | undefined,
201
- >(
202
- client: Client<Transport, chain, account>,
203
- parameters: approveSync.Parameters<chain, account>,
204
- ): Promise<approveSync.ReturnValue> {
205
- const { throwOnReceiptRevert = true, ...rest } = parameters
206
- const receipt = await approve.inner(
207
- writeContractSync,
208
- client,
209
- { ...parameters, throwOnReceiptRevert } as never,
210
- rest,
211
- )
212
- const { args } = approve.extractEvent(receipt.logs)
213
- return {
214
- ...args,
215
- receipt,
216
- } as never
217
- }
218
-
219
- export namespace approveSync {
220
- export type Parameters<
221
- chain extends Chain | undefined = Chain | undefined,
222
- account extends Account | undefined = Account | undefined,
223
- > = approve.Parameters<chain, account>
224
-
225
- export type Args = approve.Args
226
-
227
- export type ReturnValue = Compute<
228
- GetEventArgs<
229
- typeof Abis.tip20,
230
- 'Approval',
231
- {
232
- IndexedOnly: false
233
- Required: true
234
- }
235
- > & {
236
- /** Transaction receipt. */
237
- receipt: TransactionReceipt
238
- }
239
- >
240
-
241
- // TODO: exhaustive error type
242
- export type ErrorType = BaseErrorType
243
- }
244
-
245
- /**
246
- * Burns TIP20 tokens from a blocked address.
247
- *
248
- * @example
249
- * ```ts
250
- * import { createClient, http } from 'viem'
251
- * import { tempo } from 'tempo.ts/chains'
252
- * import { Actions } from 'tempo.ts/viem'
253
- * import { privateKeyToAccount } from 'viem/accounts'
254
- *
255
- * const client = createClient({
256
- * account: privateKeyToAccount('0x...'),
257
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
258
- * transport: http(),
259
- * })
260
- *
261
- * const result = await Actions.token.burnBlocked(client, {
262
- * from: '0x...',
263
- * amount: 100n,
264
- * token: '0x...',
265
- * })
266
- * ```
267
- *
268
- * @param client - Client.
269
- * @param parameters - Parameters.
270
- * @returns The transaction hash.
271
- */
272
- export async function burnBlocked<
273
- chain extends Chain | undefined,
274
- account extends Account | undefined,
275
- >(
276
- client: Client<Transport, chain, account>,
277
- parameters: burnBlocked.Parameters<chain, account>,
278
- ): Promise<burnBlocked.ReturnValue> {
279
- return burnBlocked.inner(writeContract, client, parameters)
280
- }
281
-
282
- export namespace burnBlocked {
283
- export type Parameters<
284
- chain extends Chain | undefined = Chain | undefined,
285
- account extends Account | undefined = Account | undefined,
286
- > = WriteParameters<chain, account> & Args
287
-
288
- export type Args = {
289
- /** Amount of tokens to burn. */
290
- amount: bigint
291
- /** Address to burn tokens from. */
292
- from: Address
293
- /** Address or ID of the TIP20 token. */
294
- token: TokenId.TokenIdOrAddress
295
- }
296
-
297
- export type ReturnValue = WriteContractReturnType
298
-
299
- // TODO: exhaustive error type
300
- export type ErrorType = BaseErrorType
301
-
302
- /** @internal */
303
- export async function inner<
304
- action extends typeof writeContract | typeof writeContractSync,
305
- chain extends Chain | undefined,
306
- account extends Account | undefined,
307
- >(
308
- action: action,
309
- client: Client<Transport, chain, account>,
310
- parameters: burnBlocked.Parameters<chain, account>,
311
- ): Promise<ReturnType<action>> {
312
- const { amount, from, token, ...rest } = parameters
313
- const call = burnBlocked.call({ amount, from, token })
314
- return (await action(client, {
315
- ...rest,
316
- ...call,
317
- } as never)) as never
318
- }
319
-
320
- /**
321
- * Defines a call to the `burnBlocked` function.
322
- *
323
- * Can be passed as a parameter to:
324
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
325
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
326
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
327
- *
328
- * @example
329
- * ```ts
330
- * import { createClient, http, walletActions } from 'viem'
331
- * import { tempo } from 'tempo.ts/chains'
332
- * import { Actions } from 'tempo.ts/viem'
333
- *
334
- * const client = createClient({
335
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
336
- * transport: http(),
337
- * }).extend(walletActions)
338
- *
339
- * const { result } = await client.sendCalls({
340
- * calls: [
341
- * actions.token.burnBlocked.call({
342
- * from: '0x20c0...beef',
343
- * amount: 100n,
344
- * token: '0x20c0...babe',
345
- * }),
346
- * ]
347
- * })
348
- * ```
349
- *
350
- * @param args - Arguments.
351
- * @returns The call.
352
- */
353
- export function call(args: Args) {
354
- const { from, amount, token } = args
355
- return defineCall({
356
- address: TokenId.toAddress(token),
357
- abi: Abis.tip20,
358
- functionName: 'burnBlocked',
359
- args: [from, amount],
360
- })
361
- }
362
-
363
- /**
364
- * Extracts the event from the logs.
365
- *
366
- * @param logs - Logs.
367
- * @returns The event.
368
- */
369
- export function extractEvent(logs: Log[]) {
370
- const [log] = parseEventLogs({
371
- abi: Abis.tip20,
372
- logs,
373
- eventName: 'BurnBlocked',
374
- })
375
- if (!log) throw new Error('`BurnBlocked` event not found.')
376
- return log
377
- }
378
- }
379
-
380
- /**
381
- * Burns TIP20 tokens from a blocked address.
382
- *
383
- * @example
384
- * ```ts
385
- * import { createClient, http } from 'viem'
386
- * import { tempo } from 'tempo.ts/chains'
387
- * import { Actions } from 'tempo.ts/viem'
388
- * import { privateKeyToAccount } from 'viem/accounts'
389
- *
390
- * const client = createClient({
391
- * account: privateKeyToAccount('0x...'),
392
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
393
- * transport: http(),
394
- * })
395
- *
396
- * const result = await Actions.token.burnBlockedSync(client, {
397
- * from: '0x...',
398
- * amount: 100n,
399
- * token: '0x...',
400
- * })
401
- * ```
402
- *
403
- * @param client - Client.
404
- * @param parameters - Parameters.
405
- * @returns The transaction receipt and event data.
406
- */
407
- export async function burnBlockedSync<
408
- chain extends Chain | undefined,
409
- account extends Account | undefined,
410
- >(
411
- client: Client<Transport, chain, account>,
412
- parameters: burnBlockedSync.Parameters<chain, account>,
413
- ): Promise<burnBlockedSync.ReturnValue> {
414
- const { throwOnReceiptRevert = true, ...rest } = parameters
415
- const receipt = await burnBlocked.inner(writeContractSync, client, {
416
- ...rest,
417
- throwOnReceiptRevert,
418
- } as never)
419
- const { args } = burnBlocked.extractEvent(receipt.logs)
420
- return {
421
- ...args,
422
- receipt,
423
- } as never
424
- }
425
-
426
- export namespace burnBlockedSync {
427
- export type Parameters<
428
- chain extends Chain | undefined = Chain | undefined,
429
- account extends Account | undefined = Account | undefined,
430
- > = burnBlocked.Parameters<chain, account>
431
-
432
- export type Args = burnBlocked.Args
433
-
434
- export type ReturnValue = Compute<
435
- GetEventArgs<
436
- typeof Abis.tip20,
437
- 'BurnBlocked',
438
- {
439
- IndexedOnly: false
440
- Required: true
441
- }
442
- > & {
443
- /** Transaction receipt. */
444
- receipt: TransactionReceipt
445
- }
446
- >
447
-
448
- // TODO: exhaustive error type
449
- export type ErrorType = BaseErrorType
450
- }
451
-
452
- /**
453
- * Burns TIP20 tokens from the caller's balance.
454
- *
455
- * @example
456
- * ```ts
457
- * import { createClient, http } from 'viem'
458
- * import { tempo } from 'tempo.ts/chains'
459
- * import { Actions } from 'tempo.ts/viem'
460
- * import { privateKeyToAccount } from 'viem/accounts'
461
- *
462
- * const client = createClient({
463
- * account: privateKeyToAccount('0x...'),
464
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
465
- * transport: http(),
466
- * })
467
- *
468
- * const result = await Actions.token.burn(client, {
469
- * amount: 100n,
470
- * token: '0x...',
471
- * })
472
- * ```
473
- *
474
- * @param client - Client.
475
- * @param parameters - Parameters.
476
- * @returns The transaction hash.
477
- */
478
- export async function burn<
479
- chain extends Chain | undefined,
480
- account extends Account | undefined,
481
- >(
482
- client: Client<Transport, chain, account>,
483
- parameters: burn.Parameters<chain, account>,
484
- ): Promise<burn.ReturnValue> {
485
- return burn.inner(writeContract, client, parameters)
486
- }
487
-
488
- export namespace burn {
489
- export type Parameters<
490
- chain extends Chain | undefined = Chain | undefined,
491
- account extends Account | undefined = Account | undefined,
492
- > = WriteParameters<chain, account> & Args
493
-
494
- export type Args = {
495
- /** Amount of tokens to burn. */
496
- amount: bigint
497
- /** Memo to include in the transfer. */
498
- memo?: Hex.Hex | undefined
499
- /** Address or ID of the TIP20 token. */
500
- token: TokenId.TokenIdOrAddress
501
- }
502
-
503
- export type ReturnValue = WriteContractReturnType
504
-
505
- // TODO: exhaustive error type
506
- export type ErrorType = BaseErrorType
507
-
508
- /** @internal */
509
- export async function inner<
510
- action extends typeof writeContract | typeof writeContractSync,
511
- chain extends Chain | undefined,
512
- account extends Account | undefined,
513
- >(
514
- action: action,
515
- client: Client<Transport, chain, account>,
516
- parameters: burn.Parameters<chain, account>,
517
- ): Promise<ReturnType<action>> {
518
- const { amount, memo, token, ...rest } = parameters
519
- const call = burn.call({ amount, memo, token })
520
- return (await action(client, {
521
- ...rest,
522
- ...call,
523
- } as never)) as never
524
- }
525
-
526
- /**
527
- * Defines a call to the `burn` or `burnWithMemo` function.
528
- *
529
- * Can be passed as a parameter to:
530
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
531
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
532
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
533
- *
534
- * @example
535
- * ```ts
536
- * import { createClient, http, walletActions } from 'viem'
537
- * import { tempo } from 'tempo.ts/chains'
538
- * import { Actions } from 'tempo.ts/viem'
539
- *
540
- * const client = createClient({
541
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
542
- * transport: http(),
543
- * }).extend(walletActions)
544
- *
545
- * const { result } = await client.sendCalls({
546
- * calls: [
547
- * actions.token.burn.call({
548
- * amount: 100n,
549
- * token: '0x20c0...babe',
550
- * }),
551
- * ]
552
- * })
553
- * ```
554
- *
555
- * @param args - Arguments.
556
- * @returns The call.
557
- */
558
- export function call(args: Args) {
559
- const { amount, memo, token } = args
560
- const callArgs = memo
561
- ? ({
562
- functionName: 'burnWithMemo',
563
- args: [amount, Hex.padLeft(memo, 32)],
564
- } as const)
565
- : ({
566
- functionName: 'burn',
567
- args: [amount],
568
- } as const)
569
- return defineCall({
570
- address: TokenId.toAddress(token),
571
- abi: Abis.tip20,
572
- ...callArgs,
573
- })
574
- }
575
-
576
- /**
577
- * Extracts the event from the logs.
578
- *
579
- * @param logs - Logs.
580
- * @returns The event.
581
- */
582
- export function extractEvent(logs: Log[]) {
583
- const [log] = parseEventLogs({
584
- abi: Abis.tip20,
585
- logs,
586
- eventName: 'Burn',
587
- })
588
- if (!log) throw new Error('`Burn` event not found.')
589
- return log
590
- }
591
- }
592
-
593
- /**
594
- * Burns TIP20 tokens from the caller's balance.
595
- *
596
- * @example
597
- * ```ts
598
- * import { createClient, http } from 'viem'
599
- * import { tempo } from 'tempo.ts/chains'
600
- * import { Actions } from 'tempo.ts/viem'
601
- * import { privateKeyToAccount } from 'viem/accounts'
602
- *
603
- * const client = createClient({
604
- * account: privateKeyToAccount('0x...'),
605
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
606
- * transport: http(),
607
- * })
608
- *
609
- * const result = await Actions.token.burnSync(client, {
610
- * amount: 100n,
611
- * token: '0x...',
612
- * })
613
- * ```
614
- *
615
- * @param client - Client.
616
- * @param parameters - Parameters.
617
- * @returns The transaction receipt and event data.
618
- */
619
- export async function burnSync<
620
- chain extends Chain | undefined,
621
- account extends Account | undefined,
622
- >(
623
- client: Client<Transport, chain, account>,
624
- parameters: burnSync.Parameters<chain, account>,
625
- ): Promise<burnSync.ReturnValue> {
626
- const { throwOnReceiptRevert = true, ...rest } = parameters
627
- const receipt = await burn.inner(writeContractSync, client, {
628
- ...rest,
629
- throwOnReceiptRevert,
630
- } as never)
631
- const { args } = burn.extractEvent(receipt.logs)
632
- return {
633
- ...args,
634
- receipt,
635
- } as never
636
- }
637
-
638
- export namespace burnSync {
639
- export type Parameters<
640
- chain extends Chain | undefined = Chain | undefined,
641
- account extends Account | undefined = Account | undefined,
642
- > = burn.Parameters<chain, account>
643
-
644
- export type Args = burn.Args
645
-
646
- export type ReturnValue = Compute<
647
- GetEventArgs<
648
- typeof Abis.tip20,
649
- 'Burn',
650
- {
651
- IndexedOnly: false
652
- Required: true
653
- }
654
- > & {
655
- receipt: TransactionReceipt
656
- }
657
- >
658
-
659
- // TODO: exhaustive error type
660
- export type ErrorType = BaseErrorType
661
- }
662
-
663
- /**
664
- * Changes the transfer policy ID for a TIP20 token.
665
- *
666
- * @example
667
- * ```ts
668
- * import { createClient, http } from 'viem'
669
- * import { tempo } from 'tempo.ts/chains'
670
- * import { Actions } from 'tempo.ts/viem'
671
- * import { privateKeyToAccount } from 'viem/accounts'
672
- *
673
- * const client = createClient({
674
- * account: privateKeyToAccount('0x...'),
675
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
676
- * transport: http(),
677
- * })
678
- *
679
- * const result = await Actions.token.changeTransferPolicy(client, {
680
- * token: '0x...',
681
- * policyId: 1n,
682
- * })
683
- * ```
684
- *
685
- * @param client - Client.
686
- * @param parameters - Parameters.
687
- * @returns The transaction hash.
688
- */
689
- export async function changeTransferPolicy<
690
- chain extends Chain | undefined,
691
- account extends Account | undefined,
692
- >(
693
- client: Client<Transport, chain, account>,
694
- parameters: changeTransferPolicy.Parameters<chain, account>,
695
- ): Promise<changeTransferPolicy.ReturnValue> {
696
- return changeTransferPolicy.inner(writeContract, client, parameters)
697
- }
698
-
699
- export namespace changeTransferPolicy {
700
- export type Parameters<
701
- chain extends Chain | undefined = Chain | undefined,
702
- account extends Account | undefined = Account | undefined,
703
- > = WriteParameters<chain, account> & Args
704
-
705
- export type Args = {
706
- /** New transfer policy ID. */
707
- policyId: bigint
708
- /** Address or ID of the TIP20 token. */
709
- token: TokenId.TokenIdOrAddress
710
- }
711
-
712
- export type ReturnValue = WriteContractReturnType
713
-
714
- // TODO: exhaustive error type
715
- export type ErrorType = BaseErrorType
716
-
717
- /** @internal */
718
- export async function inner<
719
- action extends typeof writeContract | typeof writeContractSync,
720
- chain extends Chain | undefined,
721
- account extends Account | undefined,
722
- >(
723
- action: action,
724
- client: Client<Transport, chain, account>,
725
- parameters: changeTransferPolicy.Parameters<chain, account>,
726
- ): Promise<ReturnType<action>> {
727
- const { policyId, token, ...rest } = parameters
728
- const call = changeTransferPolicy.call({ policyId, token })
729
- return (await action(client, {
730
- ...rest,
731
- ...call,
732
- } as never)) as never
733
- }
734
-
735
- /**
736
- * Defines a call to the `changeTransferPolicyId` function.
737
- *
738
- * Can be passed as a parameter to:
739
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
740
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
741
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
742
- *
743
- * @example
744
- * ```ts
745
- * import { createClient, http, walletActions } from 'viem'
746
- * import { tempo } from 'tempo.ts/chains'
747
- * import { Actions } from 'tempo.ts/viem'
748
- *
749
- * const client = createClient({
750
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
751
- * transport: http(),
752
- * }).extend(walletActions)
753
- *
754
- * const { result } = await client.sendCalls({
755
- * calls: [
756
- * actions.token.changeTransferPolicy.call({
757
- * token: '0x20c0...babe',
758
- * policyId: 1n,
759
- * }),
760
- * ]
761
- * })
762
- * ```
763
- *
764
- * @param args - Arguments.
765
- * @returns The call.
766
- */
767
- export function call(args: Args) {
768
- const { token, policyId } = args
769
- return defineCall({
770
- address: TokenId.toAddress(token),
771
- abi: Abis.tip20,
772
- functionName: 'changeTransferPolicyId',
773
- args: [policyId],
774
- })
775
- }
776
-
777
- /**
778
- * Extracts the event from the logs.
779
- *
780
- * @param logs - Logs.
781
- * @returns The event.
782
- */
783
- export function extractEvent(logs: Log[]) {
784
- const [log] = parseEventLogs({
785
- abi: Abis.tip20,
786
- logs,
787
- eventName: 'TransferPolicyUpdate',
788
- })
789
- if (!log) throw new Error('`TransferPolicyUpdate` event not found.')
790
- return log
791
- }
792
- }
793
-
794
- /**
795
- * Changes the transfer policy ID for a TIP20 token.
796
- *
797
- * @example
798
- * ```ts
799
- * import { createClient, http } from 'viem'
800
- * import { tempo } from 'tempo.ts/chains'
801
- * import { Actions } from 'tempo.ts/viem'
802
- * import { privateKeyToAccount } from 'viem/accounts'
803
- *
804
- * const client = createClient({
805
- * account: privateKeyToAccount('0x...'),
806
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
807
- * transport: http(),
808
- * })
809
- *
810
- * const result = await Actions.token.changeTransferPolicySync(client, {
811
- * token: '0x...',
812
- * policyId: 1n,
813
- * })
814
- * ```
815
- *
816
- * @param client - Client.
817
- * @param parameters - Parameters.
818
- * @returns The transaction receipt and event data.
819
- */
820
- export async function changeTransferPolicySync<
821
- chain extends Chain | undefined,
822
- account extends Account | undefined,
823
- >(
824
- client: Client<Transport, chain, account>,
825
- parameters: changeTransferPolicySync.Parameters<chain, account>,
826
- ): Promise<changeTransferPolicySync.ReturnValue> {
827
- const { throwOnReceiptRevert = true, ...rest } = parameters
828
- const receipt = await changeTransferPolicy.inner(writeContractSync, client, {
829
- ...rest,
830
- throwOnReceiptRevert,
831
- } as never)
832
- const { args } = changeTransferPolicy.extractEvent(receipt.logs)
833
- return {
834
- ...args,
835
- receipt,
836
- } as never
837
- }
838
-
839
- export namespace changeTransferPolicySync {
840
- export type Parameters<
841
- chain extends Chain | undefined = Chain | undefined,
842
- account extends Account | undefined = Account | undefined,
843
- > = changeTransferPolicy.Parameters<chain, account>
844
-
845
- export type Args = changeTransferPolicy.Args
846
-
847
- export type ReturnValue = Compute<
848
- GetEventArgs<
849
- typeof Abis.tip20,
850
- 'TransferPolicyUpdate',
851
- {
852
- IndexedOnly: false
853
- Required: true
854
- }
855
- > & {
856
- receipt: TransactionReceipt
857
- }
858
- >
859
-
860
- // TODO: exhaustive error type
861
- export type ErrorType = BaseErrorType
862
- }
863
-
864
- /**
865
- * Creates a new TIP20 token.
866
- *
867
- * @example
868
- * ```ts
869
- * import { createClient, http } from 'viem'
870
- * import { tempo } from 'tempo.ts/chains'
871
- * import { Actions } from 'tempo.ts/viem'
872
- * import { privateKeyToAccount } from 'viem/accounts'
873
- *
874
- * const client = createClient({
875
- * account: privateKeyToAccount('0x...'),
876
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
877
- * transport: http(),
878
- * })
879
- *
880
- * const result = await Actions.token.create(client, {
881
- * name: 'My Token',
882
- * symbol: 'MTK',
883
- * currency: 'USD',
884
- * })
885
- * ```
886
- *
887
- * @param client - Client.
888
- * @param parameters - Parameters.
889
- * @returns The transaction hash.
890
- */
891
- export async function create<
892
- chain extends Chain | undefined,
893
- account extends Account | undefined,
894
- >(
895
- client: Client<Transport, chain, account>,
896
- parameters: create.Parameters<chain, account>,
897
- ): Promise<create.ReturnValue> {
898
- return create.inner(writeContract, client, parameters)
899
- }
900
-
901
- export namespace create {
902
- export type Parameters<
903
- chain extends Chain | undefined = Chain | undefined,
904
- account extends Account | undefined = Account | undefined,
905
- > = WriteParameters<chain, account> &
906
- Omit<Args, 'admin'> &
907
- (account extends Account
908
- ? { admin?: Account | Address | undefined }
909
- : { admin: Account | Address })
910
-
911
- export type Args = {
912
- /** Admin address. */
913
- admin: Address
914
- /** Currency (e.g. "USD"). */
915
- currency: string
916
- /** Token name. */
917
- name: string
918
- /** quote token. */
919
- quoteToken?: TokenId.TokenIdOrAddress | undefined
920
- /** Token symbol. */
921
- symbol: string
922
- }
923
-
924
- export type ReturnValue = WriteContractReturnType
925
-
926
- // TODO: exhaustive error type
927
- export type ErrorType = BaseErrorType
928
-
929
- /** @internal */
930
- export async function inner<
931
- action extends typeof writeContract | typeof writeContractSync,
932
- chain extends Chain | undefined,
933
- account extends Account | undefined,
934
- >(
935
- action: action,
936
- client: Client<Transport, chain, account>,
937
- parameters: any,
938
- ): Promise<ReturnType<action>> {
939
- const {
940
- account = client.account,
941
- admin: admin_ = client.account,
942
- chain = client.chain,
943
- ...rest
944
- } = parameters
945
- const admin = admin_ ? parseAccount(admin_) : undefined
946
- if (!admin) throw new Error('admin is required.')
947
-
948
- const call = create.call({ ...rest, admin: admin.address })
949
-
950
- return (await action(
951
- client as never,
952
- {
953
- ...parameters,
954
- account,
955
- chain,
956
- ...call,
957
- } as never,
958
- )) as never
959
- }
960
-
961
- /**
962
- * Defines a call to the `createToken` function.
963
- *
964
- * Can be passed as a parameter to:
965
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
966
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
967
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
968
- *
969
- * @example
970
- * ```ts
971
- * import { createClient, http, walletActions } from 'viem'
972
- * import { tempo } from 'tempo.ts/chains'
973
- * import { Actions } from 'tempo.ts/viem'
974
- *
975
- * const client = createClient({
976
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
977
- * transport: http(),
978
- * }).extend(walletActions)
979
- *
980
- * const { result } = await client.sendCalls({
981
- * calls: [
982
- * actions.token.create.call({
983
- * name: 'My Token',
984
- * symbol: 'MTK',
985
- * currency: 'USD',
986
- * admin: '0xfeed...fede',
987
- * }),
988
- * ]
989
- * })
990
- * ```
991
- *
992
- * @param args - Arguments.
993
- * @returns The call.
994
- */
995
- export function call(args: Args) {
996
- const {
997
- name,
998
- symbol,
999
- currency,
1000
- quoteToken = Addresses.pathUsd,
1001
- admin,
1002
- } = args
1003
- return defineCall({
1004
- address: Addresses.tip20Factory,
1005
- abi: Abis.tip20Factory,
1006
- args: [name, symbol, currency, TokenId.toAddress(quoteToken), admin],
1007
- functionName: 'createToken',
1008
- })
1009
- }
1010
-
1011
- /**
1012
- * Extracts the `TokenCreated` event from logs.
1013
- *
1014
- * @param logs - The logs.
1015
- * @returns The `TokenCreated` event.
1016
- */
1017
- export function extractEvent(logs: Log[]) {
1018
- const [log] = parseEventLogs({
1019
- abi: Abis.tip20Factory,
1020
- logs,
1021
- eventName: 'TokenCreated',
1022
- strict: true,
1023
- })
1024
- if (!log) throw new Error('`TokenCreated` event not found.')
1025
- return log
1026
- }
1027
- }
1028
-
1029
- /**
1030
- * Creates a new TIP20 token.
1031
- *
1032
- * @example
1033
- * ```ts
1034
- * import { createClient, http } from 'viem'
1035
- * import { tempo } from 'tempo.ts/chains'
1036
- * import { Actions } from 'tempo.ts/viem'
1037
- * import { privateKeyToAccount } from 'viem/accounts'
1038
- *
1039
- * const client = createClient({
1040
- * account: privateKeyToAccount('0x...'),
1041
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1042
- * transport: http(),
1043
- * })
1044
- *
1045
- * const result = await Actions.token.createSync(client, {
1046
- * name: 'My Token',
1047
- * symbol: 'MTK',
1048
- * currency: 'USD',
1049
- * })
1050
- * ```
1051
- *
1052
- * @param client - Client.
1053
- * @param parameters - Parameters.
1054
- * @returns The transaction receipt and event data.
1055
- */
1056
- export async function createSync<
1057
- chain extends Chain | undefined,
1058
- account extends Account | undefined,
1059
- >(
1060
- client: Client<Transport, chain, account>,
1061
- parameters: createSync.Parameters<chain, account>,
1062
- ): Promise<createSync.ReturnValue> {
1063
- const { throwOnReceiptRevert = true, ...rest } = parameters
1064
- const receipt = await create.inner(writeContractSync, client, {
1065
- ...rest,
1066
- throwOnReceiptRevert,
1067
- } as never)
1068
-
1069
- const { args } = create.extractEvent(receipt.logs)
1070
-
1071
- return {
1072
- ...args,
1073
- receipt,
1074
- } as never
1075
- }
1076
-
1077
- export namespace createSync {
1078
- export type Parameters<
1079
- chain extends Chain | undefined = Chain | undefined,
1080
- account extends Account | undefined = Account | undefined,
1081
- > = create.Parameters<chain, account>
1082
-
1083
- export type Args = create.Args
1084
-
1085
- export type ReturnValue = Compute<
1086
- GetEventArgs<
1087
- typeof Abis.tip20Factory,
1088
- 'TokenCreated',
1089
- { IndexedOnly: false; Required: true }
1090
- > & {
1091
- /** Transaction receipt. */
1092
- receipt: TransactionReceipt
1093
- }
1094
- >
1095
-
1096
- // TODO: exhaustive error type
1097
- export type ErrorType = BaseErrorType
1098
- }
1099
-
1100
- /**
1101
- * Gets TIP20 token allowance.
1102
- *
1103
- * @example
1104
- * ```ts
1105
- * import { createClient, http } from 'viem'
1106
- * import { tempo } from 'tempo.ts/chains'
1107
- * import { Actions } from 'tempo.ts/viem'
1108
- * import { privateKeyToAccount } from 'viem/accounts'
1109
- *
1110
- * const client = createClient({
1111
- * account: privateKeyToAccount('0x...'),
1112
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1113
- * transport: http(),
1114
- * })
1115
- *
1116
- * const allowance = await Actions.token.getAllowance(client, {
1117
- * spender: '0x...',
1118
- * })
1119
- * ```
1120
- *
1121
- * @param client - Client.
1122
- * @param parameters - Parameters.
1123
- * @returns The token allowance.
1124
- */
1125
- export async function getAllowance<
1126
- chain extends Chain | undefined,
1127
- account extends Account | undefined,
1128
- >(
1129
- client: Client<Transport, chain, account>,
1130
- parameters: getAllowance.Parameters<account>,
1131
- ): Promise<getAllowance.ReturnValue> {
1132
- const { account = client.account } = parameters
1133
- const address = account ? parseAccount(account).address : undefined
1134
- if (!address) throw new Error('account is required.')
1135
- return readContract(client, {
1136
- ...parameters,
1137
- ...getAllowance.call({ ...parameters, account: address }),
1138
- })
1139
- }
1140
-
1141
- export namespace getAllowance {
1142
- export type Parameters<
1143
- account extends Account | undefined = Account | undefined,
1144
- > = ReadParameters & GetAccountParameter<account> & Omit<Args, 'account'> & {}
1145
-
1146
- export type Args = {
1147
- /** Account address. */
1148
- account: Address
1149
- /** Address of the spender. */
1150
- spender: Address
1151
- /** Address or ID of the TIP20 token. */
1152
- token: TokenId.TokenIdOrAddress
1153
- }
1154
-
1155
- export type ReturnValue = ReadContractReturnType<
1156
- typeof Abis.tip20,
1157
- 'allowance',
1158
- never
1159
- >
1160
-
1161
- /**
1162
- * Defines a call to the `allowance` function.
1163
- *
1164
- * @param args - Arguments.
1165
- * @returns The call.
1166
- */
1167
- export function call(args: Args) {
1168
- const { account, spender, token } = args
1169
- return defineCall({
1170
- address: TokenId.toAddress(token),
1171
- abi: Abis.tip20,
1172
- functionName: 'allowance',
1173
- args: [account, spender],
1174
- })
1175
- }
1176
- }
1177
-
1178
- /**
1179
- * Gets TIP20 token balance for an address.
1180
- *
1181
- * @example
1182
- * ```ts
1183
- * import { createClient, http } from 'viem'
1184
- * import { tempo } from 'tempo.ts/chains'
1185
- * import { Actions } from 'tempo.ts/viem'
1186
- * import { privateKeyToAccount } from 'viem/accounts'
1187
- *
1188
- * const client = createClient({
1189
- * account: privateKeyToAccount('0x...'),
1190
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1191
- * transport: http(),
1192
- * })
1193
- *
1194
- * const balance = await Actions.token.getBalance(client, {
1195
- * token: '0x...',
1196
- * })
1197
- * ```
1198
- *
1199
- * @param client - Client.
1200
- * @param parameters - Parameters.
1201
- * @returns The token balance.
1202
- */
1203
- export async function getBalance<
1204
- chain extends Chain | undefined,
1205
- account extends Account | undefined,
1206
- >(
1207
- client: Client<Transport, chain, account>,
1208
- parameters: getBalance.Parameters<account>,
1209
- ): Promise<getBalance.ReturnValue> {
1210
- const { account = client.account, ...rest } = parameters
1211
- const address = account ? parseAccount(account).address : undefined
1212
- if (!address) throw new Error('account is required.')
1213
- return readContract(client, {
1214
- ...rest,
1215
- ...getBalance.call({ account: address, ...rest }),
1216
- })
1217
- }
1218
-
1219
- export namespace getBalance {
1220
- export type Parameters<
1221
- account extends Account | undefined = Account | undefined,
1222
- > = ReadParameters & GetAccountParameter<account> & Omit<Args, 'account'>
1223
-
1224
- export type Args = {
1225
- /** Account address. */
1226
- account: Address
1227
- /** Address or ID of the TIP20 token. */
1228
- token: TokenId.TokenIdOrAddress
1229
- }
1230
-
1231
- export type ReturnValue = ReadContractReturnType<
1232
- typeof Abis.tip20,
1233
- 'balanceOf',
1234
- never
1235
- >
1236
-
1237
- /**
1238
- * Defines a call to the `balanceOf` function.
1239
- *
1240
- * @param args - Arguments.
1241
- * @returns The call.
1242
- */
1243
- export function call(args: Args) {
1244
- const { account, token } = args
1245
- return defineCall({
1246
- address: TokenId.toAddress(token),
1247
- abi: Abis.tip20,
1248
- functionName: 'balanceOf',
1249
- args: [account],
1250
- })
1251
- }
1252
- }
1253
-
1254
- /**
1255
- * Gets TIP20 token metadata including name, symbol, currency, decimals, and total supply.
1256
- *
1257
- * @example
1258
- * ```ts
1259
- * import { createClient, http } from 'viem'
1260
- * import { tempo } from 'tempo.ts/chains'
1261
- * import { Actions } from 'tempo.ts/viem'
1262
- * import { privateKeyToAccount } from 'viem/accounts'
1263
- *
1264
- * const client = createClient({
1265
- * account: privateKeyToAccount('0x...'),
1266
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1267
- * transport: http(),
1268
- * })
1269
- *
1270
- * const metadata = await Actions.token.getMetadata(client, {
1271
- * token: '0x...',
1272
- * })
1273
- * ```
1274
- *
1275
- * @param client - Client.
1276
- * @param parameters - Parameters.
1277
- * @returns The token metadata.
1278
- */
1279
- export async function getMetadata<chain extends Chain | undefined>(
1280
- client: Client<Transport, chain>,
1281
- parameters: getMetadata.Parameters,
1282
- ): Promise<getMetadata.ReturnValue> {
1283
- const { token, ...rest } = parameters
1284
- const address = TokenId.toAddress(token)
1285
- const abi = Abis.tip20
1286
-
1287
- if (TokenId.from(token) === TokenId.fromAddress(Addresses.pathUsd))
1288
- return multicall(client, {
1289
- ...rest,
1290
- contracts: [
1291
- {
1292
- address,
1293
- abi,
1294
- functionName: 'currency',
1295
- },
1296
- {
1297
- address,
1298
- abi,
1299
- functionName: 'decimals',
1300
- },
1301
- {
1302
- address,
1303
- abi,
1304
- functionName: 'name',
1305
- },
1306
- {
1307
- address,
1308
- abi,
1309
- functionName: 'symbol',
1310
- },
1311
- {
1312
- address,
1313
- abi,
1314
- functionName: 'totalSupply',
1315
- },
1316
- ] as const,
1317
- allowFailure: false,
1318
- deployless: true,
1319
- }).then(([currency, decimals, name, symbol, totalSupply]) => ({
1320
- name,
1321
- symbol,
1322
- currency,
1323
- decimals,
1324
- totalSupply,
1325
- }))
1326
-
1327
- return multicall(client, {
1328
- ...rest,
1329
- contracts: [
1330
- {
1331
- address,
1332
- abi,
1333
- functionName: 'currency',
1334
- },
1335
- {
1336
- address,
1337
- abi,
1338
- functionName: 'decimals',
1339
- },
1340
- {
1341
- address,
1342
- abi,
1343
- functionName: 'quoteToken',
1344
- },
1345
- {
1346
- address,
1347
- abi,
1348
- functionName: 'name',
1349
- },
1350
- {
1351
- address,
1352
- abi,
1353
- functionName: 'paused',
1354
- },
1355
- {
1356
- address,
1357
- abi,
1358
- functionName: 'supplyCap',
1359
- },
1360
- {
1361
- address,
1362
- abi,
1363
- functionName: 'symbol',
1364
- },
1365
- {
1366
- address,
1367
- abi,
1368
- functionName: 'totalSupply',
1369
- },
1370
- {
1371
- address,
1372
- abi,
1373
- functionName: 'transferPolicyId',
1374
- },
1375
- ] as const,
1376
- allowFailure: false,
1377
- deployless: true,
1378
- }).then(
1379
- ([
1380
- currency,
1381
- decimals,
1382
- quoteToken,
1383
- name,
1384
- paused,
1385
- supplyCap,
1386
- symbol,
1387
- totalSupply,
1388
- transferPolicyId,
1389
- ]) => ({
1390
- name,
1391
- symbol,
1392
- currency,
1393
- decimals,
1394
- quoteToken,
1395
- totalSupply,
1396
- paused,
1397
- supplyCap,
1398
- transferPolicyId,
1399
- }),
1400
- )
1401
- }
1402
-
1403
- export declare namespace getMetadata {
1404
- export type Parameters = {
1405
- /** Address or ID of the TIP20 token. */
1406
- token: TokenId.TokenIdOrAddress
1407
- }
1408
-
1409
- export type ReturnValue = Compute<{
1410
- /**
1411
- * Currency (e.g. "USD").
1412
- */
1413
- currency: string
1414
- /**
1415
- * Decimals of the token.
1416
- */
1417
- decimals: number
1418
- /**
1419
- * Quote token.
1420
- *
1421
- * Returns `undefined` for the default quote token (`0x20c...0000`).
1422
- */
1423
- quoteToken?: Address | undefined
1424
- /**
1425
- * Name of the token.
1426
- */
1427
- name: string
1428
- /**
1429
- * Whether the token is paused.
1430
- *
1431
- * Returns `undefined` for the default quote token (`0x20c...0000`).
1432
- */
1433
- paused?: boolean | undefined
1434
- /**
1435
- * Supply cap.
1436
- *
1437
- * Returns `undefined` for the default quote token (`0x20c...0000`).
1438
- */
1439
- supplyCap?: bigint | undefined
1440
- /**
1441
- * Symbol of the token.
1442
- */
1443
- symbol: string
1444
- /**
1445
- * Total supply of the token.
1446
- */
1447
- totalSupply: bigint
1448
- /**
1449
- * Transfer policy ID.
1450
- * 0="always-reject", 1="always-allow", >2=custom policy
1451
- *
1452
- * Returns `undefined` for the default quote token (`0x20c...0000`).
1453
- */
1454
- transferPolicyId?: bigint | undefined
1455
- }>
1456
- }
1457
-
1458
- /**
1459
- * Gets the admin role for a specific role in a TIP20 token.
1460
- *
1461
- * @example
1462
- * ```ts
1463
- * import { createClient, http } from 'viem'
1464
- * import { tempo } from 'tempo.ts/chains'
1465
- * import { Actions } from 'tempo.ts/viem'
1466
- *
1467
- * const client = createClient({
1468
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1469
- * transport: http(),
1470
- * })
1471
- *
1472
- * const adminRole = await Actions.token.getRoleAdmin(client, {
1473
- * role: 'issuer',
1474
- * token: '0x...',
1475
- * })
1476
- * ```
1477
- *
1478
- * @param client - Client.
1479
- * @param parameters - Parameters.
1480
- * @returns The admin role hash.
1481
- */
1482
- export async function getRoleAdmin<chain extends Chain | undefined>(
1483
- client: Client<Transport, chain>,
1484
- parameters: getRoleAdmin.Parameters,
1485
- ): Promise<getRoleAdmin.ReturnValue> {
1486
- return readContract(client, {
1487
- ...parameters,
1488
- ...getRoleAdmin.call(parameters),
1489
- })
1490
- }
1491
-
1492
- export namespace getRoleAdmin {
1493
- export type Parameters = ReadParameters & Args
1494
-
1495
- export type Args = {
1496
- /** Role to get admin for. */
1497
- role: TokenRole.TokenRole
1498
- /** Address or ID of the TIP20 token. */
1499
- token: TokenId.TokenIdOrAddress
1500
- }
1501
-
1502
- export type ReturnValue = ReadContractReturnType<
1503
- typeof Abis.tip20,
1504
- 'getRoleAdmin',
1505
- never
1506
- >
1507
-
1508
- /**
1509
- * Defines a call to the `getRoleAdmin` function.
1510
- *
1511
- * @param args - Arguments.
1512
- * @returns The call.
1513
- */
1514
- export function call(args: Args) {
1515
- const { role, token } = args
1516
- return defineCall({
1517
- address: TokenId.toAddress(token),
1518
- abi: Abis.tip20,
1519
- functionName: 'getRoleAdmin',
1520
- args: [TokenRole.serialize(role)],
1521
- })
1522
- }
1523
- }
1524
-
1525
- /**
1526
- * Checks if an account has a specific role for a TIP20 token.
1527
- *
1528
- * @example
1529
- * ```ts
1530
- * import { createClient, http } from 'viem'
1531
- * import { tempo } from 'tempo.ts/chains'
1532
- * import { Actions } from 'tempo.ts/viem'
1533
- *
1534
- * const client = createClient({
1535
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1536
- * transport: http(),
1537
- * })
1538
- *
1539
- * const hasRole = await Actions.token.hasRole(client, {
1540
- * account: '0x...',
1541
- * role: 'issuer',
1542
- * token: '0x...',
1543
- * })
1544
- * ```
1545
- *
1546
- * @param client - Client.
1547
- * @param parameters - Parameters.
1548
- * @returns Whether the account has the role.
1549
- */
1550
- export async function hasRole<
1551
- chain extends Chain | undefined,
1552
- account extends Account | undefined,
1553
- >(
1554
- client: Client<Transport, chain, account>,
1555
- parameters: hasRole.Parameters<account>,
1556
- ): Promise<hasRole.ReturnValue> {
1557
- const { account = client.account } = parameters
1558
- const address = account ? parseAccount(account).address : undefined
1559
- if (!address) throw new Error('account is required.')
1560
- return readContract(client, {
1561
- ...parameters,
1562
- ...hasRole.call({ ...parameters, account: address }),
1563
- })
1564
- }
1565
-
1566
- export namespace hasRole {
1567
- export type Parameters<
1568
- account extends Account | undefined = Account | undefined,
1569
- > = ReadParameters & Omit<Args, 'account'> & GetAccountParameter<account>
1570
-
1571
- export type Args = {
1572
- /** Account address to check. */
1573
- account: Address
1574
- /** Role to check. */
1575
- role: TokenRole.TokenRole
1576
- /** Address or ID of the TIP20 token. */
1577
- token: TokenId.TokenIdOrAddress
1578
- }
1579
-
1580
- export type ReturnValue = ReadContractReturnType<
1581
- typeof Abis.tip20,
1582
- 'hasRole',
1583
- never
1584
- >
1585
-
1586
- /**
1587
- * Defines a call to the `hasRole` function.
1588
- *
1589
- * @param args - Arguments.
1590
- * @returns The call.
1591
- */
1592
- export function call(args: Args) {
1593
- const { account, role, token } = args
1594
- return defineCall({
1595
- address: TokenId.toAddress(token),
1596
- abi: Abis.tip20,
1597
- functionName: 'hasRole',
1598
- args: [account, TokenRole.serialize(role)],
1599
- })
1600
- }
1601
- }
1602
-
1603
- /**
1604
- * Grants a role for a TIP20 token.
1605
- *
1606
- * @example
1607
- * ```ts
1608
- * import { createClient, http } from 'viem'
1609
- * import { tempo } from 'tempo.ts/chains'
1610
- * import { Actions } from 'tempo.ts/viem'
1611
- * import { privateKeyToAccount } from 'viem/accounts'
1612
- *
1613
- * const client = createClient({
1614
- * account: privateKeyToAccount('0x...'),
1615
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1616
- * transport: http(),
1617
- * })
1618
- *
1619
- * const result = await Actions.token.grantRoles(client, {
1620
- * token: '0x...',
1621
- * to: '0x...',
1622
- * roles: ['issuer'],
1623
- * })
1624
- * ```
1625
- *
1626
- * @param client - Client.
1627
- * @param parameters - Parameters.
1628
- * @returns The transaction hash.
1629
- */
1630
- export async function grantRoles<
1631
- chain extends Chain | undefined,
1632
- account extends Account | undefined,
1633
- >(
1634
- client: Client<Transport, chain, account>,
1635
- parameters: grantRoles.Parameters<chain, account>,
1636
- ): Promise<grantRoles.ReturnValue> {
1637
- return grantRoles.inner(sendTransaction, client, parameters)
1638
- }
1639
-
1640
- export namespace grantRoles {
1641
- export type Parameters<
1642
- chain extends Chain | undefined = Chain | undefined,
1643
- account extends Account | undefined = Account | undefined,
1644
- > = WriteParameters<chain, account> &
1645
- Omit<Args, 'role'> & {
1646
- /** Role to grant. */
1647
- roles: readonly TokenRole.TokenRole[]
1648
- }
1649
-
1650
- export type Args = {
1651
- /** Role to grant. */
1652
- role: TokenRole.TokenRole
1653
- /** Address or ID of the TIP20 token. */
1654
- token: TokenId.TokenIdOrAddress
1655
- /** Address to grant the role to. */
1656
- to: Address
1657
- }
1658
-
1659
- export type ReturnValue = WriteContractReturnType
1660
-
1661
- // TODO: exhaustive error type
1662
- export type ErrorType = BaseErrorType
1663
-
1664
- /** @internal */
1665
- export async function inner<
1666
- action extends typeof sendTransaction | typeof sendTransactionSync,
1667
- chain extends Chain | undefined,
1668
- account extends Account | undefined,
1669
- >(
1670
- action: action,
1671
- client: Client<Transport, chain, account>,
1672
- parameters: grantRoles.Parameters<chain, account>,
1673
- ): Promise<ReturnType<action>> {
1674
- return (await action(client, {
1675
- ...parameters,
1676
- calls: parameters.roles.map((role) => {
1677
- const call = grantRoles.call({ ...parameters, role })
1678
- return {
1679
- ...call,
1680
- data: encodeFunctionData(call),
1681
- }
1682
- }),
1683
- } as never)) as never
1684
- }
1685
-
1686
- /**
1687
- * Defines a call to the `grantRole` function.
1688
- *
1689
- * Can be passed as a parameter to:
1690
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1691
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1692
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1693
- *
1694
- * @example
1695
- * ```ts
1696
- * import { createClient, http, walletActions } from 'viem'
1697
- * import { tempo } from 'tempo.ts/chains'
1698
- * import { Actions } from 'tempo.ts/viem'
1699
- *
1700
- * const client = createClient({
1701
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1702
- * transport: http(),
1703
- * }).extend(walletActions)
1704
- *
1705
- * const { result } = await client.sendCalls({
1706
- * calls: [
1707
- * actions.token.grantRoles.call({
1708
- * token: '0x20c0...babe',
1709
- * to: '0x20c0...beef',
1710
- * role: 'issuer',
1711
- * }),
1712
- * ]
1713
- * })
1714
- * ```
1715
- *
1716
- * @param args - Arguments.
1717
- * @returns The call.
1718
- */
1719
- export function call(args: Args) {
1720
- const { token, to, role } = args
1721
- const roleHash = TokenRole.serialize(role)
1722
- return defineCall({
1723
- address: TokenId.toAddress(token),
1724
- abi: Abis.tip20,
1725
- functionName: 'grantRole',
1726
- args: [roleHash, to],
1727
- })
1728
- }
1729
-
1730
- /**
1731
- * Extracts the events from the logs.
1732
- *
1733
- * @param logs - Logs.
1734
- * @returns The events.
1735
- */
1736
- export function extractEvents(logs: Log[]) {
1737
- const events = parseEventLogs({
1738
- abi: Abis.tip20,
1739
- logs,
1740
- eventName: 'RoleMembershipUpdated',
1741
- })
1742
- if (events.length === 0)
1743
- throw new Error('`RoleMembershipUpdated` events not found.')
1744
- return events
1745
- }
1746
- }
1747
-
1748
- /**
1749
- * Grants a role for a TIP20 token.
1750
- *
1751
- * @example
1752
- * ```ts
1753
- * import { createClient, http } from 'viem'
1754
- * import { tempo } from 'tempo.ts/chains'
1755
- * import { Actions } from 'tempo.ts/viem'
1756
- * import { privateKeyToAccount } from 'viem/accounts'
1757
- *
1758
- * const client = createClient({
1759
- * account: privateKeyToAccount('0x...'),
1760
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1761
- * transport: http(),
1762
- * })
1763
- *
1764
- * const result = await Actions.token.grantRolesSync(client, {
1765
- * token: '0x...',
1766
- * to: '0x...',
1767
- * roles: ['issuer'],
1768
- * })
1769
- * ```
1770
- *
1771
- * @param client - Client.
1772
- * @param parameters - Parameters.
1773
- * @returns The transaction receipt and event data.
1774
- */
1775
- export async function grantRolesSync<
1776
- chain extends Chain | undefined,
1777
- account extends Account | undefined,
1778
- >(
1779
- client: Client<Transport, chain, account>,
1780
- parameters: grantRolesSync.Parameters<chain, account>,
1781
- ): Promise<grantRolesSync.ReturnValue> {
1782
- const { throwOnReceiptRevert = true, ...rest } = parameters
1783
- const receipt = await grantRoles.inner(sendTransactionSync, client, {
1784
- ...rest,
1785
- throwOnReceiptRevert,
1786
- } as never)
1787
- const events = grantRoles.extractEvents(receipt.logs)
1788
- const value = events.map((event) => event.args)
1789
- return {
1790
- receipt,
1791
- value,
1792
- }
1793
- }
1794
-
1795
- export namespace grantRolesSync {
1796
- export type Parameters<
1797
- chain extends Chain | undefined = Chain | undefined,
1798
- account extends Account | undefined = Account | undefined,
1799
- > = grantRoles.Parameters<chain, account>
1800
-
1801
- export type Args = grantRoles.Args
1802
-
1803
- export type ReturnValue = {
1804
- receipt: TransactionReceipt
1805
- value: readonly GetEventArgs<
1806
- typeof Abis.tip20,
1807
- 'RoleMembershipUpdated',
1808
- { IndexedOnly: false; Required: true }
1809
- >[]
1810
- }
1811
-
1812
- // TODO: exhaustive error type
1813
- export type ErrorType = BaseErrorType
1814
- }
1815
-
1816
- /**
1817
- * Mints TIP20 tokens to an address.
1818
- *
1819
- * @example
1820
- * ```ts
1821
- * import { createClient, http } from 'viem'
1822
- * import { tempo } from 'tempo.ts/chains'
1823
- * import { Actions } from 'tempo.ts/viem'
1824
- * import { privateKeyToAccount } from 'viem/accounts'
1825
- *
1826
- * const client = createClient({
1827
- * account: privateKeyToAccount('0x...'),
1828
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1829
- * transport: http(),
1830
- * })
1831
- *
1832
- * const result = await Actions.token.mint(client, {
1833
- * to: '0x...',
1834
- * amount: 100n,
1835
- * token: '0x...',
1836
- * })
1837
- * ```
1838
- *
1839
- * @param client - Client.
1840
- * @param parameters - Parameters.
1841
- * @returns The transaction hash.
1842
- */
1843
- export async function mint<
1844
- chain extends Chain | undefined,
1845
- account extends Account | undefined,
1846
- >(
1847
- client: Client<Transport, chain, account>,
1848
- parameters: mint.Parameters<chain, account>,
1849
- ): Promise<mint.ReturnValue> {
1850
- return mint.inner(writeContract, client, parameters)
1851
- }
1852
-
1853
- export namespace mint {
1854
- export type Parameters<
1855
- chain extends Chain | undefined = Chain | undefined,
1856
- account extends Account | undefined = Account | undefined,
1857
- > = WriteParameters<chain, account> & Args
1858
-
1859
- export type Args = {
1860
- /** Amount of tokens to mint. */
1861
- amount: bigint
1862
- /** Memo to include in the mint. */
1863
- memo?: Hex.Hex | undefined
1864
- /** Address to mint tokens to. */
1865
- to: Address
1866
- /** Address or ID of the TIP20 token. */
1867
- token: TokenId.TokenIdOrAddress
1868
- }
1869
-
1870
- export type ReturnValue = WriteContractReturnType
1871
-
1872
- // TODO: exhaustive error type
1873
- export type ErrorType = BaseErrorType
1874
-
1875
- /** @internal */
1876
- export async function inner<
1877
- action extends typeof writeContract | typeof writeContractSync,
1878
- chain extends Chain | undefined,
1879
- account extends Account | undefined,
1880
- >(
1881
- action: action,
1882
- client: Client<Transport, chain, account>,
1883
- parameters: any,
1884
- ): Promise<ReturnType<action>> {
1885
- const call = mint.call(parameters)
1886
- return (await action(client, {
1887
- ...parameters,
1888
- ...call,
1889
- } as never)) as never
1890
- }
1891
-
1892
- /**
1893
- * Defines a call to the `mint` or `mintWithMemo` function.
1894
- *
1895
- * Can be passed as a parameter to:
1896
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1897
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1898
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1899
- *
1900
- * @example
1901
- * ```ts
1902
- * import { createClient, http, walletActions } from 'viem'
1903
- * import { tempo } from 'tempo.ts/chains'
1904
- * import { Actions } from 'tempo.ts/viem'
1905
- *
1906
- * const client = createClient({
1907
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1908
- * transport: http(),
1909
- * }).extend(walletActions)
1910
- *
1911
- * const { result } = await client.sendCalls({
1912
- * calls: [
1913
- * actions.token.mint.call({
1914
- * to: '0x20c0...beef',
1915
- * amount: 100n,
1916
- * token: '0x20c0...babe',
1917
- * }),
1918
- * ]
1919
- * })
1920
- * ```
1921
- *
1922
- * @param args - Arguments.
1923
- * @returns The call.
1924
- */
1925
- export function call(args: Args) {
1926
- const { to, amount, memo, token } = args
1927
- const callArgs = memo
1928
- ? ({
1929
- functionName: 'mintWithMemo',
1930
- args: [to, amount, Hex.padLeft(memo, 32)],
1931
- } as const)
1932
- : ({
1933
- functionName: 'mint',
1934
- args: [to, amount],
1935
- } as const)
1936
- return defineCall({
1937
- address: TokenId.toAddress(token),
1938
- abi: Abis.tip20,
1939
- ...callArgs,
1940
- })
1941
- }
1942
-
1943
- /**
1944
- * Extracts the event from the logs.
1945
- *
1946
- * @param logs - Logs.
1947
- * @returns The event.
1948
- */
1949
- export function extractEvent(logs: Log[]) {
1950
- const [log] = parseEventLogs({
1951
- abi: Abis.tip20,
1952
- logs,
1953
- eventName: 'Mint',
1954
- })
1955
- if (!log) throw new Error('`Mint` event not found.')
1956
- return log
1957
- }
1958
- }
1959
-
1960
- /**
1961
- * Mints TIP20 tokens to an address.
1962
- *
1963
- * @example
1964
- * ```ts
1965
- * import { createClient, http } from 'viem'
1966
- * import { tempo } from 'tempo.ts/chains'
1967
- * import { Actions } from 'tempo.ts/viem'
1968
- * import { privateKeyToAccount } from 'viem/accounts'
1969
- *
1970
- * const client = createClient({
1971
- * account: privateKeyToAccount('0x...'),
1972
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
1973
- * transport: http(),
1974
- * })
1975
- *
1976
- * const result = await Actions.token.mintSync(client, {
1977
- * to: '0x...',
1978
- * amount: 100n,
1979
- * token: '0x...',
1980
- * })
1981
- * ```
1982
- *
1983
- * @param client - Client.
1984
- * @param parameters - Parameters.
1985
- * @returns The transaction receipt and event data.
1986
- */
1987
- export async function mintSync<
1988
- chain extends Chain | undefined,
1989
- account extends Account | undefined,
1990
- >(
1991
- client: Client<Transport, chain, account>,
1992
- parameters: mintSync.Parameters<chain, account>,
1993
- ): Promise<mintSync.ReturnValue> {
1994
- const { throwOnReceiptRevert = true, ...rest } = parameters
1995
- const receipt = await mint.inner(writeContractSync, client, {
1996
- ...rest,
1997
- throwOnReceiptRevert,
1998
- } as never)
1999
- const { args } = mint.extractEvent(receipt.logs)
2000
- return {
2001
- ...args,
2002
- receipt,
2003
- } as never
2004
- }
2005
-
2006
- export namespace mintSync {
2007
- export type Parameters<
2008
- chain extends Chain | undefined = Chain | undefined,
2009
- account extends Account | undefined = Account | undefined,
2010
- > = mint.Parameters<chain, account>
2011
-
2012
- export type Args = mint.Args
2013
-
2014
- export type ReturnValue = Compute<
2015
- GetEventArgs<
2016
- typeof Abis.tip20,
2017
- 'Mint',
2018
- {
2019
- IndexedOnly: false
2020
- Required: true
2021
- }
2022
- > & {
2023
- receipt: TransactionReceipt
2024
- }
2025
- >
2026
-
2027
- // TODO: exhaustive error type
2028
- export type ErrorType = BaseErrorType
2029
- }
2030
-
2031
- /**
2032
- * Pauses a TIP20 token.
2033
- *
2034
- * @example
2035
- * ```ts
2036
- * import { createClient, http } from 'viem'
2037
- * import { tempo } from 'tempo.ts/chains'
2038
- * import { Actions } from 'tempo.ts/viem'
2039
- * import { privateKeyToAccount } from 'viem/accounts'
2040
- *
2041
- * const client = createClient({
2042
- * account: privateKeyToAccount('0x...'),
2043
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2044
- * transport: http(),
2045
- * })
2046
- *
2047
- * const result = await Actions.token.pause(client, {
2048
- * token: '0x...',
2049
- * })
2050
- * ```
2051
- *
2052
- * @param client - Client.
2053
- * @param parameters - Parameters.
2054
- * @returns The transaction hash.
2055
- */
2056
- export async function pause<
2057
- chain extends Chain | undefined,
2058
- account extends Account | undefined,
2059
- >(
2060
- client: Client<Transport, chain, account>,
2061
- parameters: pause.Parameters<chain, account>,
2062
- ): Promise<pause.ReturnValue> {
2063
- return pause.inner(writeContract, client, parameters)
2064
- }
2065
-
2066
- export namespace pause {
2067
- export type Parameters<
2068
- chain extends Chain | undefined = Chain | undefined,
2069
- account extends Account | undefined = Account | undefined,
2070
- > = WriteParameters<chain, account> & Args
2071
-
2072
- export type Args = {
2073
- /** Address or ID of the TIP20 token. */
2074
- token: TokenId.TokenIdOrAddress
2075
- }
2076
-
2077
- export type ReturnValue = WriteContractReturnType
2078
-
2079
- // TODO: exhaustive error type
2080
- export type ErrorType = BaseErrorType
2081
-
2082
- /** @internal */
2083
- export async function inner<
2084
- action extends typeof writeContract | typeof writeContractSync,
2085
- chain extends Chain | undefined,
2086
- account extends Account | undefined,
2087
- >(
2088
- action: action,
2089
- client: Client<Transport, chain, account>,
2090
- parameters: pause.Parameters<chain, account>,
2091
- ): Promise<ReturnType<action>> {
2092
- const { token, ...rest } = parameters
2093
- const call = pause.call({ token })
2094
- return (await action(client, {
2095
- ...rest,
2096
- ...call,
2097
- } as never)) as never
2098
- }
2099
-
2100
- /**
2101
- * Defines a call to the `pause` function.
2102
- *
2103
- * Can be passed as a parameter to:
2104
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2105
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2106
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2107
- *
2108
- * @example
2109
- * ```ts
2110
- * import { createClient, http, walletActions } from 'viem'
2111
- * import { tempo } from 'tempo.ts/chains'
2112
- * import { Actions } from 'tempo.ts/viem'
2113
- *
2114
- * const client = createClient({
2115
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2116
- * transport: http(),
2117
- * }).extend(walletActions)
2118
- *
2119
- * const { result } = await client.sendCalls({
2120
- * calls: [
2121
- * actions.token.pause.call({
2122
- * token: '0x20c0...babe',
2123
- * }),
2124
- * ]
2125
- * })
2126
- * ```
2127
- *
2128
- * @param args - Arguments.
2129
- * @returns The call.
2130
- */
2131
- export function call(args: Args) {
2132
- const { token } = args
2133
- return defineCall({
2134
- address: TokenId.toAddress(token),
2135
- abi: Abis.tip20,
2136
- functionName: 'pause',
2137
- args: [],
2138
- })
2139
- }
2140
-
2141
- /**
2142
- * Extracts the event from the logs.
2143
- *
2144
- * @param logs - Logs.
2145
- * @returns The event.
2146
- */
2147
- export function extractEvent(logs: Log[]) {
2148
- const [log] = parseEventLogs({
2149
- abi: Abis.tip20,
2150
- logs,
2151
- eventName: 'PauseStateUpdate',
2152
- })
2153
- if (!log) throw new Error('`PauseStateUpdate` event not found.')
2154
- return log
2155
- }
2156
- }
2157
-
2158
- /**
2159
- * Pauses a TIP20 token.
2160
- *
2161
- * @example
2162
- * ```ts
2163
- * import { createClient, http } from 'viem'
2164
- * import { tempo } from 'tempo.ts/chains'
2165
- * import { Actions } from 'tempo.ts/viem'
2166
- * import { privateKeyToAccount } from 'viem/accounts'
2167
- *
2168
- * const client = createClient({
2169
- * account: privateKeyToAccount('0x...'),
2170
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2171
- * transport: http(),
2172
- * })
2173
- *
2174
- * const result = await Actions.token.pauseSync(client, {
2175
- * token: '0x...',
2176
- * })
2177
- * ```
2178
- *
2179
- * @param client - Client.
2180
- * @param parameters - Parameters.
2181
- * @returns The transaction receipt and event data.
2182
- */
2183
- export async function pauseSync<
2184
- chain extends Chain | undefined,
2185
- account extends Account | undefined,
2186
- >(
2187
- client: Client<Transport, chain, account>,
2188
- parameters: pauseSync.Parameters<chain, account>,
2189
- ): Promise<pauseSync.ReturnValue> {
2190
- const { throwOnReceiptRevert = true, ...rest } = parameters
2191
- const receipt = await pause.inner(writeContractSync, client, {
2192
- ...rest,
2193
- throwOnReceiptRevert,
2194
- } as never)
2195
- const { args } = pause.extractEvent(receipt.logs)
2196
- return {
2197
- ...args,
2198
- receipt,
2199
- }
2200
- }
2201
-
2202
- export namespace pauseSync {
2203
- export type Parameters<
2204
- chain extends Chain | undefined = Chain | undefined,
2205
- account extends Account | undefined = Account | undefined,
2206
- > = pause.Parameters<chain, account>
2207
-
2208
- export type Args = pause.Args
2209
-
2210
- export type ReturnValue = GetEventArgs<
2211
- typeof Abis.tip20,
2212
- 'PauseStateUpdate',
2213
- { IndexedOnly: false; Required: true }
2214
- > & {
2215
- receipt: TransactionReceipt
2216
- }
2217
-
2218
- // TODO: exhaustive error type
2219
- export type ErrorType = BaseErrorType
2220
- }
2221
-
2222
- /**
2223
- * Renounces a role for a TIP20 token.
2224
- *
2225
- * @example
2226
- * ```ts
2227
- * import { createClient, http } from 'viem'
2228
- * import { tempo } from 'tempo.ts/chains'
2229
- * import { Actions } from 'tempo.ts/viem'
2230
- * import { privateKeyToAccount } from 'viem/accounts'
2231
- *
2232
- * const client = createClient({
2233
- * account: privateKeyToAccount('0x...'),
2234
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2235
- * transport: http(),
2236
- * })
2237
- *
2238
- * const result = await Actions.token.renounceRoles(client, {
2239
- * token: '0x...',
2240
- * roles: ['issuer'],
2241
- * })
2242
- * ```
2243
- *
2244
- * @param client - Client.
2245
- * @param parameters - Parameters.
2246
- * @returns The transaction hash.
2247
- */
2248
- export async function renounceRoles<
2249
- chain extends Chain | undefined,
2250
- account extends Account | undefined,
2251
- >(
2252
- client: Client<Transport, chain, account>,
2253
- parameters: renounceRoles.Parameters<chain, account>,
2254
- ): Promise<renounceRoles.ReturnValue> {
2255
- return renounceRoles.inner(sendTransaction, client, parameters)
2256
- }
2257
-
2258
- export namespace renounceRoles {
2259
- export type Parameters<
2260
- chain extends Chain | undefined = Chain | undefined,
2261
- account extends Account | undefined = Account | undefined,
2262
- > = WriteParameters<chain, account> &
2263
- Omit<Args, 'role'> & {
2264
- /** Roles to renounce. */
2265
- roles: readonly TokenRole.TokenRole[]
2266
- }
2267
-
2268
- export type Args = {
2269
- /** Role to renounce. */
2270
- role: TokenRole.TokenRole
2271
- /** Address or ID of the TIP20 token. */
2272
- token: TokenId.TokenIdOrAddress
2273
- }
2274
-
2275
- export type ReturnValue = WriteContractReturnType
2276
-
2277
- // TODO: exhaustive error type
2278
- export type ErrorType = BaseErrorType
2279
-
2280
- /** @internal */
2281
- export async function inner<
2282
- action extends typeof sendTransaction | typeof sendTransactionSync,
2283
- chain extends Chain | undefined,
2284
- account extends Account | undefined,
2285
- >(
2286
- action: action,
2287
- client: Client<Transport, chain, account>,
2288
- parameters: renounceRoles.Parameters<chain, account>,
2289
- ): Promise<ReturnType<action>> {
2290
- return (await action(client, {
2291
- ...parameters,
2292
- calls: parameters.roles.map((role) => {
2293
- const call = renounceRoles.call({ ...parameters, role })
2294
- return {
2295
- ...call,
2296
- data: encodeFunctionData(call),
2297
- }
2298
- }),
2299
- } as never)) as never
2300
- }
2301
-
2302
- /**
2303
- * Defines a call to the `renounceRole` function.
2304
- *
2305
- * Can be passed as a parameter to:
2306
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2307
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2308
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2309
- *
2310
- * @example
2311
- * ```ts
2312
- * import { createClient, http, walletActions } from 'viem'
2313
- * import { tempo } from 'tempo.ts/chains'
2314
- * import { Actions } from 'tempo.ts/viem'
2315
- *
2316
- * const client = createClient({
2317
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2318
- * transport: http(),
2319
- * }).extend(walletActions)
2320
- *
2321
- * const { result } = await client.sendCalls({
2322
- * calls: [
2323
- * actions.token.renounceRoles.call({
2324
- * token: '0x20c0...babe',
2325
- * role: 'issuer',
2326
- * }),
2327
- * ]
2328
- * })
2329
- * ```
2330
- *
2331
- * @param args - Arguments.
2332
- * @returns The call.
2333
- */
2334
- export function call(args: Args) {
2335
- const { token, role } = args
2336
- const roleHash = TokenRole.serialize(role)
2337
- return defineCall({
2338
- address: TokenId.toAddress(token),
2339
- abi: Abis.tip20,
2340
- functionName: 'renounceRole',
2341
- args: [roleHash],
2342
- })
2343
- }
2344
-
2345
- /**
2346
- * Extracts the events from the logs.
2347
- *
2348
- * @param logs - Logs.
2349
- * @returns The events.
2350
- */
2351
- export function extractEvents(logs: Log[]) {
2352
- const events = parseEventLogs({
2353
- abi: Abis.tip20,
2354
- logs,
2355
- eventName: 'RoleMembershipUpdated',
2356
- })
2357
- if (events.length === 0)
2358
- throw new Error('`RoleMembershipUpdated` events not found.')
2359
- return events
2360
- }
2361
- }
2362
-
2363
- /**
2364
- * Renounces a role for a TIP20 token.
2365
- *
2366
- * @example
2367
- * ```ts
2368
- * import { createClient, http } from 'viem'
2369
- * import { tempo } from 'tempo.ts/chains'
2370
- * import { Actions } from 'tempo.ts/viem'
2371
- * import { privateKeyToAccount } from 'viem/accounts'
2372
- *
2373
- * const client = createClient({
2374
- * account: privateKeyToAccount('0x...'),
2375
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2376
- * transport: http(),
2377
- * })
2378
- *
2379
- * const result = await Actions.token.renounceRolesSync(client, {
2380
- * token: '0x...',
2381
- * roles: ['issuer'],
2382
- * })
2383
- * ```
2384
- *
2385
- * @param client - Client.
2386
- * @param parameters - Parameters.
2387
- * @returns The transaction receipt and event data.
2388
- */
2389
- export async function renounceRolesSync<
2390
- chain extends Chain | undefined,
2391
- account extends Account | undefined,
2392
- >(
2393
- client: Client<Transport, chain, account>,
2394
- parameters: renounceRolesSync.Parameters<chain, account>,
2395
- ): Promise<renounceRolesSync.ReturnValue> {
2396
- const { throwOnReceiptRevert = true, ...rest } = parameters
2397
- const receipt = await renounceRoles.inner(sendTransactionSync, client, {
2398
- ...rest,
2399
- throwOnReceiptRevert,
2400
- } as never)
2401
- const events = renounceRoles.extractEvents(receipt.logs)
2402
- const value = events.map((event) => event.args)
2403
- return {
2404
- receipt,
2405
- value,
2406
- }
2407
- }
2408
-
2409
- export namespace renounceRolesSync {
2410
- export type Parameters<
2411
- chain extends Chain | undefined = Chain | undefined,
2412
- account extends Account | undefined = Account | undefined,
2413
- > = renounceRoles.Parameters<chain, account>
2414
-
2415
- export type Args = renounceRoles.Args
2416
-
2417
- export type ReturnValue = {
2418
- receipt: TransactionReceipt
2419
- value: readonly GetEventArgs<
2420
- typeof Abis.tip20,
2421
- 'RoleMembershipUpdated',
2422
- { IndexedOnly: false; Required: true }
2423
- >[]
2424
- }
2425
-
2426
- // TODO: exhaustive error type
2427
- export type ErrorType = BaseErrorType
2428
- }
2429
-
2430
- /**
2431
- * Revokes a role for a TIP20 token.
2432
- *
2433
- * @example
2434
- * ```ts
2435
- * import { createClient, http } from 'viem'
2436
- * import { tempo } from 'tempo.ts/chains'
2437
- * import { Actions } from 'tempo.ts/viem'
2438
- * import { privateKeyToAccount } from 'viem/accounts'
2439
- *
2440
- * const client = createClient({
2441
- * account: privateKeyToAccount('0x...'),
2442
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2443
- * transport: http(),
2444
- * })
2445
- *
2446
- * const result = await Actions.token.revokeRoles(client, {
2447
- * token: '0x...',
2448
- * from: '0x...',
2449
- * roles: ['issuer'],
2450
- * })
2451
- * ```
2452
- *
2453
- * @param client - Client.
2454
- * @param parameters - Parameters.
2455
- * @returns The transaction hash.
2456
- */
2457
- export async function revokeRoles<
2458
- chain extends Chain | undefined,
2459
- account extends Account | undefined,
2460
- >(
2461
- client: Client<Transport, chain, account>,
2462
- parameters: revokeRoles.Parameters<chain, account>,
2463
- ): Promise<revokeRoles.ReturnValue> {
2464
- return revokeRoles.inner(sendTransaction, client, parameters)
2465
- }
2466
-
2467
- export namespace revokeRoles {
2468
- export type Parameters<
2469
- chain extends Chain | undefined = Chain | undefined,
2470
- account extends Account | undefined = Account | undefined,
2471
- > = SendTransactionSyncParameters<chain, account> &
2472
- Omit<Args, 'role'> & {
2473
- /** Role to revoke. */
2474
- roles: readonly TokenRole.TokenRole[]
2475
- }
2476
-
2477
- export type Args = {
2478
- /** Address to revoke the role from. */
2479
- from: Address
2480
- /** Role to revoke. */
2481
- role: TokenRole.TokenRole
2482
- /** Address or ID of the TIP20 token. */
2483
- token: TokenId.TokenIdOrAddress
2484
- }
2485
-
2486
- export type ReturnValue = WriteContractReturnType
2487
-
2488
- // TODO: exhaustive error type
2489
- export type ErrorType = BaseErrorType
2490
-
2491
- /** @internal */
2492
- export async function inner<
2493
- action extends typeof sendTransaction | typeof sendTransactionSync,
2494
- chain extends Chain | undefined,
2495
- account extends Account | undefined,
2496
- >(
2497
- action: action,
2498
- client: Client<Transport, chain, account>,
2499
- parameters: revokeRoles.Parameters<chain, account>,
2500
- ): Promise<ReturnType<action>> {
2501
- return (await action(client, {
2502
- ...parameters,
2503
- calls: parameters.roles.map((role) => {
2504
- const call = revokeRoles.call({ ...parameters, role })
2505
- return {
2506
- ...call,
2507
- data: encodeFunctionData(call),
2508
- }
2509
- }),
2510
- } as never)) as never
2511
- }
2512
-
2513
- /**
2514
- * Defines a call to the `revokeRole` function.
2515
- *
2516
- * Can be passed as a parameter to:
2517
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2518
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2519
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2520
- *
2521
- * @example
2522
- * ```ts
2523
- * import { createClient, http, walletActions } from 'viem'
2524
- * import { tempo } from 'tempo.ts/chains'
2525
- * import { Actions } from 'tempo.ts/viem'
2526
- *
2527
- * const client = createClient({
2528
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2529
- * transport: http(),
2530
- * }).extend(walletActions)
2531
- *
2532
- * const { result } = await client.sendCalls({
2533
- * calls: [
2534
- * actions.token.revokeRoles.call({
2535
- * token: '0x20c0...babe',
2536
- * from: '0x20c0...beef',
2537
- * role: 'issuer',
2538
- * }),
2539
- * ]
2540
- * })
2541
- * ```
2542
- *
2543
- * @param args - Arguments.
2544
- * @returns The call.
2545
- */
2546
- export function call(args: Args) {
2547
- const { token, from, role } = args
2548
- const roleHash = TokenRole.serialize(role)
2549
- return defineCall({
2550
- address: TokenId.toAddress(token),
2551
- abi: Abis.tip20,
2552
- functionName: 'revokeRole',
2553
- args: [roleHash, from],
2554
- })
2555
- }
2556
-
2557
- /**
2558
- * Extracts the events from the logs.
2559
- *
2560
- * @param logs - Logs.
2561
- * @returns The events.
2562
- */
2563
- export function extractEvents(logs: Log[]) {
2564
- const events = parseEventLogs({
2565
- abi: Abis.tip20,
2566
- logs,
2567
- eventName: 'RoleMembershipUpdated',
2568
- })
2569
- if (events.length === 0)
2570
- throw new Error('`RoleMembershipUpdated` events not found.')
2571
- return events
2572
- }
2573
- }
2574
-
2575
- /**
2576
- * Revokes a role for a TIP20 token.
2577
- *
2578
- * @example
2579
- * ```ts
2580
- * import { createClient, http } from 'viem'
2581
- * import { tempo } from 'tempo.ts/chains'
2582
- * import { Actions } from 'tempo.ts/viem'
2583
- * import { privateKeyToAccount } from 'viem/accounts'
2584
- *
2585
- * const client = createClient({
2586
- * account: privateKeyToAccount('0x...'),
2587
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2588
- * transport: http(),
2589
- * })
2590
- *
2591
- * const result = await Actions.token.revokeRolesSync(client, {
2592
- * token: '0x...',
2593
- * from: '0x...',
2594
- * roles: ['issuer'],
2595
- * })
2596
- * ```
2597
- *
2598
- * @param client - Client.
2599
- * @param parameters - Parameters.
2600
- * @returns The transaction receipt and event data.
2601
- */
2602
- export async function revokeRolesSync<
2603
- chain extends Chain | undefined,
2604
- account extends Account | undefined,
2605
- >(
2606
- client: Client<Transport, chain, account>,
2607
- parameters: revokeRolesSync.Parameters<chain, account>,
2608
- ): Promise<revokeRolesSync.ReturnValue> {
2609
- const { throwOnReceiptRevert = true, ...rest } = parameters
2610
- const receipt = await revokeRoles.inner(sendTransactionSync, client, {
2611
- ...rest,
2612
- throwOnReceiptRevert,
2613
- } as never)
2614
- const events = revokeRoles.extractEvents(receipt.logs)
2615
- const value = events.map((event) => event.args)
2616
- return {
2617
- receipt,
2618
- value,
2619
- }
2620
- }
2621
-
2622
- export namespace revokeRolesSync {
2623
- export type Parameters<
2624
- chain extends Chain | undefined = Chain | undefined,
2625
- account extends Account | undefined = Account | undefined,
2626
- > = revokeRoles.Parameters<chain, account>
2627
-
2628
- export type Args = revokeRoles.Args
2629
-
2630
- export type ReturnValue = {
2631
- receipt: TransactionReceipt
2632
- value: readonly GetEventArgs<
2633
- typeof Abis.tip20,
2634
- 'RoleMembershipUpdated',
2635
- { IndexedOnly: false; Required: true }
2636
- >[]
2637
- }
2638
-
2639
- // TODO: exhaustive error type
2640
- export type ErrorType = BaseErrorType
2641
- }
2642
-
2643
- /**
2644
- * Sets the supply cap for a TIP20 token.
2645
- *
2646
- * @example
2647
- * ```ts
2648
- * import { createClient, http } from 'viem'
2649
- * import { tempo } from 'tempo.ts/chains'
2650
- * import { Actions } from 'tempo.ts/viem'
2651
- * import { privateKeyToAccount } from 'viem/accounts'
2652
- *
2653
- * const client = createClient({
2654
- * account: privateKeyToAccount('0x...'),
2655
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2656
- * transport: http(),
2657
- * })
2658
- *
2659
- * const result = await Actions.token.setSupplyCap(client, {
2660
- * token: '0x...',
2661
- * supplyCap: 1000000n,
2662
- * })
2663
- * ```
2664
- *
2665
- * @param client - Client.
2666
- * @param parameters - Parameters.
2667
- * @returns The transaction hash.
2668
- */
2669
- export async function setSupplyCap<
2670
- chain extends Chain | undefined,
2671
- account extends Account | undefined,
2672
- >(
2673
- client: Client<Transport, chain, account>,
2674
- parameters: setSupplyCap.Parameters<chain, account>,
2675
- ): Promise<setSupplyCap.ReturnValue> {
2676
- return setSupplyCap.inner(writeContract, client, parameters)
2677
- }
2678
-
2679
- export namespace setSupplyCap {
2680
- export type Parameters<
2681
- chain extends Chain | undefined = Chain | undefined,
2682
- account extends Account | undefined = Account | undefined,
2683
- > = WriteParameters<chain, account> & Args
2684
-
2685
- export type Args = {
2686
- /** New supply cap. */
2687
- supplyCap: bigint
2688
- /** Address or ID of the TIP20 token. */
2689
- token: TokenId.TokenIdOrAddress
2690
- }
2691
-
2692
- export type ReturnValue = WriteContractReturnType
2693
-
2694
- // TODO: exhaustive error type
2695
- export type ErrorType = BaseErrorType
2696
-
2697
- /** @internal */
2698
- export async function inner<
2699
- action extends typeof writeContract | typeof writeContractSync,
2700
- chain extends Chain | undefined,
2701
- account extends Account | undefined,
2702
- >(
2703
- action: action,
2704
- client: Client<Transport, chain, account>,
2705
- parameters: setSupplyCap.Parameters<chain, account>,
2706
- ): Promise<ReturnType<action>> {
2707
- const { supplyCap, token, ...rest } = parameters
2708
- const call = setSupplyCap.call({ supplyCap, token })
2709
- return (await action(client, {
2710
- ...rest,
2711
- ...call,
2712
- } as never)) as never
2713
- }
2714
-
2715
- /**
2716
- * Defines a call to the `setSupplyCap` function.
2717
- *
2718
- * Can be passed as a parameter to:
2719
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2720
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2721
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2722
- *
2723
- * @example
2724
- * ```ts
2725
- * import { createClient, http, walletActions } from 'viem'
2726
- * import { tempo } from 'tempo.ts/chains'
2727
- * import { Actions } from 'tempo.ts/viem'
2728
- *
2729
- * const client = createClient({
2730
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2731
- * transport: http(),
2732
- * }).extend(walletActions)
2733
- *
2734
- * const { result } = await client.sendCalls({
2735
- * calls: [
2736
- * actions.token.setSupplyCap.call({
2737
- * token: '0x20c0...babe',
2738
- * supplyCap: 1000000n,
2739
- * }),
2740
- * ]
2741
- * })
2742
- * ```
2743
- *
2744
- * @param args - Arguments.
2745
- * @returns The call.
2746
- */
2747
- export function call(args: Args) {
2748
- const { token, supplyCap } = args
2749
- return defineCall({
2750
- address: TokenId.toAddress(token),
2751
- abi: Abis.tip20,
2752
- functionName: 'setSupplyCap',
2753
- args: [supplyCap],
2754
- })
2755
- }
2756
-
2757
- /**
2758
- * Extracts the event from the logs.
2759
- *
2760
- * @param logs - Logs.
2761
- * @returns The event.
2762
- */
2763
- export function extractEvent(logs: Log[]) {
2764
- const [log] = parseEventLogs({
2765
- abi: Abis.tip20,
2766
- logs,
2767
- eventName: 'SupplyCapUpdate',
2768
- })
2769
- if (!log) throw new Error('`SupplyCapUpdate` event not found.')
2770
- return log
2771
- }
2772
- }
2773
-
2774
- /**
2775
- * Sets the supply cap for a TIP20 token.
2776
- *
2777
- * @example
2778
- * ```ts
2779
- * import { createClient, http } from 'viem'
2780
- * import { tempo } from 'tempo.ts/chains'
2781
- * import { Actions } from 'tempo.ts/viem'
2782
- * import { privateKeyToAccount } from 'viem/accounts'
2783
- *
2784
- * const client = createClient({
2785
- * account: privateKeyToAccount('0x...'),
2786
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2787
- * transport: http(),
2788
- * })
2789
- *
2790
- * const result = await Actions.token.setSupplyCapSync(client, {
2791
- * token: '0x...',
2792
- * supplyCap: 1000000n,
2793
- * })
2794
- * ```
2795
- *
2796
- * @param client - Client.
2797
- * @param parameters - Parameters.
2798
- * @returns The transaction receipt and event data.
2799
- */
2800
- export async function setSupplyCapSync<
2801
- chain extends Chain | undefined,
2802
- account extends Account | undefined,
2803
- >(
2804
- client: Client<Transport, chain, account>,
2805
- parameters: setSupplyCapSync.Parameters<chain, account>,
2806
- ): Promise<setSupplyCapSync.ReturnValue> {
2807
- const { throwOnReceiptRevert = true, ...rest } = parameters
2808
- const receipt = await setSupplyCap.inner(writeContractSync, client, {
2809
- ...rest,
2810
- throwOnReceiptRevert,
2811
- } as never)
2812
- const { args } = setSupplyCap.extractEvent(receipt.logs)
2813
- return {
2814
- ...args,
2815
- receipt,
2816
- } as never
2817
- }
2818
-
2819
- export namespace setSupplyCapSync {
2820
- export type Parameters<
2821
- chain extends Chain | undefined = Chain | undefined,
2822
- account extends Account | undefined = Account | undefined,
2823
- > = setSupplyCap.Parameters<chain, account>
2824
-
2825
- export type Args = setSupplyCap.Args
2826
-
2827
- export type ReturnValue = GetEventArgs<
2828
- typeof Abis.tip20,
2829
- 'SupplyCapUpdate',
2830
- { IndexedOnly: false; Required: true }
2831
- > & {
2832
- receipt: TransactionReceipt
2833
- }
2834
-
2835
- // TODO: exhaustive error type
2836
- export type ErrorType = BaseErrorType
2837
- }
2838
-
2839
- /**
2840
- * Sets the admin role for a specific role in a TIP20 token.
2841
- *
2842
- * @example
2843
- * ```ts
2844
- * import { createClient, http } from 'viem'
2845
- * import { tempo } from 'tempo.ts/chains'
2846
- * import { Actions } from 'tempo.ts/viem'
2847
- * import { privateKeyToAccount } from 'viem/accounts'
2848
- *
2849
- * const client = createClient({
2850
- * account: privateKeyToAccount('0x...'),
2851
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2852
- * transport: http(),
2853
- * })
2854
- *
2855
- * const result = await Actions.token.setRoleAdmin(client, {
2856
- * token: '0x...',
2857
- * role: 'issuer',
2858
- * adminRole: 'admin',
2859
- * })
2860
- * ```
2861
- *
2862
- * @param client - Client.
2863
- * @param parameters - Parameters.
2864
- * @returns The transaction hash.
2865
- */
2866
- export async function setRoleAdmin<
2867
- chain extends Chain | undefined,
2868
- account extends Account | undefined,
2869
- >(
2870
- client: Client<Transport, chain, account>,
2871
- parameters: setRoleAdmin.Parameters<chain, account>,
2872
- ): Promise<setRoleAdmin.ReturnValue> {
2873
- return setRoleAdmin.inner(writeContract, client, parameters)
2874
- }
2875
-
2876
- export namespace setRoleAdmin {
2877
- export type Parameters<
2878
- chain extends Chain | undefined = Chain | undefined,
2879
- account extends Account | undefined = Account | undefined,
2880
- > = WriteParameters<chain, account> & Args
2881
-
2882
- export type Args = {
2883
- /** New admin role. */
2884
- adminRole: TokenRole.TokenRole
2885
- /** Role to set admin for. */
2886
- role: TokenRole.TokenRole
2887
- /** Address or ID of the TIP20 token. */
2888
- token: TokenId.TokenIdOrAddress
2889
- }
2890
-
2891
- export type ReturnValue = WriteContractReturnType
2892
-
2893
- // TODO: exhaustive error type
2894
- export type ErrorType = BaseErrorType
2895
-
2896
- /** @internal */
2897
- export async function inner<
2898
- action extends typeof writeContract | typeof writeContractSync,
2899
- chain extends Chain | undefined,
2900
- account extends Account | undefined,
2901
- >(
2902
- action: action,
2903
- client: Client<Transport, chain, account>,
2904
- parameters: setRoleAdmin.Parameters<chain, account>,
2905
- ): Promise<ReturnType<action>> {
2906
- const { adminRole, role, token, ...rest } = parameters
2907
- const call = setRoleAdmin.call({ adminRole, role, token })
2908
- return (await action(client, {
2909
- ...rest,
2910
- ...call,
2911
- } as never)) as never
2912
- }
2913
-
2914
- /**
2915
- * Defines a call to the `setRoleAdmin` function.
2916
- *
2917
- * Can be passed as a parameter to:
2918
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
2919
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
2920
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
2921
- *
2922
- * @example
2923
- * ```ts
2924
- * import { createClient, http, walletActions } from 'viem'
2925
- * import { tempo } from 'tempo.ts/chains'
2926
- * import { Actions } from 'tempo.ts/viem'
2927
- *
2928
- * const client = createClient({
2929
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2930
- * transport: http(),
2931
- * }).extend(walletActions)
2932
- *
2933
- * const { result } = await client.sendCalls({
2934
- * calls: [
2935
- * actions.token.setRoleAdmin.call({
2936
- * token: '0x20c0...babe',
2937
- * role: 'issuer',
2938
- * adminRole: 'admin',
2939
- * }),
2940
- * ]
2941
- * })
2942
- * ```
2943
- *
2944
- * @param args - Arguments.
2945
- * @returns The call.
2946
- */
2947
- export function call(args: Args) {
2948
- const { token, role, adminRole } = args
2949
- const roleHash = TokenRole.serialize(role)
2950
- const adminRoleHash = TokenRole.serialize(adminRole)
2951
- return defineCall({
2952
- address: TokenId.toAddress(token),
2953
- abi: Abis.tip20,
2954
- functionName: 'setRoleAdmin',
2955
- args: [roleHash, adminRoleHash],
2956
- })
2957
- }
2958
-
2959
- /**
2960
- * Extracts the event from the logs.
2961
- *
2962
- * @param logs - Logs.
2963
- * @returns The event.
2964
- */
2965
- export function extractEvent(logs: Log[]) {
2966
- const [log] = parseEventLogs({
2967
- abi: Abis.tip20,
2968
- logs,
2969
- eventName: 'RoleAdminUpdated',
2970
- })
2971
- if (!log) throw new Error('`RoleAdminUpdated` event not found.')
2972
- return log
2973
- }
2974
- }
2975
-
2976
- /**
2977
- * Sets the admin role for a specific role in a TIP20 token.
2978
- *
2979
- * @example
2980
- * ```ts
2981
- * import { createClient, http } from 'viem'
2982
- * import { tempo } from 'tempo.ts/chains'
2983
- * import { Actions } from 'tempo.ts/viem'
2984
- * import { privateKeyToAccount } from 'viem/accounts'
2985
- *
2986
- * const client = createClient({
2987
- * account: privateKeyToAccount('0x...'),
2988
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
2989
- * transport: http(),
2990
- * })
2991
- *
2992
- * const result = await Actions.token.setRoleAdminSync(client, {
2993
- * token: '0x...',
2994
- * role: 'issuer',
2995
- * adminRole: 'admin',
2996
- * })
2997
- * ```
2998
- *
2999
- * @param client - Client.
3000
- * @param parameters - Parameters.
3001
- * @returns The transaction receipt and event data.
3002
- */
3003
- export async function setRoleAdminSync<
3004
- chain extends Chain | undefined,
3005
- account extends Account | undefined,
3006
- >(
3007
- client: Client<Transport, chain, account>,
3008
- parameters: setRoleAdminSync.Parameters<chain, account>,
3009
- ): Promise<setRoleAdminSync.ReturnValue> {
3010
- const { throwOnReceiptRevert = true, ...rest } = parameters
3011
- const receipt = await setRoleAdmin.inner(writeContractSync, client, {
3012
- ...rest,
3013
- throwOnReceiptRevert,
3014
- } as never)
3015
- const { args } = setRoleAdmin.extractEvent(receipt.logs)
3016
- return {
3017
- ...args,
3018
- receipt,
3019
- } as never
3020
- }
3021
-
3022
- export namespace setRoleAdminSync {
3023
- export type Parameters<
3024
- chain extends Chain | undefined = Chain | undefined,
3025
- account extends Account | undefined = Account | undefined,
3026
- > = setRoleAdmin.Parameters<chain, account>
3027
-
3028
- export type Args = setRoleAdmin.Args
3029
-
3030
- export type ReturnValue = GetEventArgs<
3031
- typeof Abis.tip20,
3032
- 'RoleAdminUpdated',
3033
- { IndexedOnly: false; Required: true }
3034
- > & {
3035
- receipt: TransactionReceipt
3036
- }
3037
-
3038
- // TODO: exhaustive error type
3039
- export type ErrorType = BaseErrorType
3040
- }
3041
-
3042
- /**
3043
- * Transfers TIP20 tokens to another address.
3044
- *
3045
- * @example
3046
- * ```ts
3047
- * import { createClient, http } from 'viem'
3048
- * import { tempo } from 'tempo.ts/chains'
3049
- * import { Actions } from 'tempo.ts/viem'
3050
- * import { privateKeyToAccount } from 'viem/accounts'
3051
- *
3052
- * const client = createClient({
3053
- * account: privateKeyToAccount('0x...'),
3054
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3055
- * transport: http(),
3056
- * })
3057
- *
3058
- * const result = await Actions.token.transfer(client, {
3059
- * to: '0x...',
3060
- * amount: 100n,
3061
- * })
3062
- * ```
3063
- *
3064
- * @param client - Client.
3065
- * @param parameters - Parameters.
3066
- * @returns The transaction hash.
3067
- */
3068
- export async function transfer<
3069
- chain extends Chain | undefined,
3070
- account extends Account | undefined,
3071
- >(
3072
- client: Client<Transport, chain, account>,
3073
- parameters: transfer.Parameters<chain, account>,
3074
- ): Promise<transfer.ReturnValue> {
3075
- return transfer.inner(writeContract, client, parameters)
3076
- }
3077
-
3078
- export namespace transfer {
3079
- export type Parameters<
3080
- chain extends Chain | undefined = Chain | undefined,
3081
- account extends Account | undefined = Account | undefined,
3082
- > = WriteParameters<chain, account> & Args
3083
-
3084
- export type Args = {
3085
- /** Amount of tokens to transfer. */
3086
- amount: bigint
3087
- /** Address to transfer tokens from. */
3088
- from?: Address | undefined
3089
- /** Memo to include in the transfer. */
3090
- memo?: Hex.Hex | undefined
3091
- /** Address or ID of the TIP20 token. */
3092
- token: TokenId.TokenIdOrAddress
3093
- /** Address to transfer tokens to. */
3094
- to: Address
3095
- }
3096
-
3097
- export type ReturnValue = WriteContractReturnType
3098
-
3099
- // TODO: exhaustive error type
3100
- export type ErrorType = BaseErrorType
3101
-
3102
- /** @internal */
3103
- export async function inner<
3104
- action extends typeof writeContract | typeof writeContractSync,
3105
- chain extends Chain | undefined,
3106
- account extends Account | undefined,
3107
- >(
3108
- action: action,
3109
- client: Client<Transport, chain, account>,
3110
- parameters: transfer.Parameters<chain, account>,
3111
- ): Promise<ReturnType<action>> {
3112
- const { amount, from, memo, token, to, ...rest } = parameters
3113
- const call = transfer.call({ amount, from, memo, token, to })
3114
- return (await action(client, {
3115
- ...rest,
3116
- ...call,
3117
- } as never)) as never
3118
- }
3119
-
3120
- /**
3121
- * Defines a call to the `transfer`, `transferFrom`, `transferWithMemo`, or `transferFromWithMemo` function.
3122
- *
3123
- * Can be passed as a parameter to:
3124
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
3125
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
3126
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
3127
- *
3128
- * @example
3129
- * ```ts
3130
- * import { createClient, http, walletActions } from 'viem'
3131
- * import { tempo } from 'tempo.ts/chains'
3132
- * import { Actions } from 'tempo.ts/viem'
3133
- *
3134
- * const client = createClient({
3135
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3136
- * transport: http(),
3137
- * }).extend(walletActions)
3138
- *
3139
- * const { result } = await client.sendCalls({
3140
- * calls: [
3141
- * actions.token.transfer.call({
3142
- * to: '0x20c0...beef',
3143
- * amount: 100n,
3144
- * token: '0x20c0...babe',
3145
- * }),
3146
- * ]
3147
- * })
3148
- * ```
3149
- *
3150
- * @param args - Arguments.
3151
- * @returns The call.
3152
- */
3153
- export function call(args: Args) {
3154
- const { amount, from, memo, token, to } = args
3155
- const callArgs = (() => {
3156
- if (memo && from)
3157
- return {
3158
- functionName: 'transferFromWithMemo',
3159
- args: [from, to, amount, Hex.padLeft(memo, 32)],
3160
- } as const
3161
- if (memo)
3162
- return {
3163
- functionName: 'transferWithMemo',
3164
- args: [to, amount, Hex.padLeft(memo, 32)],
3165
- } as const
3166
- if (from)
3167
- return {
3168
- functionName: 'transferFrom',
3169
- args: [from, to, amount],
3170
- } as const
3171
- return {
3172
- functionName: 'transfer',
3173
- args: [to, amount],
3174
- } as const
3175
- })()
3176
- return defineCall({
3177
- address: TokenId.toAddress(token),
3178
- abi: Abis.tip20,
3179
- ...callArgs,
3180
- })
3181
- }
3182
-
3183
- /**
3184
- * Extracts the event from the logs.
3185
- *
3186
- * @param logs - Logs.
3187
- * @returns The event.
3188
- */
3189
- export function extractEvent(logs: Log[]) {
3190
- const [log] = parseEventLogs({
3191
- abi: Abis.tip20,
3192
- logs,
3193
- eventName: 'Transfer',
3194
- })
3195
- if (!log) throw new Error('`Transfer` event not found.')
3196
- return log
3197
- }
3198
- }
3199
-
3200
- /**
3201
- * Transfers TIP20 tokens to another address.
3202
- *
3203
- * @example
3204
- * ```ts
3205
- * import { createClient, http } from 'viem'
3206
- * import { tempo } from 'tempo.ts/chains'
3207
- * import { Actions } from 'tempo.ts/viem'
3208
- * import { privateKeyToAccount } from 'viem/accounts'
3209
- *
3210
- * const client = createClient({
3211
- * account: privateKeyToAccount('0x...'),
3212
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3213
- * transport: http(),
3214
- * })
3215
- *
3216
- * const result = await Actions.token.transferSync(client, {
3217
- * to: '0x...',
3218
- * amount: 100n,
3219
- * })
3220
- * ```
3221
- *
3222
- * @param client - Client.
3223
- * @param parameters - Parameters.
3224
- * @returns The transaction receipt and event data.
3225
- */
3226
- export async function transferSync<
3227
- chain extends Chain | undefined,
3228
- account extends Account | undefined,
3229
- >(
3230
- client: Client<Transport, chain, account>,
3231
- parameters: transferSync.Parameters<chain, account>,
3232
- ): Promise<transferSync.ReturnValue> {
3233
- const { throwOnReceiptRevert = true, ...rest } = parameters
3234
- const receipt = await transfer.inner(writeContractSync, client, {
3235
- ...rest,
3236
- throwOnReceiptRevert,
3237
- } as never)
3238
- const { args } = transfer.extractEvent(receipt.logs)
3239
- return {
3240
- ...args,
3241
- receipt,
3242
- } as never
3243
- }
3244
-
3245
- export namespace transferSync {
3246
- export type Parameters<
3247
- chain extends Chain | undefined = Chain | undefined,
3248
- account extends Account | undefined = Account | undefined,
3249
- > = transfer.Parameters<chain, account>
3250
-
3251
- export type Args = transfer.Args
3252
-
3253
- export type ReturnValue = GetEventArgs<
3254
- typeof Abis.tip20,
3255
- 'Transfer',
3256
- { IndexedOnly: false; Required: true }
3257
- > & {
3258
- receipt: TransactionReceipt
3259
- }
3260
-
3261
- // TODO: exhaustive error type
3262
- export type ErrorType = BaseErrorType
3263
- }
3264
-
3265
- /**
3266
- * Unpauses a TIP20 token.
3267
- *
3268
- * @example
3269
- * ```ts
3270
- * import { createClient, http } from 'viem'
3271
- * import { tempo } from 'tempo.ts/chains'
3272
- * import { Actions } from 'tempo.ts/viem'
3273
- * import { privateKeyToAccount } from 'viem/accounts'
3274
- *
3275
- * const client = createClient({
3276
- * account: privateKeyToAccount('0x...'),
3277
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3278
- * transport: http(),
3279
- * })
3280
- *
3281
- * const result = await Actions.token.unpause(client, {
3282
- * token: '0x...',
3283
- * })
3284
- * ```
3285
- *
3286
- * @param client - Client.
3287
- * @param parameters - Parameters.
3288
- * @returns The transaction hash.
3289
- */
3290
- export async function unpause<
3291
- chain extends Chain | undefined,
3292
- account extends Account | undefined,
3293
- >(
3294
- client: Client<Transport, chain, account>,
3295
- parameters: unpause.Parameters<chain, account>,
3296
- ): Promise<unpause.ReturnValue> {
3297
- return unpause.inner(writeContract, client, parameters)
3298
- }
3299
-
3300
- export namespace unpause {
3301
- export type Parameters<
3302
- chain extends Chain | undefined = Chain | undefined,
3303
- account extends Account | undefined = Account | undefined,
3304
- > = WriteParameters<chain, account> & Args
3305
-
3306
- export type Args = {
3307
- /** Address or ID of the TIP20 token. */
3308
- token: TokenId.TokenIdOrAddress
3309
- }
3310
-
3311
- export type ReturnValue = WriteContractReturnType
3312
-
3313
- // TODO: exhaustive error type
3314
- export type ErrorType = BaseErrorType
3315
-
3316
- /** @internal */
3317
- export async function inner<
3318
- action extends typeof writeContract | typeof writeContractSync,
3319
- chain extends Chain | undefined,
3320
- account extends Account | undefined,
3321
- >(
3322
- action: action,
3323
- client: Client<Transport, chain, account>,
3324
- parameters: unpause.Parameters<chain, account>,
3325
- ): Promise<ReturnType<action>> {
3326
- const { token, ...rest } = parameters
3327
- const call = unpause.call({ token })
3328
- return (await action(client, {
3329
- ...rest,
3330
- ...call,
3331
- } as never)) as never
3332
- }
3333
-
3334
- /**
3335
- * Defines a call to the `unpause` function.
3336
- *
3337
- * Can be passed as a parameter to:
3338
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
3339
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
3340
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
3341
- *
3342
- * @example
3343
- * ```ts
3344
- * import { createClient, http, walletActions } from 'viem'
3345
- * import { tempo } from 'tempo.ts/chains'
3346
- * import { Actions } from 'tempo.ts/viem'
3347
- *
3348
- * const client = createClient({
3349
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3350
- * transport: http(),
3351
- * }).extend(walletActions)
3352
- *
3353
- * const { result } = await client.sendCalls({
3354
- * calls: [
3355
- * actions.token.unpause.call({
3356
- * token: '0x20c0...babe',
3357
- * }),
3358
- * ]
3359
- * })
3360
- * ```
3361
- *
3362
- * @param args - Arguments.
3363
- * @returns The call.
3364
- */
3365
- export function call(args: Args) {
3366
- const { token } = args
3367
- return defineCall({
3368
- address: TokenId.toAddress(token),
3369
- abi: Abis.tip20,
3370
- functionName: 'unpause',
3371
- args: [],
3372
- })
3373
- }
3374
-
3375
- /**
3376
- * Extracts the event from the logs.
3377
- *
3378
- * @param logs - Logs.
3379
- * @returns The event.
3380
- */
3381
- export function extractEvent(logs: Log[]) {
3382
- const [log] = parseEventLogs({
3383
- abi: Abis.tip20,
3384
- logs,
3385
- eventName: 'PauseStateUpdate',
3386
- })
3387
- if (!log) throw new Error('`PauseStateUpdate` event not found.')
3388
- return log
3389
- }
3390
- }
3391
-
3392
- /**
3393
- * Unpauses a TIP20 token.
3394
- *
3395
- * @example
3396
- * ```ts
3397
- * import { createClient, http } from 'viem'
3398
- * import { tempo } from 'tempo.ts/chains'
3399
- * import { Actions } from 'tempo.ts/viem'
3400
- * import { privateKeyToAccount } from 'viem/accounts'
3401
- *
3402
- * const client = createClient({
3403
- * account: privateKeyToAccount('0x...'),
3404
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3405
- * transport: http(),
3406
- * })
3407
- *
3408
- * const result = await Actions.token.unpauseSync(client, {
3409
- * token: '0x...',
3410
- * })
3411
- * ```
3412
- *
3413
- * @param client - Client.
3414
- * @param parameters - Parameters.
3415
- * @returns The transaction receipt and event data.
3416
- */
3417
- export async function unpauseSync<
3418
- chain extends Chain | undefined,
3419
- account extends Account | undefined,
3420
- >(
3421
- client: Client<Transport, chain, account>,
3422
- parameters: unpauseSync.Parameters<chain, account>,
3423
- ): Promise<unpauseSync.ReturnValue> {
3424
- const { throwOnReceiptRevert = true, ...rest } = parameters
3425
- const receipt = await unpause.inner(writeContractSync, client, {
3426
- ...rest,
3427
- throwOnReceiptRevert,
3428
- } as never)
3429
- const { args } = unpause.extractEvent(receipt.logs)
3430
- return {
3431
- ...args,
3432
- receipt,
3433
- } as never
3434
- }
3435
-
3436
- export namespace unpauseSync {
3437
- export type Parameters<
3438
- chain extends Chain | undefined = Chain | undefined,
3439
- account extends Account | undefined = Account | undefined,
3440
- > = unpause.Parameters<chain, account>
3441
-
3442
- export type Args = unpause.Args
3443
-
3444
- export type ReturnValue = GetEventArgs<
3445
- typeof Abis.tip20,
3446
- 'PauseStateUpdate',
3447
- { IndexedOnly: false; Required: true }
3448
- > & {
3449
- receipt: TransactionReceipt
3450
- }
3451
-
3452
- // TODO: exhaustive error type
3453
- export type ErrorType = BaseErrorType
3454
- }
3455
-
3456
- /**
3457
- * Updates the quote token for a TIP20 token.
3458
- *
3459
- * @example
3460
- * ```ts
3461
- * import { createClient, http } from 'viem'
3462
- * import { tempo } from 'tempo.ts/chains'
3463
- * import { Actions } from 'tempo.ts/viem'
3464
- * import { privateKeyToAccount } from 'viem/accounts'
3465
- *
3466
- * const client = createClient({
3467
- * account: privateKeyToAccount('0x...'),
3468
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3469
- * transport: http(),
3470
- * })
3471
- *
3472
- * const result = await Actions.token.prepareUpdateQuoteToken(client, {
3473
- * token: '0x...',
3474
- * quoteToken: '0x...',
3475
- * })
3476
- * ```
3477
- *
3478
- * @param client - Client.
3479
- * @param parameters - Parameters.
3480
- * @returns The transaction hash.
3481
- */
3482
- export async function prepareUpdateQuoteToken<
3483
- chain extends Chain | undefined,
3484
- account extends Account | undefined,
3485
- >(
3486
- client: Client<Transport, chain, account>,
3487
- parameters: prepareUpdateQuoteToken.Parameters<chain, account>,
3488
- ): Promise<prepareUpdateQuoteToken.ReturnValue> {
3489
- return prepareUpdateQuoteToken.inner(writeContract, client, parameters)
3490
- }
3491
-
3492
- export namespace prepareUpdateQuoteToken {
3493
- export type Parameters<
3494
- chain extends Chain | undefined = Chain | undefined,
3495
- account extends Account | undefined = Account | undefined,
3496
- > = WriteParameters<chain, account> & Args
3497
-
3498
- export type Args = {
3499
- /** New quote token address. */
3500
- quoteToken: TokenId.TokenIdOrAddress
3501
- /** Address or ID of the TIP20 token. */
3502
- token: TokenId.TokenIdOrAddress
3503
- }
3504
-
3505
- export type ReturnValue = WriteContractReturnType
3506
-
3507
- // TODO: exhaustive error type
3508
- export type ErrorType = BaseErrorType
3509
-
3510
- /** @internal */
3511
- export async function inner<
3512
- action extends typeof writeContract | typeof writeContractSync,
3513
- chain extends Chain | undefined,
3514
- account extends Account | undefined,
3515
- >(
3516
- action: action,
3517
- client: Client<Transport, chain, account>,
3518
- parameters: prepareUpdateQuoteToken.Parameters<chain, account>,
3519
- ): Promise<ReturnType<action>> {
3520
- const { quoteToken, token, ...rest } = parameters
3521
- const call = prepareUpdateQuoteToken.call({ quoteToken, token })
3522
- return (await action(client, {
3523
- ...rest,
3524
- ...call,
3525
- } as never)) as never
3526
- }
3527
-
3528
- /**
3529
- * Defines a call to the `prepareUpdateQuoteToken` function.
3530
- *
3531
- * Can be passed as a parameter to:
3532
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
3533
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
3534
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
3535
- *
3536
- * @example
3537
- * ```ts
3538
- * import { createClient, http, walletActions } from 'viem'
3539
- * import { tempo } from 'tempo.ts/chains'
3540
- * import { Actions } from 'tempo.ts/viem'
3541
- *
3542
- * const client = createClient({
3543
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3544
- * transport: http(),
3545
- * }).extend(walletActions)
3546
- *
3547
- * const { result } = await client.sendCalls({
3548
- * calls: [
3549
- * actions.token.prepareUpdateQuoteToken.call({
3550
- * token: '0x20c0...babe',
3551
- * quoteToken: '0x20c0...cafe',
3552
- * }),
3553
- * ]
3554
- * })
3555
- * ```
3556
- *
3557
- * @param args - Arguments.
3558
- * @returns The call.
3559
- */
3560
- export function call(args: Args) {
3561
- const { token, quoteToken } = args
3562
- return defineCall({
3563
- address: TokenId.toAddress(token),
3564
- abi: Abis.tip20,
3565
- functionName: 'setNextQuoteToken',
3566
- args: [TokenId.toAddress(quoteToken)],
3567
- })
3568
- }
3569
-
3570
- /**
3571
- * Extracts the event from the logs.
3572
- *
3573
- * @param logs - Logs.
3574
- * @returns The event.
3575
- */
3576
- export function extractEvent(logs: Log[]) {
3577
- const [log] = parseEventLogs({
3578
- abi: Abis.tip20,
3579
- logs,
3580
- eventName: 'NextQuoteTokenSet',
3581
- })
3582
- if (!log) throw new Error('`NextQuoteTokenSet` event not found.')
3583
- return log
3584
- }
3585
- }
3586
-
3587
- /**
3588
- * Updates the quote token for a TIP20 token.
3589
- *
3590
- * @example
3591
- * ```ts
3592
- * import { createClient, http } from 'viem'
3593
- * import { tempo } from 'tempo.ts/chains'
3594
- * import { Actions } from 'tempo.ts/viem'
3595
- * import { privateKeyToAccount } from 'viem/accounts'
3596
- *
3597
- * const client = createClient({
3598
- * account: privateKeyToAccount('0x...'),
3599
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3600
- * transport: http(),
3601
- * })
3602
- *
3603
- * const result = await Actions.token.prepareUpdateQuoteTokenSync(client, {
3604
- * token: '0x...',
3605
- * quoteToken: '0x...',
3606
- * })
3607
- * ```
3608
- *
3609
- * @param client - Client.
3610
- * @param parameters - Parameters.
3611
- * @returns The transaction receipt and event data.
3612
- */
3613
- export async function prepareUpdateQuoteTokenSync<
3614
- chain extends Chain | undefined,
3615
- account extends Account | undefined,
3616
- >(
3617
- client: Client<Transport, chain, account>,
3618
- parameters: prepareUpdateQuoteTokenSync.Parameters<chain, account>,
3619
- ): Promise<prepareUpdateQuoteTokenSync.ReturnValue> {
3620
- const receipt = await prepareUpdateQuoteToken.inner(
3621
- writeContractSync,
3622
- client,
3623
- parameters,
3624
- )
3625
- const { args } = prepareUpdateQuoteToken.extractEvent(receipt.logs)
3626
- return {
3627
- ...args,
3628
- receipt,
3629
- } as never
3630
- }
3631
-
3632
- export namespace prepareUpdateQuoteTokenSync {
3633
- export type Parameters<
3634
- chain extends Chain | undefined = Chain | undefined,
3635
- account extends Account | undefined = Account | undefined,
3636
- > = prepareUpdateQuoteToken.Parameters<chain, account>
3637
-
3638
- export type Args = prepareUpdateQuoteToken.Args
3639
-
3640
- export type ReturnValue = Compute<
3641
- GetEventArgs<
3642
- typeof Abis.tip20,
3643
- 'NextQuoteTokenSet',
3644
- {
3645
- IndexedOnly: false
3646
- Required: true
3647
- }
3648
- > & {
3649
- receipt: TransactionReceipt
3650
- }
3651
- >
3652
-
3653
- // TODO: exhaustive error type
3654
- export type ErrorType = BaseErrorType
3655
- }
3656
-
3657
- /**
3658
- * Updates the quote token for a TIP20 token.
3659
- *
3660
- * @example
3661
- * ```ts
3662
- * import { createClient, http } from 'viem'
3663
- * import { tempo } from 'tempo.ts/chains'
3664
- * import { Actions } from 'tempo.ts/viem'
3665
- * import { privateKeyToAccount } from 'viem/accounts'
3666
- *
3667
- * const client = createClient({
3668
- * account: privateKeyToAccount('0x...'),
3669
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3670
- * transport: http(),
3671
- * })
3672
- *
3673
- * const result = await Actions.token.updateQuoteToken(client, {
3674
- * token: '0x...',
3675
- * })
3676
- * ```
3677
- *
3678
- * @param client - Client.
3679
- * @param parameters - Parameters.
3680
- * @returns The transaction hash.
3681
- */
3682
- export async function updateQuoteToken<
3683
- chain extends Chain | undefined,
3684
- account extends Account | undefined,
3685
- >(
3686
- client: Client<Transport, chain, account>,
3687
- parameters: updateQuoteToken.Parameters<chain, account>,
3688
- ): Promise<updateQuoteToken.ReturnValue> {
3689
- return updateQuoteToken.inner(writeContract, client, parameters)
3690
- }
3691
-
3692
- export namespace updateQuoteToken {
3693
- export type Parameters<
3694
- chain extends Chain | undefined = Chain | undefined,
3695
- account extends Account | undefined = Account | undefined,
3696
- > = WriteParameters<chain, account> & Args
3697
-
3698
- export type Args = {
3699
- /** Address or ID of the TIP20 token. */
3700
- token: TokenId.TokenIdOrAddress
3701
- }
3702
-
3703
- export type ReturnValue = WriteContractReturnType
3704
-
3705
- // TODO: exhaustive error type
3706
- export type ErrorType = BaseErrorType
3707
-
3708
- /** @internal */
3709
- export async function inner<
3710
- action extends typeof writeContract | typeof writeContractSync,
3711
- chain extends Chain | undefined,
3712
- account extends Account | undefined,
3713
- >(
3714
- action: action,
3715
- client: Client<Transport, chain, account>,
3716
- parameters: updateQuoteToken.Parameters<chain, account>,
3717
- ): Promise<ReturnType<action>> {
3718
- const { token, ...rest } = parameters
3719
- const call = updateQuoteToken.call({ token })
3720
- return (await action(client, {
3721
- ...rest,
3722
- ...call,
3723
- } as never)) as never
3724
- }
3725
-
3726
- /**
3727
- * Defines a call to the `updateQuoteToken` function.
3728
- *
3729
- * Can be passed as a parameter to:
3730
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
3731
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
3732
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
3733
- *
3734
- * @example
3735
- * ```ts
3736
- * import { createClient, http, walletActions } from 'viem'
3737
- * import { tempo } from 'tempo.ts/chains'
3738
- * import { Actions } from 'tempo.ts/viem'
3739
- *
3740
- * const client = createClient({
3741
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3742
- * transport: http(),
3743
- * }).extend(walletActions)
3744
- *
3745
- * const { result } = await client.sendCalls({
3746
- * calls: [
3747
- * actions.token.updateQuoteToken.call({
3748
- * token: '0x20c0...babe',
3749
- * }),
3750
- * ]
3751
- * })
3752
- * ```
3753
- *
3754
- * @param args - Arguments.
3755
- * @returns The call.
3756
- */
3757
- export function call(args: Args) {
3758
- const { token } = args
3759
- return defineCall({
3760
- address: TokenId.toAddress(token),
3761
- abi: Abis.tip20,
3762
- functionName: 'completeQuoteTokenUpdate',
3763
- args: [],
3764
- })
3765
- }
3766
-
3767
- /**
3768
- * Extracts the event from the logs.
3769
- *
3770
- * @param logs - Logs.
3771
- * @returns The event.
3772
- */
3773
- export function extractEvent(logs: Log[]) {
3774
- const [log] = parseEventLogs({
3775
- abi: Abis.tip20,
3776
- logs,
3777
- eventName: 'QuoteTokenUpdate',
3778
- })
3779
- if (!log) throw new Error('`QuoteTokenUpdateCompleted` event not found.')
3780
- return log
3781
- }
3782
- }
3783
-
3784
- /**
3785
- * Updates the quote token for a TIP20 token.
3786
- *
3787
- * @example
3788
- * ```ts
3789
- * import { createClient, http } from 'viem'
3790
- * import { tempo } from 'tempo.ts/chains'
3791
- * import { Actions } from 'tempo.ts/viem'
3792
- * import { privateKeyToAccount } from 'viem/accounts'
3793
- *
3794
- * const client = createClient({
3795
- * account: privateKeyToAccount('0x...'),
3796
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3797
- * transport: http(),
3798
- * })
3799
- *
3800
- * const result = await Actions.token.updateQuoteTokenSync(client, {
3801
- * token: '0x...',
3802
- * })
3803
- * ```
3804
- *
3805
- * @param client - Client.
3806
- * @param parameters - Parameters.
3807
- * @returns The transaction receipt and event data.
3808
- */
3809
- export async function updateQuoteTokenSync<
3810
- chain extends Chain | undefined,
3811
- account extends Account | undefined,
3812
- >(
3813
- client: Client<Transport, chain, account>,
3814
- parameters: updateQuoteTokenSync.Parameters<chain, account>,
3815
- ): Promise<updateQuoteTokenSync.ReturnValue> {
3816
- const receipt = await updateQuoteToken.inner(
3817
- writeContractSync,
3818
- client,
3819
- parameters,
3820
- )
3821
- const { args } = updateQuoteToken.extractEvent(receipt.logs)
3822
- return {
3823
- ...args,
3824
- receipt,
3825
- } as never
3826
- }
3827
-
3828
- export namespace updateQuoteTokenSync {
3829
- export type Parameters<
3830
- chain extends Chain | undefined = Chain | undefined,
3831
- account extends Account | undefined = Account | undefined,
3832
- > = updateQuoteToken.Parameters<chain, account>
3833
-
3834
- export type Args = updateQuoteToken.Args
3835
-
3836
- export type ReturnValue = Compute<
3837
- GetEventArgs<
3838
- typeof Abis.tip20,
3839
- 'QuoteTokenUpdate',
3840
- {
3841
- IndexedOnly: false
3842
- Required: true
3843
- }
3844
- > & {
3845
- receipt: TransactionReceipt
3846
- }
3847
- >
3848
-
3849
- // TODO: exhaustive error type
3850
- export type ErrorType = BaseErrorType
3851
- }
3852
-
3853
- /**
3854
- * Watches for TIP20 token approval events.
3855
- *
3856
- * @example
3857
- * ```ts
3858
- * import { createClient, http } from 'viem'
3859
- * import { tempo } from 'tempo.ts/chains'
3860
- * import { Actions } from 'tempo.ts/viem'
3861
- *
3862
- * const client = createClient({
3863
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3864
- * transport: http(),
3865
- * })
3866
- *
3867
- * const unwatch = actions.token.watchApprove(client, {
3868
- * onApproval: (args, log) => {
3869
- * console.log('Approval:', args)
3870
- * },
3871
- * })
3872
- * ```
3873
- *
3874
- * @param client - Client.
3875
- * @param parameters - Parameters.
3876
- * @returns A function to unsubscribe from the event.
3877
- */
3878
- export function watchApprove<
3879
- chain extends Chain | undefined,
3880
- account extends Account | undefined,
3881
- >(
3882
- client: Client<Transport, chain, account>,
3883
- parameters: watchApprove.Parameters,
3884
- ) {
3885
- const { onApproval, token, ...rest } = parameters
3886
- return watchContractEvent(client, {
3887
- ...rest,
3888
- address: TokenId.toAddress(token),
3889
- abi: Abis.tip20,
3890
- eventName: 'Approval',
3891
- onLogs: (logs) => {
3892
- for (const log of logs) onApproval(log.args, log)
3893
- },
3894
- strict: true,
3895
- })
3896
- }
3897
-
3898
- export declare namespace watchApprove {
3899
- export type Args = GetEventArgs<
3900
- typeof Abis.tip20,
3901
- 'Approval',
3902
- { IndexedOnly: false; Required: true }
3903
- >
3904
-
3905
- export type Log = viem_Log<
3906
- bigint,
3907
- number,
3908
- false,
3909
- ExtractAbiItem<typeof Abis.tip20, 'Approval'>,
3910
- true
3911
- >
3912
-
3913
- export type Parameters = UnionOmit<
3914
- WatchContractEventParameters<typeof Abis.tip20, 'Approval', true>,
3915
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
3916
- > & {
3917
- /** Callback to invoke when tokens are approved. */
3918
- onApproval: (args: Args, log: Log) => void
3919
- /** Address or ID of the TIP20 token. */
3920
- token: TokenId.TokenIdOrAddress
3921
- }
3922
- }
3923
-
3924
- /**
3925
- * Watches for TIP20 token burn events.
3926
- *
3927
- * @example
3928
- * ```ts
3929
- * import { createClient, http } from 'viem'
3930
- * import { tempo } from 'tempo.ts/chains'
3931
- * import { Actions } from 'tempo.ts/viem'
3932
- *
3933
- * const client = createClient({
3934
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
3935
- * transport: http(),
3936
- * })
3937
- *
3938
- * const unwatch = actions.token.watchBurn(client, {
3939
- * onBurn: (args, log) => {
3940
- * console.log('Burn:', args)
3941
- * },
3942
- * })
3943
- * ```
3944
- *
3945
- * @param client - Client.
3946
- * @param parameters - Parameters.
3947
- * @returns A function to unsubscribe from the event.
3948
- */
3949
- export function watchBurn<
3950
- chain extends Chain | undefined,
3951
- account extends Account | undefined,
3952
- >(client: Client<Transport, chain, account>, parameters: watchBurn.Parameters) {
3953
- const { onBurn, token, ...rest } = parameters
3954
- return watchContractEvent(client, {
3955
- ...rest,
3956
- address: TokenId.toAddress(token),
3957
- abi: Abis.tip20,
3958
- eventName: 'Burn',
3959
- onLogs: (logs) => {
3960
- for (const log of logs) onBurn(log.args, log)
3961
- },
3962
- strict: true,
3963
- })
3964
- }
3965
-
3966
- export declare namespace watchBurn {
3967
- export type Args = GetEventArgs<
3968
- typeof Abis.tip20,
3969
- 'Burn',
3970
- { IndexedOnly: false; Required: true }
3971
- >
3972
-
3973
- export type Log = viem_Log<
3974
- bigint,
3975
- number,
3976
- false,
3977
- ExtractAbiItem<typeof Abis.tip20, 'Burn'>,
3978
- true
3979
- >
3980
-
3981
- export type Parameters = UnionOmit<
3982
- WatchContractEventParameters<typeof Abis.tip20, 'Burn', true>,
3983
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
3984
- > & {
3985
- /** Callback to invoke when tokens are burned. */
3986
- onBurn: (args: Args, log: Log) => void
3987
- /** Address or ID of the TIP20 token. */
3988
- token: TokenId.TokenIdOrAddress
3989
- }
3990
- }
3991
-
3992
- /**
3993
- * Watches for new TIP20 tokens created.
3994
- *
3995
- * @example
3996
- * ```ts
3997
- * import { createClient, http } from 'viem'
3998
- * import { tempo } from 'tempo.ts/chains'
3999
- * import { Actions } from 'tempo.ts/viem'
4000
- *
4001
- * const client = createClient({
4002
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
4003
- * transport: http(),
4004
- * })
4005
- *
4006
- * const unwatch = actions.token.watchCreate(client, {
4007
- * onTokenCreated: (args, log) => {
4008
- * console.log('Token created:', args)
4009
- * },
4010
- * })
4011
- * ```
4012
- *
4013
- * @param client - Client.
4014
- * @param parameters - Parameters.
4015
- * @returns A function to unsubscribe from the event.
4016
- */
4017
- export function watchCreate<
4018
- chain extends Chain | undefined,
4019
- account extends Account | undefined,
4020
- >(
4021
- client: Client<Transport, chain, account>,
4022
- parameters: watchCreate.Parameters,
4023
- ) {
4024
- const { onTokenCreated, ...rest } = parameters
4025
- return watchContractEvent(client, {
4026
- ...rest,
4027
- address: Addresses.tip20Factory,
4028
- abi: Abis.tip20Factory,
4029
- eventName: 'TokenCreated',
4030
- onLogs: (logs) => {
4031
- for (const log of logs) onTokenCreated(log.args, log)
4032
- },
4033
- strict: true,
4034
- })
4035
- }
4036
-
4037
- export declare namespace watchCreate {
4038
- export type Args = GetEventArgs<
4039
- typeof Abis.tip20Factory,
4040
- 'TokenCreated',
4041
- { IndexedOnly: false; Required: true }
4042
- >
4043
-
4044
- export type Log = viem_Log<
4045
- bigint,
4046
- number,
4047
- false,
4048
- ExtractAbiItem<typeof Abis.tip20Factory, 'TokenCreated'>,
4049
- true
4050
- >
4051
-
4052
- export type Parameters = UnionOmit<
4053
- WatchContractEventParameters<
4054
- typeof Abis.tip20Factory,
4055
- 'TokenCreated',
4056
- true
4057
- >,
4058
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
4059
- > & {
4060
- /** Callback to invoke when a new TIP20 token is created. */
4061
- onTokenCreated: (args: Args, log: Log) => void
4062
- }
4063
- }
4064
-
4065
- /**
4066
- * Watches for TIP20 token mint events.
4067
- *
4068
- * @example
4069
- * ```ts
4070
- * import { createClient, http } from 'viem'
4071
- * import { tempo } from 'tempo.ts/chains'
4072
- * import { Actions } from 'tempo.ts/viem'
4073
- *
4074
- * const client = createClient({
4075
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
4076
- * transport: http(),
4077
- * })
4078
- *
4079
- * const unwatch = actions.token.watchMint(client, {
4080
- * onMint: (args, log) => {
4081
- * console.log('Mint:', args)
4082
- * },
4083
- * })
4084
- * ```
4085
- *
4086
- * @param client - Client.
4087
- * @param parameters - Parameters.
4088
- * @returns A function to unsubscribe from the event.
4089
- */
4090
- export function watchMint<
4091
- chain extends Chain | undefined,
4092
- account extends Account | undefined,
4093
- >(client: Client<Transport, chain, account>, parameters: watchMint.Parameters) {
4094
- const { onMint, token, ...rest } = parameters
4095
- return watchContractEvent(client, {
4096
- ...rest,
4097
- address: TokenId.toAddress(token),
4098
- abi: Abis.tip20,
4099
- eventName: 'Mint',
4100
- onLogs: (logs) => {
4101
- for (const log of logs) onMint(log.args, log)
4102
- },
4103
- strict: true,
4104
- })
4105
- }
4106
-
4107
- export declare namespace watchMint {
4108
- export type Args = GetEventArgs<
4109
- typeof Abis.tip20,
4110
- 'Mint',
4111
- { IndexedOnly: false; Required: true }
4112
- >
4113
-
4114
- export type Log = viem_Log<
4115
- bigint,
4116
- number,
4117
- false,
4118
- ExtractAbiItem<typeof Abis.tip20, 'Mint'>,
4119
- true
4120
- >
4121
-
4122
- export type Parameters = UnionOmit<
4123
- WatchContractEventParameters<typeof Abis.tip20, 'Mint', true>,
4124
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
4125
- > & {
4126
- /** Callback to invoke when tokens are minted. */
4127
- onMint: (args: Args, log: Log) => void
4128
- /** Address or ID of the TIP20 token. */
4129
- token: TokenId.TokenIdOrAddress
4130
- }
4131
-
4132
- export type ReturnValue = WatchContractEventReturnType
4133
- }
4134
-
4135
- /**
4136
- * Watches for TIP20 token role admin updates.
4137
- *
4138
- * @example
4139
- * ```ts
4140
- * import { createClient, http } from 'viem'
4141
- * import { tempo } from 'tempo.ts/chains'
4142
- * import { Actions } from 'tempo.ts/viem'
4143
- *
4144
- * const client = createClient({
4145
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
4146
- * transport: http(),
4147
- * })
4148
- *
4149
- * const unwatch = actions.token.watchAdminRole(client, {
4150
- * onRoleAdminUpdated: (args, log) => {
4151
- * console.log('Role admin updated:', args)
4152
- * },
4153
- * })
4154
- * ```
4155
- *
4156
- * @param client - Client.
4157
- * @param parameters - Parameters.
4158
- * @returns A function to unsubscribe from the event.
4159
- */
4160
- export function watchAdminRole<
4161
- chain extends Chain | undefined,
4162
- account extends Account | undefined,
4163
- >(
4164
- client: Client<Transport, chain, account>,
4165
- parameters: watchAdminRole.Parameters,
4166
- ) {
4167
- const { onRoleAdminUpdated, token, ...rest } = parameters
4168
- return watchContractEvent(client, {
4169
- ...rest,
4170
- address: TokenId.toAddress(token),
4171
- abi: Abis.tip20,
4172
- eventName: 'RoleAdminUpdated',
4173
- onLogs: (logs) => {
4174
- for (const log of logs) onRoleAdminUpdated(log.args, log)
4175
- },
4176
- strict: true,
4177
- })
4178
- }
4179
-
4180
- export declare namespace watchAdminRole {
4181
- export type Args = GetEventArgs<
4182
- typeof Abis.tip20,
4183
- 'RoleAdminUpdated',
4184
- { IndexedOnly: false; Required: true }
4185
- >
4186
-
4187
- export type Log = viem_Log<
4188
- bigint,
4189
- number,
4190
- false,
4191
- ExtractAbiItem<typeof Abis.tip20, 'RoleAdminUpdated'>,
4192
- true
4193
- >
4194
-
4195
- export type Parameters = UnionOmit<
4196
- WatchContractEventParameters<typeof Abis.tip20, 'RoleAdminUpdated', true>,
4197
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
4198
- > & {
4199
- /** Callback to invoke when a role admin is updated. */
4200
- onRoleAdminUpdated: (args: Args, log: Log) => void
4201
- /** Address or ID of the TIP20 token. */
4202
- token: TokenId.TokenIdOrAddress
4203
- }
4204
- }
4205
-
4206
- /**
4207
- * Watches for TIP20 token role membership updates.
4208
- *
4209
- * @example
4210
- * ```ts
4211
- * import { createClient, http } from 'viem'
4212
- * import { tempo } from 'tempo.ts/chains'
4213
- * import { Actions } from 'tempo.ts/viem'
4214
- *
4215
- * const client = createClient({
4216
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
4217
- * transport: http(),
4218
- * })
4219
- *
4220
- * const unwatch = actions.token.watchRole(client, {
4221
- * onRoleUpdated: (args, log) => {
4222
- * console.log('Role updated:', args)
4223
- * },
4224
- * })
4225
- * ```
4226
- *
4227
- * @param client - Client.
4228
- * @param parameters - Parameters.
4229
- * @returns A function to unsubscribe from the event.
4230
- */
4231
- export function watchRole<
4232
- chain extends Chain | undefined,
4233
- account extends Account | undefined,
4234
- >(client: Client<Transport, chain, account>, parameters: watchRole.Parameters) {
4235
- const { onRoleUpdated, token, ...rest } = parameters
4236
- return watchContractEvent(client, {
4237
- ...rest,
4238
- address: TokenId.toAddress(token),
4239
- abi: Abis.tip20,
4240
- eventName: 'RoleMembershipUpdated',
4241
- onLogs: (logs) => {
4242
- for (const log of logs) {
4243
- const type = log.args.hasRole ? 'granted' : 'revoked'
4244
- onRoleUpdated({ ...log.args, type }, log)
4245
- }
4246
- },
4247
- strict: true,
4248
- })
4249
- }
4250
-
4251
- export declare namespace watchRole {
4252
- export type Args = GetEventArgs<
4253
- typeof Abis.tip20,
4254
- 'RoleMembershipUpdated',
4255
- { IndexedOnly: false; Required: true }
4256
- > & {
4257
- /** Type of role update. */
4258
- type: 'granted' | 'revoked'
4259
- }
4260
-
4261
- export type Log = viem_Log<
4262
- bigint,
4263
- number,
4264
- false,
4265
- ExtractAbiItem<typeof Abis.tip20, 'RoleMembershipUpdated'>,
4266
- true
4267
- >
4268
-
4269
- export type Parameters = UnionOmit<
4270
- WatchContractEventParameters<
4271
- typeof Abis.tip20,
4272
- 'RoleMembershipUpdated',
4273
- true
4274
- >,
4275
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
4276
- > & {
4277
- /** Callback to invoke when a role membership is updated. */
4278
- onRoleUpdated: (args: Args, log: Log) => void
4279
- /** Address or ID of the TIP20 token. */
4280
- token: TokenId.TokenIdOrAddress
4281
- }
4282
- }
4283
-
4284
- /**
4285
- * Watches for TIP20 token transfer events.
4286
- *
4287
- * @example
4288
- * ```ts
4289
- * import { createClient, http } from 'viem'
4290
- * import { tempo } from 'tempo.ts/chains'
4291
- * import { Actions } from 'tempo.ts/viem'
4292
- *
4293
- * const client = createClient({
4294
- * account: privateKeyToAccount('0x...'),
4295
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
4296
- * transport: http(),
4297
- * })
4298
- *
4299
- * const unwatch = actions.token.watchTransfer(client, {
4300
- * onTransfer: (args, log) => {
4301
- * console.log('Transfer:', args)
4302
- * },
4303
- * })
4304
- * ```
4305
- *
4306
- * @param client - Client.
4307
- * @param parameters - Parameters.
4308
- * @returns A function to unsubscribe from the event.
4309
- */
4310
- export function watchTransfer<
4311
- chain extends Chain | undefined,
4312
- account extends Account | undefined,
4313
- >(
4314
- client: Client<Transport, chain, account>,
4315
- parameters: watchTransfer.Parameters,
4316
- ) {
4317
- const { onTransfer, token, ...rest } = parameters
4318
- return watchContractEvent(client, {
4319
- ...rest,
4320
- address: TokenId.toAddress(token),
4321
- abi: Abis.tip20,
4322
- eventName: 'Transfer',
4323
- onLogs: (logs) => {
4324
- for (const log of logs) onTransfer(log.args, log)
4325
- },
4326
- strict: true,
4327
- })
4328
- }
4329
-
4330
- export declare namespace watchTransfer {
4331
- export type Args = GetEventArgs<
4332
- typeof Abis.tip20,
4333
- 'Transfer',
4334
- { IndexedOnly: false; Required: true }
4335
- >
4336
-
4337
- export type Log = viem_Log<
4338
- bigint,
4339
- number,
4340
- false,
4341
- ExtractAbiItem<typeof Abis.tip20, 'Transfer'>,
4342
- true
4343
- >
4344
-
4345
- export type Parameters = UnionOmit<
4346
- WatchContractEventParameters<typeof Abis.tip20, 'Transfer', true>,
4347
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
4348
- > & {
4349
- /** Callback to invoke when tokens are transferred. */
4350
- onTransfer: (args: Args, log: Log) => void
4351
- /** Address or ID of the TIP20 token. */
4352
- token: TokenId.TokenIdOrAddress
4353
- }
4354
- }
4355
-
4356
- /**
4357
- * Watches for TIP20 token quote token update events.
4358
- *
4359
- * @example
4360
- * ```ts
4361
- * import { createClient, http } from 'viem'
4362
- * import { tempo } from 'tempo.ts/chains'
4363
- * import { Actions } from 'tempo.ts/viem'
4364
- *
4365
- * const client = createClient({
4366
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
4367
- * transport: http(),
4368
- * })
4369
- *
4370
- * const unwatch = actions.token.watchUpdateQuoteToken(client, {
4371
- * onUpdateQuoteToken: (args, log) => {
4372
- * if (args.completed)
4373
- * console.log('quote token update completed:', args.newQuoteToken)
4374
- * else
4375
- * console.log('quote token update proposed:', args.newQuoteToken)
4376
- * },
4377
- * })
4378
- * ```
4379
- *
4380
- * @param client - Client.
4381
- * @param parameters - Parameters.
4382
- * @returns A function to unsubscribe from the event.
4383
- */
4384
- export function watchUpdateQuoteToken<
4385
- chain extends Chain | undefined,
4386
- account extends Account | undefined,
4387
- >(
4388
- client: Client<Transport, chain, account>,
4389
- parameters: watchUpdateQuoteToken.Parameters,
4390
- ) {
4391
- const { onUpdateQuoteToken, token, ...rest } = parameters
4392
- const address = TokenId.toAddress(token)
4393
-
4394
- return watchContractEvent(client, {
4395
- ...rest,
4396
- address,
4397
- abi: Abis.tip20,
4398
- onLogs: (
4399
- logs: viem_Log<
4400
- bigint,
4401
- number,
4402
- false,
4403
- ExtractAbiItem<
4404
- typeof Abis.tip20,
4405
- 'NextQuoteTokenSet' | 'QuoteTokenUpdate'
4406
- >,
4407
- true
4408
- >[],
4409
- ) => {
4410
- for (const log of logs) {
4411
- if (
4412
- log.eventName !== 'NextQuoteTokenSet' &&
4413
- log.eventName !== 'QuoteTokenUpdate'
4414
- )
4415
- continue
4416
-
4417
- onUpdateQuoteToken(
4418
- {
4419
- ...log.args,
4420
- completed: log.eventName === 'QuoteTokenUpdate',
4421
- },
4422
- log,
4423
- )
4424
- }
4425
- },
4426
- strict: true,
4427
- } as never)
4428
- }
4429
-
4430
- export declare namespace watchUpdateQuoteToken {
4431
- export type Args = OneOf<
4432
- | GetEventArgs<
4433
- typeof Abis.tip20,
4434
- 'NextQuoteTokenSet',
4435
- { IndexedOnly: false; Required: true }
4436
- >
4437
- | GetEventArgs<
4438
- typeof Abis.tip20,
4439
- 'QuoteTokenUpdate',
4440
- { IndexedOnly: false; Required: true }
4441
- >
4442
- > & {
4443
- /** Whether the update has been completed. */
4444
- completed: boolean
4445
- }
4446
-
4447
- export type Log = viem_Log
4448
-
4449
- export type Parameters = UnionOmit<
4450
- WatchContractEventParameters<typeof Abis.tip20, any, true>,
4451
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
4452
- > & {
4453
- /** Callback to invoke when a quote token update is proposed or completed. */
4454
- onUpdateQuoteToken: (args: Args, log: Log) => void
4455
- /** Address or ID of the TIP20 token. */
4456
- token: TokenId.TokenIdOrAddress
4457
- }
4458
- }