@matterlabs/zksync-js 0.0.2 → 0.0.5

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/README.md +1 -3
  2. package/dist/adapters/ethers/client.cjs.map +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 +3 -3
  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 +3 -3
  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-OC6ZVLSP.js → chunk-JXUFGIJG.js} +348 -150
  43. package/dist/{chunk-QJS6ETEE.js → chunk-LL3WKCFJ.js} +15 -1
  44. package/dist/{chunk-BCCKWWOX.js → chunk-NBJEQAOE.js} +373 -158
  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
@@ -1,4 +1,4 @@
1
- import { FORMAL_ETH_ADDRESS, L2_BASE_TOKEN_ADDRESS, ETH_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L1_MESSENGER_ADDRESS, TOPIC_L1_MESSAGE_SENT_NEW, TOPIC_L1_MESSAGE_SENT_LEG } from './chunk-F2ENUV3A.js';
1
+ import { ETH_ADDRESS, FORMAL_ETH_ADDRESS, L2_BASE_TOKEN_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L1_MESSENGER_ADDRESS, TOPIC_L1_MESSAGE_SENT_NEW, TOPIC_L1_MESSAGE_SENT_LEG } from './chunk-F2ENUV3A.js';
2
2
 
3
3
  // src/core/utils/addr.ts
4
4
  var isHash66 = (x) => !!x && x.startsWith("0x") && x.length === 66;
@@ -17,16 +17,8 @@ function normalizeAddrEq(a, b) {
17
17
  };
18
18
  return normalize(a) === normalize(b);
19
19
  }
20
-
21
- // src/core/resources/deposits/route.ts
22
- async function pickDepositRoute(client, chainIdL2, token) {
23
- if (isETH(token)) {
24
- const base2 = await client.baseToken(chainIdL2);
25
- return isETH(base2) ? "eth-base" : "eth-nonbase";
26
- }
27
- const base = await client.baseToken(chainIdL2);
28
- return normalizeAddrEq(token, base) ? "erc20-base" : "erc20-nonbase";
29
- }
20
+ var hexEq = (a, b) => a.toLowerCase() === b.toLowerCase();
21
+ var normalizeL1Token = (token) => isAddressEq(token, FORMAL_ETH_ADDRESS) ? ETH_ADDRESS : token;
30
22
 
31
23
  // src/core/resources/withdrawals/route.ts
32
24
  function normalizeTokenForRouting(token) {
@@ -73,4 +65,4 @@ function messengerLogIndex(raw, opts) {
73
65
  return (hits[index] ?? hits[0]).i;
74
66
  }
75
67
 
76
- export { findL1MessageSentLog, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, pickDepositRoute, pickWithdrawRoute };
68
+ export { findL1MessageSentLog, hexEq, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, normalizeL1Token, pickWithdrawRoute };
@@ -0,0 +1,13 @@
1
+ import { isETH, normalizeAddrEq } from './chunk-NEC2ZKHI.js';
2
+
3
+ // src/core/resources/deposits/route.ts
4
+ async function pickDepositRoute(client, chainIdL2, token) {
5
+ if (isETH(token)) {
6
+ const base2 = await client.baseToken(chainIdL2);
7
+ return isETH(base2) ? "eth-base" : "eth-nonbase";
8
+ }
9
+ const base = await client.baseToken(chainIdL2);
10
+ return normalizeAddrEq(token, base) ? "erc20-base" : "erc20-nonbase";
11
+ }
12
+
13
+ export { pickDepositRoute };
@@ -0,0 +1,48 @@
1
+ import type { Address, Hex } from '../types/primitives';
2
+ /**
3
+ * Dependencies injected by the adapter (ethers or viem)
4
+ */
5
+ export interface NTVCodecDeps {
6
+ /**
7
+ * ABI encoder: (types, values) => encoded hex string
8
+ * For ethers: AbiCoder.encode
9
+ * For viem: encodeAbiParameters
10
+ */
11
+ encode(types: string[], values: unknown[]): Hex;
12
+ /**
13
+ * Keccak-256 hash function: (data) => hash as hex string
14
+ * For ethers: ethers.keccak256
15
+ * For viem: keccak256
16
+ */
17
+ keccak256(data: Hex): Hex;
18
+ }
19
+ /**
20
+ * Factory to create NTV (Native Token Vault) codec utilities.
21
+ * This keeps core adapter-agnostic while enabling code reuse.
22
+ *
23
+ * @param deps - Adapter-specific encode and keccak256 implementations
24
+ * @returns Codec utilities for NTV assetId encoding
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Ethers adapter
29
+ * import { AbiCoder, ethers } from 'ethers';
30
+ * const codec = createNTVCodec({
31
+ * encode: (types, values) => new AbiCoder().encode(types, values),
32
+ * keccak256: ethers.keccak256
33
+ * });
34
+ *
35
+ * // Viem adapter
36
+ * import { encodeAbiParameters, keccak256 } from 'viem';
37
+ * const codec = createNTVCodec({
38
+ * encode: (types, values) => encodeAbiParameters(
39
+ * types.map((t, i) => ({ type: t, name: `arg${i}` })),
40
+ * values
41
+ * ),
42
+ * keccak256
43
+ * });
44
+ * ```
45
+ */
46
+ export declare function createNTVCodec(deps: NTVCodecDeps): {
47
+ encodeAssetId: (originChainId: bigint, ntvAddress: Address, tokenAddress: Address) => Hex;
48
+ };
@@ -4974,6 +4974,8 @@ function normalizeAddrEq(a, b) {
4974
4974
  };
4975
4975
  return normalize(a) === normalize(b);
4976
4976
  }
4977
+ var hexEq = (a, b) => a.toLowerCase() === b.toLowerCase();
4978
+ var normalizeL1Token = (token) => isAddressEq(token, FORMAL_ETH_ADDRESS) ? ETH_ADDRESS : token;
4977
4979
 
4978
4980
  // src/core/resources/deposits/route.ts
4979
4981
  async function pickDepositRoute(client, chainIdL2, token) {
@@ -5041,6 +5043,7 @@ exports.abi = abi_exports;
5041
5043
  exports.errors = factory_exports;
5042
5044
  exports.findL1MessageSentLog = findL1MessageSentLog;
5043
5045
  exports.formatEnvelopePretty = formatEnvelopePretty;
5046
+ exports.hexEq = hexEq;
5044
5047
  exports.isAddressEq = isAddressEq;
5045
5048
  exports.isETH = isETH;
5046
5049
  exports.isHash66 = isHash66;
@@ -5048,6 +5051,7 @@ exports.makeTransportFromEthers = makeTransportFromEthers;
5048
5051
  exports.makeTransportFromViem = makeTransportFromViem;
5049
5052
  exports.messengerLogIndex = messengerLogIndex;
5050
5053
  exports.normalizeAddrEq = normalizeAddrEq;
5054
+ exports.normalizeL1Token = normalizeL1Token;
5051
5055
  exports.pickDepositRoute = pickDepositRoute;
5052
5056
  exports.pickWithdrawRoute = pickWithdrawRoute;
5053
5057
  exports.zksRpc = zks_exports;