viem 2.21.57 → 2.21.59

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 (175) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
  3. package/_cjs/account-abstraction/actions/bundler/prepareUserOperation.js +1 -1
  4. package/_cjs/account-abstraction/actions/bundler/prepareUserOperation.js.map +1 -1
  5. package/_cjs/account-abstraction/actions/bundler/sendUserOperation.js.map +1 -1
  6. package/_cjs/account-abstraction/index.js.map +1 -1
  7. package/_cjs/account-abstraction/utils/errors/getUserOperationError.js +1 -1
  8. package/_cjs/account-abstraction/utils/errors/getUserOperationError.js.map +1 -1
  9. package/_cjs/chains/definitions/arthera.js +28 -0
  10. package/_cjs/chains/definitions/arthera.js.map +1 -0
  11. package/_cjs/chains/index.js +12 -10
  12. package/_cjs/chains/index.js.map +1 -1
  13. package/_cjs/errors/version.js +1 -1
  14. package/_cjs/experimental/erc7821/actions/execute.js +78 -0
  15. package/_cjs/experimental/erc7821/actions/execute.js.map +1 -0
  16. package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js +21 -0
  17. package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -0
  18. package/_cjs/experimental/erc7821/constants.js +65 -0
  19. package/_cjs/experimental/erc7821/constants.js.map +1 -0
  20. package/_cjs/experimental/erc7821/decorators/erc7821.js +14 -0
  21. package/_cjs/experimental/erc7821/decorators/erc7821.js.map +1 -0
  22. package/_cjs/experimental/erc7821/errors.js +26 -0
  23. package/_cjs/experimental/erc7821/errors.js.map +1 -0
  24. package/_cjs/experimental/erc7821/index.js +13 -0
  25. package/_cjs/experimental/erc7821/index.js.map +1 -0
  26. package/_cjs/experimental/index.js +3 -1
  27. package/_cjs/experimental/index.js.map +1 -1
  28. package/_cjs/types/calls.js +3 -0
  29. package/_cjs/types/calls.js.map +1 -0
  30. package/_cjs/zksync/actions/deployContract.js +3 -1
  31. package/_cjs/zksync/actions/deployContract.js.map +1 -1
  32. package/_cjs/zksync/actions/getL1TokenAddress.js +21 -0
  33. package/_cjs/zksync/actions/getL1TokenAddress.js.map +1 -0
  34. package/_cjs/zksync/actions/getL2TokenAddress.js +25 -0
  35. package/_cjs/zksync/actions/getL2TokenAddress.js.map +1 -0
  36. package/_cjs/zksync/actions/sendEip712Transaction.js +3 -3
  37. package/_cjs/zksync/actions/sendEip712Transaction.js.map +1 -1
  38. package/_cjs/zksync/actions/signEip712Transaction.js +2 -2
  39. package/_cjs/zksync/actions/signEip712Transaction.js.map +1 -1
  40. package/_cjs/zksync/constants/abis.js +185 -1
  41. package/_cjs/zksync/constants/abis.js.map +1 -1
  42. package/_cjs/zksync/constants/address.js +2 -1
  43. package/_cjs/zksync/constants/address.js.map +1 -1
  44. package/_cjs/zksync/decorators/publicL2.js +4 -0
  45. package/_cjs/zksync/decorators/publicL2.js.map +1 -1
  46. package/_cjs/zksync/index.js +5 -1
  47. package/_cjs/zksync/index.js.map +1 -1
  48. package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
  49. package/_esm/account-abstraction/actions/bundler/prepareUserOperation.js +1 -1
  50. package/_esm/account-abstraction/actions/bundler/prepareUserOperation.js.map +1 -1
  51. package/_esm/account-abstraction/actions/bundler/sendUserOperation.js.map +1 -1
  52. package/_esm/account-abstraction/index.js.map +1 -1
  53. package/_esm/account-abstraction/utils/errors/getUserOperationError.js +1 -1
  54. package/_esm/account-abstraction/utils/errors/getUserOperationError.js.map +1 -1
  55. package/_esm/chains/definitions/arthera.js +25 -0
  56. package/_esm/chains/definitions/arthera.js.map +1 -0
  57. package/_esm/chains/index.js +2 -1
  58. package/_esm/chains/index.js.map +1 -1
  59. package/_esm/errors/version.js +1 -1
  60. package/_esm/experimental/erc7821/actions/execute.js +143 -0
  61. package/_esm/experimental/erc7821/actions/execute.js.map +1 -0
  62. package/_esm/experimental/erc7821/actions/supportsExecutionMode.js +41 -0
  63. package/_esm/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -0
  64. package/_esm/experimental/erc7821/constants.js +62 -0
  65. package/_esm/experimental/erc7821/constants.js.map +1 -0
  66. package/_esm/experimental/erc7821/decorators/erc7821.js +24 -0
  67. package/_esm/experimental/erc7821/decorators/erc7821.js.map +1 -0
  68. package/_esm/experimental/erc7821/errors.js +21 -0
  69. package/_esm/experimental/erc7821/errors.js.map +1 -0
  70. package/_esm/experimental/erc7821/index.js +7 -0
  71. package/_esm/experimental/erc7821/index.js.map +1 -0
  72. package/_esm/experimental/index.js +1 -0
  73. package/_esm/experimental/index.js.map +1 -1
  74. package/_esm/types/calls.js +2 -0
  75. package/_esm/types/calls.js.map +1 -0
  76. package/_esm/zksync/actions/deployContract.js +5 -3
  77. package/_esm/zksync/actions/deployContract.js.map +1 -1
  78. package/_esm/zksync/actions/getL1TokenAddress.js +40 -0
  79. package/_esm/zksync/actions/getL1TokenAddress.js.map +1 -0
  80. package/_esm/zksync/actions/getL2TokenAddress.js +45 -0
  81. package/_esm/zksync/actions/getL2TokenAddress.js.map +1 -0
  82. package/_esm/zksync/actions/sendEip712Transaction.js +3 -3
  83. package/_esm/zksync/actions/sendEip712Transaction.js.map +1 -1
  84. package/_esm/zksync/actions/signEip712Transaction.js +4 -2
  85. package/_esm/zksync/actions/signEip712Transaction.js.map +1 -1
  86. package/_esm/zksync/constants/abis.js +184 -0
  87. package/_esm/zksync/constants/abis.js.map +1 -1
  88. package/_esm/zksync/constants/address.js +1 -0
  89. package/_esm/zksync/constants/address.js.map +1 -1
  90. package/_esm/zksync/decorators/publicL2.js +4 -0
  91. package/_esm/zksync/decorators/publicL2.js.map +1 -1
  92. package/_esm/zksync/index.js +2 -0
  93. package/_esm/zksync/index.js.map +1 -1
  94. package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts +3 -2
  95. package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
  96. package/_types/account-abstraction/actions/bundler/prepareUserOperation.d.ts +3 -2
  97. package/_types/account-abstraction/actions/bundler/prepareUserOperation.d.ts.map +1 -1
  98. package/_types/account-abstraction/actions/bundler/sendUserOperation.d.ts +3 -2
  99. package/_types/account-abstraction/actions/bundler/sendUserOperation.d.ts.map +1 -1
  100. package/_types/account-abstraction/index.d.ts +1 -1
  101. package/_types/account-abstraction/index.d.ts.map +1 -1
  102. package/_types/account-abstraction/types/userOperation.d.ts +2 -30
  103. package/_types/account-abstraction/types/userOperation.d.ts.map +1 -1
  104. package/_types/account-abstraction/utils/errors/getUserOperationError.d.ts.map +1 -1
  105. package/_types/actions/public/getEip712Domain.d.ts +1 -1
  106. package/_types/actions/public/getEip712Domain.d.ts.map +1 -1
  107. package/_types/chains/definitions/arthera.d.ts +34 -0
  108. package/_types/chains/definitions/arthera.d.ts.map +1 -0
  109. package/_types/chains/index.d.ts +2 -1
  110. package/_types/chains/index.d.ts.map +1 -1
  111. package/_types/errors/version.d.ts +1 -1
  112. package/_types/experimental/erc7739/utils/hashTypedData.d.ts +1 -1
  113. package/_types/experimental/erc7739/utils/hashTypedData.d.ts.map +1 -1
  114. package/_types/experimental/erc7821/actions/execute.d.ts +94 -0
  115. package/_types/experimental/erc7821/actions/execute.d.ts.map +1 -0
  116. package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts +37 -0
  117. package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts.map +1 -0
  118. package/_types/experimental/erc7821/constants.d.ts +48 -0
  119. package/_types/experimental/erc7821/constants.d.ts.map +1 -0
  120. package/_types/experimental/erc7821/decorators/erc7821.d.ts +116 -0
  121. package/_types/experimental/erc7821/decorators/erc7821.d.ts.map +1 -0
  122. package/_types/experimental/erc7821/errors.d.ts +14 -0
  123. package/_types/experimental/erc7821/errors.d.ts.map +1 -0
  124. package/_types/experimental/erc7821/index.d.ts +6 -0
  125. package/_types/experimental/erc7821/index.d.ts.map +1 -0
  126. package/_types/experimental/index.d.ts +1 -0
  127. package/_types/experimental/index.d.ts.map +1 -1
  128. package/_types/types/calls.d.ts +14 -0
  129. package/_types/types/calls.d.ts.map +1 -0
  130. package/_types/zksync/actions/deployContract.d.ts +1 -1
  131. package/_types/zksync/actions/deployContract.d.ts.map +1 -1
  132. package/_types/zksync/actions/getL1TokenAddress.d.ts +34 -0
  133. package/_types/zksync/actions/getL1TokenAddress.d.ts.map +1 -0
  134. package/_types/zksync/actions/getL2TokenAddress.d.ts +37 -0
  135. package/_types/zksync/actions/getL2TokenAddress.d.ts.map +1 -0
  136. package/_types/zksync/actions/sendEip712Transaction.d.ts.map +1 -1
  137. package/_types/zksync/actions/signEip712Transaction.d.ts +2 -0
  138. package/_types/zksync/actions/signEip712Transaction.d.ts.map +1 -1
  139. package/_types/zksync/constants/abis.d.ts +143 -0
  140. package/_types/zksync/constants/abis.d.ts.map +1 -1
  141. package/_types/zksync/constants/address.d.ts +1 -0
  142. package/_types/zksync/constants/address.d.ts.map +1 -1
  143. package/_types/zksync/decorators/publicL2.d.ts +46 -0
  144. package/_types/zksync/decorators/publicL2.d.ts.map +1 -1
  145. package/_types/zksync/index.d.ts +2 -0
  146. package/_types/zksync/index.d.ts.map +1 -1
  147. package/account-abstraction/actions/bundler/estimateUserOperationGas.ts +2 -4
  148. package/account-abstraction/actions/bundler/prepareUserOperation.ts +6 -10
  149. package/account-abstraction/actions/bundler/sendUserOperation.ts +2 -4
  150. package/account-abstraction/index.ts +0 -2
  151. package/account-abstraction/types/userOperation.ts +2 -72
  152. package/account-abstraction/utils/errors/getUserOperationError.ts +11 -17
  153. package/actions/public/getEip712Domain.ts +1 -1
  154. package/chains/definitions/arthera.ts +25 -0
  155. package/chains/index.ts +2 -1
  156. package/errors/version.ts +1 -1
  157. package/experimental/erc7739/utils/hashTypedData.ts +1 -1
  158. package/experimental/erc7821/actions/execute.ts +232 -0
  159. package/experimental/erc7821/actions/supportsExecutionMode.ts +60 -0
  160. package/experimental/erc7821/constants.ts +62 -0
  161. package/experimental/erc7821/decorators/erc7821.ts +149 -0
  162. package/experimental/erc7821/errors.ts +29 -0
  163. package/experimental/erc7821/index.ts +23 -0
  164. package/experimental/index.ts +5 -0
  165. package/package.json +9 -4
  166. package/types/calls.ts +38 -0
  167. package/zksync/actions/deployContract.ts +9 -3
  168. package/zksync/actions/getL1TokenAddress.ts +59 -0
  169. package/zksync/actions/getL2TokenAddress.ts +70 -0
  170. package/zksync/actions/sendEip712Transaction.ts +5 -3
  171. package/zksync/actions/signEip712Transaction.ts +5 -2
  172. package/zksync/constants/abis.ts +185 -0
  173. package/zksync/constants/address.ts +3 -0
  174. package/zksync/decorators/publicL2.ts +62 -0
  175. package/zksync/index.ts +10 -0
