@matterlabs/zksync-js 0.0.21 → 0.0.23

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.
Files changed (77) hide show
  1. package/dist/adapters/ethers/client.cjs +31 -8
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.d.ts +11 -0
  4. package/dist/adapters/ethers/client.js +6 -5
  5. package/dist/adapters/ethers/index.cjs +1194 -364
  6. package/dist/adapters/ethers/index.cjs.map +1 -1
  7. package/dist/adapters/ethers/index.d.ts +2 -1
  8. package/dist/adapters/ethers/index.js +10 -8
  9. package/dist/adapters/ethers/resources/deposits/context.d.ts +2 -0
  10. package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +3 -0
  11. package/dist/adapters/ethers/resources/withdrawals/context.d.ts +12 -1
  12. package/dist/adapters/ethers/resources/withdrawals/index.d.ts +17 -1
  13. package/dist/adapters/ethers/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
  14. package/dist/adapters/ethers/resources/withdrawals/services/finalization.d.ts +35 -17
  15. package/dist/adapters/ethers/resources/withdrawals/services/protocol.d.ts +11 -0
  16. package/dist/adapters/ethers/sdk.cjs +1166 -370
  17. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  18. package/dist/adapters/ethers/sdk.d.ts +3 -1
  19. package/dist/adapters/ethers/sdk.js +8 -7
  20. package/dist/adapters/viem/client.cjs +44 -7
  21. package/dist/adapters/viem/client.cjs.map +1 -1
  22. package/dist/adapters/viem/client.d.ts +11 -0
  23. package/dist/adapters/viem/client.js +6 -5
  24. package/dist/adapters/viem/index.cjs +1237 -383
  25. package/dist/adapters/viem/index.cjs.map +1 -1
  26. package/dist/adapters/viem/index.d.ts +2 -1
  27. package/dist/adapters/viem/index.js +10 -8
  28. package/dist/adapters/viem/resources/deposits/context.d.ts +2 -0
  29. package/dist/adapters/viem/resources/deposits/services/gas.d.ts +3 -0
  30. package/dist/adapters/viem/resources/withdrawals/context.d.ts +12 -1
  31. package/dist/adapters/viem/resources/withdrawals/index.d.ts +17 -1
  32. package/dist/adapters/viem/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
  33. package/dist/adapters/viem/resources/withdrawals/services/finalization.d.ts +36 -18
  34. package/dist/adapters/viem/resources/withdrawals/services/protocol.d.ts +11 -0
  35. package/dist/adapters/viem/sdk.cjs +1191 -385
  36. package/dist/adapters/viem/sdk.cjs.map +1 -1
  37. package/dist/adapters/viem/sdk.d.ts +3 -1
  38. package/dist/adapters/viem/sdk.js +8 -7
  39. package/dist/{chunk-UEKFQAOS.js → chunk-2DDJFHHD.js} +304 -9
  40. package/dist/{chunk-MT4X5FEO.js → chunk-3IPSDGHO.js} +19 -1
  41. package/dist/{chunk-JSBMIT4S.js → chunk-4GPIHYVF.js} +1 -1
  42. package/dist/{chunk-SBGBYZJM.js → chunk-4M7VNYGC.js} +2 -2
  43. package/dist/{chunk-CK5UFAZK.js → chunk-6WIAMFIW.js} +37 -3
  44. package/dist/chunk-JJ523MOL.js +157 -0
  45. package/dist/{chunk-7GZDTLHX.js → chunk-NVOFHV3A.js} +666 -304
  46. package/dist/{chunk-LGTYM5XP.js → chunk-OEUDZFXH.js} +1 -1
  47. package/dist/{chunk-NJK325XV.js → chunk-TUN6NH5D.js} +2 -2
  48. package/dist/chunk-UMPAKZCQ.js +19 -0
  49. package/dist/{chunk-24TE2NNJ.js → chunk-URHDNDFN.js} +24 -4
  50. package/dist/{chunk-2CGBLD5H.js → chunk-V2TDNGI5.js} +642 -288
  51. package/dist/{chunk-IDXSGCGF.js → chunk-WPCZNITC.js} +63 -50
  52. package/dist/{chunk-TYYUG5GA.js → chunk-X2JJDQ4O.js} +1 -1
  53. package/dist/core/abi.d.ts +1 -0
  54. package/dist/core/adapters/interfaces.d.ts +2 -0
  55. package/dist/core/constants.cjs +18 -0
  56. package/dist/core/constants.cjs.map +1 -1
  57. package/dist/core/constants.d.ts +17 -0
  58. package/dist/core/constants.js +1 -1
  59. package/dist/core/index.cjs +504 -7
  60. package/dist/core/index.cjs.map +1 -1
  61. package/dist/core/index.d.ts +6 -1
  62. package/dist/core/index.js +6 -4
  63. package/dist/core/internal/abis/IERC7786Attributes.d.ts +10 -0
  64. package/dist/core/internal/abis/IL1NullifierV32.d.ts +221 -0
  65. package/dist/core/internal/abis/IL2AssetRouter.d.ts +0 -14
  66. package/dist/core/resources/deposits/priority.d.ts +30 -0
  67. package/dist/core/resources/interop/attributes/bundle.d.ts +1 -0
  68. package/dist/core/resources/interop/attributes/resource.d.ts +1 -0
  69. package/dist/core/resources/protocol/semver.d.ts +18 -0
  70. package/dist/core/resources/withdrawals/bundle.d.ts +80 -0
  71. package/dist/core/resources/withdrawals/finalization.d.ts +142 -0
  72. package/dist/core/resources/withdrawals/protocol.d.ts +55 -0
  73. package/dist/core/types/flows/withdrawals.d.ts +30 -0
  74. package/dist/index.cjs +320 -7
  75. package/dist/index.cjs.map +1 -1
  76. package/dist/index.js +4 -4
  77. package/package.json +1 -1
@@ -27,6 +27,7 @@ var L1_MESSENGER_ADDRESS = "0x0000000000000000000000000000000000008008";
27
27
  var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
28
28
  var L2_INTEROP_CENTER_ADDRESS = "0x000000000000000000000000000000000001000d";
29
29
  var L2_INTEROP_ROOT_STORAGE_ADDRESS = "0x0000000000000000000000000000000000010008";
30
+ var L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS = "0x0000000000000000000000000000000000010015";
30
31
  var BUNDLE_IDENTIFIER = "0x01";
31
32
  var TOPIC_L1_MESSAGE_SENT_NEW = k256hex("L1MessageSent(uint256,bytes32,bytes)");
32
33
  var TOPIC_L1_MESSAGE_SENT_LEG = k256hex("L1MessageSent(address,bytes32,bytes)");
@@ -46,6 +47,14 @@ var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
46
47
  var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
47
48
  var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
48
49
  var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
50
+ var L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS = 21000n;
51
+ var L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS = 40n;
52
+ var L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS = 351n;
53
+ var MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS = 1n << 35n;
54
+ var L1_TX_NATIVE_PER_GAS = 100000000n;
55
+ var ZKSYNC_OS_PRIORITY_TX_TYPE = "0x7f";
56
+ var REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS = 140000n;
57
+ var REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES = 300n;
49
58
 
50
59
  // src/core/utils/number.ts
51
60
  var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
@@ -2288,6 +2297,294 @@ var IL1NullifierABI = [
2288
2297
  ];
2289
2298
  var IL1Nullifier_default = IL1NullifierABI;
2290
2299
 
