@matterlabs/zksync-js 0.0.1

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.
Files changed (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/dist/adapters/ethers/client.cjs +4548 -0
  4. package/dist/adapters/ethers/client.cjs.map +1 -0
  5. package/dist/adapters/ethers/client.d.ts +61 -0
  6. package/dist/adapters/ethers/client.js +5 -0
  7. package/dist/adapters/ethers/errors/error-ops.d.ts +20 -0
  8. package/dist/adapters/ethers/errors/revert.d.ts +28 -0
  9. package/dist/adapters/ethers/index.cjs +7537 -0
  10. package/dist/adapters/ethers/index.cjs.map +1 -0
  11. package/dist/adapters/ethers/index.d.ts +12 -0
  12. package/dist/adapters/ethers/index.js +8 -0
  13. package/dist/adapters/ethers/resources/deposits/context.d.ts +27 -0
  14. package/dist/adapters/ethers/resources/deposits/index.d.ts +46 -0
  15. package/dist/adapters/ethers/resources/deposits/routes/erc20-base.d.ts +2 -0
  16. package/dist/adapters/ethers/resources/deposits/routes/erc20-nonbase.d.ts +2 -0
  17. package/dist/adapters/ethers/resources/deposits/routes/eth-nonbase.d.ts +2 -0
  18. package/dist/adapters/ethers/resources/deposits/routes/eth.d.ts +2 -0
  19. package/dist/adapters/ethers/resources/deposits/routes/types.d.ts +10 -0
  20. package/dist/adapters/ethers/resources/deposits/services/verification.d.ts +9 -0
  21. package/dist/adapters/ethers/resources/token-info.d.ts +31 -0
  22. package/dist/adapters/ethers/resources/utils.d.ts +39 -0
  23. package/dist/adapters/ethers/resources/withdrawals/context.d.ts +19 -0
  24. package/dist/adapters/ethers/resources/withdrawals/index.d.ts +56 -0
  25. package/dist/adapters/ethers/resources/withdrawals/routes/erc20-nonbase.d.ts +2 -0
  26. package/dist/adapters/ethers/resources/withdrawals/routes/eth-nonbase.d.ts +2 -0
  27. package/dist/adapters/ethers/resources/withdrawals/routes/eth.d.ts +2 -0
  28. package/dist/adapters/ethers/resources/withdrawals/routes/types.d.ts +18 -0
  29. package/dist/adapters/ethers/resources/withdrawals/services/finalization.d.ts +33 -0
  30. package/dist/adapters/ethers/rpc.d.ts +4 -0
  31. package/dist/adapters/ethers/sdk.cjs +6245 -0
  32. package/dist/adapters/ethers/sdk.cjs.map +1 -0
  33. package/dist/adapters/ethers/sdk.d.ts +29 -0
  34. package/dist/adapters/ethers/sdk.js +6 -0
  35. package/dist/adapters/ethers/typechain/IAssetRouterBase.d.ts +198 -0
  36. package/dist/adapters/ethers/typechain/IBridgehub.d.ts +731 -0
  37. package/dist/adapters/ethers/typechain/IERC20.d.ts +108 -0
  38. package/dist/adapters/ethers/typechain/IL1AssetRouter.d.ts +570 -0
  39. package/dist/adapters/ethers/typechain/IL1NativeTokenVault.d.ts +154 -0
  40. package/dist/adapters/ethers/typechain/IL1Nullifier.d.ts +305 -0
  41. package/dist/adapters/ethers/typechain/IL2AssetRouter.d.ts +288 -0
  42. package/dist/adapters/ethers/typechain/IL2NativeTokenVault.d.ts +380 -0
  43. package/dist/adapters/ethers/typechain/common.d.ts +46 -0
  44. package/dist/adapters/ethers/typechain/factories/IAssetRouterBase__factory.d.ts +203 -0
  45. package/dist/adapters/ethers/typechain/factories/IBridgehub__factory.d.ts +998 -0
  46. package/dist/adapters/ethers/typechain/factories/IERC20__factory.d.ts +177 -0
  47. package/dist/adapters/ethers/typechain/factories/IL1AssetRouter__factory.d.ts +666 -0
  48. package/dist/adapters/ethers/typechain/factories/IL1NativeTokenVault__factory.d.ts +234 -0
  49. package/dist/adapters/ethers/typechain/factories/IL1Nullifier__factory.d.ts +382 -0
  50. package/dist/adapters/ethers/typechain/factories/IL2AssetRouter__factory.d.ts +327 -0
  51. package/dist/adapters/ethers/typechain/factories/IL2NativeTokenVault__factory.d.ts +696 -0
  52. package/dist/adapters/ethers/typechain/factories/index.d.ts +8 -0
  53. package/dist/adapters/ethers/typechain/index.d.ts +17 -0
  54. package/dist/adapters/viem/client.cjs +4534 -0
  55. package/dist/adapters/viem/client.cjs.map +1 -0
  56. package/dist/adapters/viem/client.d.ts +44 -0
  57. package/dist/adapters/viem/client.js +5 -0
  58. package/dist/adapters/viem/errors/error-ops.d.ts +20 -0
  59. package/dist/adapters/viem/errors/revert.d.ts +25 -0
  60. package/dist/adapters/viem/index.cjs +7772 -0
  61. package/dist/adapters/viem/index.cjs.map +1 -0
  62. package/dist/adapters/viem/index.d.ts +11 -0
  63. package/dist/adapters/viem/index.js +8 -0
  64. package/dist/adapters/viem/resources/deposits/context.d.ts +27 -0
  65. package/dist/adapters/viem/resources/deposits/index.d.ts +46 -0
  66. package/dist/adapters/viem/resources/deposits/routes/erc20-base.d.ts +2 -0
  67. package/dist/adapters/viem/resources/deposits/routes/erc20-nonbase.d.ts +2 -0
  68. package/dist/adapters/viem/resources/deposits/routes/eth-nonbase.d.ts +2 -0
  69. package/dist/adapters/viem/resources/deposits/routes/eth.d.ts +2 -0
  70. package/dist/adapters/viem/resources/deposits/routes/types.d.ts +20 -0
  71. package/dist/adapters/viem/resources/deposits/services/verification.d.ts +7 -0
  72. package/dist/adapters/viem/resources/token-info.d.ts +34 -0
  73. package/dist/adapters/viem/resources/utils.d.ts +42 -0
  74. package/dist/adapters/viem/resources/withdrawals/context.d.ts +22 -0
  75. package/dist/adapters/viem/resources/withdrawals/index.d.ts +56 -0
  76. package/dist/adapters/viem/resources/withdrawals/routes/erc20-nonbase.d.ts +2 -0
  77. package/dist/adapters/viem/resources/withdrawals/routes/eth-nonbase.d.ts +2 -0
  78. package/dist/adapters/viem/resources/withdrawals/routes/eth.d.ts +2 -0
  79. package/dist/adapters/viem/resources/withdrawals/routes/types.d.ts +19 -0
  80. package/dist/adapters/viem/resources/withdrawals/services/finalization.d.ts +33 -0
  81. package/dist/adapters/viem/rpc.d.ts +2 -0
  82. package/dist/adapters/viem/sdk.cjs +6481 -0
  83. package/dist/adapters/viem/sdk.cjs.map +1 -0
  84. package/dist/adapters/viem/sdk.d.ts +32 -0
  85. package/dist/adapters/viem/sdk.js +6 -0
  86. package/dist/chunk-263G6636.js +36 -0
  87. package/dist/chunk-3LALBFFE.js +138 -0
  88. package/dist/chunk-4HLJJKIY.js +262 -0
  89. package/dist/chunk-6GCT6TLS.js +45 -0
  90. package/dist/chunk-7M4V3FMT.js +2444 -0
  91. package/dist/chunk-B77GWPO5.js +339 -0
  92. package/dist/chunk-BD2LUO5T.js +123 -0
  93. package/dist/chunk-CGO27P7F.js +2187 -0
  94. package/dist/chunk-DI2CJDPZ.js +76 -0
  95. package/dist/chunk-Y75OMFK6.js +4489 -0
  96. package/dist/core/constants.cjs +39 -0
  97. package/dist/core/constants.cjs.map +1 -0
  98. package/dist/core/constants.d.ts +36 -0
  99. package/dist/core/constants.js +1 -0
  100. package/dist/core/errors/factory.d.ts +10 -0
  101. package/dist/core/errors/formatter.d.ts +2 -0
  102. package/dist/core/errors/rpc.d.ts +4 -0
  103. package/dist/core/errors/withdrawal-revert-map.d.ts +3 -0
  104. package/dist/core/index.cjs +552 -0
  105. package/dist/core/index.cjs.map +1 -0
  106. package/dist/core/index.d.ts +18 -0
  107. package/dist/core/index.js +4 -0
  108. package/dist/core/internal/abi-registry.d.ts +9 -0
  109. package/dist/core/internal/abis/IAssetRouterBase.d.ts +198 -0
  110. package/dist/core/internal/abis/IBaseToken.d.ts +162 -0
  111. package/dist/core/internal/abis/IBridgehub.d.ts +994 -0
  112. package/dist/core/internal/abis/IERC20.d.ts +224 -0
  113. package/dist/core/internal/abis/IL1AssetRouter.d.ts +661 -0
  114. package/dist/core/internal/abis/IL1Nullifier.d.ts +377 -0
  115. package/dist/core/internal/abis/IL2AssetRouter.d.ts +690 -0
  116. package/dist/core/internal/abis/L1NativeTokenVault.d.ts +719 -0
  117. package/dist/core/internal/abis/L2NativeTokenVault.d.ts +735 -0
  118. package/dist/core/internal/abis/Mailbox.d.ts +779 -0
  119. package/dist/core/resources/deposits/route.d.ts +6 -0
  120. package/dist/core/resources/withdrawals/events.d.ts +9 -0
  121. package/dist/core/resources/withdrawals/logs.d.ts +5 -0
  122. package/dist/core/resources/withdrawals/route.d.ts +6 -0
  123. package/dist/core/rpc/transport.d.ts +10 -0
  124. package/dist/core/rpc/types.d.ts +40 -0
  125. package/dist/core/rpc/zks.d.ts +12 -0
  126. package/dist/core/types/errors.d.ts +177 -0
  127. package/dist/core/types/flows/base.d.ts +51 -0
  128. package/dist/core/types/flows/deposits.d.ts +43 -0
  129. package/dist/core/types/flows/route.d.ts +12 -0
  130. package/dist/core/types/flows/withdrawals.d.ts +83 -0
  131. package/dist/core/types/index.d.ts +2 -0
  132. package/dist/core/types/primitives.d.ts +3 -0
  133. package/dist/core/utils/addr.d.ts +5 -0
  134. package/dist/core/utils/gas.d.ts +13 -0
  135. package/dist/index.cjs +571 -0
  136. package/dist/index.cjs.map +1 -0
  137. package/dist/index.d.ts +18 -0
  138. package/dist/index.js +4 -0
  139. package/package.json +177 -0
@@ -0,0 +1,2 @@
1
+ import type { DepositRouteStrategy } from './types';
2
+ export declare function routeEthDirect(): DepositRouteStrategy;
@@ -0,0 +1,10 @@
1
+ import type { TransactionRequest } from 'ethers';
2
+ import type { DepositParams } from '../../../../../core/types/flows/deposits';
3
+ import type { RouteStrategy } from '../../../../../core/types/flows/route';
4
+ import type { BuildCtx as DepositBuildCtx } from '../context';
5
+ export type DepositQuoteExtras = {
6
+ baseCost: bigint;
7
+ mintValue: bigint;
8
+ l1GasLimit?: bigint;
9
+ };
10
+ export type DepositRouteStrategy = RouteStrategy<DepositParams, TransactionRequest, DepositQuoteExtras, DepositBuildCtx>;
@@ -0,0 +1,9 @@
1
+ import { Interface, type Log, type Provider, type TransactionReceipt } from 'ethers';
2
+ import type { Hex } from '../../../../../core/types/primitives';
3
+ export declare const I_BRIDGEHUB: Interface;
4
+ export declare const TOPIC_BRIDGEHUB_NPR: string;
5
+ export declare function extractL2TxHashFromL1Logs(logs: ReadonlyArray<Log>): Hex | null;
6
+ export declare function waitForL2ExecutionFromL1Tx(l1: Provider, l2: Provider, l1TxHash: Hex): Promise<{
7
+ l2Receipt: TransactionReceipt;
8
+ l2TxHash: Hex;
9
+ }>;
@@ -0,0 +1,31 @@
1
+ import { type Provider } from 'ethers';
2
+ import type { Address } from '../../../core/types/primitives';
3
+ /**
4
+ * Read the `BASE_TOKEN_ASSET_ID` from the L2 NativeTokenVault.
5
+ * This is the encoded assetId of the chain’s base token.
6
+ */
7
+ export declare function ntvBaseAssetId(l2: Provider, ntv: Address): Promise<`0x${string}`>;
8
+ /**
9
+ * Read the `L1_CHAIN_ID` that the L2 NativeTokenVault is anchored to.
10
+ * Needed when encoding asset IDs.
11
+ */
12
+ export declare function ntvL1ChainId(l2: Provider, ntv: Address): Promise<bigint>;
13
+ /**
14
+ * Ensure a token is registered in the L2 NativeTokenVault and return its assetId.
15
+ * (Will register on-chain if not yet registered.)
16
+ */
17
+ export declare function ntvAssetIdForToken(l2: Provider, ntv: Address, token: Address): Promise<`0x${string}`>;
18
+ /**
19
+ * Check if the chain is ETH-based (i.e. base token == ETH).
20
+ */
21
+ export declare function isEthBasedChain(l2: Provider, ntv: Address): Promise<boolean>;
22
+ /**
23
+ * Check if a given token address is the chain’s base token.
24
+ */
25
+ export declare function isBaseToken(l2: Provider, ntv: Address, token: Address): Promise<boolean>;
26
+ /**
27
+ * Check if the token should be treated as "ETH" on this L2.
28
+ * - If it equals the universal ETH alias (0x…800A), return true immediately.
29
+ * - Else compare the token’s assetId to the ETH sentinel assetId via the NTV.
30
+ */
31
+ export declare function isEthTokenOnThisChain(l2: Provider, ntv: Address, token: Address): Promise<boolean>;
@@ -0,0 +1,39 @@
1
+ import { ethers } from 'ethers';
2
+ import type { Address } from '../../../core/types';
3
+ import type { EthersClient } from '../client';
4
+ import type { Eip1559GasOverrides, ResolvedEip1559Fees } from '../../../core/types/flows/base';
5
+ export declare function encodeNativeTokenVaultAssetId(chainId: bigint, address: string): string;
6
+ export declare function encodeNativeTokenVaultTransferData(amount: bigint, receiver: Address, token: Address): string;
7
+ export declare function encodeSecondBridgeDataV1(assetId: string, transferData: string): string;
8
+ export declare function encodeNTVAssetId(chainId: bigint, address: string): string;
9
+ export declare function encodeNTVTransferData(amount: bigint, receiver: Address, token: Address): string;
10
+ export declare function scaleGasLimit(gasLimit: bigint): bigint;
11
+ export declare function checkBaseCost(baseCost: ethers.BigNumberish, value: ethers.BigNumberish | Promise<ethers.BigNumberish>): Promise<void>;
12
+ export type ResolvedFeeOverrides = ResolvedEip1559Fees & {
13
+ gasPriceForBaseCost: bigint;
14
+ };
15
+ export declare function getFeeOverrides(client: EthersClient, overrides?: Eip1559GasOverrides): Promise<ResolvedFeeOverrides>;
16
+ export declare function getL2FeeOverrides(client: EthersClient, overrides?: Eip1559GasOverrides): Promise<ResolvedEip1559Fees>;
17
+ export declare function getGasPriceWei(client: EthersClient): Promise<bigint>;
18
+ export declare function buildDirectRequestStruct(args: {
19
+ chainId: bigint;
20
+ mintValue: bigint;
21
+ l2GasLimit: bigint;
22
+ gasPerPubdata: bigint;
23
+ refundRecipient: Address;
24
+ l2Contract: Address;
25
+ l2Value: bigint;
26
+ }): {
27
+ chainId: bigint;
28
+ l2Contract: `0x${string}`;
29
+ mintValue: bigint;
30
+ l2Value: bigint;
31
+ l2Calldata: string;
32
+ l2GasLimit: bigint;
33
+ l2GasPerPubdataByteLimit: bigint;
34
+ factoryDeps: `0x${string}`[];
35
+ refundRecipient: `0x${string}`;
36
+ };
37
+ export declare function encodeSecondBridgeArgs(token: Address, amount: bigint, l2Receiver: Address): `0x${string}`;
38
+ export declare function encodeSecondBridgeErc20Args(token: Address, amount: bigint, l2Receiver: Address): `0x${string}`;
39
+ export declare function encodeSecondBridgeEthArgs(amount: bigint, l2Receiver: Address, ethToken?: Address): `0x${string}`;
@@ -0,0 +1,19 @@
1
+ import type { EthersClient } from '../../client';
2
+ import type { Address } from '../../../../core/types/primitives';
3
+ import type { WithdrawParams, WithdrawRoute } from '../../../../core/types/flows/withdrawals';
4
+ import type { CommonCtx, ResolvedEip1559Fees } from '../../../../core/types/flows/base';
5
+ export interface BuildCtx extends CommonCtx {
6
+ client: EthersClient;
7
+ l1AssetRouter: Address;
8
+ l1Nullifier: Address;
9
+ l2AssetRouter: Address;
10
+ l2NativeTokenVault: Address;
11
+ l2BaseTokenSystem: Address;
12
+ baseIsEth: boolean;
13
+ l2GasLimit: bigint;
14
+ gasBufferPct: number;
15
+ fee: ResolvedEip1559Fees;
16
+ }
17
+ export declare function commonCtx(p: WithdrawParams, client: EthersClient): Promise<BuildCtx & {
18
+ route: WithdrawRoute;
19
+ }>;
@@ -0,0 +1,56 @@
1
+ import { type TransactionRequest, type TransactionReceipt } from 'ethers';
2
+ import type { EthersClient } from '../../client';
3
+ import type { WithdrawParams, WithdrawQuote, WithdrawPlan, WithdrawHandle, WithdrawalWaitable, WithdrawRoute, WithdrawalStatus } from '../../../../core/types/flows/withdrawals';
4
+ import type { Hex } from '../../../../core/types/primitives';
5
+ import type { WithdrawRouteStrategy, TransactionReceiptZKsyncOS } from './routes/types';
6
+ import { createFinalizationServices, type FinalizationServices } from './services/finalization';
7
+ export declare const ROUTES: Record<WithdrawRoute, WithdrawRouteStrategy>;
8
+ export interface WithdrawalsResource {
9
+ quote(p: WithdrawParams): Promise<WithdrawQuote>;
10
+ tryQuote(p: WithdrawParams): Promise<{
11
+ ok: true;
12
+ value: WithdrawQuote;
13
+ } | {
14
+ ok: false;
15
+ error: unknown;
16
+ }>;
17
+ prepare(p: WithdrawParams): Promise<WithdrawPlan<TransactionRequest>>;
18
+ tryPrepare(p: WithdrawParams): Promise<{
19
+ ok: true;
20
+ value: WithdrawPlan<TransactionRequest>;
21
+ } | {
22
+ ok: false;
23
+ error: unknown;
24
+ }>;
25
+ create(p: WithdrawParams): Promise<WithdrawHandle<TransactionRequest>>;
26
+ tryCreate(p: WithdrawParams): Promise<{
27
+ ok: true;
28
+ value: WithdrawHandle<TransactionRequest>;
29
+ } | {
30
+ ok: false;
31
+ error: unknown;
32
+ }>;
33
+ status(h: WithdrawalWaitable | Hex): Promise<WithdrawalStatus>;
34
+ wait(h: WithdrawalWaitable | Hex, opts: {
35
+ for: 'l2' | 'ready' | 'finalized';
36
+ pollMs?: number;
37
+ timeoutMs?: number;
38
+ }): Promise<TransactionReceiptZKsyncOS | TransactionReceipt | null>;
39
+ finalize(l2TxHash: Hex): Promise<{
40
+ status: WithdrawalStatus;
41
+ receipt?: TransactionReceipt;
42
+ }>;
43
+ tryFinalize(l2TxHash: Hex): Promise<{
44
+ ok: true;
45
+ value: {
46
+ status: WithdrawalStatus;
47
+ receipt?: TransactionReceipt;
48
+ };
49
+ } | {
50
+ ok: false;
51
+ error: unknown;
52
+ }>;
53
+ }
54
+ export declare function createWithdrawalsResource(client: EthersClient): WithdrawalsResource;
55
+ export { createFinalizationServices };
56
+ export type { FinalizationServices };
@@ -0,0 +1,2 @@
1
+ import type { WithdrawRouteStrategy } from './types';
2
+ export declare function routeErc20NonBase(): WithdrawRouteStrategy;
@@ -0,0 +1,2 @@
1
+ import type { WithdrawRouteStrategy } from './types';
2
+ export declare function routeEthNonBase(): WithdrawRouteStrategy;
@@ -0,0 +1,2 @@
1
+ import type { WithdrawRouteStrategy } from './types';
2
+ export declare function routeEthBase(): WithdrawRouteStrategy;
@@ -0,0 +1,18 @@
1
+ import type { TransactionRequest, TransactionReceipt } from 'ethers';
2
+ import type { WithdrawParams } from '../../../../../core/types/flows/withdrawals';
3
+ import type { RouteStrategy } from '../../../../../core/types/flows/route';
4
+ import type { BuildCtx as WithdrawBuildCtx } from '../context';
5
+ import type { Address, Hex } from '../../../../../core/types';
6
+ export type WithdrawQuoteExtras = Record<string, never>;
7
+ export type WithdrawRouteStrategy = RouteStrategy<WithdrawParams, TransactionRequest, WithdrawQuoteExtras, WithdrawBuildCtx>;
8
+ export interface L2ToL1Log {
9
+ l2ShardId?: number;
10
+ isService?: boolean;
11
+ txNumberInBlock?: number;
12
+ sender?: Address;
13
+ key?: Hex;
14
+ value?: Hex;
15
+ }
16
+ export type TransactionReceiptZKsyncOS = TransactionReceipt & {
17
+ l2ToL1Logs?: L2ToL1Log[];
18
+ };
@@ -0,0 +1,33 @@
1
+ import { type TransactionReceipt } from 'ethers';
2
+ import type { Address, Hex } from '../../../../../core/types/primitives';
3
+ import type { EthersClient } from '../../../client';
4
+ import { type FinalizeReadiness, type FinalizeDepositParams, type WithdrawalKey, type FinalizationEstimate } from '../../../../../core/types/flows/withdrawals';
5
+ export interface FinalizationServices {
6
+ /**
7
+ * Build finalizeDeposit params.
8
+ */
9
+ fetchFinalizeDepositParams(l2TxHash: Hex): Promise<{
10
+ params: FinalizeDepositParams;
11
+ nullifier: Address;
12
+ }>;
13
+ /**
14
+ * Read the Nullifier mapping to check finalization status.
15
+ */
16
+ isWithdrawalFinalized(key: WithdrawalKey): Promise<boolean>;
17
+ /**
18
+ * Simulate finalizeDeposit on L1 Nullifier to check readiness.
19
+ */
20
+ simulateFinalizeReadiness(params: FinalizeDepositParams): Promise<FinalizeReadiness>;
21
+ /**
22
+ * Estimate gas & fees for finalizeDeposit on L1 Nullifier.
23
+ */
24
+ estimateFinalization(params: FinalizeDepositParams): Promise<FinalizationEstimate>;
25
+ /**
26
+ * Call finalizeDeposit on L1 Nullifier.
27
+ */
28
+ finalizeDeposit(params: FinalizeDepositParams): Promise<{
29
+ hash: string;
30
+ wait: () => Promise<TransactionReceipt>;
31
+ }>;
32
+ }
33
+ export declare function createFinalizationServices(client: EthersClient): FinalizationServices;
@@ -0,0 +1,4 @@
1
+ import type { AbstractProvider, JsonRpcApiProvider } from 'ethers';
2
+ import { createZksRpc } from '../../core/rpc/zks';
3
+ export declare function zksRpcFromEthers(l2Provider: JsonRpcApiProvider): ReturnType<typeof createZksRpc>;
4
+ export declare function zksRpcFromEthers(l2Provider: AbstractProvider): ReturnType<typeof createZksRpc>;