@@ -0,0 +1,23 @@
1
+ /** */
2
+ // biome-ignore lint/performance/noBarrelFile: entrypoint
3
+ export {
4
+ type ExecuteErrorType,
5
+ type ExecuteParameters,
6
+ type ExecuteReturnType,
7
+ execute,
8
+ } from './actions/execute.js'
9
+ export {
10
+ type SupportsExecutionModeErrorType,
11
+ type SupportsExecutionModeParameters,
12
+ type SupportsExecutionModeReturnType,
13
+ supportsExecutionMode,
14
+ } from './actions/supportsExecutionMode.js'
15
+
16
+ export {
17
+ ExecuteUnsupportedError,
18
+ type ExecuteUnsupportedErrorType,
19
+ FunctionSelectorNotRecognizedError,
20
+ type FunctionSelectorNotRecognizedErrorType,
21
+ } from './errors.js'
22
+
23
+ export { type Erc7821Actions, erc7821Actions } from './decorators/erc7821.js'
@@ -111,6 +111,11 @@ export {
111
111
  erc7739Actions,
112
112
  } from './erc7739/decorators/erc7739.js'
113
113
 
114
+ export {
115
+ type Erc7821Actions,
116
+ erc7821Actions,
117
+ } from './erc7821/decorators/erc7821.js'
118
+
114
119
  export {
115
120
  /** @deprecated This is no longer experimental – use `import type { ParseErc6492SignatureErrorType } from 'viem'` instead. */
116
121
  type ParseErc6492SignatureErrorType,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.21.57",
4
+ "version": "2.21.59",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -69,6 +69,11 @@
69
69
  "import": "./_esm/experimental/erc7739/index.js",
70
70
  "default": "./_cjs/experimental/erc7739/index.js"
71
71
  },
