@matterlabs/zksync-js 0.0.5 → 0.0.7

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 (48) hide show
  1. package/dist/adapters/ethers/client.cjs +170 -48
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.js +6 -6
  4. package/dist/adapters/ethers/errors/error-ops.d.ts +26 -19
  5. package/dist/adapters/ethers/index.cjs +194 -50
  6. package/dist/adapters/ethers/index.cjs.map +1 -1
  7. package/dist/adapters/ethers/index.js +9 -9
  8. package/dist/adapters/ethers/resources/withdrawals/index.d.ts +11 -0
  9. package/dist/adapters/ethers/sdk.cjs +75 -47
  10. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  11. package/dist/adapters/ethers/sdk.js +7 -7
  12. package/dist/adapters/viem/client.cjs +119 -3
  13. package/dist/adapters/viem/client.cjs.map +1 -1
  14. package/dist/adapters/viem/client.js +4 -4
  15. package/dist/adapters/viem/errors/error-ops.d.ts +26 -19
  16. package/dist/adapters/viem/index.cjs +194 -50
  17. package/dist/adapters/viem/index.cjs.map +1 -1
  18. package/dist/adapters/viem/index.js +8 -8
  19. package/dist/adapters/viem/resources/withdrawals/index.d.ts +11 -0
  20. package/dist/adapters/viem/sdk.cjs +75 -47
  21. package/dist/adapters/viem/sdk.cjs.map +1 -1
  22. package/dist/adapters/viem/sdk.js +6 -6
  23. package/dist/{chunk-YUK547UF.js → chunk-7VP6742W.js} +3 -3
  24. package/dist/{chunk-NBJEQAOE.js → chunk-EWLA4NUE.js} +28 -6
  25. package/dist/{chunk-M5J2MM2U.js → chunk-GIXLOHLK.js} +1 -1
  26. package/dist/{chunk-XRE7H466.js → chunk-GNERKUWO.js} +3 -47
  27. package/dist/chunk-KAMEGD6I.js +75 -0
  28. package/dist/{chunk-JXUFGIJG.js → chunk-KRIRXY74.js} +30 -52
  29. package/dist/{chunk-F2ENUV3A.js → chunk-NCR42O6O.js} +1 -1
  30. package/dist/{chunk-3MRGU4HV.js → chunk-NGXRO2ZX.js} +4 -4
  31. package/dist/{chunk-LL3WKCFJ.js → chunk-NNFWIAVG.js} +2 -2
  32. package/dist/{chunk-NEC2ZKHI.js → chunk-P5PIWVEO.js} +1 -1
  33. package/dist/{chunk-NTEIA5KA.js → chunk-VRL6Y4YJ.js} +1 -1
  34. package/dist/{chunk-6K6VJQAL.js → chunk-WY36Z6YB.js} +122 -5
  35. package/dist/core/constants.cjs +1 -1
  36. package/dist/core/constants.d.ts +1 -1
  37. package/dist/core/constants.js +1 -1
  38. package/dist/core/errors/error-ops.d.ts +18 -0
  39. package/dist/core/index.cjs +120 -3
  40. package/dist/core/index.cjs.map +1 -1
  41. package/dist/core/index.js +5 -5
  42. package/dist/core/rpc/types.d.ts +5 -0
  43. package/dist/core/rpc/zks.d.ts +4 -1
  44. package/dist/index.cjs +121 -4
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.js +5 -5
  47. package/package.json +1 -1
  48. package/dist/chunk-NCAIVYBR.js +0 -23
