viem 2.48.2 → 2.48.4

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 (78) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/errors/version.js +1 -1
  3. package/_cjs/tempo/Addresses.js +2 -1
  4. package/_cjs/tempo/Addresses.js.map +1 -1
  5. package/_cjs/tempo/Decorator.js +7 -0
  6. package/_cjs/tempo/Decorator.js.map +1 -1
  7. package/_cjs/tempo/actions/index.js +2 -1
  8. package/_cjs/tempo/actions/index.js.map +1 -1
  9. package/_cjs/tempo/actions/virtualAddress.js +95 -0
  10. package/_cjs/tempo/actions/virtualAddress.js.map +1 -0
  11. package/_cjs/tempo/index.js +7 -2
  12. package/_cjs/tempo/index.js.map +1 -1
  13. package/_esm/errors/version.js +1 -1
  14. package/_esm/tempo/Addresses.js +1 -0
  15. package/_esm/tempo/Addresses.js.map +1 -1
  16. package/_esm/tempo/Decorator.js +7 -0
  17. package/_esm/tempo/Decorator.js.map +1 -1
  18. package/_esm/tempo/actions/accessKey.js +10 -10
  19. package/_esm/tempo/actions/amm.js +14 -14
  20. package/_esm/tempo/actions/dex.js +34 -34
  21. package/_esm/tempo/actions/faucet.js +2 -2
  22. package/_esm/tempo/actions/fee.js +10 -10
  23. package/_esm/tempo/actions/index.js +1 -0
  24. package/_esm/tempo/actions/index.js.map +1 -1
  25. package/_esm/tempo/actions/nonce.js +2 -2
  26. package/_esm/tempo/actions/policy.js +18 -18
  27. package/_esm/tempo/actions/reward.js +14 -14
  28. package/_esm/tempo/actions/token.js +61 -61
  29. package/_esm/tempo/actions/validator.js +27 -27
  30. package/_esm/tempo/actions/virtualAddress.js +228 -0
  31. package/_esm/tempo/actions/virtualAddress.js.map +1 -0
  32. package/_esm/tempo/index.js +3 -3
  33. package/_esm/tempo/index.js.map +1 -1
  34. package/_types/errors/version.d.ts +1 -1
  35. package/_types/tempo/Addresses.d.ts +1 -0
  36. package/_types/tempo/Addresses.d.ts.map +1 -1
  37. package/_types/tempo/Decorator.d.ts +101 -1
  38. package/_types/tempo/Decorator.d.ts.map +1 -1
  39. package/_types/tempo/actions/accessKey.d.ts +10 -10
  40. package/_types/tempo/actions/amm.d.ts +14 -14
  41. package/_types/tempo/actions/dex.d.ts +34 -34
  42. package/_types/tempo/actions/faucet.d.ts +2 -2
  43. package/_types/tempo/actions/fee.d.ts +10 -10
  44. package/_types/tempo/actions/index.d.ts +1 -0
  45. package/_types/tempo/actions/index.d.ts.map +1 -1
  46. package/_types/tempo/actions/nonce.d.ts +2 -2
  47. package/_types/tempo/actions/policy.d.ts +18 -18
  48. package/_types/tempo/actions/reward.d.ts +14 -14
  49. package/_types/tempo/actions/token.d.ts +61 -61
  50. package/_types/tempo/actions/validator.d.ts +27 -27
  51. package/_types/tempo/actions/virtualAddress.d.ts +350 -0
  52. package/_types/tempo/actions/virtualAddress.d.ts.map +1 -0
  53. package/_types/tempo/index.d.ts +2 -2
  54. package/_types/tempo/index.d.ts.map +1 -1
  55. package/errors/version.ts +1 -1
  56. package/package.json +2 -2
  57. package/tempo/Addresses.ts +1 -0
  58. package/tempo/Decorator.ts +125 -1
  59. package/tempo/actions/accessKey.ts +10 -10
  60. package/tempo/actions/amm.ts +14 -14
  61. package/tempo/actions/dex.ts +34 -34
  62. package/tempo/actions/faucet.ts +2 -2
  63. package/tempo/actions/fee.ts +10 -10
  64. package/tempo/actions/index.ts +1 -0
  65. package/tempo/actions/nonce.ts +2 -2
  66. package/tempo/actions/policy.ts +18 -18
  67. package/tempo/actions/reward.ts +14 -14
  68. package/tempo/actions/token.ts +61 -61
  69. package/tempo/actions/validator.ts +27 -27
  70. package/tempo/actions/virtualAddress.ts +337 -0
  71. package/tempo/index.ts +10 -3
  72. package/_cjs/tempo/Secp256k1.js +0 -6
  73. package/_cjs/tempo/Secp256k1.js.map +0 -1
  74. package/_esm/tempo/Secp256k1.js +0 -3
  75. package/_esm/tempo/Secp256k1.js.map +0 -1
  76. package/_types/tempo/Secp256k1.d.ts +0 -2
  77. package/_types/tempo/Secp256k1.d.ts.map +0 -1
  78. package/tempo/Secp256k1.ts +0 -2
