@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,6 +1,6 @@
1
- export { createEthersSdk } from '../../chunk-N5E4FLBF.js';
1
+ export { createEthersSdk } from '../../chunk-YWUBX7YE.js';
2
2
  import '../../chunk-RZH7HBH3.js';
3
- import '../../chunk-JWN26CQ6.js';
3
+ import '../../chunk-FMBQ7PVA.js';
4
4
  import '../../chunk-BQ2YCWV2.js';
5
5
  import '../../chunk-OEUDZFXH.js';
6
6
  import '../../chunk-4ZANKNIK.js';
@@ -8122,10 +8122,28 @@ async function quoteL2Gas(input) {
8122
8122
  }
8123
8123
 
8124
8124
  // src/core/resources/deposits/priority.ts
8125
+ var ZK_CHAIN_PRICING_GETTERS_ABI = [
8126
+ {
8127
+ type: "function",
8128
+ name: "getZKsyncOS",
8129
+ stateMutability: "view",
8130
+ inputs: [],
8131
+ outputs: [{ name: "", type: "bool" }]
8132
+ },
8133
+ {
8134
+ type: "function",
8135
+ name: "getPubdataPricingMode",
8136
+ stateMutability: "view",
8137
+ inputs: [],
8138
+ outputs: [{ name: "", type: "uint8" }]
8139
+ }
8140
+ ];
8141
+ var PUBDATA_PRICING_MODE_ROLLUP = 0;
8125
8142
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
8126
8143
  var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
8127
8144
  var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
8128
8145
  var PRIORITY_L2_GAS_BUFFER = 40n;
8146
+ var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
8129
8147
  var maxBigInt2 = (a, b) => a > b ? a : b;
8130
8148
  var ceilDiv = (a, b) => (a + b - 1n) / b;
8131
8149
  function applyL1ToL2Alias(address) {
@@ -8172,6 +8190,16 @@ function clampPriorityL2GasLimit(input) {
8172
8190
  })
8173
8191
  );
8174
8192
  }
8193
+ function resolveBaseTokenPriorityL2GasLimit(input) {
8194
+ if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
8195
+ return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
8196
+ }
8197
+ if (!input.chargesPubdata) return input.priorityFloorGasLimit;
8198
+ return maxBigInt2(
8199
+ input.priorityFloorGasLimit,
8200
+ applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
8201
+ );
8202
+ }
8175
8203
  function resolveRegisteredTokenPriorityL2GasLimit(input) {
8176
8204
  if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
8177
8205
  return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
@@ -8182,8 +8210,6 @@ function resolveRegisteredTokenPriorityL2GasLimit(input) {
8182
8210
  applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
8183
8211
  );
8184
8212
  }
8185
-
8186
- // src/adapters/viem/estimator.ts
8187
8213
  function toCoreTx(tx) {
8188
8214
  return {
8189
8215
  to: tx.to,
@@ -8242,6 +8268,7 @@ function viemToGasEstimator(client) {
8242
8268
  from: tx.from,
8243
8269
  to: tx.to,
8244
8270
  data: tx.data,
8271
+ ...tx.value != null ? { value: viem.toHex(tx.value) } : {},
8245
8272
  type: ZKSYNC_OS_PRIORITY_TX_TYPE
8246
8273
  }
8247
8274
  ]
@@ -8290,6 +8317,48 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
8290
8317
  return void 0;
8291
8318
  }
8292
8319
  }
