tempo.ts 0.0.0 → 0.0.2

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