@@ -1,9 +1,9 @@
1
- export { createEthersClient as createClient, createEthersClient } from '../../chunk-3MRGU4HV.js';
2
- export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createTokensResource, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs } from '../../chunk-NBJEQAOE.js';
3
- export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-XRE7H466.js';
4
- import '../../chunk-LL3WKCFJ.js';
5
- import '../../chunk-NEC2ZKHI.js';
6
- import '../../chunk-NCAIVYBR.js';
7
- import '../../chunk-6K6VJQAL.js';
8
- import '../../chunk-M5J2MM2U.js';
9
- import '../../chunk-F2ENUV3A.js';
1
+ export { createEthersClient as createClient, createEthersClient } from '../../chunk-NGXRO2ZX.js';
2
+ export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createTokensResource, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs } from '../../chunk-EWLA4NUE.js';
3
+ export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-GNERKUWO.js';
4
+ import '../../chunk-NNFWIAVG.js';
5
+ import '../../chunk-P5PIWVEO.js';
6
+ import '../../chunk-KAMEGD6I.js';
7
+ import '../../chunk-WY36Z6YB.js';
8
+ import '../../chunk-GIXLOHLK.js';
9
+ import '../../chunk-NCR42O6O.js';
@@ -38,6 +38,17 @@ export interface WithdrawalsResource {
38
38
  pollMs?: number;
39
39
  timeoutMs?: number;
40
40
  }): Promise<TransactionReceiptZKsyncOS | TransactionReceipt | null>;
41
+ tryWait(h: WithdrawalWaitable | Hex, opts: {
42
+ for: 'l2' | 'ready' | 'finalized';
43
+ pollMs?: number;
44
+ timeoutMs?: number;
45
+ }): Promise<{
46
+ ok: true;
47
+ value: TransactionReceiptZKsyncOS | TransactionReceipt;
48
+ } | {
49
+ ok: false;
50
+ error: unknown;
51
+ }>;
41
52
  finalize(l2TxHash: Hex): Promise<{
42
53
  status: WithdrawalStatus;
43
54
  receipt?: TransactionReceipt;
@@ -21,7 +21,7 @@ var TX_OVERHEAD_GAS = 10000n;
21
21
  var TX_MEMORY_OVERHEAD_GAS = 10n;
22
22
  var DEFAULT_PUBDATA_BYTES = 155n;
23
23
  var DEFAULT_ABI_BYTES = 400n;
24
- var SAFE_L1_BRIDGE_GAS = 600000n;
24
+ var SAFE_L1_BRIDGE_GAS = 700000n;
25
25
 
26
26
  // src/core/utils/addr.ts
27
27
  var isHash66 = (x) => !!x && x.startsWith("0x") && x.length === 66;
@@ -3821,6 +3821,56 @@ function ethersToGasEstimator(provider) {
3821
3821
  };
3822
3822
  }
3823
3823
 
3824
+ // src/core/errors/error-ops.ts
3825
+ function resolveMessage(op, msg) {
3826
+ if (!msg) return `Error during ${op}.`;
3827
+ return typeof msg === "function" ? msg() : msg;
3828
+ }
3829
+ function createErrorOps(decodeRevert2) {
3830
+ function toZKsyncError2(type, base, err) {
3831
+ if (isZKsyncError(err)) return err;
3832
+ const revert = decodeRevert2 ? decodeRevert2(err) : void 0;
3833
+ return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
3834
+ }
3835
+ function createErrorHandlers2(resource) {
3836
+ async function run(kind, operation, fn, opts) {
3837
+ try {
3838
+ return await fn();
3839
+ } catch (e) {
3840
+ if (isZKsyncError(e)) throw e;
3841
+ const message = resolveMessage(operation, opts?.message);
3842
+ throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
3843
+ }
3844
+ }
3845
+ function wrap2(operation, fn, opts) {
3846
+ return run("INTERNAL", operation, fn, opts);
3847
+ }
3848
+ function wrapAs9(kind, operation, fn, opts) {
3849
+ return run(kind, operation, fn, opts);
3850
+ }
3851
+ async function toResult2(operation, fn, opts) {
3852
+ try {
3853
+ const value = await wrap2(operation, fn, opts);
3854
+ return { ok: true, value };
3855
+ } catch (e) {
3856
+ const shaped = isZKsyncError(e) ? e : toZKsyncError2(
3857
+ "INTERNAL",
3858
+ {
3859
+ resource,
3860
+ operation,
3861
+ context: opts?.ctx ?? {},
3862
+ message: resolveMessage(operation, opts?.message)
3863
+ },
3864
+ e
3865
+ );
3866
+ return { ok: false, error: shaped };
3867
+ }
3868
+ }
3869
+ return { wrap: wrap2, wrapAs: wrapAs9, toResult: toResult2 };
3870
+ }
3871
+ return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
3872
+ }
3873
+
3824
3874
  // src/core/errors/withdrawal-revert-map.ts
