viem 2.23.2 → 2.23.3
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 +28 -0
- package/_cjs/chains/definitions/b3.js +6 -0
- package/_cjs/chains/definitions/b3.js.map +1 -1
- package/_cjs/chains/definitions/b3Sepolia.js +6 -0
- package/_cjs/chains/definitions/b3Sepolia.js.map +1 -1
- package/_cjs/chains/definitions/berachainTestnet.js +6 -0
- package/_cjs/chains/definitions/berachainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/donatuz.js +1 -1
- package/_cjs/chains/definitions/donatuz.js.map +1 -1
- package/_cjs/chains/definitions/hashkeyChainTestnet.js +1 -0
- package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/haustTestnet.js +26 -0
- package/_cjs/chains/definitions/haustTestnet.js.map +1 -0
- package/_cjs/chains/definitions/lumoz.js +26 -0
- package/_cjs/chains/definitions/lumoz.js.map +1 -0
- package/_cjs/chains/definitions/lumozTestnet.js +20 -0
- package/_cjs/chains/definitions/lumozTestnet.js.map +1 -0
- package/_cjs/chains/definitions/newton.js +26 -0
- package/_cjs/chains/definitions/newton.js.map +1 -0
- package/_cjs/chains/definitions/peaq.js +41 -0
- package/_cjs/chains/definitions/peaq.js.map +1 -0
- package/_cjs/chains/definitions/polynomial.js +31 -0
- package/_cjs/chains/definitions/polynomial.js.map +1 -0
- package/_cjs/chains/definitions/polynomialSepolia.js +31 -0
- package/_cjs/chains/definitions/polynomialSepolia.js.map +1 -0
- package/_cjs/chains/definitions/story.js +7 -0
- package/_cjs/chains/definitions/story.js.map +1 -1
- package/_cjs/chains/definitions/storyAeneid.js +31 -0
- package/_cjs/chains/definitions/storyAeneid.js.map +1 -0
- package/_cjs/chains/definitions/worldchain.js +1 -1
- package/_cjs/chains/index.js +23 -7
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/op-stack/abis.js +7 -96
- package/_cjs/op-stack/abis.js.map +1 -1
- package/_cjs/op-stack/actions/getWithdrawalStatus.js +21 -14
- package/_cjs/op-stack/actions/getWithdrawalStatus.js.map +1 -1
- package/_cjs/zksync/actions/finalizeWithdrawal.js +99 -0
- package/_cjs/zksync/actions/finalizeWithdrawal.js.map +1 -0
- package/_cjs/zksync/constants/abis.js +724 -1
- package/_cjs/zksync/constants/abis.js.map +1 -1
- package/_cjs/zksync/constants/address.js +2 -1
- package/_cjs/zksync/constants/address.js.map +1 -1
- package/_cjs/zksync/decorators/walletL1.js +2 -0
- package/_cjs/zksync/decorators/walletL1.js.map +1 -1
- package/_cjs/zksync/errors/bridge.js +11 -1
- package/_cjs/zksync/errors/bridge.js.map +1 -1
- package/_cjs/zksync/index.js +4 -2
- package/_cjs/zksync/index.js.map +1 -1
- package/_cjs/zksync/utils/bridge/getWithdrawalL2ToL1Log.js +19 -0
- package/_cjs/zksync/utils/bridge/getWithdrawalL2ToL1Log.js.map +1 -0
- package/_cjs/zksync/utils/bridge/getWithdrawalLog.js +19 -0
- package/_cjs/zksync/utils/bridge/getWithdrawalLog.js.map +1 -0
- package/_esm/chains/definitions/b3.js +6 -0
- package/_esm/chains/definitions/b3.js.map +1 -1
- package/_esm/chains/definitions/b3Sepolia.js +6 -0
- package/_esm/chains/definitions/b3Sepolia.js.map +1 -1
- package/_esm/chains/definitions/berachainTestnet.js +6 -0
- package/_esm/chains/definitions/berachainTestnet.js.map +1 -1
- package/_esm/chains/definitions/donatuz.js +1 -1
- package/_esm/chains/definitions/donatuz.js.map +1 -1
- package/_esm/chains/definitions/hashkeyChainTestnet.js +1 -0
- package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_esm/chains/definitions/haustTestnet.js +23 -0
- package/_esm/chains/definitions/haustTestnet.js.map +1 -0
- package/_esm/chains/definitions/lumoz.js +23 -0
- package/_esm/chains/definitions/lumoz.js.map +1 -0
- package/_esm/chains/definitions/lumozTestnet.js +17 -0
- package/_esm/chains/definitions/lumozTestnet.js.map +1 -0
- package/_esm/chains/definitions/newton.js +23 -0
- package/_esm/chains/definitions/newton.js.map +1 -0
- package/_esm/chains/definitions/peaq.js +38 -0
- package/_esm/chains/definitions/peaq.js.map +1 -0
- package/_esm/chains/definitions/polynomial.js +28 -0
- package/_esm/chains/definitions/polynomial.js.map +1 -0
- package/_esm/chains/definitions/polynomialSepolia.js +28 -0
- package/_esm/chains/definitions/polynomialSepolia.js.map +1 -0
- package/_esm/chains/definitions/story.js +7 -0
- package/_esm/chains/definitions/story.js.map +1 -1
- package/_esm/chains/definitions/storyAeneid.js +28 -0
- package/_esm/chains/definitions/storyAeneid.js.map +1 -0
- package/_esm/chains/definitions/worldchain.js +1 -1
- package/_esm/chains/index.js +10 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/op-stack/abis.js +7 -96
- package/_esm/op-stack/abis.js.map +1 -1
- package/_esm/op-stack/actions/getWithdrawalStatus.js +25 -14
- package/_esm/op-stack/actions/getWithdrawalStatus.js.map +1 -1
- package/_esm/zksync/actions/finalizeWithdrawal.js +147 -0
- package/_esm/zksync/actions/finalizeWithdrawal.js.map +1 -0
- package/_esm/zksync/constants/abis.js +723 -0
- package/_esm/zksync/constants/abis.js.map +1 -1
- package/_esm/zksync/constants/address.js +1 -0
- package/_esm/zksync/constants/address.js.map +1 -1
- package/_esm/zksync/decorators/walletL1.js +2 -0
- package/_esm/zksync/decorators/walletL1.js.map +1 -1
- package/_esm/zksync/errors/bridge.js +9 -0
- package/_esm/zksync/errors/bridge.js.map +1 -1
- package/_esm/zksync/index.js +1 -0
- package/_esm/zksync/index.js.map +1 -1
- package/_esm/zksync/utils/bridge/getWithdrawalL2ToL1Log.js +17 -0
- package/_esm/zksync/utils/bridge/getWithdrawalL2ToL1Log.js.map +1 -0
- package/_esm/zksync/utils/bridge/getWithdrawalLog.js +17 -0
- package/_esm/zksync/utils/bridge/getWithdrawalLog.js.map +1 -0
- package/_types/chains/definitions/b3.d.ts +6 -10
- package/_types/chains/definitions/b3.d.ts.map +1 -1
- package/_types/chains/definitions/b3Sepolia.d.ts +6 -10
- package/_types/chains/definitions/b3Sepolia.d.ts.map +1 -1
- package/_types/chains/definitions/berachainTestnet.d.ts +6 -10
- package/_types/chains/definitions/berachainTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/donatuz.d.ts +1 -1
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts +1 -1
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/haustTestnet.d.ts +37 -0
- package/_types/chains/definitions/haustTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/lumoz.d.ts +37 -0
- package/_types/chains/definitions/lumoz.d.ts.map +1 -0
- package/_types/chains/definitions/lumozTestnet.d.ts +43 -0
- package/_types/chains/definitions/lumozTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/newton.d.ts +37 -0
- package/_types/chains/definitions/newton.d.ts.map +1 -0
- package/_types/chains/definitions/peaq.d.ts +34 -0
- package/_types/chains/definitions/peaq.d.ts.map +1 -0
- package/_types/chains/definitions/polynomial.d.ts +32 -0
- package/_types/chains/definitions/polynomial.d.ts.map +1 -0
- package/_types/chains/definitions/polynomialSepolia.d.ts +32 -0
- package/_types/chains/definitions/polynomialSepolia.d.ts.map +1 -0
- package/_types/chains/definitions/story.d.ts +6 -11
- package/_types/chains/definitions/story.d.ts.map +1 -1
- package/_types/chains/definitions/storyAeneid.d.ts +34 -0
- package/_types/chains/definitions/storyAeneid.d.ts.map +1 -0
- package/_types/chains/definitions/worldchain.d.ts +1 -1
- package/_types/chains/index.d.ts +10 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/op-stack/abis.d.ts +7 -77
- package/_types/op-stack/abis.d.ts.map +1 -1
- package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
- package/_types/zksync/actions/finalizeWithdrawal.d.ts +73 -0
- package/_types/zksync/actions/finalizeWithdrawal.d.ts.map +1 -0
- package/_types/zksync/constants/abis.d.ts +567 -0
- package/_types/zksync/constants/abis.d.ts.map +1 -1
- package/_types/zksync/constants/address.d.ts +1 -0
- package/_types/zksync/constants/address.d.ts.map +1 -1
- package/_types/zksync/decorators/walletL1.d.ts +31 -0
- package/_types/zksync/decorators/walletL1.d.ts.map +1 -1
- package/_types/zksync/errors/bridge.d.ts +9 -0
- package/_types/zksync/errors/bridge.d.ts.map +1 -1
- package/_types/zksync/index.d.ts +1 -0
- package/_types/zksync/index.d.ts.map +1 -1
- package/_types/zksync/utils/bridge/getWithdrawalL2ToL1Log.d.ts +20 -0
- package/_types/zksync/utils/bridge/getWithdrawalL2ToL1Log.d.ts.map +1 -0
- package/_types/zksync/utils/bridge/getWithdrawalLog.d.ts +20 -0
- package/_types/zksync/utils/bridge/getWithdrawalLog.d.ts.map +1 -0
- package/chains/definitions/b3.ts +6 -0
- package/chains/definitions/b3Sepolia.ts +6 -0
- package/chains/definitions/berachainTestnet.ts +6 -0
- package/chains/definitions/donatuz.ts +1 -1
- package/chains/definitions/hashkeyChainTestnet.ts +1 -0
- package/chains/definitions/haustTestnet.ts +23 -0
- package/chains/definitions/lumoz.ts +23 -0
- package/chains/definitions/lumozTestnet.ts +17 -0
- package/chains/definitions/newton.ts +23 -0
- package/chains/definitions/peaq.ts +38 -0
- package/chains/definitions/polynomial.ts +28 -0
- package/chains/definitions/polynomialSepolia.ts +28 -0
- package/chains/definitions/story.ts +7 -0
- package/chains/definitions/storyAeneid.ts +28 -0
- package/chains/definitions/worldchain.ts +1 -1
- package/chains/index.ts +10 -0
- package/errors/version.ts +1 -1
- package/op-stack/abis.ts +7 -96
- package/op-stack/actions/getWithdrawalStatus.ts +28 -17
- package/package.json +1 -1
- package/zksync/actions/finalizeWithdrawal.ts +248 -0
- package/zksync/constants/abis.ts +724 -0
- package/zksync/constants/address.ts +3 -0
- package/zksync/decorators/walletL1.ts +48 -0
- package/zksync/errors/bridge.ts +17 -0
- package/zksync/index.ts +6 -0
- package/zksync/utils/bridge/getWithdrawalL2ToL1Log.ts +47 -0
- package/zksync/utils/bridge/getWithdrawalLog.ts +47 -0
@@ -249,27 +249,38 @@ export async function getWithdrawalStatus<
|
|
249
249
|
if (checkWithdrawalResult.status === 'rejected') {
|
250
250
|
const error = checkWithdrawalResult.reason as ReadContractErrorType
|
251
251
|
if (error.cause instanceof ContractFunctionRevertedError) {
|
252
|
-
|
253
|
-
if
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
'OptimismPortal: withdrawal has not been proven
|
258
|
-
|
259
|
-
'OptimismPortal: dispute game created before respected game type was updated'
|
260
|
-
|
252
|
+
// All potential error causes listed here, can either be the error string or the error name
|
253
|
+
// if custom error types are returned.
|
254
|
+
const errorCauses = {
|
255
|
+
'ready-to-prove': [
|
256
|
+
'OptimismPortal: invalid game type',
|
257
|
+
'OptimismPortal: withdrawal has not been proven yet',
|
258
|
+
'OptimismPortal: withdrawal has not been proven by proof submitter address yet',
|
259
|
+
'OptimismPortal: dispute game created before respected game type was updated',
|
260
|
+
'InvalidGameType',
|
261
|
+
'LegacyGame',
|
262
|
+
],
|
263
|
+
'waiting-to-finalize': [
|
264
|
+
'OptimismPortal: proven withdrawal has not matured yet',
|
265
|
+
'OptimismPortal: output proposal has not been finalized yet',
|
266
|
+
'OptimismPortal: output proposal in air-gap',
|
267
|
+
],
|
268
|
+
}
|
269
|
+
|
270
|
+
// Pick out the error message and/or error name
|
271
|
+
// Return the status based on the error
|
272
|
+
const errors = [
|
273
|
+
error.cause.data?.errorName,
|
274
|
+
error.cause.data?.args?.[0] as string,
|
275
|
+
]
|
276
|
+
if (errorCauses['ready-to-prove'].some((cause) => errors.includes(cause)))
|
261
277
|
return 'ready-to-prove'
|
262
278
|
if (
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
'OptimismPortal: output proposal has not been finalized yet' ||
|
267
|
-
errorMessage === 'OptimismPortal: output proposal in air-gap'
|
279
|
+
errorCauses['waiting-to-finalize'].some((cause) =>
|
280
|
+
errors.includes(cause),
|
281
|
+
)
|
268
282
|
)
|
269
283
|
return 'waiting-to-finalize'
|
270
|
-
|
271
|
-
if (error.cause.data?.errorName === 'InvalidGameType')
|
272
|
-
return 'ready-to-prove'
|
273
284
|
}
|
274
285
|
throw checkWithdrawalResult.reason
|
275
286
|
}
|
package/package.json
CHANGED
@@ -0,0 +1,248 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Account } from '../../accounts/types.js'
|
3
|
+
import { readContract } from '../../actions/public/readContract.js'
|
4
|
+
import {
|
5
|
+
type SendTransactionErrorType,
|
6
|
+
type SendTransactionParameters,
|
7
|
+
type SendTransactionRequest,
|
8
|
+
type SendTransactionReturnType,
|
9
|
+
sendTransaction,
|
10
|
+
} from '../../actions/wallet/sendTransaction.js'
|
11
|
+
import type { Client } from '../../clients/createClient.js'
|
12
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
13
|
+
import { AccountNotFoundError } from '../../errors/account.js'
|
14
|
+
import {
|
15
|
+
ChainNotFoundError,
|
16
|
+
type ChainNotFoundErrorType,
|
17
|
+
} from '../../errors/chain.js'
|
18
|
+
import type { Chain } from '../../types/chain.js'
|
19
|
+
import type { Hex } from '../../types/misc.js'
|
20
|
+
import {
|
21
|
+
decodeAbiParameters,
|
22
|
+
encodeFunctionData,
|
23
|
+
isAddressEqual,
|
24
|
+
parseAccount,
|
25
|
+
slice,
|
26
|
+
} from '../../utils/index.js'
|
27
|
+
import { l1SharedBridgeAbi, l2SharedBridgeAbi } from '../constants/abis.js'
|
28
|
+
import { l2BaseTokenAddress } from '../constants/address.js'
|
29
|
+
import {
|
30
|
+
WithdrawalLogNotFoundError,
|
31
|
+
type WithdrawalLogNotFoundErrorType,
|
32
|
+
} from '../errors/bridge.js'
|
33
|
+
import type { ChainEIP712 } from '../types/chain.js'
|
34
|
+
import { getWithdrawalL2ToL1Log } from '../utils/bridge/getWithdrawalL2ToL1Log.js'
|
35
|
+
import { getWithdrawalLog } from '../utils/bridge/getWithdrawalLog.js'
|
36
|
+
import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
|
37
|
+
import { getLogProof } from './getLogProof.js'
|
38
|
+
|
39
|
+
export type FinalizeWithdrawalParameters<
|
40
|
+
chain extends Chain | undefined = Chain | undefined,
|
41
|
+
account extends Account | undefined = Account | undefined,
|
42
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
43
|
+
chainL2 extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
44
|
+
accountL2 extends Account | undefined = Account | undefined,
|
45
|
+
request extends SendTransactionRequest<
|
46
|
+
chain,
|
47
|
+
chainOverride
|
48
|
+
> = SendTransactionRequest<chain, chainOverride>,
|
49
|
+
> = Omit<
|
50
|
+
SendTransactionParameters<chain, account, chainOverride, request>,
|
51
|
+
'value' | 'data' | 'to'
|
52
|
+
> & {
|
53
|
+
/** L2 client */
|
54
|
+
client: Client<Transport, chainL2, accountL2>
|
55
|
+
/** Hash of the L2 transaction where the withdrawal was initiated. */
|
56
|
+
hash: Hex
|
57
|
+
/** In case there were multiple withdrawals in one transaction, you may pass an index of the
|
58
|
+
withdrawal you want to finalize. */
|
59
|
+
index?: number | undefined
|
60
|
+
}
|
61
|
+
|
62
|
+
export type FinalizeWithdrawalReturnType = SendTransactionReturnType
|
63
|
+
|
64
|
+
export type FinalizeWithdrawalErrorType =
|
65
|
+
| SendTransactionErrorType
|
66
|
+
| WithdrawalLogNotFoundErrorType
|
67
|
+
| ChainNotFoundErrorType
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Proves the inclusion of the `L2->L1` withdrawal message.
|
71
|
+
*
|
72
|
+
* @param client - Client to use
|
73
|
+
* @param parameters - {@link FinalizeWithdrawalParameters}
|
74
|
+
* @returns hash - The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link FinalizeWithdrawalReturnType}
|
75
|
+
*
|
76
|
+
* @example
|
77
|
+
* import { createPublicClient, http } from 'viem'
|
78
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
79
|
+
* import { mainnet, zksync } from 'viem/chains'
|
80
|
+
* import { finalizeWithdrawal, publicActionsL2 } from 'viem/zksync'
|
81
|
+
*
|
82
|
+
* const client = createPublicClient({
|
83
|
+
* chain: mainnet,
|
84
|
+
* transport: http(),
|
85
|
+
* })
|
86
|
+
*
|
87
|
+
* const clientL2 = createPublicClient({
|
88
|
+
* chain: zksync,
|
89
|
+
* transport: http(),
|
90
|
+
* }).extend(publicActionsL2())
|
91
|
+
*
|
92
|
+
* const hash = await finalizeWithdrawal(client, {
|
93
|
+
* account: privateKeyToAccount('0x…'),
|
94
|
+
* client: clientL2,
|
95
|
+
* hash: '0x...',
|
96
|
+
* })
|
97
|
+
*
|
98
|
+
* @example Account Hoisting
|
99
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
100
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
101
|
+
* import { mainnet, zksync } from 'viem/chains'
|
102
|
+
* import { finalizeWithdrawal, publicActionsL2 } from 'viem/zksync'
|
103
|
+
*
|
104
|
+
* const client = createWalletClient({
|
105
|
+
* account: privateKeyToAccount('0x…'),
|
106
|
+
* chain: mainnet,
|
107
|
+
* transport: http(),
|
108
|
+
* })
|
109
|
+
*
|
110
|
+
* const clientL2 = createPublicClient({
|
111
|
+
* chain: zksync,
|
112
|
+
* transport: http(),
|
113
|
+
* }).extend(publicActionsL2())
|
114
|
+
*
|
115
|
+
* const hash = await finalizeWithdrawal(client, {
|
116
|
+
* client: clientL2,
|
117
|
+
* hash: '0x…',
|
118
|
+
* })
|
119
|
+
*/
|
120
|
+
export async function finalizeWithdrawal<
|
121
|
+
chain extends Chain | undefined,
|
122
|
+
account extends Account | undefined,
|
123
|
+
accountL2 extends Account | undefined,
|
124
|
+
const request extends SendTransactionRequest<chain, chainOverride>,
|
125
|
+
chainOverride extends Chain | undefined,
|
126
|
+
chainL2 extends ChainEIP712 | undefined,
|
127
|
+
>(
|
128
|
+
client: Client<Transport, chain, account>,
|
129
|
+
parameters: FinalizeWithdrawalParameters<
|
130
|
+
chain,
|
131
|
+
account,
|
132
|
+
chainOverride,
|
133
|
+
chainL2,
|
134
|
+
accountL2,
|
135
|
+
request
|
136
|
+
>,
|
137
|
+
): Promise<FinalizeWithdrawalReturnType> {
|
138
|
+
const {
|
139
|
+
account: account_ = client.account,
|
140
|
+
client: l2Client,
|
141
|
+
hash,
|
142
|
+
index = 0,
|
143
|
+
...rest
|
144
|
+
} = parameters
|
145
|
+
const account = account_ ? parseAccount(account_) : client.account
|
146
|
+
if (!account)
|
147
|
+
throw new AccountNotFoundError({
|
148
|
+
docsPath: '/docs/actions/wallet/sendTransaction',
|
149
|
+
})
|
150
|
+
if (!l2Client.chain) throw new ChainNotFoundError()
|
151
|
+
|
152
|
+
const {
|
153
|
+
l1BatchNumber,
|
154
|
+
l2MessageIndex,
|
155
|
+
l2TxNumberInBlock,
|
156
|
+
message,
|
157
|
+
sender,
|
158
|
+
proof,
|
159
|
+
} = await getFinalizeWithdrawalParams(l2Client, { hash, index })
|
160
|
+
|
161
|
+
let l1Bridge: Address
|
162
|
+
|
163
|
+
if (isAddressEqual(sender, l2BaseTokenAddress))
|
164
|
+
l1Bridge = (await getDefaultBridgeAddresses(l2Client)).sharedL1
|
165
|
+
else if (!(await isLegacyBridge(l2Client, { address: sender })))
|
166
|
+
l1Bridge = await readContract(l2Client, {
|
167
|
+
address: sender,
|
168
|
+
abi: l2SharedBridgeAbi,
|
169
|
+
functionName: 'l1SharedBridge',
|
170
|
+
args: [],
|
171
|
+
})
|
172
|
+
else
|
173
|
+
l1Bridge = await readContract(l2Client, {
|
174
|
+
address: sender,
|
175
|
+
abi: l2SharedBridgeAbi,
|
176
|
+
functionName: 'l1Bridge',
|
177
|
+
args: [],
|
178
|
+
})
|
179
|
+
|
180
|
+
const data = encodeFunctionData({
|
181
|
+
abi: l1SharedBridgeAbi,
|
182
|
+
functionName: 'finalizeWithdrawal',
|
183
|
+
args: [
|
184
|
+
BigInt(l2Client.chain.id),
|
185
|
+
l1BatchNumber!,
|
186
|
+
BigInt(l2MessageIndex),
|
187
|
+
Number(l2TxNumberInBlock),
|
188
|
+
message,
|
189
|
+
proof,
|
190
|
+
],
|
191
|
+
})
|
192
|
+
|
193
|
+
return await sendTransaction(client, {
|
194
|
+
account,
|
195
|
+
to: l1Bridge,
|
196
|
+
data,
|
197
|
+
value: 0n,
|
198
|
+
...rest,
|
199
|
+
} as SendTransactionParameters)
|
200
|
+
}
|
201
|
+
|
202
|
+
async function getFinalizeWithdrawalParams<
|
203
|
+
chain extends Chain | undefined,
|
204
|
+
account extends Account | undefined,
|
205
|
+
>(
|
206
|
+
client: Client<Transport, chain, account>,
|
207
|
+
parameters: { hash: Hex; index: number },
|
208
|
+
) {
|
209
|
+
const { hash } = parameters
|
210
|
+
const { log, l1BatchTxId } = await getWithdrawalLog(client, parameters)
|
211
|
+
const { l2ToL1LogIndex } = await getWithdrawalL2ToL1Log(client, parameters)
|
212
|
+
const sender = slice(log.topics[1]!, 12) as Address
|
213
|
+
const proof = await getLogProof(client, {
|
214
|
+
txHash: hash,
|
215
|
+
index: l2ToL1LogIndex!,
|
216
|
+
})
|
217
|
+
if (!proof) {
|
218
|
+
throw new WithdrawalLogNotFoundError({ hash })
|
219
|
+
}
|
220
|
+
|
221
|
+
const [message] = decodeAbiParameters([{ type: 'bytes' }], log.data)
|
222
|
+
|
223
|
+
return {
|
224
|
+
l1BatchNumber: log.l1BatchNumber,
|
225
|
+
l2MessageIndex: proof.id,
|
226
|
+
l2TxNumberInBlock: l1BatchTxId,
|
227
|
+
message,
|
228
|
+
sender,
|
229
|
+
proof: proof.proof,
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
async function isLegacyBridge<
|
234
|
+
chain extends Chain | undefined,
|
235
|
+
account extends Account | undefined,
|
236
|
+
>(client: Client<Transport, chain, account>, parameters: { address: Address }) {
|
237
|
+
try {
|
238
|
+
await readContract(client, {
|
239
|
+
address: parameters.address,
|
240
|
+
abi: l2SharedBridgeAbi,
|
241
|
+
functionName: 'l1SharedBridge',
|
242
|
+
args: [],
|
243
|
+
})
|
244
|
+
return false
|
245
|
+
} catch (_e) {
|
246
|
+
return true
|
247
|
+
}
|
248
|
+
}
|