@matterlabs/zksync-js 0.0.2 → 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.
Files changed (61) hide show
  1. package/dist/adapters/ethers/client.cjs.map +1 -1
  2. package/dist/adapters/ethers/client.js +1 -1
  3. package/dist/adapters/ethers/index.cjs +391 -170
  4. package/dist/adapters/ethers/index.cjs.map +1 -1
  5. package/dist/adapters/ethers/index.d.ts +1 -0
  6. package/dist/adapters/ethers/index.js +4 -4
  7. package/dist/adapters/ethers/resources/contracts/contracts.d.ts +9 -0
  8. package/dist/adapters/ethers/resources/contracts/index.d.ts +2 -0
  9. package/dist/adapters/ethers/resources/contracts/types.d.ts +60 -0
  10. package/dist/adapters/ethers/resources/deposits/context.d.ts +16 -2
  11. package/dist/adapters/ethers/resources/deposits/index.d.ts +3 -1
  12. package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +3 -2
  13. package/dist/adapters/ethers/resources/tokens/index.d.ts +1 -0
  14. package/dist/adapters/ethers/resources/tokens/tokens.d.ts +10 -0
  15. package/dist/adapters/ethers/resources/utils.d.ts +0 -3
  16. package/dist/adapters/ethers/resources/withdrawals/context.d.ts +11 -3
  17. package/dist/adapters/ethers/resources/withdrawals/index.d.ts +3 -1
  18. package/dist/adapters/ethers/sdk.cjs +386 -154
  19. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  20. package/dist/adapters/ethers/sdk.d.ts +5 -22
  21. package/dist/adapters/ethers/sdk.js +3 -3
  22. package/dist/adapters/viem/client.cjs.map +1 -1
  23. package/dist/adapters/viem/index.cjs +383 -176
  24. package/dist/adapters/viem/index.cjs.map +1 -1
  25. package/dist/adapters/viem/index.d.ts +3 -0
  26. package/dist/adapters/viem/index.js +4 -4
  27. package/dist/adapters/viem/resources/contracts/contracts.d.ts +9 -0
  28. package/dist/adapters/viem/resources/contracts/index.d.ts +2 -0
  29. package/dist/adapters/viem/resources/contracts/types.d.ts +61 -0
  30. package/dist/adapters/viem/resources/deposits/context.d.ts +16 -2
  31. package/dist/adapters/viem/resources/deposits/index.d.ts +3 -1
  32. package/dist/adapters/viem/resources/deposits/services/gas.d.ts +2 -1
  33. package/dist/adapters/viem/resources/tokens/index.d.ts +1 -0
  34. package/dist/adapters/viem/resources/tokens/tokens.d.ts +3 -0
  35. package/dist/adapters/viem/resources/utils.d.ts +0 -3
  36. package/dist/adapters/viem/resources/withdrawals/context.d.ts +11 -3
  37. package/dist/adapters/viem/resources/withdrawals/index.d.ts +3 -1
  38. package/dist/adapters/viem/sdk.cjs +401 -189
  39. package/dist/adapters/viem/sdk.cjs.map +1 -1
  40. package/dist/adapters/viem/sdk.d.ts +5 -25
  41. package/dist/adapters/viem/sdk.js +3 -3
  42. package/dist/{chunk-BCCKWWOX.js → chunk-5YWP4CZP.js} +373 -158
  43. package/dist/{chunk-OC6ZVLSP.js → chunk-JXUFGIJG.js} +348 -150
  44. package/dist/{chunk-QJS6ETEE.js → chunk-LL3WKCFJ.js} +15 -1
  45. package/dist/{chunk-HLUANWGN.js → chunk-NEC2ZKHI.js} +4 -12
  46. package/dist/chunk-NTEIA5KA.js +13 -0
  47. package/dist/core/codec/ntv.d.ts +48 -0
  48. package/dist/core/index.cjs +4 -0
  49. package/dist/core/index.cjs.map +1 -1
  50. package/dist/core/index.d.ts +1 -0
  51. package/dist/core/index.js +2 -1
  52. package/dist/core/types/errors.d.ts +1 -1
  53. package/dist/core/types/flows/token.d.ts +192 -0
  54. package/dist/core/utils/addr.d.ts +2 -0
  55. package/dist/index.cjs +4 -0
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.ts +1 -0
  58. package/dist/index.js +2 -1
  59. package/package.json +1 -1
  60. package/dist/adapters/ethers/resources/token-info.d.ts +0 -31
  61. package/dist/adapters/viem/resources/token-info.d.ts +0 -34
