viem 2.19.9 → 2.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +2 -2
  3. package/_cjs/account-abstraction/accounts/toSmartAccount.js +4 -5
  4. package/_cjs/account-abstraction/accounts/toSmartAccount.js.map +1 -1
  5. package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js +12 -9
  6. package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
  7. package/_cjs/account-abstraction/actions/bundler/sendUserOperation.js +14 -8
  8. package/_cjs/account-abstraction/actions/bundler/sendUserOperation.js.map +1 -1
  9. package/_cjs/accounts/index.js +3 -1
  10. package/_cjs/accounts/index.js.map +1 -1
  11. package/_cjs/chains/definitions/botanixTestnet.js +23 -0
  12. package/_cjs/chains/definitions/botanixTestnet.js.map +1 -0
  13. package/_cjs/chains/definitions/hashkeyChainTestnet.js +25 -0
  14. package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -0
  15. package/_cjs/chains/definitions/holesky.js +1 -0
  16. package/_cjs/chains/definitions/holesky.js.map +1 -1
  17. package/_cjs/chains/definitions/kaia.js +29 -0
  18. package/_cjs/chains/definitions/kaia.js.map +1 -0
  19. package/_cjs/chains/definitions/kairos.js +31 -0
  20. package/_cjs/chains/definitions/kairos.js.map +1 -0
  21. package/_cjs/chains/definitions/sophonTestnet.js +33 -0
  22. package/_cjs/chains/definitions/sophonTestnet.js.map +1 -0
  23. package/_cjs/chains/index.js +17 -7
  24. package/_cjs/chains/index.js.map +1 -1
  25. package/_cjs/errors/version.js +1 -1
  26. package/_cjs/experimental/eip5792/actions/sendCalls.js +22 -7
  27. package/_cjs/experimental/eip5792/actions/sendCalls.js.map +1 -1
  28. package/_cjs/experimental/eip5792/actions/writeContracts.js.map +1 -1
  29. package/_cjs/op-stack/actions/getTimeToFinalize.js +7 -1
  30. package/_cjs/op-stack/actions/getTimeToFinalize.js.map +1 -1
  31. package/_cjs/op-stack/actions/getWithdrawalStatus.js +7 -1
  32. package/_cjs/op-stack/actions/getWithdrawalStatus.js.map +1 -1
  33. package/_esm/account-abstraction/accounts/toSmartAccount.js +4 -5
  34. package/_esm/account-abstraction/accounts/toSmartAccount.js.map +1 -1
  35. package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js +12 -9
  36. package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
  37. package/_esm/account-abstraction/actions/bundler/sendUserOperation.js +14 -8
  38. package/_esm/account-abstraction/actions/bundler/sendUserOperation.js.map +1 -1
  39. package/_esm/accounts/index.js +1 -0
  40. package/_esm/accounts/index.js.map +1 -1
  41. package/_esm/chains/definitions/botanixTestnet.js +20 -0
  42. package/_esm/chains/definitions/botanixTestnet.js.map +1 -0
  43. package/_esm/chains/definitions/hashkeyChainTestnet.js +22 -0
  44. package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -0
  45. package/_esm/chains/definitions/holesky.js +1 -0
  46. package/_esm/chains/definitions/holesky.js.map +1 -1
  47. package/_esm/chains/definitions/kaia.js +26 -0
  48. package/_esm/chains/definitions/kaia.js.map +1 -0
  49. package/_esm/chains/definitions/kairos.js +28 -0
  50. package/_esm/chains/definitions/kairos.js.map +1 -0
  51. package/_esm/chains/definitions/sophonTestnet.js +30 -0
  52. package/_esm/chains/definitions/sophonTestnet.js.map +1 -0
  53. package/_esm/chains/index.js +7 -0
  54. package/_esm/chains/index.js.map +1 -1
  55. package/_esm/errors/version.js +1 -1
  56. package/_esm/experimental/eip5792/actions/sendCalls.js +22 -7
  57. package/_esm/experimental/eip5792/actions/sendCalls.js.map +1 -1
  58. package/_esm/experimental/eip5792/actions/writeContracts.js +2 -0
  59. package/_esm/experimental/eip5792/actions/writeContracts.js.map +1 -1
  60. package/_esm/op-stack/actions/getTimeToFinalize.js +7 -1
  61. package/_esm/op-stack/actions/getTimeToFinalize.js.map +1 -1
  62. package/_esm/op-stack/actions/getWithdrawalStatus.js +7 -1
  63. package/_esm/op-stack/actions/getWithdrawalStatus.js.map +1 -1
  64. package/_types/account-abstraction/accounts/toSmartAccount.d.ts.map +1 -1
  65. package/_types/account-abstraction/accounts/types.d.ts +3 -0
  66. package/_types/account-abstraction/accounts/types.d.ts.map +1 -1
  67. package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts +6 -4
  68. package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
  69. package/_types/account-abstraction/actions/bundler/sendUserOperation.d.ts +7 -5
  70. package/_types/account-abstraction/actions/bundler/sendUserOperation.d.ts.map +1 -1
  71. package/_types/accounts/index.d.ts +1 -0
  72. package/_types/accounts/index.d.ts.map +1 -1
  73. package/_types/chains/definitions/botanixTestnet.d.ts +36 -0
  74. package/_types/chains/definitions/botanixTestnet.d.ts.map +1 -0
  75. package/_types/chains/definitions/hashkeyChainTestnet.d.ts +35 -0
  76. package/_types/chains/definitions/hashkeyChainTestnet.d.ts.map +1 -0
  77. package/_types/chains/definitions/holesky.d.ts +1 -0
  78. package/_types/chains/definitions/holesky.d.ts.map +1 -1
  79. package/_types/chains/definitions/kaia.d.ts +33 -0
  80. package/_types/chains/definitions/kaia.d.ts.map +1 -0
  81. package/_types/chains/definitions/kairos.d.ts +34 -0
  82. package/_types/chains/definitions/kairos.d.ts.map +1 -0
  83. package/_types/chains/definitions/sophonTestnet.d.ts +34 -0
  84. package/_types/chains/definitions/sophonTestnet.d.ts.map +1 -0
  85. package/_types/chains/index.d.ts +7 -0
  86. package/_types/chains/index.d.ts.map +1 -1
  87. package/_types/errors/version.d.ts +1 -1
  88. package/_types/experimental/eip5792/actions/sendCalls.d.ts +33 -12
  89. package/_types/experimental/eip5792/actions/sendCalls.d.ts.map +1 -1
  90. package/_types/experimental/eip5792/actions/writeContracts.d.ts +2 -0
  91. package/_types/experimental/eip5792/actions/writeContracts.d.ts.map +1 -1
  92. package/_types/op-stack/actions/getTimeToFinalize.d.ts.map +1 -1
  93. package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
  94. package/_types/types/eip1193.d.ts +6 -6
  95. package/_types/types/eip1193.d.ts.map +1 -1
  96. package/account-abstraction/accounts/toSmartAccount.ts +12 -10
  97. package/account-abstraction/accounts/types.ts +3 -0
  98. package/account-abstraction/actions/bundler/estimateUserOperationGas.ts +53 -32
  99. package/account-abstraction/actions/bundler/sendUserOperation.ts +50 -33
  100. package/accounts/index.ts +1 -0
  101. package/chains/definitions/botanixTestnet.ts +20 -0
  102. package/chains/definitions/hashkeyChainTestnet.ts +22 -0
  103. package/chains/definitions/holesky.ts +1 -0
  104. package/chains/definitions/kaia.ts +26 -0
  105. package/chains/definitions/kairos.ts +28 -0
  106. package/chains/definitions/sophonTestnet.ts +30 -0
  107. package/chains/index.ts +7 -0
  108. package/errors/version.ts +1 -1
  109. package/experimental/eip5792/actions/sendCalls.ts +107 -21
  110. package/experimental/eip5792/actions/writeContracts.ts +2 -0
  111. package/op-stack/actions/getTimeToFinalize.ts +8 -1
  112. package/op-stack/actions/getWithdrawalStatus.ts +8 -1
  113. package/package.json +1 -1
  114. package/types/eip1193.ts +8 -11