2300
+ // src/core/internal/abis/IL1NullifierV32.ts
2301
+ var IL1NullifierV32ABI = [
2302
+ {
2303
+ anonymous: false,
2304
+ inputs: [
2305
+ {
2306
+ indexed: true,
2307
+ internalType: "uint256",
2308
+ name: "chainId",
2309
+ type: "uint256"
2310
+ },
2311
+ {
2312
+ indexed: true,
2313
+ internalType: "bytes32",
2314
+ name: "txDataHash",
2315
+ type: "bytes32"
2316
+ },
2317
+ {
2318
+ indexed: true,
2319
+ internalType: "bytes32",
2320
+ name: "l2DepositTxHash",
2321
+ type: "bytes32"
2322
+ }
2323
+ ],
2324
+ name: "BridgehubDepositFinalized",
2325
+ type: "event"
2326
+ },
2327
+ {
2328
+ inputs: [],
2329
+ name: "BRIDGE_HUB",
2330
+ outputs: [
2331
+ {
2332
+ internalType: "contract IL1Bridgehub",
2333
+ name: "",
2334
+ type: "address"
2335
+ }
2336
+ ],
2337
+ stateMutability: "view",
2338
+ type: "function"
2339
+ },
2340
+ {
2341
+ inputs: [],
2342
+ name: "l1AssetRouter",
2343
+ outputs: [
2344
+ {
2345
+ internalType: "contract IL1AssetRouter",
2346
+ name: "",
2347
+ type: "address"
2348
+ }
2349
+ ],
2350
+ stateMutability: "view",
2351
+ type: "function"
2352
+ },
2353
+ {
2354
+ // The contract that took over withdrawal finalization from the nullifier's own (removed)
2355
+ // `finalizeDeposit`.
2356
+ inputs: [],
2357
+ name: "l1InteropHandler",
2358
+ outputs: [
2359
+ {
2360
+ internalType: "address",
2361
+ name: "",
2362
+ type: "address"
2363
+ }
2364
+ ],
2365
+ stateMutability: "view",
2366
+ type: "function"
2367
+ },
2368
+ {
2369
+ inputs: [],
2370
+ name: "l1NativeTokenVault",
2371
+ outputs: [
2372
+ {
2373
+ internalType: "contract IL1NativeTokenVault",
2374
+ name: "",
2375
+ type: "address"
2376
+ }
2377
+ ],
2378
+ stateMutability: "view",
2379
+ type: "function"
2380
+ },
2381
+ {
2382
+ inputs: [
2383
+ {
2384
+ internalType: "uint256",
2385
+ name: "_chainId",
2386
+ type: "uint256"
2387
+ },
2388
+ {
2389
+ internalType: "bytes32",
2390
+ name: "_l2TxHash",
2391
+ type: "bytes32"
2392
+ }
2393
+ ],
2394
+ name: "depositHappened",
2395
+ outputs: [
2396
+ {
2397
+ internalType: "bytes32",
2398
+ name: "",
2399
+ type: "bytes32"
2400
+ }
2401
+ ],
2402
+ stateMutability: "view",
2403
+ type: "function"
2404
+ },
2405
+ {
2406
+ inputs: [
2407
+ {
2408
+ internalType: "uint256",
2409
+ name: "_chainId",
2410
+ type: "uint256"
2411
+ },
2412
+ {
2413
+ internalType: "bytes32",
2414
+ name: "_txDataHash",
2415
+ type: "bytes32"
2416
+ },
2417
+ {
2418
+ internalType: "bytes32",
2419
+ name: "_txHash",
2420
+ type: "bytes32"
2421
+ }
2422
+ ],
2423
+ name: "bridgehubConfirmL2TransactionForwarded",
2424
+ outputs: [],
2425
+ stateMutability: "nonpayable",
2426
+ type: "function"
2427
+ },
2428
+ {
2429
+ inputs: [
2430
+ {
2431
+ components: [
2432
+ {
2433
+ internalType: "uint256",
2434
+ name: "_chainId",
2435
+ type: "uint256"
2436
+ },
2437
+ {
2438
+ internalType: "address",
2439
+ name: "_depositSender",
2440
+ type: "address"
2441
+ },
2442
+ {
2443
+ internalType: "uint16",
2444
+ name: "_l2TxNumberInBatch",
2445
+ type: "uint16"
2446
+ },
2447
+ {
2448
+ internalType: "enum TxStatus",
2449
+ name: "_txStatus",
2450
+ type: "uint8"
2451
+ },
2452
+ {
2453
+ internalType: "bytes32",
2454
+ name: "_assetId",
2455
+ type: "bytes32"
2456
+ },
2457
+ {
2458
+ internalType: "bytes",
2459
+ name: "_assetData",
2460
+ type: "bytes"
2461
+ },
2462
+ {
2463
+ internalType: "bytes32",
2464
+ name: "_l2TxHash",
2465
+ type: "bytes32"
2466
+ },
2467
+ {
2468
+ internalType: "uint256",
2469
+ name: "_l2BatchNumber",
2470
+ type: "uint256"
2471
+ },
2472
+ {
2473
+ internalType: "uint256",
2474
+ name: "_l2MessageIndex",
2475
+ type: "uint256"
2476
+ },
2477
+ {
2478
+ internalType: "bytes32[]",
2479
+ name: "_merkleProof",
2480
+ type: "bytes32[]"
2481
+ }
2482
+ ],
2483
+ internalType: "struct ConfirmTransferResultData",
2484
+ name: "_confirmTransferResultData",
2485
+ type: "tuple"
2486
+ }
2487
+ ],
2488
+ name: "bridgeConfirmTransferResult",
2489
+ outputs: [],
2490
+ stateMutability: "nonpayable",
2491
+ type: "function"
2492
+ },
2493
+ {
2494
+ inputs: [
2495
+ {
2496
+ internalType: "uint256",
2497
+ name: "_chainId",
2498
+ type: "uint256"
2499
+ },
2500
+ {
2501
+ internalType: "address",
2502
+ name: "_depositSender",
2503
+ type: "address"
2504
+ },
2505
+ {
2506
+ internalType: "bytes32",
2507
+ name: "_assetId",
2508
+ type: "bytes32"
2509
+ },
2510
+ {
2511
+ internalType: "bytes",
2512
+ name: "_assetData",
2513
+ type: "bytes"
2514
+ },
2515
+ {
2516
+ internalType: "bytes32",
2517
+ name: "_l2TxHash",
2518
+ type: "bytes32"
2519
+ },
2520
+ {
2521
+ internalType: "uint256",
2522
+ name: "_l2BatchNumber",
2523
+ type: "uint256"
2524
+ },
2525
+ {
2526
+ internalType: "uint256",
2527
+ name: "_l2MessageIndex",
2528
+ type: "uint256"
2529
+ },
2530
+ {
2531
+ internalType: "uint16",
2532
+ name: "_l2TxNumberInBatch",
2533
+ type: "uint16"
2534
+ },
2535
+ {
2536
+ internalType: "bytes32[]",
2537
+ name: "_merkleProof",
2538
+ type: "bytes32[]"
2539
+ }
2540
+ ],
2541
+ name: "bridgeRecoverFailedTransfer",
2542
+ outputs: [],
2543
+ stateMutability: "nonpayable",
2544
+ type: "function"
2545
+ },
2546
+ {
2547
+ inputs: [
2548
+ {
2549
+ internalType: "contract IL1NativeTokenVault",
2550
+ name: "_nativeTokenVault",
2551
+ type: "address"
2552
+ }
2553
+ ],
2554
+ name: "setL1NativeTokenVault",
2555
+ outputs: [],
2556
+ stateMutability: "nonpayable",
2557
+ type: "function"
2558
+ },
2559
+ {
2560
+ inputs: [
2561
+ {
2562
+ internalType: "address",
2563
+ name: "_l1AssetRouter",
2564
+ type: "address"
2565
+ }
2566
+ ],
2567
+ name: "setL1AssetRouter",
2568
+ outputs: [],
2569
+ stateMutability: "nonpayable",
2570
+ type: "function"
2571
+ },
2572
+ {
2573
+ inputs: [
2574
+ {
2575
+ internalType: "address",
2576
+ name: "_l1InteropHandler",
2577
+ type: "address"
2578
+ }
2579
+ ],
2580
+ name: "setL1InteropHandler",
2581
+ outputs: [],
2582
+ stateMutability: "nonpayable",
2583
+ type: "function"
2584
+ }
2585
+ ];
2586
+ var IL1NullifierV32_default = IL1NullifierV32ABI;
2587
+
2291
2588
  // src/core/internal/abis/IL2AssetRouter.ts