@@ -16,4 +16,5 @@ export type * from './types/flows/base';
16
16
  export type * from './types/flows/deposits';
17
17
  export type * from './types/flows/withdrawals';
18
18
  export type * from './types/flows/route';
19
+ export type * from './types/flows/token';
19
20
  export type * from './types/primitives';
@@ -1,4 +1,5 @@
1
- export { findL1MessageSentLog, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, pickDepositRoute, pickWithdrawRoute } from '../chunk-HLUANWGN.js';
1
+ export { pickDepositRoute } from '../chunk-NTEIA5KA.js';
2
+ export { findL1MessageSentLog, hexEq, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, normalizeL1Token, pickWithdrawRoute } from '../chunk-NEC2ZKHI.js';
2
3
  export { makeTransportFromEthers, makeTransportFromViem, zks_exports as zksRpc } from '../chunk-6K6VJQAL.js';
3
4
  export { abi_exports as abi, factory_exports as errors, formatEnvelopePretty } from '../chunk-M5J2MM2U.js';
4
5
  export { ETH_ADDRESS, FORMAL_ETH_ADDRESS, L1_MESSENGER_ADDRESS, L1_SOPH_TOKEN_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS } from '../chunk-F2ENUV3A.js';
@@ -1,6 +1,6 @@
1
1
  export type ErrorType = 'VALIDATION' | 'STATE' | 'EXECUTION' | 'RPC' | 'INTERNAL' | 'VERIFICATION' | 'CONTRACT';
2
2
  /** Resource surface */
3
- export type Resource = 'deposits' | 'withdrawals' | 'withdrawal-finalization' | 'helpers' | 'zksrpc' | 'client';
3
+ export type Resource = 'deposits' | 'withdrawals' | 'withdrawal-finalization' | 'tokens' | 'contracts' | 'helpers' | 'zksrpc' | 'client';
4
4
  /** Envelope we throw only for SDK-domain errors. */
5
5
  export interface ErrorEnvelope {
6
6
  /** Resource surface that raised the error. */
@@ -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
+ }
@@ -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;
package/dist/index.cjs CHANGED
@@ -5011,6 +5011,8 @@ function normalizeAddrEq(a, b) {
5011
5011
  };
5012
5012
  return normalize(a) === normalize(b);
5013
5013
  }
5014
+ var hexEq = (a, b) => a.toLowerCase() === b.toLowerCase();
5015
+ var normalizeL1Token = (token) => isAddressEq(token, FORMAL_ETH_ADDRESS) ? ETH_ADDRESS : token;
5014
5016
 
5015
5017
  // src/core/resources/deposits/route.ts
5016
5018
  async function pickDepositRoute(client, chainIdL2, token) {
@@ -5072,6 +5074,7 @@ exports.constants = constants_exports;
5072
5074
  exports.errors = factory_exports;
5073
5075
  exports.findL1MessageSentLog = findL1MessageSentLog;
5074
5076
  exports.formatEnvelopePretty = formatEnvelopePretty;
5077
+ exports.hexEq = hexEq;
5075
5078
  exports.isAddressEq = isAddressEq;
5076
5079
  exports.isETH = isETH;
5077
5080
  exports.isHash66 = isHash66;
@@ -5079,6 +5082,7 @@ exports.makeTransportFromEthers = makeTransportFromEthers;
5079
5082
  exports.makeTransportFromViem = makeTransportFromViem;
5080
5083
  exports.messengerLogIndex = messengerLogIndex;
5081
5084
  exports.normalizeAddrEq = normalizeAddrEq;
5085
+ exports.normalizeL1Token = normalizeL1Token;
5082
5086
  exports.pickDepositRoute = pickDepositRoute;
5083
5087
  exports.pickWithdrawRoute = pickWithdrawRoute;
5084
5088
  exports.zksRpc = zks_exports;