@matterlabs/zksync-js 0.0.25 → 0.0.26

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.
@@ -1,5 +1,5 @@
1
- export { createViemSdk } from '../../chunk-NFRRRT5X.js';
2
- import '../../chunk-JWN26CQ6.js';
1
+ export { createViemSdk } from '../../chunk-VVDJFIXV.js';
2
+ import '../../chunk-FMBQ7PVA.js';
3
3
  import '../../chunk-BQ2YCWV2.js';
4
4
  import '../../chunk-OEUDZFXH.js';
5
5
  import '../../chunk-H5A6GU3D.js';
@@ -228,10 +228,28 @@ function toGasOverrides(overrides) {
228
228
  }
229
229
 
230
230
  // src/core/resources/deposits/priority.ts
231
+ var ZK_CHAIN_PRICING_GETTERS_ABI = [
232
+ {
233
+ type: "function",
234
+ name: "getZKsyncOS",
235
+ stateMutability: "view",
236
+ inputs: [],
237
+ outputs: [{ name: "", type: "bool" }]
238
+ },
239
+ {
240
+ type: "function",
241
+ name: "getPubdataPricingMode",
242
+ stateMutability: "view",
243
+ inputs: [],
244
+ outputs: [{ name: "", type: "uint8" }]
245
+ }
246
+ ];
247
+ var PUBDATA_PRICING_MODE_ROLLUP = 0;
231
248
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
232
249
  var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
233
250
  var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
234
251
  var PRIORITY_L2_GAS_BUFFER = 40n;
252
+ var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
235
253
  var maxBigInt2 = (a, b) => a > b ? a : b;
236
254
  var ceilDiv = (a, b) => (a + b - 1n) / b;
237
255
  function applyL1ToL2Alias(address) {
@@ -278,6 +296,16 @@ function clampPriorityL2GasLimit(input) {
278
296
  })
279
297
  );
280
298
  }
299
+ function resolveBaseTokenPriorityL2GasLimit(input) {
300
+ if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
301
+ return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
302
+ }
303
+ if (!input.chargesPubdata) return input.priorityFloorGasLimit;
304
+ return maxBigInt2(
305
+ input.priorityFloorGasLimit,
306
+ applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
307
+ );
308
+ }
281
309
  function resolveRegisteredTokenPriorityL2GasLimit(input) {
282
310
  if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
283
311
  return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
@@ -702,4 +730,4 @@ async function quoteL2Gas2(input) {
702
730
  }
703
731
  }
704
732
 
705
- export { DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, ZERO_HASH, applyL1ToL2Alias, applyPriorityL2GasLimitBuffer, assertProtocolVersion, buildDirectBundle, buildFeeBreakdown, buildFinalizationInfo, buildIndirectBundle, clampPriorityL2GasLimit, createAttributesResource, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, isInteropFinalizationInfo, parseBundleReceiptInfo, parseBundleSentFromReceipt, pickInteropRoute, preflightDirect, preflightIndirect, quoteL1Fees, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, resolveCreateDepositL1GasLimit, resolveIdsFromWaitable, resolveRegisteredTokenPriorityL2GasLimit, toGasOverrides };
733
+ export { DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, PUBDATA_PRICING_MODE_ROLLUP, ZERO_HASH, ZK_CHAIN_PRICING_GETTERS_ABI, applyL1ToL2Alias, applyPriorityL2GasLimitBuffer, assertProtocolVersion, buildDirectBundle, buildFeeBreakdown, buildFinalizationInfo, buildIndirectBundle, clampPriorityL2GasLimit, createAttributesResource, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, isInteropFinalizationInfo, parseBundleReceiptInfo, parseBundleSentFromReceipt, pickInteropRoute, preflightDirect, preflightIndirect, quoteL1Fees, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, resolveBaseTokenPriorityL2GasLimit, resolveCreateDepositL1GasLimit, resolveIdsFromWaitable, resolveRegisteredTokenPriorityL2GasLimit, toGasOverrides };
@@ -1,10 +1,10 @@
1
- import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, quoteL2Gas, quoteL1Fees, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-JWN26CQ6.js';
1
+ import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, resolveBaseTokenPriorityL2GasLimit, quoteL2Gas, quoteL1Fees, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, ZK_CHAIN_PRICING_GETTERS_ABI, PUBDATA_PRICING_MODE_ROLLUP, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-FMBQ7PVA.js';
2
2
  import { detectWithdrawalProtocol, buildWithdrawalFinalization, parseBundleHashFromLogs, classifyWithdrawalOutcome, phaseFromReadiness, buildWithdrawalBundle } from './chunk-BQ2YCWV2.js';
