@matterlabs/zksync-js 0.0.20 → 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 +1057 -290
- 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 +1010 -274
- 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 +1094 -296
- 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 +1048 -295
- 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-3HHUZXSV.js → chunk-32N6TI6K.js} +10 -2
- package/dist/{chunk-6LYAENO6.js → chunk-3SPDWWRD.js} +6 -4
- package/dist/{chunk-3T5V4HKS.js → chunk-4K4LOCQJ.js} +569 -259
- package/dist/{chunk-UEKFQAOS.js → chunk-AMRHBZIY.js} +304 -2
- package/dist/{chunk-E2XKJCI5.js → chunk-CP4SQ5PM.js} +537 -242
- 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 +513 -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/resources/withdrawals/status.d.ts +5 -0
- package/dist/core/types/flows/withdrawals.d.ts +32 -2
- package/dist/core/utils/events.d.ts +2 -0
- package/dist/index.cjs +313 -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) {
|
|
@@ -8614,19 +9200,151 @@ function isL1MessageSentLog(log, opts) {
|
|
|
8614
9200
|
const preferAddr = extractPreferAddress(opts);
|
|
8615
9201
|
return log.address.toLowerCase() === preferAddr && (topic === TOPIC_L1_MESSAGE_SENT_LEG.toLowerCase() || topic === TOPIC_L1_MESSAGE_SENT_NEW.toLowerCase());
|
|
8616
9202
|
}
|
|
9203
|
+
var SENDER_TOPIC = /^0x0{24}([0-9a-fA-F]{40})$/;
|
|
9204
|
+
function l1MessageSentSender(log) {
|
|
9205
|
+
const sender = SENDER_TOPIC.exec(log.topics?.[1] ?? "")?.[1];
|
|
9206
|
+
if (!sender) {
|
|
9207
|
+
throw new Error("L1MessageSent log has no valid sender topic.");
|
|
9208
|
+
}
|
|
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
|
+
}
|
|
9278
|
+
}
|
|
9279
|
+
|
|
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" } };
|
|
9289
|
+
}
|
|
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
|
+
};
|
|
9304
|
+
}
|
|
8617
9305
|
|
|
8618
|
-
// src/
|
|
8619
|
-
function
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
|
|
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
|
+
}
|
|
8626
9316
|
}
|
|
8627
|
-
|
|
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
|
+
};
|
|
8628
9346
|
}
|
|
8629
|
-
var { wrapAs:
|
|
9347
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
8630
9348
|
var IL1NullifierMini = [
|
|
8631
9349
|
{
|
|
8632
9350
|
type: "function",
|
|
@@ -8640,183 +9358,279 @@ var IL1NullifierMini = [
|
|
|
8640
9358
|
outputs: [{ type: "bool" }]
|
|
8641
9359
|
}
|
|
8642
9360
|
];
|
|
8643
|
-
function createFinalizationServices(client) {
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
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
|
|
8653
9468
|
}
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
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
|
|
8662
9489
|
}
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
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
|
+
}),
|
|
8668
9508
|
{
|
|
8669
|
-
ctx: {
|
|
8670
|
-
message: "Failed to
|
|
9509
|
+
ctx: { where: "isWithdrawalFinalized", params: finalization.params },
|
|
9510
|
+
message: "Failed to read finalization status."
|
|
8671
9511
|
}
|
|
8672
9512
|
);
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
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
|
+
}),
|
|
8680
9526
|
{
|
|
8681
|
-
ctx: { where: "
|
|
8682
|
-
message: "Failed to
|
|
9527
|
+
ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
|
|
9528
|
+
message: "Failed to read bundle status."
|
|
8683
9529
|
}
|
|
8684
|
-
)
|
|
8685
|
-
|
|
9530
|
+
)
|
|
9531
|
+
);
|
|
9532
|
+
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
9533
|
+
const callStatus = Number(
|
|
9534
|
+
await wrapAs10(
|
|
8686
9535
|
"RPC",
|
|
8687
|
-
OP_WITHDRAWALS.finalize.
|
|
8688
|
-
() => 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
|
+
}),
|
|
8689
9543
|
{
|
|
8690
|
-
ctx: { where: "
|
|
8691
|
-
message: "Failed to
|
|
9544
|
+
ctx: { where: "L1InteropHandler.callStatus", bundleHash },
|
|
9545
|
+
message: "Failed to read bundle call status."
|
|
8692
9546
|
}
|
|
8693
|
-
)
|
|
8694
|
-
|
|
8695
|
-
|
|
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", {
|
|
8696
9562
|
resource: "withdrawals",
|
|
8697
|
-
operation: OP_WITHDRAWALS.finalize.fetchParams.
|
|
8698
|
-
message: "
|
|
8699
|
-
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 }
|
|
8700
9566
|
});
|
|
8701
9567
|
}
|
|
8702
|
-
|
|
8703
|
-
"INTERNAL",
|
|
8704
|
-
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
8705
|
-
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
8706
|
-
{
|
|
8707
|
-
ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
|
|
8708
|
-
message: "Failed to derive messenger log index."
|
|
8709
|
-
}
|
|
8710
|
-
);
|
|
8711
|
-
const proof = await wrapAs9(
|
|
8712
|
-
"RPC",
|
|
8713
|
-
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
8714
|
-
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
8715
|
-
{
|
|
8716
|
-
ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
|
|
8717
|
-
message: "Failed to fetch L2\u2192L1 log proof."
|
|
8718
|
-
}
|
|
8719
|
-
);
|
|
8720
|
-
const chainId = await wrapAs9(
|
|
8721
|
-
"RPC",
|
|
8722
|
-
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
8723
|
-
() => client.l2.getChainId(),
|
|
8724
|
-
{ ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
|
|
8725
|
-
);
|
|
8726
|
-
const txIndex = Number(parsed.transactionIndex ?? 0);
|
|
8727
|
-
const params = {
|
|
8728
|
-
chainId: BigInt(chainId),
|
|
8729
|
-
l2BatchNumber: proof.batchNumber,
|
|
8730
|
-
l2MessageIndex: proof.id,
|
|
8731
|
-
l2Sender: parsed.to,
|
|
8732
|
-
l2TxNumberInBatch: txIndex,
|
|
8733
|
-
message,
|
|
8734
|
-
merkleProof: proof.proof
|
|
8735
|
-
};
|
|
8736
|
-
const { l1Nullifier } = await client.ensureAddresses();
|
|
8737
|
-
return { params, nullifier: l1Nullifier };
|
|
9568
|
+
return { params: resolved.finalization.params, nullifier: resolved.target };
|
|
8738
9569
|
},
|
|
8739
|
-
async simulateFinalizeReadiness(
|
|
8740
|
-
const
|
|
9570
|
+
async simulateFinalizeReadiness(finalization) {
|
|
9571
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
8741
9572
|
const done = await (async () => {
|
|
8742
9573
|
try {
|
|
8743
|
-
|
|
8744
|
-
"RPC",
|
|
8745
|
-
OP_WITHDRAWALS.finalize.readiness.isFinalized,
|
|
8746
|
-
() => client.l1.readContract({
|
|
8747
|
-
address: l1Nullifier,
|
|
8748
|
-
abi: IL1NullifierMini,
|
|
8749
|
-
functionName: "isWithdrawalFinalized",
|
|
8750
|
-
args: [params.chainId, params.l2BatchNumber, params.l2MessageIndex]
|
|
8751
|
-
}),
|
|
8752
|
-
{
|
|
8753
|
-
ctx: { where: "isWithdrawalFinalized", params },
|
|
8754
|
-
message: "Failed to read finalization status."
|
|
8755
|
-
}
|
|
8756
|
-
);
|
|
8757
|
-
return result;
|
|
9574
|
+
return await isWithdrawalFinalized(finalization);
|
|
8758
9575
|
} catch {
|
|
8759
9576
|
return false;
|
|
8760
9577
|
}
|
|
8761
9578
|
})();
|
|
8762
9579
|
if (done) return { kind: "FINALIZED" };
|
|
8763
9580
|
try {
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
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
|
+
}
|
|
8771
9598
|
return { kind: "READY" };
|
|
8772
9599
|
} catch (e) {
|
|
8773
9600
|
return classifyReadinessFromRevert(e);
|
|
8774
9601
|
}
|
|
8775
9602
|
},
|
|
8776
|
-
async
|
|
8777
|
-
const
|
|
8778
|
-
|
|
8779
|
-
"RPC",
|
|
8780
|
-
OP_WITHDRAWALS.finalize.isFinalized,
|
|
8781
|
-
() => client.l1.readContract({
|
|
8782
|
-
address: l1Nullifier,
|
|
8783
|
-
abi: IL1NullifierMini,
|
|
8784
|
-
functionName: "isWithdrawalFinalized",
|
|
8785
|
-
args: [key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex]
|
|
8786
|
-
}),
|
|
8787
|
-
{
|
|
8788
|
-
ctx: { where: "isWithdrawalFinalized", key },
|
|
8789
|
-
message: "Failed to read finalization status."
|
|
8790
|
-
}
|
|
8791
|
-
);
|
|
8792
|
-
},
|
|
8793
|
-
async estimateFinalization(params) {
|
|
8794
|
-
const { l1Nullifier } = await client.ensureAddresses();
|
|
8795
|
-
const gasLimit = await wrapAs9(
|
|
9603
|
+
async estimateFinalization(finalization) {
|
|
9604
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
9605
|
+
const gasLimit = await wrapAs10(
|
|
8796
9606
|
"RPC",
|
|
8797
9607
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8798
|
-
() => client.l1.estimateContractGas({
|
|
8799
|
-
address:
|
|
9608
|
+
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
9609
|
+
address: target,
|
|
8800
9610
|
abi: IL1Nullifier_default,
|
|
8801
9611
|
functionName: "finalizeDeposit",
|
|
8802
|
-
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],
|
|
8803
9619
|
account: client.account
|
|
8804
9620
|
}),
|
|
8805
9621
|
{
|
|
8806
9622
|
ctx: {
|
|
8807
|
-
where: "estimateContractGas(
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
8811
|
-
l1Nullifier
|
|
9623
|
+
where: "estimateContractGas(finalize)",
|
|
9624
|
+
protocol: finalization.protocol,
|
|
9625
|
+
target
|
|
8812
9626
|
},
|
|
8813
|
-
message: "Failed to estimate gas for
|
|
9627
|
+
message: "Failed to estimate gas for withdrawal finalization."
|
|
8814
9628
|
}
|
|
8815
9629
|
);
|
|
8816
9630
|
let maxFeePerGas;
|
|
8817
9631
|
let maxPriorityFeePerGas;
|
|
8818
9632
|
try {
|
|
8819
|
-
const fee = await
|
|
9633
|
+
const fee = await wrapAs10(
|
|
8820
9634
|
"RPC",
|
|
8821
9635
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8822
9636
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -8835,32 +9649,34 @@ function createFinalizationServices(client) {
|
|
|
8835
9649
|
})();
|
|
8836
9650
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
8837
9651
|
} catch {
|
|
8838
|
-
const gasPrice = await
|
|
9652
|
+
const gasPrice = await wrapAs10(
|
|
8839
9653
|
"RPC",
|
|
8840
9654
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8841
9655
|
() => client.l1.getGasPrice(),
|
|
8842
9656
|
{
|
|
8843
9657
|
ctx: { where: "getGasPrice" },
|
|
8844
|
-
message: "Failed to read gas price for
|
|
9658
|
+
message: "Failed to read gas price for withdrawal finalization."
|
|
8845
9659
|
}
|
|
8846
9660
|
);
|
|
8847
9661
|
maxFeePerGas = gasPrice;
|
|
8848
9662
|
maxPriorityFeePerGas = 0n;
|
|
8849
9663
|
}
|
|
8850
|
-
return {
|
|
8851
|
-
gasLimit,
|
|
8852
|
-
maxFeePerGas,
|
|
8853
|
-
maxPriorityFeePerGas
|
|
8854
|
-
};
|
|
9664
|
+
return { gasLimit, maxFeePerGas, maxPriorityFeePerGas };
|
|
8855
9665
|
},
|
|
8856
|
-
async
|
|
8857
|
-
const
|
|
9666
|
+
async finalize(finalization) {
|
|
9667
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
8858
9668
|
try {
|
|
8859
|
-
const hash = await client.l1Wallet.writeContract({
|
|
8860
|
-
address:
|
|
9669
|
+
const hash = finalization.protocol === "legacy-withdrawal" ? await client.l1Wallet.writeContract({
|
|
9670
|
+
address: target,
|
|
8861
9671
|
abi: IL1Nullifier_default,
|
|
8862
9672
|
functionName: "finalizeDeposit",
|
|
8863
|
-
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],
|
|
8864
9680
|
account: client.account
|
|
8865
9681
|
});
|
|
8866
9682
|
return {
|
|
@@ -8874,8 +9690,8 @@ function createFinalizationServices(client) {
|
|
|
8874
9690
|
{
|
|
8875
9691
|
resource: "withdrawals",
|
|
8876
9692
|
operation: OP_WITHDRAWALS.finalize.wait,
|
|
8877
|
-
message: "Failed while waiting for
|
|
8878
|
-
context: { txHash: hash }
|
|
9693
|
+
message: "Failed while waiting for the withdrawal finalization transaction.",
|
|
9694
|
+
context: { txHash: hash, protocol: finalization.protocol }
|
|
8879
9695
|
},
|
|
8880
9696
|
e
|
|
8881
9697
|
);
|
|
@@ -8888,13 +9704,8 @@ function createFinalizationServices(client) {
|
|
|
8888
9704
|
{
|
|
8889
9705
|
resource: "withdrawals",
|
|
8890
9706
|
operation: OP_WITHDRAWALS.finalize.send,
|
|
8891
|
-
message: "Failed to send
|
|
8892
|
-
context: {
|
|
8893
|
-
chainIdL2: params.chainId,
|
|
8894
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
8895
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
8896
|
-
l1Nullifier
|
|
8897
|
-
}
|
|
9707
|
+
message: "Failed to send the withdrawal finalization transaction.",
|
|
9708
|
+
context: { protocol: finalization.protocol, target }
|
|
8898
9709
|
},
|
|
8899
9710
|
e
|
|
8900
9711
|
);
|
|
@@ -8903,6 +9714,23 @@ function createFinalizationServices(client) {
|
|
|
8903
9714
|
};
|
|
8904
9715
|
}
|
|
8905
9716
|
|
|
9717
|
+
// src/core/resources/withdrawals/status.ts
|
|
9718
|
+
function phaseFromReadiness(r) {
|
|
9719
|
+
switch (r.kind) {
|
|
9720
|
+
case "FINALIZED":
|
|
9721
|
+
return { phase: "FINALIZED" };
|
|
9722
|
+
case "READY":
|
|
9723
|
+
return { phase: "READY_TO_FINALIZE" };
|
|
9724
|
+
case "NOT_READY":
|
|
9725
|
+
return { phase: "PENDING", reason: formatReason(r.reason, r.detail) };
|
|
9726
|
+
case "UNFINALIZABLE":
|
|
9727
|
+
return { phase: "UNFINALIZABLE", reason: formatReason(r.reason, r.detail) };
|
|
9728
|
+
default:
|
|
9729
|
+
return assertNever(r);
|
|
9730
|
+
}
|
|
9731
|
+
}
|
|
9732
|
+
var formatReason = (reason, detail) => detail ? `${reason}: ${detail}` : reason;
|
|
9733
|
+
|
|
8906
9734
|
// src/adapters/viem/resources/withdrawals/index.ts
|
|
8907
9735
|
var ROUTES2 = {
|
|
8908
9736
|
base: routeEthBase(),
|
|
@@ -8910,15 +9738,28 @@ var ROUTES2 = {
|
|
|
8910
9738
|
"erc20-nonbase": routeErc20NonBase2()
|
|
8911
9739
|
// AssetRouter.withdraw for non-base ERC-20s
|
|
8912
9740
|
};
|
|
8913
|
-
|
|
8914
|
-
|
|
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);
|
|
8915
9754
|
const { wrap: wrap7, toResult: toResult3 } = createErrorHandlers("withdrawals");
|
|
8916
9755
|
const tokensResource = tokens ?? createTokensResource(client);
|
|
8917
9756
|
const contractsResource = contracts ?? createContractsResource(client);
|
|
8918
9757
|
async function buildPlan(p) {
|
|
8919
|
-
const
|
|
8920
|
-
await
|
|
8921
|
-
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);
|
|
8922
9763
|
return {
|
|
8923
9764
|
route: ctx.route,
|
|
8924
9765
|
summary: {
|
|
@@ -9085,24 +9926,22 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9085
9926
|
if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
|
|
9086
9927
|
let pack;
|
|
9087
9928
|
try {
|
|
9088
|
-
pack = await svc.
|
|
9929
|
+
pack = await svc.fetchFinalization(l2TxHash);
|
|
9089
9930
|
} catch {
|
|
9090
9931
|
return { phase: "PENDING", l2TxHash };
|
|
9091
9932
|
}
|
|
9092
|
-
const key =
|
|
9093
|
-
chainIdL2: pack.params.chainId,
|
|
9094
|
-
l2BatchNumber: pack.params.l2BatchNumber,
|
|
9095
|
-
l2MessageIndex: pack.params.l2MessageIndex
|
|
9096
|
-
};
|
|
9933
|
+
const key = pack.key;
|
|
9097
9934
|
try {
|
|
9098
|
-
const
|
|
9099
|
-
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
|
+
}
|
|
9100
9940
|
} catch {
|
|
9101
9941
|
}
|
|
9102
|
-
const readiness = await svc.simulateFinalizeReadiness(pack.
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
return { phase: "PENDING", l2TxHash, key };
|
|
9942
|
+
const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
|
|
9943
|
+
const { phase, reason } = phaseFromReadiness(readiness);
|
|
9944
|
+
return { phase, reason, l2TxHash, key };
|
|
9106
9945
|
},
|
|
9107
9946
|
{
|
|
9108
9947
|
message: "Internal error while checking withdrawal status.",
|
|
@@ -9150,6 +9989,14 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9150
9989
|
const deadline = opts.timeoutMs ? Date.now() + opts.timeoutMs : void 0;
|
|
9151
9990
|
while (true) {
|
|
9152
9991
|
const s = await status(l2Hash);
|
|
9992
|
+
if (s.phase === "UNFINALIZABLE") {
|
|
9993
|
+
throw createError("STATE", {
|
|
9994
|
+
resource: "withdrawals",
|
|
9995
|
+
operation: OP_WITHDRAWALS.wait,
|
|
9996
|
+
message: "Withdrawal can never be finalized.",
|
|
9997
|
+
context: { l2TxHash: l2Hash, reason: s.reason }
|
|
9998
|
+
});
|
|
9999
|
+
}
|
|
9153
10000
|
if (opts.for === "ready") {
|
|
9154
10001
|
if (s.phase === "READY_TO_FINALIZE" || s.phase === "FINALIZED") return null;
|
|
9155
10002
|
} else {
|
|
@@ -9186,7 +10033,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9186
10033
|
async () => {
|
|
9187
10034
|
const pack = await (async () => {
|
|
9188
10035
|
try {
|
|
9189
|
-
return await svc.
|
|
10036
|
+
return await svc.fetchFinalization(l2TxHash);
|
|
9190
10037
|
} catch (e) {
|
|
9191
10038
|
throw createError("STATE", {
|
|
9192
10039
|
resource: "withdrawals",
|
|
@@ -9197,21 +10044,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9197
10044
|
});
|
|
9198
10045
|
}
|
|
9199
10046
|
})();
|
|
9200
|
-
const {
|
|
9201
|
-
const key = {
|
|
9202
|
-
chainIdL2: params.chainId,
|
|
9203
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
9204
|
-
l2MessageIndex: params.l2MessageIndex
|
|
9205
|
-
};
|
|
10047
|
+
const { finalization } = pack;
|
|
9206
10048
|
try {
|
|
9207
|
-
const
|
|
9208
|
-
if (
|
|
10049
|
+
const outcome = await svc.withdrawalOutcome(finalization);
|
|
10050
|
+
if (outcome === "finalized" || outcome === "failed") {
|
|
9209
10051
|
const statusNow = await status(l2TxHash);
|
|
9210
10052
|
return { status: statusNow };
|
|
9211
10053
|
}
|
|
9212
10054
|
} catch {
|
|
9213
10055
|
}
|
|
9214
|
-
const readiness = await svc.simulateFinalizeReadiness(
|
|
10056
|
+
const readiness = await svc.simulateFinalizeReadiness(finalization);
|
|
9215
10057
|
if (readiness.kind === "FINALIZED") {
|
|
9216
10058
|
const statusNow = await status(l2TxHash);
|
|
9217
10059
|
return { status: statusNow };
|
|
@@ -9225,7 +10067,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9225
10067
|
});
|
|
9226
10068
|
}
|
|
9227
10069
|
try {
|
|
9228
|
-
const tx = await svc.
|
|
10070
|
+
const tx = await svc.finalize(finalization);
|
|
9229
10071
|
finalizeCache.set(l2TxHash, tx.hash);
|
|
9230
10072
|
const rcpt = await tx.wait();
|
|
9231
10073
|
const statusNow = await status(l2TxHash);
|
|
@@ -9234,7 +10076,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9234
10076
|
const statusNow = await status(l2TxHash);
|
|
9235
10077
|
if (statusNow.phase === "FINALIZED") return { status: statusNow };
|
|
9236
10078
|
try {
|
|
9237
|
-
const again = await svc.simulateFinalizeReadiness(
|
|
10079
|
+
const again = await svc.simulateFinalizeReadiness(finalization);
|
|
9238
10080
|
if (again.kind === "NOT_READY") {
|
|
9239
10081
|
throw createError("STATE", {
|
|
9240
10082
|
resource: "withdrawals",
|
|
@@ -9293,77 +10135,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9293
10135
|
};
|
|
9294
10136
|
}
|
|
9295
10137
|
|
|
9296
|
-
// src/core/resources/interop/attributes/call.ts
|
|
9297
|
-
function createCallAttributes(codec) {
|
|
9298
|
-
const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
|
|
9299
|
-
const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
|
|
9300
|
-
return {
|
|
9301
|
-
indirectCall,
|
|
9302
|
-
interopCallValue
|
|
9303
|
-
};
|
|
9304
|
-
}
|
|
9305
|
-
|
|
9306
|
-
// src/core/resources/interop/attributes/bundle.ts
|
|
9307
|
-
function createBundleAttributes(codec) {
|
|
9308
|
-
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
9309
|
-
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
9310
|
-
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
9311
|
-
return {
|
|
9312
|
-
executionAddress,
|
|
9313
|
-
unbundlerAddress,
|
|
9314
|
-
useFixedFee
|
|
9315
|
-
};
|
|
9316
|
-
}
|
|
9317
|
-
|
|
9318
|
-
// src/core/resources/interop/attributes/resource.ts
|
|
9319
|
-
function createAttributesResource(codec) {
|
|
9320
|
-
return {
|
|
9321
|
-
call: createCallAttributes(codec),
|
|
9322
|
-
bundle: createBundleAttributes(codec)
|
|
9323
|
-
};
|
|
9324
|
-
}
|
|
9325
|
-
|
|
9326
|
-
// src/adapters/viem/resources/interop/attributes/resource.ts
|
|
9327
|
-
function getInteropAttributes(params, ctx) {
|
|
9328
|
-
const bundleAttributes = [];
|
|
9329
|
-
if (params.execution?.only) {
|
|
9330
|
-
bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
|
|
9331
|
-
}
|
|
9332
|
-
if (params.unbundling?.by) {
|
|
9333
|
-
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
9334
|
-
}
|
|
9335
|
-
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
9336
|
-
const callAttributes = params.actions.map((action) => {
|
|
9337
|
-
switch (action.type) {
|
|
9338
|
-
case "sendNative": {
|
|
9339
|
-
const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
|
|
9340
|
-
if (baseMatches) {
|
|
9341
|
-
return [ctx.attributes.call.interopCallValue(action.amount)];
|
|
9342
|
-
}
|
|
9343
|
-
return [ctx.attributes.call.indirectCall(action.amount)];
|
|
9344
|
-
}
|
|
9345
|
-
case "call":
|
|
9346
|
-
if (action.value && action.value > 0n) {
|
|
9347
|
-
return [ctx.attributes.call.interopCallValue(action.value)];
|
|
9348
|
-
}
|
|
9349
|
-
return [];
|
|
9350
|
-
case "sendErc20":
|
|
9351
|
-
return [ctx.attributes.call.indirectCall(0n)];
|
|
9352
|
-
default:
|
|
9353
|
-
assertNever(action);
|
|
9354
|
-
}
|
|
9355
|
-
});
|
|
9356
|
-
return { bundleAttributes, callAttributes };
|
|
9357
|
-
}
|
|
9358
|
-
function createViemAttributesResource() {
|
|
9359
|
-
const encode = (fn, args) => viem.encodeFunctionData({
|
|
9360
|
-
abi: IERC7786Attributes_default,
|
|
9361
|
-
functionName: fn,
|
|
9362
|
-
args
|
|
9363
|
-
});
|
|
9364
|
-
return createAttributesResource({ encode });
|
|
9365
|
-
}
|
|
9366
|
-
|
|
9367
10138
|
// src/core/types/flows/interop.ts
|
|
9368
10139
|
function isInteropMessageProof(obj) {
|
|
9369
10140
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -9540,24 +10311,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
|
|
|
9540
10311
|
}
|
|
9541
10312
|
};
|
|
9542
10313
|
}
|
|
9543
|
-
var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
|
|
9544
|
-
var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
|
|
9545
|
-
function formatInteropEvmChain(chainId) {
|
|
9546
|
-
const chainRef = viem.toBytes(viem.toHex(chainId));
|
|
9547
|
-
const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
|
|
9548
|
-
const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
|
|
9549
|
-
return viem.toHex(payload);
|
|
9550
|
-
}
|
|
9551
|
-
function formatInteropEvmAddress(address) {
|
|
9552
|
-
const normalized = viem.getAddress(address);
|
|
9553
|
-
const addrBytes = viem.toBytes(normalized);
|
|
9554
|
-
const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
|
|
9555
|
-
return viem.toHex(payload);
|
|
9556
|
-
}
|
|
9557
|
-
var interopCodec = {
|
|
9558
|
-
formatChain: formatInteropEvmChain,
|
|
9559
|
-
formatAddress: formatInteropEvmAddress
|
|
9560
|
-
};
|
|
9561
10314
|
function getErc20Tokens(params) {
|
|
9562
10315
|
const erc20Tokens = /* @__PURE__ */ new Map();
|
|
9563
10316
|
for (const action of params.actions) {
|
|
@@ -9739,7 +10492,7 @@ function routeIndirect() {
|
|
|
9739
10492
|
resolveErc20AssetIds(erc20Tokens, ctx),
|
|
9740
10493
|
buildFeeInfo(params, ctx, params.actions.length)
|
|
9741
10494
|
]);
|
|
9742
|
-
const
|
|
10495
|
+
const attributes2 = getInteropAttributes(params, ctx);
|
|
9743
10496
|
const starterData = await getStarterData(params, ctx, erc20AssetIds);
|
|
9744
10497
|
const bundle = buildIndirectBundle(
|
|
9745
10498
|
params,
|
|
@@ -9750,7 +10503,7 @@ function routeIndirect() {
|
|
|
9750
10503
|
l2NativeTokenVault: ctx.l2NativeTokenVault,
|
|
9751
10504
|
codec: interopCodec
|
|
9752
10505
|
},
|
|
9753
|
-
|
|
10506
|
+
attributes2,
|
|
9754
10507
|
starterData,
|
|
9755
10508
|
feeInfo
|
|
9756
10509
|
);
|
|
@@ -9870,7 +10623,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
|
|
|
9870
10623
|
assertProtocolVersion(srcChainId, srcProtocolVersion);
|
|
9871
10624
|
assertProtocolVersion(dstChainId, dstProtocolVersion);
|
|
9872
10625
|
}
|
|
9873
|
-
async function commonCtx3(dstPublicClient, params, client, tokens, contracts,
|
|
10626
|
+
async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes2) {
|
|
9874
10627
|
const sender = client.account.address;
|
|
9875
10628
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9876
10629
|
const dstChainId = BigInt(await dstPublicClient.getChainId());
|
|
@@ -9904,7 +10657,7 @@ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, at
|
|
|
9904
10657
|
l2AssetRouter,
|
|
9905
10658
|
l2NativeTokenVault,
|
|
9906
10659
|
baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
|
|
9907
|
-
attributes,
|
|
10660
|
+
attributes: attributes2,
|
|
9908
10661
|
gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
|
|
9909
10662
|
};
|
|
9910
10663
|
}
|
|
@@ -10604,7 +11357,7 @@ var ROUTES3 = {
|
|
|
10604
11357
|
direct: routeDirect(),
|
|
10605
11358
|
indirect: routeIndirect()
|
|
10606
11359
|
};
|
|
10607
|
-
function createInteropResource(client, config, tokens, contracts,
|
|
11360
|
+
function createInteropResource(client, config, tokens, contracts, attributes2) {
|
|
10608
11361
|
let gwProviderCache;
|
|
10609
11362
|
function requireConfig() {
|
|
10610
11363
|
if (!config)
|
|
@@ -10842,7 +11595,7 @@ function createViemSdk(client, options) {
|
|
|
10842
11595
|
const interop = createInteropResource(client, options?.interop, tokens, contracts);
|
|
10843
11596
|
return {
|
|
10844
11597
|
deposits: createDepositsResource(client, tokens, contracts),
|
|
10845
|
-
withdrawals: createWithdrawalsResource(client, tokens, contracts),
|
|
11598
|
+
withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
|
|
10846
11599
|
tokens,
|
|
10847
11600
|
contracts,
|
|
10848
11601
|
interop
|