@matterlabs/zksync-js 0.0.21 → 0.0.23
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 -8
- 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 +1194 -364
- 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/deposits/context.d.ts +2 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +3 -0
- 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 +1166 -370
- 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 -7
- 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 +1237 -383
- 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/deposits/context.d.ts +2 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +3 -0
- 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 +1191 -385
- 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-UEKFQAOS.js → chunk-2DDJFHHD.js} +304 -9
- package/dist/{chunk-MT4X5FEO.js → chunk-3IPSDGHO.js} +19 -1
- package/dist/{chunk-JSBMIT4S.js → chunk-4GPIHYVF.js} +1 -1
- package/dist/{chunk-SBGBYZJM.js → chunk-4M7VNYGC.js} +2 -2
- package/dist/{chunk-CK5UFAZK.js → chunk-6WIAMFIW.js} +37 -3
- package/dist/chunk-JJ523MOL.js +157 -0
- package/dist/{chunk-7GZDTLHX.js → chunk-NVOFHV3A.js} +666 -304
- package/dist/{chunk-LGTYM5XP.js → chunk-OEUDZFXH.js} +1 -1
- package/dist/{chunk-NJK325XV.js → chunk-TUN6NH5D.js} +2 -2
- package/dist/chunk-UMPAKZCQ.js +19 -0
- package/dist/{chunk-24TE2NNJ.js → chunk-URHDNDFN.js} +24 -4
- package/dist/{chunk-2CGBLD5H.js → chunk-V2TDNGI5.js} +642 -288
- package/dist/{chunk-IDXSGCGF.js → chunk-WPCZNITC.js} +63 -50
- package/dist/{chunk-TYYUG5GA.js → chunk-X2JJDQ4O.js} +1 -1
- package/dist/core/abi.d.ts +1 -0
- package/dist/core/adapters/interfaces.d.ts +2 -0
- package/dist/core/constants.cjs +18 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +17 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +504 -7
- 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/internal/abis/IL2AssetRouter.d.ts +0 -14
- package/dist/core/resources/deposits/priority.d.ts +30 -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 +320 -7
- 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
|
{
|
|
@@ -1901,13 +2189,6 @@ var IL2AssetRouterABI = [
|
|
|
1901
2189
|
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
1902
2190
|
stateMutability: "view"
|
|
1903
2191
|
},
|
|
1904
|
-
{
|
|
1905
|
-
type: "function",
|
|
1906
|
-
name: "l1TokenAddress",
|
|
1907
|
-
inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
|
|
1908
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
1909
|
-
stateMutability: "view"
|
|
1910
|
-
},
|
|
1911
2192
|
{
|
|
1912
2193
|
type: "function",
|
|
1913
2194
|
name: "l2TokenAddress",
|
|
@@ -3311,6 +3592,19 @@ var IERC7786AttributesABI = [
|
|
|
3311
3592
|
outputs: [],
|
|
3312
3593
|
stateMutability: "pure"
|
|
3313
3594
|
},
|
|
3595
|
+
{
|
|
3596
|
+
type: "function",
|
|
3597
|
+
name: "interopBundleSalt",
|
|
3598
|
+
inputs: [
|
|
3599
|
+
{
|
|
3600
|
+
name: "_salt",
|
|
3601
|
+
type: "bytes32",
|
|
3602
|
+
internalType: "bytes32"
|
|
3603
|
+
}
|
|
3604
|
+
],
|
|
3605
|
+
outputs: [],
|
|
3606
|
+
stateMutability: "pure"
|
|
3607
|
+
},
|
|
3314
3608
|
{
|
|
3315
3609
|
type: "function",
|
|
3316
3610
|
name: "unbundlerAddress",
|
|
@@ -5445,7 +5739,7 @@ function toGasOverrides(overrides) {
|
|
|
5445
5739
|
|
|
5446
5740
|
// src/adapters/viem/resources/deposits/context.ts
|
|
5447
5741
|
async function commonCtx(p, client, tokens, contracts) {
|
|
5448
|
-
const { bridgehub, l1AssetRouter } = await contracts.addresses();
|
|
5742
|
+
const { bridgehub, l1AssetRouter, l1NativeTokenVault } = await contracts.addresses();
|
|
5449
5743
|
const chainId = await client.l2.getChainId();
|
|
5450
5744
|
const sender = client.account.address;
|
|
5451
5745
|
const gasPerPubdata = p.gasPerPubdata ?? 800n;
|
|
@@ -5473,6 +5767,7 @@ async function commonCtx(p, client, tokens, contracts) {
|
|
|
5473
5767
|
baseTokenL1,
|
|
5474
5768
|
baseIsEth,
|
|
5475
5769
|
l1AssetRouter,
|
|
5770
|
+
l1NativeTokenVault,
|
|
5476
5771
|
route,
|
|
5477
5772
|
bridgehub,
|
|
5478
5773
|
chainIdL2: BigInt(chainId),
|
|
@@ -5493,6 +5788,7 @@ var L1_MESSENGER_ADDRESS = "0x0000000000000000000000000000000000008008";
|
|
|
5493
5788
|
var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
5494
5789
|
var L2_INTEROP_CENTER_ADDRESS = "0x000000000000000000000000000000000001000d";
|
|
5495
5790
|
var L2_INTEROP_ROOT_STORAGE_ADDRESS = "0x0000000000000000000000000000000000010008";
|
|
5791
|
+
var L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS = "0x0000000000000000000000000000000000010015";
|
|
5496
5792
|
var BUNDLE_IDENTIFIER = "0x01";
|
|
5497
5793
|
var TOPIC_L1_MESSAGE_SENT_NEW = k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
5498
5794
|
var TOPIC_L1_MESSAGE_SENT_LEG = k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
@@ -5512,6 +5808,14 @@ var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
|
|
|
5512
5808
|
var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
|
|
5513
5809
|
var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
|
|
5514
5810
|
var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
|
|
5811
|
+
var L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS = 21000n;
|
|
5812
|
+
var L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS = 40n;
|
|
5813
|
+
var L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS = 351n;
|
|
5814
|
+
var MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS = 1n << 35n;
|
|
5815
|
+
var L1_TX_NATIVE_PER_GAS = 100000000n;
|
|
5816
|
+
var ZKSYNC_OS_PRIORITY_TX_TYPE = "0x7f";
|
|
5817
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS = 140000n;
|
|
5818
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES = 300n;
|
|
5515
5819
|
|
|
5516
5820
|
// src/adapters/viem/resources/utils.ts
|
|
5517
5821
|
function encodeNativeTokenVaultTransferData(amount, receiver, token) {
|
|
@@ -5544,9 +5848,6 @@ function encodeSecondBridgeArgs(token, amount, l2Receiver) {
|
|
|
5544
5848
|
[token, amount, l2Receiver]
|
|
5545
5849
|
);
|
|
5546
5850
|
}
|
|
5547
|
-
function encodeSecondBridgeErc20Args(token, amount, l2Receiver) {
|
|
5548
|
-
return encodeSecondBridgeArgs(token, amount, l2Receiver);
|
|
5549
|
-
}
|
|
5550
5851
|
function encodeSecondBridgeEthArgs(amount, l2Receiver, ethToken = ETH_ADDRESS) {
|
|
5551
5852
|
return encodeSecondBridgeArgs(ethToken, amount, l2Receiver);
|
|
5552
5853
|
}
|
|
@@ -6011,7 +6312,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6011
6312
|
function wrap7(operation, fn, opts) {
|
|
6012
6313
|
return run("INTERNAL", operation, fn, opts);
|
|
6013
6314
|
}
|
|
6014
|
-
function
|
|
6315
|
+
function wrapAs11(kind, operation, fn, opts) {
|
|
6015
6316
|
return run(kind, operation, fn, opts);
|
|
6016
6317
|
}
|
|
6017
6318
|
async function toResult3(operation, fn, opts) {
|
|
@@ -6032,7 +6333,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6032
6333
|
return { ok: false, error: shaped };
|
|
6033
6334
|
}
|
|
6034
6335
|
}
|
|
6035
|
-
return { wrap: wrap7, wrapAs:
|
|
6336
|
+
return { wrap: wrap7, wrapAs: wrapAs11, toResult: toResult3 };
|
|
6036
6337
|
}
|
|
6037
6338
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
6038
6339
|
}
|
|
@@ -6302,6 +6603,68 @@ async function quoteL2Gas(input) {
|
|
|
6302
6603
|
}
|
|
6303
6604
|
}
|
|
6304
6605
|
|
|
6606
|
+
// src/core/resources/deposits/priority.ts
|
|
6607
|
+
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6608
|
+
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
6609
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
6610
|
+
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
6611
|
+
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
6612
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6613
|
+
function applyL1ToL2Alias(address) {
|
|
6614
|
+
return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
|
|
6615
|
+
}
|
|
6616
|
+
function derivePriorityTxGasBreakdown(input) {
|
|
6617
|
+
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
6618
|
+
const minBodyGas = maxBigInt2(
|
|
6619
|
+
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
6620
|
+
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
6621
|
+
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
6622
|
+
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
6623
|
+
L1_TX_MIN_L2_GAS_BASE
|
|
6624
|
+
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
6625
|
+
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
6626
|
+
const derivedBodyGas = minBodyGas;
|
|
6627
|
+
return {
|
|
6628
|
+
encodedLength: input.encodedLength,
|
|
6629
|
+
minBodyGas,
|
|
6630
|
+
overhead,
|
|
6631
|
+
derivedBodyGas,
|
|
6632
|
+
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
6633
|
+
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
6634
|
+
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
6635
|
+
};
|
|
6636
|
+
}
|
|
6637
|
+
function derivePriorityBodyGasEstimateCap(input) {
|
|
6638
|
+
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
6639
|
+
}
|
|
6640
|
+
function applyPriorityL2GasLimitBuffer(input) {
|
|
6641
|
+
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
6642
|
+
}
|
|
6643
|
+
function minimalPriorityTxL2Gas(input) {
|
|
6644
|
+
const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
|
|
6645
|
+
const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
|
|
6646
|
+
return maxBigInt2(intrinsic, pubdata);
|
|
6647
|
+
}
|
|
6648
|
+
function clampPriorityL2GasLimit(input) {
|
|
6649
|
+
return maxBigInt2(
|
|
6650
|
+
input.gasLimit,
|
|
6651
|
+
minimalPriorityTxL2Gas({
|
|
6652
|
+
calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
|
|
6653
|
+
gasPerPubdata: input.gasPerPubdata
|
|
6654
|
+
})
|
|
6655
|
+
);
|
|
6656
|
+
}
|
|
6657
|
+
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
6658
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
6659
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
6660
|
+
}
|
|
6661
|
+
const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
|
|
6662
|
+
return maxBigInt2(
|
|
6663
|
+
input.priorityFloorGasLimit,
|
|
6664
|
+
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
6665
|
+
);
|
|
6666
|
+
}
|
|
6667
|
+
|
|
6305
6668
|
// src/adapters/viem/estimator.ts
|
|
6306
6669
|
function toCoreTx(tx) {
|
|
6307
6670
|
return {
|
|
@@ -6353,6 +6716,20 @@ function viemToGasEstimator(client) {
|
|
|
6353
6716
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
6354
6717
|
});
|
|
6355
6718
|
},
|
|
6719
|
+
async estimatePriorityTxGas(tx) {
|
|
6720
|
+
const result = await client.request({
|
|
6721
|
+
method: "eth_estimateGas",
|
|
6722
|
+
params: [
|
|
6723
|
+
{
|
|
6724
|
+
from: tx.from,
|
|
6725
|
+
to: tx.to,
|
|
6726
|
+
data: tx.data,
|
|
6727
|
+
type: ZKSYNC_OS_PRIORITY_TX_TYPE
|
|
6728
|
+
}
|
|
6729
|
+
]
|
|
6730
|
+
});
|
|
6731
|
+
return BigInt(result);
|
|
6732
|
+
},
|
|
6356
6733
|
async estimateFeesPerGas() {
|
|
6357
6734
|
try {
|
|
6358
6735
|
const fees = await client.estimateFeesPerGas();
|
|
@@ -6386,6 +6763,14 @@ function viemToGasEstimator(client) {
|
|
|
6386
6763
|
|
|
6387
6764
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
6388
6765
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
6766
|
+
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
6767
|
+
if (!leg) return void 0;
|
|
6768
|
+
try {
|
|
6769
|
+
return await viemToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
|
|
6770
|
+
} catch {
|
|
6771
|
+
return void 0;
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6389
6774
|
async function quoteL1Gas2(input) {
|
|
6390
6775
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
6391
6776
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -6440,7 +6825,12 @@ async function determineNonBaseL2Gas(input) {
|
|
|
6440
6825
|
return quoteL2Gas2({
|
|
6441
6826
|
ctx,
|
|
6442
6827
|
route,
|
|
6443
|
-
overrideGasLimit:
|
|
6828
|
+
overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
|
|
6829
|
+
chainIdL2: ctx.chainIdL2,
|
|
6830
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6831
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
6832
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
|
|
6833
|
+
})
|
|
6444
6834
|
});
|
|
6445
6835
|
}
|
|
6446
6836
|
const modelTx = {
|
|
@@ -6477,6 +6867,7 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
6477
6867
|
knownL2Token: input.ctx.resolvedToken?.l2,
|
|
6478
6868
|
modelTx: input.modelTx,
|
|
6479
6869
|
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6870
|
+
priorityTxL2Leg: input.priorityTxL2Leg,
|
|
6480
6871
|
undeployedGasLimit: input.undeployedGasLimit
|
|
6481
6872
|
});
|
|
6482
6873
|
}
|
|
@@ -6530,40 +6921,6 @@ function buildFeeBreakdown(p) {
|
|
|
6530
6921
|
l2
|
|
6531
6922
|
};
|
|
6532
6923
|
}
|
|
6533
|
-
|
|
6534
|
-
// src/core/resources/deposits/priority.ts
|
|
6535
|
-
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6536
|
-
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
6537
|
-
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
6538
|
-
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
6539
|
-
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6540
|
-
function derivePriorityTxGasBreakdown(input) {
|
|
6541
|
-
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
6542
|
-
const minBodyGas = maxBigInt2(
|
|
6543
|
-
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
6544
|
-
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
6545
|
-
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
6546
|
-
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
6547
|
-
L1_TX_MIN_L2_GAS_BASE
|
|
6548
|
-
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
6549
|
-
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
6550
|
-
const derivedBodyGas = minBodyGas;
|
|
6551
|
-
return {
|
|
6552
|
-
encodedLength: input.encodedLength,
|
|
6553
|
-
minBodyGas,
|
|
6554
|
-
overhead,
|
|
6555
|
-
derivedBodyGas,
|
|
6556
|
-
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
6557
|
-
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
6558
|
-
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
6559
|
-
};
|
|
6560
|
-
}
|
|
6561
|
-
function derivePriorityBodyGasEstimateCap(input) {
|
|
6562
|
-
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
6563
|
-
}
|
|
6564
|
-
function applyPriorityL2GasLimitBuffer(input) {
|
|
6565
|
-
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
6566
|
-
}
|
|
6567
6924
|
var EMPTY_BYTES = "0x";
|
|
6568
6925
|
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
6569
6926
|
var L2_CANONICAL_TRANSACTION_PARAMETER = {
|
|
@@ -6640,9 +6997,13 @@ function routeEthDirect() {
|
|
|
6640
6997
|
l2Calldata,
|
|
6641
6998
|
gasPerPubdata: ctx.gasPerPubdata
|
|
6642
6999
|
});
|
|
6643
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
6644
|
-
|
|
6645
|
-
|
|
7000
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
7001
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7002
|
+
chainIdL2: ctx.chainIdL2,
|
|
7003
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7004
|
+
}),
|
|
7005
|
+
l2Calldata,
|
|
7006
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
6646
7007
|
});
|
|
6647
7008
|
const l2GasParams = await quoteL2Gas2({
|
|
6648
7009
|
ctx,
|
|
@@ -6802,26 +7163,18 @@ var ntvCodec = createNTVCodec({
|
|
|
6802
7163
|
keccak256: viem.keccak256
|
|
6803
7164
|
});
|
|
6804
7165
|
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
6809
|
-
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
6810
|
-
l1ChainId,
|
|
7166
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
7167
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
|
|
7168
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
6811
7169
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
6812
7170
|
input.token
|
|
6813
7171
|
);
|
|
6814
|
-
const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
|
|
6815
|
-
const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
|
|
6816
|
-
if (isL1Origin) {
|
|
6817
|
-
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
6818
|
-
}
|
|
6819
7172
|
const transferData = encodeNativeTokenVaultTransferData(
|
|
6820
7173
|
input.amount,
|
|
6821
7174
|
input.receiver,
|
|
6822
7175
|
input.token
|
|
6823
7176
|
);
|
|
6824
|
-
return encodeSecondBridgeDataV1(
|
|
7177
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
6825
7178
|
}
|
|
6826
7179
|
async function getPriorityGasModel(input) {
|
|
6827
7180
|
try {
|
|
@@ -6863,9 +7216,18 @@ async function getPriorityGasModel(input) {
|
|
|
6863
7216
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
6864
7217
|
});
|
|
6865
7218
|
const model = {
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
7219
|
+
priorityTxL2Leg: {
|
|
7220
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
7221
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
7222
|
+
data: l2Calldata
|
|
7223
|
+
},
|
|
7224
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7225
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7226
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
7227
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7228
|
+
}),
|
|
7229
|
+
l2Calldata,
|
|
7230
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
6869
7231
|
})
|
|
6870
7232
|
};
|
|
6871
7233
|
if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -6908,6 +7270,7 @@ function routeErc20NonBase() {
|
|
|
6908
7270
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
6909
7271
|
const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
|
|
6910
7272
|
const assetRouter = ctx.l1AssetRouter;
|
|
7273
|
+
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
6911
7274
|
const receiver = p.to ?? ctx.sender;
|
|
6912
7275
|
const secondBridgeCalldata = await wrapAs3(
|
|
6913
7276
|
"INTERNAL",
|
|
@@ -6937,6 +7300,7 @@ function routeErc20NonBase() {
|
|
|
6937
7300
|
ctx,
|
|
6938
7301
|
l1Token: p.token,
|
|
6939
7302
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
7303
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
6940
7304
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit,
|
|
6941
7305
|
modelTx: {
|
|
6942
7306
|
to: receiver,
|
|
@@ -6957,10 +7321,10 @@ function routeErc20NonBase() {
|
|
|
6957
7321
|
address: p.token,
|
|
6958
7322
|
abi: IERC20_default,
|
|
6959
7323
|
functionName: "allowance",
|
|
6960
|
-
args: [ctx.sender,
|
|
7324
|
+
args: [ctx.sender, nativeTokenVault]
|
|
6961
7325
|
}),
|
|
6962
7326
|
{
|
|
6963
|
-
ctx: { where: "erc20.allowance", token: p.token, spender:
|
|
7327
|
+
ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
|
|
6964
7328
|
message: "Failed to read deposit-token allowance."
|
|
6965
7329
|
}
|
|
6966
7330
|
);
|
|
@@ -6971,7 +7335,7 @@ function routeErc20NonBase() {
|
|
|
6971
7335
|
() => buildApprovalRequest({
|
|
6972
7336
|
ctx,
|
|
6973
7337
|
token: p.token,
|
|
6974
|
-
spender:
|
|
7338
|
+
spender: nativeTokenVault,
|
|
6975
7339
|
amount: p.amount
|
|
6976
7340
|
}),
|
|
6977
7341
|
{
|
|
@@ -6979,9 +7343,9 @@ function routeErc20NonBase() {
|
|
|
6979
7343
|
message: "Failed to simulate deposit token approve."
|
|
6980
7344
|
}
|
|
6981
7345
|
);
|
|
6982
|
-
approvals.push({ token: p.token, spender:
|
|
7346
|
+
approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
|
|
6983
7347
|
steps.push({
|
|
6984
|
-
key: `approve:${p.token}:${
|
|
7348
|
+
key: `approve:${p.token}:${nativeTokenVault}`,
|
|
6985
7349
|
kind: "approve",
|
|
6986
7350
|
description: `Approve deposit token for amount`,
|
|
6987
7351
|
tx: approveTx
|
|
@@ -6995,10 +7359,10 @@ function routeErc20NonBase() {
|
|
|
6995
7359
|
address: baseToken,
|
|
6996
7360
|
abi: IERC20_default,
|
|
6997
7361
|
functionName: "allowance",
|
|
6998
|
-
args: [ctx.sender,
|
|
7362
|
+
args: [ctx.sender, nativeTokenVault]
|
|
6999
7363
|
}),
|
|
7000
7364
|
{
|
|
7001
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender:
|
|
7365
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
|
|
7002
7366
|
message: "Failed to read base-token allowance."
|
|
7003
7367
|
}
|
|
7004
7368
|
);
|
|
@@ -7009,7 +7373,7 @@ function routeErc20NonBase() {
|
|
|
7009
7373
|
() => buildApprovalRequest({
|
|
7010
7374
|
ctx,
|
|
7011
7375
|
token: baseToken,
|
|
7012
|
-
spender:
|
|
7376
|
+
spender: nativeTokenVault,
|
|
7013
7377
|
amount: mintValue
|
|
7014
7378
|
}),
|
|
7015
7379
|
{
|
|
@@ -7017,9 +7381,9 @@ function routeErc20NonBase() {
|
|
|
7017
7381
|
message: "Failed to simulate base token approve."
|
|
7018
7382
|
}
|
|
7019
7383
|
);
|
|
7020
|
-
approvals.push({ token: baseToken, spender:
|
|
7384
|
+
approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
|
|
7021
7385
|
steps.push({
|
|
7022
|
-
key: `approve:${baseToken}:${
|
|
7386
|
+
key: `approve:${baseToken}:${nativeTokenVault}`,
|
|
7023
7387
|
kind: "approve",
|
|
7024
7388
|
description: `Approve base token for mintValue`,
|
|
7025
7389
|
tx: approveBaseTx
|
|
@@ -7158,9 +7522,18 @@ async function getPriorityGasModel2(input) {
|
|
|
7158
7522
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7159
7523
|
});
|
|
7160
7524
|
const model = {
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7525
|
+
priorityTxL2Leg: {
|
|
7526
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
7527
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
7528
|
+
data: l2Calldata
|
|
7529
|
+
},
|
|
7530
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7531
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7532
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
7533
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7534
|
+
}),
|
|
7535
|
+
l2Calldata,
|
|
7536
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7164
7537
|
})
|
|
7165
7538
|
};
|
|
7166
7539
|
if (input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -7235,6 +7608,7 @@ function routeEthNonBase() {
|
|
|
7235
7608
|
ctx,
|
|
7236
7609
|
modelTx: l2TxModel,
|
|
7237
7610
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
7611
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
7238
7612
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
7239
7613
|
});
|
|
7240
7614
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
@@ -7249,10 +7623,10 @@ function routeEthNonBase() {
|
|
|
7249
7623
|
address: baseToken,
|
|
7250
7624
|
abi: IERC20_default,
|
|
7251
7625
|
functionName: "allowance",
|
|
7252
|
-
args: [ctx.sender, ctx.
|
|
7626
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
7253
7627
|
}),
|
|
7254
7628
|
{
|
|
7255
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
7629
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
7256
7630
|
message: "Failed to read base-token allowance."
|
|
7257
7631
|
}
|
|
7258
7632
|
);
|
|
@@ -7264,7 +7638,7 @@ function routeEthNonBase() {
|
|
|
7264
7638
|
() => buildApprovalRequest({
|
|
7265
7639
|
ctx,
|
|
7266
7640
|
token: baseToken,
|
|
7267
|
-
spender: ctx.
|
|
7641
|
+
spender: ctx.l1NativeTokenVault,
|
|
7268
7642
|
amount: mintValue
|
|
7269
7643
|
}),
|
|
7270
7644
|
{
|
|
@@ -7272,9 +7646,9 @@ function routeEthNonBase() {
|
|
|
7272
7646
|
message: "Failed to simulate base-token approve."
|
|
7273
7647
|
}
|
|
7274
7648
|
);
|
|
7275
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
7649
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
7276
7650
|
steps.push({
|
|
7277
|
-
key: `approve:${baseToken}:${ctx.
|
|
7651
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
7278
7652
|
kind: "approve",
|
|
7279
7653
|
description: `Approve base token for fees (mintValue)`,
|
|
7280
7654
|
tx: approveTx
|
|
@@ -7427,9 +7801,13 @@ function routeErc20Base() {
|
|
|
7427
7801
|
l2Calldata,
|
|
7428
7802
|
gasPerPubdata: ctx.gasPerPubdata
|
|
7429
7803
|
});
|
|
7430
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
7431
|
-
|
|
7432
|
-
|
|
7804
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
7805
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7806
|
+
chainIdL2: ctx.chainIdL2,
|
|
7807
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7808
|
+
}),
|
|
7809
|
+
l2Calldata,
|
|
7810
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
7433
7811
|
});
|
|
7434
7812
|
const l2Gas = await quoteL2Gas2({
|
|
7435
7813
|
ctx,
|
|
@@ -7448,10 +7826,10 @@ function routeErc20Base() {
|
|
|
7448
7826
|
address: baseToken,
|
|
7449
7827
|
abi: IERC20_default,
|
|
7450
7828
|
functionName: "allowance",
|
|
7451
|
-
args: [ctx.sender, ctx.
|
|
7829
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
7452
7830
|
}),
|
|
7453
7831
|
{
|
|
7454
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
7832
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
7455
7833
|
message: "Failed to read base-token allowance."
|
|
7456
7834
|
}
|
|
7457
7835
|
);
|
|
@@ -7463,7 +7841,7 @@ function routeErc20Base() {
|
|
|
7463
7841
|
() => buildApprovalRequest({
|
|
7464
7842
|
ctx,
|
|
7465
7843
|
token: baseToken,
|
|
7466
|
-
spender: ctx.
|
|
7844
|
+
spender: ctx.l1NativeTokenVault,
|
|
7467
7845
|
amount: mintValue
|
|
7468
7846
|
}),
|
|
7469
7847
|
{
|
|
@@ -7471,9 +7849,9 @@ function routeErc20Base() {
|
|
|
7471
7849
|
message: "Failed to simulate ERC-20 approve."
|
|
7472
7850
|
}
|
|
7473
7851
|
);
|
|
7474
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
7852
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
7475
7853
|
steps.push({
|
|
7476
|
-
key: `approve:${baseToken}:${ctx.
|
|
7854
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
7477
7855
|
kind: "approve",
|
|
7478
7856
|
description: "Approve base token for mintValue",
|
|
7479
7857
|
tx: approveTx
|
|
@@ -7719,8 +8097,17 @@ function createTokensResource(client) {
|
|
|
7719
8097
|
const chainId = BigInt(await client.l2.getChainId());
|
|
7720
8098
|
return await client.baseToken(chainId);
|
|
7721
8099
|
}
|
|
7722
|
-
const {
|
|
7723
|
-
const
|
|
8100
|
+
const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
|
|
8101
|
+
const assetId = await l2NativeTokenVault.read.assetId([l2Token]);
|
|
8102
|
+
if (BigInt(assetId) === 0n) {
|
|
8103
|
+
throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
|
|
8104
|
+
}
|
|
8105
|
+
const l1Token = await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
8106
|
+
if (BigInt(l1Token) === 0n) {
|
|
8107
|
+
throw new Error(
|
|
8108
|
+
`Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
|
|
8109
|
+
);
|
|
8110
|
+
}
|
|
7724
8111
|
return l1Token;
|
|
7725
8112
|
});
|
|
7726
8113
|
}
|
|
@@ -8245,7 +8632,7 @@ function pickWithdrawRoute(args) {
|
|
|
8245
8632
|
}
|
|
8246
8633
|
|
|
8247
8634
|
// src/adapters/viem/resources/withdrawals/context.ts
|
|
8248
|
-
async function commonCtx2(p, client, tokens, contracts) {
|
|
8635
|
+
async function commonCtx2(p, client, tokens, contracts, protocol) {
|
|
8249
8636
|
const sender = client.account.address;
|
|
8250
8637
|
const {
|
|
8251
8638
|
bridgehub,
|
|
@@ -8253,9 +8640,11 @@ async function commonCtx2(p, client, tokens, contracts) {
|
|
|
8253
8640
|
l1Nullifier,
|
|
8254
8641
|
l2AssetRouter,
|
|
8255
8642
|
l2NativeTokenVault,
|
|
8256
|
-
l2BaseTokenSystem
|
|
8643
|
+
l2BaseTokenSystem,
|
|
8644
|
+
interopCenter
|
|
8257
8645
|
} = await contracts.addresses();
|
|
8258
8646
|
const chainIdL2 = BigInt(await client.l2.getChainId());
|
|
8647
|
+
const l1ChainId = BigInt(await client.l1.getChainId());
|
|
8259
8648
|
const resolvedToken = await tokens.resolve(p.token, { chain: "l2" });
|
|
8260
8649
|
const baseTokenAssetId = resolvedToken.baseTokenAssetId;
|
|
8261
8650
|
const baseTokenL1 = await tokens.l1TokenFromAssetId(baseTokenAssetId);
|
|
@@ -8277,6 +8666,9 @@ async function commonCtx2(p, client, tokens, contracts) {
|
|
|
8277
8666
|
l2AssetRouter,
|
|
8278
8667
|
l2NativeTokenVault,
|
|
8279
8668
|
l2BaseTokenSystem,
|
|
8669
|
+
interopCenter,
|
|
8670
|
+
protocol,
|
|
8671
|
+
l1ChainId,
|
|
8280
8672
|
baseIsEth,
|
|
8281
8673
|
gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
|
|
8282
8674
|
};
|
|
@@ -8586,6 +8978,285 @@ function routeErc20NonBase2() {
|
|
|
8586
8978
|
}
|
|
8587
8979
|
};
|
|
8588
8980
|
}
|
|
8981
|
+
var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
|
|
8982
|
+
var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
|
|
8983
|
+
function formatInteropEvmChain(chainId) {
|
|
8984
|
+
const chainRef = viem.toBytes(viem.toHex(chainId));
|
|
8985
|
+
const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
|
|
8986
|
+
const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
|
|
8987
|
+
return viem.toHex(payload);
|
|
8988
|
+
}
|
|
8989
|
+
function formatInteropEvmAddress(address) {
|
|
8990
|
+
const normalized = viem.getAddress(address);
|
|
8991
|
+
const addrBytes = viem.toBytes(normalized);
|
|
8992
|
+
const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
|
|
8993
|
+
return viem.toHex(payload);
|
|
8994
|
+
}
|
|
8995
|
+
var interopCodec = {
|
|
8996
|
+
formatChain: formatInteropEvmChain,
|
|
8997
|
+
formatAddress: formatInteropEvmAddress
|
|
8998
|
+
};
|
|
8999
|
+
|
|
9000
|
+
// src/core/resources/interop/attributes/call.ts
|
|
9001
|
+
function createCallAttributes(codec) {
|
|
9002
|
+
const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
|
|
9003
|
+
const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
|
|
9004
|
+
return {
|
|
9005
|
+
indirectCall,
|
|
9006
|
+
interopCallValue
|
|
9007
|
+
};
|
|
9008
|
+
}
|
|
9009
|
+
|
|
9010
|
+
// src/core/resources/interop/attributes/bundle.ts
|
|
9011
|
+
function createBundleAttributes(codec) {
|
|
9012
|
+
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
9013
|
+
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
9014
|
+
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
9015
|
+
const interopBundleSalt = (salt) => codec.encode("interopBundleSalt", [salt]);
|
|
9016
|
+
return {
|
|
9017
|
+
executionAddress,
|
|
9018
|
+
unbundlerAddress,
|
|
9019
|
+
useFixedFee,
|
|
9020
|
+
interopBundleSalt
|
|
9021
|
+
};
|
|
9022
|
+
}
|
|
9023
|
+
|
|
9024
|
+
// src/core/resources/interop/attributes/resource.ts
|
|
9025
|
+
function createAttributesResource(codec) {
|
|
9026
|
+
return {
|
|
9027
|
+
call: createCallAttributes(codec),
|
|
9028
|
+
bundle: createBundleAttributes(codec)
|
|
9029
|
+
};
|
|
9030
|
+
}
|
|
9031
|
+
|
|
9032
|
+
// src/adapters/viem/resources/interop/attributes/resource.ts
|
|
9033
|
+
function getInteropAttributes(params, ctx) {
|
|
9034
|
+
const bundleAttributes = [];
|
|
9035
|
+
if (params.execution?.only) {
|
|
9036
|
+
bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
|
|
9037
|
+
}
|
|
9038
|
+
if (params.unbundling?.by) {
|
|
9039
|
+
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
9040
|
+
}
|
|
9041
|
+
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
9042
|
+
const callAttributes = params.actions.map((action) => {
|
|
9043
|
+
switch (action.type) {
|
|
9044
|
+
case "sendNative": {
|
|
9045
|
+
const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
|
|
9046
|
+
if (baseMatches) {
|
|
9047
|
+
return [ctx.attributes.call.interopCallValue(action.amount)];
|
|
9048
|
+
}
|
|
9049
|
+
return [ctx.attributes.call.indirectCall(action.amount)];
|
|
9050
|
+
}
|
|
9051
|
+
case "call":
|
|
9052
|
+
if (action.value && action.value > 0n) {
|
|
9053
|
+
return [ctx.attributes.call.interopCallValue(action.value)];
|
|
9054
|
+
}
|
|
9055
|
+
return [];
|
|
9056
|
+
case "sendErc20":
|
|
9057
|
+
return [ctx.attributes.call.indirectCall(0n)];
|
|
9058
|
+
default:
|
|
9059
|
+
assertNever(action);
|
|
9060
|
+
}
|
|
9061
|
+
});
|
|
9062
|
+
return { bundleAttributes, callAttributes };
|
|
9063
|
+
}
|
|
9064
|
+
function createViemAttributesResource() {
|
|
9065
|
+
const encode = (fn, args) => viem.encodeFunctionData({
|
|
9066
|
+
abi: IERC7786Attributes_default,
|
|
9067
|
+
functionName: fn,
|
|
9068
|
+
args
|
|
9069
|
+
});
|
|
9070
|
+
return createAttributesResource({ encode });
|
|
9071
|
+
}
|
|
9072
|
+
|
|
9073
|
+
// src/core/resources/withdrawals/bundle.ts
|
|
9074
|
+
function buildWithdrawalBundle(input) {
|
|
9075
|
+
const {
|
|
9076
|
+
assetId,
|
|
9077
|
+
amount,
|
|
9078
|
+
l1Receiver,
|
|
9079
|
+
l2Token,
|
|
9080
|
+
isBaseToken,
|
|
9081
|
+
l1ChainId,
|
|
9082
|
+
l2AssetRouter,
|
|
9083
|
+
salt,
|
|
9084
|
+
codec,
|
|
9085
|
+
attributes: attributes2,
|
|
9086
|
+
transferData
|
|
9087
|
+
} = input;
|
|
9088
|
+
const burnData = transferData.encodeBridgeBurnData(amount, l1Receiver, l2Token);
|
|
9089
|
+
const depositData = transferData.encodeAssetRouterDepositData(assetId, burnData);
|
|
9090
|
+
const indirectCallMessageValue = isBaseToken ? amount : 0n;
|
|
9091
|
+
const starter = [
|
|
9092
|
+
codec.formatAddress(l2AssetRouter),
|
|
9093
|
+
depositData,
|
|
9094
|
+
[attributes2.indirectCall(indirectCallMessageValue), attributes2.interopCallValue(0n)]
|
|
9095
|
+
];
|
|
9096
|
+
return {
|
|
9097
|
+
destinationChain: codec.formatChain(l1ChainId),
|
|
9098
|
+
starters: [starter],
|
|
9099
|
+
// No `atomicBundle` attribute: L2 -> L1 withdrawals are non-atomic and are published to L1 as a
|
|
9100
|
+
// `BUNDLE_IDENTIFIER`-prefixed message, which is what the L1 handler proves inclusion of.
|
|
9101
|
+
bundleAttributes: [attributes2.interopBundleSalt(salt)],
|
|
9102
|
+
value: indirectCallMessageValue
|
|
9103
|
+
};
|
|
9104
|
+
}
|
|
9105
|
+
|
|
9106
|
+
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
9107
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
9108
|
+
var attributes = createViemAttributesResource();
|
|
9109
|
+
function saltFor(sender, nonce) {
|
|
9110
|
+
return viem.keccak256(
|
|
9111
|
+
viem.encodeAbiParameters(
|
|
9112
|
+
[
|
|
9113
|
+
{ type: "address", name: "sender" },
|
|
9114
|
+
{ type: "uint256", name: "nonce" }
|
|
9115
|
+
],
|
|
9116
|
+
[sender, BigInt(nonce)]
|
|
9117
|
+
)
|
|
9118
|
+
);
|
|
9119
|
+
}
|
|
9120
|
+
function routeInteropBundle() {
|
|
9121
|
+
return {
|
|
9122
|
+
async build(p, ctx) {
|
|
9123
|
+
const steps = [];
|
|
9124
|
+
const approvals = [];
|
|
9125
|
+
const isBaseToken = ctx.route === "base";
|
|
9126
|
+
const l1Receiver = p.to ?? ctx.sender;
|
|
9127
|
+
let assetId;
|
|
9128
|
+
let allowanceSufficient = true;
|
|
9129
|
+
if (isBaseToken) {
|
|
9130
|
+
assetId = ctx.baseTokenAssetId;
|
|
9131
|
+
} else {
|
|
9132
|
+
assetId = (await wrapAs9(
|
|
9133
|
+
"CONTRACT",
|
|
9134
|
+
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
9135
|
+
() => ctx.client.l2.simulateContract({
|
|
9136
|
+
address: ctx.l2NativeTokenVault,
|
|
9137
|
+
abi: L2NativeTokenVault_default,
|
|
9138
|
+
functionName: "ensureTokenIsRegistered",
|
|
9139
|
+
args: [p.token],
|
|
9140
|
+
account: ctx.client.account
|
|
9141
|
+
}),
|
|
9142
|
+
{
|
|
9143
|
+
ctx: { where: "L2NativeTokenVault.ensureTokenIsRegistered", token: p.token },
|
|
9144
|
+
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
9145
|
+
}
|
|
9146
|
+
)).result;
|
|
9147
|
+
const current = await wrapAs9(
|
|
9148
|
+
"CONTRACT",
|
|
9149
|
+
OP_WITHDRAWALS.erc20.allowance,
|
|
9150
|
+
() => ctx.client.l2.readContract({
|
|
9151
|
+
address: p.token,
|
|
9152
|
+
abi: IERC20_default,
|
|
9153
|
+
functionName: "allowance",
|
|
9154
|
+
args: [ctx.sender, ctx.l2NativeTokenVault],
|
|
9155
|
+
account: ctx.client.account
|
|
9156
|
+
}),
|
|
9157
|
+
{
|
|
9158
|
+
ctx: {
|
|
9159
|
+
where: "erc20.allowance",
|
|
9160
|
+
chain: "L2",
|
|
9161
|
+
token: p.token,
|
|
9162
|
+
spender: ctx.l2NativeTokenVault
|
|
9163
|
+
},
|
|
9164
|
+
message: "Failed to read L2 ERC-20 allowance."
|
|
9165
|
+
}
|
|
9166
|
+
);
|
|
9167
|
+
allowanceSufficient = current >= p.amount;
|
|
9168
|
+
if (!allowanceSufficient) {
|
|
9169
|
+
approvals.push({ token: p.token, spender: ctx.l2NativeTokenVault, amount: p.amount });
|
|
9170
|
+
const approveTxCandidate = {
|
|
9171
|
+
to: p.token,
|
|
9172
|
+
data: viem.encodeFunctionData({
|
|
9173
|
+
abi: IERC20_default,
|
|
9174
|
+
functionName: "approve",
|
|
9175
|
+
args: [ctx.l2NativeTokenVault, p.amount]
|
|
9176
|
+
}),
|
|
9177
|
+
value: 0n,
|
|
9178
|
+
from: ctx.sender
|
|
9179
|
+
};
|
|
9180
|
+
const approveGas = await quoteL2Gas4({ ctx, tx: approveTxCandidate });
|
|
9181
|
+
steps.push({
|
|
9182
|
+
key: `approve:l2:${p.token}:${ctx.l2NativeTokenVault}`,
|
|
9183
|
+
kind: "approve:l2",
|
|
9184
|
+
description: `Approve ${p.amount} to NativeTokenVault`,
|
|
9185
|
+
tx: {
|
|
9186
|
+
address: p.token,
|
|
9187
|
+
abi: IERC20_default,
|
|
9188
|
+
functionName: "approve",
|
|
9189
|
+
args: [ctx.l2NativeTokenVault, p.amount],
|
|
9190
|
+
account: ctx.client.account,
|
|
9191
|
+
...approveGas
|
|
9192
|
+
}
|
|
9193
|
+
});
|
|
9194
|
+
}
|
|
9195
|
+
}
|
|
9196
|
+
const nonce = await wrapAs9(
|
|
9197
|
+
"RPC",
|
|
9198
|
+
OP_WITHDRAWALS.prepare,
|
|
9199
|
+
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
9200
|
+
{
|
|
9201
|
+
ctx: { where: "l2.getTransactionCount", sender: ctx.sender },
|
|
9202
|
+
message: "Failed to read L2 nonce for the interop bundle salt."
|
|
9203
|
+
}
|
|
9204
|
+
);
|
|
9205
|
+
const bundle = buildWithdrawalBundle({
|
|
9206
|
+
assetId,
|
|
9207
|
+
amount: p.amount,
|
|
9208
|
+
l1Receiver,
|
|
9209
|
+
l2Token: isBaseToken ? FORMAL_ETH_ADDRESS : p.token,
|
|
9210
|
+
isBaseToken,
|
|
9211
|
+
l1ChainId: ctx.l1ChainId,
|
|
9212
|
+
l2AssetRouter: ctx.l2AssetRouter,
|
|
9213
|
+
salt: saltFor(ctx.sender, nonce),
|
|
9214
|
+
codec: interopCodec,
|
|
9215
|
+
attributes: {
|
|
9216
|
+
indirectCall: attributes.call.indirectCall,
|
|
9217
|
+
interopCallValue: attributes.call.interopCallValue,
|
|
9218
|
+
interopBundleSalt: attributes.bundle.interopBundleSalt
|
|
9219
|
+
},
|
|
9220
|
+
transferData: {
|
|
9221
|
+
encodeBridgeBurnData: encodeNativeTokenVaultTransferData,
|
|
9222
|
+
encodeAssetRouterDepositData: encodeSecondBridgeDataV1
|
|
9223
|
+
}
|
|
9224
|
+
});
|
|
9225
|
+
const sendArgs = [bundle.destinationChain, bundle.starters, bundle.bundleAttributes];
|
|
9226
|
+
const sendTxCandidate = {
|
|
9227
|
+
to: ctx.interopCenter,
|
|
9228
|
+
data: viem.encodeFunctionData({
|
|
9229
|
+
abi: IInteropCenter_default,
|
|
9230
|
+
functionName: "sendBundle",
|
|
9231
|
+
args: sendArgs
|
|
9232
|
+
}),
|
|
9233
|
+
value: bundle.value,
|
|
9234
|
+
from: ctx.sender
|
|
9235
|
+
};
|
|
9236
|
+
const sendGas = allowanceSufficient ? await quoteL2Gas4({ ctx, tx: sendTxCandidate }) : void 0;
|
|
9237
|
+
const sendTx = {
|
|
9238
|
+
address: ctx.interopCenter,
|
|
9239
|
+
abi: IInteropCenter_default,
|
|
9240
|
+
functionName: "sendBundle",
|
|
9241
|
+
args: sendArgs,
|
|
9242
|
+
account: ctx.client.account,
|
|
9243
|
+
value: bundle.value,
|
|
9244
|
+
...sendGas
|
|
9245
|
+
};
|
|
9246
|
+
steps.push({
|
|
9247
|
+
key: "interop-center:send-bundle",
|
|
9248
|
+
kind: "interop-center:send-bundle",
|
|
9249
|
+
description: "Burn on L2 & send L2\u2192L1 withdrawal bundle",
|
|
9250
|
+
tx: sendTx
|
|
9251
|
+
});
|
|
9252
|
+
const fees = buildFeeBreakdown2({
|
|
9253
|
+
feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
|
|
9254
|
+
l2Gas: sendGas
|
|
9255
|
+
});
|
|
9256
|
+
return { steps, approvals, fees };
|
|
9257
|
+
}
|
|
9258
|
+
};
|
|
9259
|
+
}
|
|
8589
9260
|
|
|
8590
9261
|
// src/core/utils/events.ts
|
|
8591
9262
|
function extractPreferAddress(opts) {
|
|
@@ -8620,21 +9291,145 @@ function l1MessageSentSender(log) {
|
|
|
8620
9291
|
if (!sender) {
|
|
8621
9292
|
throw new Error("L1MessageSent log has no valid sender topic.");
|
|
8622
9293
|
}
|
|
8623
|
-
return `0x${sender.toLowerCase()}`;
|
|
9294
|
+
return `0x${sender.toLowerCase()}`;
|
|
9295
|
+
}
|
|
9296
|
+
|
|
9297
|
+
// src/core/resources/withdrawals/logs.ts
|
|
9298
|
+
function messengerLogIndex(raw, opts) {
|
|
9299
|
+
const index = opts?.index;
|
|
9300
|
+
const messenger = (opts?.messenger).toLowerCase();
|
|
9301
|
+
const arr = Array.isArray(raw?.l2ToL1Logs) ? raw.l2ToL1Logs : [];
|
|
9302
|
+
const hits = arr.map((lg, i) => ({ i, lg })).filter(({ lg }) => (lg?.sender ?? "").toLowerCase() === messenger);
|
|
9303
|
+
if (!hits.length) {
|
|
9304
|
+
throw new Error("No L2->L1 messenger logs found in receipt.");
|
|
9305
|
+
}
|
|
9306
|
+
return (hits[index] ?? hits[0]).i;
|
|
9307
|
+
}
|
|
9308
|
+
function keccakHex(data) {
|
|
9309
|
+
return `0x${utils.bytesToHex(sha3.keccak_256(utils.hexToBytes(data.slice(2))))}`;
|
|
9310
|
+
}
|
|
9311
|
+
function stripBundleIdentifier(messageData) {
|
|
9312
|
+
const prefix = `0x${messageData.slice(2, 4)}`;
|
|
9313
|
+
if (prefix !== BUNDLE_IDENTIFIER) {
|
|
9314
|
+
throw createError("STATE", {
|
|
9315
|
+
resource: "withdrawals",
|
|
9316
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9317
|
+
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.",
|
|
9318
|
+
context: { prefix, expected: BUNDLE_IDENTIFIER }
|
|
9319
|
+
});
|
|
9320
|
+
}
|
|
9321
|
+
return `0x${messageData.slice(4)}`;
|
|
9322
|
+
}
|
|
9323
|
+
function parseBundleHashFromLogs(logs, interopCenter = L2_INTEROP_CENTER_ADDRESS) {
|
|
9324
|
+
const center = interopCenter.toLowerCase();
|
|
9325
|
+
for (const log of logs) {
|
|
9326
|
+
if (log.address?.toLowerCase() !== center) continue;
|
|
9327
|
+
if (log.topics?.length !== 1) continue;
|
|
9328
|
+
if (!log.data || (log.data.length - 2) / 64 < 3) continue;
|
|
9329
|
+
return `0x${log.data.slice(66, 130)}`;
|
|
9330
|
+
}
|
|
9331
|
+
return void 0;
|
|
9332
|
+
}
|
|
9333
|
+
function buildWithdrawalFinalization(input) {
|
|
9334
|
+
const { messageData, sourceChainId, txNumberInBatch, proof } = input;
|
|
9335
|
+
const bundle = stripBundleIdentifier(messageData);
|
|
9336
|
+
return {
|
|
9337
|
+
bundle,
|
|
9338
|
+
bundleHash: input.bundleHash ?? keccakHex(bundle),
|
|
9339
|
+
proof: {
|
|
9340
|
+
chainId: sourceChainId,
|
|
9341
|
+
l1BatchNumber: proof.batchNumber,
|
|
9342
|
+
l2MessageIndex: proof.id,
|
|
9343
|
+
message: {
|
|
9344
|
+
txNumberInBatch,
|
|
9345
|
+
sender: input.interopCenter ?? L2_INTEROP_CENTER_ADDRESS,
|
|
9346
|
+
data: messageData
|
|
9347
|
+
},
|
|
9348
|
+
proof: proof.proof
|
|
9349
|
+
}
|
|
9350
|
+
};
|
|
9351
|
+
}
|
|
9352
|
+
function classifyWithdrawalOutcome(bundleStatus, callStatus) {
|
|
9353
|
+
if (bundleStatus === 2 /* FullyExecuted */) return "finalized";
|
|
9354
|
+
if (bundleStatus !== 3 /* Unbundled */) return "pending";
|
|
9355
|
+
switch (callStatus) {
|
|
9356
|
+
case 1 /* Executed */:
|
|
9357
|
+
return "finalized";
|
|
9358
|
+
case 2 /* Cancelled */:
|
|
9359
|
+
return "failed";
|
|
9360
|
+
default:
|
|
9361
|
+
return "pending";
|
|
9362
|
+
}
|
|
8624
9363
|
}
|
|
8625
9364
|
|
|
8626
|
-
// src/core/resources/withdrawals/
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
const
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
9365
|
+
// src/core/resources/withdrawals/protocol.ts
|
|
9366
|
+
var MIN_INTEROP_WITHDRAWAL_MINOR = 32;
|
|
9367
|
+
function protocolFromVersion(version) {
|
|
9368
|
+
const [, minor] = version;
|
|
9369
|
+
return minor >= MIN_INTEROP_WITHDRAWAL_MINOR ? "interop-bundle" : "legacy-withdrawal";
|
|
9370
|
+
}
|
|
9371
|
+
async function detectWithdrawalProtocol(probes, override) {
|
|
9372
|
+
if (override) {
|
|
9373
|
+
return { protocol: override, source: { via: "override" } };
|
|
8634
9374
|
}
|
|
8635
|
-
|
|
9375
|
+
const version = await probes.protocolVersion();
|
|
9376
|
+
if (version) {
|
|
9377
|
+
return { protocol: protocolFromVersion(version), source: { via: "protocol-version", version } };
|
|
9378
|
+
}
|
|
9379
|
+
if (await probes.hasCodeAt(L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS)) {
|
|
9380
|
+
return {
|
|
9381
|
+
protocol: "interop-bundle",
|
|
9382
|
+
source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
|
|
9383
|
+
};
|
|
9384
|
+
}
|
|
9385
|
+
return {
|
|
9386
|
+
protocol: "legacy-withdrawal",
|
|
9387
|
+
source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
|
|
9388
|
+
};
|
|
8636
9389
|
}
|
|
8637
|
-
|
|
9390
|
+
|
|
9391
|
+
// src/adapters/viem/resources/withdrawals/services/protocol.ts
|
|
9392
|
+
function createWithdrawalProtocolService(client, override) {
|
|
9393
|
+
let cached;
|
|
9394
|
+
async function hasCodeAt(address) {
|
|
9395
|
+
try {
|
|
9396
|
+
const code = await client.l2.getCode({ address });
|
|
9397
|
+
return !!code && code !== "0x";
|
|
9398
|
+
} catch {
|
|
9399
|
+
return false;
|
|
9400
|
+
}
|
|
9401
|
+
}
|
|
9402
|
+
async function protocolVersion() {
|
|
9403
|
+
try {
|
|
9404
|
+
return await client.getChainProtocolVersion();
|
|
9405
|
+
} catch {
|
|
9406
|
+
return void 0;
|
|
9407
|
+
}
|
|
9408
|
+
}
|
|
9409
|
+
function detect() {
|
|
9410
|
+
cached ??= detectWithdrawalProtocol(
|
|
9411
|
+
{
|
|
9412
|
+
protocolVersion,
|
|
9413
|
+
hasCodeAt
|
|
9414
|
+
},
|
|
9415
|
+
override
|
|
9416
|
+
).catch((e) => {
|
|
9417
|
+
cached = void 0;
|
|
9418
|
+
throw e;
|
|
9419
|
+
});
|
|
9420
|
+
return cached;
|
|
9421
|
+
}
|
|
9422
|
+
return {
|
|
9423
|
+
detect,
|
|
9424
|
+
async protocol() {
|
|
9425
|
+
return (await detect()).protocol;
|
|
9426
|
+
},
|
|
9427
|
+
refresh() {
|
|
9428
|
+
cached = void 0;
|
|
9429
|
+
}
|
|
9430
|
+
};
|
|
9431
|
+
}
|
|
9432
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
8638
9433
|
var IL1NullifierMini = [
|
|
8639
9434
|
{
|
|
8640
9435
|
type: "function",
|
|
@@ -8648,183 +9443,279 @@ var IL1NullifierMini = [
|
|
|
8648
9443
|
outputs: [{ type: "bool" }]
|
|
8649
9444
|
}
|
|
8650
9445
|
];
|
|
8651
|
-
function createFinalizationServices(client) {
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
9446
|
+
function createFinalizationServices(client, protocolService = createWithdrawalProtocolService(client)) {
|
|
9447
|
+
async function finalizationTarget(protocol) {
|
|
9448
|
+
const { l1Nullifier } = await client.ensureAddresses();
|
|
9449
|
+
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
9450
|
+
return await wrapAs10(
|
|
9451
|
+
"CONTRACT",
|
|
9452
|
+
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9453
|
+
() => client.l1.readContract({
|
|
9454
|
+
address: l1Nullifier,
|
|
9455
|
+
abi: IL1NullifierV32_default,
|
|
9456
|
+
functionName: "l1InteropHandler"
|
|
9457
|
+
}),
|
|
9458
|
+
{
|
|
9459
|
+
ctx: { where: "L1Nullifier.l1InteropHandler", l1Nullifier },
|
|
9460
|
+
message: "Failed to resolve the L1 interop handler. The chain reports protocol v32+, but its L1Nullifier does not expose `l1InteropHandler()`."
|
|
9461
|
+
}
|
|
9462
|
+
);
|
|
9463
|
+
}
|
|
9464
|
+
async function fetchMessageAndProof(l2TxHash) {
|
|
9465
|
+
const raw = await wrapAs10(
|
|
9466
|
+
"RPC",
|
|
9467
|
+
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9468
|
+
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
9469
|
+
{
|
|
9470
|
+
ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
|
|
9471
|
+
message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
|
|
9472
|
+
}
|
|
9473
|
+
);
|
|
9474
|
+
if (!raw) {
|
|
9475
|
+
throw createError("STATE", {
|
|
9476
|
+
resource: "withdrawals",
|
|
9477
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9478
|
+
message: "L2 receipt not found.",
|
|
9479
|
+
context: { l2TxHash }
|
|
9480
|
+
});
|
|
9481
|
+
}
|
|
9482
|
+
const ev = await wrapAs10(
|
|
9483
|
+
"INTERNAL",
|
|
9484
|
+
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
9485
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
9486
|
+
() => Promise.resolve(findL1MessageSentLog(raw, { index: 0 })),
|
|
9487
|
+
{
|
|
9488
|
+
ctx: { l2TxHash, index: 0 },
|
|
9489
|
+
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
9490
|
+
}
|
|
9491
|
+
);
|
|
9492
|
+
const message = await wrapAs10(
|
|
9493
|
+
"INTERNAL",
|
|
9494
|
+
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9495
|
+
() => {
|
|
9496
|
+
const [decoded] = viem.decodeAbiParameters([{ type: "bytes" }], ev.data);
|
|
9497
|
+
return Promise.resolve(decoded);
|
|
9498
|
+
},
|
|
9499
|
+
{
|
|
9500
|
+
ctx: { where: "decode L1MessageSent", data: ev.data },
|
|
9501
|
+
message: "Failed to decode withdrawal message."
|
|
9502
|
+
}
|
|
9503
|
+
);
|
|
9504
|
+
const idx = await wrapAs10(
|
|
9505
|
+
"INTERNAL",
|
|
9506
|
+
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
9507
|
+
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
9508
|
+
{
|
|
9509
|
+
ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
|
|
9510
|
+
message: "Failed to derive messenger log index."
|
|
9511
|
+
}
|
|
9512
|
+
);
|
|
9513
|
+
const proof = await wrapAs10(
|
|
9514
|
+
"RPC",
|
|
9515
|
+
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
9516
|
+
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
9517
|
+
{
|
|
9518
|
+
ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
|
|
9519
|
+
message: "Failed to fetch L2\u2192L1 log proof."
|
|
9520
|
+
}
|
|
9521
|
+
);
|
|
9522
|
+
const chainId = await wrapAs10(
|
|
9523
|
+
"RPC",
|
|
9524
|
+
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
9525
|
+
() => client.l2.getChainId(),
|
|
9526
|
+
{ ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
|
|
9527
|
+
);
|
|
9528
|
+
const txNumberInBatch = Number(raw.transactionIndex ?? 0);
|
|
9529
|
+
const l2Sender = l1MessageSentSender(ev);
|
|
9530
|
+
return { raw, message, proof, chainId: BigInt(chainId), txNumberInBatch, l2Sender };
|
|
9531
|
+
}
|
|
9532
|
+
async function fetchFinalization(l2TxHash) {
|
|
9533
|
+
const protocol = await protocolService.protocol();
|
|
9534
|
+
const { raw, message, proof, chainId, txNumberInBatch, l2Sender } = await fetchMessageAndProof(l2TxHash);
|
|
9535
|
+
const target = await finalizationTarget(protocol);
|
|
9536
|
+
if (protocol === "legacy-withdrawal") {
|
|
9537
|
+
const params2 = {
|
|
9538
|
+
chainId,
|
|
9539
|
+
l2BatchNumber: proof.batchNumber,
|
|
9540
|
+
l2MessageIndex: proof.id,
|
|
9541
|
+
l2Sender,
|
|
9542
|
+
l2TxNumberInBatch: txNumberInBatch,
|
|
9543
|
+
message,
|
|
9544
|
+
merkleProof: proof.proof
|
|
9545
|
+
};
|
|
9546
|
+
return {
|
|
9547
|
+
target,
|
|
9548
|
+
finalization: { protocol, params: params2 },
|
|
9549
|
+
key: {
|
|
9550
|
+
chainIdL2: chainId,
|
|
9551
|
+
l2BatchNumber: proof.batchNumber,
|
|
9552
|
+
l2MessageIndex: proof.id
|
|
8661
9553
|
}
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
9554
|
+
};
|
|
9555
|
+
}
|
|
9556
|
+
const { interopCenter } = await client.ensureAddresses();
|
|
9557
|
+
const params = buildWithdrawalFinalization({
|
|
9558
|
+
messageData: message,
|
|
9559
|
+
sourceChainId: chainId,
|
|
9560
|
+
txNumberInBatch,
|
|
9561
|
+
proof: { batchNumber: proof.batchNumber, id: proof.id, proof: proof.proof },
|
|
9562
|
+
// Prefer the hash the InteropCenter emitted over recomputing it.
|
|
9563
|
+
bundleHash: parseBundleHashFromLogs(raw.logs ?? [], interopCenter),
|
|
9564
|
+
interopCenter
|
|
9565
|
+
});
|
|
9566
|
+
return {
|
|
9567
|
+
target,
|
|
9568
|
+
finalization: { protocol, params },
|
|
9569
|
+
key: {
|
|
9570
|
+
chainIdL2: chainId,
|
|
9571
|
+
l2BatchNumber: proof.batchNumber,
|
|
9572
|
+
l2MessageIndex: proof.id,
|
|
9573
|
+
bundleHash: params.bundleHash
|
|
8670
9574
|
}
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
9575
|
+
};
|
|
9576
|
+
}
|
|
9577
|
+
async function withdrawalOutcome(finalization) {
|
|
9578
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
9579
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
9580
|
+
const done = await wrapAs10(
|
|
9581
|
+
"RPC",
|
|
9582
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9583
|
+
() => client.l1.readContract({
|
|
9584
|
+
address: target,
|
|
9585
|
+
abi: IL1NullifierMini,
|
|
9586
|
+
functionName: "isWithdrawalFinalized",
|
|
9587
|
+
args: [
|
|
9588
|
+
finalization.params.chainId,
|
|
9589
|
+
finalization.params.l2BatchNumber,
|
|
9590
|
+
finalization.params.l2MessageIndex
|
|
9591
|
+
]
|
|
9592
|
+
}),
|
|
8676
9593
|
{
|
|
8677
|
-
ctx: {
|
|
8678
|
-
message: "Failed to
|
|
9594
|
+
ctx: { where: "isWithdrawalFinalized", params: finalization.params },
|
|
9595
|
+
message: "Failed to read finalization status."
|
|
8679
9596
|
}
|
|
8680
9597
|
);
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
9598
|
+
return done ? "finalized" : "pending";
|
|
9599
|
+
}
|
|
9600
|
+
const { bundleHash } = finalization.params;
|
|
9601
|
+
const status = Number(
|
|
9602
|
+
await wrapAs10(
|
|
9603
|
+
"RPC",
|
|
9604
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9605
|
+
() => client.l1.readContract({
|
|
9606
|
+
address: target,
|
|
9607
|
+
abi: IInteropHandler_default,
|
|
9608
|
+
functionName: "bundleStatus",
|
|
9609
|
+
args: [bundleHash]
|
|
9610
|
+
}),
|
|
8688
9611
|
{
|
|
8689
|
-
ctx: { where: "
|
|
8690
|
-
message: "Failed to
|
|
9612
|
+
ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
|
|
9613
|
+
message: "Failed to read bundle status."
|
|
8691
9614
|
}
|
|
8692
|
-
)
|
|
8693
|
-
|
|
9615
|
+
)
|
|
9616
|
+
);
|
|
9617
|
+
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
9618
|
+
const callStatus = Number(
|
|
9619
|
+
await wrapAs10(
|
|
8694
9620
|
"RPC",
|
|
8695
|
-
OP_WITHDRAWALS.finalize.
|
|
8696
|
-
() => client.
|
|
9621
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9622
|
+
() => client.l1.readContract({
|
|
9623
|
+
address: target,
|
|
9624
|
+
abi: IInteropHandler_default,
|
|
9625
|
+
functionName: "callStatus",
|
|
9626
|
+
args: [bundleHash, 0n]
|
|
9627
|
+
}),
|
|
8697
9628
|
{
|
|
8698
|
-
ctx: { where: "
|
|
8699
|
-
message: "Failed to
|
|
9629
|
+
ctx: { where: "L1InteropHandler.callStatus", bundleHash },
|
|
9630
|
+
message: "Failed to read bundle call status."
|
|
8700
9631
|
}
|
|
8701
|
-
)
|
|
8702
|
-
|
|
8703
|
-
|
|
9632
|
+
)
|
|
9633
|
+
);
|
|
9634
|
+
return classifyWithdrawalOutcome(status, callStatus);
|
|
9635
|
+
}
|
|
9636
|
+
async function isWithdrawalFinalized(finalization) {
|
|
9637
|
+
return await withdrawalOutcome(finalization) === "finalized";
|
|
9638
|
+
}
|
|
9639
|
+
return {
|
|
9640
|
+
fetchFinalization,
|
|
9641
|
+
isWithdrawalFinalized,
|
|
9642
|
+
withdrawalOutcome,
|
|
9643
|
+
async fetchFinalizeDepositParams(l2TxHash) {
|
|
9644
|
+
const resolved = await fetchFinalization(l2TxHash);
|
|
9645
|
+
if (resolved.finalization.protocol !== "legacy-withdrawal") {
|
|
9646
|
+
throw createError("VALIDATION", {
|
|
8704
9647
|
resource: "withdrawals",
|
|
8705
|
-
operation: OP_WITHDRAWALS.finalize.fetchParams.
|
|
8706
|
-
message: "
|
|
8707
|
-
context: { l2TxHash }
|
|
9648
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9649
|
+
message: "This chain finalizes withdrawals through the L1 interop handler; `finalizeDeposit` params do not exist. Use `fetchFinalization` instead.",
|
|
9650
|
+
context: { l2TxHash, protocol: resolved.finalization.protocol }
|
|
8708
9651
|
});
|
|
8709
9652
|
}
|
|
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 };
|
|
9653
|
+
return { params: resolved.finalization.params, nullifier: resolved.target };
|
|
8746
9654
|
},
|
|
8747
|
-
async simulateFinalizeReadiness(
|
|
8748
|
-
const
|
|
9655
|
+
async simulateFinalizeReadiness(finalization) {
|
|
9656
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
8749
9657
|
const done = await (async () => {
|
|
8750
9658
|
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;
|
|
9659
|
+
return await isWithdrawalFinalized(finalization);
|
|
8766
9660
|
} catch {
|
|
8767
9661
|
return false;
|
|
8768
9662
|
}
|
|
8769
9663
|
})();
|
|
8770
9664
|
if (done) return { kind: "FINALIZED" };
|
|
8771
9665
|
try {
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
9666
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
9667
|
+
await client.l1.simulateContract({
|
|
9668
|
+
address: target,
|
|
9669
|
+
abi: IL1Nullifier_default,
|
|
9670
|
+
functionName: "finalizeDeposit",
|
|
9671
|
+
args: [finalization.params],
|
|
9672
|
+
account: client.account
|
|
9673
|
+
});
|
|
9674
|
+
} else {
|
|
9675
|
+
await client.l1.simulateContract({
|
|
9676
|
+
address: target,
|
|
9677
|
+
abi: IInteropHandler_default,
|
|
9678
|
+
functionName: "executeBundle",
|
|
9679
|
+
args: [finalization.params.bundle, finalization.params.proof],
|
|
9680
|
+
account: client.account
|
|
9681
|
+
});
|
|
9682
|
+
}
|
|
8779
9683
|
return { kind: "READY" };
|
|
8780
9684
|
} catch (e) {
|
|
8781
9685
|
return classifyReadinessFromRevert(e);
|
|
8782
9686
|
}
|
|
8783
9687
|
},
|
|
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(
|
|
9688
|
+
async estimateFinalization(finalization) {
|
|
9689
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
9690
|
+
const gasLimit = await wrapAs10(
|
|
8804
9691
|
"RPC",
|
|
8805
9692
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8806
|
-
() => client.l1.estimateContractGas({
|
|
8807
|
-
address:
|
|
9693
|
+
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
9694
|
+
address: target,
|
|
8808
9695
|
abi: IL1Nullifier_default,
|
|
8809
9696
|
functionName: "finalizeDeposit",
|
|
8810
|
-
args: [params],
|
|
9697
|
+
args: [finalization.params],
|
|
9698
|
+
account: client.account
|
|
9699
|
+
}) : client.l1.estimateContractGas({
|
|
9700
|
+
address: target,
|
|
9701
|
+
abi: IInteropHandler_default,
|
|
9702
|
+
functionName: "executeBundle",
|
|
9703
|
+
args: [finalization.params.bundle, finalization.params.proof],
|
|
8811
9704
|
account: client.account
|
|
8812
9705
|
}),
|
|
8813
9706
|
{
|
|
8814
9707
|
ctx: {
|
|
8815
|
-
where: "estimateContractGas(
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
8819
|
-
l1Nullifier
|
|
9708
|
+
where: "estimateContractGas(finalize)",
|
|
9709
|
+
protocol: finalization.protocol,
|
|
9710
|
+
target
|
|
8820
9711
|
},
|
|
8821
|
-
message: "Failed to estimate gas for
|
|
9712
|
+
message: "Failed to estimate gas for withdrawal finalization."
|
|
8822
9713
|
}
|
|
8823
9714
|
);
|
|
8824
9715
|
let maxFeePerGas;
|
|
8825
9716
|
let maxPriorityFeePerGas;
|
|
8826
9717
|
try {
|
|
8827
|
-
const fee = await
|
|
9718
|
+
const fee = await wrapAs10(
|
|
8828
9719
|
"RPC",
|
|
8829
9720
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8830
9721
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -8843,32 +9734,34 @@ function createFinalizationServices(client) {
|
|
|
8843
9734
|
})();
|
|
8844
9735
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
8845
9736
|
} catch {
|
|
8846
|
-
const gasPrice = await
|
|
9737
|
+
const gasPrice = await wrapAs10(
|
|
8847
9738
|
"RPC",
|
|
8848
9739
|
OP_WITHDRAWALS.finalize.estimate,
|
|
8849
9740
|
() => client.l1.getGasPrice(),
|
|
8850
9741
|
{
|
|
8851
9742
|
ctx: { where: "getGasPrice" },
|
|
8852
|
-
message: "Failed to read gas price for
|
|
9743
|
+
message: "Failed to read gas price for withdrawal finalization."
|
|
8853
9744
|
}
|
|
8854
9745
|
);
|
|
8855
9746
|
maxFeePerGas = gasPrice;
|
|
8856
9747
|
maxPriorityFeePerGas = 0n;
|
|
8857
9748
|
}
|
|
8858
|
-
return {
|
|
8859
|
-
gasLimit,
|
|
8860
|
-
maxFeePerGas,
|
|
8861
|
-
maxPriorityFeePerGas
|
|
8862
|
-
};
|
|
9749
|
+
return { gasLimit, maxFeePerGas, maxPriorityFeePerGas };
|
|
8863
9750
|
},
|
|
8864
|
-
async
|
|
8865
|
-
const
|
|
9751
|
+
async finalize(finalization) {
|
|
9752
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
8866
9753
|
try {
|
|
8867
|
-
const hash = await client.l1Wallet.writeContract({
|
|
8868
|
-
address:
|
|
9754
|
+
const hash = finalization.protocol === "legacy-withdrawal" ? await client.l1Wallet.writeContract({
|
|
9755
|
+
address: target,
|
|
8869
9756
|
abi: IL1Nullifier_default,
|
|
8870
9757
|
functionName: "finalizeDeposit",
|
|
8871
|
-
args: [params],
|
|
9758
|
+
args: [finalization.params],
|
|
9759
|
+
account: client.account
|
|
9760
|
+
}) : await client.l1Wallet.writeContract({
|
|
9761
|
+
address: target,
|
|
9762
|
+
abi: IInteropHandler_default,
|
|
9763
|
+
functionName: "executeBundle",
|
|
9764
|
+
args: [finalization.params.bundle, finalization.params.proof],
|
|
8872
9765
|
account: client.account
|
|
8873
9766
|
});
|
|
8874
9767
|
return {
|
|
@@ -8882,8 +9775,8 @@ function createFinalizationServices(client) {
|
|
|
8882
9775
|
{
|
|
8883
9776
|
resource: "withdrawals",
|
|
8884
9777
|
operation: OP_WITHDRAWALS.finalize.wait,
|
|
8885
|
-
message: "Failed while waiting for
|
|
8886
|
-
context: { txHash: hash }
|
|
9778
|
+
message: "Failed while waiting for the withdrawal finalization transaction.",
|
|
9779
|
+
context: { txHash: hash, protocol: finalization.protocol }
|
|
8887
9780
|
},
|
|
8888
9781
|
e
|
|
8889
9782
|
);
|
|
@@ -8896,13 +9789,8 @@ function createFinalizationServices(client) {
|
|
|
8896
9789
|
{
|
|
8897
9790
|
resource: "withdrawals",
|
|
8898
9791
|
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
|
-
}
|
|
9792
|
+
message: "Failed to send the withdrawal finalization transaction.",
|
|
9793
|
+
context: { protocol: finalization.protocol, target }
|
|
8906
9794
|
},
|
|
8907
9795
|
e
|
|
8908
9796
|
);
|
|
@@ -8935,15 +9823,28 @@ var ROUTES2 = {
|
|
|
8935
9823
|
"erc20-nonbase": routeErc20NonBase2()
|
|
8936
9824
|
// AssetRouter.withdraw for non-base ERC-20s
|
|
8937
9825
|
};
|
|
8938
|
-
|
|
8939
|
-
|
|
9826
|
+
var INTEROP_ROUTES = {
|
|
9827
|
+
base: routeInteropBundle(),
|
|
9828
|
+
"erc20-nonbase": routeInteropBundle()
|
|
9829
|
+
};
|
|
9830
|
+
function routeStrategy(protocol, route) {
|
|
9831
|
+
return protocol === "interop-bundle" ? INTEROP_ROUTES[route] : ROUTES2[route];
|
|
9832
|
+
}
|
|
9833
|
+
function createWithdrawalsResource(client, tokens, contracts, options) {
|
|
9834
|
+
const protocolService = createWithdrawalProtocolService(
|
|
9835
|
+
client,
|
|
9836
|
+
options?.protocol
|
|
9837
|
+
);
|
|
9838
|
+
const svc = createFinalizationServices(client, protocolService);
|
|
8940
9839
|
const { wrap: wrap7, toResult: toResult3 } = createErrorHandlers("withdrawals");
|
|
8941
9840
|
const tokensResource = tokens ?? createTokensResource(client);
|
|
8942
9841
|
const contractsResource = contracts ?? createContractsResource(client);
|
|
8943
9842
|
async function buildPlan(p) {
|
|
8944
|
-
const
|
|
8945
|
-
await
|
|
8946
|
-
const
|
|
9843
|
+
const protocol = await protocolService.protocol();
|
|
9844
|
+
const ctx = await commonCtx2(p, client, tokensResource, contractsResource, protocol);
|
|
9845
|
+
const strategy = routeStrategy(protocol, ctx.route);
|
|
9846
|
+
await strategy.preflight?.(p, ctx);
|
|
9847
|
+
const { steps, approvals, fees } = await strategy.build(p, ctx);
|
|
8947
9848
|
return {
|
|
8948
9849
|
route: ctx.route,
|
|
8949
9850
|
summary: {
|
|
@@ -9110,21 +10011,20 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9110
10011
|
if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
|
|
9111
10012
|
let pack;
|
|
9112
10013
|
try {
|
|
9113
|
-
pack = await svc.
|
|
10014
|
+
pack = await svc.fetchFinalization(l2TxHash);
|
|
9114
10015
|
} catch {
|
|
9115
10016
|
return { phase: "PENDING", l2TxHash };
|
|
9116
10017
|
}
|
|
9117
|
-
const key =
|
|
9118
|
-
chainIdL2: pack.params.chainId,
|
|
9119
|
-
l2BatchNumber: pack.params.l2BatchNumber,
|
|
9120
|
-
l2MessageIndex: pack.params.l2MessageIndex
|
|
9121
|
-
};
|
|
10018
|
+
const key = pack.key;
|
|
9122
10019
|
try {
|
|
9123
|
-
const
|
|
9124
|
-
if (
|
|
10020
|
+
const outcome = await svc.withdrawalOutcome(pack.finalization);
|
|
10021
|
+
if (outcome === "finalized") return { phase: "FINALIZED", l2TxHash, key };
|
|
10022
|
+
if (outcome === "failed") {
|
|
10023
|
+
return { phase: "UNFINALIZABLE", l2TxHash, key, reason: "bundle-cancelled" };
|
|
10024
|
+
}
|
|
9125
10025
|
} catch {
|
|
9126
10026
|
}
|
|
9127
|
-
const readiness = await svc.simulateFinalizeReadiness(pack.
|
|
10027
|
+
const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
|
|
9128
10028
|
const { phase, reason } = phaseFromReadiness(readiness);
|
|
9129
10029
|
return { phase, reason, l2TxHash, key };
|
|
9130
10030
|
},
|
|
@@ -9218,7 +10118,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9218
10118
|
async () => {
|
|
9219
10119
|
const pack = await (async () => {
|
|
9220
10120
|
try {
|
|
9221
|
-
return await svc.
|
|
10121
|
+
return await svc.fetchFinalization(l2TxHash);
|
|
9222
10122
|
} catch (e) {
|
|
9223
10123
|
throw createError("STATE", {
|
|
9224
10124
|
resource: "withdrawals",
|
|
@@ -9229,21 +10129,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9229
10129
|
});
|
|
9230
10130
|
}
|
|
9231
10131
|
})();
|
|
9232
|
-
const {
|
|
9233
|
-
const key = {
|
|
9234
|
-
chainIdL2: params.chainId,
|
|
9235
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
9236
|
-
l2MessageIndex: params.l2MessageIndex
|
|
9237
|
-
};
|
|
10132
|
+
const { finalization } = pack;
|
|
9238
10133
|
try {
|
|
9239
|
-
const
|
|
9240
|
-
if (
|
|
10134
|
+
const outcome = await svc.withdrawalOutcome(finalization);
|
|
10135
|
+
if (outcome === "finalized" || outcome === "failed") {
|
|
9241
10136
|
const statusNow = await status(l2TxHash);
|
|
9242
10137
|
return { status: statusNow };
|
|
9243
10138
|
}
|
|
9244
10139
|
} catch {
|
|
9245
10140
|
}
|
|
9246
|
-
const readiness = await svc.simulateFinalizeReadiness(
|
|
10141
|
+
const readiness = await svc.simulateFinalizeReadiness(finalization);
|
|
9247
10142
|
if (readiness.kind === "FINALIZED") {
|
|
9248
10143
|
const statusNow = await status(l2TxHash);
|
|
9249
10144
|
return { status: statusNow };
|
|
@@ -9257,7 +10152,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9257
10152
|
});
|
|
9258
10153
|
}
|
|
9259
10154
|
try {
|
|
9260
|
-
const tx = await svc.
|
|
10155
|
+
const tx = await svc.finalize(finalization);
|
|
9261
10156
|
finalizeCache.set(l2TxHash, tx.hash);
|
|
9262
10157
|
const rcpt = await tx.wait();
|
|
9263
10158
|
const statusNow = await status(l2TxHash);
|
|
@@ -9266,7 +10161,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9266
10161
|
const statusNow = await status(l2TxHash);
|
|
9267
10162
|
if (statusNow.phase === "FINALIZED") return { status: statusNow };
|
|
9268
10163
|
try {
|
|
9269
|
-
const again = await svc.simulateFinalizeReadiness(
|
|
10164
|
+
const again = await svc.simulateFinalizeReadiness(finalization);
|
|
9270
10165
|
if (again.kind === "NOT_READY") {
|
|
9271
10166
|
throw createError("STATE", {
|
|
9272
10167
|
resource: "withdrawals",
|
|
@@ -9325,77 +10220,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
9325
10220
|
};
|
|
9326
10221
|
}
|
|
9327
10222
|
|
|
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
10223
|
// src/core/types/flows/interop.ts
|
|
9400
10224
|
function isInteropMessageProof(obj) {
|
|
9401
10225
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -9572,24 +10396,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
|
|
|
9572
10396
|
}
|
|
9573
10397
|
};
|
|
9574
10398
|
}
|
|
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
10399
|
function getErc20Tokens(params) {
|
|
9594
10400
|
const erc20Tokens = /* @__PURE__ */ new Map();
|
|
9595
10401
|
for (const action of params.actions) {
|
|
@@ -9771,7 +10577,7 @@ function routeIndirect() {
|
|
|
9771
10577
|
resolveErc20AssetIds(erc20Tokens, ctx),
|
|
9772
10578
|
buildFeeInfo(params, ctx, params.actions.length)
|
|
9773
10579
|
]);
|
|
9774
|
-
const
|
|
10580
|
+
const attributes2 = getInteropAttributes(params, ctx);
|
|
9775
10581
|
const starterData = await getStarterData(params, ctx, erc20AssetIds);
|
|
9776
10582
|
const bundle = buildIndirectBundle(
|
|
9777
10583
|
params,
|
|
@@ -9782,7 +10588,7 @@ function routeIndirect() {
|
|
|
9782
10588
|
l2NativeTokenVault: ctx.l2NativeTokenVault,
|
|
9783
10589
|
codec: interopCodec
|
|
9784
10590
|
},
|
|
9785
|
-
|
|
10591
|
+
attributes2,
|
|
9786
10592
|
starterData,
|
|
9787
10593
|
feeInfo
|
|
9788
10594
|
);
|
|
@@ -9902,7 +10708,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
|
|
|
9902
10708
|
assertProtocolVersion(srcChainId, srcProtocolVersion);
|
|
9903
10709
|
assertProtocolVersion(dstChainId, dstProtocolVersion);
|
|
9904
10710
|
}
|
|
9905
|
-
async function commonCtx3(dstPublicClient, params, client, tokens, contracts,
|
|
10711
|
+
async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes2) {
|
|
9906
10712
|
const sender = client.account.address;
|
|
9907
10713
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9908
10714
|
const dstChainId = BigInt(await dstPublicClient.getChainId());
|
|
@@ -9936,7 +10742,7 @@ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, at
|
|
|
9936
10742
|
l2AssetRouter,
|
|
9937
10743
|
l2NativeTokenVault,
|
|
9938
10744
|
baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
|
|
9939
|
-
attributes,
|
|
10745
|
+
attributes: attributes2,
|
|
9940
10746
|
gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
|
|
9941
10747
|
};
|
|
9942
10748
|
}
|
|
@@ -10636,7 +11442,7 @@ var ROUTES3 = {
|
|
|
10636
11442
|
direct: routeDirect(),
|
|
10637
11443
|
indirect: routeIndirect()
|
|
10638
11444
|
};
|
|
10639
|
-
function createInteropResource(client, config, tokens, contracts,
|
|
11445
|
+
function createInteropResource(client, config, tokens, contracts, attributes2) {
|
|
10640
11446
|
let gwProviderCache;
|
|
10641
11447
|
function requireConfig() {
|
|
10642
11448
|
if (!config)
|
|
@@ -10874,7 +11680,7 @@ function createViemSdk(client, options) {
|
|
|
10874
11680
|
const interop = createInteropResource(client, options?.interop, tokens, contracts);
|
|
10875
11681
|
return {
|
|
10876
11682
|
deposits: createDepositsResource(client, tokens, contracts),
|
|
10877
|
-
withdrawals: createWithdrawalsResource(client, tokens, contracts),
|
|
11683
|
+
withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
|
|
10878
11684
|
tokens,
|
|
10879
11685
|
contracts,
|
|
10880
11686
|
interop
|