3
3
  import { findL1MessageSentLog, messengerLogIndex, l1MessageSentSender, pickWithdrawRoute } from './chunk-OEUDZFXH.js';
4
4
  import { createErrorHandlers, toZKsyncError, classifyReadinessFromRevert } from './chunk-H5A6GU3D.js';
5
5
  import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, OP_WITHDRAWALS, createError, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, IBridgehub_default, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, IBaseToken_default, assertNever } from './chunk-JNS4XZE2.js';
6
6
  import { ETH_ADDRESS, TOPIC_CANONICAL_ASSIGNED, TOPIC_CANONICAL_SUCCESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L1_MESSENGER_ADDRESS, L2_INTEROP_ROOT_STORAGE_ADDRESS, BUFFER, SAFE_L1_BRIDGE_GAS, L2_ASSET_ROUTER_ADDRESS, FORMAL_ETH_ADDRESS, ZKSYNC_OS_PRIORITY_TX_TYPE } from './chunk-3IPSDGHO.js';
7
- import { keccak256, encodeAbiParameters, toBytes, encodeFunctionData, concat, decodeEventLog, createWalletClient, custom, decodeAbiParameters, createPublicClient, http, encodeEventTopics, numberToHex, zeroAddress, getAddress, toHex } from 'viem';
7
+ import { keccak256, encodeAbiParameters, toBytes, encodeFunctionData, concat, decodeEventLog, createWalletClient, custom, decodeAbiParameters, createPublicClient, http, encodeEventTopics, numberToHex, zeroAddress, getAddress, toHex, BaseError, ContractFunctionRevertedError } from 'viem';
8
8
 
9
9
  // src/adapters/viem/resources/deposits/context.ts
10
10
  async function commonCtx(p, client, tokens, contracts) {
@@ -97,8 +97,6 @@ function buildDirectRequestStruct(args) {
97
97
  refundRecipient: args.refundRecipient
98
98
  };
99
99
  }
100
-
101
- // src/adapters/viem/estimator.ts
102
100
  function toCoreTx(tx) {
103
101
  return {
104
102
  to: tx.to,
@@ -157,6 +155,7 @@ function viemToGasEstimator(client) {
157
155
  from: tx.from,
158
156
  to: tx.to,
159
157
  data: tx.data,
158
+ ...tx.value != null ? { value: toHex(tx.value) } : {},
160
159
  type: ZKSYNC_OS_PRIORITY_TX_TYPE
161
160
  }
162
161
  ]
@@ -205,6 +204,48 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
205
204
  return void 0;
206
205
  }
207
206
  }