3825
3875
  var REVERT_TO_READINESS = {
3826
3876
  // Already done
@@ -3944,51 +3994,7 @@ function classifyReadinessFromRevert(e) {
3944
3994
  }
3945
3995
 
3946
3996
  // src/adapters/ethers/errors/error-ops.ts
3947
- function toZKsyncError(type, base, err) {
3948
- if (isZKsyncError(err)) return err;
3949
- const revert = decodeRevert(err);
3950
- return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
3951
- }
3952
- function resolveMessage(op, msg) {
3953
- if (!msg) return `Error during ${op}.`;
3954
- return typeof msg === "function" ? msg() : msg;
3955
- }
3956
- function createErrorHandlers(resource) {
3957
- async function run(kind, operation, fn, opts) {
3958
- try {
3959
- return await fn();
3960
- } catch (e) {
3961
- if (isZKsyncError(e)) throw e;
3962
- const message = resolveMessage(operation, opts?.message);
3963
- throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
3964
- }
3965
- }
3966
- function wrap2(operation, fn, opts) {
3967
- return run("INTERNAL", operation, fn, opts);
3968
- }
3969
- function wrapAs9(kind, operation, fn, opts) {
3970
- return run(kind, operation, fn, opts);
3971
- }
3972
- async function toResult2(operation, fn, opts) {
3973
- try {
3974
- const value = await wrap2(operation, fn, opts);
3975
- return { ok: true, value };
3976
- } catch (e) {
3977
- const shaped = isZKsyncError(e) ? e : toZKsyncError(
3978
- "INTERNAL",
3979
- {
3980
- resource,
3981
- operation,
3982
- context: opts?.ctx ?? {},
3983
- message: resolveMessage(operation, opts?.message)
3984
- },
3985
- e
3986
- );
3987
- return { ok: false, error: shaped };
3988
- }
3989
- }
3990
- return { wrap: wrap2, wrapAs: wrapAs9, toResult: toResult2 };
3991
- }
3997
+ var { toZKsyncError, createErrorHandlers } = createErrorOps(decodeRevert);
3992
3998
 
3993
3999
  // src/adapters/ethers/resources/deposits/services/fee.ts
3994
4000
  var { wrapAs } = createErrorHandlers("deposits");
@@ -6101,6 +6107,27 @@ function createWithdrawalsResource(client, tokens, contracts) {
6101
6107
  message: "Internal error while attempting to tryFinalize withdrawal.",
6102
6108
  ctx: { l2TxHash, where: "withdrawals.tryFinalize" }
6103
6109
  });
6110
+ const tryWait = (h, opts) => toResult2(
6111
+ OP_WITHDRAWALS.tryWait,
6112
+ async () => {
6113
+ const v = await wait(h, opts);
6114
+ if (v) return v;
6115
+ throw createError("STATE", {
6116
+ resource: "withdrawals",
6117
+ operation: "withdrawals.tryWait",
6118
+ message: opts.for === "l2" ? "No L2 receipt yet; the withdrawal has not executed on L2." : "No L1 receipt yet; the withdrawal has not been included on L1.",
6119
+ context: {
6120
+ for: opts.for,
6121
+ l2TxHash: typeof h === "string" ? h : "l2TxHash" in h ? h.l2TxHash : void 0,
6122
+ where: "withdrawals.tryWait"
6123
+ }
6124
+ });
6125
+ },
6126
+ {
6127
+ message: "Internal error while waiting for withdrawal.",
6128
+ ctx: { input: h, for: opts?.for, where: "withdrawals.tryWait" }
6129
+ }
6130
+ );
6104
6131
  return {
6105
6132
  quote,
6106
6133
  tryQuote,
@@ -6111,7 +6138,8 @@ function createWithdrawalsResource(client, tokens, contracts) {
6111
6138
  status,
6112
6139
  wait,
6113
6140
  finalize,
6114
- tryFinalize
6141
+ tryFinalize,
6142
+ tryWait
6115
6143
  };
6116
6144
  }
6117
6145