@matterlabs/zksync-js 0.0.13 → 0.0.15
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 +13 -4
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.d.ts +1 -2
- package/dist/adapters/ethers/client.js +6 -6
- package/dist/adapters/ethers/index.cjs +607 -259
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/resources/deposits/routes/priority.d.ts +12 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +4 -0
- package/dist/adapters/ethers/resources/interop/index.d.ts +14 -14
- package/dist/adapters/ethers/resources/interop/resolvers.d.ts +3 -8
- package/dist/adapters/ethers/resources/interop/routes/types.d.ts +2 -1
- package/dist/adapters/ethers/resources/interop/services/erc20.d.ts +10 -0
- package/dist/adapters/ethers/resources/interop/services/fee.d.ts +12 -0
- package/dist/adapters/ethers/resources/interop/services/finalization/index.d.ts +1 -1
- package/dist/adapters/ethers/resources/interop/services/finalization/polling.d.ts +1 -1
- package/dist/adapters/ethers/resources/interop/services/gas.d.ts +12 -0
- package/dist/adapters/ethers/resources/interop/types.d.ts +6 -14
- package/dist/adapters/ethers/sdk.cjs +1008 -259
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.d.ts +6 -1
- package/dist/adapters/ethers/sdk.js +7 -7
- package/dist/adapters/viem/client.cjs +795 -7
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.d.ts +6 -1
- package/dist/adapters/viem/client.js +6 -6
- package/dist/adapters/viem/index.cjs +6490 -2799
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.d.ts +5 -0
- package/dist/adapters/viem/index.js +9 -9
- package/dist/adapters/viem/resources/deposits/routes/priority.d.ts +13 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +4 -0
- package/dist/adapters/viem/resources/interop/address.d.ts +18 -0
- package/dist/adapters/viem/resources/interop/attributes/resource.d.ts +6 -0
- package/dist/adapters/viem/resources/interop/context.d.ts +31 -0
- package/dist/adapters/viem/resources/interop/index.d.ts +62 -0
- package/dist/adapters/viem/resources/interop/resolvers.d.ts +4 -0
- package/dist/adapters/viem/resources/interop/routes/direct.d.ts +2 -0
- package/dist/adapters/viem/resources/interop/routes/indirect.d.ts +2 -0
- package/dist/adapters/viem/resources/interop/routes/types.d.ts +23 -0
- package/dist/adapters/viem/resources/interop/services/erc20.d.ts +25 -0
- package/dist/adapters/viem/resources/interop/services/fee.d.ts +12 -0
- package/dist/adapters/viem/resources/interop/services/finalization/bundle.d.ts +15 -0
- package/dist/adapters/viem/resources/interop/services/finalization/data-fetchers.d.ts +17 -0
- package/dist/adapters/viem/resources/interop/services/finalization/decoders.d.ts +11 -0
- package/dist/adapters/viem/resources/interop/services/finalization/index.d.ts +13 -0
- package/dist/adapters/viem/resources/interop/services/finalization/polling.d.ts +7 -0
- package/dist/adapters/viem/resources/interop/services/finalization/status.d.ts +5 -0
- package/dist/adapters/viem/resources/interop/services/finalization/topics.d.ts +4 -0
- package/dist/adapters/viem/resources/interop/services/gas.d.ts +12 -0
- package/dist/adapters/viem/resources/interop/services/starter-data.d.ts +6 -0
- package/dist/adapters/viem/resources/interop/types.d.ts +8 -0
- package/dist/adapters/viem/sdk.cjs +6401 -2758
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.d.ts +8 -1
- package/dist/adapters/viem/sdk.js +7 -7
- package/dist/{chunk-E3KP7XCG.js → chunk-3HHUZXSV.js} +1 -1
- package/dist/{chunk-EDWBCPO3.js → chunk-4PZCNTQ3.js} +1387 -71
- package/dist/{chunk-UDBRUBEK.js → chunk-65HAYKVL.js} +2 -2
- package/dist/chunk-BWKWWLY4.js +9 -0
- package/dist/{chunk-JHO2UQ5F.js → chunk-HGB3DOV2.js} +445 -554
- package/dist/{chunk-HI64OOAR.js → chunk-HVHMLAYH.js} +1 -1
- package/dist/{chunk-2RIARDXZ.js → chunk-JHRYNLZG.js} +65 -7
- package/dist/{chunk-RI73VJSH.js → chunk-JXR5V5YK.js} +463 -27
- package/dist/chunk-K2UVKMLN.js +658 -0
- package/dist/{chunk-53MC5BR2.js → chunk-MDPX5LNW.js} +1 -1
- package/dist/{chunk-QQ2OR434.js → chunk-MT4X5FEO.js} +18 -2
- package/dist/{chunk-R5WRFPK2.js → chunk-MZBKM3GH.js} +4 -4
- package/dist/{chunk-5R7L5NM5.js → chunk-YIWXIP2M.js} +10 -2
- package/dist/core/constants.cjs +17 -1
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +9 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +52 -24
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +5 -5
- package/dist/core/internal/abis/IERC7786Attributes.d.ts +21 -11
- package/dist/core/internal/abis/IInteropCenter.d.ts +4 -0
- package/dist/core/resources/deposits/chains.d.ts +1 -0
- package/dist/core/resources/deposits/gas.d.ts +7 -0
- package/dist/core/resources/deposits/priority.d.ts +41 -0
- package/dist/core/resources/interop/attributes/bundle.d.ts +1 -0
- package/dist/core/resources/interop/attributes/resource.d.ts +1 -0
- package/dist/core/resources/interop/plan.d.ts +11 -3
- package/dist/core/resources/interop/protocol.d.ts +3 -0
- package/dist/core/rpc/types.d.ts +1 -0
- package/dist/core/rpc/zks.d.ts +5 -1
- package/dist/core/types/errors.d.ts +5 -0
- package/dist/core/types/flows/interop.d.ts +11 -20
- package/dist/core/types/primitives.d.ts +2 -0
- package/dist/index.cjs +69 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-4S4XDA4N.js +0 -415
- package/dist/chunk-5L6EYUJB.js +0 -237
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { pickDepositRoute } from './chunk-
|
|
2
|
-
export { findL1MessageSentLog, isL1MessageSentLog, messengerLogIndex, pickWithdrawRoute } from './chunk-
|
|
3
|
-
export { makeTransportFromEthers, makeTransportFromViem
|
|
4
|
-
export { abi_exports as abi, factory_exports as errors, formatEnvelopePretty, hexEq, isAddress, isAddressEq, isETH, isHash, isHash66, isHash66Array, isHashArray, normalizeAddrEq, normalizeL1Token } from './chunk-
|
|
5
|
-
export { constants_exports as constants } from './chunk-
|
|
1
|
+
export { pickDepositRoute } from './chunk-HVHMLAYH.js';
|
|
2
|
+
export { findL1MessageSentLog, isL1MessageSentLog, messengerLogIndex, pickWithdrawRoute } from './chunk-3HHUZXSV.js';
|
|
3
|
+
export { makeTransportFromEthers, makeTransportFromViem } from './chunk-BWKWWLY4.js';
|
|
4
|
+
export { abi_exports as abi, factory_exports as errors, formatEnvelopePretty, hexEq, isAddress, isAddressEq, isETH, isHash, isHash66, isHash66Array, isHashArray, normalizeAddrEq, normalizeL1Token, zks_exports as zksRpc } from './chunk-JXR5V5YK.js';
|
|
5
|
+
export { constants_exports as constants } from './chunk-MT4X5FEO.js';
|
package/package.json
CHANGED
package/dist/chunk-4S4XDA4N.js
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import { createError, isBigint, isNumber, isZKsyncError, shapeCause } from './chunk-RI73VJSH.js';
|
|
2
|
-
import { __export } from './chunk-QQ2OR434.js';
|
|
3
|
-
|
|
4
|
-
// src/core/rpc/zks.ts
|
|
5
|
-
var zks_exports = {};
|
|
6
|
-
__export(zks_exports, {
|
|
7
|
-
createZksRpc: () => createZksRpc,
|
|
8
|
-
normalizeBlockMetadata: () => normalizeBlockMetadata,
|
|
9
|
-
normalizeGenesis: () => normalizeGenesis,
|
|
10
|
-
normalizeProof: () => normalizeProof
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// src/core/errors/rpc.ts
|
|
14
|
-
async function withRpcOp(operation, message, ctx, fn) {
|
|
15
|
-
try {
|
|
16
|
-
return await fn();
|
|
17
|
-
} catch (e) {
|
|
18
|
-
if (isZKsyncError(e)) throw e;
|
|
19
|
-
throw createError("RPC", {
|
|
20
|
-
resource: "zksrpc",
|
|
21
|
-
operation,
|
|
22
|
-
message,
|
|
23
|
-
context: ctx,
|
|
24
|
-
cause: shapeCause(e)
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/core/rpc/zks.ts
|
|
30
|
-
var METHODS = {
|
|
31
|
-
getBridgehub: "zks_getBridgehubContract",
|
|
32
|
-
getL2ToL1LogProof: "zks_getL2ToL1LogProof",
|
|
33
|
-
getReceipt: "eth_getTransactionReceipt",
|
|
34
|
-
getBytecodeSupplier: "zks_getBytecodeSupplierContract",
|
|
35
|
-
getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
|
|
36
|
-
getGenesis: "zks_getGenesis"
|
|
37
|
-
};
|
|
38
|
-
function toHexArray(arr) {
|
|
39
|
-
const list = Array.isArray(arr) ? arr : [];
|
|
40
|
-
return list.map((x) => x);
|
|
41
|
-
}
|
|
42
|
-
function normalizeProof(p) {
|
|
43
|
-
try {
|
|
44
|
-
const raw = p ?? {};
|
|
45
|
-
const idRaw = raw?.id ?? raw?.index;
|
|
46
|
-
const bnRaw = raw?.batch_number ?? raw?.batchNumber;
|
|
47
|
-
if (idRaw == null || bnRaw == null) {
|
|
48
|
-
throw createError("RPC", {
|
|
49
|
-
resource: "zksrpc",
|
|
50
|
-
operation: "zksrpc.normalizeProof",
|
|
51
|
-
message: "Malformed proof: missing id or batch number.",
|
|
52
|
-
context: { keys: Object.keys(raw ?? {}) }
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
const toBig = (x) => isBigint(x) ? x : isNumber(x) ? BigInt(x) : typeof x === "string" ? BigInt(x) : (() => {
|
|
56
|
-
throw createError("RPC", {
|
|
57
|
-
resource: "zksrpc",
|
|
58
|
-
operation: "zksrpc.normalizeProof",
|
|
59
|
-
message: "Malformed proof: invalid numeric field.",
|
|
60
|
-
context: { valueType: typeof x }
|
|
61
|
-
});
|
|
62
|
-
})();
|
|
63
|
-
return {
|
|
64
|
-
id: toBig(idRaw),
|
|
65
|
-
batchNumber: toBig(bnRaw),
|
|
66
|
-
proof: toHexArray(raw?.proof),
|
|
67
|
-
root: raw.root
|
|
68
|
-
};
|
|
69
|
-
} catch (e) {
|
|
70
|
-
if (isZKsyncError(e)) throw e;
|
|
71
|
-
throw createError("RPC", {
|
|
72
|
-
resource: "zksrpc",
|
|
73
|
-
operation: "zksrpc.normalizeProof",
|
|
74
|
-
message: "Failed to normalize proof.",
|
|
75
|
-
context: { receivedType: typeof p },
|
|
76
|
-
cause: shapeCause(e)
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function ensureHex(value, field, context) {
|
|
81
|
-
if (typeof value === "string" && value.startsWith("0x")) return value;
|
|
82
|
-
throw createError("RPC", {
|
|
83
|
-
resource: "zksrpc",
|
|
84
|
-
operation: "zksrpc.normalizeGenesis",
|
|
85
|
-
message: "Malformed genesis response: expected 0x-prefixed hex value.",
|
|
86
|
-
context: { field, valueType: typeof value, ...context }
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function ensureNumber(value, field, opts) {
|
|
90
|
-
const operation = opts?.operation;
|
|
91
|
-
const messagePrefix = opts?.messagePrefix;
|
|
92
|
-
if (isNumber(value)) return value;
|
|
93
|
-
if (isBigint(value)) return Number(value);
|
|
94
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
95
|
-
const parsed = Number(value);
|
|
96
|
-
if (Number.isFinite(parsed)) return parsed;
|
|
97
|
-
}
|
|
98
|
-
throw createError("RPC", {
|
|
99
|
-
resource: "zksrpc",
|
|
100
|
-
operation,
|
|
101
|
-
message: `${messagePrefix}: expected numeric value.`,
|
|
102
|
-
context: { field, valueType: typeof value }
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function ensureBigInt(value, field, opts) {
|
|
106
|
-
const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
|
|
107
|
-
const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
|
|
108
|
-
if (isBigint(value)) return value;
|
|
109
|
-
if (isNumber(value)) {
|
|
110
|
-
if (!Number.isInteger(value)) {
|
|
111
|
-
throw createError("RPC", {
|
|
112
|
-
resource: "zksrpc",
|
|
113
|
-
operation,
|
|
114
|
-
message: `${messagePrefix}: expected integer value.`,
|
|
115
|
-
context: { field, valueType: typeof value }
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return BigInt(value);
|
|
119
|
-
}
|
|
120
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
121
|
-
try {
|
|
122
|
-
return BigInt(value);
|
|
123
|
-
} catch {
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
throw createError("RPC", {
|
|
127
|
-
resource: "zksrpc",
|
|
128
|
-
operation,
|
|
129
|
-
message: `${messagePrefix}: expected bigint-compatible value.`,
|
|
130
|
-
context: { field, valueType: typeof value }
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function isRecord(x) {
|
|
134
|
-
return !!x && typeof x === "object" && !Array.isArray(x);
|
|
135
|
-
}
|
|
136
|
-
function normalizeContractTuple(tuple, index) {
|
|
137
|
-
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
138
|
-
throw createError("RPC", {
|
|
139
|
-
resource: "zksrpc",
|
|
140
|
-
operation: "zksrpc.normalizeGenesis",
|
|
141
|
-
message: "Malformed genesis response: invalid contract tuple.",
|
|
142
|
-
context: { index, valueType: typeof tuple }
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
const [addrRaw, bytecodeRaw] = tuple;
|
|
146
|
-
return {
|
|
147
|
-
address: ensureHex(addrRaw, "initial_contracts.address", { index }),
|
|
148
|
-
bytecode: ensureHex(bytecodeRaw, "initial_contracts.bytecode", { index })
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function normalizeRawStorageTuple(tuple, index) {
|
|
152
|
-
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
153
|
-
throw createError("RPC", {
|
|
154
|
-
resource: "zksrpc",
|
|
155
|
-
operation: "zksrpc.normalizeGenesis",
|
|
156
|
-
message: "Malformed genesis response: invalid storage tuple.",
|
|
157
|
-
context: { index, valueType: typeof tuple }
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
const [keyRaw, valueRaw] = tuple;
|
|
161
|
-
return {
|
|
162
|
-
format: "raw",
|
|
163
|
-
key: ensureHex(keyRaw, "additional_storage.key", { index }),
|
|
164
|
-
value: ensureHex(valueRaw, "additional_storage.value", { index })
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function normalizeAdditionalStorage(value, record) {
|
|
168
|
-
const effective = value ?? record["additional_storage_raw"];
|
|
169
|
-
if (Array.isArray(effective)) {
|
|
170
|
-
return effective.map((entry, index) => {
|
|
171
|
-
const kv = normalizeRawStorageTuple(entry, index);
|
|
172
|
-
return { format: "raw", key: kv.key, value: kv.value };
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
if (isRecord(effective)) {
|
|
176
|
-
const out = [];
|
|
177
|
-
for (const [addrRaw, slotsRaw] of Object.entries(effective)) {
|
|
178
|
-
const address = ensureHex(addrRaw, "additional_storage.address", {});
|
|
179
|
-
if (!isRecord(slotsRaw)) {
|
|
180
|
-
throw createError("RPC", {
|
|
181
|
-
resource: "zksrpc",
|
|
182
|
-
operation: "zksrpc.normalizeGenesis",
|
|
183
|
-
message: "Malformed genesis response: additional_storage[address] must be an object map.",
|
|
184
|
-
context: { address, valueType: typeof slotsRaw }
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
for (const [slotRaw, valRaw] of Object.entries(slotsRaw)) {
|
|
188
|
-
out.push({
|
|
189
|
-
format: "pretty",
|
|
190
|
-
address,
|
|
191
|
-
key: ensureHex(slotRaw, "additional_storage.key", { address }),
|
|
192
|
-
value: ensureHex(valRaw, "additional_storage.value", { address, key: slotRaw })
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return out;
|
|
197
|
-
}
|
|
198
|
-
throw createError("RPC", {
|
|
199
|
-
resource: "zksrpc",
|
|
200
|
-
operation: "zksrpc.normalizeGenesis",
|
|
201
|
-
message: "Malformed genesis response: additional_storage must be an array (raw) or an object map (pretty).",
|
|
202
|
-
context: {
|
|
203
|
-
valueType: typeof effective,
|
|
204
|
-
hasAdditionalStorage: "additional_storage" in record,
|
|
205
|
-
hasAdditionalStorageRaw: "additional_storage_raw" in record
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function normalizeGenesis(raw) {
|
|
210
|
-
try {
|
|
211
|
-
if (!raw || typeof raw !== "object") {
|
|
212
|
-
throw createError("RPC", {
|
|
213
|
-
resource: "zksrpc",
|
|
214
|
-
operation: "zksrpc.normalizeGenesis",
|
|
215
|
-
message: "Malformed genesis response: expected object.",
|
|
216
|
-
context: { receivedType: typeof raw }
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
const record = raw;
|
|
220
|
-
const contractsRaw = record["initial_contracts"];
|
|
221
|
-
if (!Array.isArray(contractsRaw)) {
|
|
222
|
-
throw createError("RPC", {
|
|
223
|
-
resource: "zksrpc",
|
|
224
|
-
operation: "zksrpc.normalizeGenesis",
|
|
225
|
-
message: "Malformed genesis response: initial_contracts must be an array.",
|
|
226
|
-
context: { valueType: typeof contractsRaw }
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
const genesisRoot = ensureHex(record["genesis_root"], "genesis_root", {});
|
|
230
|
-
const initialContracts = contractsRaw.map(
|
|
231
|
-
(entry, index) => normalizeContractTuple(entry, index)
|
|
232
|
-
);
|
|
233
|
-
const additionalStorage = normalizeAdditionalStorage(record["additional_storage"], record);
|
|
234
|
-
return {
|
|
235
|
-
initialContracts,
|
|
236
|
-
additionalStorage,
|
|
237
|
-
genesisRoot
|
|
238
|
-
};
|
|
239
|
-
} catch (e) {
|
|
240
|
-
if (isZKsyncError(e)) throw e;
|
|
241
|
-
throw createError("RPC", {
|
|
242
|
-
resource: "zksrpc",
|
|
243
|
-
operation: "zksrpc.normalizeGenesis",
|
|
244
|
-
message: "Failed to normalize genesis response.",
|
|
245
|
-
context: { receivedType: typeof raw },
|
|
246
|
-
cause: shapeCause(e)
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
function normalizeBlockMetadata(raw) {
|
|
251
|
-
try {
|
|
252
|
-
if (!raw || typeof raw !== "object") {
|
|
253
|
-
throw createError("RPC", {
|
|
254
|
-
resource: "zksrpc",
|
|
255
|
-
operation: "zksrpc.normalizeBlockMetadata",
|
|
256
|
-
message: "Malformed block metadata response: expected object.",
|
|
257
|
-
context: { receivedType: typeof raw }
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
const record = raw;
|
|
261
|
-
const pubdataPricePerByte = ensureBigInt(
|
|
262
|
-
record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
|
|
263
|
-
"pubdata_price_per_byte",
|
|
264
|
-
{
|
|
265
|
-
operation: "zksrpc.normalizeBlockMetadata",
|
|
266
|
-
messagePrefix: "Malformed block metadata response"
|
|
267
|
-
}
|
|
268
|
-
);
|
|
269
|
-
const nativePrice = ensureBigInt(
|
|
270
|
-
record["native_price"] ?? record["nativePrice"],
|
|
271
|
-
"native_price",
|
|
272
|
-
{
|
|
273
|
-
operation: "zksrpc.normalizeBlockMetadata",
|
|
274
|
-
messagePrefix: "Malformed block metadata response"
|
|
275
|
-
}
|
|
276
|
-
);
|
|
277
|
-
const executionVersion = ensureNumber(
|
|
278
|
-
record["execution_version"] ?? record["executionVersion"],
|
|
279
|
-
"execution_version",
|
|
280
|
-
{
|
|
281
|
-
operation: "zksrpc.normalizeBlockMetadata",
|
|
282
|
-
messagePrefix: "Malformed block metadata response"
|
|
283
|
-
}
|
|
284
|
-
);
|
|
285
|
-
return {
|
|
286
|
-
pubdataPricePerByte,
|
|
287
|
-
nativePrice,
|
|
288
|
-
executionVersion
|
|
289
|
-
};
|
|
290
|
-
} catch (e) {
|
|
291
|
-
if (isZKsyncError(e)) throw e;
|
|
292
|
-
throw createError("RPC", {
|
|
293
|
-
resource: "zksrpc",
|
|
294
|
-
operation: "zksrpc.normalizeBlockMetadata",
|
|
295
|
-
message: "Failed to normalize block metadata response.",
|
|
296
|
-
context: { receivedType: typeof raw },
|
|
297
|
-
cause: shapeCause(e)
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
function createZksRpc(transport) {
|
|
302
|
-
return {
|
|
303
|
-
// Fetches the Bridgehub contract address.
|
|
304
|
-
async getBridgehubAddress() {
|
|
305
|
-
return withRpcOp(
|
|
306
|
-
"zksrpc.getBridgehubAddress",
|
|
307
|
-
"Failed to fetch Bridgehub address.",
|
|
308
|
-
{},
|
|
309
|
-
async () => {
|
|
310
|
-
const addrRaw = await transport(METHODS.getBridgehub, []);
|
|
311
|
-
if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
|
|
312
|
-
throw createError("RPC", {
|
|
313
|
-
resource: "zksrpc",
|
|
314
|
-
operation: "zksrpc.getBridgehubAddress",
|
|
315
|
-
message: "Unexpected Bridgehub address response.",
|
|
316
|
-
context: { valueType: typeof addrRaw }
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
return addrRaw;
|
|
320
|
-
}
|
|
321
|
-
);
|
|
322
|
-
},
|
|
323
|
-
// Fetches the Bytecode Supplier contract address.
|
|
324
|
-
async getBytecodeSupplierAddress() {
|
|
325
|
-
return withRpcOp(
|
|
326
|
-
"zksrpc.getBytecodeSupplierAddress",
|
|
327
|
-
"Failed to fetch Bytecode Supplier address.",
|
|
328
|
-
{},
|
|
329
|
-
async () => {
|
|
330
|
-
const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
|
|
331
|
-
if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
|
|
332
|
-
throw createError("RPC", {
|
|
333
|
-
resource: "zksrpc",
|
|
334
|
-
operation: "zksrpc.getBytecodeSupplierAddress",
|
|
335
|
-
message: "Unexpected Bytecode Supplier address response.",
|
|
336
|
-
context: { valueType: typeof addrRaw }
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
return addrRaw;
|
|
340
|
-
}
|
|
341
|
-
);
|
|
342
|
-
},
|
|
343
|
-
// Fetches a proof for an L2→L1 log emitted in the given transaction.
|
|
344
|
-
async getL2ToL1LogProof(txHash, index) {
|
|
345
|
-
return withRpcOp(
|
|
346
|
-
"zksrpc.getL2ToL1LogProof",
|
|
347
|
-
"Failed to fetch L2\u2192L1 log proof.",
|
|
348
|
-
{ txHash, index },
|
|
349
|
-
async () => {
|
|
350
|
-
const proof = await transport(METHODS.getL2ToL1LogProof, [txHash, index]);
|
|
351
|
-
if (!proof) {
|
|
352
|
-
throw createError("STATE", {
|
|
353
|
-
resource: "zksrpc",
|
|
354
|
-
operation: "zksrpc.getL2ToL1LogProof",
|
|
355
|
-
message: "Proof not yet available. Please try again later.",
|
|
356
|
-
context: { txHash, index }
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
return normalizeProof(proof);
|
|
360
|
-
}
|
|
361
|
-
);
|
|
362
|
-
},
|
|
363
|
-
// Fetches the transaction receipt, including the `l2ToL1Logs` field.
|
|
364
|
-
async getReceiptWithL2ToL1(txHash) {
|
|
365
|
-
return withRpcOp(
|
|
366
|
-
"zksrpc.getReceiptWithL2ToL1",
|
|
367
|
-
"Failed to fetch transaction receipt.",
|
|
368
|
-
{ txHash },
|
|
369
|
-
async () => {
|
|
370
|
-
const rcptRaw = await transport(METHODS.getReceipt, [txHash]);
|
|
371
|
-
if (!rcptRaw) return null;
|
|
372
|
-
const rcptObj = rcptRaw;
|
|
373
|
-
const logs = Array.isArray(rcptObj["l2ToL1Logs"]) ? rcptObj["l2ToL1Logs"] : [];
|
|
374
|
-
rcptObj["l2ToL1Logs"] = logs;
|
|
375
|
-
return rcptObj;
|
|
376
|
-
}
|
|
377
|
-
);
|
|
378
|
-
},
|
|
379
|
-
// Fetches block metadata for the given block number.
|
|
380
|
-
async getBlockMetadataByNumber(blockNumber) {
|
|
381
|
-
return withRpcOp(
|
|
382
|
-
"zksrpc.getBlockMetadataByNumber",
|
|
383
|
-
"Failed to fetch block metadata.",
|
|
384
|
-
{ blockNumber },
|
|
385
|
-
async () => {
|
|
386
|
-
const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
|
|
387
|
-
if (raw == null) return null;
|
|
388
|
-
return normalizeBlockMetadata(raw);
|
|
389
|
-
}
|
|
390
|
-
);
|
|
391
|
-
},
|
|
392
|
-
// Fetches the genesis configuration returned by `zks_getGenesis`.
|
|
393
|
-
async getGenesis() {
|
|
394
|
-
return withRpcOp(
|
|
395
|
-
"zksrpc.getGenesis",
|
|
396
|
-
"Failed to fetch genesis configuration.",
|
|
397
|
-
{},
|
|
398
|
-
async () => {
|
|
399
|
-
const genesisRaw = await transport(METHODS.getGenesis, []);
|
|
400
|
-
return normalizeGenesis(genesisRaw);
|
|
401
|
-
}
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// src/core/rpc/transport.ts
|
|
408
|
-
function makeTransportFromEthers(provider) {
|
|
409
|
-
return (m, p = []) => provider.send(m, p);
|
|
410
|
-
}
|
|
411
|
-
function makeTransportFromViem(client) {
|
|
412
|
-
return (m, p = []) => client.request({ method: m, params: p });
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
export { createZksRpc, makeTransportFromEthers, makeTransportFromViem, zks_exports };
|
package/dist/chunk-5L6EYUJB.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { IBridgehub_default } from './chunk-RI73VJSH.js';
|
|
2
|
-
import { BUFFER, DEFAULT_ABI_BYTES, DEFAULT_PUBDATA_BYTES, TX_MEMORY_OVERHEAD_GAS, TX_OVERHEAD_GAS } from './chunk-QQ2OR434.js';
|
|
3
|
-
|
|
4
|
-
// src/core/codec/ntv.ts
|
|
5
|
-
function createNTVCodec(deps) {
|
|
6
|
-
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
7
|
-
const encoded = deps.encode(
|
|
8
|
-
["uint256", "address", "address"],
|
|
9
|
-
[originChainId, ntvAddress, tokenAddress]
|
|
10
|
-
);
|
|
11
|
-
return deps.keccak256(encoded);
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
encodeAssetId
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/core/types/fees.ts
|
|
19
|
-
function toGasOverrides(overrides) {
|
|
20
|
-
const { nonce: _, ...gas } = overrides;
|
|
21
|
-
return gas;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/core/resources/deposits/fee.ts
|
|
25
|
-
function buildFeeBreakdown(p) {
|
|
26
|
-
const l1MaxTotal = p.l1Gas?.maxCost ?? 0n;
|
|
27
|
-
const l2Total = p.l2BaseCost + p.operatorTip;
|
|
28
|
-
const l1 = {
|
|
29
|
-
gasLimit: p.l1Gas?.gasLimit ?? 0n,
|
|
30
|
-
maxFeePerGas: p.l1Gas?.maxFeePerGas ?? 0n,
|
|
31
|
-
maxPriorityFeePerGas: p.l1Gas?.maxPriorityFeePerGas,
|
|
32
|
-
maxTotal: l1MaxTotal
|
|
33
|
-
};
|
|
34
|
-
const l2 = {
|
|
35
|
-
total: l2Total,
|
|
36
|
-
baseCost: p.l2BaseCost,
|
|
37
|
-
operatorTip: p.operatorTip,
|
|
38
|
-
gasLimit: p.l2Gas?.gasLimit ?? 0n,
|
|
39
|
-
maxFeePerGas: p.l2Gas?.maxFeePerGas ?? 0n,
|
|
40
|
-
maxPriorityFeePerGas: p.l2Gas?.maxPriorityFeePerGas,
|
|
41
|
-
gasPerPubdata: p.l2Gas?.gasPerPubdata ?? 0n
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
token: p.feeToken,
|
|
45
|
-
maxTotal: l1MaxTotal + l2Total,
|
|
46
|
-
mintValue: p.mintValue,
|
|
47
|
-
l1,
|
|
48
|
-
l2
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/core/resources/deposits/gas.ts
|
|
53
|
-
function makeGasQuote(p) {
|
|
54
|
-
const maxPriorityFeePerGas = p.maxPriorityFeePerGas ?? 0n;
|
|
55
|
-
return {
|
|
56
|
-
gasLimit: p.gasLimit,
|
|
57
|
-
maxFeePerGas: p.maxFeePerGas,
|
|
58
|
-
maxPriorityFeePerGas,
|
|
59
|
-
gasPerPubdata: p.gasPerPubdata,
|
|
60
|
-
maxCost: p.gasLimit * p.maxFeePerGas
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async function fetchFees(estimator) {
|
|
64
|
-
try {
|
|
65
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
66
|
-
if (fees.maxFeePerGas != null) {
|
|
67
|
-
return {
|
|
68
|
-
maxFeePerGas: fees.maxFeePerGas,
|
|
69
|
-
maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (fees.gasPrice != null) {
|
|
73
|
-
return {
|
|
74
|
-
maxFeePerGas: fees.gasPrice,
|
|
75
|
-
maxPriorityFeePerGas: 0n
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
} catch {
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const gp = await estimator.getGasPrice();
|
|
82
|
-
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
83
|
-
} catch {
|
|
84
|
-
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function quoteL1Gas(input) {
|
|
88
|
-
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
89
|
-
let market;
|
|
90
|
-
const getMarket = async () => {
|
|
91
|
-
if (market) return market;
|
|
92
|
-
market = await fetchFees(estimator);
|
|
93
|
-
return market;
|
|
94
|
-
};
|
|
95
|
-
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
96
|
-
const maxPriorityFeePerGas = overrides?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : (await getMarket()).maxPriorityFeePerGas);
|
|
97
|
-
const explicitGasLimit = overrides?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
|
|
98
|
-
if (explicitGasLimit != null) {
|
|
99
|
-
return makeGasQuote({ gasLimit: explicitGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
const est = await estimator.estimateGas(tx);
|
|
103
|
-
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
104
|
-
return makeGasQuote({ gasLimit: buffered, maxFeePerGas, maxPriorityFeePerGas });
|
|
105
|
-
} catch (err) {
|
|
106
|
-
if (fallbackGasLimit != null) {
|
|
107
|
-
return makeGasQuote({ gasLimit: fallbackGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
108
|
-
}
|
|
109
|
-
console.warn("L1 gas estimation failed", err);
|
|
110
|
-
return void 0;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async function quoteL2Gas(input) {
|
|
114
|
-
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
115
|
-
const market = await fetchFees(estimator);
|
|
116
|
-
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
117
|
-
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
118
|
-
const explicit = overrideGasLimit ?? txGasLimit;
|
|
119
|
-
if (explicit != null) {
|
|
120
|
-
return makeGasQuote({
|
|
121
|
-
gasLimit: explicit,
|
|
122
|
-
maxFeePerGas,
|
|
123
|
-
gasPerPubdata
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
if (!tx) {
|
|
127
|
-
return makeGasQuote({
|
|
128
|
-
gasLimit: l2GasLimit ?? 0n,
|
|
129
|
-
maxFeePerGas,
|
|
130
|
-
gasPerPubdata
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
const execEstimate = await estimator.estimateGas(tx, stateOverrides);
|
|
135
|
-
const memoryBytes = route === "erc20-nonbase" ? 500n : DEFAULT_ABI_BYTES;
|
|
136
|
-
const pubdataBytes = route === "erc20-nonbase" ? 200n : DEFAULT_PUBDATA_BYTES;
|
|
137
|
-
const pp = gasPerPubdata ?? 800n;
|
|
138
|
-
const memoryOverhead = memoryBytes * TX_MEMORY_OVERHEAD_GAS;
|
|
139
|
-
const pubdataOverhead = pubdataBytes * pp;
|
|
140
|
-
let total = BigInt(execEstimate) + TX_OVERHEAD_GAS + memoryOverhead + pubdataOverhead;
|
|
141
|
-
total = total * (100n + BUFFER) / 100n;
|
|
142
|
-
return makeGasQuote({
|
|
143
|
-
gasLimit: total,
|
|
144
|
-
maxFeePerGas,
|
|
145
|
-
gasPerPubdata: pp
|
|
146
|
-
});
|
|
147
|
-
} catch (err) {
|
|
148
|
-
console.warn("L2 gas estimation failed", err);
|
|
149
|
-
return makeGasQuote({
|
|
150
|
-
gasLimit: l2GasLimit ?? 0n,
|
|
151
|
-
maxFeePerGas,
|
|
152
|
-
gasPerPubdata
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
async function quoteL2BaseCost(input) {
|
|
157
|
-
const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata } = input;
|
|
158
|
-
const market = await fetchFees(estimator);
|
|
159
|
-
const l1GasPrice = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
160
|
-
if (l1GasPrice === 0n) {
|
|
161
|
-
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
162
|
-
}
|
|
163
|
-
const data = encode(IBridgehub_default, "l2TransactionBaseCost", [
|
|
164
|
-
chainIdL2,
|
|
165
|
-
l1GasPrice,
|
|
166
|
-
l2GasLimit,
|
|
167
|
-
gasPerPubdata
|
|
168
|
-
]);
|
|
169
|
-
const raw = await estimator.call({
|
|
170
|
-
to: bridgehub,
|
|
171
|
-
data
|
|
172
|
-
});
|
|
173
|
-
return BigInt(raw);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// src/core/resources/withdrawals/gas.ts
|
|
177
|
-
function makeGasQuote2(p) {
|
|
178
|
-
return {
|
|
179
|
-
gasLimit: p.gasLimit,
|
|
180
|
-
maxFeePerGas: p.maxFeePerGas,
|
|
181
|
-
maxPriorityFeePerGas: p.maxPriorityFeePerGas,
|
|
182
|
-
maxCost: p.gasLimit * p.maxFeePerGas
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
async function fetchFees2(estimator) {
|
|
186
|
-
try {
|
|
187
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
188
|
-
if (fees.maxFeePerGas != null) {
|
|
189
|
-
return {
|
|
190
|
-
maxFeePerGas: fees.maxFeePerGas,
|
|
191
|
-
maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
if (fees.gasPrice != null) {
|
|
195
|
-
return {
|
|
196
|
-
maxFeePerGas: fees.gasPrice,
|
|
197
|
-
maxPriorityFeePerGas: 0n
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
} catch {
|
|
201
|
-
}
|
|
202
|
-
try {
|
|
203
|
-
const gp = await estimator.getGasPrice();
|
|
204
|
-
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
205
|
-
} catch {
|
|
206
|
-
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
async function quoteL2Gas2(input) {
|
|
210
|
-
const { estimator, tx, overrides } = input;
|
|
211
|
-
const market = await fetchFees2(estimator);
|
|
212
|
-
const o = overrides;
|
|
213
|
-
const maxFeePerGas = o?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : market.maxFeePerGas);
|
|
214
|
-
const maxPriorityFeePerGas = o?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : market.maxPriorityFeePerGas);
|
|
215
|
-
const explicitGasLimit = o?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
|
|
216
|
-
if (explicitGasLimit != null) {
|
|
217
|
-
return makeGasQuote2({
|
|
218
|
-
gasLimit: explicitGasLimit,
|
|
219
|
-
maxFeePerGas,
|
|
220
|
-
maxPriorityFeePerGas
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
const est = await estimator.estimateGas(tx);
|
|
225
|
-
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
226
|
-
return makeGasQuote2({
|
|
227
|
-
gasLimit: buffered,
|
|
228
|
-
maxFeePerGas,
|
|
229
|
-
maxPriorityFeePerGas
|
|
230
|
-
});
|
|
231
|
-
} catch (err) {
|
|
232
|
-
console.warn("Failed to estimate L2 gas for withdrawal.", err);
|
|
233
|
-
return void 0;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export { buildFeeBreakdown, createNTVCodec, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, toGasOverrides };
|