8320
+ async function resolvePriorityTxL2Sender(ctx) {
8321
+ try {
8322
+ const code = await ctx.client.l1.getCode({ address: ctx.sender });
8323
+ if (!code || code === "0x") return ctx.sender;
8324
+ } catch {
8325
+ }
8326
+ return applyL1ToL2Alias(ctx.sender);
8327
+ }
8328
+ var chainPricingCache = /* @__PURE__ */ new WeakMap();
8329
+ var isContractRevert = (err) => err instanceof viem.BaseError && err.walk((e) => e instanceof viem.ContractFunctionRevertedError) != null;
8330
+ async function readChainPricing(ctx) {
8331
+ const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
8332
+ if (cached) return cached;
8333
+ try {
8334
+ const zkChain = await ctx.client.l1.readContract({
8335
+ address: ctx.bridgehub,
8336
+ abi: IBridgehub_default,
8337
+ functionName: "getZKChain",
8338
+ args: [ctx.chainIdL2]
8339
+ });
8340
+ const read = (functionName) => ctx.client.l1.readContract({
8341
+ address: zkChain,
8342
+ abi: ZK_CHAIN_PRICING_GETTERS_ABI,
8343
+ functionName
8344
+ });
8345
+ let zksyncOS;
8346
+ try {
8347
+ zksyncOS = await read("getZKsyncOS");
8348
+ } catch (err) {
8349
+ if (!isContractRevert(err)) throw err;
8350
+ zksyncOS = false;
8351
+ }
8352
+ const chargesPubdata = zksyncOS && Number(await read("getPubdataPricingMode")) === PUBDATA_PRICING_MODE_ROLLUP;
8353
+ const pricing = { zksyncOS, chargesPubdata };
8354
+ const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
8355
+ perClient.set(ctx.chainIdL2, pricing);
8356
+ chainPricingCache.set(ctx.client, perClient);
8357
+ return pricing;
8358
+ } catch {
8359
+ return void 0;
8360
+ }
8361
+ }
8293
8362
  async function quoteL1Fees2(input) {
8294
8363
  const { ctx } = input;
8295
8364
  return wrapAs(
@@ -8326,6 +8395,26 @@ async function quoteL2Gas2(input) {
8326
8395
  stateOverrides: input.stateOverrides
8327
8396
  });
8328
8397
  }
8398
+ async function determineBaseL2GasLimit(input) {
8399
+ const { ctx } = input;
8400
+ if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
8401
+ const [pricing, from] = await Promise.all([
8402
+ readChainPricing(ctx),
8403
+ resolvePriorityTxL2Sender(ctx)
8404
+ ]);
8405
+ if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
8406
+ return resolveBaseTokenPriorityL2GasLimit({
8407
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
8408
+ gasPerPubdata: ctx.gasPerPubdata,
8409
+ chargesPubdata: pricing?.chargesPubdata ?? true,
8410
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
8411
+ from,
8412
+ to: input.l2Contract,
8413
+ data: input.l2Calldata,
8414
+ value: input.l2Value
8415
+ })
8416
+ });
8417
+ }
8329
8418
  async function determineNonBaseL2Gas(input) {
8330
8419
  const { ctx, l1Token, route } = input;
8331
8420
  const fallbackQuote = () => quoteL2Gas2({
@@ -8525,13 +8614,19 @@ function routeEthDirect() {
8525
8614
  l2Calldata,
8526
8615
  gasPerPubdata: ctx.gasPerPubdata
8527
8616
  });
8528
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
8529
- gasLimit: applyPriorityL2GasLimitBuffer({
8530
- chainIdL2: ctx.chainIdL2,
8531
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
8532
- }),
8617
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
8618
+ ctx,
8619
+ l2Contract,
8620
+ l2Value,
8533
8621
  l2Calldata,
8534
- gasPerPubdata: ctx.gasPerPubdata
8622
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
8623
+ gasLimit: applyPriorityL2GasLimitBuffer({
8624
+ chainIdL2: ctx.chainIdL2,
8625
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
8626
+ }),
8627
+ l2Calldata,
8628
+ gasPerPubdata: ctx.gasPerPubdata
8629
+ })
8535
8630
  });
8536
8631
  const l2GasParams = await quoteL2Gas2({
8537
8632
  ctx,
@@ -9351,13 +9446,19 @@ function routeErc20Base() {
9351
9446
  l2Calldata,
9352
9447
  gasPerPubdata: ctx.gasPerPubdata
9353
9448
  });
9354
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
9355
- gasLimit: applyPriorityL2GasLimitBuffer({
9356
- chainIdL2: ctx.chainIdL2,
9357
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9358
- }),
9449
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
9450
+ ctx,
9451
+ l2Contract,
9452
+ l2Value,
9359
9453
  l2Calldata,
9360
- gasPerPubdata: ctx.gasPerPubdata
9454
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
9455
+ gasLimit: applyPriorityL2GasLimitBuffer({
9456
+ chainIdL2: ctx.chainIdL2,
9457
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9458
+ }),
9459
+ l2Calldata,
9460
+ gasPerPubdata: ctx.gasPerPubdata
9461
+ })
9361
9462
  });
9362
9463
  const l2Gas = await quoteL2Gas2({
9363
9464
  ctx,