72
+ "./experimental/erc7821": {
73
+ "types": "./_types/experimental/erc7821/index.d.ts",
74
+ "import": "./_esm/experimental/erc7821/index.js",
75
+ "default": "./_cjs/experimental/erc7821/index.js"
76
+ },
72
77
  "./linea": {
73
78
  "types": "./_types/linea/index.d.ts",
74
79
  "import": "./_esm/linea/index.js",
@@ -134,8 +139,8 @@
134
139
  "experimental": [
135
140
  "./_types/experimental/index.d.ts"
136
141
  ],
137
- "experimental/solady": [
138
- "./_types/experimental/solady/index.d.ts"
142
+ "experimental/erc7739": [
143
+ "./_types/experimental/erc7739/index.d.ts"
139
144
  ],
140
145
  "node": [
141
146
  "./_types/node/index.d.ts"
@@ -172,7 +177,7 @@
172
177
  "@scure/bip39": "1.5.0",
173
178
  "abitype": "1.0.7",
174
179
  "isows": "1.0.6",
175
- "ox": "0.1.2",
180
+ "ox": "0.4.4",
176
181
  "webauthn-p256": "0.0.10",
177
182
  "ws": "8.18.0"
178
183
  },
package/types/calls.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { AbiStateMutability, Address } from 'abitype'
2
+ import type { Hex } from './misc.js'
3
+ import type { GetMulticallContractParameters } from './multicall.js'
4
+ import type { OneOf, Prettify } from './utils.js'
5
+
6
+ export type Call<call = unknown> = OneOf<
7
+ | {
8
+ data?: Hex | undefined
9
+ to: Address
10
+ value?: bigint | undefined
11
+ }
12
+ | (Omit<
13
+ GetMulticallContractParameters<call, AbiStateMutability>,
14
+ 'address'
15
+ > & {
16
+ to: Address
17
+ value?: bigint | undefined
18
+ })
19
+ >
20
+
21
+ export type Calls<
22
+ calls extends readonly unknown[],
23
+ ///
24
+ result extends readonly any[] = [],
25
+ > = calls extends readonly [] // no calls, return empty
26
+ ? readonly []
27
+ : calls extends readonly [infer call] // one call left before returning `result`
28
+ ? readonly [...result, Prettify<Call<call>>]
29
+ : calls extends readonly [infer call, ...infer rest] // grab first call and recurse through `rest`
30
+ ? Calls<[...rest], [...result, Prettify<Call<call>>]>
31
+ : readonly unknown[] extends calls
32
+ ? calls
33
+ : // If `calls` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
34
+ // use this to infer the param types in the case of Array.map() argument
35
+ calls extends readonly (infer call extends OneOf<Call>)[]
36
+ ? readonly Prettify<call>[]
37
+ : // Fallback
38
+ readonly OneOf<Call>[]
@@ -7,7 +7,10 @@ import type { Transport } from '../../clients/transports/createTransport.js'
7
7
  import type { ErrorType } from '../../errors/utils.js'
8
8
  import type { ContractConstructorArgs } from '../../types/contract.js'
9
9
  import type { Hash, Hex } from '../../types/misc.js'
10
- import { contractDeployerAddress } from '../constants/address.js'
10
+ import {
11
+ contract2FactoryAddress,
12
+ contractDeployerAddress,
13
+ } from '../constants/address.js'
11
14
  import type { ChainEIP712 } from '../types/chain.js'
12
15
  import type { ContractDeploymentType } from '../types/contract.js'
13
16
  import {
@@ -45,7 +48,7 @@ export type DeployContractErrorType =
45
48
  *
46
49
  * - Docs: https://viem.sh/docs/contract/deployContract
47
50
  *
48
- * @param client - Client to use
51
+ * @param walletClient - Client to use
49
52
  * @param parameters - {@link DeployContractParameters}
50
53
  * @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
51
54
  *
@@ -97,7 +100,10 @@ export function deployContract<
97
100
  return sendEip712Transaction(walletClient, {
98
101
  ...request,
99
102
  data,
100
- to: contractDeployerAddress,
103
+ to:
104
+ deploymentType === 'create2' || deploymentType === 'create2Account'
105
+ ? contract2FactoryAddress
106
+ : contractDeployerAddress,
101
107
  } as unknown as SendEip712TransactionParameters<
102
108
  chain,
103
109
  account,
@@ -0,0 +1,59 @@
1
+ import type { Address } from '../../accounts/index.js'
2
+ import { readContract } from '../../actions/public/readContract.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { Account } from '../../types/account.js'
6
+ import type { Chain } from '../../types/chain.js'
7
+ import { isAddressEqual } from '../../utils/index.js'
8
+ import { l2SharedBridgeAbi } from '../constants/abis.js'
9
+ import { legacyEthAddress } from '../constants/address.js'
10
+ import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
11
+
12
+ export type GetL1TokenAddressParameters = {
13
+ /** The address of the token on L2. */
14
+ token: Address
15
+ }
16
+
17
+ export type GetL1TokenAddressReturnType = Address
18
+
19
+ /**
20
+ * Returns the L1 token address equivalent for a L2 token address as they are not equal.
21
+ * ETH address is set to zero address.
22
+ *
23
+ * @remarks Only works for tokens bridged on default ZKsync Era bridges.
24
+ *
25
+ * @param client - Client to use
26
+ * @param parameters - {@link GetL1TokenAddressParameters}
27
+ * @returns The L1 token address equivalent for a L2 token address.
28
+ *
29
+ *
30
+ * @example
31
+ * import { createPublicClient, http } from 'viem'
32
+ * import { zksync } from 'viem/chains'
33
+ *
34
+ * const client = createPublicClient({
35
+ * chain: zksync,
36
+ * transport: http(),
37
+ * })
38
+ *
39
+ * const address = await getL1TokenAddress(client, {token: '0x...'});
40
+ */
41
+ export async function getL1TokenAddress<
42
+ chain extends Chain | undefined,
43
+ account extends Account | undefined,
44
+ >(
45
+ client: Client<Transport, chain, account>,
46
+ parameters: GetL1TokenAddressParameters,
47
+ ): Promise<Address> {
48
+ const { token } = parameters
49
+ if (isAddressEqual(token, legacyEthAddress)) return legacyEthAddress
50
+
51
+ const bridgeAddress = (await getDefaultBridgeAddresses(client)).sharedL2
52
+
53
+ return await readContract(client, {
54
+ address: bridgeAddress,
55
+ abi: l2SharedBridgeAbi,
56
+ functionName: 'l1TokenAddress',
57
+ args: [token],
58
+ })
59
+ }
@@ -0,0 +1,70 @@
1
+ import type { Address } from '../../accounts/index.js'
2
+ import { readContract } from '../../actions/public/readContract.js'
3
+ import type { Client } from '../../clients/createClient.js'
4
+ import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { Account } from '../../types/account.js'
6
+ import type { Chain } from '../../types/chain.js'
7
+ import { isAddressEqual } from '../../utils/index.js'
8
+ import { l2SharedBridgeAbi } from '../constants/abis.js'
9
+ import {
10
+ ethAddressInContracts,
11
+ l2BaseTokenAddress,
12
+ legacyEthAddress,
13
+ } from '../constants/address.js'
14
+ import { getBaseTokenL1Address } from './getBaseTokenL1Address.js'
15
+ import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
16
+
17
+ export type GetL2TokenAddressParameters = {
18
+ /** The address of the token on L1. */
19
+ token: Address
20
+ /** The address of custom bridge, which will be used to get l2 token address. */
21
+ bridgeAddress?: Address | undefined
22
+ }
23
+
24
+ export type GetL2TokenAddressReturnType = Address
25
+
26
+ /**
27
+ * Returns the L2 token address equivalent for a L1 token address as they are not equal.
28
+ * ETH address is set to zero address.
29
+ *
30
+ * @remarks Only works for tokens bridged on default ZKsync Era bridges.
31
+ *
32
+ * @param client - Client to use
33
+ * @param parameters - {@link GetL2TokenAddressParameters}
34
+ * @returns The L2 token address equivalent for a L1 token address.
35
+ *
36
+ *
37
+ * @example
38
+ * import { createPublicClient, http } from 'viem'
39
+ * import { zksync } from 'viem/chains'
40
+ * import { publicActionsL2 } from 'viem/zksync'
41
+ *
42
+ * const client = createPublicClient({
43
+ * chain: zksync,
44
+ * transport: http(),
45
+ * }).extend(publicActionsL2())
46
+ *
47
+ * const address = await getL2TokenAddress(client, {token: '0x...'});
48
+ */
49
+ export async function getL2TokenAddress<
50
+ chain extends Chain | undefined,
51
+ account extends Account | undefined,
52
+ >(
53
+ client: Client<Transport, chain, account>,
54
+ parameters: GetL2TokenAddressParameters,
55
+ ): Promise<Address> {
56
+ let { token, bridgeAddress } = parameters
57
+ if (isAddressEqual(token, legacyEthAddress)) token = ethAddressInContracts
58
+
59
+ const baseToken = await getBaseTokenL1Address(client)
60
+ if (isAddressEqual(token, baseToken)) return l2BaseTokenAddress
61
+
62
+ bridgeAddress ??= (await getDefaultBridgeAddresses(client)).sharedL2
63
+
64
+ return await readContract(client, {
65
+ address: bridgeAddress,
66
+ abi: l2SharedBridgeAbi,
67
+ functionName: 'l2TokenAddress',
68
+ args: [token],
69
+ })
70
+ }
@@ -92,13 +92,15 @@ export async function sendEip712Transaction<
92
92
  request
93
93
  >,
94
94
  ): Promise<SendEip712TransactionReturnType> {
95
- const { chain = client.chain } = parameters
95
+ const { account: account_ = client.account, chain = client.chain } =
96
+ parameters
96
97
 
97
- if (!parameters.account)
98
+ const account = account_ ? parseAccount(account_) : client.account
99
+
100
+ if (!account)
98
101
  throw new AccountNotFoundError({
99
102
  docsPath: '/docs/actions/wallet/sendTransaction',
100
103
  })
101
- const account = parseAccount(parameters.account)
102
104
 
103
105
  try {
104
106
  assertEip712Request(parameters)
@@ -53,6 +53,8 @@ export type SignEip712TransactionErrorType = SignTransactionErrorType
53
53
  /**
54
54
  * Signs an EIP712 transaction.
55
55
  *
56
+ *
57
+ * @param client - Client to use
56
58
  * @param args - {@link SignTransactionParameters}
57
59
  * @returns The signed serialized transaction. {@link SignTransactionReturnType}
58
60
  *
@@ -102,11 +104,12 @@ export async function signEip712Transaction<
102
104
  ...transaction
103
105
  } = args
104
106
 
105
- if (!account_)
107
+ const account = account_ ? parseAccount(account_) : client.account
108
+
109
+ if (!account)
106
110
  throw new AccountNotFoundError({
107
111
  docsPath: '/docs/actions/wallet/signTransaction',
108
112
  })
109
- const account = parseAccount(account_)
110
113
 
111
114
  assertEip712Request({
112
115
  account,
@@ -461,3 +461,188 @@ export const paymasterAbi = [
461
461
  type: 'function',
462
462
  },
463
463
  ]
464
+
465
+ export const l2SharedBridgeAbi = [
466
+ {
467
+ anonymous: false,
468
+ inputs: [
469
+ {
470
+ indexed: true,
471
+ internalType: 'address',
472
+ name: 'l1Sender',
473
+ type: 'address',
474
+ },
475
+ {
476
+ indexed: true,
477
+ internalType: 'address',
478
+ name: 'l2Receiver',
479
+ type: 'address',
480
+ },
481
+ {
482
+ indexed: true,
483
+ internalType: 'address',
484
+ name: 'l2Token',
485
+ type: 'address',
486
+ },
487
+ {
488
+ indexed: false,
489
+ internalType: 'uint256',
490
+ name: 'amount',
491
+ type: 'uint256',
492
+ },
493
+ ],
494
+ name: 'FinalizeDeposit',
495
+ type: 'event',
496
+ },
497
+ {
498
+ anonymous: false,
499
+ inputs: [
500
+ {
501
+ indexed: true,
502
+ internalType: 'address',
503
+ name: 'l2Sender',
504
+ type: 'address',
505
+ },
506
+ {
507
+ indexed: true,
508
+ internalType: 'address',
509
+ name: 'l1Receiver',
510
+ type: 'address',
511
+ },
512
+ {
513
+ indexed: true,
514
+ internalType: 'address',
515
+ name: 'l2Token',
516
+ type: 'address',
517
+ },
518
+ {
519
+ indexed: false,
520
+ internalType: 'uint256',
521
+ name: 'amount',
522
+ type: 'uint256',
523
+ },
524
+ ],
525
+ name: 'WithdrawalInitiated',
526
+ type: 'event',
527
+ },
528
+ {
529
+ inputs: [
530
+ {
531
+ internalType: 'address',
532
+ name: '_l1Sender',
533
+ type: 'address',
534
+ },
535
+ {
536
+ internalType: 'address',
537
+ name: '_l2Receiver',
538
+ type: 'address',
539
+ },
540
+ {
541
+ internalType: 'address',
542
+ name: '_l1Token',
543
+ type: 'address',
544
+ },
545
+ {
546
+ internalType: 'uint256',
547
+ name: '_amount',
548
+ type: 'uint256',
549
+ },
550
+ {
551
+ internalType: 'bytes',
552
+ name: '_data',
553
+ type: 'bytes',
554
+ },
555
+ ],
556
+ name: 'finalizeDeposit',
557
+ outputs: [],
558
+ stateMutability: 'nonpayable',
559
+ type: 'function',
560
+ },
561
+ {
562
+ inputs: [],
563
+ name: 'l1Bridge',
564
+ outputs: [
565
+ {
566
+ internalType: 'address',
567
+ name: '',
568
+ type: 'address',
569
+ },
570
+ ],
571
+ stateMutability: 'view',
572
+ type: 'function',
573
+ },
574
+ {
575
+ inputs: [],
576
+ name: 'l1SharedBridge',
577
+ outputs: [
578
+ {
579
+ internalType: 'address',
580
+ name: '',
581
+ type: 'address',
582
+ },
583
+ ],
584
+ stateMutability: 'view',
585
+ type: 'function',
586
+ },
587
+ {
588
+ inputs: [
589
+ {
590
+ internalType: 'address',
591
+ name: '_l2Token',
592
+ type: 'address',
593
+ },
594
+ ],
595
+ name: 'l1TokenAddress',
596
+ outputs: [
597
+ {
598
+ internalType: 'address',
599
+ name: '',
600
+ type: 'address',
601
+ },
602
+ ],
603
+ stateMutability: 'view',
604
+ type: 'function',
605
+ },
606
+ {
607
+ inputs: [
608
+ {
609
+ internalType: 'address',
610
+ name: '_l1Token',
611
+ type: 'address',
612
+ },
613
+ ],
614
+ name: 'l2TokenAddress',
615
+ outputs: [
616
+ {
617
+ internalType: 'address',
618
+ name: '',
619
+ type: 'address',
620
+ },
621
+ ],
622
+ stateMutability: 'view',
623
+ type: 'function',
624
+ },
625
+ {
626
+ inputs: [
627
+ {
628
+ internalType: 'address',
629
+ name: '_l1Receiver',
630
+ type: 'address',
631
+ },
632
+ {
633
+ internalType: 'address',
634
+ name: '_l2Token',
635
+ type: 'address',
636
+ },
637
+ {
638
+ internalType: 'uint256',
639
+ name: '_amount',
640
+ type: 'uint256',
641
+ },
642
+ ],
643
+ name: 'withdraw',
644
+ outputs: [],
645
+ stateMutability: 'nonpayable',
646
+ type: 'function',
647
+ },
648
+ ] as const
@@ -1,6 +1,9 @@
1
1
  export const contractDeployerAddress =
2
2
  '0x0000000000000000000000000000000000008006' as const
3
3
 
4
+ export const contract2FactoryAddress =
5
+ '0x0000000000000000000000000000000000010000' as const
6
+
4
7
  export const legacyEthAddress =
5
8
  '0x0000000000000000000000000000000000000000' as const
6
9
 
@@ -52,6 +52,16 @@ import {
52
52
  type GetL1ChainIdReturnType,
53
53
  getL1ChainId,
54
54
  } from '../actions/getL1ChainId.js'
55
+ import {
56
+ type GetL1TokenAddressParameters,
57
+ type GetL1TokenAddressReturnType,
58
+ getL1TokenAddress,
59
+ } from '../actions/getL1TokenAddress.js'
60
+ import {
61
+ type GetL2TokenAddressParameters,
62
+ type GetL2TokenAddressReturnType,
63
+ getL2TokenAddress,
64
+ } from '../actions/getL2TokenAddress.js'
55
65
  import {
56
66
  type GetLogProofParameters,
57
67
  type GetLogProofReturnType,
@@ -411,6 +421,56 @@ export type PublicActionsL2<
411
421
  * const address = await client.getBaseTokenL1Address();
412
422
  */
413
423
  getBaseTokenL1Address: () => Promise<GetBaseTokenL1AddressReturnType>
424
+
425
+ /**
426
+ * Returns the L2 token address equivalent for a L1 token address as they are not equal.
427
+ * ETH address is set to zero address.
428
+ *
429
+ * @remarks Only works for tokens bridged on default ZKsync Era bridges.
430
+ *
431
+ * @param args - {@link GetL2TokenAddressParameters}
432
+ * @returns The L2 token address equivalent for a L1 token address.
433
+ *
434
+ * @example
435
+ * import { createPublicClient, http } from 'viem'
436
+ * import { zksync } from 'viem/chains'
437
+ * import { publicActionsL2 } from 'viem/zksync'
438
+ *
439
+ * const client = createPublicClient({
440
+ * chain: zksync,
441
+ * transport: http(),
442
+ * }).extend(publicActionsL2())
443
+ *
444
+ * const address = await client.getL2TokenAddress({token: '0x...'});
445
+ */
446
+ getL2TokenAddress: (
447
+ args: GetL2TokenAddressParameters,
448
+ ) => Promise<GetL2TokenAddressReturnType>
449
+
450
+ /**
451
+ * Returns the L1 token address equivalent for a L2 token address as they are not equal.
452
+ * ETH address is set to zero address.
453
+ *
454
+ * @remarks Only works for tokens bridged on default ZKsync Era bridges.
455
+ *
456
+ * @param args - {@link GetL1TokenAddressParameters}
457
+ * @returns The L1 token address equivalent for a L2 token address.
458
+ *
459
+ * @example
460
+ * import { createPublicClient, http } from 'viem'
461
+ * import { zksync } from 'viem/chains'
462
+ * import { publicActionsL2 } from 'viem/zksync'
463
+ *
464
+ * const client = createPublicClient({
465
+ * chain: zksync,
466
+ * transport: http(),
467
+ * }).extend(publicActionsL2())
468
+ *
469
+ * const address = await client.getL1TokenAddress({token: '0x...'});
470
+ */
471
+ getL1TokenAddress: (
472
+ args: GetL1TokenAddressParameters,
473
+ ) => Promise<GetL1TokenAddressReturnType>
414
474
  }
415
475
 
416
476
  export function publicActionsL2() {
@@ -438,6 +498,8 @@ export function publicActionsL2() {
438
498
  estimateFee: (args) => estimateFee(client, args),
439
499
  getBridgehubContractAddress: () => getBridgehubContractAddress(client),
440
500
  getBaseTokenL1Address: () => getBaseTokenL1Address(client),
501
+ getL2TokenAddress: (args) => getL2TokenAddress(client, args),
502
+ getL1TokenAddress: (args) => getL1TokenAddress(client, args),
441
503
  }
442
504
  }
443
505
  }
package/zksync/index.ts CHANGED
@@ -119,6 +119,16 @@ export {
119
119
  type SignTransactionReturnType,
120
120
  signTransaction,
121
121
  } from './actions/signTransaction.js'
122
+ export {
123
+ type GetL2TokenAddressReturnType,
124
+ type GetL2TokenAddressParameters,
125
+ getL2TokenAddress,
126
+ } from './actions/getL2TokenAddress.js'
127
+ export {
128
+ type GetL1TokenAddressReturnType,
129
+ type GetL1TokenAddressParameters,
130
+ getL1TokenAddress,
131
+ } from './actions/getL1TokenAddress.js'
122
132
 
123
133
  export {
124
134
  /** @deprecated Use `zksync` instead */