@@ -7,7 +7,7 @@ import type { BaseError } from '../../../errors/base.js'
7
7
  import type { ErrorType } from '../../../errors/utils.js'
8
8
  import type { Chain } from '../../../types/chain.js'
9
9
  import type { Hex } from '../../../types/misc.js'
10
- import type { Assign, OneOf } from '../../../types/utils.js'
10
+ import type { Assign, MaybeRequired, OneOf } from '../../../types/utils.js'
11
11
  import type { RequestErrorType } from '../../../utils/buildRequest.js'
12
12
  import { getAction } from '../../../utils/getAction.js'
13
13
  import type { SmartAccount } from '../../accounts/types.js'
@@ -47,27 +47,39 @@ export type SendUserOperationParameters<
47
47
  >,
48
48
  _derivedVersion extends
49
49
  EntryPointVersion = DeriveEntryPointVersion<_derivedAccount>,
50
- > = Assign<
51
- UserOperationRequest<_derivedVersion>,
52
- OneOf<{ calls: UserOperationCalls<Narrow<calls>> } | { callData: Hex }> & {
53
- paymaster?:
54
- | Address
55
- | true
56
- | {
57
- /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */
58
- getPaymasterData?: PaymasterActions['getPaymasterData'] | undefined
59
- /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */
60
- getPaymasterStubData?:
61
- | PaymasterActions['getPaymasterStubData']
50
+ > = GetSmartAccountParameter<account, accountOverride, false> &
51
+ (
52
+ | UserOperation // Accept a full-formed User Operation.
53
+ | Assign<
54
+ // Accept a partially-formed User Operation (UserOperationRequest) to be filled.
55
+ UserOperationRequest<_derivedVersion>,
56
+ OneOf<
57
+ { calls: UserOperationCalls<Narrow<calls>> } | { callData: Hex }
58
+ > & {
59
+ paymaster?:
60
+ | Address
61
+ | true
62
+ | {
63
+ /** Retrieves paymaster-related User Operation properties to be used for sending the User Operation. */
64
+ getPaymasterData?:
65
+ | PaymasterActions['getPaymasterData']
66
+ | undefined
67
+ /** Retrieves paymaster-related User Operation properties to be used for gas estimation. */
68
+ getPaymasterStubData?:
69
+ | PaymasterActions['getPaymasterStubData']
70
+ | undefined
71
+ }
62
72
  | undefined
73
+ /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */
74
+ paymasterContext?: unknown | undefined
63
75
  }
64
- | undefined
65
- /** Paymaster context to pass to `getPaymasterData` and `getPaymasterStubData` calls. */
66
- paymasterContext?: unknown
67
- }
68
- > &
69
- GetSmartAccountParameter<account, accountOverride>
70
-
76
+ >
77
+ ) &
78
+ // Allow the EntryPoint address to be overridden, if no Account is provided, it will need to be required.
79
+ MaybeRequired<
80
+ { entryPointAddress?: Address },
81
+ _derivedAccount extends undefined ? true : false
82
+ >
71
83
  export type SendUserOperationReturnType = Hex
72
84
 
73
85
  export type SendUserOperationErrorType =
@@ -111,20 +123,21 @@ export async function sendUserOperation<
111
123
  client: Client<Transport, Chain | undefined, account>,
112
124
  parameters: SendUserOperationParameters<account, accountOverride, calls>,
113
125
  ) {
114
- const { account: account_ = client.account } = parameters
126
+ const { account: account_ = client.account, entryPointAddress } = parameters
115
127
 
116
- if (!account_) throw new AccountNotFoundError()
117
- const account = parseAccount(account_)
128
+ if (!account_ && !parameters.sender) throw new AccountNotFoundError()
129
+ const account = account_ ? parseAccount(account_) : undefined
118
130
 
119
- const request = await getAction(
120
- client,
121
- prepareUserOperation,
122
- 'prepareUserOperation',
123
- )(parameters as unknown as PrepareUserOperationParameters)
131
+ const request = account
132
+ ? await getAction(
133
+ client,
134
+ prepareUserOperation,
135
+ 'prepareUserOperation',
136
+ )(parameters as unknown as PrepareUserOperationParameters)
137
+ : parameters
124
138
 
125
- const signature =
126
- parameters.signature ||
127
- (await account.signUserOperation(request as UserOperation))
139
+ const signature = (parameters.signature ||
140
+ (await account?.signUserOperation(request as UserOperation)))!
128
141
 
129
142
  const rpcParameters = formatUserOperationRequest({
130
143
  ...request,
@@ -135,14 +148,18 @@ export async function sendUserOperation<
135
148
  return await client.request(
136
149
  {
137
150
  method: 'eth_sendUserOperation',
138
- params: [rpcParameters, account.entryPoint.address],
151
+ params: [
152
+ rpcParameters,
153
+ (entryPointAddress ?? account?.entryPoint.address)!,
154
+ ],
139
155
  },
140
156
  { retryCount: 0 },
141
157
  )
142
158
  } catch (error) {
159
+ const calls = (parameters as any).calls
143
160
  throw getUserOperationError(error as BaseError, {
144
161
  ...(request as UserOperation),
145
- calls: parameters.calls,
162
+ ...(calls ? { calls } : {}),
146
163
  signature,
147
164
  })
148
165
  }
package/accounts/index.ts CHANGED
@@ -8,6 +8,7 @@ export { wordlist as french } from '@scure/bip39/wordlists/french'
8
8
  export { wordlist as italian } from '@scure/bip39/wordlists/italian'
9
9
  export { wordlist as japanese } from '@scure/bip39/wordlists/japanese'
10
10
  export { wordlist as korean } from '@scure/bip39/wordlists/korean'
11
+ export { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese'
11
12
  export { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese'
12
13
  export { wordlist as spanish } from '@scure/bip39/wordlists/spanish'
13
14
  export { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese'
@@ -0,0 +1,20 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const botanixTestnet = /*#__PURE__*/ defineChain({
4
+ id: 3636,
5
+ name: 'Botanix Testnet',
6
+ nativeCurrency: { name: 'Botanix', symbol: 'BTC', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://poa-node.botanixlabs.dev'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'blockscout',
15
+ url: 'https://blockscout.botanixlabs.dev',
16
+ apiUrl: 'https://blockscout.botanixlabs.dev',
17
+ },
18
+ },
19
+ testnet: true,
20
+ })
@@ -0,0 +1,22 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const hashkeyTestnet = /*#__PURE__*/ defineChain({
4
+ id: 133,
5
+ name: 'HashKey Chain Testnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'HashKey EcoPoints',
9
+ symbol: 'HSK',
10
+ },
11
+ rpcUrls: {
12
+ default: {
13
+ http: ['https://hashkeychain-testnet.alt.technology'],
14
+ },
15
+ },
16
+ blockExplorers: {
17
+ default: {
18
+ name: 'HashKey Chain Explorer',
19
+ url: 'https://hashkeychain-testnet-explorer.alt.technology',
20
+ },
21
+ },
22
+ })
@@ -13,6 +13,7 @@ export const holesky = /*#__PURE__*/ defineChain({
13
13
  default: {
14
14
  name: 'Etherscan',
15
15
  url: 'https://holesky.etherscan.io',
16
+ apiUrl: 'https://api-holesky.etherscan.io/api',
16
17
  },
17
18
  },
18
19
  contracts: {
@@ -0,0 +1,26 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kaia = /*#__PURE__*/ defineChain({
4
+ id: 8_217,
5
+ name: 'Kaia',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'Kaia',
9
+ symbol: 'KAIA',
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ['https://public-en.node.kaia.io'] },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'KaiaScope',
17
+ url: 'https://kaiascope.com',
18
+ },
19
+ },
20
+ contracts: {
21
+ multicall3: {
22
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
23
+ blockCreated: 96002415,
24
+ },
25
+ },
26
+ })
@@ -0,0 +1,28 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kairos = /*#__PURE__*/ defineChain({
4
+ id: 1_001,
5
+ name: 'Kairos Testnet',
6
+ network: 'kairos',
7
+ nativeCurrency: {
8
+ decimals: 18,
9
+ name: 'Kairos KAIA',
10
+ symbol: 'KAIA',
11
+ },
12
+ rpcUrls: {
13
+ default: { http: ['https://public-en-kairos.node.kaia.io'] },
14
+ },
15
+ blockExplorers: {
16
+ default: {
17
+ name: 'KaiaScope',
18
+ url: 'https://kairos.kaiascope.com',
19
+ },
20
+ },
21
+ contracts: {
22
+ multicall3: {
23
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
24
+ blockCreated: 123390593,
25
+ },
26
+ },
27
+ testnet: true,
28
+ })
@@ -0,0 +1,30 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const sophonTestnet = /*#__PURE__*/ defineChain({
4
+ id: 531_050_104,
5
+ name: 'Sophon Testnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'Sophon',
9
+ symbol: 'ETH',
10
+ },
11
+ rpcUrls: {
12
+ default: {
13
+ http: ['https://rpc.testnet.sophon.xyz'],
14
+ webSocket: ['wss://rpc.testnet.sophon.xyz/ws'],
15
+ },
16
+ },
17
+ blockExplorers: {
18
+ default: {
19
+ name: 'Sophon Block Explorer',
20
+ url: 'https://explorer.testnet.sophon.xyz',
21
+ },
22
+ },
23
+ contracts: {
24
+ multicall3: {
25
+ address: '0x83c04d112adedA2C6D9037bb6ecb42E7f0b108Af',
26
+ blockCreated: 15_642,
27
+ },
28
+ },
29
+ testnet: true,
30
+ })
package/chains/index.ts CHANGED
@@ -47,6 +47,7 @@ export { bob } from './definitions/bob.js'
47
47
  export { bobSepolia } from './definitions/bobSepolia.js'
48
48
  export { boba } from './definitions/boba.js'
49
49
  export { bobaSepolia } from './definitions/bobaSepolia.js'
50
+ export { botanixTestnet } from './definitions/botanixTestnet.js'
50
51
  export { bronos } from './definitions/bronos.js'
51
52
  export { bronosTestnet } from './definitions/bronosTestnet.js'
52
53
  export { bsc } from './definitions/bsc.js'
@@ -132,6 +133,7 @@ export { gravity } from './definitions/gravity.js'
132
133
  export { ham } from './definitions/ham.js'
133
134
  export { hardhat } from './definitions/hardhat.js'
134
135
  export { harmonyOne } from './definitions/harmonyOne.js'
136
+ export { hashkeyTestnet } from './definitions/hashkeyChainTestnet.js'
135
137
  export { haqqMainnet } from './definitions/haqqMainnet.js'
136
138
  export { haqqTestedge2 } from './definitions/haqqTestedge2.js'
137
139
  export { hedera } from './definitions/hedera.js'
@@ -147,8 +149,12 @@ export { kakarotSepolia } from './definitions/kakarotSepolia.js'
147
149
  export { kava } from './definitions/kava.js'
148
150
  export { kavaTestnet } from './definitions/kavaTestnet.js'
149
151
  export { kcc } from './definitions/kcc.js'
152
+ /** @deprecated Use `kaia` instead. */
150
153
  export { klaytn } from './definitions/klaytn.js'
154
+ /** @deprecated Use `kairos` instead. */
151
155
  export { klaytnBaobab } from './definitions/klaytnBaobab.js'
156
+ export { kaia } from './definitions/kaia.js'
157
+ export { kairos } from './definitions/kairos.js'
152
158
  export { koi } from './definitions/koi.js'
153
159
  export { kroma } from './definitions/kroma.js'
154
160
  export { kromaSepolia } from './definitions/kromaSepolia.js'
@@ -273,6 +279,7 @@ export { skaleTitanTestnet } from './definitions/skale/titanTestnet.js'
273
279
  export { sketchpad } from './definitions/sketchpad.js'
274
280
  export { songbird } from './definitions/songbird.js'
275
281
  export { songbirdTestnet } from './definitions/songbirdTestnet.js'
282
+ export { sophonTestnet } from './definitions/sophonTestnet.js'
276
283
  export { spicy } from './definitions/spicy.js'
277
284
  export { shardeumSphinx } from './definitions/shardeumSphinx.js'
278
285
  export { shibarium } from './definitions/shibarium.js'
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.9'
1
+ export const version = '2.20.1'
@@ -1,3 +1,4 @@
1
+ import type { AbiStateMutability, Address, Narrow } from 'abitype'
1
2
  import { parseAccount } from '../../../accounts/utils/parseAccount.js'
2
3
  import type { Client } from '../../../clients/createClient.js'
3
4
  import type { Transport } from '../../../clients/transports/createTransport.js'
@@ -6,13 +7,16 @@ import type { BaseError } from '../../../errors/base.js'
6
7
  import { ChainNotFoundError } from '../../../errors/chain.js'
7
8
  import type { ErrorType } from '../../../errors/utils.js'
8
9
  import type { Account, GetAccountParameter } from '../../../types/account.js'
9
- import type { Chain, GetChainParameter } from '../../../types/chain.js'
10
+ import type { Chain, DeriveChain } from '../../../types/chain.js'
11
+ import type { ContractFunctionParameters } from '../../../types/contract.js'
10
12
  import type {
11
13
  WalletCapabilities,
12
14
  WalletSendCallsParameters,
13
15
  } from '../../../types/eip1193.js'
14
16
  import type { Hex } from '../../../types/misc.js'
15
- import type { OneOf } from '../../../types/utils.js'
17
+ import type { GetMulticallContractParameters } from '../../../types/multicall.js'
18
+ import type { MaybeRequired, OneOf, Prettify } from '../../../types/utils.js'
19
+ import { encodeFunctionData } from '../../../utils/abi/encodeFunctionData.js'
16
20
  import type { RequestErrorType } from '../../../utils/buildRequest.js'
17
21
  import { numberToHex } from '../../../utils/encoding/toHex.js'
18
22
  import { getTransactionError } from '../../../utils/errors/getTransactionError.js'
@@ -21,23 +25,17 @@ export type SendCallsParameters<
21
25
  chain extends Chain | undefined = Chain | undefined,
22
26
  account extends Account | undefined = Account | undefined,
23
27
  chainOverride extends Chain | undefined = Chain | undefined,
28
+ calls extends readonly unknown[] = readonly unknown[],
29
+ //
30
+ _chain extends Chain | undefined = DeriveChain<chain, chainOverride>,
24
31
  > = {
25
- calls: OneOf<
26
- | {
27
- to: Hex
28
- data?: Hex | undefined
29
- value?: bigint | undefined
30
- }
31
- | {
32
- data: Hex
33
- }
34
- >[]
32
+ chain?: chainOverride | Chain | undefined
33
+ calls: Calls<Narrow<calls>, _chain>
35
34
  capabilities?:
36
35
  | WalletSendCallsParameters<WalletCapabilities>[number]['capabilities']
37
36
  | undefined
38
37
  version?: WalletSendCallsParameters[number]['version'] | undefined
39
- } & GetAccountParameter<account> &
40
- GetChainParameter<chain, chainOverride>
38
+ } & GetAccountParameter<account>
41
39
 
