viem 2.51.2 → 2.52.0

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 (73) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/_cjs/errors/version.js +1 -1
  3. package/_cjs/tempo/Abis.js +189 -1
  4. package/_cjs/tempo/Abis.js.map +1 -1
  5. package/_cjs/tempo/Account.js +27 -20
  6. package/_cjs/tempo/Account.js.map +1 -1
  7. package/_cjs/tempo/Addresses.js +3 -1
  8. package/_cjs/tempo/Addresses.js.map +1 -1
  9. package/_cjs/tempo/Decorator.js +23 -0
  10. package/_cjs/tempo/Decorator.js.map +1 -1
  11. package/_cjs/tempo/Hardfork.js +3 -0
  12. package/_cjs/tempo/Hardfork.js.map +1 -1
  13. package/_cjs/tempo/actions/accessKey.js +239 -72
  14. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  15. package/_cjs/tempo/actions/index.js +2 -1
  16. package/_cjs/tempo/actions/index.js.map +1 -1
  17. package/_cjs/tempo/actions/receivePolicy.js +363 -0
  18. package/_cjs/tempo/actions/receivePolicy.js.map +1 -0
  19. package/_cjs/tempo/index.js +2 -1
  20. package/_cjs/tempo/index.js.map +1 -1
  21. package/_esm/errors/version.js +1 -1
  22. package/_esm/tempo/Abis.js +188 -0
  23. package/_esm/tempo/Abis.js.map +1 -1
  24. package/_esm/tempo/Account.js +35 -20
  25. package/_esm/tempo/Account.js.map +1 -1
  26. package/_esm/tempo/Addresses.js +2 -0
  27. package/_esm/tempo/Addresses.js.map +1 -1
  28. package/_esm/tempo/Decorator.js +23 -0
  29. package/_esm/tempo/Decorator.js.map +1 -1
  30. package/_esm/tempo/Hardfork.js +3 -0
  31. package/_esm/tempo/Hardfork.js.map +1 -1
  32. package/_esm/tempo/actions/accessKey.js +562 -127
  33. package/_esm/tempo/actions/accessKey.js.map +1 -1
  34. package/_esm/tempo/actions/index.js +1 -0
  35. package/_esm/tempo/actions/index.js.map +1 -1
  36. package/_esm/tempo/actions/receivePolicy.js +753 -0
  37. package/_esm/tempo/actions/receivePolicy.js.map +1 -0
  38. package/_esm/tempo/index.js +1 -1
  39. package/_esm/tempo/index.js.map +1 -1
  40. package/_types/errors/version.d.ts +1 -1
  41. package/_types/tempo/Abis.d.ts +671 -4
  42. package/_types/tempo/Abis.d.ts.map +1 -1
  43. package/_types/tempo/Account.d.ts +13 -2
  44. package/_types/tempo/Account.d.ts.map +1 -1
  45. package/_types/tempo/Addresses.d.ts +2 -0
  46. package/_types/tempo/Addresses.d.ts.map +1 -1
  47. package/_types/tempo/Decorator.d.ts +501 -0
  48. package/_types/tempo/Decorator.d.ts.map +1 -1
  49. package/_types/tempo/Hardfork.d.ts +1 -1
  50. package/_types/tempo/Hardfork.d.ts.map +1 -1
  51. package/_types/tempo/actions/accessKey.d.ts +1520 -304
  52. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  53. package/_types/tempo/actions/dex.d.ts +75 -0
  54. package/_types/tempo/actions/dex.d.ts.map +1 -1
  55. package/_types/tempo/actions/index.d.ts +1 -0
  56. package/_types/tempo/actions/index.d.ts.map +1 -1
  57. package/_types/tempo/actions/policy.d.ts +352 -0
  58. package/_types/tempo/actions/policy.d.ts.map +1 -1
  59. package/_types/tempo/actions/receivePolicy.d.ts +1511 -0
  60. package/_types/tempo/actions/receivePolicy.d.ts.map +1 -0
  61. package/_types/tempo/index.d.ts +1 -1
  62. package/_types/tempo/index.d.ts.map +1 -1
  63. package/errors/version.ts +1 -1
  64. package/package.json +2 -2
  65. package/tempo/Abis.ts +189 -0
  66. package/tempo/Account.ts +56 -27
  67. package/tempo/Addresses.ts +2 -0
  68. package/tempo/Decorator.ts +578 -0
  69. package/tempo/Hardfork.ts +3 -0
  70. package/tempo/actions/accessKey.ts +1003 -279
  71. package/tempo/actions/index.ts +1 -0
  72. package/tempo/actions/receivePolicy.ts +1266 -0
  73. package/tempo/index.ts +1 -0
