@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.
- package/dist/adapters/ethers/client.cjs +170 -48
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +6 -6
- package/dist/adapters/ethers/errors/error-ops.d.ts +26 -19
- package/dist/adapters/ethers/index.cjs +194 -50
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/resources/withdrawals/index.d.ts +11 -0
- package/dist/adapters/ethers/sdk.cjs +75 -47
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +7 -7
- package/dist/adapters/viem/client.cjs +119 -3
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.js +4 -4
- package/dist/adapters/viem/errors/error-ops.d.ts +26 -19
- package/dist/adapters/viem/index.cjs +194 -50
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/resources/withdrawals/index.d.ts +11 -0
- package/dist/adapters/viem/sdk.cjs +75 -47
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-YUK547UF.js → chunk-7VP6742W.js} +3 -3
- package/dist/{chunk-NBJEQAOE.js → chunk-EWLA4NUE.js} +28 -6
- package/dist/{chunk-M5J2MM2U.js → chunk-GIXLOHLK.js} +1 -1
- package/dist/{chunk-XRE7H466.js → chunk-GNERKUWO.js} +3 -47
- package/dist/chunk-KAMEGD6I.js +75 -0
- package/dist/{chunk-JXUFGIJG.js → chunk-KRIRXY74.js} +30 -52
- package/dist/{chunk-F2ENUV3A.js → chunk-NCR42O6O.js} +1 -1
- package/dist/{chunk-3MRGU4HV.js → chunk-NGXRO2ZX.js} +4 -4
- package/dist/{chunk-LL3WKCFJ.js → chunk-NNFWIAVG.js} +2 -2
- package/dist/{chunk-NEC2ZKHI.js → chunk-P5PIWVEO.js} +1 -1
- package/dist/{chunk-NTEIA5KA.js → chunk-VRL6Y4YJ.js} +1 -1
- package/dist/{chunk-6K6VJQAL.js → chunk-WY36Z6YB.js} +122 -5
- package/dist/core/constants.cjs +1 -1
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/errors/error-ops.d.ts +18 -0
- package/dist/core/index.cjs +120 -3
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +5 -5
- package/dist/core/rpc/types.d.ts +5 -0
- package/dist/core/rpc/zks.d.ts +4 -1
- package/dist/index.cjs +121 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-NCAIVYBR.js +0 -23
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { buildDirectRequestStruct, classifyReadinessFromRevert, createContractsResource, createDepositsResource, createErrorHandlers, createFinalizationServices, createTokensResource, createViemSdk, createWithdrawalsResource, decodeRevert, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, registerErrorAbi, toZKsyncError } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
export { createViemClient as createClient, createViemClient } from '../../chunk-
|
|
6
|
-
import '../../chunk-
|
|
7
|
-
import '../../chunk-
|
|
8
|
-
import '../../chunk-
|
|
1
|
+
export { buildDirectRequestStruct, classifyReadinessFromRevert, createContractsResource, createDepositsResource, createErrorHandlers, createFinalizationServices, createTokensResource, createViemSdk, createWithdrawalsResource, decodeRevert, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, registerErrorAbi, toZKsyncError } from '../../chunk-KRIRXY74.js';
|
|
2
|
+
import '../../chunk-NNFWIAVG.js';
|
|
3
|
+
import '../../chunk-P5PIWVEO.js';
|
|
4
|
+
import '../../chunk-KAMEGD6I.js';
|
|
5
|
+
export { createViemClient as createClient, createViemClient } from '../../chunk-7VP6742W.js';
|
|
6
|
+
import '../../chunk-WY36Z6YB.js';
|
|
7
|
+
import '../../chunk-GIXLOHLK.js';
|
|
8
|
+
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;
|
|
@@ -3703,7 +3703,7 @@ var TX_OVERHEAD_GAS = 10000n;
|
|
|
3703
3703
|
var TX_MEMORY_OVERHEAD_GAS = 10n;
|
|
3704
3704
|
var DEFAULT_PUBDATA_BYTES = 155n;
|
|
3705
3705
|
var DEFAULT_ABI_BYTES = 400n;
|
|
3706
|
-
var SAFE_L1_BRIDGE_GAS =
|
|
3706
|
+
var SAFE_L1_BRIDGE_GAS = 700000n;
|
|
3707
3707
|
|
|
3708
3708
|
// src/adapters/viem/resources/utils.ts
|
|
3709
3709
|
function encodeSecondBridgeArgs(token, amount, l2Receiver) {
|
|
@@ -4054,6 +4054,56 @@ function shapeCause(err) {
|
|
|
4054
4054
|
};
|
|
4055
4055
|
}
|
|
4056
4056
|
|
|
4057
|
+
// src/core/errors/error-ops.ts
|
|
4058
|
+
function resolveMessage(op, msg) {
|
|
4059
|
+
if (!msg) return `Error during ${op}.`;
|
|
4060
|
+
return typeof msg === "function" ? msg() : msg;
|
|
4061
|
+
}
|
|
4062
|
+
function createErrorOps(decodeRevert2) {
|
|
4063
|
+
function toZKsyncError2(type, base, err) {
|
|
4064
|
+
if (isZKsyncError(err)) return err;
|
|
4065
|
+
const revert = decodeRevert2 ? decodeRevert2(err) : void 0;
|
|
4066
|
+
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
4067
|
+
}
|
|
4068
|
+
function createErrorHandlers2(resource) {
|
|
4069
|
+
async function run(kind, operation, fn, opts) {
|
|
4070
|
+
try {
|
|
4071
|
+
return await fn();
|
|
4072
|
+
} catch (e) {
|
|
4073
|
+
if (isZKsyncError(e)) throw e;
|
|
4074
|
+
const message = resolveMessage(operation, opts?.message);
|
|
4075
|
+
throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
function wrap2(operation, fn, opts) {
|
|
4079
|
+
return run("INTERNAL", operation, fn, opts);
|
|
4080
|
+
}
|
|
4081
|
+
function wrapAs10(kind, operation, fn, opts) {
|
|
4082
|
+
return run(kind, operation, fn, opts);
|
|
4083
|
+
}
|
|
4084
|
+
async function toResult2(operation, fn, opts) {
|
|
4085
|
+
try {
|
|
4086
|
+
const value = await wrap2(operation, fn, opts);
|
|
4087
|
+
return { ok: true, value };
|
|
4088
|
+
} catch (e) {
|
|
4089
|
+
const shaped = isZKsyncError(e) ? e : toZKsyncError2(
|
|
4090
|
+
"INTERNAL",
|
|
4091
|
+
{
|
|
4092
|
+
resource,
|
|
4093
|
+
operation,
|
|
4094
|
+
context: opts?.ctx ?? {},
|
|
4095
|
+
message: resolveMessage(operation, opts?.message)
|
|
4096
|
+
},
|
|
4097
|
+
e
|
|
4098
|
+
);
|
|
4099
|
+
return { ok: false, error: shaped };
|
|
4100
|
+
}
|
|
4101
|
+
}
|
|
4102
|
+
return { wrap: wrap2, wrapAs: wrapAs10, toResult: toResult2 };
|
|
4103
|
+
}
|
|
4104
|
+
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
4105
|
+
}
|
|
4106
|
+
|
|
4057
4107
|
// src/core/errors/withdrawal-revert-map.ts
|
|
4058
4108
|
var REVERT_TO_READINESS = {
|
|
4059
4109
|
// Already done
|
|
@@ -4177,51 +4227,7 @@ function classifyReadinessFromRevert(e) {
|
|
|
4177
4227
|
}
|
|
4178
4228
|
|
|
4179
4229
|
// src/adapters/viem/errors/error-ops.ts
|
|
4180
|
-
|
|
4181
|
-
if (isZKsyncError(err)) return err;
|
|
4182
|
-
const revert = decodeRevert(err);
|
|
4183
|
-
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
4184
|
-
}
|
|
4185
|
-
function resolveMessage(op, msg) {
|
|
4186
|
-
if (!msg) return `Error during ${op}.`;
|
|
4187
|
-
return typeof msg === "function" ? msg() : msg;
|
|
4188
|
-
}
|
|
4189
|
-
function createErrorHandlers(resource) {
|
|
4190
|
-
async function run(kind, operation, fn, opts) {
|
|
4191
|
-
try {
|
|
4192
|
-
return await fn();
|
|
4193
|
-
} catch (e) {
|
|
4194
|
-
if (isZKsyncError(e)) throw e;
|
|
4195
|
-
const message = resolveMessage(operation, opts?.message);
|
|
4196
|
-
throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
4197
|
-
}
|
|
4198
|
-
}
|
|
4199
|
-
function wrap2(operation, fn, opts) {
|
|
4200
|
-
return run("INTERNAL", operation, fn, opts);
|
|
4201
|
-
}
|
|
4202
|
-
function wrapAs10(kind, operation, fn, opts) {
|
|
4203
|
-
return run(kind, operation, fn, opts);
|
|
4204
|
-
}
|
|
4205
|
-
async function toResult2(operation, fn, opts) {
|
|
4206
|
-
try {
|
|
4207
|
-
const value = await wrap2(operation, fn, opts);
|
|
4208
|
-
return { ok: true, value };
|
|
4209
|
-
} catch (e) {
|
|
4210
|
-
const shaped = isZKsyncError(e) ? e : toZKsyncError(
|
|
4211
|
-
"INTERNAL",
|
|
4212
|
-
{
|
|
4213
|
-
resource,
|
|
4214
|
-
operation,
|
|
4215
|
-
context: opts?.ctx ?? {},
|
|
4216
|
-
message: resolveMessage(operation, opts?.message)
|
|
4217
|
-
},
|
|
4218
|
-
e
|
|
4219
|
-
);
|
|
4220
|
-
return { ok: false, error: shaped };
|
|
4221
|
-
}
|
|
4222
|
-
}
|
|
4223
|
-
return { wrap: wrap2, wrapAs: wrapAs10, toResult: toResult2 };
|
|
4224
|
-
}
|
|
4230
|
+
var { toZKsyncError, createErrorHandlers } = createErrorOps(decodeRevert);
|
|
4225
4231
|
|
|
4226
4232
|
// src/core/resources/deposits/gas.ts
|
|
4227
4233
|
function makeGasQuote(p) {
|
|
@@ -6976,6 +6982,27 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
6976
6982
|
message: "Internal error while attempting to tryFinalize withdrawal.",
|
|
6977
6983
|
ctx: { l2TxHash, where: "withdrawals.tryFinalize" }
|
|
6978
6984
|
});
|
|
6985
|
+
const tryWait = (h, opts) => toResult2(
|
|
6986
|
+
OP_WITHDRAWALS.tryWait,
|
|
6987
|
+
async () => {
|
|
6988
|
+
const v = await wait(h, opts);
|
|
6989
|
+
if (v) return v;
|
|
6990
|
+
throw createError("STATE", {
|
|
6991
|
+
resource: "withdrawals",
|
|
6992
|
+
operation: "withdrawals.tryWait",
|
|
6993
|
+
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.",
|
|
6994
|
+
context: {
|
|
6995
|
+
for: opts.for,
|
|
6996
|
+
l2TxHash: typeof h === "string" ? h : "l2TxHash" in h ? h.l2TxHash : void 0,
|
|
6997
|
+
where: "withdrawals.tryWait"
|
|
6998
|
+
}
|
|
6999
|
+
});
|
|
7000
|
+
},
|
|
7001
|
+
{
|
|
7002
|
+
message: "Internal error while waiting for withdrawal.",
|
|
7003
|
+
ctx: { input: h, for: opts?.for, where: "withdrawals.tryWait" }
|
|
7004
|
+
}
|
|
7005
|
+
);
|
|
6979
7006
|
return {
|
|
6980
7007
|
quote,
|
|
6981
7008
|
tryQuote,
|
|
@@ -6986,7 +7013,8 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
6986
7013
|
status,
|
|
6987
7014
|
wait,
|
|
6988
7015
|
finalize,
|
|
6989
|
-
tryFinalize
|
|
7016
|
+
tryFinalize,
|
|
7017
|
+
tryWait
|
|
6990
7018
|
};
|
|
6991
7019
|
}
|
|
6992
7020
|
|