viem 2.23.2 → 2.23.4
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 +38 -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/ethernity.js +30 -0
- package/_cjs/chains/definitions/ethernity.js.map +1 -0
- 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/definitions/xdc.js +1 -1
- package/_cjs/chains/definitions/xdc.js.map +1 -1
- package/_cjs/chains/index.js +27 -9
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/eip5792/actions/sendCalls.js +3 -3
- package/_cjs/experimental/eip5792/actions/sendCalls.js.map +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 +38 -21
- 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/ethernity.js +27 -0
- package/_esm/chains/definitions/ethernity.js.map +1 -0
- 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/definitions/xdc.js +1 -1
- package/_esm/chains/definitions/xdc.js.map +1 -1
- package/_esm/chains/index.js +11 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/eip5792/actions/sendCalls.js +3 -3
- package/_esm/experimental/eip5792/actions/sendCalls.js.map +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 +42 -21
- 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/ethernity.d.ts +33 -0
- package/_types/chains/definitions/ethernity.d.ts.map +1 -0
- 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/definitions/xdc.d.ts +1 -1
- package/_types/chains/index.d.ts +11 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/eip5792/actions/sendCalls.d.ts +2 -2
- package/_types/experimental/eip5792/actions/sendCalls.d.ts.map +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 +20 -1
- package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +1 -3
- package/_types/types/eip1193.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/ethernity.ts +27 -0
- 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/definitions/xdc.ts +1 -1
- package/chains/index.ts +11 -0
- package/errors/version.ts +1 -1
- package/experimental/eip5792/actions/sendCalls.ts +5 -5
- package/op-stack/abis.ts +7 -96
- package/op-stack/actions/getWithdrawalStatus.ts +74 -31
- package/package.json +1 -1
- package/types/eip1193.ts +1 -3
- 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
package/op-stack/abis.ts
CHANGED
@@ -917,19 +917,6 @@ export const portal2Abi = [
|
|
917
917
|
stateMutability: 'payable',
|
918
918
|
type: 'receive',
|
919
919
|
},
|
920
|
-
{
|
921
|
-
inputs: [],
|
922
|
-
name: 'balance',
|
923
|
-
outputs: [
|
924
|
-
{
|
925
|
-
internalType: 'uint256',
|
926
|
-
name: '',
|
927
|
-
type: 'uint256',
|
928
|
-
},
|
929
|
-
],
|
930
|
-
stateMutability: 'view',
|
931
|
-
type: 'function',
|
932
|
-
},
|
933
920
|
{
|
934
921
|
inputs: [
|
935
922
|
{
|
@@ -961,44 +948,6 @@ export const portal2Abi = [
|
|
961
948
|
stateMutability: 'view',
|
962
949
|
type: 'function',
|
963
950
|
},
|
964
|
-
{
|
965
|
-
inputs: [
|
966
|
-
{
|
967
|
-
internalType: 'address',
|
968
|
-
name: '_to',
|
969
|
-
type: 'address',
|
970
|
-
},
|
971
|
-
{
|
972
|
-
internalType: 'uint256',
|
973
|
-
name: '_mint',
|
974
|
-
type: 'uint256',
|
975
|
-
},
|
976
|
-
{
|
977
|
-
internalType: 'uint256',
|
978
|
-
name: '_value',
|
979
|
-
type: 'uint256',
|
980
|
-
},
|
981
|
-
{
|
982
|
-
internalType: 'uint64',
|
983
|
-
name: '_gasLimit',
|
984
|
-
type: 'uint64',
|
985
|
-
},
|
986
|
-
{
|
987
|
-
internalType: 'bool',
|
988
|
-
name: '_isCreation',
|
989
|
-
type: 'bool',
|
990
|
-
},
|
991
|
-
{
|
992
|
-
internalType: 'bytes',
|
993
|
-
name: '_data',
|
994
|
-
type: 'bytes',
|
995
|
-
},
|
996
|
-
],
|
997
|
-
name: 'depositERC20Transaction',
|
998
|
-
outputs: [],
|
999
|
-
stateMutability: 'nonpayable',
|
1000
|
-
type: 'function',
|
1001
|
-
},
|
1002
951
|
{
|
1003
952
|
inputs: [
|
1004
953
|
{
|
@@ -1056,7 +1005,7 @@ export const portal2Abi = [
|
|
1056
1005
|
name: 'disputeGameFactory',
|
1057
1006
|
outputs: [
|
1058
1007
|
{
|
1059
|
-
internalType: 'contract
|
1008
|
+
internalType: 'contract IDisputeGameFactory',
|
1060
1009
|
name: '',
|
1061
1010
|
type: 'address',
|
1062
1011
|
},
|
@@ -1214,17 +1163,17 @@ export const portal2Abi = [
|
|
1214
1163
|
{
|
1215
1164
|
inputs: [
|
1216
1165
|
{
|
1217
|
-
internalType: 'contract
|
1166
|
+
internalType: 'contract IDisputeGameFactory',
|
1218
1167
|
name: '_disputeGameFactory',
|
1219
1168
|
type: 'address',
|
1220
1169
|
},
|
1221
1170
|
{
|
1222
|
-
internalType: 'contract
|
1171
|
+
internalType: 'contract ISystemConfig',
|
1223
1172
|
name: '_systemConfig',
|
1224
1173
|
type: 'address',
|
1225
1174
|
},
|
1226
1175
|
{
|
1227
|
-
internalType: 'contract
|
1176
|
+
internalType: 'contract ISuperchainConfig',
|
1228
1177
|
name: '_superchainConfig',
|
1229
1178
|
type: 'address',
|
1230
1179
|
},
|
@@ -1500,34 +1449,6 @@ export const portal2Abi = [
|
|
1500
1449
|
stateMutability: 'view',
|
1501
1450
|
type: 'function',
|
1502
1451
|
},
|
1503
|
-
{
|
1504
|
-
inputs: [
|
1505
|
-
{
|
1506
|
-
internalType: 'address',
|
1507
|
-
name: '_token',
|
1508
|
-
type: 'address',
|
1509
|
-
},
|
1510
|
-
{
|
1511
|
-
internalType: 'uint8',
|
1512
|
-
name: '_decimals',
|
1513
|
-
type: 'uint8',
|
1514
|
-
},
|
1515
|
-
{
|
1516
|
-
internalType: 'bytes32',
|
1517
|
-
name: '_name',
|
1518
|
-
type: 'bytes32',
|
1519
|
-
},
|
1520
|
-
{
|
1521
|
-
internalType: 'bytes32',
|
1522
|
-
name: '_symbol',
|
1523
|
-
type: 'bytes32',
|
1524
|
-
},
|
1525
|
-
],
|
1526
|
-
name: 'setGasPayingToken',
|
1527
|
-
outputs: [],
|
1528
|
-
stateMutability: 'nonpayable',
|
1529
|
-
type: 'function',
|
1530
|
-
},
|
1531
1452
|
{
|
1532
1453
|
inputs: [
|
1533
1454
|
{
|
@@ -1546,7 +1467,7 @@ export const portal2Abi = [
|
|
1546
1467
|
name: 'superchainConfig',
|
1547
1468
|
outputs: [
|
1548
1469
|
{
|
1549
|
-
internalType: 'contract
|
1470
|
+
internalType: 'contract ISuperchainConfig',
|
1550
1471
|
name: '',
|
1551
1472
|
type: 'address',
|
1552
1473
|
},
|
@@ -1559,7 +1480,7 @@ export const portal2Abi = [
|
|
1559
1480
|
name: 'systemConfig',
|
1560
1481
|
outputs: [
|
1561
1482
|
{
|
1562
|
-
internalType: 'contract
|
1483
|
+
internalType: 'contract ISystemConfig',
|
1563
1484
|
name: '',
|
1564
1485
|
type: 'address',
|
1565
1486
|
},
|
@@ -1791,7 +1712,7 @@ export const portal2Abi = [
|
|
1791
1712
|
},
|
1792
1713
|
{
|
1793
1714
|
inputs: [],
|
1794
|
-
name: '
|
1715
|
+
name: 'LegacyGame',
|
1795
1716
|
type: 'error',
|
1796
1717
|
},
|
1797
1718
|
{
|
@@ -1799,11 +1720,6 @@ export const portal2Abi = [
|
|
1799
1720
|
name: 'NonReentrant',
|
1800
1721
|
type: 'error',
|
1801
1722
|
},
|
1802
|
-
{
|
1803
|
-
inputs: [],
|
1804
|
-
name: 'OnlyCustomGasToken',
|
1805
|
-
type: 'error',
|
1806
|
-
},
|
1807
1723
|
{
|
1808
1724
|
inputs: [],
|
1809
1725
|
name: 'OutOfGas',
|
@@ -1819,11 +1735,6 @@ export const portal2Abi = [
|
|
1819
1735
|
name: 'SmallGasLimit',
|
1820
1736
|
type: 'error',
|
1821
1737
|
},
|
1822
|
-
{
|
1823
|
-
inputs: [],
|
1824
|
-
name: 'TransferFailed',
|
1825
|
-
type: 'error',
|
1826
|
-
},
|
1827
1738
|
{
|
1828
1739
|
inputs: [],
|
1829
1740
|
name: 'Unauthorized',
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
1
2
|
import {
|
2
3
|
type ReadContractErrorType,
|
3
4
|
readContract,
|
@@ -12,6 +13,7 @@ import type {
|
|
12
13
|
DeriveChain,
|
13
14
|
GetChainParameter,
|
14
15
|
} from '../../types/chain.js'
|
16
|
+
import type { Hash } from '../../types/misc.js'
|
15
17
|
import type { TransactionReceipt } from '../../types/transaction.js'
|
16
18
|
import type { OneOf } from '../../types/utils.js'
|
17
19
|
import { portal2Abi, portalAbi } from '../abis.js'
|
@@ -62,13 +64,33 @@ export type GetWithdrawalStatusParameters<
|
|
62
64
|
* @default 100
|
63
65
|
*/
|
64
66
|
gameLimit?: number
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
} & OneOf<
|
68
|
+
| {
|
69
|
+
/**
|
70
|
+
* The relative index of the withdrawal in the transaction receipt logs.
|
71
|
+
* @default 0
|
72
|
+
*/
|
73
|
+
logIndex?: number
|
74
|
+
/**
|
75
|
+
* The transaction receipt of the withdrawal.
|
76
|
+
*/
|
77
|
+
receipt: TransactionReceipt
|
78
|
+
}
|
79
|
+
| {
|
80
|
+
/**
|
81
|
+
* The L2 block number of the withdrawal.
|
82
|
+
*/
|
83
|
+
l2BlockNumber: bigint
|
84
|
+
/**
|
85
|
+
* The sender of the withdrawal.
|
86
|
+
*/
|
87
|
+
sender: Address
|
88
|
+
/**
|
89
|
+
* The hash of the withdrawal.
|
90
|
+
*/
|
91
|
+
withdrawalHash: Hash
|
92
|
+
}
|
93
|
+
>
|
72
94
|
export type GetWithdrawalStatusReturnType =
|
73
95
|
| 'waiting-to-prove'
|
74
96
|
| 'ready-to-prove'
|
@@ -138,12 +160,22 @@ export async function getWithdrawalStatus<
|
|
138
160
|
return Object.values(targetChain.contracts.portal)[0].address
|
139
161
|
})()
|
140
162
|
|
141
|
-
const
|
163
|
+
const l2BlockNumber = receipt?.blockNumber ?? parameters.l2BlockNumber
|
142
164
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
165
|
+
const withdrawal = (() => {
|
166
|
+
if (receipt) {
|
167
|
+
const withdrawal = getWithdrawals({ logs: receipt.logs })[logIndex]
|
168
|
+
if (!withdrawal)
|
169
|
+
throw new ReceiptContainsNoWithdrawalsError({
|
170
|
+
hash: receipt.transactionHash,
|
171
|
+
})
|
172
|
+
return withdrawal
|
173
|
+
}
|
174
|
+
return {
|
175
|
+
sender: parameters.sender,
|
176
|
+
withdrawalHash: parameters.withdrawalHash,
|
177
|
+
}
|
178
|
+
})()
|
147
179
|
|
148
180
|
const portalVersion = await getPortalVersion(
|
149
181
|
client,
|
@@ -156,7 +188,7 @@ export async function getWithdrawalStatus<
|
|
156
188
|
await Promise.allSettled([
|
157
189
|
getL2Output(client, {
|
158
190
|
...parameters,
|
159
|
-
l2BlockNumber
|
191
|
+
l2BlockNumber,
|
160
192
|
} as GetL2OutputParameters),
|
161
193
|
readContract(client, {
|
162
194
|
abi: portalAbi,
|
@@ -221,7 +253,7 @@ export async function getWithdrawalStatus<
|
|
221
253
|
await Promise.allSettled([
|
222
254
|
getGame(client, {
|
223
255
|
...parameters,
|
224
|
-
l2BlockNumber
|
256
|
+
l2BlockNumber,
|
225
257
|
limit: gameLimit,
|
226
258
|
} as GetGameParameters),
|
227
259
|
readContract(client, {
|
@@ -249,27 +281,38 @@ export async function getWithdrawalStatus<
|
|
249
281
|
if (checkWithdrawalResult.status === 'rejected') {
|
250
282
|
const error = checkWithdrawalResult.reason as ReadContractErrorType
|
251
283
|
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
|
-
|
284
|
+
// All potential error causes listed here, can either be the error string or the error name
|
285
|
+
// if custom error types are returned.
|
286
|
+
const errorCauses = {
|
287
|
+
'ready-to-prove': [
|
288
|
+
'OptimismPortal: invalid game type',
|
289
|
+
'OptimismPortal: withdrawal has not been proven yet',
|
290
|
+
'OptimismPortal: withdrawal has not been proven by proof submitter address yet',
|
291
|
+
'OptimismPortal: dispute game created before respected game type was updated',
|
292
|
+
'InvalidGameType',
|
293
|
+
'LegacyGame',
|
294
|
+
],
|
295
|
+
'waiting-to-finalize': [
|
296
|
+
'OptimismPortal: proven withdrawal has not matured yet',
|
297
|
+
'OptimismPortal: output proposal has not been finalized yet',
|
298
|
+
'OptimismPortal: output proposal in air-gap',
|
299
|
+
],
|
300
|
+
}
|
301
|
+
|
302
|
+
// Pick out the error message and/or error name
|
303
|
+
// Return the status based on the error
|
304
|
+
const errors = [
|
305
|
+
error.cause.data?.errorName,
|
306
|
+
error.cause.data?.args?.[0] as string,
|
307
|
+
]
|
308
|
+
if (errorCauses['ready-to-prove'].some((cause) => errors.includes(cause)))
|
261
309
|
return 'ready-to-prove'
|
262
310
|
if (
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
'OptimismPortal: output proposal has not been finalized yet' ||
|
267
|
-
errorMessage === 'OptimismPortal: output proposal in air-gap'
|
311
|
+
errorCauses['waiting-to-finalize'].some((cause) =>
|
312
|
+
errors.includes(cause),
|
313
|
+
)
|
268
314
|
)
|
269
315
|
return 'waiting-to-finalize'
|
270
|
-
|
271
|
-
if (error.cause.data?.errorName === 'InvalidGameType')
|
272
|
-
return 'ready-to-prove'
|
273
316
|
}
|
274
317
|
throw checkWithdrawalResult.reason
|
275
318
|
}
|
package/package.json
CHANGED
package/types/eip1193.ts
CHANGED
@@ -210,15 +210,13 @@ export type WalletSendCallsParameters<
|
|
210
210
|
> = [
|
211
211
|
{
|
212
212
|
calls: readonly {
|
213
|
-
chainId?: chainId | undefined
|
214
213
|
to?: Address | undefined
|
215
214
|
data?: Hex | undefined
|
216
215
|
value?: quantity | undefined
|
217
216
|
}[]
|
218
217
|
capabilities?: capabilities | undefined
|
219
|
-
/** @deprecated Use `chainId` on `calls` instead. */
|
220
218
|
chainId?: chainId | undefined
|
221
|
-
from
|
219
|
+
from?: Address | undefined
|
222
220
|
version: string
|
223
221
|
},
|
224
222
|
]
|
@@ -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
|
+
}
|