@@ -0,0 +1,753 @@
1
+ import { parseAccount } from '../../accounts/utils/parseAccount.js';
2
+ import { readContract } from '../../actions/public/readContract.js';
3
+ import { watchContractEvent } from '../../actions/public/watchContractEvent.js';
4
+ import { writeContract } from '../../actions/wallet/writeContract.js';
5
+ import { writeContractSync } from '../../actions/wallet/writeContractSync.js';
6
+ import { zeroAddress } from '../../constants/address.js';
7
+ import { parseEventLogs } from '../../utils/abi/parseEventLogs.js';
8
+ import { isAddressEqual } from '../../utils/index.js';
9
+ import * as Abis from '../Abis.js';
10
+ import * as Addresses from '../Addresses.js';
11
+ import { defineCall } from '../internal/utils.js';
12
+ /** @internal */
13
+ const policyTypes = ['whitelist', 'blacklist'];
14
+ /** @internal Built-in TIP-403 policy id that rejects everything. */
15
+ const rejectAllPolicyId = 0n;
16
+ /** @internal Built-in TIP-403 policy id that allows everything. */
17
+ const allowAllPolicyId = 1n;
18
+ /** @internal */
19
+ const blockedReasons = ['none', 'tokenFilter', 'receivePolicy'];
20
+ /**
21
+ * Burns the funds backing a blocked receipt.
22
+ *
23
+ * Requires the caller to hold the token's `BURN_BLOCKED_ROLE`, and is only
24
+ * valid when the receipt's policy subject is currently unauthorized as a sender
25
+ * under the token's TIP-403 policy.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { createClient, http } from 'viem'
30
+ * import { tempo } from 'viem/chains'
31
+ * import { Actions } from 'viem/tempo'
32
+ * import { privateKeyToAccount } from 'viem/accounts'
33
+ *
34
+ * const client = createClient({
35
+ * account: privateKeyToAccount('0x...'),
36
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
37
+ * transport: http(),
38
+ * })
39
+ *
40
+ * const hash = await Actions.receivePolicy.burn(client, {
41
+ * receipt: '0x...',
42
+ * })
43
+ * ```
44
+ *
45
+ * @param client - Client.
46
+ * @param parameters - Parameters.
47
+ * @returns The transaction hash.
48
+ */
49
+ export async function burn(client, parameters) {
50
+ return burn.inner(writeContract, client, parameters);
51
+ }
52
+ (function (burn) {
53
+ /** @internal */
54
+ async function inner(action, client, parameters) {
55
+ const { account = client.account, chain = client.chain, receipt, ...rest } = parameters;
56
+ if (!account)
57
+ throw new Error('`account` is required');
58
+ const call = burn.call({ receipt });
59
+ return action(client, {
60
+ ...rest,
61
+ account,
62
+ chain,
63
+ ...call,
64
+ });
65
+ }
66
+ burn.inner = inner;
67
+ /**
68
+ * Defines a call to the `burnBlockedReceipt` function.
69
+ *
70
+ * @param args - Arguments.
71
+ * @returns The call.
72
+ */
73
+ function call(args) {
74
+ const { receipt } = args;
75
+ return defineCall({
76
+ address: Addresses.receivePolicyGuard,
77
+ abi: Abis.receivePolicyGuard,
78
+ functionName: 'burnBlockedReceipt',
79
+ args: [receipt],
80
+ });
81
+ }
82
+ burn.call = call;
83
+ /**
84
+ * Extracts the `ReceiptBurned` event from logs.
85
+ *
86
+ * @param logs - The logs.
87
+ * @returns The `ReceiptBurned` event.
88
+ */
89
+ function extractEvent(logs) {
90
+ const [log] = parseEventLogs({
91
+ abi: Abis.receivePolicyGuard,
92
+ logs,
93
+ eventName: 'ReceiptBurned',
94
+ strict: true,
95
+ });
96
+ if (!log)
97
+ throw new Error('`ReceiptBurned` event not found.');
98
+ return log;
99
+ }
100
+ burn.extractEvent = extractEvent;
101
+ })(burn || (burn = {}));
102
+ /**
103
+ * Burns the funds backing a blocked receipt and waits for the receipt.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { createClient, http } from 'viem'
108
+ * import { tempo } from 'viem/chains'
109
+ * import { Actions } from 'viem/tempo'
110
+ * import { privateKeyToAccount } from 'viem/accounts'
111
+ *
112
+ * const client = createClient({
113
+ * account: privateKeyToAccount('0x...'),
114
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
115
+ * transport: http(),
116
+ * })
117
+ *
118
+ * const { receipt, ...result } = await Actions.receivePolicy.burnSync(client, {
119
+ * receipt: '0x...',
120
+ * })
121
+ * ```
122
+ *
123
+ * @param client - Client.
124
+ * @param parameters - Parameters.
125
+ * @returns The transaction receipt and event data.
126
+ */
127
+ export async function burnSync(client, parameters) {
128
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
129
+ const receipt = await burn.inner(writeContractSync, client, {
130
+ ...rest,
131
+ throwOnReceiptRevert,
132
+ });
133
+ const { args } = burn.extractEvent(receipt.logs);
134
+ return {
135
+ ...args,
136
+ receipt,
137
+ };
138
+ }
139
+ /**
140
+ * Claims blocked funds for a receipt, releasing them to a destination.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { createClient, http } from 'viem'
145
+ * import { tempo } from 'viem/chains'
146
+ * import { Actions } from 'viem/tempo'
147
+ * import { privateKeyToAccount } from 'viem/accounts'
148
+ *
149
+ * const client = createClient({
150
+ * account: privateKeyToAccount('0x...'),
151
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
152
+ * transport: http(),
153
+ * })
154
+ *
155
+ * const hash = await Actions.receivePolicy.claim(client, {
156
+ * to: '0x...',
157
+ * receipt: '0x...',
158
+ * })
159
+ * ```
160
+ *
161
+ * @param client - Client.
162
+ * @param parameters - Parameters.
163
+ * @returns The transaction hash.
164
+ */
165
+ export async function claim(client, parameters) {
166
+ return claim.inner(writeContract, client, parameters);
167
+ }
168
+ (function (claim) {
169
+ /** @internal */
170
+ async function inner(action, client, parameters) {
171
+ const { account = client.account, chain = client.chain, to, receipt, ...rest } = parameters;
172
+ if (!account)
173
+ throw new Error('`account` is required');
174
+ const call = claim.call({ to, receipt });
175
+ return action(client, {
176
+ ...rest,
177
+ account,
178
+ chain,
179
+ ...call,
180
+ });
181
+ }
182
+ claim.inner = inner;
183
+ /**
184
+ * Defines a call to the `claim` function.
185
+ *
186
+ * @param args - Arguments.
187
+ * @returns The call.
188
+ */
189
+ function call(args) {
190
+ const { to, receipt } = args;
191
+ return defineCall({
192
+ address: Addresses.receivePolicyGuard,
193
+ abi: Abis.receivePolicyGuard,
194
+ functionName: 'claim',
195
+ args: [to, receipt],
196
+ });
197
+ }
198
+ claim.call = call;
199
+ /**
200
+ * Extracts the `ReceiptClaimed` event from logs.
201
+ *
202
+ * @param logs - The logs.
203
+ * @returns The `ReceiptClaimed` event.
204
+ */
205
+ function extractEvent(logs) {
206
+ const [log] = parseEventLogs({
207
+ abi: Abis.receivePolicyGuard,
208
+ logs,
209
+ eventName: 'ReceiptClaimed',
210
+ strict: true,
211
+ });
212
+ if (!log)
213
+ throw new Error('`ReceiptClaimed` event not found.');
214
+ return log;
215
+ }
216
+ claim.extractEvent = extractEvent;
217
+ })(claim || (claim = {}));
218
+ /**
219
+ * Claims blocked funds for a receipt and waits for the receipt.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * import { createClient, http } from 'viem'
224
+ * import { tempo } from 'viem/chains'
225
+ * import { Actions } from 'viem/tempo'
226
+ * import { privateKeyToAccount } from 'viem/accounts'
227
+ *
228
+ * const client = createClient({
229
+ * account: privateKeyToAccount('0x...'),
230
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
231
+ * transport: http(),
232
+ * })
233
+ *
234
+ * const { receipt, ...result } = await Actions.receivePolicy.claimSync(client, {
235
+ * to: '0x...',
236
+ * receipt: '0x...',
237
+ * })
238
+ * ```
239
+ *
240
+ * @param client - Client.
241
+ * @param parameters - Parameters.
242
+ * @returns The transaction receipt and event data.
243
+ */
244
+ export async function claimSync(client, parameters) {
245
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
246
+ const receipt = await claim.inner(writeContractSync, client, {
247
+ ...rest,
248
+ throwOnReceiptRevert,
249
+ });
250
+ const { args } = claim.extractEvent(receipt.logs);
251
+ return {
252
+ ...args,
253
+ receipt,
254
+ };
255
+ }
256
+ /**
257
+ * Gets the receive policy configured for an account.
258
+ *
259
+ * @example
260
+ * ```ts
261
+ * import { createClient, http } from 'viem'
262
+ * import { tempo } from 'viem/chains'
263
+ * import { Actions } from 'viem/tempo'
264
+ *
265
+ * const client = createClient({
266
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
267
+ * transport: http(),
268
+ * })
269
+ *
270
+ * const policy = await Actions.receivePolicy.get(client, {
271
+ * account: '0x...',
272
+ * })
273
+ * ```
274
+ *
275
+ * @param client - Client.
276
+ * @param parameters - Parameters.
277
+ * @returns The receive policy.
278
+ */
279
+ export async function get(client, parameters) {
280
+ const { account: account_ = client.account, ...rest } = parameters;
281
+ if (!account_)
282
+ throw new Error('`account` is required.');
283
+ const account = parseAccount(account_);
284
+ const [hasReceivePolicy, senderPolicyId, senderPolicyType, tokenPolicyId, tokenPolicyType, recoveryAuthority,] = await readContract(client, {
285
+ ...rest,
286
+ account: null,
287
+ ...get.call({ account: account.address }),
288
+ });
289
+ return {
290
+ hasReceivePolicy,
291
+ senderPolicyId: toPolicyRef(senderPolicyId),
292
+ senderPolicyType: policyTypes[senderPolicyType] ?? 'whitelist',
293
+ tokenPolicyId: toPolicyRef(tokenPolicyId),
294
+ tokenPolicyType: policyTypes[tokenPolicyType] ?? 'whitelist',
295
+ claimer: toClaimer(recoveryAuthority, account.address),
296
+ recoveryAuthority,
297
+ };
298
+ }
299
+ (function (get) {
300
+ /**
301
+ * Defines a call to the `receivePolicy` function.
302
+ *
303
+ * @param args - Arguments.
304
+ * @returns The call.
305
+ */
306
+ function call(args) {
307
+ const { account } = args;
308
+ return defineCall({
309
+ address: Addresses.tip403Registry,
310
+ abi: Abis.tip403Registry,
311
+ functionName: 'receivePolicy',
312
+ args: [account],
313
+ });
314
+ }
315
+ get.call = call;
316
+ })(get || (get = {}));
317
+ /**
318
+ * Gets the blocked balance for an encoded receipt.
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * import { createClient, http } from 'viem'
323
+ * import { tempo } from 'viem/chains'
324
+ * import { Actions } from 'viem/tempo'
325
+ *
326
+ * const client = createClient({
327
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
328
+ * transport: http(),
329
+ * })
330
+ *
331
+ * const amount = await Actions.receivePolicy.getBlockedBalance(client, {
332
+ * receipt: '0x...',
333
+ * })
334
+ * ```
335
+ *
336
+ * @param client - Client.
337
+ * @param parameters - Parameters.
338
+ * @returns The blocked amount for the receipt.
339
+ */
340
+ export async function getBlockedBalance(client, parameters) {
341
+ const { receipt, ...rest } = parameters;
342
+ return readContract(client, {
343
+ ...rest,
344
+ ...getBlockedBalance.call({ receipt }),
345
+ });
346
+ }
347
+ (function (getBlockedBalance) {
348
+ /**
349
+ * Defines a call to the `balanceOf` function.
350
+ *
351
+ * @param args - Arguments.
352
+ * @returns The call.
353
+ */
354
+ function call(args) {
355
+ const { receipt } = args;
356
+ return defineCall({
357
+ address: Addresses.receivePolicyGuard,
358
+ abi: Abis.receivePolicyGuard,
359
+ functionName: 'balanceOf',
360
+ args: [receipt],
361
+ });
362
+ }
363
+ getBlockedBalance.call = call;
364
+ })(getBlockedBalance || (getBlockedBalance = {}));
365
+ /**
366
+ * Sets the receive policy for the calling account.
367
+ *
368
+ * A receive policy controls which TIP-20 tokens and which senders an account
369
+ * accepts. Inbound transfers and mints that violate the policy are not
370
+ * reverted – instead the funds are redirected to the `ReceivePolicyGuard` and
371
+ * can be reclaimed later (see {@link claim}).
372
+ *
373
+ * @example
374
+ * ```ts
375
+ * import { createClient, http } from 'viem'
376
+ * import { tempo } from 'viem/chains'
377
+ * import { Actions } from 'viem/tempo'
378
+ * import { privateKeyToAccount } from 'viem/accounts'
379
+ *
380
+ * const client = createClient({
381
+ * account: privateKeyToAccount('0x...'),
382
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
383
+ * transport: http(),
384
+ * })
385
+ *
386
+ * const hash = await Actions.receivePolicy.set(client, {
387
+ * senderPolicyId: 'allow-all',
388
+ * tokenPolicyId: 'allow-all',
389
+ * claimer: 'self',
390
+ * })
391
+ * ```
392
+ *
393
+ * @param client - Client.
394
+ * @param parameters - Parameters.
395
+ * @returns The transaction hash.
396
+ */
397
+ export async function set(client, parameters) {
398
+ return set.inner(writeContract, client, parameters);
399
+ }
400
+ (function (set) {
401
+ /** @internal */
402
+ async function inner(action, client, parameters) {
403
+ const { account = client.account, chain = client.chain, senderPolicyId = 'allow-all', tokenPolicyId = 'allow-all', claimer = 'sender', ...rest } = parameters;
404
+ if (!account)
405
+ throw new Error('`account` is required');
406
+ const address = parseAccount(account).address;
407
+ const recoveryAuthority = resolveClaimer(claimer, address);
408
+ const call = set.call({
409
+ senderPolicyId: resolvePolicyRef(senderPolicyId),
410
+ tokenFilterId: resolvePolicyRef(tokenPolicyId),
411
+ recoveryAuthority,
412
+ });
413
+ return action(client, {
414
+ ...rest,
415
+ account,
416
+ chain,
417
+ ...call,
418
+ });
419
+ }
420
+ set.inner = inner;
421
+ /**
422
+ * Defines a call to the `setReceivePolicy` function.
423
+ *
424
+ * @param args - Arguments.
425
+ * @returns The call.
426
+ */
427
+ function call(args) {
428
+ const { senderPolicyId, tokenFilterId, recoveryAuthority } = args;
429
+ return defineCall({
430
+ address: Addresses.tip403Registry,
431
+ abi: Abis.tip403Registry,
432
+ functionName: 'setReceivePolicy',
433
+ args: [senderPolicyId, tokenFilterId, recoveryAuthority],
434
+ });
435
+ }
436
+ set.call = call;
437
+ /**
438
+ * Extracts the `ReceivePolicyUpdated` event from logs.
439
+ *
440
+ * @param logs - The logs.
441
+ * @returns The `ReceivePolicyUpdated` event.
442
+ */
443
+ function extractEvent(logs) {
444
+ const [log] = parseEventLogs({
445
+ abi: Abis.tip403Registry,
446
+ logs,
447
+ eventName: 'ReceivePolicyUpdated',
448
+ strict: true,
449
+ });
450
+ if (!log)
451
+ throw new Error('`ReceivePolicyUpdated` event not found.');
452
+ return log;
453
+ }
454
+ set.extractEvent = extractEvent;
455
+ })(set || (set = {}));
456
+ /**
457
+ * Sets the receive policy for the calling account and waits for the receipt.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * import { createClient, http } from 'viem'
462
+ * import { tempo } from 'viem/chains'
463
+ * import { Actions } from 'viem/tempo'
464
+ * import { privateKeyToAccount } from 'viem/accounts'
465
+ *
466
+ * const client = createClient({
467
+ * account: privateKeyToAccount('0x...'),
468
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
469
+ * transport: http(),
470
+ * })
471
+ *
472
+ * const { receipt, ...result } = await Actions.receivePolicy.setSync(client, {
473
+ * senderPolicyId: 'allow-all',
474
+ * tokenPolicyId: 'allow-all',
475
+ * claimer: 'self',
476
+ * })
477
+ * ```
478
+ *
479
+ * @param client - Client.
480
+ * @param parameters - Parameters.
481
+ * @returns The transaction receipt and event data.
482
+ */
483
+ export async function setSync(client, parameters) {
484
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
485
+ const receipt = await set.inner(writeContractSync, client, {
486
+ ...rest,
487
+ throwOnReceiptRevert,
488
+ });
489
+ const { tokenFilterId, ...args } = set.extractEvent(receipt.logs).args;
490
+ return {
491
+ ...args,
492
+ senderPolicyId: toPolicyRef(args.senderPolicyId),
493
+ tokenPolicyId: toPolicyRef(tokenFilterId),
494
+ claimer: toClaimer(args.recoveryAuthority, args.account),
495
+ receipt,
496
+ };
497
+ }
498
+ /**
499
+ * Checks whether a transfer or mint to a receiver is allowed by the receiver's
500
+ * receive policy.
501
+ *
502
+ * @example
503
+ * ```ts
504
+ * import { createClient, http } from 'viem'
505
+ * import { tempo } from 'viem/chains'
506
+ * import { Actions } from 'viem/tempo'
507
+ *
508
+ * const client = createClient({
509
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
510
+ * transport: http(),
511
+ * })
512
+ *
513
+ * const { authorized, blockedReason } = await Actions.receivePolicy.validate(
514
+ * client,
515
+ * {
516
+ * token: '0x...',
517
+ * sender: '0x...',
518
+ * receiver: '0x...',
519
+ * },
520
+ * )
521
+ * ```
522
+ *
523
+ * @param client - Client.
524
+ * @param parameters - Parameters.
525
+ * @returns Whether the transfer is authorized and, if not, why.
526
+ */
527
+ export async function validate(client, parameters) {
528
+ const { token, sender, receiver, ...rest } = parameters;
529
+ const [authorized, blockedReason] = await readContract(client, {
530
+ ...rest,
531
+ ...validate.call({ token, sender, receiver }),
532
+ });
533
+ return {
534
+ authorized,
535
+ blockedReason: blockedReasons[blockedReason] ?? 'none',
536
+ };
537
+ }
538
+ (function (validate) {
539
+ /**
540
+ * Defines a call to the `validateReceivePolicy` function.
541
+ *
542
+ * @param args - Arguments.
543
+ * @returns The call.
544
+ */
545
+ function call(args) {
546
+ const { token, sender, receiver } = args;
547
+ return defineCall({
548
+ address: Addresses.tip403Registry,
549
+ abi: Abis.tip403Registry,
550
+ functionName: 'validateReceivePolicy',
551
+ args: [token, sender, receiver],
552
+ });
553
+ }
554
+ validate.call = call;
555
+ })(validate || (validate = {}));
556
+ /**
557
+ * Watches for blocked transfer events.
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * import { createClient, http } from 'viem'
562
+ * import { tempo } from 'viem/chains'
563
+ * import { Actions } from 'viem/tempo'
564
+ *
565
+ * const client = createClient({
566
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
567
+ * transport: http(),
568
+ * })
569
+ *
570
+ * const unwatch = Actions.receivePolicy.watchBlocked(client, {
571
+ * onBlocked: (args, log) => {
572
+ * console.log('Transfer blocked:', args)
573
+ * },
574
+ * })
575
+ * ```
576
+ *
577
+ * @param client - Client.
578
+ * @param parameters - Parameters.
579
+ * @returns A function to unsubscribe from the event.
580
+ */
581
+ export function watchBlocked(client, parameters) {
582
+ const { onBlocked, ...rest } = parameters;
583
+ return watchContractEvent(client, {
584
+ ...rest,
585
+ address: Addresses.receivePolicyGuard,
586
+ abi: Abis.receivePolicyGuard,
587
+ eventName: 'TransferBlocked',
588
+ onLogs: (logs) => {
589
+ for (const log of logs) {
590
+ const { receipt, ...args } = log.args;
591
+ onBlocked({ ...args, claimReceipt: receipt }, log);
592
+ }
593
+ },
594
+ strict: true,
595
+ });
596
+ }
597
+ /**
598
+ * Watches for receipt burned events.
599
+ *
600
+ * @example
601
+ * ```ts
602
+ * import { createClient, http } from 'viem'
603
+ * import { tempo } from 'viem/chains'
604
+ * import { Actions } from 'viem/tempo'
605
+ *
606
+ * const client = createClient({
607
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
608
+ * transport: http(),
609
+ * })
610
+ *
611
+ * const unwatch = Actions.receivePolicy.watchBurned(client, {
612
+ * onBurned: (args, log) => {
613
+ * console.log('Receipt burned:', args)
614
+ * },
615
+ * })
616
+ * ```
617
+ *
618
+ * @param client - Client.
619
+ * @param parameters - Parameters.
620
+ * @returns A function to unsubscribe from the event.
621
+ */
622
+ export function watchBurned(client, parameters) {
623
+ const { onBurned, ...rest } = parameters;
624
+ return watchContractEvent(client, {
625
+ ...rest,
626
+ address: Addresses.receivePolicyGuard,
627
+ abi: Abis.receivePolicyGuard,
628
+ eventName: 'ReceiptBurned',
629
+ onLogs: (logs) => {
630
+ for (const log of logs)
631
+ onBurned(log.args, log);
632
+ },
633
+ strict: true,
634
+ });
635
+ }
636
+ /**
637
+ * Watches for receipt claimed events.
638
+ *
639
+ * @example
640
+ * ```ts
641
+ * import { createClient, http } from 'viem'
642
+ * import { tempo } from 'viem/chains'
643
+ * import { Actions } from 'viem/tempo'
644
+ *
645
+ * const client = createClient({
646
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
647
+ * transport: http(),
648
+ * })
649
+ *
650
+ * const unwatch = Actions.receivePolicy.watchClaimed(client, {
651
+ * onClaimed: (args, log) => {
652
+ * console.log('Receipt claimed:', args)
653
+ * },
654
+ * })
655
+ * ```
656
+ *
657
+ * @param client - Client.
658
+ * @param parameters - Parameters.
659
+ * @returns A function to unsubscribe from the event.
660
+ */
661
+ export function watchClaimed(client, parameters) {
662
+ const { onClaimed, ...rest } = parameters;
663
+ return watchContractEvent(client, {
664
+ ...rest,
665
+ address: Addresses.receivePolicyGuard,
666
+ abi: Abis.receivePolicyGuard,
667
+ eventName: 'ReceiptClaimed',
668
+ onLogs: (logs) => {
669
+ for (const log of logs)
670
+ onClaimed(log.args, log);
671
+ },
672
+ strict: true,
673
+ });
674
+ }
675
+ /**
676
+ * Watches for receive policy update events.
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * import { createClient, http } from 'viem'
681
+ * import { tempo } from 'viem/chains'
682
+ * import { Actions } from 'viem/tempo'
683
+ *
684
+ * const client = createClient({
685
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
686
+ * transport: http(),
687
+ * })
688
+ *
689
+ * const unwatch = Actions.receivePolicy.watchUpdated(client, {
690
+ * onUpdated: (args, log) => {
691
+ * console.log('Receive policy updated:', args)
692
+ * },
693
+ * })
694
+ * ```
695
+ *
696
+ * @param client - Client.
697
+ * @param parameters - Parameters.
698
+ * @returns A function to unsubscribe from the event.
699
+ */
700
+ export function watchUpdated(client, parameters) {
701
+ const { onUpdated, ...rest } = parameters;
702
+ return watchContractEvent(client, {
703
+ ...rest,
704
+ address: Addresses.tip403Registry,
705
+ abi: Abis.tip403Registry,
706
+ eventName: 'ReceivePolicyUpdated',
707
+ onLogs: (logs) => {
708
+ for (const log of logs) {
709
+ const { tokenFilterId, ...args } = log.args;
710
+ onUpdated({
711
+ ...args,
712
+ senderPolicyId: toPolicyRef(args.senderPolicyId),
713
+ tokenPolicyId: toPolicyRef(tokenFilterId),
714
+ claimer: toClaimer(args.recoveryAuthority, args.account),
715
+ }, log);
716
+ }
717
+ },
718
+ strict: true,
719
+ });
720
+ }
721
+ /** @internal */
722
+ function resolvePolicyRef(ref) {
723
+ if (ref === 'reject-all')
724
+ return rejectAllPolicyId;
725
+ if (ref === 'allow-all')
726
+ return allowAllPolicyId;
727
+ return ref;
728
+ }
729
+ /** @internal */
730
+ function toPolicyRef(id) {
731
+ if (id === rejectAllPolicyId)
732
+ return 'reject-all';
733
+ if (id === allowAllPolicyId)
734
+ return 'allow-all';
735
+ return id;
736
+ }
737
+ /** @internal */
738
+ function resolveClaimer(claimer, self) {
739
+ if (claimer === 'sender')
740
+ return zeroAddress;
741
+ if (claimer === 'self')
742
+ return self;
743
+ return claimer;
744
+ }
745
+ /** @internal */
746
+ function toClaimer(recoveryAuthority, account) {
747
+ if (recoveryAuthority === zeroAddress)
748
+ return 'sender';
749
+ if (isAddressEqual(recoveryAuthority, account))
750
+ return 'self';
751
+ return recoveryAuthority;
752
+ }
753
+ //# sourceMappingURL=receivePolicy.js.map