viem 2.9.29 → 2.9.30

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 (96) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/_cjs/chains/definitions/otimDevnet.js +24 -0
  3. package/_cjs/chains/definitions/otimDevnet.js.map +1 -0
  4. package/_cjs/chains/definitions/telcoinTestnet.js +22 -0
  5. package/_cjs/chains/definitions/telcoinTestnet.js.map +1 -0
  6. package/_cjs/chains/index.js +7 -3
  7. package/_cjs/chains/index.js.map +1 -1
  8. package/_cjs/errors/version.js +1 -1
  9. package/_cjs/experimental/eip3074/constants/abis.js +123 -0
  10. package/_cjs/experimental/eip3074/constants/abis.js.map +1 -0
  11. package/_cjs/experimental/eip3074/invokers/coders/batchInvokerCoder.js +26 -0
  12. package/_cjs/experimental/eip3074/invokers/coders/batchInvokerCoder.js.map +1 -0
  13. package/_cjs/experimental/eip3074/invokers/coders/defineInvokerCoder.js +8 -0
  14. package/_cjs/experimental/eip3074/invokers/coders/defineInvokerCoder.js.map +1 -0
  15. package/_cjs/experimental/eip3074/invokers/getInvoker.js +64 -0
  16. package/_cjs/experimental/eip3074/invokers/getInvoker.js.map +1 -0
  17. package/_cjs/experimental/index.js +7 -1
  18. package/_cjs/experimental/index.js.map +1 -1
  19. package/_cjs/zksync/constants/abis.js +39 -1
  20. package/_cjs/zksync/constants/abis.js.map +1 -1
  21. package/_cjs/zksync/index.js +5 -1
  22. package/_cjs/zksync/index.js.map +1 -1
  23. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +16 -0
  24. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -0
  25. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js +16 -0
  26. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -0
  27. package/_esm/chains/definitions/otimDevnet.js +21 -0
  28. package/_esm/chains/definitions/otimDevnet.js.map +1 -0
  29. package/_esm/chains/definitions/telcoinTestnet.js +19 -0
  30. package/_esm/chains/definitions/telcoinTestnet.js.map +1 -0
  31. package/_esm/chains/index.js +2 -0
  32. package/_esm/chains/index.js.map +1 -1
  33. package/_esm/errors/version.js +1 -1
  34. package/_esm/experimental/eip3074/constants/abis.js +120 -0
  35. package/_esm/experimental/eip3074/constants/abis.js.map +1 -0
  36. package/_esm/experimental/eip3074/invokers/coders/batchInvokerCoder.js +22 -0
  37. package/_esm/experimental/eip3074/invokers/coders/batchInvokerCoder.js.map +1 -0
  38. package/_esm/experimental/eip3074/invokers/coders/defineInvokerCoder.js +4 -0
  39. package/_esm/experimental/eip3074/invokers/coders/defineInvokerCoder.js.map +1 -0
  40. package/_esm/experimental/eip3074/invokers/getInvoker.js +60 -0
  41. package/_esm/experimental/eip3074/invokers/getInvoker.js.map +1 -0
  42. package/_esm/experimental/index.js +3 -0
  43. package/_esm/experimental/index.js.map +1 -1
  44. package/_esm/zksync/constants/abis.js +38 -0
  45. package/_esm/zksync/constants/abis.js.map +1 -1
  46. package/_esm/zksync/index.js +2 -0
  47. package/_esm/zksync/index.js.map +1 -1
  48. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +13 -0
  49. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -0
  50. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js +12 -0
  51. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -0
  52. package/_types/accounts/types.d.ts +1 -1
  53. package/_types/accounts/types.d.ts.map +1 -1
  54. package/_types/chains/definitions/otimDevnet.d.ts +38 -0
  55. package/_types/chains/definitions/otimDevnet.d.ts.map +1 -0
  56. package/_types/chains/definitions/telcoinTestnet.d.ts +35 -0
  57. package/_types/chains/definitions/telcoinTestnet.d.ts.map +1 -0
  58. package/_types/chains/index.d.ts +2 -0
  59. package/_types/chains/index.d.ts.map +1 -1
  60. package/_types/errors/version.d.ts +1 -1
  61. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts +5 -5
  62. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts.map +1 -1
  63. package/_types/experimental/eip3074/constants/abis.d.ts +91 -0
  64. package/_types/experimental/eip3074/constants/abis.d.ts.map +1 -0
  65. package/_types/experimental/eip3074/invokers/coders/batchInvokerCoder.d.ts +11 -0
  66. package/_types/experimental/eip3074/invokers/coders/batchInvokerCoder.d.ts.map +1 -0
  67. package/_types/experimental/eip3074/invokers/coders/defineInvokerCoder.d.ts +14 -0
  68. package/_types/experimental/eip3074/invokers/coders/defineInvokerCoder.d.ts.map +1 -0
  69. package/_types/experimental/eip3074/invokers/getInvoker.d.ts +48 -0
  70. package/_types/experimental/eip3074/invokers/getInvoker.d.ts.map +1 -0
  71. package/_types/experimental/index.d.ts +3 -0
  72. package/_types/experimental/index.d.ts.map +1 -1
  73. package/_types/zksync/constants/abis.d.ts +11 -0
  74. package/_types/zksync/constants/abis.d.ts.map +1 -1
  75. package/_types/zksync/index.d.ts +2 -0
  76. package/_types/zksync/index.d.ts.map +1 -1
  77. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts +11 -0
  78. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts.map +1 -0
  79. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts +8 -0
  80. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts.map +1 -0
  81. package/accounts/types.ts +1 -1
  82. package/chains/definitions/otimDevnet.ts +21 -0
  83. package/chains/definitions/telcoinTestnet.ts +19 -0
  84. package/chains/index.ts +2 -0
  85. package/errors/version.ts +1 -1
  86. package/experimental/eip3074/actions/signAuthMessage.ts +5 -5
  87. package/experimental/eip3074/constants/abis.ts +119 -0
  88. package/experimental/eip3074/invokers/coders/batchInvokerCoder.ts +46 -0
  89. package/experimental/eip3074/invokers/coders/defineInvokerCoder.ts +20 -0
  90. package/experimental/eip3074/invokers/getInvoker.ts +192 -0
  91. package/experimental/index.ts +21 -0
  92. package/package.json +1 -1
  93. package/zksync/constants/abis.ts +39 -0
  94. package/zksync/index.ts +11 -0
  95. package/zksync/utils/paymaster/getApprovalBasedPaymasterInput.ts +29 -0
  96. package/zksync/utils/paymaster/getGeneralPaymasterInput.ts +25 -0