2292
2589
  var IL2AssetRouterABI = [
2293
2590
  {
@@ -2411,13 +2708,6 @@ var IL2AssetRouterABI = [
2411
2708
  outputs: [{ name: "", type: "address", internalType: "address" }],
2412
2709
  stateMutability: "view"
2413
2710
  },
2414
- {
2415
- type: "function",
2416
- name: "l1TokenAddress",
2417
- inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
2418
- outputs: [{ name: "", type: "address", internalType: "address" }],
2419
- stateMutability: "view"
2420
- },
2421
2711
  {
2422
2712
  type: "function",
2423
2713
  name: "l2TokenAddress",
@@ -3703,7 +3993,20 @@ var IERC7786AttributesABI = [
3703
3993
  name: "indirectCall",
3704
3994
  inputs: [
3705
3995
  {
3706
- name: "_indirectCallMessageValue",
3996
+ name: "_indirectCallMessageValue",
3997
+ type: "uint256",
3998
+ internalType: "uint256"
3999
+ }
4000
+ ],
4001
+ outputs: [],
4002
+ stateMutability: "pure"
4003
+ },
4004
+ {
4005
+ type: "function",
4006
+ name: "interopCallValue",
4007
+ inputs: [
4008
+ {
4009
+ name: "_interopCallValue",
3707
4010
  type: "uint256",
3708
4011
  internalType: "uint256"
3709
4012
  }
@@ -3713,12 +4016,12 @@ var IERC7786AttributesABI = [
3713
4016
  },
3714
4017
  {
3715
4018
  type: "function",
3716
- name: "interopCallValue",
4019
+ name: "interopBundleSalt",
3717
4020
  inputs: [
3718
4021
  {
3719
- name: "_interopCallValue",
3720
- type: "uint256",
3721
- internalType: "uint256"
4022
+ name: "_salt",
4023
+ type: "bytes32",
4024
+ internalType: "bytes32"
3722
4025
  }
3723
4026
  ],
3724
4027
  outputs: [],
@@ -5858,7 +6161,7 @@ function toGasOverrides(overrides) {
5858
6161
 
5859
6162
  // src/adapters/ethers/resources/deposits/context.ts
5860
6163
  async function commonCtx(p, client, tokens, contracts) {
5861
- const { bridgehub, l1AssetRouter } = await contracts.addresses();
6164
+ const { bridgehub, l1AssetRouter, l1NativeTokenVault } = await contracts.addresses();
5862
6165
  const { chainId } = await client.l2.getNetwork();
5863
6166
  const sender = await client.signer.getAddress();
5864
6167
  const gasPerPubdata = p.gasPerPubdata ?? 800n;
@@ -5886,6 +6189,7 @@ async function commonCtx(p, client, tokens, contracts) {
5886
6189
  baseTokenL1,
5887
6190
  baseIsEth,
5888
6191
  l1AssetRouter,
6192
+ l1NativeTokenVault,
5889
6193
  route,
5890
6194
  bridgehub,
5891
6195
  chainIdL2: BigInt(chainId),
@@ -5911,9 +6215,6 @@ function encodeSecondBridgeArgs(token, amount, l2Receiver) {
5911
6215
  [token, amount, l2Receiver]
5912
6216
  );
5913
6217
  }
5914
- function encodeSecondBridgeErc20Args(token, amount, l2Receiver) {
5915
- return encodeSecondBridgeArgs(token, amount, l2Receiver);
5916
- }
5917
6218
  function encodeSecondBridgeEthArgs(amount, l2Receiver, ethToken = ETH_ADDRESS) {
5918
6219
  return encodeSecondBridgeArgs(ethToken, amount, l2Receiver);
5919
6220
  }
@@ -6123,6 +6424,15 @@ function ethersToGasEstimator(provider) {
6123
6424
  }
6124
6425
  return await provider.estimateGas(ethTx);
6125
6426
  },
6427
+ async estimatePriorityTxGas(tx) {
6428
+ if (!("send" in provider)) {
6429
+ throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
6430
+ }
6431
+ const result = await provider.send("eth_estimateGas", [
6432
+ { from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
6433
+ ]);
6434
+ return BigInt(result);
6435
+ },
6126
6436
  async estimateFeesPerGas() {
6127
6437
  const fd = await provider.getFeeData();
6128
6438
  return {
@@ -6172,7 +6482,7 @@ function createErrorOps(decodeRevert2) {
6172
6482
  function wrap7(operation, fn, opts) {
6173
6483
  return run("INTERNAL", operation, fn, opts);
6174
6484
  }
6175
- function wrapAs9(kind, operation, fn, opts) {
6485
+ function wrapAs10(kind, operation, fn, opts) {
6176
6486
  return run(kind, operation, fn, opts);
6177
6487
  }
6178
6488
  async function toResult3(operation, fn, opts) {
@@ -6193,7 +6503,7 @@ function createErrorOps(decodeRevert2) {
6193
6503
  return { ok: false, error: shaped };
6194
6504
  }
6195
6505
  }
6196
- return { wrap: wrap7, wrapAs: wrapAs9, toResult: toResult3 };
6506
+ return { wrap: wrap7, wrapAs: wrapAs10, toResult: toResult3 };
6197
6507
  }
6198
6508
  return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
6199
6509
  }
@@ -6354,9 +6664,79 @@ async function quoteL2BaseCost2(input) {
6354
6664
  );
6355
6665
  }
6356
6666
 
6667
+ // src/core/resources/deposits/priority.ts
6668
+ var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
6669
+ var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
6670
+ var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
6671
+ var PRIORITY_L2_GAS_BUFFER = 40n;
6672
+ var maxBigInt2 = (a, b) => a > b ? a : b;
6673
+ var ceilDiv = (a, b) => (a + b - 1n) / b;
6674
+ function applyL1ToL2Alias(address) {
6675
+ return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
6676
+ }
6677
+ function derivePriorityTxGasBreakdown(input) {
6678
+ const factoryDepsCount = input.factoryDepsCount ?? 0n;
6679
+ const minBodyGas = maxBigInt2(
6680
+ L1_TX_INTRINSIC_L2_GAS + ceilDiv(
6681
+ input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
6682
+ PRIORITY_TX_ENCODING_STEP_BYTES
6683
+ ) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
6684
+ L1_TX_MIN_L2_GAS_BASE
6685
+ ) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
6686
+ const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
6687
+ const derivedBodyGas = minBodyGas;
6688
+ return {
6689
+ encodedLength: input.encodedLength,
6690
+ minBodyGas,
6691
+ overhead,
6692
+ derivedBodyGas,
6693
+ derivedL2GasLimit: derivedBodyGas + overhead,
6694
+ priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
6695
+ priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
6696
+ };
6697
+ }
6698
+ function derivePriorityBodyGasEstimateCap(input) {
6699
+ return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
6700
+ }
6701
+ function applyPriorityL2GasLimitBuffer(input) {
6702
+ return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
6703
+ }
6704
+ function minimalPriorityTxL2Gas(input) {
6705
+ const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
6706
+ const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
6707
+ return maxBigInt2(intrinsic, pubdata);
6708
+ }
6709
+ function clampPriorityL2GasLimit(input) {
6710
+ return maxBigInt2(
6711
+ input.gasLimit,
6712
+ minimalPriorityTxL2Gas({
6713
+ calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
6714
+ gasPerPubdata: input.gasPerPubdata
6715
+ })
6716
+ );
6717
+ }
6718
+ function resolveRegisteredTokenPriorityL2GasLimit(input) {
6719
+ if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
6720
+ return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
6721
+ }
6722
+ const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
6723
+ return maxBigInt2(
6724
+ input.priorityFloorGasLimit,
6725
+ applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
6726
+ );
6727
+ }
6728
+
6357
6729
  // src/adapters/ethers/resources/deposits/services/gas.ts
6358
6730
  var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
6359
6731
  var ZERO_L2_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
6732
+ async function estimatePriorityTxL2Gas(ctx, leg) {
6733
+ if (!leg) return void 0;
6734
+ try {
6735
+ return await ethersToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
6736
+ } catch {
6737
+ return void 0;
6738
+ }
6739
+ }
6360
6740
  async function quoteL1Gas2(input) {
6361
6741
  const { ctx, tx, overrides, fallbackGasLimit } = input;
6362
6742
  const estimator = ethersToGasEstimator(ctx.client.l1);
@@ -6410,7 +6790,12 @@ async function determineNonBaseL2Gas(input) {
6410
6790
  return quoteL2Gas2({
6411
6791
  ctx,
6412
6792
  route,
6413
- overrideGasLimit: input.priorityFloorGasLimit
6793
+ overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
6794
+ chainIdL2: ctx.chainIdL2,
6795
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
6796
+ gasPerPubdata: ctx.gasPerPubdata,
6797
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
6798
+ })
6414
6799
  });
6415
6800
  }
6416
6801
  const modelTx = {
@@ -6447,6 +6832,7 @@ async function determineEthNonBaseL2Gas(input) {
6447
6832
  knownL2Token: input.ctx.resolvedToken?.l2,
6448
6833
  modelTx: input.modelTx,
6449
6834
  priorityFloorGasLimit: input.priorityFloorGasLimit,
6835
+ priorityTxL2Leg: input.priorityTxL2Leg,
6450
6836
  undeployedGasLimit: input.undeployedGasLimit
6451
6837
  });
6452
6838
  }
@@ -6478,40 +6864,6 @@ function buildFeeBreakdown(p) {
6478
6864
  l2
6479
6865
  };
6480
6866
  }
6481
-
6482
- // src/core/resources/deposits/priority.ts
6483
- var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
6484
- var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
6485
- var PRIORITY_L2_GAS_BUFFER = 40n;
6486
- var maxBigInt2 = (a, b) => a > b ? a : b;
6487
- var ceilDiv = (a, b) => (a + b - 1n) / b;
6488
- function derivePriorityTxGasBreakdown(input) {
6489
- const factoryDepsCount = input.factoryDepsCount ?? 0n;
6490
- const minBodyGas = maxBigInt2(
6491
- L1_TX_INTRINSIC_L2_GAS + ceilDiv(
6492
- input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
6493
- PRIORITY_TX_ENCODING_STEP_BYTES
6494
- ) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
6495
- L1_TX_MIN_L2_GAS_BASE
6496
- ) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
6497
- const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
6498
- const derivedBodyGas = minBodyGas;
6499
- return {
6500
- encodedLength: input.encodedLength,
6501
- minBodyGas,
6502
- overhead,
6503
- derivedBodyGas,
6504
- derivedL2GasLimit: derivedBodyGas + overhead,
6505
- priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
6506
- priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
6507
- };
6508
- }
6509
- function derivePriorityBodyGasEstimateCap(input) {
6510
- return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
6511
- }
6512
- function applyPriorityL2GasLimitBuffer(input) {
6513
- return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
6514
- }
6515
6867
  var EMPTY_BYTES = "0x";
6516
6868
  var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
6517
6869
  var L2_CANONICAL_TRANSACTION_TUPLE = "tuple(uint256 txType,uint256 from,uint256 to,uint256 gasLimit,uint256 gasPerPubdataByteLimit,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,uint256 paymaster,uint256 nonce,uint256 value,uint256[4] reserved,bytes data,bytes signature,uint256[] factoryDeps,bytes paymasterInput,bytes reservedDynamic)";
@@ -6568,9 +6920,13 @@ function routeEthDirect() {
6568
6920
  l2Calldata,
6569
6921
  gasPerPubdata: ctx.gasPerPubdata
6570
6922
  });
6571
- const quotedL2GasLimit = ctx.l2GasLimit ?? applyPriorityL2GasLimitBuffer({
6572
- chainIdL2: ctx.chainIdL2,
6573
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
6923
+ const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
6924
+ gasLimit: applyPriorityL2GasLimitBuffer({
6925
+ chainIdL2: ctx.chainIdL2,
6926
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
6927
+ }),
6928
+ l2Calldata,
6929
+ gasPerPubdata: ctx.gasPerPubdata
6574
6930
  });
6575
6931
  const l2GasParams = await quoteL2Gas2({
6576
6932
  ctx,
@@ -6660,26 +7016,18 @@ var ntvCodec = createNTVCodec({
6660
7016
  keccak256: (data) => ethers.keccak256(data)
6661
7017
  });
6662
7018
  async function encodeSecondBridgeErc20DepositCalldata(input) {
6663
- if (!input.ctx.resolvedToken) {
6664
- return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
6665
- }
6666
- const { chainId } = await input.ctx.client.l1.getNetwork();
6667
- const expectedL1AssetId = ntvCodec.encodeAssetId(
6668
- BigInt(chainId),
7019
+ const registeredAssetId = input.ctx.resolvedToken?.assetId;
7020
+ const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
7021
+ BigInt((await input.ctx.client.l1.getNetwork()).chainId),
6669
7022
  L2_NATIVE_TOKEN_VAULT_ADDRESS,
6670
7023
  input.token
6671
7024
  );
6672
- const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
6673
- const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
6674
- if (isL1Origin) {
6675
- return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
6676
- }
6677
7025
  const transferData = encodeNativeTokenVaultTransferData(
6678
7026
  input.amount,
6679
7027
  input.receiver,
6680
7028
  input.token
6681
7029
  );
6682
- return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
7030
+ return encodeSecondBridgeDataV1(assetId, transferData);
6683
7031
  }
6684
7032
  async function getPriorityGasModel(input) {
6685
7033
  try {
@@ -6714,9 +7062,18 @@ async function getPriorityGasModel(input) {
6714
7062
  gasPerPubdata: input.ctx.gasPerPubdata
6715
7063
  });
6716
7064
  const model = {
6717
- priorityFloorGasLimit: applyPriorityL2GasLimitBuffer({
6718
- chainIdL2: input.ctx.chainIdL2,
6719
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7065
+ priorityTxL2Leg: {
7066
+ from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
7067
+ to: L2_ASSET_ROUTER_ADDRESS,
7068
+ data: l2Calldata
7069
+ },
7070
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
7071
+ gasLimit: applyPriorityL2GasLimitBuffer({
7072
+ chainIdL2: input.ctx.chainIdL2,
7073
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7074
+ }),
7075
+ l2Calldata,
7076
+ gasPerPubdata: input.ctx.gasPerPubdata
6720
7077
  })
6721
7078
  };
6722
7079
  if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS2) {
@@ -6774,6 +7131,7 @@ function routeErc20NonBase() {
6774
7131
  ctx,
6775
7132
  l1Token: p.token,
6776
7133
  priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
7134
+ priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
6777
7135
  undeployedGasLimit: priorityGasModel.undeployedGasLimit,
6778
7136
  modelTx: {
6779
7137
  to: receiver,
@@ -6788,25 +7146,29 @@ function routeErc20NonBase() {
6788
7146
  const approvals = [];
6789
7147
  const steps = [];
6790
7148
  const assetRouter = ctx.l1AssetRouter;
7149
+ const nativeTokenVault = ctx.l1NativeTokenVault;
6791
7150
  const erc20Deposit = new ethers.Contract(p.token, IERC20_default, l1Signer);
6792
7151
  const allowanceToken = await wrapAs2(
6793
7152
  "RPC",
6794
7153
  OP_DEPOSITS.nonbase.allowanceToken,
6795
- () => erc20Deposit.allowance(ctx.sender, assetRouter),
7154
+ () => erc20Deposit.allowance(ctx.sender, nativeTokenVault),
6796
7155
  {
6797
- ctx: { where: "erc20.allowance", token: p.token, spender: assetRouter },
7156
+ ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
6798
7157
  message: "Failed to read deposit-token allowance."
6799
7158
  }
6800
7159
  );
6801
7160
  if (allowanceToken < p.amount) {
6802
- approvals.push({ token: p.token, spender: assetRouter, amount: p.amount });
7161
+ approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
6803
7162
  steps.push({
6804
- key: `approve:${p.token}:${assetRouter}`,
7163
+ key: `approve:${p.token}:${nativeTokenVault}`,
6805
7164
  kind: "approve",
6806
- description: `Approve ${p.amount} for router (deposit token)`,
7165
+ description: `Approve ${p.amount} for the native token vault (deposit token)`,
6807
7166
  tx: {
6808
7167
  to: p.token,
6809
- data: erc20Deposit.interface.encodeFunctionData("approve", [assetRouter, p.amount]),
7168
+ data: erc20Deposit.interface.encodeFunctionData("approve", [
7169
+ nativeTokenVault,
7170
+ p.amount
7171
+ ]),
6810
7172
  from: ctx.sender,
6811
7173
  ...ctx.gasOverrides
6812
7174
  }
@@ -6817,21 +7179,24 @@ function routeErc20NonBase() {
6817
7179
  const allowanceBase = await wrapAs2(
6818
7180
  "RPC",
6819
7181
  OP_DEPOSITS.nonbase.allowanceBase,
6820
- () => erc20Base.allowance(ctx.sender, assetRouter),
7182
+ () => erc20Base.allowance(ctx.sender, nativeTokenVault),
6821
7183
  {
6822
- ctx: { where: "erc20.allowance", token: baseToken, spender: assetRouter },
7184
+ ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
6823
7185
  message: "Failed to read base-token allowance."
6824
7186
  }
6825
7187
  );
6826
7188
  if (allowanceBase < mintValue) {
6827
- approvals.push({ token: baseToken, spender: assetRouter, amount: mintValue });
7189
+ approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
6828
7190
  steps.push({
6829
- key: `approve:${baseToken}:${assetRouter}`,
7191
+ key: `approve:${baseToken}:${nativeTokenVault}`,
6830
7192
  kind: "approve",
6831
7193
  description: `Approve base token for mintValue`,
6832
7194
  tx: {
6833
7195
  to: baseToken,
6834
- data: erc20Base.interface.encodeFunctionData("approve", [assetRouter, mintValue]),
7196
+ data: erc20Base.interface.encodeFunctionData("approve", [
7197
+ nativeTokenVault,
7198
+ mintValue
7199
+ ]),
6835
7200
  from: ctx.sender,
6836
7201
  ...ctx.gasOverrides
6837
7202
  }
@@ -6928,9 +7293,18 @@ async function getPriorityGasModel2(input) {
6928
7293
  gasPerPubdata: input.ctx.gasPerPubdata
6929
7294
  });
6930
7295
  const model = {
6931
- priorityFloorGasLimit: applyPriorityL2GasLimitBuffer({
6932
- chainIdL2: input.ctx.chainIdL2,
6933
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7296
+ priorityTxL2Leg: {
7297
+ from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
7298
+ to: L2_ASSET_ROUTER_ADDRESS,
7299
+ data: l2Calldata
7300
+ },
7301
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
7302
+ gasLimit: applyPriorityL2GasLimitBuffer({
7303
+ chainIdL2: input.ctx.chainIdL2,
7304
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7305
+ }),
7306
+ l2Calldata,
7307
+ gasPerPubdata: input.ctx.gasPerPubdata
6934
7308
  })
6935
7309
  };
6936
7310
  if (input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS3) {
@@ -7007,6 +7381,7 @@ function routeEthNonBase() {
7007
7381
  ctx,
7008
7382
  modelTx: l2TxModel,
7009
7383
  priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
7384
+ priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
7010
7385
  undeployedGasLimit: priorityGasModel.undeployedGasLimit
7011
7386
  });
7012
7387
  if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
@@ -7018,21 +7393,24 @@ function routeEthNonBase() {
7018
7393
  const allowance = await wrapAs3(
7019
7394
  "RPC",
7020
7395
  OP_DEPOSITS.ethNonBase.allowanceBase,
7021
- () => erc20Base.allowance(ctx.sender, ctx.l1AssetRouter),
7396
+ () => erc20Base.allowance(ctx.sender, ctx.l1NativeTokenVault),
7022
7397
  {
7023
- ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1AssetRouter },
7398
+ ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
7024
7399
  message: "Failed to read base-token allowance."
7025
7400
  }
7026
7401
  );
7027
7402
  if (allowance < mintValue) {
7028
- approvals.push({ token: baseToken, spender: ctx.l1AssetRouter, amount: mintValue });
7403
+ approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
7029
7404
  steps.push({
7030
- key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
7405
+ key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
7031
7406
  kind: "approve",
7032
7407
  description: `Approve base token for fees (mintValue)`,
7033
7408
  tx: {
7034
7409
  to: baseToken,
7035
- data: erc20Base.interface.encodeFunctionData("approve", [ctx.l1AssetRouter, mintValue]),
7410
+ data: erc20Base.interface.encodeFunctionData("approve", [
7411
+ ctx.l1NativeTokenVault,
7412
+ mintValue
7413
+ ]),
7036
7414
  from: ctx.sender,
7037
7415
  ...ctx.gasOverrides
7038
7416
  }
@@ -7148,9 +7526,13 @@ function routeErc20Base() {
7148
7526
  l2Calldata,
7149
7527
  gasPerPubdata: ctx.gasPerPubdata
7150
7528
  });
7151
- const quotedL2GasLimit = ctx.l2GasLimit ?? applyPriorityL2GasLimitBuffer({
7152
- chainIdL2: ctx.chainIdL2,
7153
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7529
+ const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
7530
+ gasLimit: applyPriorityL2GasLimitBuffer({
7531
+ chainIdL2: ctx.chainIdL2,
7532
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7533
+ }),
7534
+ l2Calldata,
7535
+ gasPerPubdata: ctx.gasPerPubdata
7154
7536
  });
7155
7537
  const l2GasParams = await quoteL2Gas2({
7156
7538
  ctx,
@@ -7167,21 +7549,24 @@ function routeErc20Base() {
7167
7549
  const allowance = await wrapAs4(
7168
7550
  "RPC",
7169
7551
  OP_DEPOSITS.base.allowance,
7170
- () => erc20.allowance(ctx.sender, ctx.l1AssetRouter),
7552
+ () => erc20.allowance(ctx.sender, ctx.l1NativeTokenVault),
7171
7553
  {
7172
- ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1AssetRouter },
7554
+ ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
7173
7555
  message: "Failed to read base-token allowance."
7174
7556
  }
7175
7557
  );
7176
7558
  if (allowance < mintValue) {
7177
- approvals.push({ token: baseToken, spender: ctx.l1AssetRouter, amount: mintValue });
7559
+ approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
7178
7560
  steps.push({
7179
- key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
7561
+ key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
7180
7562
  kind: "approve",
7181
7563
  description: "Approve base token for mintValue",
7182
7564
  tx: {
7183
7565
  to: baseToken,
7184
- data: erc20.interface.encodeFunctionData("approve", [ctx.l1AssetRouter, mintValue]),
7566
+ data: erc20.interface.encodeFunctionData("approve", [
7567
+ ctx.l1NativeTokenVault,
7568
+ mintValue
7569
+ ]),
7185
7570
  from: ctx.sender,
7186
7571
  ...ctx.gasOverrides
7187
7572
  }
@@ -7315,8 +7700,17 @@ function createTokensResource(client) {
7315
7700
  const { chainId } = await client.l2.getNetwork();
7316
7701
  return await client.baseToken(BigInt(chainId));
7317
7702
  }
7318
- const { l2AssetRouter } = await client.contracts();
7319
- const l1Token = await l2AssetRouter.l1TokenAddress(l2Token);
7703
+ const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
7704
+ const assetId = await l2NativeTokenVault.assetId(l2Token);
7705
+ if (BigInt(assetId) === 0n) {
7706
+ throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
7707
+ }
7708
+ const l1Token = await l1NativeTokenVault.tokenAddress(assetId);
7709
+ if (BigInt(l1Token) === 0n) {
7710
+ throw new Error(
7711
+ `Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
7712
+ );
7713
+ }
7320
7714
  return l1Token;
7321
7715
  });
7322
7716
  }
@@ -7824,7 +8218,7 @@ function pickWithdrawRoute(args) {
7824
8218
  }
7825
8219
 
7826
8220
  // src/adapters/ethers/resources/withdrawals/context.ts
7827
- async function commonCtx2(p, client, tokens, contracts) {
8221
+ async function commonCtx2(p, client, tokens, contracts, protocol) {
7828
8222
  const sender = await client.signer.getAddress();
7829
8223
  const {
7830
8224
  bridgehub,
@@ -7832,10 +8226,12 @@ async function commonCtx2(p, client, tokens, contracts) {
7832
8226
  l1Nullifier,
7833
8227
  l2AssetRouter,
7834
8228
  l2NativeTokenVault,
7835
- l2BaseTokenSystem
8229
+ l2BaseTokenSystem,
8230
+ interopCenter
7836
8231
  } = await contracts.addresses();
7837
8232
  const { chainId } = await client.l2.getNetwork();
7838
8233
  const chainIdL2 = BigInt(chainId);
8234
+ const l1ChainId = BigInt((await client.l1.getNetwork()).chainId);
7839
8235
  const resolvedToken = await tokens.resolve(p.token, { chain: "l2" });
7840
8236
  const baseTokenAssetId = resolvedToken.baseTokenAssetId;
7841
8237
  const baseTokenL1 = await tokens.l1TokenFromAssetId(baseTokenAssetId);
@@ -7857,6 +8253,9 @@ async function commonCtx2(p, client, tokens, contracts) {
7857
8253
  l2AssetRouter,
7858
8254
  l2NativeTokenVault,
7859
8255
  l2BaseTokenSystem,
8256
+ interopCenter,
8257
+ protocol,
8258
+ l1ChainId,
7860
8259
  baseIsEth,
7861
8260
  gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
7862
8261
  };
@@ -8093,7 +8492,269 @@ function routeErc20NonBase2() {
8093
8492
  });
8094
8493
  const fees = buildFeeBreakdown2({
8095
8494
  feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
8096
- l2Gas: withdrawGas
8495
+ l2Gas: withdrawGas
8496
+ });
8497
+ return { steps, approvals, fees };
8498
+ }
8499
+ };
8500
+ }
8501
+ var PREFIX_EVM_CHAIN = ethers.getBytes("0x00010000");
8502
+ var PREFIX_EVM_ADDRESS = ethers.getBytes("0x000100000014");
8503
+ function formatInteropEvmChain(chainId) {
8504
+ const chainRef = ethers.toBeArray(chainId);
8505
+ const chainRefLength = ethers.getBytes(ethers.toBeHex(chainRef.length, 1));
8506
+ const payload = ethers.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
8507
+ return ethers.hexlify(payload);
8508
+ }
8509
+ function formatInteropEvmAddress(address) {
8510
+ const normalized = ethers.getAddress(address);
8511
+ const addrBytes = ethers.getBytes(normalized);
8512
+ const payload = ethers.concat([PREFIX_EVM_ADDRESS, addrBytes]);
8513
+ return ethers.hexlify(payload);
8514
+ }
8515
+ var interopCodec = {
8516
+ formatChain: formatInteropEvmChain,
8517
+ formatAddress: formatInteropEvmAddress
8518
+ };
8519
+
8520
+ // src/core/resources/interop/attributes/call.ts
8521
+ function createCallAttributes(codec) {
8522
+ const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
8523
+ const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
8524
+ return {
8525
+ indirectCall,
8526
+ interopCallValue
8527
+ };
8528
+ }
8529
+
8530
+ // src/core/resources/interop/attributes/bundle.ts
8531
+ function createBundleAttributes(codec) {
8532
+ const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
8533
+ const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
8534
+ const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
8535
+ const interopBundleSalt = (salt) => codec.encode("interopBundleSalt", [salt]);
8536
+ return {
8537
+ executionAddress,
8538
+ unbundlerAddress,
8539
+ useFixedFee,
8540
+ interopBundleSalt
8541
+ };
8542
+ }
8543
+
8544
+ // src/core/resources/interop/attributes/resource.ts
8545
+ function createAttributesResource(codec) {
8546
+ return {
8547
+ call: createCallAttributes(codec),
8548
+ bundle: createBundleAttributes(codec)
8549
+ };
8550
+ }
8551
+
8552
+ // src/adapters/ethers/resources/interop/attributes/resource.ts
8553
+ function getInteropAttributes(params, ctx) {
8554
+ const bundleAttributes = [];
8555
+ if (params.execution?.only) {
8556
+ bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
8557
+ }
8558
+ if (params.unbundling?.by) {
8559
+ bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
8560
+ }
8561
+ bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
8562
+ const callAttributes = params.actions.map((action) => {
8563
+ switch (action.type) {
8564
+ case "sendNative": {
8565
+ const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
8566
+ if (baseMatches) {
8567
+ return [ctx.attributes.call.interopCallValue(action.amount)];
8568
+ }
8569
+ return [ctx.attributes.call.indirectCall(action.amount)];
8570
+ }
8571
+ case "call":
8572
+ if (action.value && action.value > 0n) {
8573
+ return [ctx.attributes.call.interopCallValue(action.value)];
8574
+ }
8575
+ return [];
8576
+ case "sendErc20":
8577
+ return [ctx.attributes.call.indirectCall(0n)];
8578
+ default:
8579
+ assertNever(action);
8580
+ }
8581
+ });
8582
+ return { bundleAttributes, callAttributes };
8583
+ }
8584
+ function createEthersAttributesResource(opts = {}) {
8585
+ const iface = opts.iface ?? new ethers.Interface(IERC7786Attributes_default);
8586
+ const encode2 = (fn, args) => iface.encodeFunctionData(fn, args);
8587
+ return createAttributesResource({ encode: encode2 });
8588
+ }
8589
+
8590
+ // src/core/resources/withdrawals/bundle.ts
8591
+ function buildWithdrawalBundle(input) {
8592
+ const {
8593
+ assetId,
8594
+ amount,
8595
+ l1Receiver,
8596
+ l2Token,
8597
+ isBaseToken,
8598
+ l1ChainId,
8599
+ l2AssetRouter,
8600
+ salt,
8601
+ codec,
8602
+ attributes: attributes2,
8603
+ transferData
8604
+ } = input;
8605
+ const burnData = transferData.encodeBridgeBurnData(amount, l1Receiver, l2Token);
8606
+ const depositData = transferData.encodeAssetRouterDepositData(assetId, burnData);
8607
+ const indirectCallMessageValue = isBaseToken ? amount : 0n;
8608
+ const starter = [
8609
+ codec.formatAddress(l2AssetRouter),
8610
+ depositData,
8611
+ [attributes2.indirectCall(indirectCallMessageValue), attributes2.interopCallValue(0n)]
8612
+ ];
8613
+ return {
8614
+ destinationChain: codec.formatChain(l1ChainId),
8615
+ starters: [starter],
8616
+ // No `atomicBundle` attribute: L2 -> L1 withdrawals are non-atomic and are published to L1 as a
8617
+ // `BUNDLE_IDENTIFIER`-prefixed message, which is what the L1 handler proves inclusion of.
8618
+ bundleAttributes: [attributes2.interopBundleSalt(salt)],
8619
+ value: indirectCallMessageValue
8620
+ };
8621
+ }
8622
+
8623
+ // src/adapters/ethers/resources/withdrawals/routes/interop-bundle.ts
8624
+ var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
8625
+ var attributes = createEthersAttributesResource();
8626
+ function saltFor(sender, nonce) {
8627
+ return ethers.keccak256(
8628
+ ethers.AbiCoder.defaultAbiCoder().encode(["address", "uint256"], [sender, BigInt(nonce)])
8629
+ );
8630
+ }
8631
+ function routeInteropBundle() {
8632
+ return {
8633
+ async build(p, ctx) {
8634
+ const steps = [];
8635
+ const approvals = [];
8636
+ const isBaseToken = ctx.route === "base";
8637
+ const l1Receiver = p.to ?? ctx.sender;
8638
+ let assetId;
8639
+ let allowanceSufficient = true;
8640
+ if (isBaseToken) {
8641
+ assetId = ctx.baseTokenAssetId;
8642
+ } else {
8643
+ assetId = await wrapAs8(
8644
+ "CONTRACT",
8645
+ OP_WITHDRAWALS.erc20.ensureRegistered,
8646
+ async () => {
8647
+ const ntv = await ctx.contracts.l2NativeTokenVault();
8648
+ return await ntv.getFunction("ensureTokenIsRegistered").staticCall(p.token);
8649
+ },
8650
+ {
8651
+ ctx: { where: "L2NativeTokenVault.ensureTokenIsRegistered", token: p.token },
8652
+ message: "Failed to ensure token is registered in L2NativeTokenVault."
8653
+ }
8654
+ );
8655
+ const erc20 = new ethers.Contract(p.token, IERC20_default, ctx.client.l2);
8656
+ const current = await wrapAs8(
8657
+ "CONTRACT",
8658
+ OP_WITHDRAWALS.erc20.allowance,
8659
+ () => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
8660
+ {
8661
+ ctx: {
8662
+ where: "erc20.allowance",
8663
+ chain: "L2",
8664
+ token: p.token,
8665
+ spender: ctx.l2NativeTokenVault
8666
+ },
8667
+ message: "Failed to read L2 ERC-20 allowance."
8668
+ }
8669
+ );
8670
+ allowanceSufficient = current >= p.amount;
8671
+ if (!allowanceSufficient) {
8672
+ approvals.push({ token: p.token, spender: ctx.l2NativeTokenVault, amount: p.amount });
8673
+ const approveTx = {
8674
+ to: p.token,
8675
+ data: erc20.interface.encodeFunctionData("approve", [ctx.l2NativeTokenVault, p.amount]),
8676
+ from: ctx.sender
8677
+ };
8678
+ const approveGas = await quoteL2Gas4({ ctx, tx: approveTx });
8679
+ if (approveGas) {
8680
+ approveTx.gasLimit = approveGas.gasLimit;
8681
+ approveTx.maxFeePerGas = approveGas.maxFeePerGas;
8682
+ approveTx.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
8683
+ }
8684
+ steps.push({
8685
+ key: `approve:l2:${p.token}:${ctx.l2NativeTokenVault}`,
8686
+ kind: "approve:l2",
8687
+ description: `Approve ${p.amount} to NativeTokenVault`,
8688
+ tx: approveTx
8689
+ });
8690
+ }
8691
+ }
8692
+ const nonce = await wrapAs8(
8693
+ "RPC",
8694
+ OP_WITHDRAWALS.prepare,
8695
+ () => ctx.client.l2.getTransactionCount(ctx.sender, "pending"),
8696
+ {
8697
+ ctx: { where: "l2.getTransactionCount", sender: ctx.sender },
8698
+ message: "Failed to read L2 nonce for the interop bundle salt."
8699
+ }
8700
+ );
8701
+ const bundle = buildWithdrawalBundle({
8702
+ assetId,
8703
+ amount: p.amount,
8704
+ l1Receiver,
8705
+ l2Token: isBaseToken ? FORMAL_ETH_ADDRESS : p.token,
8706
+ isBaseToken,
8707
+ l1ChainId: ctx.l1ChainId,
8708
+ l2AssetRouter: ctx.l2AssetRouter,
8709
+ salt: saltFor(ctx.sender, nonce),
8710
+ codec: interopCodec,
8711
+ attributes: {
8712
+ indirectCall: attributes.call.indirectCall,
8713
+ interopCallValue: attributes.call.interopCallValue,
8714
+ interopBundleSalt: attributes.bundle.interopBundleSalt
8715
+ },
8716
+ transferData: {
8717
+ encodeBridgeBurnData: (amount, receiver, token) => encodeNativeTokenVaultTransferData(amount, receiver, token),
8718
+ encodeAssetRouterDepositData: (id, data2) => encodeSecondBridgeDataV1(id, data2)
8719
+ }
8720
+ });
8721
+ const interopCenter = await ctx.contracts.interopCenter();
8722
+ const data = await wrapAs8(
8723
+ "INTERNAL",
8724
+ OP_WITHDRAWALS.erc20.encodeWithdraw,
8725
+ () => Promise.resolve(
8726
+ interopCenter.interface.encodeFunctionData("sendBundle", [
8727
+ bundle.destinationChain,
8728
+ bundle.starters,
8729
+ bundle.bundleAttributes
8730
+ ])
8731
+ ),
8732
+ {
8733
+ ctx: { where: "InteropCenter.sendBundle", assetId },
8734
+ message: "Failed to encode sendBundle calldata."
8735
+ }
8736
+ );
8737
+ const sendTx = {
8738
+ to: ctx.interopCenter,
8739
+ data,
8740
+ from: ctx.sender,
8741
+ value: bundle.value
8742
+ };
8743
+ const sendGas = allowanceSufficient ? await quoteL2Gas4({ ctx, tx: sendTx }) : void 0;
8744
+ if (sendGas) {
8745
+ sendTx.gasLimit = sendGas.gasLimit;
8746
+ sendTx.maxFeePerGas = sendGas.maxFeePerGas;
8747
+ sendTx.maxPriorityFeePerGas = sendGas.maxPriorityFeePerGas;
8748
+ }
8749
+ steps.push({
8750
+ key: "interop-center:send-bundle",
8751
+ kind: "interop-center:send-bundle",
8752
+ description: "Burn on L2 & send L2\u2192L1 withdrawal bundle",
8753
+ tx: sendTx
8754
+ });
8755
+ const fees = buildFeeBreakdown2({
8756
+ feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
8757
+ l2Gas: sendGas
8097
8758
  });
8098
8759
  return { steps, approvals, fees };
8099
8760
  }
@@ -8147,176 +8808,379 @@ function messengerLogIndex(raw, opts) {
8147
8808
  }
8148
8809
  return (hits[index] ?? hits[0]).i;
8149
8810
  }
8811
+ function keccakHex(data) {
8812
+ return `0x${utils.bytesToHex(sha3.keccak_256(utils.hexToBytes(data.slice(2))))}`;
8813
+ }
8814
+ function stripBundleIdentifier(messageData) {
8815
+ const prefix = `0x${messageData.slice(2, 4)}`;
8816
+ if (prefix !== BUNDLE_IDENTIFIER) {
8817
+ throw createError("STATE", {
8818
+ resource: "withdrawals",
8819
+ operation: OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
8820
+ message: "L2\u2192L1 message is not an interop bundle. This withdrawal was most likely initiated before the chain upgraded to protocol v32 and cannot be finalized through the interop handler.",
8821
+ context: { prefix, expected: BUNDLE_IDENTIFIER }
8822
+ });
8823
+ }
8824
+ return `0x${messageData.slice(4)}`;
8825
+ }
8826
+ function parseBundleHashFromLogs(logs, interopCenter = L2_INTEROP_CENTER_ADDRESS) {
8827
+ const center = interopCenter.toLowerCase();
8828
+ for (const log of logs) {
8829
+ if (log.address?.toLowerCase() !== center) continue;
8830
+ if (log.topics?.length !== 1) continue;
8831
+ if (!log.data || (log.data.length - 2) / 64 < 3) continue;
8832
+ return `0x${log.data.slice(66, 130)}`;
8833
+ }
8834
+ return void 0;
8835
+ }
8836
+ function buildWithdrawalFinalization(input) {
8837
+ const { messageData, sourceChainId, txNumberInBatch, proof } = input;
8838
+ const bundle = stripBundleIdentifier(messageData);
8839
+ return {
8840
+ bundle,
8841
+ bundleHash: input.bundleHash ?? keccakHex(bundle),
8842
+ proof: {
8843
+ chainId: sourceChainId,
8844
+ l1BatchNumber: proof.batchNumber,
8845
+ l2MessageIndex: proof.id,
8846
+ message: {
8847
+ txNumberInBatch,
8848
+ sender: input.interopCenter ?? L2_INTEROP_CENTER_ADDRESS,
8849
+ data: messageData
8850
+ },
8851
+ proof: proof.proof
8852
+ }
8853
+ };
8854
+ }
8855
+ function classifyWithdrawalOutcome(bundleStatus, callStatus) {
8856
+ if (bundleStatus === 2 /* FullyExecuted */) return "finalized";
8857
+ if (bundleStatus !== 3 /* Unbundled */) return "pending";
8858
+ switch (callStatus) {
8859
+ case 1 /* Executed */:
8860
+ return "finalized";
8861
+ case 2 /* Cancelled */:
8862
+ return "failed";
8863
+ default:
8864
+ return "pending";
8865
+ }
8866
+ }
8867
+
8868
+ // src/core/resources/withdrawals/protocol.ts
8869
+ var MIN_INTEROP_WITHDRAWAL_MINOR = 32;
8870
+ function protocolFromVersion(version) {
8871
+ const [, minor] = version;
8872
+ return minor >= MIN_INTEROP_WITHDRAWAL_MINOR ? "interop-bundle" : "legacy-withdrawal";
8873
+ }
8874
+ async function detectWithdrawalProtocol(probes, override) {
8875
+ if (override) {
8876
+ return { protocol: override, source: { via: "override" } };
8877
+ }
8878
+ const version = await probes.protocolVersion();
8879
+ if (version) {
8880
+ return { protocol: protocolFromVersion(version), source: { via: "protocol-version", version } };
8881
+ }
8882
+ if (await probes.hasCodeAt(L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS)) {
8883
+ return {
8884
+ protocol: "interop-bundle",
8885
+ source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
8886
+ };
8887
+ }
8888
+ return {
8889
+ protocol: "legacy-withdrawal",
8890
+ source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
8891
+ };
8892
+ }
8893
+
8894
+ // src/adapters/ethers/resources/withdrawals/services/protocol.ts
8895
+ function createWithdrawalProtocolService(client, override) {
8896
+ let cached;
8897
+ async function hasCodeAt(address) {
8898
+ try {
8899
+ const code = await client.l2.getCode(address);
8900
+ return !!code && code !== "0x";
8901
+ } catch {
8902
+ return false;
8903
+ }
8904
+ }
8905
+ async function protocolVersion() {
8906
+ try {
8907
+ return await client.getChainProtocolVersion();
8908
+ } catch {
8909
+ return void 0;
8910
+ }
8911
+ }
8912
+ function detect() {
8913
+ cached ??= detectWithdrawalProtocol(
8914
+ {
8915
+ protocolVersion,
8916
+ hasCodeAt
8917
+ },
8918
+ override
8919
+ ).catch((e) => {
8920
+ cached = void 0;
8921
+ throw e;
8922
+ });
8923
+ return cached;
8924
+ }
8925
+ return {
8926
+ detect,
8927
+ async protocol() {
8928
+ return (await detect()).protocol;
8929
+ },
8930
+ refresh() {
8931
+ cached = void 0;
8932
+ }
8933
+ };
8934
+ }
8150
8935
 
8151
8936
  // src/adapters/ethers/resources/withdrawals/services/finalization.ts
8152
- var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
8937
+ var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
8153
8938
  var IL1NullifierMini = [
8154
8939
  "function isWithdrawalFinalized(uint256,uint256,uint256) view returns (bool)"
8155
8940
  ];
8156
- function createFinalizationServices(client) {
8941
+ function createFinalizationServices(client, protocolService = createWithdrawalProtocolService(client)) {
8157
8942
  const { l1, l2, signer } = client;
8158
- return {
8159
- async fetchFinalizeDepositParams(l2TxHash) {
8160
- const parsed = await wrapAs8(
8161
- "RPC",
8162
- OP_WITHDRAWALS.finalize.fetchParams.receipt,
8163
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
8164
- {
8165
- ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
8166
- message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
8943
+ async function finalizationTarget(protocol) {
8944
+ const { l1Nullifier } = await client.ensureAddresses();
8945
+ if (protocol === "legacy-withdrawal") return l1Nullifier;
8946
+ const nullifier = new ethers.Contract(l1Nullifier, IL1NullifierV32_default, l1);
8947
+ const handler = await wrapAs9(
8948
+ "CONTRACT",
8949
+ OP_WITHDRAWALS.finalize.fetchParams.receipt,
8950
+ () => nullifier.l1InteropHandler(),
8951
+ {
8952
+ ctx: { where: "L1Nullifier.l1InteropHandler", l1Nullifier },
8953
+ message: "Failed to resolve the L1 interop handler. The chain reports protocol v32+, but its L1Nullifier does not expose `l1InteropHandler()`."
8954
+ }
8955
+ );
8956
+ return handler;
8957
+ }
8958
+ async function fetchMessageAndProof(l2TxHash) {
8959
+ const raw = await wrapAs9(
8960
+ "RPC",
8961
+ OP_WITHDRAWALS.finalize.fetchParams.receipt,
8962
+ () => client.zks.getReceiptWithL2ToL1(l2TxHash),
8963
+ {
8964
+ ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
8965
+ message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
8966
+ }
8967
+ );
8968
+ if (!raw) {
8969
+ throw createError("STATE", {
8970
+ resource: "withdrawals",
8971
+ operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
8972
+ message: "L2 receipt not found.",
8973
+ context: { l2TxHash }
8974
+ });
8975
+ }
8976
+ const ev = await wrapAs9(
8977
+ "INTERNAL",
8978
+ OP_WITHDRAWALS.finalize.fetchParams.findMessage,
8979
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
8980
+ () => Promise.resolve(findL1MessageSentLog(raw, { index: 0 })),
8981
+ {
8982
+ ctx: { l2TxHash, index: 0 },
8983
+ message: "Failed to locate L1MessageSent event in L2 receipt."
8984
+ }
8985
+ );
8986
+ const message = await wrapAs9(
8987
+ "INTERNAL",
8988
+ OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
8989
+ () => Promise.resolve(ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
8990
+ {
8991
+ ctx: { where: "decode L1MessageSent", data: ev.data },
8992
+ message: "Failed to decode withdrawal message."
8993
+ }
8994
+ );
8995
+ const idx = await wrapAs9(
8996
+ "INTERNAL",
8997
+ OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
8998
+ () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
8999
+ {
9000
+ ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
9001
+ message: "Failed to derive messenger log index."
9002
+ }
9003
+ );
9004
+ const proof = await wrapAs9(
9005
+ "RPC",
9006
+ OP_WITHDRAWALS.finalize.fetchParams.proof,
9007
+ () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
9008
+ {
9009
+ ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
9010
+ message: "Failed to fetch L2\u2192L1 log proof."
9011
+ }
9012
+ );
9013
+ const { chainId } = await wrapAs9(
9014
+ "RPC",
9015
+ OP_WITHDRAWALS.finalize.fetchParams.network,
9016
+ () => l2.getNetwork(),
9017
+ { ctx: { where: "l2.getNetwork" }, message: "Failed to read L2 network." }
9018
+ );
9019
+ const txNumberInBatch = Number(raw.transactionIndex ?? 0);
9020
+ const l2Sender = l1MessageSentSender(ev);
9021
+ return { raw, message, proof, chainId: BigInt(chainId), txNumberInBatch, l2Sender };
9022
+ }
9023
+ async function fetchFinalization(l2TxHash) {
9024
+ const protocol = await protocolService.protocol();
9025
+ const { raw, message, proof, chainId, txNumberInBatch, l2Sender } = await fetchMessageAndProof(l2TxHash);
9026
+ const target = await finalizationTarget(protocol);
9027
+ if (protocol === "legacy-withdrawal") {
9028
+ const params2 = {
9029
+ chainId,
9030
+ l2BatchNumber: proof.batchNumber,
9031
+ l2MessageIndex: proof.id,
9032
+ l2Sender,
9033
+ l2TxNumberInBatch: txNumberInBatch,
9034
+ message,
9035
+ merkleProof: proof.proof
9036
+ };
9037
+ return {
9038
+ target,
9039
+ finalization: { protocol, params: params2 },
9040
+ key: {
9041
+ chainIdL2: chainId,
9042
+ l2BatchNumber: proof.batchNumber,
9043
+ l2MessageIndex: proof.id
8167
9044
  }
8168
- );
8169
- if (!parsed) {
8170
- throw createError("STATE", {
8171
- resource: "withdrawals",
8172
- operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
8173
- message: "L2 receipt not found.",
8174
- context: { l2TxHash }
8175
- });
9045
+ };
9046
+ }
9047
+ const { interopCenter } = await client.ensureAddresses();
9048
+ const params = buildWithdrawalFinalization({
9049
+ messageData: message,
9050
+ sourceChainId: chainId,
9051
+ txNumberInBatch,
9052
+ proof: { batchNumber: proof.batchNumber, id: proof.id, proof: proof.proof },
9053
+ // Prefer the hash the InteropCenter emitted over recomputing it.
9054
+ bundleHash: parseBundleHashFromLogs(raw.logs ?? [], interopCenter),
9055
+ interopCenter
9056
+ });
9057
+ return {
9058
+ target,
9059
+ finalization: { protocol, params },
9060
+ key: {
9061
+ chainIdL2: chainId,
9062
+ l2BatchNumber: proof.batchNumber,
9063
+ l2MessageIndex: proof.id,
9064
+ bundleHash: params.bundleHash
8176
9065
  }
8177
- const ev = await wrapAs8(
8178
- "INTERNAL",
8179
- OP_WITHDRAWALS.finalize.fetchParams.findMessage,
8180
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
8181
- () => Promise.resolve(findL1MessageSentLog(parsed, { index: 0 })),
9066
+ };
9067
+ }
9068
+ async function withdrawalOutcome(finalization) {
9069
+ const target = await finalizationTarget(finalization.protocol);
9070
+ if (finalization.protocol === "legacy-withdrawal") {
9071
+ const c = new ethers.Contract(target, IL1NullifierMini, l1);
9072
+ const done = await wrapAs9(
9073
+ "RPC",
9074
+ OP_WITHDRAWALS.finalize.isFinalized,
9075
+ () => c.isWithdrawalFinalized(
9076
+ finalization.params.chainId,
9077
+ finalization.params.l2BatchNumber,
9078
+ finalization.params.l2MessageIndex
9079
+ ),
8182
9080
  {
8183
- ctx: { l2TxHash, index: 0 },
8184
- message: "Failed to locate L1MessageSent event in L2 receipt."
9081
+ ctx: { where: "isWithdrawalFinalized", params: finalization.params },
9082
+ message: "Failed to read finalization status."
8185
9083
  }
8186
9084
  );
8187
- const message = await wrapAs8(
8188
- "INTERNAL",
8189
- OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
8190
- () => Promise.resolve(ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
9085
+ return done ? "finalized" : "pending";
9086
+ }
9087
+ const { bundleHash } = finalization.params;
9088
+ const handler = new ethers.Contract(target, IInteropHandler_default, l1);
9089
+ const status = Number(
9090
+ await wrapAs9(
9091
+ "RPC",
9092
+ OP_WITHDRAWALS.finalize.isFinalized,
9093
+ () => handler.bundleStatus(bundleHash),
8191
9094
  {
8192
- ctx: { where: "decode L1MessageSent", data: ev.data },
8193
- message: "Failed to decode withdrawal message."
9095
+ ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
9096
+ message: "Failed to read bundle status."
8194
9097
  }
8195
- );
8196
- const raw = await wrapAs8(
9098
+ )
9099
+ );
9100
+ if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
9101
+ const callStatus = Number(
9102
+ await wrapAs9(
8197
9103
  "RPC",
8198
- OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
8199
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
9104
+ OP_WITHDRAWALS.finalize.isFinalized,
9105
+ () => handler.callStatus(bundleHash, 0),
8200
9106
  {
8201
- ctx: { where: "getReceiptWithL2ToL1 (raw)", l2TxHash },
8202
- message: "Failed to fetch raw L2 receipt."
9107
+ ctx: { where: "L1InteropHandler.callStatus", bundleHash },
9108
+ message: "Failed to read bundle call status."
8203
9109
  }
8204
- );
8205
- if (!raw) {
8206
- throw createError("STATE", {
9110
+ )
9111
+ );
9112
+ return classifyWithdrawalOutcome(status, callStatus);
9113
+ }
9114
+ async function isWithdrawalFinalized(finalization) {
9115
+ return await withdrawalOutcome(finalization) === "finalized";
9116
+ }
9117
+ return {
9118
+ fetchFinalization,
9119
+ isWithdrawalFinalized,
9120
+ withdrawalOutcome,
9121
+ async fetchFinalizeDepositParams(l2TxHash) {
9122
+ const resolved = await fetchFinalization(l2TxHash);
9123
+ if (resolved.finalization.protocol !== "legacy-withdrawal") {
9124
+ throw createError("VALIDATION", {
8207
9125
  resource: "withdrawals",
8208
- operation: OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
8209
- message: "Raw L2 receipt not found.",
8210
- context: { l2TxHash }
9126
+ operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
9127
+ message: "This chain finalizes withdrawals through the L1 interop handler; `finalizeDeposit` params do not exist. Use `fetchFinalization` instead.",
9128
+ context: { l2TxHash, protocol: resolved.finalization.protocol }
8211
9129
  });
8212
9130
  }
8213
- const idx = await wrapAs8(
8214
- "INTERNAL",
8215
- OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
8216
- () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
8217
- {
8218
- ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
8219
- message: "Failed to derive messenger log index."
8220
- }
8221
- );
8222
- const proof = await wrapAs8(
8223
- "RPC",
8224
- OP_WITHDRAWALS.finalize.fetchParams.proof,
8225
- () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
8226
- {
8227
- ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
8228
- message: "Failed to fetch L2\u2192L1 log proof."
8229
- }
8230
- );
8231
- const { chainId } = await wrapAs8(
8232
- "RPC",
8233
- OP_WITHDRAWALS.finalize.fetchParams.network,
8234
- () => l2.getNetwork(),
8235
- {
8236
- ctx: { where: "l2.getNetwork" },
8237
- message: "Failed to read L2 network."
8238
- }
8239
- );
8240
- const txIndex = Number(parsed.transactionIndex ?? 0);
8241
- const params = {
8242
- chainId: BigInt(chainId),
8243
- l2BatchNumber: proof.batchNumber,
8244
- l2MessageIndex: proof.id,
8245
- l2Sender: l1MessageSentSender(ev),
8246
- l2TxNumberInBatch: txIndex,
8247
- message,
8248
- merkleProof: proof.proof
8249
- };
8250
- const { l1Nullifier } = await client.ensureAddresses();
8251
- return { params, nullifier: l1Nullifier };
9131
+ return { params: resolved.finalization.params, nullifier: resolved.target };
8252
9132
  },
8253
- async simulateFinalizeReadiness(params) {
8254
- const { l1Nullifier } = await client.ensureAddresses();
9133
+ async simulateFinalizeReadiness(finalization) {
9134
+ const target = await finalizationTarget(finalization.protocol);
8255
9135
  const done = await (async () => {
8256
9136
  try {
8257
- const cMini = new ethers.Contract(l1Nullifier, IL1NullifierMini, l1);
8258
- const isFinalized = await wrapAs8(
8259
- "RPC",
8260
- OP_WITHDRAWALS.finalize.readiness.isFinalized,
8261
- () => cMini.isWithdrawalFinalized(
8262
- params.chainId,
8263
- params.l2BatchNumber,
8264
- params.l2MessageIndex
8265
- ),
8266
- {
8267
- ctx: { where: "isWithdrawalFinalized", params },
8268
- message: "Failed to read finalization status."
8269
- }
8270
- );
8271
- return Boolean(isFinalized);
9137
+ return await isWithdrawalFinalized(finalization);
8272
9138
  } catch {
8273
9139
  return false;
8274
9140
  }
8275
9141
  })();
8276
9142
  if (done) return { kind: "FINALIZED" };
8277
- const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, l1);
8278
9143
  try {
8279
- await c.finalizeDeposit.staticCall(params);
9144
+ if (finalization.protocol === "legacy-withdrawal") {
9145
+ const c = new ethers.Contract(target, IL1Nullifier_default, l1);
9146
+ await c.finalizeDeposit.staticCall(finalization.params);
9147
+ } else {
9148
+ const handler = new ethers.Contract(target, IInteropHandler_default, l1);
9149
+ await handler.executeBundle.staticCall(
9150
+ finalization.params.bundle,
9151
+ finalization.params.proof
9152
+ );
9153
+ }
8280
9154
  return { kind: "READY" };
8281
9155
  } catch (e) {
8282
9156
  return classifyReadinessFromRevert(e);
8283
9157
  }
8284
9158
  },
8285
- async isWithdrawalFinalized(key) {
8286
- const { l1Nullifier } = await client.ensureAddresses();
8287
- const c = new ethers.Contract(l1Nullifier, IL1NullifierMini, l1);
8288
- return await wrapAs8(
8289
- "RPC",
8290
- OP_WITHDRAWALS.finalize.isFinalized,
8291
- () => c.isWithdrawalFinalized(key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex),
8292
- {
8293
- ctx: { where: "isWithdrawalFinalized", key },
8294
- message: "Failed to read finalization status."
8295
- }
8296
- );
8297
- },
8298
- async estimateFinalization(params) {
8299
- const { l1Nullifier } = await client.ensureAddresses();
8300
- const signer2 = client.getL1Signer();
8301
- const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, signer2);
8302
- const gasLimit = await wrapAs8(
9159
+ async estimateFinalization(finalization) {
9160
+ const target = await finalizationTarget(finalization.protocol);
9161
+ const l1Signer = client.getL1Signer();
9162
+ const gasLimit = await wrapAs9(
8303
9163
  "RPC",
8304
9164
  OP_WITHDRAWALS.finalize.estimate,
8305
- () => c.finalizeDeposit.estimateGas(params),
9165
+ () => {
9166
+ if (finalization.protocol === "legacy-withdrawal") {
9167
+ const c = new ethers.Contract(target, IL1Nullifier_default, l1Signer);
9168
+ return c.finalizeDeposit.estimateGas(finalization.params);
9169
+ }
9170
+ const handler = new ethers.Contract(target, IInteropHandler_default, l1Signer);
9171
+ return handler.executeBundle.estimateGas(
9172
+ finalization.params.bundle,
9173
+ finalization.params.proof
9174
+ );
9175
+ },
8306
9176
  {
8307
- ctx: {
8308
- where: "estimateGas(finalizeDeposit)",
8309
- chainIdL2: params.chainId,
8310
- l2BatchNumber: params.l2BatchNumber,
8311
- l2MessageIndex: params.l2MessageIndex,
8312
- l1Nullifier
8313
- },
8314
- message: "Failed to estimate gas for finalizeDeposit."
9177
+ ctx: { where: "estimateGas(finalize)", protocol: finalization.protocol, target },
9178
+ message: "Failed to estimate gas for withdrawal finalization."
8315
9179
  }
8316
9180
  );
8317
- const feeData = await wrapAs8("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
9181
+ const feeData = await wrapAs9("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
8318
9182
  ctx: { where: "l1.getFeeData" },
8319
- message: "Failed to estimate fee data for finalizeDeposit."
9183
+ message: "Failed to estimate fee data for withdrawal finalization."
8320
9184
  });
8321
9185
  const maxFeePerGas = feeData.maxFeePerGas ?? feeData.gasPrice ?? // legacy-style gas price if present
8322
9186
  (() => {
@@ -8327,33 +9191,49 @@ function createFinalizationServices(client) {
8327
9191
  context: { feeData }
8328
9192
  });
8329
9193
  })();
8330
- const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
8331
9194
  return {
8332
9195
  gasLimit,
8333
9196
  maxFeePerGas,
8334
- maxPriorityFeePerGas
9197
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 0n
8335
9198
  };
8336
9199
  },
8337
- async finalizeDeposit(params) {
8338
- const { l1Nullifier } = await client.ensureAddresses();
8339
- const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, signer);
9200
+ async finalize(finalization) {
9201
+ const target = await finalizationTarget(finalization.protocol);
8340
9202
  try {
8341
- const receipt = await c.finalizeDeposit(params);
8342
- const hash = receipt.hash;
9203
+ const sent = await (async () => {
9204
+ if (finalization.protocol === "legacy-withdrawal") {
9205
+ const c = new ethers.Contract(target, IL1Nullifier_default, signer);
9206
+ return await c.finalizeDeposit(finalization.params);
9207
+ }
9208
+ const handler = new ethers.Contract(target, IInteropHandler_default, signer);
9209
+ return await handler.executeBundle(
9210
+ finalization.params.bundle,
9211
+ finalization.params.proof
9212
+ );
9213
+ })();
9214
+ const hash = sent.hash;
8343
9215
  return {
8344
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
8345
9216
  hash,
8346
9217
  wait: async () => {
8347
9218
  try {
8348
- return await receipt.wait();
9219
+ const receipt = await sent.wait();
9220
+ if (!receipt) {
9221
+ throw createError("EXECUTION", {
9222
+ resource: "withdrawals",
9223
+ operation: OP_WITHDRAWALS.finalize.wait,
9224
+ message: "Withdrawal finalization transaction produced no receipt.",
9225
+ context: { txHash: hash, protocol: finalization.protocol }
9226
+ });
9227
+ }
9228
+ return receipt;
8349
9229
  } catch (e) {
8350
9230
  throw toZKsyncError(
8351
9231
  "EXECUTION",
8352
9232
  {
8353
9233
  resource: "withdrawals",
8354
9234
  operation: OP_WITHDRAWALS.finalize.wait,
8355
- message: "Failed while waiting for finalizeDeposit transaction.",
8356
- context: { txHash: hash }
9235
+ message: "Failed while waiting for the withdrawal finalization transaction.",
9236
+ context: { txHash: hash, protocol: finalization.protocol }
8357
9237
  },
8358
9238
  e
8359
9239
  );
@@ -8366,13 +9246,8 @@ function createFinalizationServices(client) {
8366
9246
  {
8367
9247
  resource: "withdrawals",
8368
9248
  operation: OP_WITHDRAWALS.finalize.send,
8369
- message: "Failed to send finalizeDeposit transaction.",
8370
- context: {
8371
- chainIdL2: params.chainId,
8372
- l2BatchNumber: params.l2BatchNumber,
8373
- l2MessageIndex: params.l2MessageIndex,
8374
- l1Nullifier
8375
- }
9249
+ message: "Failed to send the withdrawal finalization transaction.",
9250
+ context: { protocol: finalization.protocol, target }
8376
9251
  },
8377
9252
  e
8378
9253
  );
@@ -8405,15 +9280,28 @@ var ROUTES2 = {
8405
9280
  "erc20-nonbase": routeErc20NonBase2()
8406
9281
  // AssetRouter.withdraw for non-base ERC-20s
8407
9282
  };
8408
- function createWithdrawalsResource(client, tokens, contracts) {
8409
- const svc = createFinalizationServices(client);
9283
+ var INTEROP_ROUTES = {
9284
+ base: routeInteropBundle(),
9285
+ "erc20-nonbase": routeInteropBundle()
9286
+ };
9287
+ function routeStrategy(protocol, route) {
9288
+ return protocol === "interop-bundle" ? INTEROP_ROUTES[route] : ROUTES2[route];
9289
+ }
9290
+ function createWithdrawalsResource(client, tokens, contracts, options) {
9291
+ const protocolService = createWithdrawalProtocolService(
9292
+ client,
9293
+ options?.protocol
9294
+ );
9295
+ const svc = createFinalizationServices(client, protocolService);
8410
9296
  const { wrap: wrap7, toResult: toResult3 } = createErrorHandlers("withdrawals");
8411
9297
  const tokensResource = tokens ?? createTokensResource(client);
8412
9298
  const contractsResource = contracts ?? createContractsResource(client);
8413
9299
  async function buildPlan(p) {
8414
- const ctx = await commonCtx2(p, client, tokensResource, contractsResource);
8415
- await ROUTES2[ctx.route].preflight?.(p, ctx);
8416
- const { steps, approvals, fees } = await ROUTES2[ctx.route].build(p, ctx);
9300
+ const protocol = await protocolService.protocol();
9301
+ const ctx = await commonCtx2(p, client, tokensResource, contractsResource, protocol);
9302
+ const strategy = routeStrategy(protocol, ctx.route);
9303
+ await strategy.preflight?.(p, ctx);
9304
+ const { steps, approvals, fees } = await strategy.build(p, ctx);
8417
9305
  return {
8418
9306
  route: ctx.route,
8419
9307
  summary: {
@@ -8557,21 +9445,20 @@ function createWithdrawalsResource(client, tokens, contracts) {
8557
9445
  if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
8558
9446
  let pack;
8559
9447
  try {
8560
- pack = await svc.fetchFinalizeDepositParams(l2TxHash);
9448
+ pack = await svc.fetchFinalization(l2TxHash);
8561
9449
  } catch {
8562
9450
  return { phase: "PENDING", l2TxHash };
8563
9451
  }
8564
- const key = {
8565
- chainIdL2: pack.params.chainId,
8566
- l2BatchNumber: pack.params.l2BatchNumber,
8567
- l2MessageIndex: pack.params.l2MessageIndex
8568
- };
9452
+ const key = pack.key;
8569
9453
  try {
8570
- const done = await svc.isWithdrawalFinalized(key);
8571
- if (done) return { phase: "FINALIZED", l2TxHash, key };
9454
+ const outcome = await svc.withdrawalOutcome(pack.finalization);
9455
+ if (outcome === "finalized") return { phase: "FINALIZED", l2TxHash, key };
9456
+ if (outcome === "failed") {
9457
+ return { phase: "UNFINALIZABLE", l2TxHash, key, reason: "bundle-cancelled" };
9458
+ }
8572
9459
  } catch {
8573
9460
  }
8574
- const readiness = await svc.simulateFinalizeReadiness(pack.params);
9461
+ const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
8575
9462
  const { phase, reason } = phaseFromReadiness(readiness);
8576
9463
  return { phase, reason, l2TxHash, key };
8577
9464
  },
@@ -8661,7 +9548,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
8661
9548
  async () => {
8662
9549
  const pack = await (async () => {
8663
9550
  try {
8664
- return await svc.fetchFinalizeDepositParams(l2TxHash);
9551
+ return await svc.fetchFinalization(l2TxHash);
8665
9552
  } catch (e) {
8666
9553
  throw createError("STATE", {
8667
9554
  resource: "withdrawals",
@@ -8672,21 +9559,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
8672
9559
  });
8673
9560
  }
8674
9561
  })();
8675
- const { params } = pack;
8676
- const key = {
8677
- chainIdL2: params.chainId,
8678
- l2BatchNumber: params.l2BatchNumber,
8679
- l2MessageIndex: params.l2MessageIndex
8680
- };
9562
+ const { finalization } = pack;
8681
9563
  try {
8682
- const done = await svc.isWithdrawalFinalized(key);
8683
- if (done) {
9564
+ const outcome = await svc.withdrawalOutcome(finalization);
9565
+ if (outcome === "finalized" || outcome === "failed") {
8684
9566
  const statusNow = await status(l2TxHash);
8685
9567
  return { status: statusNow };
8686
9568
  }
8687
9569
  } catch {
8688
9570
  }
8689
- const readiness = await svc.simulateFinalizeReadiness(params);
9571
+ const readiness = await svc.simulateFinalizeReadiness(finalization);
8690
9572
  if (readiness.kind === "FINALIZED") {
8691
9573
  const statusNow = await status(l2TxHash);
8692
9574
  return { status: statusNow };
@@ -8700,7 +9582,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
8700
9582
  });
8701
9583
  }
8702
9584
  try {
8703
- const tx = await svc.finalizeDeposit(params);
9585
+ const tx = await svc.finalize(finalization);
8704
9586
  finalizeCache.set(l2TxHash, tx.hash);
8705
9587
  const rcpt = await tx.wait();
8706
9588
  const statusNow = await status(l2TxHash);
@@ -8709,7 +9591,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
8709
9591
  const statusNow = await status(l2TxHash);
8710
9592
  if (statusNow.phase === "FINALIZED") return { status: statusNow };
8711
9593
  try {
8712
- const again = await svc.simulateFinalizeReadiness(params);
9594
+ const again = await svc.simulateFinalizeReadiness(finalization);
8713
9595
  if (again.kind === "NOT_READY") {
8714
9596
  throw createError("STATE", {
8715
9597
  resource: "withdrawals",
@@ -8768,74 +9650,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
8768
9650
  };
8769
9651
  }
8770
9652
 
8771
- // src/core/resources/interop/attributes/call.ts
8772
- function createCallAttributes(codec) {
8773
- const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
8774
- const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
8775
- return {
8776
- indirectCall,
8777
- interopCallValue
8778
- };
8779
- }
8780
-
8781
- // src/core/resources/interop/attributes/bundle.ts
8782
- function createBundleAttributes(codec) {
8783
- const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
8784
- const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
8785
- const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
8786
- return {
8787
- executionAddress,
8788
- unbundlerAddress,
8789
- useFixedFee
8790
- };
8791
- }
8792
-
8793
- // src/core/resources/interop/attributes/resource.ts
8794
- function createAttributesResource(codec) {
8795
- return {
8796
- call: createCallAttributes(codec),
8797
- bundle: createBundleAttributes(codec)
8798
- };
8799
- }
8800
-
8801
- // src/adapters/ethers/resources/interop/attributes/resource.ts
8802
- function getInteropAttributes(params, ctx) {
8803
- const bundleAttributes = [];
8804
- if (params.execution?.only) {
8805
- bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
8806
- }
8807
- if (params.unbundling?.by) {
8808
- bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
8809
- }
8810
- bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
8811
- const callAttributes = params.actions.map((action) => {
8812
- switch (action.type) {
8813
- case "sendNative": {
8814
- const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
8815
- if (baseMatches) {
8816
- return [ctx.attributes.call.interopCallValue(action.amount)];
8817
- }
8818
- return [ctx.attributes.call.indirectCall(action.amount)];
8819
- }
8820
- case "call":
8821
- if (action.value && action.value > 0n) {
8822
- return [ctx.attributes.call.interopCallValue(action.value)];
8823
- }
8824
- return [];
8825
- case "sendErc20":
8826
- return [ctx.attributes.call.indirectCall(0n)];
8827
- default:
8828
- assertNever(action);
8829
- }
8830
- });
8831
- return { bundleAttributes, callAttributes };
8832
- }
8833
- function createEthersAttributesResource(opts = {}) {
8834
- const iface = opts.iface ?? new ethers.Interface(IERC7786Attributes_default);
8835
- const encode2 = (fn, args) => iface.encodeFunctionData(fn, args);
8836
- return createAttributesResource({ encode: encode2 });
8837
- }
8838
-
8839
9653
  // src/core/types/flows/interop.ts
8840
9654
  function isInteropMessageProof(obj) {
8841
9655
  if (typeof obj !== "object" || obj === null) return false;
@@ -9012,24 +9826,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
9012
9826
  }
9013
9827
  };
9014
9828
  }
9015
- var PREFIX_EVM_CHAIN = ethers.getBytes("0x00010000");
9016
- var PREFIX_EVM_ADDRESS = ethers.getBytes("0x000100000014");
9017
- function formatInteropEvmChain(chainId) {
9018
- const chainRef = ethers.toBeArray(chainId);
9019
- const chainRefLength = ethers.getBytes(ethers.toBeHex(chainRef.length, 1));
9020
- const payload = ethers.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
9021
- return ethers.hexlify(payload);
9022
- }
9023
- function formatInteropEvmAddress(address) {
9024
- const normalized = ethers.getAddress(address);
9025
- const addrBytes = ethers.getBytes(normalized);
9026
- const payload = ethers.concat([PREFIX_EVM_ADDRESS, addrBytes]);
9027
- return ethers.hexlify(payload);
9028
- }
9029
- var interopCodec = {
9030
- formatChain: formatInteropEvmChain,
9031
- formatAddress: formatInteropEvmAddress
9032
- };
9033
9829
  function getErc20Tokens(params) {
9034
9830
  const erc20Tokens = /* @__PURE__ */ new Map();
9035
9831
  for (const action of params.actions) {
@@ -9185,7 +9981,7 @@ function routeIndirect() {
9185
9981
  resolveErc20AssetIds(erc20Tokens, ctx),
9186
9982
  buildFeeInfo(params, ctx, params.actions.length)
9187
9983
  ]);
9188
- const attributes = getInteropAttributes(params, ctx);
9984
+ const attributes2 = getInteropAttributes(params, ctx);
9189
9985
  const starterData = await getStarterData(params, ctx, erc20AssetIds);
9190
9986
  const bundle = buildIndirectBundle(
9191
9987
  params,
@@ -9196,7 +9992,7 @@ function routeIndirect() {
9196
9992
  l2NativeTokenVault: ctx.l2NativeTokenVault,
9197
9993
  codec: interopCodec
9198
9994
  },
9199
- attributes,
9995
+ attributes2,
9200
9996
  starterData,
9201
9997
  feeInfo
9202
9998
  );
@@ -9319,7 +10115,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
9319
10115
  assertProtocolVersion(srcChainId, srcProtocolVersion);
9320
10116
  assertProtocolVersion(dstChainId, dstProtocolVersion);
9321
10117
  }
9322
- async function commonCtx3(dstProvider, params, client, tokens, contracts, attributes) {
10118
+ async function commonCtx3(dstProvider, params, client, tokens, contracts, attributes2) {
9323
10119
  const sender = await client.signer.getAddress();
9324
10120
  const chainId = (await client.l2.getNetwork()).chainId;
9325
10121
  const dstChainId = (await dstProvider.getNetwork()).chainId;
@@ -9356,7 +10152,7 @@ async function commonCtx3(dstProvider, params, client, tokens, contracts, attrib
9356
10152
  l2NativeTokenVault,
9357
10153
  baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
9358
10154
  ifaces: { interopCenter: interopCenterIface, interopHandler: interopHandlerIface },
9359
- attributes,
10155
+ attributes: attributes2,
9360
10156
  gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
9361
10157
  };
9362
10158
  }
@@ -10012,7 +10808,7 @@ var ROUTES3 = {
10012
10808
  direct: routeDirect(),
10013
10809
  indirect: routeIndirect()
10014
10810
  };
10015
- function createInteropResource(client, config, tokens, contracts, attributes) {
10811
+ function createInteropResource(client, config, tokens, contracts, attributes2) {
10016
10812
  let gwProviderCache;
10017
10813
  function requireConfig() {
10018
10814
  if (!config)
@@ -10243,7 +11039,7 @@ function createEthersSdk(client, options) {
10243
11039
  const interop = createInteropResource(client, options?.interop, tokens, contracts);
10244
11040
  return {
10245
11041
  deposits: createDepositsResource(client, tokens, contracts),
10246
- withdrawals: createWithdrawalsResource(client, tokens, contracts),
11042
+ withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
10247
11043
  tokens,
10248
11044
  contracts,
10249
11045
  interop