@@ -28,7 +28,7 @@ import { defineCall } from '../internal/utils.js'
28
28
  *
29
29
  * const client = createClient({
30
30
  * account: privateKeyToAccount('0x...'),
31
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
31
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
32
32
  * transport: http(),
33
33
  * })
34
34
  *
@@ -125,7 +125,7 @@ export namespace add {
125
125
  * import { Actions } from 'viem/tempo'
126
126
  *
127
127
  * const client = createClient({
128
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
128
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
129
129
  * transport: http(),
130
130
  * }).extend(walletActions)
131
131
  *
@@ -180,7 +180,7 @@ export namespace add {
180
180
  *
181
181
  * const client = createClient({
182
182
  * account: privateKeyToAccount('0x...'),
183
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
183
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
184
184
  * transport: http(),
185
185
  * })
186
186
  *
@@ -237,7 +237,7 @@ export namespace addSync {
237
237
  *
238
238
  * const client = createClient({
239
239
  * account: privateKeyToAccount('0x...'),
240
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
240
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
241
241
  * transport: http(),
242
242
  * })
243
243
  *
@@ -309,7 +309,7 @@ export namespace changeOwner {
309
309
  * import { Actions } from 'viem/tempo'
310
310
  *
311
311
  * const client = createClient({
312
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
312
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
313
313
  * transport: http(),
314
314
  * }).extend(walletActions)
315
315
  *
@@ -348,7 +348,7 @@ export namespace changeOwner {
348
348
  *
349
349
  * const client = createClient({
350
350
  * account: privateKeyToAccount('0x...'),
351
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
351
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
352
352
  * transport: http(),
353
353
  * })
354
354
  *
@@ -401,7 +401,7 @@ export namespace changeOwnerSync {
401
401
  *
402
402
  * const client = createClient({
403
403
  * account: privateKeyToAccount('0x...'),
404
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
404
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
405
405
  * transport: http(),
406
406
  * })
407
407
  *
@@ -476,7 +476,7 @@ export namespace changeStatus {
476
476
  * import { Actions } from 'viem/tempo'
477
477
  *
478
478
  * const client = createClient({
479
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
479
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
480
480
  * transport: http(),
481
481
  * }).extend(walletActions)
482
482
  *
@@ -516,7 +516,7 @@ export namespace changeStatus {
516
516
  *
517
517
  * const client = createClient({
518
518
  * account: privateKeyToAccount('0x...'),
519
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
519
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
520
520
  * transport: http(),
521
521
  * })
522
522
  *
@@ -568,7 +568,7 @@ export namespace changeStatusSync {
568
568
  * import { Actions } from 'viem/tempo'
569
569
  *
570
570
  * const client = createClient({
571
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
571
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
572
572
  * transport: http(),
573
573
  * })
574
574
  *
@@ -616,7 +616,7 @@ export namespace getNextFullDkgCeremony {
616
616
  * import { Actions } from 'viem/tempo'
617
617
  *
618
618
  * const client = createClient({
619
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
619
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
620
620
  * transport: http(),
621
621
  * })
622
622
  *
@@ -647,7 +647,7 @@ export namespace getNextFullDkgCeremony {
647
647
  * import { Actions } from 'viem/tempo'
648
648
  *
649
649
  * const client = createClient({
650
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
650
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
651
651
  * transport: http(),
652
652
  * })
653
653
  *
@@ -695,7 +695,7 @@ export namespace getOwner {
695
695
  * import { Actions } from 'viem/tempo'
696
696
  *
697
697
  * const client = createClient({
698
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
698
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
699
699
  * transport: http(),
700
700
  * })
701
701
  *
@@ -726,7 +726,7 @@ export namespace getOwner {
726
726
  * import { Actions } from 'viem/tempo'
727
727
  *
728
728
  * const client = createClient({
729
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
729
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
730
730
  * transport: http(),
731
731
  * })
732
732
  *
@@ -782,7 +782,7 @@ export namespace get {
782
782
  * import { Actions } from 'viem/tempo'
783
783
  *
784
784
  * const client = createClient({
785
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
785
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
786
786
  * transport: http(),
787
787
  * })
788
788
  *
@@ -817,7 +817,7 @@ export namespace get {
817
817
  * import { Actions } from 'viem/tempo'
818
818
  *
819
819
  * const client = createClient({
820
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
820
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
821
821
  * transport: http(),
822
822
  * })
823
823
  *
@@ -873,7 +873,7 @@ export namespace getByIndex {
873
873
  * import { Actions } from 'viem/tempo'
874
874
  *
875
875
  * const client = createClient({
876
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
876
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
877
877
  * transport: http(),
878
878
  * })
879
879
  *
@@ -909,7 +909,7 @@ export namespace getByIndex {
909
909
  * import { Actions } from 'viem/tempo'
910
910
  *
911
911
  * const client = createClient({
912
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
912
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
913
913
  * transport: http(),
914
914
  * })
915
915
  *
@@ -957,7 +957,7 @@ export namespace getCount {
957
957
  * import { Actions } from 'viem/tempo'
958
958
  *
959
959
  * const client = createClient({
960
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
960
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
961
961
  * transport: http(),
962
962
  * })
963
963
  *
@@ -988,7 +988,7 @@ export namespace getCount {
988
988
  * import { Actions } from 'viem/tempo'
989
989
  *
990
990
  * const client = createClient({
991
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
991
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
992
992
  * transport: http(),
993
993
  * })
994
994
  *
@@ -1036,7 +1036,7 @@ export namespace list {
1036
1036
  * import { Actions } from 'viem/tempo'
1037
1037
  *
1038
1038
  * const client = createClient({
1039
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1039
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1040
1040
  * transport: http(),
1041
1041
  * })
1042
1042
  *
@@ -1069,7 +1069,7 @@ export namespace list {
1069
1069
  *
1070
1070
  * const client = createClient({
1071
1071
  * account: privateKeyToAccount('0x...'),
1072
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1072
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1073
1073
  * transport: http(),
1074
1074
  * })
1075
1075
  *
@@ -1141,7 +1141,7 @@ export namespace setNextFullDkgCeremony {
1141
1141
  * import { Actions } from 'viem/tempo'
1142
1142
  *
1143
1143
  * const client = createClient({
1144
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1144
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1145
1145
  * transport: http(),
1146
1146
  * }).extend(walletActions)
1147
1147
  *
@@ -1180,7 +1180,7 @@ export namespace setNextFullDkgCeremony {
1180
1180
  *
1181
1181
  * const client = createClient({
1182
1182
  * account: privateKeyToAccount('0x...'),
1183
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1183
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1184
1184
  * transport: http(),
1185
1185
  * })
1186
1186
  *
@@ -1237,7 +1237,7 @@ export namespace setNextFullDkgCeremonySync {
1237
1237
  *
1238
1238
  * const client = createClient({
1239
1239
  * account: privateKeyToAccount('0x...'),
1240
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1240
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1241
1241
  * transport: http(),
1242
1242
  * })
1243
1243
  *
@@ -1329,7 +1329,7 @@ export namespace update {
1329
1329
  * import { Actions } from 'viem/tempo'
1330
1330
  *
1331
1331
  * const client = createClient({
1332
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1332
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1333
1333
  * transport: http(),
1334
1334
  * }).extend(walletActions)
1335
1335
  *
@@ -1372,7 +1372,7 @@ export namespace update {
1372
1372
  *
1373
1373
  * const client = createClient({
1374
1374
  * account: privateKeyToAccount('0x...'),
1375
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1375
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1376
1376
  * transport: http(),
1377
1377
  * })
1378
1378
  *
@@ -0,0 +1,337 @@
1
+ import type { Address } from 'abitype'
2
+ import * as Hex from 'ox/Hex'
3
+ import type { Account } from '../../accounts/types.js'
4
+ import { readContract } from '../../actions/public/readContract.js'
5
+ import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
6
+ import { writeContract } from '../../actions/wallet/writeContract.js'
7
+ import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
8
+ import type { Client } from '../../clients/createClient.js'
9
+ import type { Transport } from '../../clients/transports/createTransport.js'
10
+ import { zeroAddress } from '../../constants/address.js'
11
+ import type { BaseErrorType } from '../../errors/base.js'
12
+ import type { Chain } from '../../types/chain.js'
13
+ import type { GetEventArgs } from '../../types/contract.js'
14
+ import type { Compute } from '../../types/utils.js'
15
+ import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
16
+ import * as Abis from '../Abis.js'
17
+ import * as Addresses from '../Addresses.js'
18
+ import type { ReadParameters, WriteParameters } from '../internal/types.js'
19
+ import { defineCall } from '../internal/utils.js'
20
+ import type { TransactionReceipt } from '../Transaction.js'
21
+
22
+ /**
23
+ * Gets the master address for a given master ID.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { createClient, http } from 'viem'
28
+ * import { tempo } from 'viem/chains'
29
+ * import { Actions } from 'viem/tempo'
30
+ *
31
+ * const client = createClient({
32
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' })
33
+ * transport: http(),
34
+ * })
35
+ *
36
+ * const address = await Actions.virtualAddress.getMasterAddress(client, {
37
+ * masterId: '0xdeadbeef',
38
+ * })
39
+ * ```
40
+ *
41
+ * @param client - Client.
42
+ * @param parameters - Parameters.
43
+ * @returns The master address, or null if unregistered.
44
+ */
45
+ export async function getMasterAddress<
46
+ chain extends Chain | undefined,
47
+ account extends Account | undefined,
48
+ >(
49
+ client: Client<Transport, chain, account>,
50
+ parameters: getMasterAddress.Parameters,
51
+ ): Promise<getMasterAddress.ReturnValue> {
52
+ const address = await readContract(client, {
53
+ ...parameters,
54
+ ...getMasterAddress.call({ masterId: parameters.masterId }),
55
+ })
56
+ if (address === zeroAddress) return null
57
+ return address
58
+ }
59
+
60
+ export namespace getMasterAddress {
61
+ export type Parameters = ReadParameters & Args
62
+
63
+ export type Args = {
64
+ /** The master ID (bytes4). */
65
+ masterId: Hex.Hex
66
+ }
67
+
68
+ export type ReturnValue = Address | null
69
+
70
+ // TODO: exhaustive error type
71
+ export type ErrorType = BaseErrorType
72
+
73
+ /**
74
+ * Defines a call to the `getMaster` function.
75
+ *
76
+ * @param args - Arguments.
77
+ * @returns The call.
78
+ */
79
+ export function call(args: Args) {
80
+ const { masterId } = args
81
+ return defineCall({
82
+ address: Addresses.addressRegistry,
83
+ abi: Abis.addressRegistry,
84
+ args: [masterId],
85
+ functionName: 'getMaster',
86
+ })
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Resolves a virtual address to its master address.
92
+ *
93
+ * - Non-virtual addresses are returned unchanged.
94
+ * - Virtual addresses with a registered master return the master address.
95
+ * - Virtual addresses with an unregistered master return null.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { createClient, http } from 'viem'
100
+ * import { tempo } from 'viem/chains'
101
+ * import { Actions } from 'viem/tempo'
102
+ *
103
+ * const client = createClient({
104
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' })
105
+ * transport: http(),
106
+ * })
107
+ *
108
+ * const recipient = await Actions.virtualAddress.resolve(client, {
109
+ * address: '0x...',
110
+ * })
111
+ * ```
112
+ *
113
+ * @param client - Client.
114
+ * @param parameters - Parameters.
115
+ * @returns The resolved address, or null if virtual and unregistered.
116
+ */
117
+ export async function resolve<
118
+ chain extends Chain | undefined,
119
+ account extends Account | undefined,
120
+ >(
121
+ client: Client<Transport, chain, account>,
122
+ parameters: resolve.Parameters,
123
+ ): Promise<resolve.ReturnValue> {
124
+ if (!isVirtual(parameters.address)) return parameters.address
125
+
126
+ const masterId = Hex.slice(parameters.address, 0, 4)
127
+ return getMasterAddress(client, { ...parameters, masterId })
128
+ }
129
+
130
+ export namespace resolve {
131
+ export type Parameters = ReadParameters & Args
132
+
133
+ export type Args = {
134
+ /** The address to resolve. */
135
+ address: Address
136
+ }
137
+
138
+ export type ReturnValue = Address | null
139
+
140
+ // TODO: exhaustive error type
141
+ export type ErrorType = BaseErrorType
142
+ }
143
+
144
+ /**
145
+ * Registers a virtual master address.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { createClient, http } from 'viem'
150
+ * import { tempo } from 'viem/chains'
151
+ * import { Actions } from 'viem/tempo'
152
+ * import { privateKeyToAccount } from 'viem/accounts'
153
+ *
154
+ * const client = createClient({
155
+ * account: privateKeyToAccount('0x...'),
156
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' })
157
+ * transport: http(),
158
+ * })
159
+ *
160
+ * const hash = await Actions.virtualAddress.registerMaster(client, {
161
+ * salt: '0x...',
162
+ * })
163
+ * ```
164
+ *
165
+ * @param client - Client.
166
+ * @param parameters - Parameters.
167
+ * @returns The transaction hash.
168
+ */
169
+ export async function registerMaster<
170
+ chain extends Chain | undefined,
171
+ account extends Account | undefined,
172
+ >(
173
+ client: Client<Transport, chain, account>,
174
+ parameters: registerMaster.Parameters<chain, account>,
175
+ ): Promise<registerMaster.ReturnValue> {
176
+ return registerMaster.inner(writeContract, client, parameters)
177
+ }
178
+
179
+ export namespace registerMaster {
180
+ export type Parameters<
181
+ chain extends Chain | undefined = Chain | undefined,
182
+ account extends Account | undefined = Account | undefined,
183
+ > = WriteParameters<chain, account> & Args
184
+
185
+ export type Args = {
186
+ /** The salt (bytes32) used for proof-of-work master ID derivation. */
187
+ salt: Hex.Hex
188
+ }
189
+
190
+ export type ReturnValue = WriteContractReturnType
191
+
192
+ // TODO: exhaustive error type
193
+ export type ErrorType = BaseErrorType
194
+
195
+ /** @internal */
196
+ export async function inner<
197
+ action extends typeof writeContract | typeof writeContractSync,
198
+ chain extends Chain | undefined,
199
+ account extends Account | undefined,
200
+ >(
201
+ action: action,
202
+ client: Client<Transport, chain, account>,
203
+ parameters: registerMaster.Parameters<chain, account>,
204
+ ): Promise<ReturnType<action>> {
205
+ const { salt, ...rest } = parameters
206
+ const call = registerMaster.call({ salt })
207
+ return (await action(client, {
208
+ ...rest,
209
+ ...call,
210
+ } as never)) as never
211
+ }
212
+
213
+ /**
214
+ * Defines a call to the `registerVirtualMaster` function.
215
+ *
216
+ * Can be passed as a parameter to:
217
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
218
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
219
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * import { createClient, http, walletActions } from 'viem'
224
+ * import { tempo } from 'viem/chains'
225
+ * import { Actions } from 'viem/tempo'
226
+ *
227
+ * const client = createClient({
228
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' })
229
+ * transport: http(),
230
+ * }).extend(walletActions)
231
+ *
232
+ * const { result } = await client.sendCalls({
233
+ * calls: [
234
+ * Actions.virtualAddress.registerMaster.call({
235
+ * salt: '0x...',
236
+ * }),
237
+ * ]
238
+ * })
239
+ * ```
240
+ *
241
+ * @param args - Arguments.
242
+ * @returns The call.
243
+ */
244
+ export function call(args: Args) {
245
+ const { salt } = args
246
+ return defineCall({
247
+ address: Addresses.addressRegistry,
248
+ abi: Abis.addressRegistry,
249
+ functionName: 'registerVirtualMaster',
250
+ args: [salt],
251
+ })
252
+ }
253
+
254
+ export function extractEvent(logs: import('../../types/log.js').Log[]) {
255
+ const [log] = parseEventLogs({
256
+ abi: Abis.addressRegistry,
257
+ logs,
258
+ eventName: 'MasterRegistered',
259
+ strict: true,
260
+ })
261
+ if (!log) throw new Error('`MasterRegistered` event not found.')
262
+ return log
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Registers a virtual master address and waits for confirmation.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * import { createClient, http } from 'viem'
272
+ * import { tempo } from 'viem/chains'
273
+ * import { Actions } from 'viem/tempo'
274
+ * import { privateKeyToAccount } from 'viem/accounts'
275
+ *
276
+ * const client = createClient({
277
+ * account: privateKeyToAccount('0x...'),
278
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' })
279
+ * transport: http(),
280
+ * })
281
+ *
282
+ * const { receipt, masterId, masterAddress } = await Actions.virtualAddress.registerMasterSync(client, {
283
+ * salt: '0x...',
284
+ * })
285
+ * ```
286
+ *
287
+ * @param client - Client.
288
+ * @param parameters - Parameters.
289
+ * @returns The transaction receipt and extracted event data.
290
+ */
291
+ export async function registerMasterSync<
292
+ chain extends Chain | undefined,
293
+ account extends Account | undefined,
294
+ >(
295
+ client: Client<Transport, chain, account>,
296
+ parameters: registerMasterSync.Parameters<chain, account>,
297
+ ): Promise<registerMasterSync.ReturnValue> {
298
+ const { throwOnReceiptRevert = true, ...rest } = parameters
299
+ const receipt = await registerMaster.inner(writeContractSync, client, {
300
+ ...rest,
301
+ throwOnReceiptRevert,
302
+ } as never)
303
+ const { args } = registerMaster.extractEvent(receipt.logs)
304
+ return {
305
+ ...args,
306
+ receipt,
307
+ } as never
308
+ }
309
+
310
+ export namespace registerMasterSync {
311
+ export type Parameters<
312
+ chain extends Chain | undefined = Chain | undefined,
313
+ account extends Account | undefined = Account | undefined,
314
+ > = registerMaster.Parameters<chain, account>
315
+
316
+ export type Args = registerMaster.Args
317
+
318
+ export type ReturnValue = Compute<
319
+ GetEventArgs<
320
+ typeof Abis.addressRegistry,
321
+ 'MasterRegistered',
322
+ { IndexedOnly: false; Required: true }
323
+ > & {
324
+ receipt: TransactionReceipt
325
+ }
326
+ >
327
+
328
+ // TODO: exhaustive error type
329
+ export type ErrorType = BaseErrorType
330
+ }
331
+
332
+ const virtualMagic = '0xfdfdfdfdfdfdfdfdfdfd'
333
+
334
+ /** @internal */
335
+ function isVirtual(address: string): boolean {
336
+ return Hex.slice(address as Hex.Hex, 4, 14).toLowerCase() === virtualMagic
337
+ }
package/tempo/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
2
+ export { Bytes, PublicKey, Secp256k1 } from 'ox'
1
3
  // Export types required for inference.
2
4
  export type {
3
5
  /** @deprecated */
@@ -9,8 +11,14 @@ export type {
9
11
  /** @deprecated */
10
12
  TxEnvelopeTempo as z_TxEnvelopeTempo,
11
13
  } from 'ox/tempo'
12
- // biome-ignore lint/performance/noBarrelFile: _
13
- export { Period, TempoAddress, Tick, TokenId } from 'ox/tempo'
14
+ export {
15
+ Period,
16
+ TempoAddress,
17
+ Tick,
18
+ TokenId,
19
+ VirtualAddress,
20
+ VirtualMaster,
21
+ } from 'ox/tempo'
14
22
  export * as Abis from './Abis.js'
15
23
  export * as Account from './Account.js'
16
24
  export * as Addresses from './Addresses.js'
@@ -24,7 +32,6 @@ export * as Expiry from './Expiry.js'
24
32
  export * as Formatters from './Formatters.js'
25
33
  export * as Hardfork from './Hardfork.js'
26
34
  export * as P256 from './P256.js'
27
- export * as Secp256k1 from './Secp256k1.js'
28
35
  export * as Storage from './Storage.js'
29
36
  export * as TokenIds from './TokenIds.js'
30
37
  // Export types required for inference.
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomPrivateKey = void 0;
4
- var Secp256k1_1 = require("ox/Secp256k1");
5
- Object.defineProperty(exports, "randomPrivateKey", { enumerable: true, get: function () { return Secp256k1_1.randomPrivateKey; } });
6
- //# sourceMappingURL=Secp256k1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Secp256k1.js","sourceRoot":"","sources":["../../tempo/Secp256k1.ts"],"names":[],"mappings":";;;AACA,0CAA+C;AAAtC,6GAAA,gBAAgB,OAAA"}
@@ -1,3 +0,0 @@
1
- // biome-ignore lint/performance/noBarrelFile: _
2
- export { randomPrivateKey } from 'ox/Secp256k1';
3
- //# sourceMappingURL=Secp256k1.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Secp256k1.js","sourceRoot":"","sources":["../../tempo/Secp256k1.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA"}
@@ -1,2 +0,0 @@
1
- export { randomPrivateKey } from 'ox/Secp256k1';
2
- //# sourceMappingURL=Secp256k1.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Secp256k1.d.ts","sourceRoot":"","sources":["../../tempo/Secp256k1.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA"}
@@ -1,2 +0,0 @@
1
- // biome-ignore lint/performance/noBarrelFile: _
2
- export { randomPrivateKey } from 'ox/Secp256k1'