@@ -0,0 +1,46 @@
1
+ import type { Address } from 'abitype'
2
+ import { readContract } from '../../../../actions/public/readContract.js'
3
+ import type { Hex } from '../../../../types/misc.js'
4
+ import { encodeAbiParameters } from '../../../../utils/abi/encodeAbiParameters.js'
5
+ import { encodePacked } from '../../../../utils/abi/encodePacked.js'
6
+ import { concat } from '../../../../utils/data/concat.js'
7
+ import { size } from '../../../../utils/data/size.js'
8
+ import { invokerAbi } from '../../constants/abis.js'
9
+ import { defineInvokerCoder } from './defineInvokerCoder.js'
10
+
11
+ type Calls = readonly {
12
+ to: Address
13
+ data?: Hex | undefined
14
+ value?: bigint | undefined
15
+ }[]
16
+
17
+ export type BatchInvokerArgs = Calls
18
+
19
+ export function batchInvokerCoder() {
20
+ return defineInvokerCoder({
21
+ async toExecData(
22
+ args: BatchInvokerArgs,
23
+ { authority, client, invokerAddress },
24
+ ) {
25
+ const nonce = await readContract(client, {
26
+ abi: invokerAbi,
27
+ address: invokerAddress,
28
+ functionName: 'nextNonce',
29
+ args: [authority],
30
+ })
31
+
32
+ const calls = concat(
33
+ args.map(({ data = '0x', to, value = 0n }) =>
34
+ encodePacked(
35
+ ['uint8', 'address', 'uint256', 'uint256', 'bytes'],
36
+ [2, to, value, BigInt(size(data)), data],
37
+ ),
38
+ ),
39
+ )
40
+ return encodeAbiParameters(
41
+ [{ type: 'uint256' }, { type: 'bytes' }],
42
+ [nonce, calls],
43
+ )
44
+ },
45
+ })
46
+ }
@@ -0,0 +1,20 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Client } from '../../../../clients/createClient.js'
3
+ import type { Hex } from '../../../../types/misc.js'
4
+
5
+ export type InvokerCoder<args = unknown> = {
6
+ toExecData: (
7
+ args: args,
8
+ options: { authority: Address; client: Client; invokerAddress: Hex },
9
+ ) => Promise<Hex>
10
+ }
11
+
12
+ export type DefineInvokerCoderParameters<args = unknown> = InvokerCoder<args>
13
+
14
+ export type DefineInvokerCoderReturnType<args = unknown> = InvokerCoder<args>
15
+
16
+ export function defineInvokerCoder<args>(
17
+ parameters: DefineInvokerCoderParameters<args>,
18
+ ): DefineInvokerCoderReturnType<args> {
19
+ return parameters
20
+ }
@@ -0,0 +1,192 @@
1
+ import type { Address } from 'abitype'
2
+ import {
3
+ type GetTransactionCountErrorType,
4
+ getTransactionCount,
5
+ } from '../../../actions/public/getTransactionCount.js'
6
+ import {
7
+ type WriteContractErrorType,
8
+ writeContract,
9
+ } from '../../../actions/wallet/writeContract.js'
10
+ import type { Client } from '../../../clients/createClient.js'
11
+ import type { Transport } from '../../../clients/transports/createTransport.js'
12
+ import type { ErrorType } from '../../../errors/utils.js'
13
+ import type { Account, LocalAccount } from '../../../types/account.js'
14
+ import type { Chain, GetChainParameter } from '../../../types/chain.js'
15
+ import type { Hex } from '../../../types/misc.js'
16
+ import type { IsUndefined } from '../../../types/utils.js'
17
+ import { parseAccount } from '../../../utils/accounts.js'
18
+ import {
19
+ type IsAddressEqualErrorType,
20
+ isAddressEqual,
21
+ } from '../../../utils/address/isAddressEqual.js'
22
+ import { getAction } from '../../../utils/getAction.js'
23
+ import {
24
+ type Keccak256ErrorType,
25
+ keccak256,
26
+ } from '../../../utils/hash/keccak256.js'
27
+ import {
28
+ type HexToSignatureErrorType,
29
+ hexToSignature,
30
+ } from '../../../utils/signature/hexToSignature.js'
31
+ import {
32
+ type SignAuthMessageErrorType,
33
+ signAuthMessage,
34
+ } from '../actions/signAuthMessage.js'
35
+ import { invokerAbi } from '../constants/abis.js'
36
+ import type { InvokerCoder } from './coders/defineInvokerCoder.js'
37
+
38
+ type GetExecutorParameter<
39
+ TAccount extends Account | undefined = Account | undefined,
40
+ TAccountOverride extends Account | Address | undefined = Account | Address,
41
+ TRequired extends boolean = true,
42
+ > = IsUndefined<TAccount> extends true
43
+ ? TRequired extends true
44
+ ? { executor: TAccountOverride | Account | Address }
45
+ : { executor?: TAccountOverride | Account | Address | undefined }
46
+ : { executor?: TAccountOverride | Account | Address | undefined }
47
+
48
+ export type InvokerExecuteParameters<
49
+ account extends Account | undefined = Account | undefined,
50
+ chain extends Chain | undefined = Chain | undefined,
51
+ chainOverride extends Chain | undefined = Chain | undefined,
52
+ args = unknown,
53
+ > = {
54
+ args: args
55
+ authority: Account | Address
56
+ signature: Hex
57
+ } & GetExecutorParameter<account> &
58
+ GetChainParameter<chain, chainOverride>
59
+
60
+ export type InvokerExecuteErrorType =
61
+ | WriteContractErrorType
62
+ | HexToSignatureErrorType
63
+ | ErrorType
64
+
65
+ export type InvokerSignParameters<
66
+ account extends Account | undefined = Account | undefined,
67
+ chain extends Chain | undefined = Chain | undefined,
68
+ chainOverride extends Chain | undefined = Chain | undefined,
69
+ args = unknown,
70
+ > = {
71
+ args: args
72
+ authority: LocalAccount
73
+ } & GetExecutorParameter<account, Account | Address, false> &
74
+ GetChainParameter<chain, chainOverride>
75
+
76
+ export type InvokerSignErrorType =
77
+ | GetTransactionCountErrorType
78
+ | SignAuthMessageErrorType
79
+ | Keccak256ErrorType
80
+ | IsAddressEqualErrorType
81
+ | ErrorType
82
+
83
+ export type Invoker<
84
+ account extends Account | undefined = Account | undefined,
85
+ chain extends Chain | undefined = Chain | undefined,
86
+ args = unknown,
87
+ > = {
88
+ address: Address
89
+ execute<chainOverride extends Chain | undefined = undefined>(
90
+ parameters: InvokerExecuteParameters<account, chain, chainOverride, args>,
91
+ ): Promise<Hex>
92
+ sign<chainOverride extends Chain | undefined = undefined>(
93
+ parameters: InvokerSignParameters<account, chain, chainOverride, args>,
94
+ ): Promise<Hex>
95
+ }
96
+
97
+ export type GetInvokerParameters<
98
+ account extends Account | undefined = Account | undefined,
99
+ chain extends Chain | undefined = Chain | undefined,
100
+ args = unknown,
101
+ > = {
102
+ address: Address
103
+ client: Client<Transport, chain, account>
104
+ coder: InvokerCoder<args>
105
+ }
106
+
107
+ export type GetInvokerErrorType = ErrorType
108
+
109
+ export type InvokerArgs<invoker extends Invoker<any, any, any> = Invoker> =
110
+ invoker extends Invoker<any, any, infer args> ? args : unknown
111
+
112
+ export function getInvoker<
113
+ account extends Account | undefined,
114
+ chain extends Chain | undefined,
115
+ args,
116
+ >(
117
+ parameters: GetInvokerParameters<account, chain, args>,
118
+ ): Invoker<account, chain, args> {
119
+ const { address, client, coder } = parameters
120
+ return {
121
+ address,
122
+ async execute(parameters) {
123
+ const {
124
+ executor: executor_ = client.account,
125
+ authority: authority_,
126
+ args,
127
+ chain = client.chain,
128
+ signature,
129
+ } = parameters
130
+ const authority = parseAccount(authority_!)
131
+ const executor = parseAccount(executor_!)
132
+
133
+ const execData = await coder.toExecData(args, {
134
+ authority: authority.address,
135
+ client,
136
+ invokerAddress: address,
137
+ })
138
+
139
+ const { r, s, yParity } = hexToSignature(signature)
140
+ return getAction(
141
+ client,
142
+ writeContract,
143
+ 'writeContract',
144
+ )({
145
+ abi: invokerAbi,
146
+ address,
147
+ account: executor,
148
+ chain,
149
+ functionName: 'execute',
150
+ args: [execData, { signer: authority.address, r, s, yParity }],
151
+ })
152
+ },
153
+ async sign(parameters) {
154
+ const {
155
+ args,
156
+ authority,
157
+ executor: executor_ = client.account,
158
+ chain = client.chain,
159
+ } = parameters
160
+ const executor = parseAccount(executor_!)
161
+ const [execData, nonce] = await Promise.all([
162
+ await coder.toExecData(args, {
163
+ authority: authority.address,
164
+ client,
165
+ invokerAddress: address,
166
+ }),
167
+ getAction(
168
+ client,
169
+ getTransactionCount,
170
+ 'getTransactionCount',
171
+ )({
172
+ address: authority.address,
173
+ blockTag: 'pending',
174
+ }),
175
+ ])
176
+ const signature = await getAction(
177
+ client,
178
+ signAuthMessage,
179
+ 'signAuthMessage',
180
+ )({
181
+ account: authority,
182
+ chain,
183
+ commit: keccak256(execData),
184
+ invokerAddress: address,
185
+ nonce: isAddressEqual(authority.address, executor.address)
186
+ ? nonce + 1
187
+ : nonce,
188
+ })
189
+ return signature
190
+ },
191
+ }
192
+ }
@@ -20,6 +20,27 @@ export {
20
20
  type WalletActionsEip3074,
21
21
  walletActionsEip3074,
22
22
  } from './eip3074/decorators/eip3074.js'
