@matterlabs/zksync-js 0.0.1 → 0.0.3
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/README.md +12 -12
- package/dist/adapters/ethers/client.cjs +642 -1
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +6 -5
- package/dist/adapters/ethers/estimator.d.ts +4 -0
- package/dist/adapters/ethers/index.cjs +1279 -925
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.d.ts +1 -0
- package/dist/adapters/ethers/index.js +9 -8
- package/dist/adapters/ethers/resources/contracts/contracts.d.ts +9 -0
- package/dist/adapters/ethers/resources/contracts/index.d.ts +2 -0
- package/dist/adapters/ethers/resources/contracts/types.d.ts +60 -0
- package/dist/adapters/ethers/resources/deposits/context.d.ts +21 -7
- package/dist/adapters/ethers/resources/deposits/index.d.ts +3 -1
- package/dist/adapters/ethers/resources/deposits/routes/types.d.ts +2 -6
- package/dist/adapters/ethers/resources/deposits/services/fee.d.ts +6 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +41 -0
- package/dist/adapters/ethers/resources/tokens/index.d.ts +1 -0
- package/dist/adapters/ethers/resources/tokens/tokens.d.ts +10 -0
- package/dist/adapters/ethers/resources/utils.d.ts +3 -17
- package/dist/adapters/ethers/resources/withdrawals/context.d.ts +15 -7
- package/dist/adapters/ethers/resources/withdrawals/index.d.ts +3 -1
- package/dist/adapters/ethers/resources/withdrawals/routes/types.d.ts +2 -2
- package/dist/adapters/ethers/resources/withdrawals/services/fees.d.ts +14 -0
- package/dist/adapters/ethers/resources/withdrawals/services/gas.d.ts +12 -0
- package/dist/adapters/ethers/sdk.cjs +1388 -1501
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.d.ts +5 -22
- package/dist/adapters/ethers/sdk.js +7 -6
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.d.ts +1 -1
- package/dist/adapters/viem/client.js +4 -5
- package/dist/adapters/viem/estimator.d.ts +4 -0
- package/dist/adapters/viem/index.cjs +1233 -744
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.d.ts +3 -0
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/resources/contracts/contracts.d.ts +9 -0
- package/dist/adapters/viem/resources/contracts/index.d.ts +2 -0
- package/dist/adapters/viem/resources/contracts/types.d.ts +61 -0
- package/dist/adapters/viem/resources/deposits/context.d.ts +21 -7
- package/dist/adapters/viem/resources/deposits/index.d.ts +3 -1
- package/dist/adapters/viem/resources/deposits/routes/types.d.ts +2 -6
- package/dist/adapters/viem/resources/deposits/services/fee.d.ts +6 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +37 -0
- package/dist/adapters/viem/resources/tokens/index.d.ts +1 -0
- package/dist/adapters/viem/resources/tokens/tokens.d.ts +3 -0
- package/dist/adapters/viem/resources/utils.d.ts +3 -19
- package/dist/adapters/viem/resources/withdrawals/context.d.ts +14 -9
- package/dist/adapters/viem/resources/withdrawals/index.d.ts +3 -1
- package/dist/adapters/viem/resources/withdrawals/routes/types.d.ts +12 -2
- package/dist/adapters/viem/resources/withdrawals/services/fee.d.ts +17 -0
- package/dist/adapters/viem/resources/withdrawals/services/gas.d.ts +12 -0
- package/dist/adapters/viem/sdk.cjs +1225 -699
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.d.ts +5 -25
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-3LALBFFE.js → chunk-3MRGU4HV.js} +9 -5
- package/dist/{chunk-CGO27P7F.js → chunk-5YWP4CZP.js} +849 -835
- package/dist/{chunk-4HLJJKIY.js → chunk-6K6VJQAL.js} +2 -2
- package/dist/{chunk-6GCT6TLS.js → chunk-F2ENUV3A.js} +13 -1
- package/dist/{chunk-7M4V3FMT.js → chunk-JXUFGIJG.js} +986 -678
- package/dist/chunk-LL3WKCFJ.js +231 -0
- package/dist/{chunk-Y75OMFK6.js → chunk-M5J2MM2U.js} +351 -1
- package/dist/{chunk-263G6636.js → chunk-NCAIVYBR.js} +1 -14
- package/dist/{chunk-DI2CJDPZ.js → chunk-NEC2ZKHI.js} +5 -13
- package/dist/chunk-NTEIA5KA.js +13 -0
- package/dist/chunk-XRE7H466.js +157 -0
- package/dist/{chunk-BD2LUO5T.js → chunk-YUK547UF.js} +3 -3
- package/dist/core/abi.d.ts +9 -0
- package/dist/core/adapters/interfaces.d.ts +25 -0
- package/dist/core/codec/ntv.d.ts +48 -0
- package/dist/core/constants.cjs +12 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +6 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +4508 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +5 -4
- package/dist/core/resources/deposits/fee.d.ts +15 -0
- package/dist/core/resources/deposits/gas.d.ts +38 -0
- package/dist/core/resources/withdrawals/gas.d.ts +14 -0
- package/dist/core/types/errors.d.ts +1 -1
- package/dist/core/types/fees.d.ts +40 -0
- package/dist/core/types/flows/base.d.ts +0 -10
- package/dist/core/types/flows/deposits.d.ts +20 -6
- package/dist/core/types/flows/route.d.ts +2 -3
- package/dist/core/types/flows/token.d.ts +192 -0
- package/dist/core/types/flows/withdrawals.d.ts +12 -6
- package/dist/core/utils/addr.d.ts +2 -0
- package/dist/index.cjs +4520 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -4
- package/package.json +5 -1
- package/dist/adapters/ethers/resources/token-info.d.ts +0 -31
- package/dist/adapters/ethers/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
- package/dist/adapters/viem/resources/token-info.d.ts +0 -34
- package/dist/adapters/viem/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
- package/dist/chunk-B77GWPO5.js +0 -339
- package/dist/core/internal/abi-registry.d.ts +0 -9
- package/dist/core/utils/gas.d.ts +0 -13
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Address, Hex } from '../primitives';
|
|
2
|
+
/**
|
|
3
|
+
* Token kind classification.
|
|
4
|
+
* - 'eth': Ethereum / native ETH token
|
|
5
|
+
* - 'base': The base token of the target L2 chain
|
|
6
|
+
* - 'erc20': ERC-20 token
|
|
7
|
+
*/
|
|
8
|
+
export type TokenKind = 'eth' | 'base' | 'erc20';
|
|
9
|
+
/**
|
|
10
|
+
* Reference to a token on a specific chain.
|
|
11
|
+
* Used as input to identify a token for resolution.
|
|
12
|
+
*/
|
|
13
|
+
export type TokenRef = {
|
|
14
|
+
chain: 'l1';
|
|
15
|
+
address: Address;
|
|
16
|
+
} | {
|
|
17
|
+
chain: 'l2';
|
|
18
|
+
address: Address;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Fully resolved token information including L1/L2 addresses,
|
|
22
|
+
* bridge identity, and chain-specific facts.
|
|
23
|
+
*/
|
|
24
|
+
export interface ResolvedToken {
|
|
25
|
+
/**
|
|
26
|
+
* Token kind: 'eth', 'base', or 'erc20'
|
|
27
|
+
*/
|
|
28
|
+
kind: TokenKind;
|
|
29
|
+
/**
|
|
30
|
+
* Canonical L1 token address
|
|
31
|
+
*/
|
|
32
|
+
l1: Address;
|
|
33
|
+
/**
|
|
34
|
+
* Canonical L2 token address
|
|
35
|
+
*/
|
|
36
|
+
l2: Address;
|
|
37
|
+
/**
|
|
38
|
+
* Bridge asset ID (bytes32)
|
|
39
|
+
*/
|
|
40
|
+
assetId: Hex;
|
|
41
|
+
/**
|
|
42
|
+
* Chain ID where this token originates
|
|
43
|
+
*/
|
|
44
|
+
originChainId: bigint;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the L2 chain is ETH-based (i.e., base token is ETH)
|
|
47
|
+
*/
|
|
48
|
+
isChainEthBased: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Asset ID of the chain's base token
|
|
51
|
+
*/
|
|
52
|
+
baseTokenAssetId: Hex;
|
|
53
|
+
/**
|
|
54
|
+
* WETH address on L1
|
|
55
|
+
*/
|
|
56
|
+
wethL1: Address;
|
|
57
|
+
/**
|
|
58
|
+
* WETH address on L2
|
|
59
|
+
*/
|
|
60
|
+
wethL2: Address;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Tokens resource interface providing token identity, L1/L2 mapping,
|
|
64
|
+
* and bridge assetId primitives.
|
|
65
|
+
*/
|
|
66
|
+
export interface TokensResource {
|
|
67
|
+
/**
|
|
68
|
+
* Resolves a token reference into a complete `ResolvedToken` with all
|
|
69
|
+
* L1/L2 addresses, assetId, origin chain, and chain facts.
|
|
70
|
+
*
|
|
71
|
+
* @param ref - Token address or TokenRef object
|
|
72
|
+
* @param opts - Optional chain specification when ref is an Address
|
|
73
|
+
* @returns Fully resolved token information
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Resolve by L1 address (default)
|
|
78
|
+
* const token = await sdk.tokens.resolve('0x...');
|
|
79
|
+
*
|
|
80
|
+
* // Explicitly specify chain
|
|
81
|
+
* const token = await sdk.tokens.resolve('0x...', { chain: 'l2' });
|
|
82
|
+
*
|
|
83
|
+
* // Use TokenRef object
|
|
84
|
+
* const token = await sdk.tokens.resolve({ chain: 'l1', address: '0x...' });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
resolve(ref: Address | TokenRef, opts?: {
|
|
88
|
+
chain?: 'l1' | 'l2';
|
|
89
|
+
}): Promise<ResolvedToken>;
|
|
90
|
+
/**
|
|
91
|
+
* Maps an L1 token address to its corresponding L2 token address.
|
|
92
|
+
*
|
|
93
|
+
* @param l1Token - L1 token address
|
|
94
|
+
* @returns Corresponding L2 token address
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const l2Token = await sdk.tokens.toL2Address('0x...L1Address');
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
toL2Address(l1Token: Address): Promise<Address>;
|
|
102
|
+
/**
|
|
103
|
+
* Maps an L2 token address to its corresponding L1 token address.
|
|
104
|
+
*
|
|
105
|
+
* @param l2Token - L2 token address
|
|
106
|
+
* @returns Corresponding L1 token address
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const l1Token = await sdk.tokens.toL1Address('0x...L2Address');
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
toL1Address(l2Token: Address): Promise<Address>;
|
|
114
|
+
/**
|
|
115
|
+
* Computes the bridge assetId for a given L1 token address.
|
|
116
|
+
*
|
|
117
|
+
* @param l1Token - L1 token address
|
|
118
|
+
* @returns AssetId (bytes32)
|
|
119
|
+
*/
|
|
120
|
+
assetIdOfL1(l1Token: Address): Promise<Hex>;
|
|
121
|
+
/**
|
|
122
|
+
* Computes the bridge assetId for a given L2 token address.
|
|
123
|
+
*
|
|
124
|
+
* @param l2Token - L2 token address
|
|
125
|
+
* @returns AssetId (bytes32)
|
|
126
|
+
*/
|
|
127
|
+
assetIdOfL2(l2Token: Address): Promise<Hex>;
|
|
128
|
+
/**
|
|
129
|
+
* Retrieves the L2 token address for a given assetId.
|
|
130
|
+
*
|
|
131
|
+
* @param assetId - Bridge asset ID (bytes32)
|
|
132
|
+
* @returns L2 token address
|
|
133
|
+
*/
|
|
134
|
+
l2TokenFromAssetId(assetId: Hex): Promise<Address>;
|
|
135
|
+
/**
|
|
136
|
+
* Retrieves the L1 token address for a given assetId.
|
|
137
|
+
*
|
|
138
|
+
* @param assetId - Bridge asset ID (bytes32)
|
|
139
|
+
* @returns L1 token address
|
|
140
|
+
*/
|
|
141
|
+
l1TokenFromAssetId(assetId: Hex): Promise<Address>;
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves the origin chain ID for a given assetId.
|
|
144
|
+
*
|
|
145
|
+
* @param assetId - Bridge asset ID (bytes32)
|
|
146
|
+
* @returns Origin chain ID
|
|
147
|
+
*/
|
|
148
|
+
originChainId(assetId: Hex): Promise<bigint>;
|
|
149
|
+
/**
|
|
150
|
+
* Returns the assetId of the base token for the L2 chain.
|
|
151
|
+
*
|
|
152
|
+
* @returns Base token assetId (bytes32)
|
|
153
|
+
*/
|
|
154
|
+
baseTokenAssetId(): Promise<Hex>;
|
|
155
|
+
/**
|
|
156
|
+
* Determines whether the L2 chain is ETH-based (i.e., base token is ETH).
|
|
157
|
+
*
|
|
158
|
+
* @returns True if the chain is ETH-based, false otherwise
|
|
159
|
+
*/
|
|
160
|
+
isChainEthBased(): Promise<boolean>;
|
|
161
|
+
/**
|
|
162
|
+
* Returns the WETH token address on L1.
|
|
163
|
+
*
|
|
164
|
+
* @returns WETH L1 address
|
|
165
|
+
*/
|
|
166
|
+
wethL1(): Promise<Address>;
|
|
167
|
+
/**
|
|
168
|
+
* Returns the WETH token address on L2.
|
|
169
|
+
*
|
|
170
|
+
* @returns WETH L2 address
|
|
171
|
+
*/
|
|
172
|
+
wethL2(): Promise<Address>;
|
|
173
|
+
/**
|
|
174
|
+
* Predicts the L2 address for a bridged token given its origin chain and L1 address.
|
|
175
|
+
* This uses the CREATE2 deterministic deployment address calculation.
|
|
176
|
+
*
|
|
177
|
+
* @param args - Origin chain ID and L1 token address
|
|
178
|
+
* @returns Predicted L2 token address
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const predictedL2Addr = await sdk.tokens.computeL2BridgedAddress({
|
|
183
|
+
* originChainId: 1n,
|
|
184
|
+
* l1Token: '0x...'
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
computeL2BridgedAddress(args: {
|
|
189
|
+
originChainId: bigint;
|
|
190
|
+
l1Token: Address;
|
|
191
|
+
}): Promise<Address>;
|
|
192
|
+
}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
import type { WithdrawalFeeBreakdown, TxOverrides } from '../fees';
|
|
1
2
|
import type { Address, Hex } from '../primitives';
|
|
2
|
-
import type { ApprovalNeed, Plan, Handle
|
|
3
|
+
import type { ApprovalNeed, Plan, Handle } from './base';
|
|
3
4
|
/** Input */
|
|
4
5
|
export interface WithdrawParams {
|
|
5
6
|
token: Address;
|
|
6
7
|
amount: bigint;
|
|
7
8
|
to?: Address;
|
|
8
|
-
|
|
9
|
-
l2TxOverrides?:
|
|
9
|
+
refundRecipient?: Address;
|
|
10
|
+
l2TxOverrides?: TxOverrides;
|
|
10
11
|
}
|
|
11
12
|
/** Routes */
|
|
12
|
-
export type WithdrawRoute = '
|
|
13
|
+
export type WithdrawRoute = 'base' | 'erc20-nonbase';
|
|
13
14
|
/** Quote */
|
|
14
15
|
export interface WithdrawQuote {
|
|
15
16
|
route: WithdrawRoute;
|
|
16
17
|
approvalsNeeded: readonly ApprovalNeed[];
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
amounts: {
|
|
19
|
+
transfer: {
|
|
20
|
+
token: Address;
|
|
21
|
+
amount: bigint;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
fees: WithdrawalFeeBreakdown;
|
|
19
25
|
}
|
|
20
26
|
/** Plan (Tx generic) */
|
|
21
27
|
export type WithdrawPlan<Tx> = Plan<Tx, WithdrawRoute, WithdrawQuote>;
|
|
@@ -3,3 +3,5 @@ export declare const isHash66: (x?: string) => x is Hex;
|
|
|
3
3
|
export declare function isAddressEq(a: Address, b: Address): boolean;
|
|
4
4
|
export declare function isETH(token: Address): boolean;
|
|
5
5
|
export declare function normalizeAddrEq(a?: string, b?: string): boolean;
|
|
6
|
+
export declare const hexEq: (a: Hex, b: Hex) => boolean;
|
|
7
|
+
export declare const normalizeL1Token: (token: Address) => Address;
|