42
40
  export type SendCallsReturnType = string
43
41
 
@@ -76,16 +74,16 @@ export type SendCallsErrorType = RequestErrorType | ErrorType
76
74
  * })
77
75
  */
78
76
  export async function sendCalls<
77
+ const calls extends readonly unknown[],
79
78
  chain extends Chain | undefined,
80
79
  account extends Account | undefined = undefined,
81
80
  chainOverride extends Chain | undefined = undefined,
82
81
  >(
83
82
  client: Client<Transport, chain, account>,
84
- parameters: SendCallsParameters<chain, account, chainOverride>,
83
+ parameters: SendCallsParameters<chain, account, chainOverride, calls>,
85
84
  ): Promise<SendCallsReturnType> {
86
85
  const {
87
86
  account: account_ = client.account,
88
- calls,
89
87
  capabilities,
90
88
  chain = client.chain,
91
89
  version = '1.0',
@@ -97,7 +95,27 @@ export async function sendCalls<
97
95
  })
98
96
  const account = parseAccount(account_)
99
97
 
100
- if (!chain) throw new ChainNotFoundError()
98
+ const calls = parameters.calls.map((call_: unknown) => {
99
+ const call = call_ as Call
100
+
101
+ const chainId = call.chain?.id ?? call.chainId ?? chain?.id
102
+ if (!chainId) throw new ChainNotFoundError()
103
+
104
+ const data = call.abi
105
+ ? encodeFunctionData({
106
+ abi: call.abi,
107
+ functionName: call.functionName,
108
+ args: call.args,
109
+ })
110
+ : call.data
111
+
112
+ return {
113
+ chainId: numberToHex(chainId),
114
+ data,
115
+ to: call.to,
116
+ value: call.value ? numberToHex(call.value) : undefined,
117
+ }
118
+ })
101
119
 