23
+ export {
24
+ type GetInvokerErrorType,
25
+ type GetInvokerParameters,
26
+ type Invoker,
27
+ type InvokerArgs,
28
+ type InvokerExecuteErrorType,
29
+ type InvokerExecuteParameters,
30
+ type InvokerSignErrorType,
31
+ type InvokerSignParameters,
32
+ getInvoker,
33
+ } from './eip3074/invokers/getInvoker.js'
34
+ export {
35
+ type BatchInvokerArgs,
36
+ batchInvokerCoder,
37
+ } from './eip3074/invokers/coders/batchInvokerCoder.js'
38
+ export {
39
+ type DefineInvokerCoderParameters,
40
+ type DefineInvokerCoderReturnType,
41
+ type InvokerCoder,
42
+ defineInvokerCoder,
43
+ } from './eip3074/invokers/coders/defineInvokerCoder.js'
23
44
 
24
45
  export {
25
46
  type GetCapabilitiesErrorType,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.9.29",
4
+ "version": "2.9.30",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -422,3 +422,42 @@ export const contractDeployerAbi = [
422
422
  type: 'function',
423
423
  },
424
424
  ]
425
+
426
+ export const paymasterAbi = [
427
+ {
428
+ inputs: [
429
+ {
430
+ internalType: 'address',
431
+ name: '_token',
432
+ type: 'address',
433
+ },
434
+ {
435
+ internalType: 'uint256',
436
+ name: '_minAllowance',
437
+ type: 'uint256',
438
+ },
439
+ {
440
+ internalType: 'bytes',
441
+ name: '_innerInput',
442
+ type: 'bytes',
443
+ },
444
+ ],
445
+ name: 'approvalBased',
446
+ outputs: [],
447
+ stateMutability: 'nonpayable',
448
+ type: 'function',
449
+ },
450
+ {
451
+ inputs: [
452
+ {
453
+ internalType: 'bytes',
454
+ name: 'input',
455
+ type: 'bytes',
456
+ },
457
+ ],
458
+ name: 'general',
459
+ outputs: [],
460
+ stateMutability: 'nonpayable',
461
+ type: 'function',
462
+ },
463
+ ]
package/zksync/index.ts CHANGED
@@ -84,3 +84,14 @@ export type {
84
84
  ZkSyncTransactionSerializedEIP712,
85
85
  ZkSyncTransactionType,
86
86
  } from './types/transaction.js'