207
+ async function resolvePriorityTxL2Sender(ctx) {
208
+ try {
209
+ const code = await ctx.client.l1.getCode({ address: ctx.sender });
210
+ if (!code || code === "0x") return ctx.sender;
211
+ } catch {
212
+ }
213
+ return applyL1ToL2Alias(ctx.sender);
214
+ }
215
+ var chainPricingCache = /* @__PURE__ */ new WeakMap();
216
+ var isContractRevert = (err) => err instanceof BaseError && err.walk((e) => e instanceof ContractFunctionRevertedError) != null;
217
+ async function readChainPricing(ctx) {
218
+ const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
219
+ if (cached) return cached;
220
+ try {
221
+ const zkChain = await ctx.client.l1.readContract({
222
+ address: ctx.bridgehub,
223
+ abi: IBridgehub_default,
224
+ functionName: "getZKChain",
225
+ args: [ctx.chainIdL2]
226
+ });
227
+ const read = (functionName) => ctx.client.l1.readContract({
228
+ address: zkChain,
229
+ abi: ZK_CHAIN_PRICING_GETTERS_ABI,
230
+ functionName
231
+ });
232
+ let zksyncOS;
233
+ try {
234
+ zksyncOS = await read("getZKsyncOS");
235
+ } catch (err) {
236
+ if (!isContractRevert(err)) throw err;
237
+ zksyncOS = false;
238
+ }
239
+ const chargesPubdata = zksyncOS && Number(await read("getPubdataPricingMode")) === PUBDATA_PRICING_MODE_ROLLUP;
240
+ const pricing = { zksyncOS, chargesPubdata };
241
+ const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
242
+ perClient.set(ctx.chainIdL2, pricing);
243
+ chainPricingCache.set(ctx.client, perClient);
244
+ return pricing;
245
+ } catch {
246
+ return void 0;
247
+ }
248
+ }
208
249
  async function quoteL1Fees2(input) {
209
250
  const { ctx } = input;
210
251
  return wrapAs(
@@ -241,6 +282,26 @@ async function quoteL2Gas3(input) {
241
282
  stateOverrides: input.stateOverrides
242
283
  });
243
284
  }
285
+ async function determineBaseL2GasLimit(input) {
286
+ const { ctx } = input;
287
+ if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
288
+ const [pricing, from] = await Promise.all([
289
+ readChainPricing(ctx),
290
+ resolvePriorityTxL2Sender(ctx)
291
+ ]);
292
+ if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
293
+ return resolveBaseTokenPriorityL2GasLimit({
294
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
295
+ gasPerPubdata: ctx.gasPerPubdata,
296
+ chargesPubdata: pricing?.chargesPubdata ?? true,
297
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
298
+ from,
299
+ to: input.l2Contract,
300
+ data: input.l2Calldata,
301
+ value: input.l2Value
302
+ })
303
+ });
304
+ }
244
305
  async function determineNonBaseL2Gas(input) {
245
306
  const { ctx, l1Token, route } = input;
246
307
  const fallbackQuote = () => quoteL2Gas3({
@@ -412,13 +473,19 @@ function routeEthDirect() {
412
473
  l2Calldata,
413
474
  gasPerPubdata: ctx.gasPerPubdata
414
475
  });
415
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
416
- gasLimit: applyPriorityL2GasLimitBuffer({
417
- chainIdL2: ctx.chainIdL2,
418
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
419
- }),
476
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
477
+ ctx,
478
+ l2Contract,
479
+ l2Value,
420
480
  l2Calldata,
421
- gasPerPubdata: ctx.gasPerPubdata
481
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
482
+ gasLimit: applyPriorityL2GasLimitBuffer({
483
+ chainIdL2: ctx.chainIdL2,
484
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
485
+ }),
486
+ l2Calldata,
487
+ gasPerPubdata: ctx.gasPerPubdata
488
+ })
422
489
  });
423
490
  const l2GasParams = await quoteL2Gas3({
424
491
  ctx,
@@ -1224,13 +1291,19 @@ function routeErc20Base() {
1224
1291
  l2Calldata,
1225
1292
  gasPerPubdata: ctx.gasPerPubdata
1226
1293
  });
1227
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
1228
- gasLimit: applyPriorityL2GasLimitBuffer({
1229
- chainIdL2: ctx.chainIdL2,
1230
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
1231
- }),
1294
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
1295
+ ctx,
1296
+ l2Contract,
1297
+ l2Value,
1232
1298
  l2Calldata,
1233
- gasPerPubdata: ctx.gasPerPubdata
1299
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
1300
+ gasLimit: applyPriorityL2GasLimitBuffer({
1301
+ chainIdL2: ctx.chainIdL2,
1302
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
1303
+ }),
1304
+ l2Calldata,
1305
+ gasPerPubdata: ctx.gasPerPubdata
1306
+ })
1234
1307
  });