102
120
  try {
103
121
  return await client.request(
@@ -105,10 +123,7 @@ export async function sendCalls<
105
123
  method: 'wallet_sendCalls',
106
124
  params: [
107
125
  {
108
- calls: calls.map((call) => ({
109
- ...call,
110
- value: call.value ? numberToHex(call.value) : undefined,
111
- })) as any,
126
+ calls,
112
127
  capabilities,
113
128
  chainId: numberToHex(chain!.id),
114
129
  from: account.address,
@@ -126,3 +141,74 @@ export async function sendCalls<
126
141
  })
127
142
  }
128
143
  }
144
+
145
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
146
+
147
+ type RawCall = { data?: Hex; to?: Address; value?: bigint }
148
+
149
+ type Call<
150
+ chain extends Chain | undefined = Chain | undefined,
151
+ contractFunctionParameters = Omit<ContractFunctionParameters, 'address'>,
152
+ > = OneOf<
153
+ | (contractFunctionParameters & {
154
+ to: Address
155
+ value?: bigint | undefined
156
+ })
157
+ | RawCall
158
+ > &
159
+ OneOf<
160
+ | MaybeRequired<
161
+ { chain?: Chain | undefined },
162
+ chain extends Chain ? false : true
163
+ >
164
+ | MaybeRequired<{ chainId?: number }, chain extends Chain ? false : true>
165
+ >
166
+
167
+ type Calls<
168
+ calls extends readonly unknown[],
169
+ chain extends Chain | undefined,
170
+ ///
171
+ result extends readonly any[] = [],
172
+ > = calls extends readonly [] // no calls, return empty
173
+ ? readonly []
174
+ : calls extends readonly [infer call] // one call left before returning `result`
175
+ ? readonly [
176
+ ...result,
177
+ Prettify<
178
+ Call<
179
+ chain,
180
+ Omit<
181
+ GetMulticallContractParameters<call, AbiStateMutability>,
182
+ 'address'
183
+ >
184
+ >
185
+ >,
186
+ ]
187
+ : calls extends readonly [infer call, ...infer rest] // grab first call and recurse through `rest`
188
+ ? Calls<
189
+ [...rest],
190
+ chain,
191
+ [
192
+ ...result,
193
+ Prettify<
194
+ Call<
195
+ chain,
196
+ Omit<
197
+ GetMulticallContractParameters<call, AbiStateMutability>,
198
+ 'address'
199
+ >
200
+ >
201
+ >,
202
+ ]
203
+ >
204
+ : readonly unknown[] extends calls
205
+ ? calls
206
+ : // If `calls` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
207
+ // use this to infer the param types in the case of Array.map() argument
208
+ calls extends readonly (infer call extends Call<
209
+ chain,
210
+ Omit<ContractFunctionParameters, 'address'>
211
+ >)[]
212
+ ? readonly Prettify<call>[]
213
+ : // Fallback
214
+ readonly Call<chain, Omit<ContractFunctionParameters, 'address'>>[]
@@ -50,6 +50,8 @@ export type WriteContractsErrorType =
50
50
  | ErrorType
