@matterlabs/zksync-js 0.0.21 → 0.0.22
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/dist/adapters/ethers/client.cjs +31 -1
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.d.ts +11 -0
- package/dist/adapters/ethers/client.js +6 -5
- package/dist/adapters/ethers/index.cjs +1009 -274
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.d.ts +2 -1
- package/dist/adapters/ethers/index.js +10 -8
- package/dist/adapters/ethers/resources/withdrawals/context.d.ts +12 -1
- package/dist/adapters/ethers/resources/withdrawals/index.d.ts +17 -1
- package/dist/adapters/ethers/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
- package/dist/adapters/ethers/resources/withdrawals/services/finalization.d.ts +35 -17
- package/dist/adapters/ethers/resources/withdrawals/services/protocol.d.ts +11 -0
- package/dist/adapters/ethers/sdk.cjs +976 -272
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.d.ts +3 -1
- package/dist/adapters/ethers/sdk.js +8 -7
- package/dist/adapters/viem/client.cjs +44 -0
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.d.ts +11 -0
- package/dist/adapters/viem/client.js +6 -5
- package/dist/adapters/viem/index.cjs +1060 -294
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.d.ts +2 -1
- package/dist/adapters/viem/index.js +10 -8
- package/dist/adapters/viem/resources/withdrawals/context.d.ts +12 -1
- package/dist/adapters/viem/resources/withdrawals/index.d.ts +17 -1
- package/dist/adapters/viem/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
- package/dist/adapters/viem/resources/withdrawals/services/finalization.d.ts +36 -18
- package/dist/adapters/viem/resources/withdrawals/services/protocol.d.ts +11 -0
- package/dist/adapters/viem/sdk.cjs +1014 -293
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.d.ts +3 -1
- package/dist/adapters/viem/sdk.js +8 -7
- package/dist/{chunk-SBGBYZJM.js → chunk-2D3FBCZC.js} +2 -2
- package/dist/{chunk-LGTYM5XP.js → chunk-32N6TI6K.js} +1 -1
- package/dist/{chunk-IDXSGCGF.js → chunk-3SPDWWRD.js} +7 -22
- package/dist/{chunk-7GZDTLHX.js → chunk-4K4LOCQJ.js} +559 -256
- package/dist/{chunk-UEKFQAOS.js → chunk-AMRHBZIY.js} +304 -2
- package/dist/{chunk-2CGBLD5H.js → chunk-CP4SQ5PM.js} +527 -239
- package/dist/{chunk-NJK325XV.js → chunk-CPNHKNI4.js} +2 -2
- package/dist/{chunk-TYYUG5GA.js → chunk-CUBUD4J4.js} +1 -1
- package/dist/{chunk-CK5UFAZK.js → chunk-JXBLQQEN.js} +37 -3
- package/dist/{chunk-JSBMIT4S.js → chunk-KL6ZCPWJ.js} +1 -1
- package/dist/{chunk-MT4X5FEO.js → chunk-NQRYXL3K.js} +3 -1
- package/dist/{chunk-24TE2NNJ.js → chunk-PI4PF6WT.js} +24 -4
- package/dist/chunk-QUAPG3ZR.js +157 -0
- package/dist/chunk-UMPAKZCQ.js +19 -0
- package/dist/core/abi.d.ts +1 -0
- package/dist/core/constants.cjs +2 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +9 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +504 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.js +6 -4
- package/dist/core/internal/abis/IERC7786Attributes.d.ts +10 -0
- package/dist/core/internal/abis/IL1NullifierV32.d.ts +221 -0
- package/dist/core/resources/interop/attributes/bundle.d.ts +1 -0
- package/dist/core/resources/interop/attributes/resource.d.ts +1 -0
- package/dist/core/resources/protocol/semver.d.ts +18 -0
- package/dist/core/resources/withdrawals/bundle.d.ts +80 -0
- package/dist/core/resources/withdrawals/finalization.d.ts +142 -0
- package/dist/core/resources/withdrawals/protocol.d.ts +55 -0
- package/dist/core/types/flows/withdrawals.d.ts +30 -0
- package/dist/index.cjs +304 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -1778,6 +1778,294 @@ var IL1NullifierABI = [
|
|
|
1778
1778
|
];
|
|
1779
1779
|
var IL1Nullifier_default = IL1NullifierABI;
|
|
1780
1780
|
|
|
1781
|
+
// src/core/internal/abis/IL1NullifierV32.ts
|
|
1782
|
+
var IL1NullifierV32ABI = [
|
|
1783
|
+
{
|
|
1784
|
+
anonymous: false,
|
|
1785
|
+
inputs: [
|
|
1786
|
+
{
|
|
1787
|
+
indexed: true,
|
|
1788
|
+
internalType: "uint256",
|
|
1789
|
+
name: "chainId",
|
|
1790
|
+
type: "uint256"
|
|
1791
|
+
},
|
|
1792
|
+
{
|
|
1793
|
+
indexed: true,
|
|
1794
|
+
internalType: "bytes32",
|
|
1795
|
+
name: "txDataHash",
|
|
1796
|
+
type: "bytes32"
|
|
1797
|
+
},
|
|
1798
|
+
{
|
|
1799
|
+
indexed: true,
|
|
1800
|
+
internalType: "bytes32",
|
|
1801
|
+
name: "l2DepositTxHash",
|
|
1802
|
+
type: "bytes32"
|
|
1803
|
+
}
|
|
1804
|
+
],
|
|
1805
|
+
name: "BridgehubDepositFinalized",
|
|
1806
|
+
type: "event"
|
|
1807
|
+
},
|
|
1808
|
+
{
|
|
1809
|
+
inputs: [],
|
|
1810
|
+
name: "BRIDGE_HUB",
|
|
1811
|
+
outputs: [
|
|
1812
|
+
{
|
|
1813
|
+
internalType: "contract IL1Bridgehub",
|
|
1814
|
+
name: "",
|
|
1815
|
+
type: "address"
|
|
1816
|
+
}
|
|
1817
|
+
],
|
|
1818
|
+
stateMutability: "view",
|
|
1819
|
+
type: "function"
|
|
1820
|
+
},
|
|
1821
|
+
{
|
|
1822
|
+
inputs: [],
|
|
1823
|
+
name: "l1AssetRouter",
|
|
1824
|
+
outputs: [
|
|
1825
|
+
{
|
|
1826
|
+
internalType: "contract IL1AssetRouter",
|
|
1827
|
+
name: "",
|
|
1828
|
+
type: "address"
|
|
1829
|
+
}
|
|
1830
|
+
],
|
|
1831
|
+
stateMutability: "view",
|
|
1832
|
+
type: "function"
|
|
1833
|
+
},
|
|
1834
|
+
{
|
|
1835
|
+
// The contract that took over withdrawal finalization from the nullifier's own (removed)
|
|
1836
|
+
// `finalizeDeposit`.
|
|
1837
|
+
inputs: [],
|
|
1838
|
+
name: "l1InteropHandler",
|
|
1839
|
+
outputs: [
|
|
1840
|
+
{
|
|
1841
|
+
internalType: "address",
|
|
1842
|
+
name: "",
|
|
1843
|
+
type: "address"
|
|
1844
|
+
}
|
|
1845
|
+
],
|
|
1846
|
+
stateMutability: "view",
|
|
1847
|
+
type: "function"
|
|
1848
|
+
},
|
|
1849
|
+
{
|
|
1850
|
+
inputs: [],
|
|
1851
|
+
name: "l1NativeTokenVault",
|
|
1852
|
+
outputs: [
|
|
1853
|
+
{
|
|
1854
|
+
internalType: "contract IL1NativeTokenVault",
|
|
1855
|
+
name: "",
|
|
1856
|
+
type: "address"
|
|
1857
|
+
}
|
|
1858
|
+
],
|
|
1859
|
+
stateMutability: "view",
|
|
1860
|
+
type: "function"
|
|
1861
|
+
},
|
|
1862
|
+
{
|
|
1863
|
+
inputs: [
|
|
1864
|
+
{
|
|
1865
|
+
internalType: "uint256",
|
|
1866
|
+
name: "_chainId",
|
|
1867
|
+
type: "uint256"
|
|
1868
|
+
},
|
|
1869
|
+
{
|
|
1870
|
+
internalType: "bytes32",
|
|
1871
|
+
name: "_l2TxHash",
|
|
1872
|
+
type: "bytes32"
|
|
1873
|
+
}
|
|
1874
|
+
],
|
|
1875
|
+
name: "depositHappened",
|
|
1876
|
+
outputs: [
|
|
1877
|
+
{
|
|
1878
|
+
internalType: "bytes32",
|
|
1879
|
+
name: "",
|
|
1880
|
+
type: "bytes32"
|
|
1881
|
+
}
|
|
1882
|
+
],
|
|
1883
|
+
stateMutability: "view",
|
|
1884
|
+
type: "function"
|
|
1885
|
+
},
|
|
1886
|
+
{
|
|
1887
|
+
inputs: [
|
|
1888
|
+
{
|
|
1889
|
+
internalType: "uint256",
|
|
1890
|
+
name: "_chainId",
|
|
1891
|
+
type: "uint256"
|
|
1892
|
+
},
|
|
1893
|
+
{
|
|
1894
|
+
internalType: "bytes32",
|
|
1895
|
+
name: "_txDataHash",
|
|
1896
|
+
type: "bytes32"
|
|
1897
|
+
},
|
|
1898
|
+
{
|
|
1899
|
+
internalType: "bytes32",
|
|
1900
|
+
name: "_txHash",
|
|
1901
|
+
type: "bytes32"
|
|
1902
|
+
}
|
|
1903
|
+
],
|
|
1904
|
+
name: "bridgehubConfirmL2TransactionForwarded",
|
|
1905
|
+
outputs: [],
|
|
1906
|
+
stateMutability: "nonpayable",
|
|
1907
|
+
type: "function"
|
|
1908
|
+
},
|
|
1909
|
+
{
|
|
1910
|
+
inputs: [
|
|
1911
|
+
{
|
|
1912
|
+
components: [
|
|
1913
|
+
{
|
|
1914
|
+
internalType: "uint256",
|
|
1915
|
+
name: "_chainId",
|
|
1916
|
+
type: "uint256"
|
|
1917
|
+
},
|
|
1918
|
+
{
|
|
1919
|
+
internalType: "address",
|
|
1920
|
+
name: "_depositSender",
|
|
1921
|
+
type: "address"
|
|
1922
|
+
},
|
|
1923
|
+
{
|
|
1924
|
+
internalType: "uint16",
|
|
1925
|
+
name: "_l2TxNumberInBatch",
|
|
1926
|
+
type: "uint16"
|
|
1927
|
+
},
|
|
1928
|
+
{
|
|
1929
|
+
internalType: "enum TxStatus",
|
|
1930
|
+
name: "_txStatus",
|
|
1931
|
+
type: "uint8"
|
|
1932
|
+
},
|
|
1933
|
+
{
|
|
1934
|
+
internalType: "bytes32",
|
|
1935
|
+
name: "_assetId",
|
|
1936
|
+
type: "bytes32"
|
|
1937
|
+
},
|
|
1938
|
+
{
|
|
1939
|
+
internalType: "bytes",
|
|
1940
|
+
name: "_assetData",
|
|
1941
|
+
type: "bytes"
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
internalType: "bytes32",
|
|
1945
|
+
name: "_l2TxHash",
|
|
1946
|
+
type: "bytes32"
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
internalType: "uint256",
|
|
1950
|
+
name: "_l2BatchNumber",
|
|
1951
|
+
type: "uint256"
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
internalType: "uint256",
|
|
1955
|
+
name: "_l2MessageIndex",
|
|
1956
|
+
type: "uint256"
|
|
1957
|
+
},
|
|
1958
|
+
{
|
|
1959
|
+
internalType: "bytes32[]",
|
|
1960
|
+
name: "_merkleProof",
|
|
1961
|
+
type: "bytes32[]"
|
|
1962
|
+
}
|
|
1963
|
+
],
|
|
1964
|
+
internalType: "struct ConfirmTransferResultData",
|
|
1965
|
+
name: "_confirmTransferResultData",
|
|
1966
|
+
type: "tuple"
|
|
1967
|
+
}
|
|
1968
|
+
],
|
|
1969
|
+
name: "bridgeConfirmTransferResult",
|
|
1970
|
+
outputs: [],
|
|
1971
|
+
stateMutability: "nonpayable",
|
|
1972
|
+
type: "function"
|
|
1973
|
+
},
|
|
1974
|
+
{
|
|
1975
|
+
inputs: [
|
|
1976
|
+
{
|
|
1977
|
+
internalType: "uint256",
|
|
1978
|
+
name: "_chainId",
|
|
1979
|
+
type: "uint256"
|
|
1980
|
+
},
|
|
1981
|
+
{
|
|
1982
|
+
internalType: "address",
|
|
1983
|
+
name: "_depositSender",
|
|
1984
|
+
type: "address"
|
|
1985
|
+
},
|
|
1986
|
+
{
|
|
1987
|
+
internalType: "bytes32",
|
|
1988
|
+
name: "_assetId",
|
|
1989
|
+
type: "bytes32"
|
|
1990
|
+
},
|
|
1991
|
+
{
|
|
1992
|
+
internalType: "bytes",
|
|
1993
|
+
name: "_assetData",
|
|
1994
|
+
type: "bytes"
|
|
1995
|
+
},
|
|
1996
|
+
{
|
|
1997
|
+
internalType: "bytes32",
|
|
1998
|
+
name: "_l2TxHash",
|
|
1999
|
+
type: "bytes32"
|
|
2000
|
+
},
|
|
2001
|
+
{
|
|
2002
|
+
internalType: "uint256",
|
|
2003
|
+
name: "_l2BatchNumber",
|
|
2004
|
+
type: "uint256"
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
internalType: "uint256",
|
|
2008
|
+
name: "_l2MessageIndex",
|
|
2009
|
+
type: "uint256"
|
|
2010
|
+
},
|
|
2011
|
+
{
|
|
2012
|
+
internalType: "uint16",
|
|
2013
|
+
name: "_l2TxNumberInBatch",
|
|
2014
|
+
type: "uint16"
|
|
2015
|
+
},
|
|
2016
|
+
{
|
|
2017
|
+
internalType: "bytes32[]",
|
|
2018
|
+
name: "_merkleProof",
|
|
2019
|
+
type: "bytes32[]"
|
|
2020
|
+
}
|
|
2021
|
+
],
|
|
2022
|
+
name: "bridgeRecoverFailedTransfer",
|
|
2023
|
+
outputs: [],
|
|
2024
|
+
stateMutability: "nonpayable",
|
|
2025
|
+
type: "function"
|
|
2026
|
+
},
|
|
2027
|
+
{
|
|
2028
|
+
inputs: [
|
|
2029
|
+
{
|
|
2030
|
+
internalType: "contract IL1NativeTokenVault",
|
|
2031
|
+
name: "_nativeTokenVault",
|
|
2032
|
+
type: "address"
|
|
2033
|
+
}
|
|
2034
|
+
],
|
|
2035
|
+
name: "setL1NativeTokenVault",
|
|
2036
|
+
outputs: [],
|
|
2037
|
+
stateMutability: "nonpayable",
|
|
2038
|
+
type: "function"
|
|
2039
|
+
},
|
|
2040
|
+
{
|
|
2041
|
+
inputs: [
|
|
2042
|
+
{
|
|
2043
|
+
internalType: "address",
|
|
2044
|
+
name: "_l1AssetRouter",
|
|
2045
|
+
type: "address"
|
|
2046
|
+
}
|
|
2047
|
+
],
|
|
2048
|
+
name: "setL1AssetRouter",
|
|
2049
|
+
outputs: [],
|
|
2050
|
+
stateMutability: "nonpayable",
|
|
2051
|
+
type: "function"
|
|
2052
|
+
},
|
|
2053
|
+
{
|
|
2054
|
+
inputs: [
|
|
2055
|
+
{
|
|
2056
|
+
internalType: "address",
|
|
2057
|
+
name: "_l1InteropHandler",
|
|
2058
|
+
type: "address"
|
|
2059
|
+
}
|
|
2060
|
+
],
|
|
2061
|
+
name: "setL1InteropHandler",
|
|
2062
|
+
outputs: [],
|
|
2063
|
+
stateMutability: "nonpayable",
|
|
2064
|
+
type: "function"
|
|
2065
|
+
}
|
|
2066
|
+
];
|
|
2067
|
+
var IL1NullifierV32_default = IL1NullifierV32ABI;
|
|
2068
|
+
|
|
1781
2069
|
// src/core/internal/abis/IL2AssetRouter.ts
|
|
1782
2070
|
var IL2AssetRouterABI = [
|
|
1783
2071
|
{
|
|
@@ -3311,6 +3599,19 @@ var IERC7786AttributesABI = [
|
|
|
3311
3599
|
outputs: [],
|
|
3312
3600
|
stateMutability: "pure"
|
|
3313
3601
|
},
|
|
3602
|
+
{
|
|
3603
|
+
type: "function",
|
|
3604
|
+
name: "interopBundleSalt",
|
|
3605
|
+
inputs: [
|
|
3606
|
+
{
|
|
3607
|
+
name: "_salt",
|
|
3608
|
+
type: "bytes32",
|
|
3609
|
+
internalType: "bytes32"
|
|
3610
|
+
}
|
|
3611
|
+
],
|
|
3612
|
+
outputs: [],
|
|
3613
|
+
stateMutability: "pure"
|
|
3614
|
+
},
|
|
3314
3615
|
{
|
|
3315
3616
|
type: "function",
|
|
3316
3617
|
name: "unbundlerAddress",
|
|
@@ -5493,6 +5794,7 @@ var L1_MESSENGER_ADDRESS = "0x0000000000000000000000000000000000008008";
|
|
|
5493
5794
|
var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
5494
5795
|
var L2_INTEROP_CENTER_ADDRESS = "0x000000000000000000000000000000000001000d";
|
|
5495
5796
|
var L2_INTEROP_ROOT_STORAGE_ADDRESS = "0x0000000000000000000000000000000000010008";
|
|
5797
|
+
var L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS = "0x0000000000000000000000000000000000010015";
|
|
5496
5798
|
var BUNDLE_IDENTIFIER = "0x01";
|
|
5497
5799
|
var TOPIC_L1_MESSAGE_SENT_NEW = k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
5498
5800
|
var TOPIC_L1_MESSAGE_SENT_LEG = k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
@@ -6011,7 +6313,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6011
6313
|
function wrap7(operation, fn, opts) {
|
|
6012
6314
|
return run("INTERNAL", operation, fn, opts);
|
|
6013
6315
|
}
|
|
6014
|
-
function
|
|
6316
|
+
function wrapAs11(kind, operation, fn, opts) {
|
|
6015
6317
|
return run(kind, operation, fn, opts);
|
|
6016
6318
|
}
|
|
6017
6319
|
async function toResult3(operation, fn, opts) {
|
|
@@ -6032,7 +6334,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6032
6334
|
return { ok: false, error: shaped };
|
|
6033
6335
|
}
|
|
6034
6336
|
}
|
|
6035
|
-
return { wrap: wrap7, wrapAs:
|
|
6337
|
+
return { wrap: wrap7, wrapAs: wrapAs11, toResult: toResult3 };
|
|
6036
6338
|
}
|
|
6037
6339
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
6038
6340
|
}
|
|
@@ -8245,7 +8547,7 @@ function pickWithdrawRoute(args) {
|
|
|
8245
8547
|
}
|
|
8246
8548
|
|
|
8247
8549
|
// src/adapters/viem/resources/withdrawals/context.ts
|
|
8248
|
-
async function commonCtx2(p, client, tokens, contracts) {
|
|
8550
|
+
async function commonCtx2(p, client, tokens, contracts, protocol) {
|
|
8249
8551
|
const sender = client.account.address;
|
|
8250
8552
|
const {
|
|
8251
8553
|
bridgehub,
|
|
@@ -8253,9 +8555,11 @@ async function commonCtx2(p, client, tokens, contracts) {
|
|
|
8253
8555
|
l1Nullifier,
|
|
8254
8556
|
l2AssetRouter,
|
|
8255
8557
|
l2NativeTokenVault,
|
|
8256
|
-
l2BaseTokenSystem
|
|
8558
|
+
l2BaseTokenSystem,
|
|
8559
|
+
interopCenter
|
|
8257
8560
|
} = await contracts.addresses();
|
|
8258
8561
|
const chainIdL2 = BigInt(await client.l2.getChainId());
|
|
8562
|
+
const l1ChainId = BigInt(await client.l1.getChainId());
|
|
8259
8563
|
const resolvedToken = await tokens.resolve(p.token, { chain: "l2" });
|
|
8260
8564
|
const baseTokenAssetId = resolvedToken.baseTokenAssetId;
|
|
8261
8565
|
const baseTokenL1 = await tokens.l1TokenFromAssetId(baseTokenAssetId);
|
|
@@ -8277,6 +8581,9 @@ async function commonCtx2(p, client, tokens, contracts) {
|
|
|
8277
8581
|
l2AssetRouter,
|
|
8278
8582
|
l2NativeTokenVault,
|
|
8279
8583
|
l2BaseTokenSystem,
|
|
8584
|
+
interopCenter,
|
|
8585
|
+
protocol,
|
|
8586
|
+
l1ChainId,
|
|
8280
8587
|
baseIsEth,
|
|
8281
8588
|
gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
|
|
8282
8589
|
};
|
|
@@ -8586,6 +8893,285 @@ function routeErc20NonBase2() {
|
|
|
8586
8893
|
}
|
|
8587
8894
|
};
|
|
8588
8895
|
}
|
|
8896
|
+
var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
|
|
8897
|
+
var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
|
|
8898
|
+
function formatInteropEvmChain(chainId) {
|
|
8899
|
+
const chainRef = viem.toBytes(viem.toHex(chainId));
|
|
8900
|
+
const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
|
|
8901
|
+
const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
|
|
8902
|
+
return viem.toHex(payload);
|
|
8903
|
+
}
|
|
8904
|
+
function formatInteropEvmAddress(address) {
|
|
8905
|
+
const normalized = viem.getAddress(address);
|
|
8906
|
+
const addrBytes = viem.toBytes(normalized);
|
|
8907
|
+
const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
|
|
8908
|
+
return viem.toHex(payload);
|
|
8909
|
+
}
|
|
8910
|
+
var interopCodec = {
|
|
8911
|
+
formatChain: formatInteropEvmChain,
|
|
8912
|
+
formatAddress: formatInteropEvmAddress
|
|
8913
|
+
};
|
|
8914
|
+
|
|
8915
|
+
// src/core/resources/interop/attributes/call.ts
|
|
8916
|
+
function createCallAttributes(codec) {
|
|
8917
|
+
const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
|
|
8918
|
+
const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
|
|
8919
|
+
return {
|
|
8920
|
+
indirectCall,
|
|
8921
|
+
interopCallValue
|
|
8922
|
+
};
|
|
8923
|
+
}
|
|
8924
|
+
|
|
8925
|
+
// src/core/resources/interop/attributes/bundle.ts
|
|
8926
|
+
function createBundleAttributes(codec) {
|
|
8927
|
+
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
8928
|
+
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
8929
|
+
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
8930
|
+
const interopBundleSalt = (salt) => codec.encode("interopBundleSalt", [salt]);
|
|
8931
|
+
return {
|
|
8932
|
+
executionAddress,
|
|
8933
|
+
unbundlerAddress,
|
|
8934
|
+
useFixedFee,
|
|
8935
|
+
interopBundleSalt
|
|
8936
|
+
};
|
|
8937
|
+
}
|
|
8938
|
+
|
|
8939
|
+
// src/core/resources/interop/attributes/resource.ts
|
|
8940
|
+
function createAttributesResource(codec) {
|
|
8941
|
+
return {
|
|
8942
|
+
call: createCallAttributes(codec),
|
|
8943
|
+
bundle: createBundleAttributes(codec)
|
|
8944
|
+
};
|
|
8945
|
+
}
|
|
8946
|
+
|
|
8947
|
+
// src/adapters/viem/resources/interop/attributes/resource.ts
|
|
8948
|
+
function getInteropAttributes(params, ctx) {
|
|
8949
|
+
const bundleAttributes = [];
|
|
8950
|
+
if (params.execution?.only) {
|
|
8951
|
+
bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
|
|
8952
|
+
}
|
|
8953
|
+
if (params.unbundling?.by) {
|
|
8954
|
+
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
8955
|
+
}
|
|
8956
|
+
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
8957
|
+
const callAttributes = params.actions.map((action) => {
|
|
8958
|
+
switch (action.type) {
|
|
8959
|
+
case "sendNative": {
|
|
8960
|
+
const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
|
|
8961
|
+
if (baseMatches) {
|
|
8962
|
+
return [ctx.attributes.call.interopCallValue(action.amount)];
|
|
8963
|
+
}
|
|
8964
|
+
return [ctx.attributes.call.indirectCall(action.amount)];
|
|
8965
|
+
}
|
|
8966
|
+
case "call":
|
|
8967
|
+
if (action.value && action.value > 0n) {
|
|
8968
|
+
return [ctx.attributes.call.interopCallValue(action.value)];
|
|
8969
|
+
}
|
|
8970
|
+
return [];
|
|
8971
|
+
case "sendErc20":
|
|
8972
|
+
return [ctx.attributes.call.indirectCall(0n)];
|
|
8973
|
+
default:
|
|
8974
|
+
assertNever(action);
|
|
8975
|
+
}
|
|
8976
|
+
});
|
|
8977
|
+
return { bundleAttributes, callAttributes };
|
|
8978
|
+
}
|
|
8979
|
+
function createViemAttributesResource() {
|
|
8980
|
+
const encode = (fn, args) => viem.encodeFunctionData({
|
|
8981
|
+
abi: IERC7786Attributes_default,
|
|
8982
|
+
functionName: fn,
|
|
8983
|
+
args
|
|
8984
|
+
});
|
|
8985
|
+
return createAttributesResource({ encode });
|
|
8986
|
+
}
|
|
8987
|
+
|
|
8988
|
+
// src/core/resources/withdrawals/bundle.ts
|
|
8989
|
+
function buildWithdrawalBundle(input) {
|
|
8990
|
+
const {
|
|
8991
|
+
assetId,
|
|
8992
|
+
amount,
|
|
8993
|
+
l1Receiver,
|
|
8994
|
+
l2Token,
|
|
8995
|
+
isBaseToken,
|
|
8996
|
+
l1ChainId,
|
|
8997
|
+
l2AssetRouter,
|
|
8998
|
+
salt,
|
|
8999
|
+
codec,
|
|
9000
|
+
attributes: attributes2,
|
|
9001
|
+
transferData
|
|
9002
|
+
} = input;
|
|
9003
|
+
const burnData = transferData.encodeBridgeBurnData(amount, l1Receiver, l2Token);
|
|
9004
|
+
const depositData = transferData.encodeAssetRouterDepositData(assetId, burnData);
|
|
9005
|
+
const indirectCallMessageValue = isBaseToken ? amount : 0n;
|
|
9006
|
+
const starter = [
|
|
9007
|
+
codec.formatAddress(l2AssetRouter),
|
|
9008
|
+
depositData,
|
|
9009
|
+
[attributes2.indirectCall(indirectCallMessageValue), attributes2.interopCallValue(0n)]
|
|
9010
|
+
];
|
|
9011
|
+
return {
|
|
9012
|
+
destinationChain: codec.formatChain(l1ChainId),
|
|
9013
|
+
starters: [starter],
|
|
9014
|
+
// No `atomicBundle` attribute: L2 -> L1 withdrawals are non-atomic and are published to L1 as a
|
|
9015
|
+
// `BUNDLE_IDENTIFIER`-prefixed message, which is what the L1 handler proves inclusion of.
|
|
9016
|
+
bundleAttributes: [attributes2.interopBundleSalt(salt)],
|
|
9017
|
+
value: indirectCallMessageValue
|
|
9018
|
+
};
|
|
9019
|
+
}
|
|
9020
|
+
|
|
9021
|
+
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
9022
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
9023
|
+
var attributes = createViemAttributesResource();
|
|
9024
|
+
function saltFor(sender, nonce) {
|
|
9025
|
+
return viem.keccak256(
|
|
9026
|
+
viem.encodeAbiParameters(
|
|
9027
|
+
[
|
|
9028
|
+
{ type: "address", name: "sender" },
|
|
9029
|
+
{ type: "uint256", name: "nonce" }
|
|
9030
|
+
],
|
|
9031
|
+
[sender, BigInt(nonce)]
|
|
9032
|
+
)
|
|
9033
|
+
);
|
|
9034
|
+
}
|
|
9035
|
+
function routeInteropBundle() {
|
|
9036
|
+
return {
|
|
9037
|
+
async build(p, ctx) {
|
|
9038
|
+
const steps = [];
|
|
9039
|
+
const approvals = [];
|
|
9040
|
+
const isBaseToken = ctx.route === "base";
|
|
9041
|
+
const l1Receiver = p.to ?? ctx.sender;
|
|
9042
|
+
let assetId;
|
|
9043
|
+
let allowanceSufficient = true;
|
|
9044
|
+
if (isBaseToken) {
|
|
9045
|
+
assetId = ctx.baseTokenAssetId;
|
|
9046
|
+
} else {
|
|
9047
|
+
assetId = (await wrapAs9(
|
|
9048
|
+
"CONTRACT",
|
|
9049
|
+
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
9050
|
+
() => ctx.client.l2.simulateContract({
|
|
9051
|
+
address: ctx.l2NativeTokenVault,
|
|
9052
|
+
abi: L2NativeTokenVault_default,
|
|
9053
|
+
functionName: "ensureTokenIsRegistered",
|
|
9054
|
+
args: [p.token],
|
|
9055
|
+
account: ctx.client.account
|
|
9056
|
+
}),
|
|
9057
|
+
{
|
|
9058
|
+
ctx: { where: "L2NativeTokenVault.ensureTokenIsRegistered", token: p.token },
|
|
9059
|
+
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
9060
|
+
}
|
|
9061
|
+
)).result;
|
|
9062
|
+
const current = await wrapAs9(
|
|
9063
|
+
"CONTRACT",
|
|
9064
|
+
OP_WITHDRAWALS.erc20.allowance,
|
|
9065
|
+
() => ctx.client.l2.readContract({
|
|
9066
|
+
address: p.token,
|
|
9067
|
+
abi: IERC20_default,
|
|
9068
|
+
functionName: "allowance",
|
|
9069
|
+
args: [ctx.sender, ctx.l2NativeTokenVault],
|
|
9070
|
+
account: ctx.client.account
|
|
9071
|
+
}),
|
|
9072
|
+
{
|
|
9073
|
+
ctx: {
|
|
9074
|
+
where: "erc20.allowance",
|
|
9075
|
+
chain: "L2",
|
|
9076
|
+
token: p.token,
|
|
9077
|
+
spender: ctx.l2NativeTokenVault
|
|
9078
|
+
},
|
|
9079
|
+
message: "Failed to read L2 ERC-20 allowance."
|
|
9080
|
+
}
|
|
9081
|
+
);
|
|
9082
|
+
allowanceSufficient = current >= p.amount;
|
|
9083
|
+
if (!allowanceSufficient) {
|
|
9084
|
+
approvals.push({ token: p.token, spender: ctx.l2NativeTokenVault, amount: p.amount });
|
|
9085
|
+
const approveTxCandidate = {
|
|
9086
|
+
to: p.token,
|
|
9087
|
+
data: viem.encodeFunctionData({
|
|
9088
|
+
abi: IERC20_default,
|
|
9089
|
+
functionName: "approve",
|
|
9090
|
+
args: [ctx.l2NativeTokenVault, p.amount]
|
|
9091
|
+
}),
|
|
9092
|
+
value: 0n,
|
|
9093
|
+
from: ctx.sender
|
|
9094
|
+
};
|
|
9095
|
+
const approveGas = await quoteL2Gas4({ ctx, tx: approveTxCandidate });
|
|
9096
|
+
steps.push({
|
|
9097
|
+
key: `approve:l2:${p.token}:${ctx.l2NativeTokenVault}`,
|
|
9098
|
+
kind: "approve:l2",
|
|
9099
|
+
description: `Approve ${p.amount} to NativeTokenVault`,
|
|
9100
|
+
tx: {
|
|
9101
|
+
address: p.token,
|
|
9102
|
+
abi: IERC20_default,
|
|
9103
|
+
functionName: "approve",
|
|
9104
|
+
args: [ctx.l2NativeTokenVault, p.amount],
|
|
9105
|
+
account: ctx.client.account,
|
|
9106
|
+
...approveGas
|
|
9107
|
+
}
|
|
9108
|
+
});
|
|
9109
|
+
}
|
|
9110
|
+
}
|
|
9111
|
+
const nonce = await wrapAs9(
|
|
9112
|
+
"RPC",
|
|
9113
|
+
OP_WITHDRAWALS.prepare,
|
|
9114
|
+
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
9115
|
+
{
|
|
9116
|
+
ctx: { where: "l2.getTransactionCount", sender: ctx.sender },
|
|
9117
|
+
message: "Failed to read L2 nonce for the interop bundle salt."
|
|
9118
|
+
}
|
|
9119
|
+
);
|
|
9120
|
+
const bundle = buildWithdrawalBundle({
|
|
9121
|
+
assetId,
|
|
9122
|
+
amount: p.amount,
|
|
9123
|
+
l1Receiver,
|
|
9124
|
+
l2Token: isBaseToken ? FORMAL_ETH_ADDRESS : p.token,
|
|
9125
|
+
isBaseToken,
|
|
9126
|
+
l1ChainId: ctx.l1ChainId,
|
|
9127
|
+
l2AssetRouter: ctx.l2AssetRouter,
|
|
9128
|
+
salt: saltFor(ctx.sender, nonce),
|
|
9129
|
+
codec: interopCodec,
|
|
9130
|
+
attributes: {
|
|
9131
|
+
indirectCall: attributes.call.indirectCall,
|
|
9132
|
+
interopCallValue: attributes.call.interopCallValue,
|
|
9133
|
+
interopBundleSalt: attributes.bundle.interopBundleSalt
|
|
9134
|
+
},
|
|
9135
|
+
transferData: {
|
|
9136
|
+
encodeBridgeBurnData: encodeNativeTokenVaultTransferData,
|
|
9137
|
+
encodeAssetRouterDepositData: encodeSecondBridgeDataV1
|
|
9138
|
+
}
|
|
9139
|
+
});
|
|
9140
|
+
const sendArgs = [bundle.destinationChain, bundle.starters, bundle.bundleAttributes];
|
|
9141
|
+
const sendTxCandidate = {
|
|
9142
|
+
to: ctx.interopCenter,
|
|
9143
|
+
data: viem.encodeFunctionData({
|
|
9144
|
+
abi: IInteropCenter_default,
|
|
9145
|
+
functionName: "sendBundle",
|
|
9146
|
+
args: sendArgs
|
|
9147
|
+
}),
|
|
9148
|
+
value: bundle.value,
|
|
9149
|
+
from: ctx.sender
|
|
9150
|
+
};
|
|
9151
|
+
const sendGas = allowanceSufficient ? await quoteL2Gas4({ ctx, tx: sendTxCandidate }) : void 0;
|
|
9152
|
+
const sendTx = {
|
|
9153
|
+
address: ctx.interopCenter,
|
|
9154
|
+
abi: IInteropCenter_default,
|
|
9155
|
+
functionName: "sendBundle",
|
|
9156
|
+
args: sendArgs,
|
|
9157
|
+
account: ctx.client.account,
|
|
9158
|
+
value: bundle.value,
|
|
9159
|
+
...sendGas
|
|
9160
|
+
};
|
|
9161
|
+
steps.push({
|
|
9162
|
+
key: "interop-center:send-bundle",
|
|
9163
|
+
kind: "interop-center:send-bundle",
|
|
9164
|
+
description: "Burn on L2 & send L2\u2192L1 withdrawal bundle",
|
|
9165
|
+
tx: sendTx
|
|
9166
|
+
});
|
|
9167
|
+
const fees = buildFeeBreakdown2({
|
|
9168
|
+
feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
|
|
9169
|
+
l2Gas: sendGas
|
|
9170
|
+
});
|
|
9171
|
+
return { steps, approvals, fees };
|
|
9172
|
+
}
|
|
9173
|
+
};
|
|
9174
|
+
}
|
|
8589
9175
|
|
|
8590
9176
|
// src/core/utils/events.ts
|
|
8591
9177
|
function extractPreferAddress(opts) {
|
|
@@ -8620,21 +9206,145 @@ function l1MessageSentSender(log) {
|
|
|
8620
9206
|
if (!sender) {
|
|
8621
9207
|
throw new Error("L1MessageSent log has no valid sender topic.");
|
|
8622
9208
|
}
|
|
8623
|
-
return `0x${sender.toLowerCase()}`;
|
|
9209
|
+
return `0x${sender.toLowerCase()}`;
|
|
9210
|
+
}
|
|
9211
|
+
|
|
9212
|
+
// src/core/resources/withdrawals/logs.ts
|
|
9213
|
+
function messengerLogIndex(raw, opts) {
|
|
9214
|
+
const index = opts?.index;
|
|
9215
|
+
const messenger = (opts?.messenger).toLowerCase();
|
|
9216
|
+
const arr = Array.isArray(raw?.l2ToL1Logs) ? raw.l2ToL1Logs : [];
|
|
9217
|
+
const hits = arr.map((lg, i) => ({ i, lg })).filter(({ lg }) => (lg?.sender ?? "").toLowerCase() === messenger);
|
|
9218
|
+
if (!hits.length) {
|
|
9219
|
+
throw new Error("No L2->L1 messenger logs found in receipt.");
|
|
9220
|
+
}
|
|
9221
|
+
return (hits[index] ?? hits[0]).i;
|
|
9222
|
+
}
|
|
9223
|
+
function keccakHex(data) {
|
|
9224
|
+
return `0x${utils.bytesToHex(sha3.keccak_256(utils.hexToBytes(data.slice(2))))}`;
|
|
9225
|
+
}
|
|
9226
|
+
function stripBundleIdentifier(messageData) {
|
|
9227
|
+
const prefix = `0x${messageData.slice(2, 4)}`;
|
|
9228
|
+
if (prefix !== BUNDLE_IDENTIFIER) {
|
|
9229
|
+
throw createError("STATE", {
|
|
9230
|
+
resource: "withdrawals",
|
|
9231
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9232
|
+
message: "L2\u2192L1 message is not an interop bundle. This withdrawal was most likely initiated before the chain upgraded to protocol v32 and cannot be finalized through the interop handler.",
|
|
9233
|
+
context: { prefix, expected: BUNDLE_IDENTIFIER }
|
|
9234
|
+
});
|
|
9235
|
+
}
|
|
9236
|
+
return `0x${messageData.slice(4)}`;
|
|
9237
|
+
}
|
|
9238
|
+
function parseBundleHashFromLogs(logs, interopCenter = L2_INTEROP_CENTER_ADDRESS) {
|
|
9239
|
+
const center = interopCenter.toLowerCase();
|
|
9240
|
+
for (const log of logs) {
|
|
9241
|
+
if (log.address?.toLowerCase() !== center) continue;
|
|
9242
|
+
if (log.topics?.length !== 1) continue;
|
|
9243
|
+
if (!log.data || (log.data.length - 2) / 64 < 3) continue;
|
|
9244
|
+
return `0x${log.data.slice(66, 130)}`;
|
|
9245
|
+
}
|
|
9246
|
+
return void 0;
|
|
9247
|
+
}
|
|
9248
|
+
function buildWithdrawalFinalization(input) {
|
|
9249
|
+
const { messageData, sourceChainId, txNumberInBatch, proof } = input;
|
|
9250
|
+
const bundle = stripBundleIdentifier(messageData);
|
|
9251
|
+
return {
|
|
9252
|
+
bundle,
|
|
9253
|
+
bundleHash: input.bundleHash ?? keccakHex(bundle),
|
|
9254
|
+
proof: {
|
|
9255
|
+
chainId: sourceChainId,
|
|
9256
|
+
l1BatchNumber: proof.batchNumber,
|
|
9257
|
+
l2MessageIndex: proof.id,
|
|
9258
|
+
message: {
|
|
9259
|
+
txNumberInBatch,
|
|
9260
|
+
sender: input.interopCenter ?? L2_INTEROP_CENTER_ADDRESS,
|
|
9261
|
+
data: messageData
|
|
9262
|
+
},
|
|
9263
|
+
proof: proof.proof
|
|
9264
|
+
}
|
|
9265
|
+
};
|
|
9266
|
+
}
|
|
9267
|
+
function classifyWithdrawalOutcome(bundleStatus, callStatus) {
|
|
9268
|
+
if (bundleStatus === 2 /* FullyExecuted */) return "finalized";
|
|
9269
|
+
if (bundleStatus !== 3 /* Unbundled */) return "pending";
|
|
9270
|
+
switch (callStatus) {
|
|
9271
|
+
case 1 /* Executed */:
|
|
9272
|
+
return "finalized";
|
|
9273
|
+
case 2 /* Cancelled */:
|
|
9274
|
+
return "failed";
|
|
9275
|
+
default:
|
|
9276
|
+
return "pending";
|
|
9277
|
+
}
|
|
8624
9278
|
}
|
|
8625
9279
|
|
|
8626
|
-
// src/core/resources/withdrawals/
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
const
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
9280
|
+
// src/core/resources/withdrawals/protocol.ts
|
|
9281
|
+
var MIN_INTEROP_WITHDRAWAL_MINOR = 32;
|
|
9282
|
+
function protocolFromVersion(version) {
|
|
9283
|
+
const [, minor] = version;
|
|
9284
|
+
return minor >= MIN_INTEROP_WITHDRAWAL_MINOR ? "interop-bundle" : "legacy-withdrawal";
|
|
9285
|
+
}
|
|
9286
|
+
async function detectWithdrawalProtocol(probes, override) {
|
|
9287
|
+
if (override) {
|
|
9288
|
+
return { protocol: override, source: { via: "override" } };
|
|
8634
9289
|
}
|
|
8635
|
-
|
|
9290
|
+
const version = await probes.protocolVersion();
|
|
9291
|
+
if (version) {
|
|
9292
|
+
return { protocol: protocolFromVersion(version), source: { via: "protocol-version", version } };
|
|
9293
|
+
}
|
|
9294
|
+
if (await probes.hasCodeAt(L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS)) {
|
|
9295
|
+
return {
|
|
9296
|
+
protocol: "interop-bundle",
|
|
9297
|
+
source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
|
|
9298
|
+
};
|
|
9299
|
+
}
|
|
9300
|
+
return {
|
|
9301
|
+
protocol: "legacy-withdrawal",
|
|
9302
|
+
source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
|
|
9303
|
+
};
|
|
8636
9304
|
}
|
|
8637
|
-
|
|
9305
|
+
|
|
9306
|
+
// src/adapters/viem/resources/withdrawals/services/protocol.ts
|
|
9307
|
+
function createWithdrawalProtocolService(client, override) {
|
|
9308
|
+
let cached;
|
|
9309
|
+
async function hasCodeAt(address) {
|
|
9310
|
+
try {
|
|
9311
|
+
const code = await client.l2.getCode({ address });
|
|
9312
|
+
return !!code && code !== "0x";
|
|
9313
|
+
} catch {
|
|
9314
|
+
return false;
|
|
9315
|
+
}
|
|
9316
|
+
}
|
|
9317
|
+
async function protocolVersion() {
|
|
9318
|
+
try {
|
|
9319
|
+
return await client.getChainProtocolVersion();
|
|
9320
|
+
} catch {
|
|
9321
|
+
return void 0;
|
|
9322
|
+
}
|
|
9323
|
+
}
|
|
9324
|
+
function detect() {
|
|
9325
|
+
cached ??= detectWithdrawalProtocol(
|
|
9326
|
+
{
|
|
9327
|
+
protocolVersion,
|
|
9328
|
+
hasCodeAt
|
|
9329
|
+
},
|
|
9330
|
+
override
|
|
9331
|
+
).catch((e) => {
|
|
9332
|
+
cached = void 0;
|
|
9333
|
+
throw e;
|
|
9334
|
+
});
|
|
9335
|
+
return cached;
|
|
9336
|
+
}
|
|
9337
|
+
return {
|
|
9338
|
+
detect,
|
|
9339
|
+
async protocol() {
|
|
9340
|
+
return (await detect()).protocol;
|
|
9341
|
+
},
|
|
9342
|
+
refresh() {
|
|
9343
|
+
cached = void 0;
|
|
9344
|
+
}
|
|
9345
|
+
};
|
|
9346
|
+
}
|
|
9347
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
8638
9348
|
var IL1NullifierMini = [
|
|
8639
9349
|
{
|
|
8640
9350
|
type: "function",
|
|
@@ -8648,183 +9358,279 @@ var IL1NullifierMini = [
|
|
|
8648
9358
|
outputs: [{ type: "bool" }]
|
|
8649
9359
|
}
|
|
8650
9360
|
];
|
|
8651
|
-
function createFinalizationServices(client) {
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
9361
|
+
function createFinalizationServices(client, protocolService = createWithdrawalProtocolService(client)) {
|
|
9362
|
+
async function finalizationTarget(protocol) {
|
|
9363
|
+
const { l1Nullifier } = await client.ensureAddresses();
|
|
9364
|
+
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
9365
|
+
return await wrapAs10(
|
|
9366
|
+
"CONTRACT",
|
|
9367
|
+
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9368
|
+
() => client.l1.readContract({
|
|
9369
|
+
address: l1Nullifier,
|
|
9370
|
+
abi: IL1NullifierV32_default,
|
|
9371
|
+
functionName: "l1InteropHandler"
|
|
9372
|
+
}),
|
|
9373
|
+
{
|
|
9374
|
+
ctx: { where: "L1Nullifier.l1InteropHandler", l1Nullifier },
|
|
9375
|
+
message: "Failed to resolve the L1 interop handler. The chain reports protocol v32+, but its L1Nullifier does not expose `l1InteropHandler()`."
|
|
9376
|
+
}
|
|
9377
|
+
);
|
|
9378
|
+
}
|
|
9379
|
+
async function fetchMessageAndProof(l2TxHash) {
|
|
9380
|
+
const raw = await wrapAs10(
|
|
9381
|
+
"RPC",
|
|
9382
|
+
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9383
|
+
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
9384
|
+
{
|
|
9385
|
+
ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
|
|
9386
|
+
message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
|
|
9387
|
+
}
|
|
9388
|
+
);
|
|
9389
|
+
if (!raw) {
|
|
9390
|
+
throw createError("STATE", {
|
|
9391
|
+
resource: "withdrawals",
|
|
9392
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9393
|
+
message: "L2 receipt not found.",
|
|
9394
|
+
context: { l2TxHash }
|
|
9395
|
+
});
|
|
9396
|
+
}
|
|
9397
|
+
const ev = await wrapAs10(
|
|
9398
|
+
"INTERNAL",
|
|
9399
|
+
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
9400
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
9401
|
+
() => Promise.resolve(findL1MessageSentLog(raw, { index: 0 })),
|
|
9402
|
+
{
|
|
9403
|
+
ctx: { l2TxHash, index: 0 },
|
|
9404
|
+
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
9405
|
+
}
|
|
9406
|
+
);
|
|
9407
|
+
const message = await wrapAs10(
|
|
9408
|
+
"INTERNAL",
|
|
9409
|
+
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9410
|
+
() => {
|
|
9411
|
+
const [decoded] = viem.decodeAbiParameters([{ type: "bytes" }], ev.data);
|
|
9412
|
+
return Promise.resolve(decoded);
|
|
9413
|
+
},
|
|
9414
|
+
{
|
|
9415
|
+
ctx: { where: "decode L1MessageSent", data: ev.data },
|
|
9416
|
+
message: "Failed to decode withdrawal message."
|
|
9417
|
+
}
|
|
9418
|
+
);
|
|
9419
|
+
const idx = await wrapAs10(
|
|
9420
|
+
"INTERNAL",
|
|
9421
|
+
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
9422
|
+
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
9423
|
+
{
|
|
9424
|
+
ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
|
|
9425
|
+
message: "Failed to derive messenger log index."
|
|
9426
|
+
}
|
|
9427
|
+
);
|
|
9428
|
+
const proof = await wrapAs10(
|
|
9429
|
+
"RPC",
|
|
9430
|
+
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
9431
|
+
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
9432
|
+
{
|
|
9433
|
+
ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
|
|
9434
|
+
message: "Failed to fetch L2\u2192L1 log proof."
|
|
9435
|
+
}
|
|
9436
|
+
);
|
|
9437
|
+
const chainId = await wrapAs10(
|
|
9438
|
+
"RPC",
|
|
9439
|
+
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
9440
|
+
() => client.l2.getChainId(),
|
|
9441
|
+
{ ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
|
|
9442
|
+
);
|
|
9443
|
+
const txNumberInBatch = Number(raw.transactionIndex ?? 0);
|
|
9444
|
+
const l2Sender = l1MessageSentSender(ev);
|
|
9445
|
+
return { raw, message, proof, chainId: BigInt(chainId), txNumberInBatch, l2Sender };
|
|
9446
|
+
}
|
|
9447
|
+
async function fetchFinalization(l2TxHash) {
|
|
9448
|
+
const protocol = await protocolService.protocol();
|
|
9449
|
+
const { raw, message, proof, chainId, txNumberInBatch, l2Sender } = await fetchMessageAndProof(l2TxHash);
|
|
9450
|
+
const target = await finalizationTarget(protocol);
|
|
9451
|
+
if (protocol === "legacy-withdrawal") {
|
|
9452
|
+
const params2 = {
|
|
9453
|
+
chainId,
|
|
9454
|
+
l2BatchNumber: proof.batchNumber,
|
|
9455
|
+
l2MessageIndex: proof.id,
|
|
9456
|
+
l2Sender,
|
|
9457
|
+
l2TxNumberInBatch: txNumberInBatch,
|
|
9458
|
+
message,
|
|
9459
|
+
merkleProof: proof.proof
|
|
9460
|
+
};
|
|
9461
|
+
return {
|
|
9462
|
+
target,
|
|
9463
|
+
finalization: { protocol, params: params2 },
|
|
9464
|
+
key: {
|
|
9465
|
+
chainIdL2: chainId,
|
|
9466
|
+
l2BatchNumber: proof.batchNumber,
|
|
9467
|
+
l2MessageIndex: proof.id
|
|
8661
9468
|
}
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
9469
|
+
};
|
|
9470
|
+
}
|
|
9471
|
+
const { interopCenter } = await client.ensureAddresses();
|
|
9472
|
+
const params = buildWithdrawalFinalization({
|
|
9473
|
+
messageData: message,
|
|
9474
|
+
sourceChainId: chainId,
|
|
9475
|
+
txNumberInBatch,
|
|
9476
|
+
proof: { batchNumber: proof.batchNumber, id: proof.id, proof: proof.proof },
|
|
9477
|
+
// Prefer the hash the InteropCenter emitted over recomputing it.
|
|
9478
|
+
bundleHash: parseBundleHashFromLogs(raw.logs ?? [], interopCenter),
|
|
9479
|
+
interopCenter
|
|
9480
|
+
});
|
|
9481
|
+
return {
|
|
9482
|
+
target,
|
|
9483
|
+
finalization: { protocol, params },
|
|
9484
|
+
key: {
|
|
9485
|
+
chainIdL2: chainId,
|
|
9486
|
+
l2BatchNumber: proof.batchNumber,
|
|
9487
|
+
l2MessageIndex: proof.id,
|
|
9488
|
+
bundleHash: params.bundleHash
|
|
8670
9489
|
}
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
9490
|
+
};
|
|
9491
|
+
}
|
|
9492
|
+
async function withdrawalOutcome(finalization) {
|
|
9493
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
9494
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
9495
|
+
const done = await wrapAs10(
|
|
9496
|
+
"RPC",
|
|
9497
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9498
|
+
() => client.l1.readContract({
|
|
9499
|
+
address: target,
|
|
9500
|
+
abi: IL1NullifierMini,
|
|
9501
|
+
functionName: "isWithdrawalFinalized",
|
|
9502
|
+
args: [
|
|
9503
|
+
finalization.params.chainId,
|
|
9504
|
+
finalization.params.l2BatchNumber,
|
|
9505
|
+
finalization.params.l2MessageIndex
|
|
9506
|
+
]
|
|
9507
|
+
}),
|
|
8676
9508
|
{
|
|
8677
|
-
ctx: {
|
|
8678
|
-
message: "Failed to
|
|
9509
|
+
ctx: { where: "isWithdrawalFinalized", params: finalization.params },
|
|
9510
|
+
message: "Failed to read finalization status."
|
|
8679
9511
|
}
|
|
8680
9512
|
);
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
9513
|
+
return done ? "finalized" : "pending";
|
|
9514
|
+
}
|
|
9515
|
+
const { bundleHash } = finalization.params;
|
|
9516
|
+
const status = Number(
|
|
9517
|
+
await wrapAs10(
|
|
9518
|
+
"RPC",
|
|
9519
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9520
|
+
() => client.l1.readContract({
|
|
9521
|
+
address: target,
|
|
9522
|
+
abi: IInteropHandler_default,
|
|
9523
|
+
functionName: "bundleStatus",
|
|
9524
|
+
args: [bundleHash]
|
|
9525
|
+
}),
|
|
8688
9526
|
{
|
|
8689
|
-
ctx: { where: "
|
|
8690
|
-
message: "Failed to
|
|
9527
|
+
ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
|
|
9528
|
+
message: "Failed to read bundle status."
|
|
8691
9529
|
}
|
|
8692
|
-
)
|
|
8693
|
-
|
|
9530
|
+
)
|
|
9531
|
+
);
|
|
9532
|
+
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
9533
|
+
const callStatus = Number(
|
|
9534
|
+
await wrapAs10(
|
|
8694
9535
|
"RPC",
|
|
8695
|
-
OP_WITHDRAWALS.finalize.
|
|
8696
|
-
() => client.
|
|
9536
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9537
|
+
() => client.l1.readContract({
|
|
9538
|
+
address: target,
|
|
9539
|
+
abi: IInteropHandler_default,
|
|
9540
|
+
functionName: "callStatus",
|
|
9541
|
+
args: [bundleHash, 0n]
|
|
9542
|
+
}),
|
|
8697
9543
|
{
|
|
8698
|
-
ctx: { where: "
|
|
8699
|
-
message: "Failed to
|
|
9544
|
+
ctx: { where: "L1InteropHandler.callStatus", bundleHash },
|
|
9545
|
+
message: "Failed to read bundle call status."
|
|
8700
9546
|
}
|
|
8701
|
-
)
|
|
8702
|
-
|
|
8703
|
-
|
|
9547
|
+
)
|
|
9548
|
+
);
|
|
9549
|
+
return classifyWithdrawalOutcome(status, callStatus);
|
|
9550
|
+
}
|
|
9551
|
+
async function isWithdrawalFinalized(finalization) {
|
|
9552
|
+
return await withdrawalOutcome(finalization) === "finalized";
|
|
9553
|
+
}
|
|
9554
|
+
return {
|
|
9555
|
+
fetchFinalization,
|
|
9556
|
+
isWithdrawalFinalized,
|
|
9557
|
+
withdrawalOutcome,
|
|
9558
|
+
async fetchFinalizeDepositParams(l2TxHash) {
|
|
9559
|
+
const resolved = await fetchFinalization(l2TxHash);
|
|
9560
|
+
if (resolved.finalization.protocol !== "legacy-withdrawal") {
|
|
9561
|
+
throw createError("VALIDATION", {
|
|
8704
9562
|
resource: "withdrawals",
|
|
8705
|
-
operation: OP_WITHDRAWALS.finalize.fetchParams.
|
|
8706
|
-
message: "
|
|
8707
|
-
context: { l2TxHash }
|
|
9563
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9564
|
+
message: "This chain finalizes withdrawals through the L1 interop handler; `finalizeDeposit` params do not exist. Use `fetchFinalization` instead.",
|
|
9565
|
+
context: { l2TxHash, protocol: resolved.finalization.protocol }
|
|
8708
9566
|
});
|
|
8709
9567
|
}
|
|
8710
|
-
|
|
8711
|
-
"INTERNAL",
|
|
8712
|
-
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
8713
|
-
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
8714
|
-
{
|
|
8715
|
-
ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
|
|
8716
|
-
message: "Failed to derive messenger log index."
|
|
8717
|
-
}
|
|
8718
|
-
);
|
|
8719
|
-
const proof = await wrapAs9(
|
|
8720
|
-
"RPC",
|
|
8721
|
-
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
8722
|
-
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
8723
|
-
{
|
|
8724
|
-
ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
|
|
8725
|
-
message: "Failed to fetch L2\u2192L1 log proof."
|
|
8726
|
-
}
|
|
8727
|
-
);
|
|
8728
|
-
const chainId = await wrapAs9(
|
|
8729
|
-
"RPC",
|
|
8730
|
-
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
8731
|
-
() => client.l2.getChainId(),
|
|
8732
|
-
{ ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
|
|
8733
|
-
);
|
|
8734
|
-
const txIndex = Number(parsed.transactionIndex ?? 0);
|
|
8735
|
-
const params = {
|
|
8736
|
-
chainId: BigInt(chainId),
|
|
8737
|
-
l2BatchNumber: proof.batchNumber,
|
|
8738
|
-
l2MessageIndex: proof.id,
|
|
8739
|
-
l2Sender: l1MessageSentSender(ev),
|
|
8740
|
-
l2TxNumberInBatch: txIndex,
|
|
8741
|
-
message,
|
|
8742
|
-
merkleProof: proof.proof
|
|
8743
|
-
};
|
|
8744
|
-
const { l1Nullifier } = await client.ensureAddresses();
|
|
8745
|
-
return { params, nullifier: l1Nullifier };
|
|
9568
|
+
return { params: resolved.finalization.params, nullifier: resolved.target };
|
|
8746
9569
|
},
|
|
8747
|
-
async simulateFinalizeReadiness(
|
|
8748
|
-
const
|
|
9570
|
+
async simulateFinalizeReadiness(finalization) {
|
|
9571
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
8749
9572
|
const done = await (async () => {
|
|
8750
9573
|
try {
|
|
8751
|
-
|
|
8752
|
-
"RPC",
|
|
8753
|
-
OP_WITHDRAWALS.finalize.readiness.isFinalized,
|
|
8754
|
-
() => client.l1.readContract({
|
|
8755
|
-
address: l1Nullifier,
|
|
8756
|
-
abi: IL1NullifierMini,
|
|
8757
|
-
functionName: "isWithdrawalFinalized",
|
|
8758
|
-
args: [params.chainId, params.l2BatchNumber, params.l2MessageIndex]
|
|
8759
|
-
}),
|
|
8760
|
-
{
|
|
8761
|
-
ctx: { where: "isWithdrawalFinalized", params },
|
|
8762
|
-
message: "Failed to read finalization status."
|
|
8763
|
-
}
|
|
8764
|
-
);
|
|
8765
|
-
return result;
|
|
9574
|
+
return await isWithdrawalFinalized(finalization);
|
|
8766
9575
|
} catch {
|
|
8767
9576
|
return false;
|
|
8768
9577
|
}
|
|
8769
9578
|
})();
|
|
8770
9579
|
if (done) return { kind: "FINALIZED" };
|
|
8771
9580
|
try {
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
9581
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
9582
|
+
await client.l1.simulateContract({
|
|
9583
|
+
address: target,
|
|
9584
|
+
abi: IL1Nullifier_default,
|
|
9585
|
+
functionName: "finalizeDeposit",
|
|
9586
|
+
args: [finalization.params],
|
|
9587
|
+
account: client.account
|
|
9588
|
+
});
|
|
9589
|
+
} else {
|
|
9590
|
+
await client.l1.simulateContract({
|
|
9591
|
+
address: target,
|
|
9592
|
+
abi: IInteropHandler_default,
|
|
9593
|
+
functionName: "executeBundle",
|
|
9594
|
+
args: [finalization.params.bundle, finalization.params.proof],
|
|
9595
|
+
account: client.account
|
|
9596
|
+
});
|
|
9597
|
+
}
|
|
8779
9598
|
return { kind: "READY" };
|
|
8780
9599
|
} catch (e) {
|
|
8781
9600
|
return classifyReadinessFromRevert(e);
|
|
8782
9601
|
}
|
|
8783
9602
|
},
|
|
8784
|
-
async
|
|
8785
|
-
const
|
|
8786
|
-
|
|
8787
|
-
"RPC",
|
|
8788
|
-
OP_WITHDRAWALS.finalize.isFinalized,
|
|
8789
|
-
() => client.l1.readContract({
|
|
8790
|
-
address: l1Nullifier,
|
|
8791
|
-
abi: IL1NullifierMini,
|
|
8792
|
-
functionName: "isWithdrawalFinalized",
|
|
8793
|
-
args: [key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex]
|
|
8794
|
-
}),
|
|
8795
|
-
{
|
|
8796
|
-
ctx: { where: "isWithdrawalFinalized", key },
|
|
8797
|
-
message: "Failed to read finalization status."
|
|
8798
|
-
}
|
|
8799
|
-
);
|
|
8800
|
-
},
|
|
8801
|
-
async estimateFinalization(params) {
|
|
8802
|
-
const { l1Nullifier } = await client.ensureAddresses();
|
|
8803
|
-
const gasLimit = await wrapAs9(
|
|
9603
|
+
async estimateFinalization(finalization) {
|
|
9604
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
9605
|
+
const gasLimit = await wrapAs10(
|
|
8804
9606
|
"RPC",
|
|
8805
9607
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8806
|
-
() => client.l1.estimateContractGas({
|
|
8807
|
-
address:
|
|
9608
|
+
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
9609
|
+
address: target,
|
|
8808
9610
|
abi: IL1Nullifier_default,
|
|
8809
9611
|
functionName: "finalizeDeposit",
|
|
8810
|
-
args: [params],
|
|
9612
|
+
args: [finalization.params],
|
|
9613
|
+
account: client.account
|
|
9614
|
+
}) : client.l1.estimateContractGas({
|
|
9615
|
+
address: target,
|
|
9616
|
+
abi: IInteropHandler_default,
|
|
9617
|
+
functionName: "executeBundle",
|
|
9618
|
+
args: [finalization.params.bundle, finalization.params.proof],
|
|
8811
9619
|
account: client.account
|
|
8812
9620
|
}),
|
|
8813
9621
|
{
|
|
8814
9622
|
ctx: {
|
|
8815
|
-
where: "estimateContractGas(
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
8819
|
-
l1Nullifier
|
|
9623
|
+
where: "estimateContractGas(finalize)",
|
|
9624
|
+
protocol: finalization.protocol,
|
|
9625
|
+
target
|
|
8820
9626
|
},
|
|
8821
|
-
message: "Failed to estimate gas for
|
|
9627
|
+
message: "Failed to estimate gas for withdrawal finalization."
|
|
8822
9628
|
}
|
|
8823
9629
|
);
|
|
8824
9630
|
let maxFeePerGas;
|
|
8825
9631
|
let maxPriorityFeePerGas;
|
|
8826
9632
|
try {
|
|
8827
|
-
const fee = await
|
|
9633
|
+
const fee = await wrapAs10(
|
|
8828
9634
|
"RPC",
|
|
8829
9635
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8830
9636
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -8843,32 +9649,34 @@ function createFinalizationServices(client) {
|
|
|
8843
9649
|
})();
|
|
8844
9650
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
8845
9651
|
} catch {
|
|
8846
|
-
const gasPrice = await
|
|
9652
|
+
const gasPrice = await wrapAs10(
|
|
8847
9653
|
"RPC",
|
|
8848
9654
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8849
9655
|
() => client.l1.getGasPrice(),
|
|
8850
9656
|
{
|
|
8851
9657
|
ctx: { where: "getGasPrice" },
|
|
8852
|
-
message: "Failed to read gas price for
|
|
9658
|
+
message: "Failed to read gas price for withdrawal finalization."
|
|
8853
9659
|
}
|
|
8854
9660
|
);
|
|
8855
9661
|
maxFeePerGas = gasPrice;
|
|
8856
9662
|
maxPriorityFeePerGas = 0n;
|
|
8857
9663
|
}
|
|
8858
|
-
return {
|
|
8859
|
-
gasLimit,
|
|
8860
|
-
maxFeePerGas,
|
|
8861
|
-
maxPriorityFeePerGas
|
|
8862
|
-
};
|
|
9664
|
+
return { gasLimit, maxFeePerGas, maxPriorityFeePerGas };
|
|
8863
9665
|
},
|
|
8864
|
-
async
|
|
8865
|
-
const
|
|
9666
|
+
async finalize(finalization) {
|
|
9667
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
8866
9668
|
try {
|
|
8867
|
-
const hash = await client.l1Wallet.writeContract({
|
|
8868
|
-
address:
|
|
9669
|
+
const hash = finalization.protocol === "legacy-withdrawal" ? await client.l1Wallet.writeContract({
|
|
9670
|
+
address: target,
|
|
8869
9671
|
abi: IL1Nullifier_default,
|
|
8870
9672
|
functionName: "finalizeDeposit",
|
|
8871
|
-
args: [params],
|
|
9673
|
+
args: [finalization.params],
|
|
9674
|
+
account: client.account
|
|
9675
|
+
}) : await client.l1Wallet.writeContract({
|
|
9676
|
+
address: target,
|
|
9677
|
+
abi: IInteropHandler_default,
|
|
9678
|
+
functionName: "executeBundle",
|
|
9679
|
+
args: [finalization.params.bundle, finalization.params.proof],
|
|
8872
9680
|
account: client.account
|
|
8873
9681
|
});
|
|
8874
9682
|
return {
|
|
@@ -8882,8 +9690,8 @@ function createFinalizationServices(client) {
|
|
|
8882
9690
|
{
|
|
8883
9691
|
resource: "withdrawals",
|
|
8884
9692
|
operation: OP_WITHDRAWALS.finalize.wait,
|
|
8885
|
-
message: "Failed while waiting for
|
|
8886
|
-
context: { txHash: hash }
|
|
9693
|
+
message: "Failed while waiting for the withdrawal finalization transaction.",
|
|
9694
|
+
context: { txHash: hash, protocol: finalization.protocol }
|
|
8887
9695
|
},
|
|
8888
9696
|
e
|
|
8889
9697
|
);
|
|
@@ -8896,13 +9704,8 @@ function createFinalizationServices(client) {
|
|
|
8896
9704
|
{
|
|
8897
9705
|
resource: "withdrawals",
|
|
8898
9706
|
operation: OP_WITHDRAWALS.finalize.send,
|
|
8899
|
-
message: "Failed to send
|
|
8900
|
-
context: {
|
|
8901
|
-
chainIdL2: params.chainId,
|
|
8902
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
8903
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
8904
|
-
l1Nullifier
|
|
8905
|
-
}
|
|
9707
|
+
message: "Failed to send the withdrawal finalization transaction.",
|
|
9708
|
+
context: { protocol: finalization.protocol, target }
|
|
8906
9709
|
},
|
|
8907
9710
|
e
|
|
8908
9711
|
);
|
|
@@ -8935,15 +9738,28 @@ var ROUTES2 = {
|
|
|
8935
9738
|
"erc20-nonbase": routeErc20NonBase2()
|
|
8936
9739
|
// AssetRouter.withdraw for non-base ERC-20s
|
|
8937
9740
|
};
|
|
8938
|
-
|
|
8939
|
-
|
|
9741
|
+
var INTEROP_ROUTES = {
|
|
9742
|
+
base: routeInteropBundle(),
|
|
9743
|
+
"erc20-nonbase": routeInteropBundle()
|
|
9744
|
+
};
|
|
9745
|
+
function routeStrategy(protocol, route) {
|
|
9746
|
+
return protocol === "interop-bundle" ? INTEROP_ROUTES[route] : ROUTES2[route];
|
|
9747
|
+
}
|
|
9748
|
+
function createWithdrawalsResource(client, tokens, contracts, options) {
|
|
9749
|
+
const protocolService = createWithdrawalProtocolService(
|
|
9750
|
+
client,
|
|
9751
|
+
options?.protocol
|
|
9752
|
+
);
|
|
9753
|
+
const svc = createFinalizationServices(client, protocolService);
|
|
8940
9754
|
const { wrap: wrap7, toResult: toResult3 } = createErrorHandlers("withdrawals");
|
|
8941
9755
|
const tokensResource = tokens ?? createTokensResource(client);
|
|
8942
9756
|
const contractsResource = contracts ?? createContractsResource(client);
|
|
8943
9757
|
async function buildPlan(p) {
|
|
8944
|
-
const
|
|
8945
|
-
await
|
|
8946
|
-
const
|
|
9758
|
+
const protocol = await protocolService.protocol();
|
|
9759
|
+
const ctx = await commonCtx2(p, client, tokensResource, contractsResource, protocol);
|
|
9760
|
+
const strategy = routeStrategy(protocol, ctx.route);
|
|
9761
|
+
await strategy.preflight?.(p, ctx);
|
|
9762
|
+
const { steps, approvals, fees } = await strategy.build(p, ctx);
|
|
8947
9763
|
return {
|
|
8948
9764
|
route: ctx.route,
|
|
8949
9765
|
summary: {
|
|
@@ -9110,21 +9926,20 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9110
9926
|
if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
|
|
9111
9927
|
let pack;
|
|
9112
9928
|
try {
|
|
9113
|
-
pack = await svc.
|
|
9929
|
+
pack = await svc.fetchFinalization(l2TxHash);
|
|
9114
9930
|
} catch {
|
|
9115
9931
|
return { phase: "PENDING", l2TxHash };
|
|
9116
9932
|
}
|
|
9117
|
-
const key =
|
|
9118
|
-
chainIdL2: pack.params.chainId,
|
|
9119
|
-
l2BatchNumber: pack.params.l2BatchNumber,
|
|
9120
|
-
l2MessageIndex: pack.params.l2MessageIndex
|
|
9121
|
-
};
|
|
9933
|
+
const key = pack.key;
|
|
9122
9934
|
try {
|
|
9123
|
-
const
|
|
9124
|
-
if (
|
|
9935
|
+
const outcome = await svc.withdrawalOutcome(pack.finalization);
|
|
9936
|
+
if (outcome === "finalized") return { phase: "FINALIZED", l2TxHash, key };
|
|
9937
|
+
if (outcome === "failed") {
|
|
9938
|
+
return { phase: "UNFINALIZABLE", l2TxHash, key, reason: "bundle-cancelled" };
|
|
9939
|
+
}
|
|
9125
9940
|
} catch {
|
|
9126
9941
|
}
|
|
9127
|
-
const readiness = await svc.simulateFinalizeReadiness(pack.
|
|
9942
|
+
const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
|
|
9128
9943
|
const { phase, reason } = phaseFromReadiness(readiness);
|
|
9129
9944
|
return { phase, reason, l2TxHash, key };
|
|
9130
9945
|
},
|
|
@@ -9218,7 +10033,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9218
10033
|
async () => {
|
|
9219
10034
|
const pack = await (async () => {
|
|
9220
10035
|
try {
|
|
9221
|
-
return await svc.
|
|
10036
|
+
return await svc.fetchFinalization(l2TxHash);
|
|
9222
10037
|
} catch (e) {
|
|
9223
10038
|
throw createError("STATE", {
|
|
9224
10039
|
resource: "withdrawals",
|
|
@@ -9229,21 +10044,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9229
10044
|
});
|
|
9230
10045
|
}
|
|
9231
10046
|
})();
|
|
9232
|
-
const {
|
|
9233
|
-
const key = {
|
|
9234
|
-
chainIdL2: params.chainId,
|
|
9235
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
9236
|
-
l2MessageIndex: params.l2MessageIndex
|
|
9237
|
-
};
|
|
10047
|
+
const { finalization } = pack;
|
|
9238
10048
|
try {
|
|
9239
|
-
const
|
|
9240
|
-
if (
|
|
10049
|
+
const outcome = await svc.withdrawalOutcome(finalization);
|
|
10050
|
+
if (outcome === "finalized" || outcome === "failed") {
|
|
9241
10051
|
const statusNow = await status(l2TxHash);
|
|
9242
10052
|
return { status: statusNow };
|
|
9243
10053
|
}
|
|
9244
10054
|
} catch {
|
|
9245
10055
|
}
|
|
9246
|
-
const readiness = await svc.simulateFinalizeReadiness(
|
|
10056
|
+
const readiness = await svc.simulateFinalizeReadiness(finalization);
|
|
9247
10057
|
if (readiness.kind === "FINALIZED") {
|
|
9248
10058
|
const statusNow = await status(l2TxHash);
|
|
9249
10059
|
return { status: statusNow };
|
|
@@ -9257,7 +10067,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9257
10067
|
});
|
|
9258
10068
|
}
|
|
9259
10069
|
try {
|
|
9260
|
-
const tx = await svc.
|
|
10070
|
+
const tx = await svc.finalize(finalization);
|
|
9261
10071
|
finalizeCache.set(l2TxHash, tx.hash);
|
|
9262
10072
|
const rcpt = await tx.wait();
|
|
9263
10073
|
const statusNow = await status(l2TxHash);
|
|
@@ -9266,7 +10076,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9266
10076
|
const statusNow = await status(l2TxHash);
|
|
9267
10077
|
if (statusNow.phase === "FINALIZED") return { status: statusNow };
|
|
9268
10078
|
try {
|
|
9269
|
-
const again = await svc.simulateFinalizeReadiness(
|
|
10079
|
+
const again = await svc.simulateFinalizeReadiness(finalization);
|
|
9270
10080
|
if (again.kind === "NOT_READY") {
|
|
9271
10081
|
throw createError("STATE", {
|
|
9272
10082
|
resource: "withdrawals",
|
|
@@ -9325,77 +10135,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9325
10135
|
};
|
|
9326
10136
|
}
|
|
9327
10137
|
|
|
9328
|
-
// src/core/resources/interop/attributes/call.ts
|
|
9329
|
-
function createCallAttributes(codec) {
|
|
9330
|
-
const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
|
|
9331
|
-
const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
|
|
9332
|
-
return {
|
|
9333
|
-
indirectCall,
|
|
9334
|
-
interopCallValue
|
|
9335
|
-
};
|
|
9336
|
-
}
|
|
9337
|
-
|
|
9338
|
-
// src/core/resources/interop/attributes/bundle.ts
|
|
9339
|
-
function createBundleAttributes(codec) {
|
|
9340
|
-
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
9341
|
-
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
9342
|
-
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
9343
|
-
return {
|
|
9344
|
-
executionAddress,
|
|
9345
|
-
unbundlerAddress,
|
|
9346
|
-
useFixedFee
|
|
9347
|
-
};
|
|
9348
|
-
}
|
|
9349
|
-
|
|
9350
|
-
// src/core/resources/interop/attributes/resource.ts
|
|
9351
|
-
function createAttributesResource(codec) {
|
|
9352
|
-
return {
|
|
9353
|
-
call: createCallAttributes(codec),
|
|
9354
|
-
bundle: createBundleAttributes(codec)
|
|
9355
|
-
};
|
|
9356
|
-
}
|
|
9357
|
-
|
|
9358
|
-
// src/adapters/viem/resources/interop/attributes/resource.ts
|
|
9359
|
-
function getInteropAttributes(params, ctx) {
|
|
9360
|
-
const bundleAttributes = [];
|
|
9361
|
-
if (params.execution?.only) {
|
|
9362
|
-
bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
|
|
9363
|
-
}
|
|
9364
|
-
if (params.unbundling?.by) {
|
|
9365
|
-
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
9366
|
-
}
|
|
9367
|
-
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
9368
|
-
const callAttributes = params.actions.map((action) => {
|
|
9369
|
-
switch (action.type) {
|
|
9370
|
-
case "sendNative": {
|
|
9371
|
-
const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
|
|
9372
|
-
if (baseMatches) {
|
|
9373
|
-
return [ctx.attributes.call.interopCallValue(action.amount)];
|
|
9374
|
-
}
|
|
9375
|
-
return [ctx.attributes.call.indirectCall(action.amount)];
|
|
9376
|
-
}
|
|
9377
|
-
case "call":
|
|
9378
|
-
if (action.value && action.value > 0n) {
|
|
9379
|
-
return [ctx.attributes.call.interopCallValue(action.value)];
|
|
9380
|
-
}
|
|
9381
|
-
return [];
|
|
9382
|
-
case "sendErc20":
|
|
9383
|
-
return [ctx.attributes.call.indirectCall(0n)];
|
|
9384
|
-
default:
|
|
9385
|
-
assertNever(action);
|
|
9386
|
-
}
|
|
9387
|
-
});
|
|
9388
|
-
return { bundleAttributes, callAttributes };
|
|
9389
|
-
}
|
|
9390
|
-
function createViemAttributesResource() {
|
|
9391
|
-
const encode = (fn, args) => viem.encodeFunctionData({
|
|
9392
|
-
abi: IERC7786Attributes_default,
|
|
9393
|
-
functionName: fn,
|
|
9394
|
-
args
|
|
9395
|
-
});
|
|
9396
|
-
return createAttributesResource({ encode });
|
|
9397
|
-
}
|
|
9398
|
-
|
|
9399
10138
|
// src/core/types/flows/interop.ts
|
|
9400
10139
|
function isInteropMessageProof(obj) {
|
|
9401
10140
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -9572,24 +10311,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
|
|
|
9572
10311
|
}
|
|
9573
10312
|
};
|
|
9574
10313
|
}
|
|
9575
|
-
var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
|
|
9576
|
-
var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
|
|
9577
|
-
function formatInteropEvmChain(chainId) {
|
|
9578
|
-
const chainRef = viem.toBytes(viem.toHex(chainId));
|
|
9579
|
-
const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
|
|
9580
|
-
const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
|
|
9581
|
-
return viem.toHex(payload);
|
|
9582
|
-
}
|
|
9583
|
-
function formatInteropEvmAddress(address) {
|
|
9584
|
-
const normalized = viem.getAddress(address);
|
|
9585
|
-
const addrBytes = viem.toBytes(normalized);
|
|
9586
|
-
const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
|
|
9587
|
-
return viem.toHex(payload);
|
|
9588
|
-
}
|
|
9589
|
-
var interopCodec = {
|
|
9590
|
-
formatChain: formatInteropEvmChain,
|
|
9591
|
-
formatAddress: formatInteropEvmAddress
|
|
9592
|
-
};
|
|
9593
10314
|
function getErc20Tokens(params) {
|
|
9594
10315
|
const erc20Tokens = /* @__PURE__ */ new Map();
|
|
9595
10316
|
for (const action of params.actions) {
|
|
@@ -9771,7 +10492,7 @@ function routeIndirect() {
|
|
|
9771
10492
|
resolveErc20AssetIds(erc20Tokens, ctx),
|
|
9772
10493
|
buildFeeInfo(params, ctx, params.actions.length)
|
|
9773
10494
|
]);
|
|
9774
|
-
const
|
|
10495
|
+
const attributes2 = getInteropAttributes(params, ctx);
|
|
9775
10496
|
const starterData = await getStarterData(params, ctx, erc20AssetIds);
|
|
9776
10497
|
const bundle = buildIndirectBundle(
|
|
9777
10498
|
params,
|
|
@@ -9782,7 +10503,7 @@ function routeIndirect() {
|
|
|
9782
10503
|
l2NativeTokenVault: ctx.l2NativeTokenVault,
|
|
9783
10504
|
codec: interopCodec
|
|
9784
10505
|
},
|
|
9785
|
-
|
|
10506
|
+
attributes2,
|
|
9786
10507
|
starterData,
|
|
9787
10508
|
feeInfo
|
|
9788
10509
|
);
|
|
@@ -9902,7 +10623,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
|
|
|
9902
10623
|
assertProtocolVersion(srcChainId, srcProtocolVersion);
|
|
9903
10624
|
assertProtocolVersion(dstChainId, dstProtocolVersion);
|
|
9904
10625
|
}
|
|
9905
|
-
async function commonCtx3(dstPublicClient, params, client, tokens, contracts,
|
|
10626
|
+
async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes2) {
|
|
9906
10627
|
const sender = client.account.address;
|
|
9907
10628
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9908
10629
|
const dstChainId = BigInt(await dstPublicClient.getChainId());
|
|
@@ -9936,7 +10657,7 @@ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, at
|
|
|
9936
10657
|
l2AssetRouter,
|
|
9937
10658
|
l2NativeTokenVault,
|
|
9938
10659
|
baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
|
|
9939
|
-
attributes,
|
|
10660
|
+
attributes: attributes2,
|
|
9940
10661
|
gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
|
|
9941
10662
|
};
|
|
9942
10663
|
}
|
|
@@ -10636,7 +11357,7 @@ var ROUTES3 = {
|
|
|
10636
11357
|
direct: routeDirect(),
|
|
10637
11358
|
indirect: routeIndirect()
|
|
10638
11359
|
};
|
|
10639
|
-
function createInteropResource(client, config, tokens, contracts,
|
|
11360
|
+
function createInteropResource(client, config, tokens, contracts, attributes2) {
|
|
10640
11361
|
let gwProviderCache;
|
|
10641
11362
|
function requireConfig() {
|
|
10642
11363
|
if (!config)
|
|
@@ -10874,7 +11595,7 @@ function createViemSdk(client, options) {
|
|
|
10874
11595
|
const interop = createInteropResource(client, options?.interop, tokens, contracts);
|
|
10875
11596
|
return {
|
|
10876
11597
|
deposits: createDepositsResource(client, tokens, contracts),
|
|
10877
|
-
withdrawals: createWithdrawalsResource(client, tokens, contracts),
|
|
11598
|
+
withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
|
|
10878
11599
|
tokens,
|
|
10879
11600
|
contracts,
|
|
10880
11601
|
interop
|