1235
1308
  const l2Gas = await quoteL2Gas3({
1236
1309
  ctx,
@@ -1,10 +1,10 @@
1
1
  import { createErrorHandlers, toZKsyncError, classifyReadinessFromRevert } from './chunk-RZH7HBH3.js';
2
- import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, quoteL2Gas, quoteL1Fees, quoteL2BaseCost, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-JWN26CQ6.js';
2
+ import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, resolveBaseTokenPriorityL2GasLimit, quoteL2Gas, quoteL1Fees, quoteL2BaseCost, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, ZK_CHAIN_PRICING_GETTERS_ABI, PUBDATA_PRICING_MODE_ROLLUP, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-FMBQ7PVA.js';
3
3
  import { detectWithdrawalProtocol, buildWithdrawalFinalization, parseBundleHashFromLogs, classifyWithdrawalOutcome, phaseFromReadiness, buildWithdrawalBundle } from './chunk-BQ2YCWV2.js';
4
4
  import { findL1MessageSentLog, messengerLogIndex, l1MessageSentSender, pickWithdrawRoute } from './chunk-OEUDZFXH.js';
5
- import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, createError, OP_WITHDRAWALS, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, assertNever } from './chunk-JNS4XZE2.js';
5
+ import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, createError, OP_WITHDRAWALS, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, assertNever, IBridgehub_default } from './chunk-JNS4XZE2.js';
6
6
  import { ETH_ADDRESS, TOPIC_CANONICAL_ASSIGNED, TOPIC_CANONICAL_SUCCESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L1_MESSENGER_ADDRESS, L2_INTEROP_ROOT_STORAGE_ADDRESS, BUFFER, SAFE_L1_BRIDGE_GAS, L2_ASSET_ROUTER_ADDRESS, FORMAL_ETH_ADDRESS, ZKSYNC_OS_PRIORITY_TX_TYPE } from './chunk-3IPSDGHO.js';
7
- import { Interface, keccak256, AbiCoder, ethers, getBytes, Contract, NonceManager, JsonRpcProvider, getAddress, concat, hexlify, toBeArray, toBeHex, isError } from 'ethers';
7
+ import { Interface, keccak256, AbiCoder, ethers, getBytes, Contract, NonceManager, JsonRpcProvider, getAddress, concat, hexlify, toBeArray, toBeHex, toQuantity, isError } from 'ethers';
8
8
 
9
9
  var I_BRIDGEHUB = new Interface([
10
10
  "event NewPriorityRequest(uint256 indexed chainId, address indexed sender, bytes32 txHash, uint256 txId, bytes data)"
@@ -145,8 +145,6 @@ function buildDirectRequestStruct(args) {
145
145
  refundRecipient: args.refundRecipient
146
146
  };
147
147
  }
148
-
149
- // src/adapters/ethers/estimator.ts
150
148
  function toCoreTx(tx) {
151
149
  return {
152
150
  to: tx.to,
@@ -196,7 +194,13 @@ function ethersToGasEstimator(provider) {
196
194
  throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
197
195
  }
198
196
  const result = await provider.send("eth_estimateGas", [
199
- { from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
197
+ {
198
+ from: tx.from,
199
+ to: tx.to,
200
+ data: tx.data,
201
+ ...tx.value != null ? { value: toQuantity(tx.value) } : {},
202
+ type: ZKSYNC_OS_PRIORITY_TX_TYPE
203
+ }
200
204
  ]);
201
205
  return BigInt(result);
202
206
  },
@@ -248,8 +252,6 @@ async function quoteL2BaseCost2(input) {
248
252
  { ctx: { chainIdL2: ctx.chainIdL2 } }
249
253
  );
250
254
  }
251
-
252
- // src/adapters/ethers/resources/deposits/services/gas.ts
253
255
  var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
254
256
  var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
255
257
  var ZERO_L2_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
@@ -261,6 +263,39 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
261
263
  return void 0;
262
264
  }
263
265
  }