51
51
 
52
52
  /**
53
+ * @deprecated Use {@link sendCalls} instead. See https://viem.sh/experimental/eip5792/sendCalls#contract-calls.
54
+ *
53
55
  * Requests for the wallet to sign and broadcast a batch of write contract calls (transactions) to the network.
54
56
  *
55
57
  * - Docs: https://viem.sh/experimental/eip5792/writeContracts
@@ -128,11 +128,18 @@ export async function getTimeToFinalize<
128
128
  return { period: Number(period), seconds, timestamp }
129
129
  }
130
130
 
131
+ const numProofSubmitters = await readContract(client, {
132
+ abi: portal2Abi,
133
+ address: portalAddress,
134
+ functionName: 'numProofSubmitters',
135
+ args: [withdrawalHash],
136
+ }).catch(() => 1n)
137
+
131
138
  const proofSubmitter = await readContract(client, {
132
139
  abi: portal2Abi,
133
140
  address: portalAddress,
134
141
  functionName: 'proofSubmitters',
135
- args: [withdrawalHash, 0n],
142
+ args: [withdrawalHash, numProofSubmitters - 1n],
136
143
  }).catch(() => undefined)
137
144
 
138
145
  const [[_disputeGameProxy, proveTimestamp], proofMaturityDelaySeconds] =
@@ -197,11 +197,18 @@ export async function getWithdrawalStatus<
197
197
  return seconds > 0 ? 'waiting-to-finalize' : 'ready-to-finalize'
198
198
  }
199
199
 
200
+ const numProofSubmitters = await readContract(client, {
201
+ abi: portal2Abi,
202
+ address: portalAddress,
203
+ functionName: 'numProofSubmitters',
204
+ args: [withdrawal.withdrawalHash],
205
+ }).catch(() => 1n)
206
+
200
207
  const proofSubmitter = await readContract(client, {
201
208
  abi: portal2Abi,
202
209
  address: portalAddress,
203
210
  functionName: 'proofSubmitters',
204
- args: [withdrawal.withdrawalHash, 0n],
211
+ args: [withdrawal.withdrawalHash, numProofSubmitters - 1n],
205
212
  }).catch(() => withdrawal.sender)
206
213
 
207
214
  const [disputeGameResult, checkWithdrawalResult, finalizedResult] =
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.19.9",
4
+ "version": "2.20.1",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/eip1193.ts CHANGED
@@ -207,18 +207,15 @@ export type WalletSendCallsParameters<
207
207
  quantity extends Quantity | bigint = Quantity,
208
208
  > = [
209
209
  {
210
- calls: OneOf<
211
- | {
212
- to: Address
213
- data?: Hex | undefined
214
- value?: quantity | undefined
215
- }
216
- | {
217
- data: Hex
218
- }
219
- >[]
210
+ calls: readonly {
211
+ chainId?: chainId | undefined
212
+ to?: Address | undefined
213
+ data?: Hex | undefined
214
+ value?: quantity | undefined
215
+ }[]
220
216
  capabilities?: capabilities | undefined
221
- chainId: chainId
217
+ /** @deprecated Use `chainId` on `calls` instead. */
218
+ chainId?: chainId | undefined
222
219
  from: Address
223
220
  version: string
224
221
  },