viem 2.23.10 → 2.23.12
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.
- package/CHANGELOG.md +34 -0
- package/_cjs/actions/public/simulateBlocks.js +1 -1
- package/_cjs/actions/public/simulateBlocks.js.map +1 -1
- package/_cjs/chains/definitions/basecampTestnet.js +24 -0
- package/_cjs/chains/definitions/basecampTestnet.js.map +1 -0
- package/_cjs/chains/definitions/happychainTestnet.js +3 -3
- package/_cjs/chains/definitions/happychainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/nibiru.js +29 -0
- package/_cjs/chains/definitions/nibiru.js.map +1 -0
- package/_cjs/chains/definitions/plume.js +1 -1
- package/_cjs/chains/definitions/plume.js.map +1 -1
- package/_cjs/chains/definitions/plumeMainnet.js +29 -0
- package/_cjs/chains/definitions/plumeMainnet.js.map +1 -0
- package/_cjs/chains/definitions/pyrope.js +35 -0
- package/_cjs/chains/definitions/pyrope.js.map +1 -0
- package/_cjs/chains/definitions/somniaTestnet.js +23 -0
- package/_cjs/chains/definitions/somniaTestnet.js.map +1 -0
- package/_cjs/chains/definitions/sonic.js +1 -1
- package/_cjs/chains/definitions/sonic.js.map +1 -1
- package/_cjs/chains/definitions/zenchainTestnet.js +3 -3
- package/_cjs/chains/index.js +22 -12
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/eip5792/actions/waitForCallsStatus.js +52 -0
- package/_cjs/experimental/eip5792/actions/waitForCallsStatus.js.map +1 -0
- package/_cjs/experimental/eip5792/decorators/eip5792.js +2 -0
- package/_cjs/experimental/eip5792/decorators/eip5792.js.map +1 -1
- package/_cjs/experimental/index.js +4 -1
- package/_cjs/experimental/index.js.map +1 -1
- package/_cjs/utils/ccip.js +1 -1
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/formatters/transactionRequest.js +6 -2
- package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/_cjs/zksync/actions/isWithdrawalFinalized.js +50 -0
- package/_cjs/zksync/actions/isWithdrawalFinalized.js.map +1 -0
- package/_cjs/zksync/decorators/publicL1.js +2 -0
- package/_cjs/zksync/decorators/publicL1.js.map +1 -1
- package/_cjs/zksync/index.js +4 -2
- package/_cjs/zksync/index.js.map +1 -1
- package/_cjs/zksync/serializers.js +1 -1
- package/_cjs/zksync/serializers.js.map +1 -1
- package/_esm/actions/public/simulateBlocks.js +1 -1
- package/_esm/actions/public/simulateBlocks.js.map +1 -1
- package/_esm/chains/definitions/basecampTestnet.js +21 -0
- package/_esm/chains/definitions/basecampTestnet.js.map +1 -0
- package/_esm/chains/definitions/happychainTestnet.js +3 -3
- package/_esm/chains/definitions/happychainTestnet.js.map +1 -1
- package/_esm/chains/definitions/nibiru.js +26 -0
- package/_esm/chains/definitions/nibiru.js.map +1 -0
- package/_esm/chains/definitions/plume.js +1 -1
- package/_esm/chains/definitions/plume.js.map +1 -1
- package/_esm/chains/definitions/plumeMainnet.js +26 -0
- package/_esm/chains/definitions/plumeMainnet.js.map +1 -0
- package/_esm/chains/definitions/pyrope.js +32 -0
- package/_esm/chains/definitions/pyrope.js.map +1 -0
- package/_esm/chains/definitions/somniaTestnet.js +20 -0
- package/_esm/chains/definitions/somniaTestnet.js.map +1 -0
- package/_esm/chains/definitions/sonic.js +1 -1
- package/_esm/chains/definitions/sonic.js.map +1 -1
- package/_esm/chains/definitions/zenchainTestnet.js +3 -3
- package/_esm/chains/index.js +6 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/eip5792/actions/getCallsStatus.js +1 -1
- package/_esm/experimental/eip5792/actions/getCapabilities.js +1 -1
- package/_esm/experimental/eip5792/actions/sendCalls.js +1 -1
- package/_esm/experimental/eip5792/actions/showCallsStatus.js +1 -1
- package/_esm/experimental/eip5792/actions/waitForCallsStatus.js +69 -0
- package/_esm/experimental/eip5792/actions/waitForCallsStatus.js.map +1 -0
- package/_esm/experimental/eip5792/decorators/eip5792.js +2 -0
- package/_esm/experimental/eip5792/decorators/eip5792.js.map +1 -1
- package/_esm/experimental/index.js +1 -0
- package/_esm/experimental/index.js.map +1 -1
- package/_esm/utils/ccip.js +1 -1
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/formatters/transactionRequest.js +6 -2
- package/_esm/utils/formatters/transactionRequest.js.map +1 -1
- package/_esm/zksync/actions/isWithdrawalFinalized.js +77 -0
- package/_esm/zksync/actions/isWithdrawalFinalized.js.map +1 -0
- package/_esm/zksync/decorators/publicL1.js +2 -0
- package/_esm/zksync/decorators/publicL1.js.map +1 -1
- package/_esm/zksync/index.js +1 -0
- package/_esm/zksync/index.js.map +1 -1
- package/_esm/zksync/serializers.js +1 -1
- package/_esm/zksync/serializers.js.map +1 -1
- package/_types/chains/definitions/basecampTestnet.d.ts +37 -0
- package/_types/chains/definitions/basecampTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/happychainTestnet.d.ts +3 -3
- package/_types/chains/definitions/nibiru.d.ts +33 -0
- package/_types/chains/definitions/nibiru.d.ts.map +1 -0
- package/_types/chains/definitions/plume.d.ts +1 -1
- package/_types/chains/definitions/plumeMainnet.d.ts +39 -0
- package/_types/chains/definitions/plumeMainnet.d.ts.map +1 -0
- package/_types/chains/definitions/pyrope.d.ts +285 -0
- package/_types/chains/definitions/pyrope.d.ts.map +1 -0
- package/_types/chains/definitions/somniaTestnet.d.ts +38 -0
- package/_types/chains/definitions/somniaTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/sonic.d.ts +1 -1
- package/_types/chains/definitions/zenchainTestnet.d.ts +3 -3
- package/_types/chains/index.d.ts +6 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/eip5792/actions/getCallsStatus.d.ts +1 -1
- package/_types/experimental/eip5792/actions/getCapabilities.d.ts +1 -1
- package/_types/experimental/eip5792/actions/sendCalls.d.ts +1 -1
- package/_types/experimental/eip5792/actions/showCallsStatus.d.ts +1 -1
- package/_types/experimental/eip5792/actions/waitForCallsStatus.d.ts +68 -0
- package/_types/experimental/eip5792/actions/waitForCallsStatus.d.ts.map +1 -0
- package/_types/experimental/eip5792/decorators/eip5792.d.ts +24 -0
- package/_types/experimental/eip5792/decorators/eip5792.d.ts.map +1 -1
- package/_types/experimental/index.d.ts +1 -0
- package/_types/experimental/index.d.ts.map +1 -1
- package/_types/zksync/actions/isWithdrawalFinalized.d.ts +48 -0
- package/_types/zksync/actions/isWithdrawalFinalized.d.ts.map +1 -0
- package/_types/zksync/decorators/publicL1.d.ts +29 -0
- package/_types/zksync/decorators/publicL1.d.ts.map +1 -1
- package/_types/zksync/index.d.ts +1 -0
- package/_types/zksync/index.d.ts.map +1 -1
- package/actions/public/simulateBlocks.ts +1 -1
- package/chains/definitions/basecampTestnet.ts +21 -0
- package/chains/definitions/happychainTestnet.ts +3 -3
- package/chains/definitions/nibiru.ts +26 -0
- package/chains/definitions/plume.ts +1 -1
- package/chains/definitions/plumeMainnet.ts +27 -0
- package/chains/definitions/pyrope.ts +33 -0
- package/chains/definitions/somniaTestnet.ts +20 -0
- package/chains/definitions/sonic.ts +1 -1
- package/chains/definitions/zenchainTestnet.ts +3 -3
- package/chains/index.ts +6 -0
- package/errors/version.ts +1 -1
- package/experimental/eip5792/actions/getCallsStatus.ts +1 -1
- package/experimental/eip5792/actions/getCapabilities.ts +1 -1
- package/experimental/eip5792/actions/sendCalls.ts +1 -1
- package/experimental/eip5792/actions/showCallsStatus.ts +1 -1
- package/experimental/eip5792/actions/waitForCallsStatus.ts +137 -0
- package/experimental/eip5792/decorators/eip5792.ts +32 -0
- package/experimental/index.ts +8 -0
- package/package.json +1 -1
- package/utils/ccip.ts +1 -1
- package/utils/formatters/transactionRequest.ts +6 -2
- package/zksync/actions/isWithdrawalFinalized.ts +122 -0
- package/zksync/decorators/publicL1.ts +36 -0
- package/zksync/index.ts +6 -0
- package/zksync/serializers.ts +1 -1
@@ -0,0 +1,137 @@
|
|
1
|
+
import type { Client } from '../../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
|
+
import { BaseError } from '../../../errors/base.js'
|
4
|
+
import type { ErrorType } from '../../../errors/utils.js'
|
5
|
+
import type { Chain } from '../../../types/chain.js'
|
6
|
+
import type { WalletGetCallsStatusReturnType } from '../../../types/eip1193.js'
|
7
|
+
import type { Prettify } from '../../../types/utils.js'
|
8
|
+
import { type ObserveErrorType, observe } from '../../../utils/observe.js'
|
9
|
+
import { type PollErrorType, poll } from '../../../utils/poll.js'
|
10
|
+
import { withResolvers } from '../../../utils/promise/withResolvers.js'
|
11
|
+
import { stringify } from '../../../utils/stringify.js'
|
12
|
+
import {
|
13
|
+
type GetCallsStatusErrorType,
|
14
|
+
getCallsStatus,
|
15
|
+
} from './getCallsStatus.js'
|
16
|
+
|
17
|
+
export type WaitForCallsStatusParameters = {
|
18
|
+
/**
|
19
|
+
* The id of the call batch to wait for.
|
20
|
+
*/
|
21
|
+
id: string
|
22
|
+
/**
|
23
|
+
* Polling frequency (in ms). Defaults to the client's pollingInterval config.
|
24
|
+
*
|
25
|
+
* @default client.pollingInterval
|
26
|
+
*/
|
27
|
+
pollingInterval?: number | undefined
|
28
|
+
/**
|
29
|
+
* The status to wait for.
|
30
|
+
*
|
31
|
+
* @default 'CONFIRMED'
|
32
|
+
*/
|
33
|
+
status?: 'CONFIRMED' | undefined
|
34
|
+
/**
|
35
|
+
* Optional timeout (in milliseconds) to wait before stopping polling.
|
36
|
+
*
|
37
|
+
* @default 60_000
|
38
|
+
*/
|
39
|
+
timeout?: number | undefined
|
40
|
+
}
|
41
|
+
|
42
|
+
export type WaitForCallsStatusReturnType = Prettify<
|
43
|
+
WalletGetCallsStatusReturnType<bigint, 'success' | 'reverted'>
|
44
|
+
>
|
45
|
+
|
46
|
+
export type WaitForCallsStatusErrorType =
|
47
|
+
| ObserveErrorType
|
48
|
+
| PollErrorType
|
49
|
+
| GetCallsStatusErrorType
|
50
|
+
| WaitForCallsStatusTimeoutError
|
51
|
+
| ErrorType
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Waits for the status & receipts of a call bundle that was sent via `sendCalls`.
|
55
|
+
*
|
56
|
+
* - Docs: https://viem.sh/experimental/eip5792/waitForCallsStatus
|
57
|
+
* - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
|
58
|
+
*
|
59
|
+
* @param client - Client to use
|
60
|
+
* @param parameters - {@link WaitForCallsStatusParameters}
|
61
|
+
* @returns Status & receipts of the call bundle. {@link WaitForCallsStatusReturnType}
|
62
|
+
*
|
63
|
+
* @example
|
64
|
+
* import { createWalletClient, custom } from 'viem'
|
65
|
+
* import { mainnet } from 'viem/chains'
|
66
|
+
* import { waitForCallsStatus } from 'viem/experimental'
|
67
|
+
*
|
68
|
+
* const client = createWalletClient({
|
69
|
+
* chain: mainnet,
|
70
|
+
* transport: custom(window.ethereum),
|
71
|
+
* })
|
72
|
+
*
|
73
|
+
* const { receipts, status } = await waitForCallsStatus(client, { id: '0xdeadbeef' })
|
74
|
+
*/
|
75
|
+
export async function waitForCallsStatus<chain extends Chain | undefined>(
|
76
|
+
client: Client<Transport, chain>,
|
77
|
+
parameters: WaitForCallsStatusParameters,
|
78
|
+
): Promise<WaitForCallsStatusReturnType> {
|
79
|
+
const {
|
80
|
+
id,
|
81
|
+
pollingInterval = client.pollingInterval,
|
82
|
+
status = 'CONFIRMED',
|
83
|
+
timeout = 60_000,
|
84
|
+
} = parameters
|
85
|
+
const observerId = stringify(['waitForCallsStatus', client.uid, id])
|
86
|
+
|
87
|
+
const { promise, resolve, reject } =
|
88
|
+
withResolvers<WaitForCallsStatusReturnType>()
|
89
|
+
|
90
|
+
let timer: Timer | undefined = undefined
|
91
|
+
|
92
|
+
const unobserve = observe(observerId, { resolve, reject }, (emit) => {
|
93
|
+
const unpoll = poll(
|
94
|
+
async () => {
|
95
|
+
try {
|
96
|
+
const result = await getCallsStatus(client, { id })
|
97
|
+
if (result.status !== status) return
|
98
|
+
emit.resolve(result)
|
99
|
+
} catch (error) {
|
100
|
+
if (timer) clearTimeout(timer)
|
101
|
+
unpoll()
|
102
|
+
emit.reject(error)
|
103
|
+
unobserve()
|
104
|
+
}
|
105
|
+
},
|
106
|
+
{
|
107
|
+
interval: pollingInterval,
|
108
|
+
emitOnBegin: true,
|
109
|
+
},
|
110
|
+
)
|
111
|
+
|
112
|
+
return unpoll
|
113
|
+
})
|
114
|
+
|
115
|
+
timer = timeout
|
116
|
+
? setTimeout(() => {
|
117
|
+
unobserve()
|
118
|
+
clearTimeout(timer)
|
119
|
+
reject(new WaitForCallsStatusTimeoutError({ id }))
|
120
|
+
}, timeout)
|
121
|
+
: undefined
|
122
|
+
|
123
|
+
return await promise
|
124
|
+
}
|
125
|
+
|
126
|
+
export type WaitForCallsStatusTimeoutErrorType =
|
127
|
+
WaitForCallsStatusTimeoutError & {
|
128
|
+
name: 'WaitForCallsStatusTimeoutError'
|
129
|
+
}
|
130
|
+
export class WaitForCallsStatusTimeoutError extends BaseError {
|
131
|
+
constructor({ id }: { id: string }) {
|
132
|
+
super(
|
133
|
+
`Timed out while waiting for call bundle with id "${id}" to be confirmed.`,
|
134
|
+
{ name: 'WaitForCallsStatusTimeoutError' },
|
135
|
+
)
|
136
|
+
}
|
137
|
+
}
|
@@ -22,6 +22,11 @@ import {
|
|
22
22
|
type ShowCallsStatusReturnType,
|
23
23
|
showCallsStatus,
|
24
24
|
} from '../actions/showCallsStatus.js'
|
25
|
+
import {
|
26
|
+
type WaitForCallsStatusParameters,
|
27
|
+
type WaitForCallsStatusReturnType,
|
28
|
+
waitForCallsStatus,
|
29
|
+
} from '../actions/waitForCallsStatus.js'
|
25
30
|
import {
|
26
31
|
type WriteContractsParameters,
|
27
32
|
type WriteContractsReturnType,
|
@@ -143,6 +148,31 @@ export type Eip5792Actions<
|
|
143
148
|
showCallsStatus: (
|
144
149
|
parameters: ShowCallsStatusParameters,
|
145
150
|
) => Promise<ShowCallsStatusReturnType>
|
151
|
+
/**
|
152
|
+
* Waits for the status & receipts of a call bundle that was sent via `sendCalls`.
|
153
|
+
*
|
154
|
+
* - Docs: https://viem.sh/experimental/eip5792/waitForCallsStatus
|
155
|
+
* - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
|
156
|
+
*
|
157
|
+
* @param client - Client to use
|
158
|
+
* @param parameters - {@link WaitForCallsStatusParameters}
|
159
|
+
* @returns Status & receipts of the call bundle. {@link WaitForCallsStatusReturnType}
|
160
|
+
*
|
161
|
+
* @example
|
162
|
+
* import { createWalletClient, custom } from 'viem'
|
163
|
+
* import { mainnet } from 'viem/chains'
|
164
|
+
* import { waitForCallsStatus } from 'viem/experimental'
|
165
|
+
*
|
166
|
+
* const client = createWalletClient({
|
167
|
+
* chain: mainnet,
|
168
|
+
* transport: custom(window.ethereum),
|
169
|
+
* })
|
170
|
+
*
|
171
|
+
* const { receipts, status } = await waitForCallsStatus(client, { id: '0xdeadbeef' })
|
172
|
+
*/
|
173
|
+
waitForCallsStatus: (
|
174
|
+
parameters: WaitForCallsStatusParameters,
|
175
|
+
) => Promise<WaitForCallsStatusReturnType>
|
146
176
|
/**
|
147
177
|
* Requests for the wallet to sign and broadcast a batch of write contract calls (transactions) to the network.
|
148
178
|
*
|
@@ -231,6 +261,8 @@ export function eip5792Actions() {
|
|
231
261
|
getCapabilities(client as any, parameters)) as any,
|
232
262
|
sendCalls: (parameters) => sendCalls(client, parameters),
|
233
263
|
showCallsStatus: (parameters) => showCallsStatus(client, parameters),
|
264
|
+
waitForCallsStatus: (parameters) =>
|
265
|
+
waitForCallsStatus(client, parameters),
|
234
266
|
writeContracts: (parameters) => writeContracts(client, parameters),
|
235
267
|
}
|
236
268
|
}
|
package/experimental/index.ts
CHANGED
@@ -23,6 +23,14 @@ export {
|
|
23
23
|
type ShowCallsStatusReturnType,
|
24
24
|
showCallsStatus,
|
25
25
|
} from './eip5792/actions/showCallsStatus.js'
|
26
|
+
export {
|
27
|
+
type WaitForCallsStatusErrorType,
|
28
|
+
type WaitForCallsStatusParameters,
|
29
|
+
type WaitForCallsStatusReturnType,
|
30
|
+
type WaitForCallsStatusTimeoutErrorType,
|
31
|
+
WaitForCallsStatusTimeoutError,
|
32
|
+
waitForCallsStatus,
|
33
|
+
} from './eip5792/actions/waitForCallsStatus.js'
|
26
34
|
export {
|
27
35
|
type WriteContractsErrorType,
|
28
36
|
type WriteContractsParameters,
|
package/package.json
CHANGED
package/utils/ccip.ts
CHANGED
@@ -141,7 +141,7 @@ export async function ccipRequest({
|
|
141
141
|
|
142
142
|
try {
|
143
143
|
const response = await fetch(
|
144
|
-
url.replace('{sender}', sender).replace('{data}', data),
|
144
|
+
url.replace('{sender}', sender.toLowerCase()).replace('{data}', data),
|
145
145
|
{
|
146
146
|
body: JSON.stringify(body),
|
147
147
|
headers,
|
@@ -91,8 +91,12 @@ function formatAuthorizationList(
|
|
91
91
|
(authorization) =>
|
92
92
|
({
|
93
93
|
address: authorization.contractAddress,
|
94
|
-
r: authorization.r
|
95
|
-
|
94
|
+
r: authorization.r
|
95
|
+
? numberToHex(BigInt(authorization.r))
|
96
|
+
: authorization.r,
|
97
|
+
s: authorization.s
|
98
|
+
? numberToHex(BigInt(authorization.s))
|
99
|
+
: authorization.s,
|
96
100
|
chainId: numberToHex(authorization.chainId),
|
97
101
|
nonce: numberToHex(authorization.nonce),
|
98
102
|
...(typeof authorization.yParity !== 'undefined'
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Account } from '../../accounts/types.js'
|
3
|
+
import { readContract } from '../../actions/public/readContract.js'
|
4
|
+
import type { Client } from '../../clients/createClient.js'
|
5
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
6
|
+
import {
|
7
|
+
ChainNotFoundError,
|
8
|
+
type ChainNotFoundErrorType,
|
9
|
+
} from '../../errors/chain.js'
|
10
|
+
import type { Chain } from '../../types/chain.js'
|
11
|
+
import type { Hash } from '../../types/misc.js'
|
12
|
+
import { isAddressEqual, slice } from '../../utils/index.js'
|
13
|
+
import { l1SharedBridgeAbi, l2SharedBridgeAbi } from '../constants/abis.js'
|
14
|
+
import { l2BaseTokenAddress } from '../constants/address.js'
|
15
|
+
import {
|
16
|
+
WithdrawalLogNotFoundError,
|
17
|
+
type WithdrawalLogNotFoundErrorType,
|
18
|
+
} from '../errors/bridge.js'
|
19
|
+
import type { ChainEIP712 } from '../types/chain.js'
|
20
|
+
import { getWithdrawalL2ToL1Log } from '../utils/bridge/getWithdrawalL2ToL1Log.js'
|
21
|
+
import { getWithdrawalLog } from '../utils/bridge/getWithdrawalLog.js'
|
22
|
+
import { getBaseTokenL1Address } from './getBaseTokenL1Address.js'
|
23
|
+
import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
|
24
|
+
import { getLogProof } from './getLogProof.js'
|
25
|
+
|
26
|
+
export type IsWithdrawalFinalizedParameters<
|
27
|
+
chain extends Chain | undefined = Chain | undefined,
|
28
|
+
account extends Account | undefined = Account | undefined,
|
29
|
+
> = {
|
30
|
+
/** L2 client */
|
31
|
+
client: Client<Transport, chain, account>
|
32
|
+
/** Hash of the L2 transaction where the withdrawal was initiated. */
|
33
|
+
hash: Hash
|
34
|
+
/** In case there were multiple withdrawals in one transaction, you may pass an index of the
|
35
|
+
withdrawal you want to finalize. */
|
36
|
+
index?: number | undefined
|
37
|
+
}
|
38
|
+
|
39
|
+
export type IsWithdrawalFinalizedReturnType = boolean
|
40
|
+
|
41
|
+
export type IsWithdrawalFinalizedErrorType =
|
42
|
+
| WithdrawalLogNotFoundErrorType
|
43
|
+
| ChainNotFoundErrorType
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Returns whether the withdrawal transaction is finalized on the L1 network.
|
47
|
+
*
|
48
|
+
* @param client - Client to use
|
49
|
+
* @param parameters - {@link IsWithdrawalFinalizedParameters}
|
50
|
+
* @returns bool - Whether the withdrawal transaction is finalized on the L1 network. {@link IsWithdrawalFinalizedReturnType}
|
51
|
+
*
|
52
|
+
* @example
|
53
|
+
* import { createPublicClient, http } from 'viem'
|
54
|
+
* import { mainnet, zksync } from 'viem/chains'
|
55
|
+
* import { isWithdrawalFinalized } from 'viem/zksync'
|
56
|
+
*
|
57
|
+
* const client = createPublicClient({
|
58
|
+
* chain: mainnet,
|
59
|
+
* transport: http(),
|
60
|
+
* })
|
61
|
+
*
|
62
|
+
* const clientL2 = createPublicClient({
|
63
|
+
* chain: zksync,
|
64
|
+
* transport: http(),
|
65
|
+
* })
|
66
|
+
*
|
67
|
+
* const hash = await isWithdrawalFinalized(client, {
|
68
|
+
* client: clientL2,
|
69
|
+
* hash: '0x...',
|
70
|
+
* })
|
71
|
+
*/
|
72
|
+
export async function isWithdrawalFinalized<
|
73
|
+
chain extends Chain | undefined,
|
74
|
+
account extends Account | undefined,
|
75
|
+
chainL2 extends ChainEIP712 | undefined,
|
76
|
+
accountL2 extends Account | undefined,
|
77
|
+
>(
|
78
|
+
client: Client<Transport, chain, account>,
|
79
|
+
parameters: IsWithdrawalFinalizedParameters<chainL2, accountL2>,
|
80
|
+
): Promise<IsWithdrawalFinalizedReturnType> {
|
81
|
+
const { client: l2Client, hash, index = 0 } = parameters
|
82
|
+
|
83
|
+
if (!l2Client.chain) throw new ChainNotFoundError()
|
84
|
+
|
85
|
+
const { log } = await getWithdrawalLog(l2Client, { hash, index })
|
86
|
+
const { l2ToL1LogIndex } = await getWithdrawalL2ToL1Log(l2Client, {
|
87
|
+
hash,
|
88
|
+
index,
|
89
|
+
})
|
90
|
+
const sender = slice(log.topics[1]!, 12) as Address
|
91
|
+
// `getLogProof` is called not to get proof but
|
92
|
+
// to get the index of the corresponding L2->L1 log,
|
93
|
+
// which is returned as `proof.id`.
|
94
|
+
const proof = await getLogProof(l2Client, {
|
95
|
+
txHash: hash,
|
96
|
+
index: l2ToL1LogIndex!,
|
97
|
+
})
|
98
|
+
if (!proof) {
|
99
|
+
throw new WithdrawalLogNotFoundError({ hash })
|
100
|
+
}
|
101
|
+
|
102
|
+
let l1Bridge: Address
|
103
|
+
if (
|
104
|
+
isAddressEqual(sender, await getBaseTokenL1Address(l2Client)) ||
|
105
|
+
isAddressEqual(sender, l2BaseTokenAddress)
|
106
|
+
)
|
107
|
+
l1Bridge = (await getDefaultBridgeAddresses(l2Client)).sharedL1
|
108
|
+
else
|
109
|
+
l1Bridge = await readContract(l2Client, {
|
110
|
+
address: sender,
|
111
|
+
abi: l2SharedBridgeAbi,
|
112
|
+
functionName: 'l1SharedBridge',
|
113
|
+
args: [],
|
114
|
+
})
|
115
|
+
|
116
|
+
return await readContract(client, {
|
117
|
+
address: l1Bridge,
|
118
|
+
abi: l1SharedBridgeAbi,
|
119
|
+
functionName: 'isWithdrawalFinalized',
|
120
|
+
args: [BigInt(l2Client.chain.id), log.l1BatchNumber!, BigInt(proof.id)],
|
121
|
+
})
|
122
|
+
}
|
@@ -17,6 +17,11 @@ import {
|
|
17
17
|
type GetL1TokenBalanceReturnType,
|
18
18
|
getL1TokenBalance,
|
19
19
|
} from '../actions/getL1TokenBalance.js'
|
20
|
+
import {
|
21
|
+
type IsWithdrawalFinalizedParameters,
|
22
|
+
type IsWithdrawalFinalizedReturnType,
|
23
|
+
isWithdrawalFinalized,
|
24
|
+
} from '../actions/isWithdrawalFinalized.js'
|
20
25
|
|
21
26
|
export type PublicActionsL1<
|
22
27
|
account extends Account | undefined = Account | undefined,
|
@@ -163,6 +168,36 @@ export type PublicActionsL1<
|
|
163
168
|
? [GetL1BalanceParameters<account>]
|
164
169
|
: [GetL1BalanceParameters<account>] | []
|
165
170
|
) => Promise<GetL1BalanceReturnType>
|
171
|
+
/**
|
172
|
+
* Returns whether the withdrawal transaction is finalized on the L1 network.
|
173
|
+
*
|
174
|
+
* @param client - Client to use
|
175
|
+
* @param parameters - {@link IsWithdrawalFinalizedParameters}
|
176
|
+
* @returns bool - Whether the withdrawal transaction is finalized on the L1 network. {@link IsWithdrawalFinalizedReturnType}
|
177
|
+
*
|
178
|
+
* @example
|
179
|
+
* import { createPublicClient, http } from 'viem'
|
180
|
+
* import { mainnet, zksync } from 'viem/chains'
|
181
|
+
* import { publicActionsL1, publicActionsL2 } from 'viem/zksync'
|
182
|
+
*
|
183
|
+
* const client = createPublicClient({
|
184
|
+
* chain: mainnet,
|
185
|
+
* transport: http(),
|
186
|
+
* }).extend(publicActionsL1())
|
187
|
+
*
|
188
|
+
* const clientL2 = createPublicClient({
|
189
|
+
* chain: zksync,
|
190
|
+
* transport: http(),
|
191
|
+
* }).extend(publicActionsL2())
|
192
|
+
*
|
193
|
+
* const hash = await client.isWithdrawalFinalized({
|
194
|
+
* client: clientL2,
|
195
|
+
* hash: '0x...',
|
196
|
+
* })
|
197
|
+
*/
|
198
|
+
isWithdrawalFinalized: (
|
199
|
+
parameters: IsWithdrawalFinalizedParameters,
|
200
|
+
) => Promise<IsWithdrawalFinalizedReturnType>
|
166
201
|
}
|
167
202
|
|
168
203
|
export function publicActionsL1() {
|
@@ -176,5 +211,6 @@ export function publicActionsL1() {
|
|
176
211
|
getL1TokenBalance: (args) => getL1TokenBalance(client, args),
|
177
212
|
// @ts-expect-error
|
178
213
|
getL1Balance: (args) => getL1Balance(client, args),
|
214
|
+
isWithdrawalFinalized: (args) => isWithdrawalFinalized(client, args),
|
179
215
|
})
|
180
216
|
}
|
package/zksync/index.ts
CHANGED
@@ -95,6 +95,12 @@ export {
|
|
95
95
|
type GetTransactionDetailsReturnType,
|
96
96
|
getTransactionDetails,
|
97
97
|
} from './actions/getTransactionDetails.js'
|
98
|
+
export {
|
99
|
+
type IsWithdrawalFinalizedErrorType,
|
100
|
+
type IsWithdrawalFinalizedReturnType,
|
101
|
+
type IsWithdrawalFinalizedParameters,
|
102
|
+
isWithdrawalFinalized,
|
103
|
+
} from './actions/isWithdrawalFinalized.js'
|
98
104
|
export {
|
99
105
|
type RequestExecuteErrorType,
|
100
106
|
type RequestExecuteReturnType,
|