@matterlabs/zksync-js 0.0.6 → 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 +171 -49
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/sdk.cjs +52 -46
- 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 +171 -49
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/sdk.cjs +52 -46
- 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-WU2LOG2A.js → chunk-EWLA4NUE.js} +5 -5
- 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-2MDK3GLO.js → chunk-KRIRXY74.js} +7 -51
- 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
package/dist/core/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { pickDepositRoute } from '../chunk-
|
|
2
|
-
export { findL1MessageSentLog, hexEq, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, normalizeL1Token, pickWithdrawRoute } from '../chunk-
|
|
3
|
-
export { makeTransportFromEthers, makeTransportFromViem, zks_exports as zksRpc } from '../chunk-
|
|
4
|
-
export { abi_exports as abi, factory_exports as errors, formatEnvelopePretty } from '../chunk-
|
|
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-
|
|
1
|
+
export { pickDepositRoute } from '../chunk-VRL6Y4YJ.js';
|
|
2
|
+
export { findL1MessageSentLog, hexEq, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, normalizeL1Token, pickWithdrawRoute } from '../chunk-P5PIWVEO.js';
|
|
3
|
+
export { makeTransportFromEthers, makeTransportFromViem, zks_exports as zksRpc } from '../chunk-WY36Z6YB.js';
|
|
4
|
+
export { abi_exports as abi, factory_exports as errors, formatEnvelopePretty } from '../chunk-GIXLOHLK.js';
|
|
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-NCR42O6O.js';
|
package/dist/core/rpc/types.d.ts
CHANGED
|
@@ -37,4 +37,9 @@ export type GenesisInput = {
|
|
|
37
37
|
executionVersion: number;
|
|
38
38
|
genesisRoot: Hex;
|
|
39
39
|
};
|
|
40
|
+
export type BlockMetadata = {
|
|
41
|
+
pubdataPricePerByte: bigint;
|
|
42
|
+
nativePrice: bigint;
|
|
43
|
+
executionVersion: number;
|
|
44
|
+
};
|
|
40
45
|
export type RpcTransport = (method: string, params?: unknown[]) => Promise<any>;
|
package/dist/core/rpc/zks.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import type { RpcTransport, ReceiptWithL2ToL1, ProofNormalized, GenesisInput } from './types';
|
|
1
|
+
import type { RpcTransport, ReceiptWithL2ToL1, ProofNormalized, GenesisInput, BlockMetadata } from './types';
|
|
2
2
|
import type { Hex, Address } from '../types/primitives';
|
|
3
3
|
/** ZKsync-specific RPC methods. */
|
|
4
4
|
export interface ZksRpc {
|
|
5
5
|
getBridgehubAddress(): Promise<Address>;
|
|
6
|
+
getBytecodeSupplierAddress(): Promise<Address>;
|
|
6
7
|
getL2ToL1LogProof(txHash: Hex, index: number): Promise<ProofNormalized>;
|
|
7
8
|
getReceiptWithL2ToL1(txHash: Hex): Promise<ReceiptWithL2ToL1 | null>;
|
|
9
|
+
getBlockMetadataByNumber(blockNumber: number): Promise<BlockMetadata | null>;
|
|
8
10
|
getGenesis(): Promise<GenesisInput>;
|
|
9
11
|
}
|
|
10
12
|
export declare function normalizeProof(p: unknown): ProofNormalized;
|
|
11
13
|
export declare function normalizeGenesis(raw: unknown): GenesisInput;
|
|
14
|
+
export declare function normalizeBlockMetadata(raw: unknown): BlockMetadata;
|
|
12
15
|
export declare function createZksRpc(transport: RpcTransport): ZksRpc;
|
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ var TX_OVERHEAD_GAS = 10000n;
|
|
|
52
52
|
var TX_MEMORY_OVERHEAD_GAS = 10n;
|
|
53
53
|
var DEFAULT_PUBDATA_BYTES = 155n;
|
|
54
54
|
var DEFAULT_ABI_BYTES = 400n;
|
|
55
|
-
var SAFE_L1_BRIDGE_GAS =
|
|
55
|
+
var SAFE_L1_BRIDGE_GAS = 700000n;
|
|
56
56
|
var L1_FEE_ESTIMATION_COEF_NUMERATOR = 12;
|
|
57
57
|
var L1_FEE_ESTIMATION_COEF_DENOMINATOR = 10;
|
|
58
58
|
|
|
@@ -4740,6 +4740,7 @@ function shapeCause(err) {
|
|
|
4740
4740
|
var zks_exports = {};
|
|
4741
4741
|
__export(zks_exports, {
|
|
4742
4742
|
createZksRpc: () => createZksRpc,
|
|
4743
|
+
normalizeBlockMetadata: () => normalizeBlockMetadata,
|
|
4743
4744
|
normalizeGenesis: () => normalizeGenesis,
|
|
4744
4745
|
normalizeProof: () => normalizeProof
|
|
4745
4746
|
});
|
|
@@ -4765,6 +4766,8 @@ var METHODS = {
|
|
|
4765
4766
|
getBridgehub: "zks_getBridgehubContract",
|
|
4766
4767
|
getL2ToL1LogProof: "zks_getL2ToL1LogProof",
|
|
4767
4768
|
getReceipt: "eth_getTransactionReceipt",
|
|
4769
|
+
getBytecodeSupplier: "zks_getBytecodeSupplierContract",
|
|
4770
|
+
getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
|
|
4768
4771
|
getGenesis: "zks_getGenesis"
|
|
4769
4772
|
};
|
|
4770
4773
|
function toHexArray(arr) {
|
|
@@ -4817,7 +4820,9 @@ function ensureHex(value, field, context) {
|
|
|
4817
4820
|
context: { field, valueType: typeof value, ...context }
|
|
4818
4821
|
});
|
|
4819
4822
|
}
|
|
4820
|
-
function ensureNumber(value, field) {
|
|
4823
|
+
function ensureNumber(value, field, opts) {
|
|
4824
|
+
const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
|
|
4825
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
|
|
4821
4826
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
4822
4827
|
if (typeof value === "bigint") return Number(value);
|
|
4823
4828
|
if (typeof value === "string" && value.trim() !== "") {
|
|
@@ -4826,8 +4831,36 @@ function ensureNumber(value, field) {
|
|
|
4826
4831
|
}
|
|
4827
4832
|
throw createError("RPC", {
|
|
4828
4833
|
resource: "zksrpc",
|
|
4829
|
-
operation
|
|
4830
|
-
message:
|
|
4834
|
+
operation,
|
|
4835
|
+
message: `${messagePrefix}: expected numeric value.`,
|
|
4836
|
+
context: { field, valueType: typeof value }
|
|
4837
|
+
});
|
|
4838
|
+
}
|
|
4839
|
+
function ensureBigInt(value, field, opts) {
|
|
4840
|
+
const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
|
|
4841
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
|
|
4842
|
+
if (typeof value === "bigint") return value;
|
|
4843
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
4844
|
+
if (!Number.isInteger(value)) {
|
|
4845
|
+
throw createError("RPC", {
|
|
4846
|
+
resource: "zksrpc",
|
|
4847
|
+
operation,
|
|
4848
|
+
message: `${messagePrefix}: expected integer value.`,
|
|
4849
|
+
context: { field, valueType: typeof value }
|
|
4850
|
+
});
|
|
4851
|
+
}
|
|
4852
|
+
return BigInt(value);
|
|
4853
|
+
}
|
|
4854
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
4855
|
+
try {
|
|
4856
|
+
return BigInt(value);
|
|
4857
|
+
} catch {
|
|
4858
|
+
}
|
|
4859
|
+
}
|
|
4860
|
+
throw createError("RPC", {
|
|
4861
|
+
resource: "zksrpc",
|
|
4862
|
+
operation,
|
|
4863
|
+
message: `${messagePrefix}: expected bigint-compatible value.`,
|
|
4831
4864
|
context: { field, valueType: typeof value }
|
|
4832
4865
|
});
|
|
4833
4866
|
}
|
|
@@ -4913,6 +4946,57 @@ function normalizeGenesis(raw) {
|
|
|
4913
4946
|
});
|
|
4914
4947
|
}
|
|
4915
4948
|
}
|
|
4949
|
+
function normalizeBlockMetadata(raw) {
|
|
4950
|
+
try {
|
|
4951
|
+
if (!raw || typeof raw !== "object") {
|
|
4952
|
+
throw createError("RPC", {
|
|
4953
|
+
resource: "zksrpc",
|
|
4954
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4955
|
+
message: "Malformed block metadata response: expected object.",
|
|
4956
|
+
context: { receivedType: typeof raw }
|
|
4957
|
+
});
|
|
4958
|
+
}
|
|
4959
|
+
const record = raw;
|
|
4960
|
+
const pubdataPricePerByte = ensureBigInt(
|
|
4961
|
+
record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
|
|
4962
|
+
"pubdata_price_per_byte",
|
|
4963
|
+
{
|
|
4964
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4965
|
+
messagePrefix: "Malformed block metadata response"
|
|
4966
|
+
}
|
|
4967
|
+
);
|
|
4968
|
+
const nativePrice = ensureBigInt(
|
|
4969
|
+
record["native_price"] ?? record["nativePrice"],
|
|
4970
|
+
"native_price",
|
|
4971
|
+
{
|
|
4972
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4973
|
+
messagePrefix: "Malformed block metadata response"
|
|
4974
|
+
}
|
|
4975
|
+
);
|
|
4976
|
+
const executionVersion = ensureNumber(
|
|
4977
|
+
record["execution_version"] ?? record["executionVersion"],
|
|
4978
|
+
"execution_version",
|
|
4979
|
+
{
|
|
4980
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4981
|
+
messagePrefix: "Malformed block metadata response"
|
|
4982
|
+
}
|
|
4983
|
+
);
|
|
4984
|
+
return {
|
|
4985
|
+
pubdataPricePerByte,
|
|
4986
|
+
nativePrice,
|
|
4987
|
+
executionVersion
|
|
4988
|
+
};
|
|
4989
|
+
} catch (e) {
|
|
4990
|
+
if (isZKsyncError(e)) throw e;
|
|
4991
|
+
throw createError("RPC", {
|
|
4992
|
+
resource: "zksrpc",
|
|
4993
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4994
|
+
message: "Failed to normalize block metadata response.",
|
|
4995
|
+
context: { receivedType: typeof raw },
|
|
4996
|
+
cause: shapeCause(e)
|
|
4997
|
+
});
|
|
4998
|
+
}
|
|
4999
|
+
}
|
|
4916
5000
|
function createZksRpc(transport) {
|
|
4917
5001
|
return {
|
|
4918
5002
|
// Fetches the Bridgehub contract address.
|
|
@@ -4935,6 +5019,26 @@ function createZksRpc(transport) {
|
|
|
4935
5019
|
}
|
|
4936
5020
|
);
|
|
4937
5021
|
},
|
|
5022
|
+
// Fetches the Bytecode Supplier contract address.
|
|
5023
|
+
async getBytecodeSupplierAddress() {
|
|
5024
|
+
return withRpcOp(
|
|
5025
|
+
"zksrpc.getBytecodeSupplierAddress",
|
|
5026
|
+
"Failed to fetch Bytecode Supplier address.",
|
|
5027
|
+
{},
|
|
5028
|
+
async () => {
|
|
5029
|
+
const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
|
|
5030
|
+
if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
|
|
5031
|
+
throw createError("RPC", {
|
|
5032
|
+
resource: "zksrpc",
|
|
5033
|
+
operation: "zksrpc.getBytecodeSupplierAddress",
|
|
5034
|
+
message: "Unexpected Bytecode Supplier address response.",
|
|
5035
|
+
context: { valueType: typeof addrRaw }
|
|
5036
|
+
});
|
|
5037
|
+
}
|
|
5038
|
+
return addrRaw;
|
|
5039
|
+
}
|
|
5040
|
+
);
|
|
5041
|
+
},
|
|
4938
5042
|
// Fetches a proof for an L2→L1 log emitted in the given transaction.
|
|
4939
5043
|
async getL2ToL1LogProof(txHash, index) {
|
|
4940
5044
|
return withRpcOp(
|
|
@@ -4971,6 +5075,19 @@ function createZksRpc(transport) {
|
|
|
4971
5075
|
}
|
|
4972
5076
|
);
|
|
4973
5077
|
},
|
|
5078
|
+
// Fetches block metadata for the given block number.
|
|
5079
|
+
async getBlockMetadataByNumber(blockNumber) {
|
|
5080
|
+
return withRpcOp(
|
|
5081
|
+
"zksrpc.getBlockMetadataByNumber",
|
|
5082
|
+
"Failed to fetch block metadata.",
|
|
5083
|
+
{ blockNumber },
|
|
5084
|
+
async () => {
|
|
5085
|
+
const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
|
|
5086
|
+
if (raw == null) return null;
|
|
5087
|
+
return normalizeBlockMetadata(raw);
|
|
5088
|
+
}
|
|
5089
|
+
);
|
|
5090
|
+
},
|
|
4974
5091
|
// Fetches the genesis configuration returned by `zks_getGenesis`.
|
|
4975
5092
|
async getGenesis() {
|
|
4976
5093
|
return withRpcOp(
|