87
+
88
+ export {
89
+ type GetApprovalBasedPaymasterInputParameters,
90
+ type GetApprovalBasedPaymasterInputReturnType,
91
+ getApprovalBasedPaymasterInput,
92
+ } from './utils/paymaster/getApprovalBasedPaymasterInput.js'
93
+ export {
94
+ type GetGeneralPaymasterInputParameters,
95
+ type GetGeneralPaymasterInputReturnType,
96
+ getGeneralPaymasterInput,
97
+ } from './utils/paymaster/getGeneralPaymasterInput.js'
@@ -0,0 +1,29 @@
1
+ import { type Address } from 'abitype'
2
+ import type { ByteArray, Hex } from '../../../types/misc.js'
3
+ import type { EncodeFunctionDataReturnType } from '../../../utils/abi/encodeFunctionData.js'
4
+ import { bytesToHex, encodeFunctionData } from '../../../utils/index.js'
5
+ import { paymasterAbi } from '../../constants/abis.js'
6
+
7
+ export type GetApprovalBasedPaymasterInputParameters = {
8
+ innerInput: Hex | ByteArray
9
+ minAllowance: bigint
10
+ token: Address
11
+ }
12
+
13
+ export type GetApprovalBasedPaymasterInputReturnType =
14
+ EncodeFunctionDataReturnType
15
+
16
+ export function getApprovalBasedPaymasterInput(
17
+ parameters: GetApprovalBasedPaymasterInputParameters,
18
+ ): GetApprovalBasedPaymasterInputReturnType {
19
+ const { innerInput, minAllowance, token } = parameters
20
+
21
+ const innerInputHex =
22
+ typeof innerInput === 'string' ? innerInput : bytesToHex(innerInput)
23
+
24
+ return encodeFunctionData({
25
+ abi: paymasterAbi,
26
+ functionName: 'approvalBased',
27
+ args: [token, minAllowance, innerInputHex],
28
+ })
29
+ }
@@ -0,0 +1,25 @@
1
+ import type { ByteArray, Hex } from '../../../types/misc.js'
2
+ import type { EncodeFunctionDataReturnType } from '../../../utils/abi/encodeFunctionData.js'
3
+ import { bytesToHex, encodeFunctionData } from '../../../utils/index.js'
4
+ import { paymasterAbi } from '../../constants/abis.js'
5
+
6
+ export type GetGeneralPaymasterInputParameters = {
7
+ innerInput: Hex | ByteArray
8
+ }
9
+
10
+ export type GetGeneralPaymasterInputReturnType = EncodeFunctionDataReturnType
11
+
12
+ export function getGeneralPaymasterInput(
13
+ parameters: GetGeneralPaymasterInputParameters,
14
+ ): GetGeneralPaymasterInputReturnType {
15
+ const { innerInput } = parameters
16
+
17
+ const innerInputHex =
18
+ typeof innerInput === 'string' ? innerInput : bytesToHex(innerInput)
19
+
20
+ return encodeFunctionData({
21
+ abi: paymasterAbi,
22
+ functionName: 'general',
23
+ args: [innerInputHex],
24
+ })
25
+ }