266
+ async function resolvePriorityTxL2Sender(ctx) {
267
+ try {
268
+ const code = await ctx.client.l1.getCode(ctx.sender);
269
+ if (!code || code === "0x") return ctx.sender;
270
+ } catch {
271
+ }
272
+ return applyL1ToL2Alias(ctx.sender);
273
+ }
274
+ var chainPricingCache = /* @__PURE__ */ new WeakMap();
275
+ async function readChainPricing(ctx) {
276
+ const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
277
+ if (cached) return cached;
278
+ try {
279
+ const bridgehub = new Contract(ctx.bridgehub, IBridgehub_default, ctx.client.l1);
280
+ const zkChainAddress = await bridgehub.getZKChain(ctx.chainIdL2);
281
+ const zkChain = new Contract(zkChainAddress, ZK_CHAIN_PRICING_GETTERS_ABI, ctx.client.l1);
282
+ let zksyncOS;
283
+ try {
284
+ zksyncOS = await zkChain.getZKsyncOS();
285
+ } catch (err) {
286
+ if (!isError(err, "CALL_EXCEPTION")) throw err;
287
+ zksyncOS = false;
288
+ }
289
+ const chargesPubdata = zksyncOS && Number(await zkChain.getPubdataPricingMode()) === PUBDATA_PRICING_MODE_ROLLUP;
290
+ const pricing = { zksyncOS, chargesPubdata };
291
+ const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
292
+ perClient.set(ctx.chainIdL2, pricing);
293
+ chainPricingCache.set(ctx.client, perClient);
294
+ return pricing;
295
+ } catch {
296
+ return void 0;
297
+ }
298
+ }
264
299
  async function quoteL1Fees2(input) {
265
300
  const { ctx } = input;
266
301
  return wrapAs2(
@@ -296,6 +331,26 @@ async function quoteL2Gas3(input) {
296
331
  stateOverrides: input.stateOverrides
297
332
  });
298
333
  }
334
+ async function determineBaseL2GasLimit(input) {
335
+ const { ctx } = input;
336
+ if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
337
+ const [pricing, from] = await Promise.all([
338
+ readChainPricing(ctx),
339
+ resolvePriorityTxL2Sender(ctx)
340
+ ]);
341
+ if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
342
+ return resolveBaseTokenPriorityL2GasLimit({
343
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
344
+ gasPerPubdata: ctx.gasPerPubdata,
345
+ chargesPubdata: pricing?.chargesPubdata ?? true,
346
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
347
+ from,
348
+ to: input.l2Contract,
349
+ data: input.l2Calldata,
350
+ value: input.l2Value
351
+ })
352
+ });
353
+ }
299
354
  async function determineNonBaseL2Gas(input) {
300
355
  const { ctx, l1Token, route } = input;
301
356
  const fallbackQuote = () => quoteL2Gas3({
@@ -428,13 +483,19 @@ function routeEthDirect() {
428
483
  l2Calldata,
429
484
  gasPerPubdata: ctx.gasPerPubdata
430
485
  });
431
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
432
- gasLimit: applyPriorityL2GasLimitBuffer({
433
- chainIdL2: ctx.chainIdL2,
434
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
435
- }),
486
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
487
+ ctx,
488
+ l2Contract,
489
+ l2Value,
436
490
  l2Calldata,
437
- gasPerPubdata: ctx.gasPerPubdata
491
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
492
+ gasLimit: applyPriorityL2GasLimitBuffer({
493
+ chainIdL2: ctx.chainIdL2,
494
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
495
+ }),
496
+ l2Calldata,
497
+ gasPerPubdata: ctx.gasPerPubdata
498
+ })
438
499
  });
439
500
  const l2GasParams = await quoteL2Gas3({
440
501
  ctx,
@@ -1047,13 +1108,19 @@ function routeErc20Base() {
1047
1108
  l2Calldata,
1048
1109
  gasPerPubdata: ctx.gasPerPubdata
1049
1110
  });
1050
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
1051
- gasLimit: applyPriorityL2GasLimitBuffer({
1052
- chainIdL2: ctx.chainIdL2,
1053
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
1054
- }),
1111
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
1112
+ ctx,
1113
+ l2Contract,
1114
+ l2Value,
1055
1115
  l2Calldata,
1056
- gasPerPubdata: ctx.gasPerPubdata
1116
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
1117
+ gasLimit: applyPriorityL2GasLimitBuffer({
1118
+ chainIdL2: ctx.chainIdL2,
1119
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
1120
+ }),
1121
+ l2Calldata,
1122
+ gasPerPubdata: ctx.gasPerPubdata
1123
+ })
1057
1124
  });
1058
1125
  const l2GasParams = await quoteL2Gas3({
1059
1126
  ctx,
@@ -13,6 +13,39 @@ export type PriorityTxL2Leg = {
13
13
  from: Address;
14
14
  to: Address;
15
15
  data: `0x${string}`;
16
+ value?: bigint;
17
+ };
18
+ /**
19
+ * Getters on a chain's L1 contract (era-contracts `Getters` facet) that decide how a base-token
20
+ * deposit's L2 gas limit is sized. Kept local: the public ABI registry feeds generated typechain.
21
+ */
22
+ export declare const ZK_CHAIN_PRICING_GETTERS_ABI: readonly [{
23
+ readonly type: "function";
24
+ readonly name: "getZKsyncOS";
25
+ readonly stateMutability: "view";
26
+ readonly inputs: readonly [];
27
+ readonly outputs: readonly [{
28
+ readonly name: "";
29
+ readonly type: "bool";
30
+ }];
31
+ }, {
32
+ readonly type: "function";
33
+ readonly name: "getPubdataPricingMode";
34
+ readonly stateMutability: "view";
35
+ readonly inputs: readonly [];
36
+ readonly outputs: readonly [{
37
+ readonly name: "";
38
+ readonly type: "uint8";
39
+ }];
40
+ }];
41
+ /** `PubdataPricingMode.Rollup` in era-contracts `Config.sol`; `Validium` is 1. */
42
+ export declare const PUBDATA_PRICING_MODE_ROLLUP = 0;
43
+ /** How a chain prices a deposit, read once from its L1 contract. */
44
+ export type ChainPricing = {
45
+ /** Runs ZKsync OS. EraVM chains cannot simulate priority txs and are sized by the floor. */
46
+ zksyncOS: boolean;
47
+ /** Charges pubdata per byte (rollup), so a deposit creating accounts costs more. */
48
+ chargesPubdata: boolean;
16
49
  };
17
50
  export declare const DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
18
51
  export declare function applyL1ToL2Alias(address: Address): Address;
@@ -58,6 +91,19 @@ export declare function clampPriorityL2GasLimit(input: {
58
91
  l2Calldata: `0x${string}`;
59
92
  gasPerPubdata: bigint;
60
93
  }): bigint;
94
+ /**
95
+ * `l2GasLimit` for a base-token deposit (`requestL2TransactionDirect`) on a ZKsync OS chain.
96
+ * The validator floor only covers L1-side validation. The L2 call and its pubdata, such as first
97
+ * writes for a fresh aliased sender, come from the node's priority-tx estimate. Without one, a
98
+ * chain that charges pubdata (rollup) gets the worst measured case of a deposit creating accounts;
99
+ * a validium charges a flat amount the floor already covers.
100
+ */
101
+ export declare function resolveBaseTokenPriorityL2GasLimit(input: {
102
+ priorityFloorGasLimit: bigint;
103
+ gasPerPubdata: bigint;
104
+ chargesPubdata: boolean;
105
+ nodeEstimate?: bigint;
106
+ }): bigint;
61
107
  /**
62
108
  * `l2GasLimit` for finalizing a deposit of a token that already exists on L2.
63
109
  * The validator floor only covers L1-side validation, so the real execution comes from the node's
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterlabs/zksync-js",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "devDependencies": {