@matterlabs/zksync-js 0.0.20 → 0.0.22

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 (72) hide show
  1. package/dist/adapters/ethers/client.cjs +31 -1
  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 +1057 -290
  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/withdrawals/context.d.ts +12 -1
  10. package/dist/adapters/ethers/resources/withdrawals/index.d.ts +17 -1
  11. package/dist/adapters/ethers/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
  12. package/dist/adapters/ethers/resources/withdrawals/services/finalization.d.ts +35 -17
  13. package/dist/adapters/ethers/resources/withdrawals/services/protocol.d.ts +11 -0
  14. package/dist/adapters/ethers/sdk.cjs +1010 -274
  15. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  16. package/dist/adapters/ethers/sdk.d.ts +3 -1
  17. package/dist/adapters/ethers/sdk.js +8 -7
  18. package/dist/adapters/viem/client.cjs +44 -0
  19. package/dist/adapters/viem/client.cjs.map +1 -1
  20. package/dist/adapters/viem/client.d.ts +11 -0
  21. package/dist/adapters/viem/client.js +6 -5
  22. package/dist/adapters/viem/index.cjs +1094 -296
  23. package/dist/adapters/viem/index.cjs.map +1 -1
  24. package/dist/adapters/viem/index.d.ts +2 -1
  25. package/dist/adapters/viem/index.js +10 -8
  26. package/dist/adapters/viem/resources/withdrawals/context.d.ts +12 -1
  27. package/dist/adapters/viem/resources/withdrawals/index.d.ts +17 -1
  28. package/dist/adapters/viem/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
  29. package/dist/adapters/viem/resources/withdrawals/services/finalization.d.ts +36 -18
  30. package/dist/adapters/viem/resources/withdrawals/services/protocol.d.ts +11 -0
  31. package/dist/adapters/viem/sdk.cjs +1048 -295
  32. package/dist/adapters/viem/sdk.cjs.map +1 -1
  33. package/dist/adapters/viem/sdk.d.ts +3 -1
  34. package/dist/adapters/viem/sdk.js +8 -7
  35. package/dist/{chunk-SBGBYZJM.js → chunk-2D3FBCZC.js} +2 -2
  36. package/dist/{chunk-3HHUZXSV.js → chunk-32N6TI6K.js} +10 -2
  37. package/dist/{chunk-6LYAENO6.js → chunk-3SPDWWRD.js} +6 -4
  38. package/dist/{chunk-3T5V4HKS.js → chunk-4K4LOCQJ.js} +569 -259
  39. package/dist/{chunk-UEKFQAOS.js → chunk-AMRHBZIY.js} +304 -2
  40. package/dist/{chunk-E2XKJCI5.js → chunk-CP4SQ5PM.js} +537 -242
  41. package/dist/{chunk-NJK325XV.js → chunk-CPNHKNI4.js} +2 -2
  42. package/dist/{chunk-TYYUG5GA.js → chunk-CUBUD4J4.js} +1 -1
  43. package/dist/{chunk-CK5UFAZK.js → chunk-JXBLQQEN.js} +37 -3
  44. package/dist/{chunk-JSBMIT4S.js → chunk-KL6ZCPWJ.js} +1 -1
  45. package/dist/{chunk-MT4X5FEO.js → chunk-NQRYXL3K.js} +3 -1
  46. package/dist/{chunk-24TE2NNJ.js → chunk-PI4PF6WT.js} +24 -4
  47. package/dist/chunk-QUAPG3ZR.js +157 -0
  48. package/dist/chunk-UMPAKZCQ.js +19 -0
  49. package/dist/core/abi.d.ts +1 -0
  50. package/dist/core/constants.cjs +2 -0
  51. package/dist/core/constants.cjs.map +1 -1
  52. package/dist/core/constants.d.ts +9 -0
  53. package/dist/core/constants.js +1 -1
  54. package/dist/core/index.cjs +513 -0
  55. package/dist/core/index.cjs.map +1 -1
  56. package/dist/core/index.d.ts +6 -1
  57. package/dist/core/index.js +6 -4
  58. package/dist/core/internal/abis/IERC7786Attributes.d.ts +10 -0
  59. package/dist/core/internal/abis/IL1NullifierV32.d.ts +221 -0
  60. package/dist/core/resources/interop/attributes/bundle.d.ts +1 -0
  61. package/dist/core/resources/interop/attributes/resource.d.ts +1 -0
  62. package/dist/core/resources/protocol/semver.d.ts +18 -0
  63. package/dist/core/resources/withdrawals/bundle.d.ts +80 -0
  64. package/dist/core/resources/withdrawals/finalization.d.ts +142 -0
  65. package/dist/core/resources/withdrawals/protocol.d.ts +55 -0
  66. package/dist/core/resources/withdrawals/status.d.ts +5 -0
  67. package/dist/core/types/flows/withdrawals.d.ts +32 -2
  68. package/dist/core/utils/events.d.ts +2 -0
  69. package/dist/index.cjs +313 -0
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.js +4 -4
  72. 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)");
@@ -2288,6 +2289,294 @@ var IL1NullifierABI = [
2288
2289
  ];
2289
2290
  var IL1Nullifier_default = IL1NullifierABI;
2290
2291
 
2292
+ // src/core/internal/abis/IL1NullifierV32.ts
2293
+ var IL1NullifierV32ABI = [
2294
+ {
2295
+ anonymous: false,
2296
+ inputs: [
2297
+ {
2298
+ indexed: true,
2299
+ internalType: "uint256",
2300
+ name: "chainId",
2301
+ type: "uint256"
2302
+ },
2303
+ {
2304
+ indexed: true,
2305
+ internalType: "bytes32",
2306
+ name: "txDataHash",
2307
+ type: "bytes32"
2308
+ },
2309
+ {
2310
+ indexed: true,
2311
+ internalType: "bytes32",
2312
+ name: "l2DepositTxHash",
2313
+ type: "bytes32"
2314
+ }
2315
+ ],
2316
+ name: "BridgehubDepositFinalized",
2317
+ type: "event"
2318
+ },
2319
+ {
2320
+ inputs: [],
2321
+ name: "BRIDGE_HUB",
2322
+ outputs: [
2323
+ {
2324
+ internalType: "contract IL1Bridgehub",
2325
+ name: "",
2326
+ type: "address"
2327
+ }
2328
+ ],
2329
+ stateMutability: "view",
2330
+ type: "function"
2331
+ },
2332
+ {
2333
+ inputs: [],
2334
+ name: "l1AssetRouter",
2335
+ outputs: [
2336
+ {
2337
+ internalType: "contract IL1AssetRouter",
2338
+ name: "",
2339
+ type: "address"
2340
+ }
2341
+ ],
2342
+ stateMutability: "view",
2343
+ type: "function"
2344
+ },
2345
+ {
2346
+ // The contract that took over withdrawal finalization from the nullifier's own (removed)
2347
+ // `finalizeDeposit`.
2348
+ inputs: [],
2349
+ name: "l1InteropHandler",
2350
+ outputs: [
2351
+ {
2352
+ internalType: "address",
2353
+ name: "",
2354
+ type: "address"
2355
+ }
2356
+ ],
2357
+ stateMutability: "view",
2358
+ type: "function"
2359
+ },
2360
+ {
2361
+ inputs: [],
2362
+ name: "l1NativeTokenVault",
2363
+ outputs: [
2364
+ {
2365
+ internalType: "contract IL1NativeTokenVault",
2366
+ name: "",
2367
+ type: "address"
2368
+ }
2369
+ ],
2370
+ stateMutability: "view",
2371
+ type: "function"
2372
+ },
2373
+ {
2374
+ inputs: [
2375
+ {
2376
+ internalType: "uint256",
2377
+ name: "_chainId",
2378
+ type: "uint256"
2379
+ },
2380
+ {
2381
+ internalType: "bytes32",
2382
+ name: "_l2TxHash",
2383
+ type: "bytes32"
2384
+ }
2385
+ ],
2386
+ name: "depositHappened",
2387
+ outputs: [
2388
+ {
2389
+ internalType: "bytes32",
2390
+ name: "",
2391
+ type: "bytes32"
2392
+ }
2393
+ ],
2394
+ stateMutability: "view",
2395
+ type: "function"
2396
+ },
2397
+ {
2398
+ inputs: [
2399
+ {
2400
+ internalType: "uint256",
2401
+ name: "_chainId",
2402
+ type: "uint256"
2403
+ },
2404
+ {
2405
+ internalType: "bytes32",
2406
+ name: "_txDataHash",
2407
+ type: "bytes32"
2408
+ },
2409
+ {
2410
+ internalType: "bytes32",
2411
+ name: "_txHash",
2412
+ type: "bytes32"
2413
+ }
2414
+ ],
2415
+ name: "bridgehubConfirmL2TransactionForwarded",
2416
+ outputs: [],
2417
+ stateMutability: "nonpayable",
2418
+ type: "function"
2419
+ },
2420
+ {
2421
+ inputs: [
2422
+ {
2423
+ components: [
2424
+ {
2425
+ internalType: "uint256",
2426
+ name: "_chainId",
2427
+ type: "uint256"
2428
+ },
2429
+ {
2430
+ internalType: "address",
2431
+ name: "_depositSender",
2432
+ type: "address"
2433
+ },
2434
+ {
2435
+ internalType: "uint16",
2436
+ name: "_l2TxNumberInBatch",
2437
+ type: "uint16"
2438
+ },
2439
+ {
2440
+ internalType: "enum TxStatus",
2441
+ name: "_txStatus",
2442
+ type: "uint8"
2443
+ },
2444
+ {
2445
+ internalType: "bytes32",
2446
+ name: "_assetId",
2447
+ type: "bytes32"
2448
+ },
2449
+ {
2450
+ internalType: "bytes",
2451
+ name: "_assetData",
2452
+ type: "bytes"
2453
+ },
2454
+ {
2455
+ internalType: "bytes32",
2456
+ name: "_l2TxHash",
2457
+ type: "bytes32"
2458
+ },
2459
+ {
2460
+ internalType: "uint256",
2461
+ name: "_l2BatchNumber",
2462
+ type: "uint256"
2463
+ },
2464
+ {
2465
+ internalType: "uint256",
2466
+ name: "_l2MessageIndex",
2467
+ type: "uint256"
2468
+ },
2469
+ {
2470
+ internalType: "bytes32[]",
2471
+ name: "_merkleProof",
2472
+ type: "bytes32[]"
2473
+ }
2474
+ ],
2475
+ internalType: "struct ConfirmTransferResultData",
2476
+ name: "_confirmTransferResultData",
2477
+ type: "tuple"
2478
+ }
2479
+ ],
2480
+ name: "bridgeConfirmTransferResult",
2481
+ outputs: [],
2482
+ stateMutability: "nonpayable",
2483
+ type: "function"
2484
+ },
2485
+ {
2486
+ inputs: [
2487
+ {
2488
+ internalType: "uint256",
2489
+ name: "_chainId",
2490
+ type: "uint256"
2491
+ },
2492
+ {
2493
+ internalType: "address",
2494
+ name: "_depositSender",
2495
+ type: "address"
2496
+ },
2497
+ {
2498
+ internalType: "bytes32",
2499
+ name: "_assetId",
2500
+ type: "bytes32"
2501
+ },
2502
+ {
2503
+ internalType: "bytes",
2504
+ name: "_assetData",
2505
+ type: "bytes"
2506
+ },
2507
+ {
2508
+ internalType: "bytes32",
2509
+ name: "_l2TxHash",
2510
+ type: "bytes32"
2511
+ },
2512
+ {
2513
+ internalType: "uint256",
2514
+ name: "_l2BatchNumber",
2515
+ type: "uint256"
2516
+ },
2517
+ {
2518
+ internalType: "uint256",
2519
+ name: "_l2MessageIndex",
2520
+ type: "uint256"
2521
+ },
2522
+ {
2523
+ internalType: "uint16",
2524
+ name: "_l2TxNumberInBatch",
2525
+ type: "uint16"
2526
+ },
2527
+ {
2528
+ internalType: "bytes32[]",
2529
+ name: "_merkleProof",
2530
+ type: "bytes32[]"
2531
+ }
2532
+ ],
2533
+ name: "bridgeRecoverFailedTransfer",
2534
+ outputs: [],
2535
+ stateMutability: "nonpayable",
2536
+ type: "function"
2537
+ },
2538
+ {
2539
+ inputs: [
2540
+ {
2541
+ internalType: "contract IL1NativeTokenVault",
2542
+ name: "_nativeTokenVault",
2543
+ type: "address"
2544
+ }
2545
+ ],
2546
+ name: "setL1NativeTokenVault",
2547
+ outputs: [],
2548
+ stateMutability: "nonpayable",
2549
+ type: "function"
2550
+ },
2551
+ {
2552
+ inputs: [
2553
+ {
2554
+ internalType: "address",
2555
+ name: "_l1AssetRouter",
2556
+ type: "address"
2557
+ }
2558
+ ],
2559
+ name: "setL1AssetRouter",
2560
+ outputs: [],
2561
+ stateMutability: "nonpayable",
2562
+ type: "function"
2563
+ },
2564
+ {
2565
+ inputs: [
2566
+ {
2567
+ internalType: "address",
2568
+ name: "_l1InteropHandler",
2569
+ type: "address"
2570
+ }
2571
+ ],
2572
+ name: "setL1InteropHandler",
2573
+ outputs: [],
2574
+ stateMutability: "nonpayable",
2575
+ type: "function"
2576
+ }
2577
+ ];
2578
+ var IL1NullifierV32_default = IL1NullifierV32ABI;
2579
+
2291
2580
  // src/core/internal/abis/IL2AssetRouter.ts
2292
2581
  var IL2AssetRouterABI = [
2293
2582
  {
@@ -3724,6 +4013,19 @@ var IERC7786AttributesABI = [
3724
4013
  outputs: [],
3725
4014
  stateMutability: "pure"
3726
4015
  },
4016
+ {
4017
+ type: "function",
4018
+ name: "interopBundleSalt",
4019
+ inputs: [
4020
+ {
4021
+ name: "_salt",
4022
+ type: "bytes32",
4023
+ internalType: "bytes32"
4024
+ }
4025
+ ],
4026
+ outputs: [],
4027
+ stateMutability: "pure"
4028
+ },
3727
4029
  {
3728
4030
  type: "function",
3729
4031
  name: "unbundlerAddress",
@@ -6172,7 +6474,7 @@ function createErrorOps(decodeRevert2) {
6172
6474
  function wrap7(operation, fn, opts) {
6173
6475
  return run("INTERNAL", operation, fn, opts);
6174
6476
  }
6175
- function wrapAs9(kind, operation, fn, opts) {
6477
+ function wrapAs10(kind, operation, fn, opts) {
6176
6478
  return run(kind, operation, fn, opts);
6177
6479
  }
6178
6480
  async function toResult3(operation, fn, opts) {
@@ -6193,7 +6495,7 @@ function createErrorOps(decodeRevert2) {
6193
6495
  return { ok: false, error: shaped };
6194
6496
  }
6195
6497
  }
6196
- return { wrap: wrap7, wrapAs: wrapAs9, toResult: toResult3 };
6498
+ return { wrap: wrap7, wrapAs: wrapAs10, toResult: toResult3 };
6197
6499
  }
6198
6500
  return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
6199
6501
  }
@@ -7824,7 +8126,7 @@ function pickWithdrawRoute(args) {
7824
8126
  }
7825
8127
 
7826
8128
  // src/adapters/ethers/resources/withdrawals/context.ts
7827
- async function commonCtx2(p, client, tokens, contracts) {
8129
+ async function commonCtx2(p, client, tokens, contracts, protocol) {
7828
8130
  const sender = await client.signer.getAddress();
7829
8131
  const {
7830
8132
  bridgehub,
@@ -7832,10 +8134,12 @@ async function commonCtx2(p, client, tokens, contracts) {
7832
8134
  l1Nullifier,
7833
8135
  l2AssetRouter,
7834
8136
  l2NativeTokenVault,
7835
- l2BaseTokenSystem
8137
+ l2BaseTokenSystem,
8138
+ interopCenter
7836
8139
  } = await contracts.addresses();
7837
8140
  const { chainId } = await client.l2.getNetwork();
7838
8141
  const chainIdL2 = BigInt(chainId);
8142
+ const l1ChainId = BigInt((await client.l1.getNetwork()).chainId);
7839
8143
  const resolvedToken = await tokens.resolve(p.token, { chain: "l2" });
7840
8144
  const baseTokenAssetId = resolvedToken.baseTokenAssetId;
7841
8145
  const baseTokenL1 = await tokens.l1TokenFromAssetId(baseTokenAssetId);
@@ -7857,6 +8161,9 @@ async function commonCtx2(p, client, tokens, contracts) {
7857
8161
  l2AssetRouter,
7858
8162
  l2NativeTokenVault,
7859
8163
  l2BaseTokenSystem,
8164
+ interopCenter,
8165
+ protocol,
8166
+ l1ChainId,
7860
8167
  baseIsEth,
7861
8168
  gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
7862
8169
  };
@@ -8099,6 +8406,268 @@ function routeErc20NonBase2() {
8099
8406
  }
8100
8407
  };
8101
8408
  }
8409
+ var PREFIX_EVM_CHAIN = ethers.getBytes("0x00010000");
8410
+ var PREFIX_EVM_ADDRESS = ethers.getBytes("0x000100000014");
8411
+ function formatInteropEvmChain(chainId) {
8412
+ const chainRef = ethers.toBeArray(chainId);
8413
+ const chainRefLength = ethers.getBytes(ethers.toBeHex(chainRef.length, 1));
8414
+ const payload = ethers.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
8415
+ return ethers.hexlify(payload);
8416
+ }
8417
+ function formatInteropEvmAddress(address) {
8418
+ const normalized = ethers.getAddress(address);
8419
+ const addrBytes = ethers.getBytes(normalized);
8420
+ const payload = ethers.concat([PREFIX_EVM_ADDRESS, addrBytes]);
8421
+ return ethers.hexlify(payload);
8422
+ }
8423
+ var interopCodec = {
8424
+ formatChain: formatInteropEvmChain,
8425
+ formatAddress: formatInteropEvmAddress
8426
+ };
8427
+
8428
+ // src/core/resources/interop/attributes/call.ts
8429
+ function createCallAttributes(codec) {
8430
+ const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
8431
+ const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
8432
+ return {
8433
+ indirectCall,
8434
+ interopCallValue
8435
+ };
8436
+ }
8437
+
8438
+ // src/core/resources/interop/attributes/bundle.ts
8439
+ function createBundleAttributes(codec) {
8440
+ const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
8441
+ const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
8442
+ const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
8443
+ const interopBundleSalt = (salt) => codec.encode("interopBundleSalt", [salt]);
8444
+ return {
8445
+ executionAddress,
8446
+ unbundlerAddress,
8447
+ useFixedFee,
8448
+ interopBundleSalt
8449
+ };
8450
+ }
8451
+
8452
+ // src/core/resources/interop/attributes/resource.ts
8453
+ function createAttributesResource(codec) {
8454
+ return {
8455
+ call: createCallAttributes(codec),
8456
+ bundle: createBundleAttributes(codec)
8457
+ };
8458
+ }
8459
+
8460
+ // src/adapters/ethers/resources/interop/attributes/resource.ts
8461
+ function getInteropAttributes(params, ctx) {
8462
+ const bundleAttributes = [];
8463
+ if (params.execution?.only) {
8464
+ bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
8465
+ }
8466
+ if (params.unbundling?.by) {
8467
+ bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
8468
+ }
8469
+ bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
8470
+ const callAttributes = params.actions.map((action) => {
8471
+ switch (action.type) {
8472
+ case "sendNative": {
8473
+ const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
8474
+ if (baseMatches) {
8475
+ return [ctx.attributes.call.interopCallValue(action.amount)];
8476
+ }
8477
+ return [ctx.attributes.call.indirectCall(action.amount)];
8478
+ }
8479
+ case "call":
8480
+ if (action.value && action.value > 0n) {
8481
+ return [ctx.attributes.call.interopCallValue(action.value)];
8482
+ }
8483
+ return [];
8484
+ case "sendErc20":
8485
+ return [ctx.attributes.call.indirectCall(0n)];
8486
+ default:
8487
+ assertNever(action);
8488
+ }
8489
+ });
8490
+ return { bundleAttributes, callAttributes };
8491
+ }
8492
+ function createEthersAttributesResource(opts = {}) {
8493
+ const iface = opts.iface ?? new ethers.Interface(IERC7786Attributes_default);
8494
+ const encode2 = (fn, args) => iface.encodeFunctionData(fn, args);
8495
+ return createAttributesResource({ encode: encode2 });
8496
+ }
8497
+
8498
+ // src/core/resources/withdrawals/bundle.ts
8499
+ function buildWithdrawalBundle(input) {
8500
+ const {
8501
+ assetId,
8502
+ amount,
8503
+ l1Receiver,
8504
+ l2Token,
8505
+ isBaseToken,
8506
+ l1ChainId,
8507
+ l2AssetRouter,
8508
+ salt,
8509
+ codec,
8510
+ attributes: attributes2,
8511
+ transferData
8512
+ } = input;
8513
+ const burnData = transferData.encodeBridgeBurnData(amount, l1Receiver, l2Token);
8514
+ const depositData = transferData.encodeAssetRouterDepositData(assetId, burnData);
8515
+ const indirectCallMessageValue = isBaseToken ? amount : 0n;
8516
+ const starter = [
8517
+ codec.formatAddress(l2AssetRouter),
8518
+ depositData,
8519
+ [attributes2.indirectCall(indirectCallMessageValue), attributes2.interopCallValue(0n)]
8520
+ ];
8521
+ return {
8522
+ destinationChain: codec.formatChain(l1ChainId),
8523
+ starters: [starter],
8524
+ // No `atomicBundle` attribute: L2 -> L1 withdrawals are non-atomic and are published to L1 as a
8525
+ // `BUNDLE_IDENTIFIER`-prefixed message, which is what the L1 handler proves inclusion of.
8526
+ bundleAttributes: [attributes2.interopBundleSalt(salt)],
8527
+ value: indirectCallMessageValue
8528
+ };
8529
+ }
8530
+
8531
+ // src/adapters/ethers/resources/withdrawals/routes/interop-bundle.ts
8532
+ var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
8533
+ var attributes = createEthersAttributesResource();
8534
+ function saltFor(sender, nonce) {
8535
+ return ethers.keccak256(
8536
+ ethers.AbiCoder.defaultAbiCoder().encode(["address", "uint256"], [sender, BigInt(nonce)])
8537
+ );
8538
+ }
8539
+ function routeInteropBundle() {
8540
+ return {
8541
+ async build(p, ctx) {
8542
+ const steps = [];
8543
+ const approvals = [];
8544
+ const isBaseToken = ctx.route === "base";
8545
+ const l1Receiver = p.to ?? ctx.sender;
8546
+ let assetId;
8547
+ let allowanceSufficient = true;
8548
+ if (isBaseToken) {
8549
+ assetId = ctx.baseTokenAssetId;
8550
+ } else {
8551
+ assetId = await wrapAs8(
8552
+ "CONTRACT",
8553
+ OP_WITHDRAWALS.erc20.ensureRegistered,
8554
+ async () => {
8555
+ const ntv = await ctx.contracts.l2NativeTokenVault();
8556
+ return await ntv.getFunction("ensureTokenIsRegistered").staticCall(p.token);
8557
+ },
8558
+ {
8559
+ ctx: { where: "L2NativeTokenVault.ensureTokenIsRegistered", token: p.token },
8560
+ message: "Failed to ensure token is registered in L2NativeTokenVault."
8561
+ }
8562
+ );
8563
+ const erc20 = new ethers.Contract(p.token, IERC20_default, ctx.client.l2);
8564
+ const current = await wrapAs8(
8565
+ "CONTRACT",
8566
+ OP_WITHDRAWALS.erc20.allowance,
8567
+ () => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
8568
+ {
8569
+ ctx: {
8570
+ where: "erc20.allowance",
8571
+ chain: "L2",
8572
+ token: p.token,
8573
+ spender: ctx.l2NativeTokenVault
8574
+ },
8575
+ message: "Failed to read L2 ERC-20 allowance."
8576
+ }
8577
+ );
8578
+ allowanceSufficient = current >= p.amount;
8579
+ if (!allowanceSufficient) {
8580
+ approvals.push({ token: p.token, spender: ctx.l2NativeTokenVault, amount: p.amount });
8581
+ const approveTx = {
8582
+ to: p.token,
8583
+ data: erc20.interface.encodeFunctionData("approve", [ctx.l2NativeTokenVault, p.amount]),
8584
+ from: ctx.sender
8585
+ };
8586
+ const approveGas = await quoteL2Gas4({ ctx, tx: approveTx });
8587
+ if (approveGas) {
8588
+ approveTx.gasLimit = approveGas.gasLimit;
8589
+ approveTx.maxFeePerGas = approveGas.maxFeePerGas;
8590
+ approveTx.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
8591
+ }
8592
+ steps.push({
8593
+ key: `approve:l2:${p.token}:${ctx.l2NativeTokenVault}`,
8594
+ kind: "approve:l2",
8595
+ description: `Approve ${p.amount} to NativeTokenVault`,
8596
+ tx: approveTx
8597
+ });
8598
+ }
8599
+ }
8600
+ const nonce = await wrapAs8(
8601
+ "RPC",
8602
+ OP_WITHDRAWALS.prepare,
8603
+ () => ctx.client.l2.getTransactionCount(ctx.sender, "pending"),
8604
+ {
8605
+ ctx: { where: "l2.getTransactionCount", sender: ctx.sender },
8606
+ message: "Failed to read L2 nonce for the interop bundle salt."
8607
+ }
8608
+ );
8609
+ const bundle = buildWithdrawalBundle({
8610
+ assetId,
8611
+ amount: p.amount,
8612
+ l1Receiver,
8613
+ l2Token: isBaseToken ? FORMAL_ETH_ADDRESS : p.token,
8614
+ isBaseToken,
8615
+ l1ChainId: ctx.l1ChainId,
8616
+ l2AssetRouter: ctx.l2AssetRouter,
8617
+ salt: saltFor(ctx.sender, nonce),
8618
+ codec: interopCodec,
8619
+ attributes: {
8620
+ indirectCall: attributes.call.indirectCall,
8621
+ interopCallValue: attributes.call.interopCallValue,
8622
+ interopBundleSalt: attributes.bundle.interopBundleSalt
8623
+ },
8624
+ transferData: {
8625
+ encodeBridgeBurnData: (amount, receiver, token) => encodeNativeTokenVaultTransferData(amount, receiver, token),
8626
+ encodeAssetRouterDepositData: (id, data2) => encodeSecondBridgeDataV1(id, data2)
8627
+ }
8628
+ });
8629
+ const interopCenter = await ctx.contracts.interopCenter();
8630
+ const data = await wrapAs8(
8631
+ "INTERNAL",
8632
+ OP_WITHDRAWALS.erc20.encodeWithdraw,
8633
+ () => Promise.resolve(
8634
+ interopCenter.interface.encodeFunctionData("sendBundle", [
8635
+ bundle.destinationChain,
8636
+ bundle.starters,
8637
+ bundle.bundleAttributes
8638
+ ])
8639
+ ),
8640
+ {
8641
+ ctx: { where: "InteropCenter.sendBundle", assetId },
8642
+ message: "Failed to encode sendBundle calldata."
8643
+ }
8644
+ );
8645
+ const sendTx = {
8646
+ to: ctx.interopCenter,
8647
+ data,
8648
+ from: ctx.sender,
8649
+ value: bundle.value
8650
+ };
8651
+ const sendGas = allowanceSufficient ? await quoteL2Gas4({ ctx, tx: sendTx }) : void 0;
8652
+ if (sendGas) {
8653
+ sendTx.gasLimit = sendGas.gasLimit;
8654
+ sendTx.maxFeePerGas = sendGas.maxFeePerGas;
8655
+ sendTx.maxPriorityFeePerGas = sendGas.maxPriorityFeePerGas;
8656
+ }
8657
+ steps.push({
8658
+ key: "interop-center:send-bundle",
8659
+ kind: "interop-center:send-bundle",
8660
+ description: "Burn on L2 & send L2\u2192L1 withdrawal bundle",
8661
+ tx: sendTx
8662
+ });
8663
+ const fees = buildFeeBreakdown2({
8664
+ feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
8665
+ l2Gas: sendGas
8666
+ });
8667
+ return { steps, approvals, fees };
8668
+ }
8669
+ };
8670
+ }
8102
8671
 
8103
8672
  // src/core/utils/events.ts
8104
8673
  function extractPreferAddress(opts) {
@@ -8127,6 +8696,14 @@ function isL1MessageSentLog(log, opts) {
8127
8696
  const preferAddr = extractPreferAddress(opts);
8128
8697
  return log.address.toLowerCase() === preferAddr && (topic === TOPIC_L1_MESSAGE_SENT_LEG.toLowerCase() || topic === TOPIC_L1_MESSAGE_SENT_NEW.toLowerCase());
8129
8698
  }
8699
+ var SENDER_TOPIC = /^0x0{24}([0-9a-fA-F]{40})$/;
8700
+ function l1MessageSentSender(log) {
8701
+ const sender = SENDER_TOPIC.exec(log.topics?.[1] ?? "")?.[1];
8702
+ if (!sender) {
8703
+ throw new Error("L1MessageSent log has no valid sender topic.");
8704
+ }
8705
+ return `0x${sender.toLowerCase()}`;
8706
+ }
8130
8707
 
8131
8708
  // src/core/resources/withdrawals/logs.ts
8132
8709
  function messengerLogIndex(raw, opts) {
@@ -8139,176 +8716,379 @@ function messengerLogIndex(raw, opts) {
8139
8716
  }
8140
8717
  return (hits[index] ?? hits[0]).i;
8141
8718
  }
8719
+ function keccakHex(data) {
8720
+ return `0x${utils.bytesToHex(sha3.keccak_256(utils.hexToBytes(data.slice(2))))}`;
8721
+ }
8722
+ function stripBundleIdentifier(messageData) {
8723
+ const prefix = `0x${messageData.slice(2, 4)}`;
8724
+ if (prefix !== BUNDLE_IDENTIFIER) {
8725
+ throw createError("STATE", {
8726
+ resource: "withdrawals",
8727
+ operation: OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
8728
+ 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.",
8729
+ context: { prefix, expected: BUNDLE_IDENTIFIER }
8730
+ });
8731
+ }
8732
+ return `0x${messageData.slice(4)}`;
8733
+ }
8734
+ function parseBundleHashFromLogs(logs, interopCenter = L2_INTEROP_CENTER_ADDRESS) {
8735
+ const center = interopCenter.toLowerCase();
8736
+ for (const log of logs) {
8737
+ if (log.address?.toLowerCase() !== center) continue;
8738
+ if (log.topics?.length !== 1) continue;
8739
+ if (!log.data || (log.data.length - 2) / 64 < 3) continue;
8740
+ return `0x${log.data.slice(66, 130)}`;
8741
+ }
8742
+ return void 0;
8743
+ }
8744
+ function buildWithdrawalFinalization(input) {
8745
+ const { messageData, sourceChainId, txNumberInBatch, proof } = input;
8746
+ const bundle = stripBundleIdentifier(messageData);
8747
+ return {
8748
+ bundle,
8749
+ bundleHash: input.bundleHash ?? keccakHex(bundle),
8750
+ proof: {
8751
+ chainId: sourceChainId,
8752
+ l1BatchNumber: proof.batchNumber,
8753
+ l2MessageIndex: proof.id,
8754
+ message: {
8755
+ txNumberInBatch,
8756
+ sender: input.interopCenter ?? L2_INTEROP_CENTER_ADDRESS,
8757
+ data: messageData
8758
+ },
8759
+ proof: proof.proof
8760
+ }
8761
+ };
8762
+ }
8763
+ function classifyWithdrawalOutcome(bundleStatus, callStatus) {
8764
+ if (bundleStatus === 2 /* FullyExecuted */) return "finalized";
8765
+ if (bundleStatus !== 3 /* Unbundled */) return "pending";
8766
+ switch (callStatus) {
8767
+ case 1 /* Executed */:
8768
+ return "finalized";
8769
+ case 2 /* Cancelled */:
8770
+ return "failed";
8771
+ default:
8772
+ return "pending";
8773
+ }
8774
+ }
8775
+
8776
+ // src/core/resources/withdrawals/protocol.ts
8777
+ var MIN_INTEROP_WITHDRAWAL_MINOR = 32;
8778
+ function protocolFromVersion(version) {
8779
+ const [, minor] = version;
8780
+ return minor >= MIN_INTEROP_WITHDRAWAL_MINOR ? "interop-bundle" : "legacy-withdrawal";
8781
+ }
8782
+ async function detectWithdrawalProtocol(probes, override) {
8783
+ if (override) {
8784
+ return { protocol: override, source: { via: "override" } };
8785
+ }
8786
+ const version = await probes.protocolVersion();
8787
+ if (version) {
8788
+ return { protocol: protocolFromVersion(version), source: { via: "protocol-version", version } };
8789
+ }
8790
+ if (await probes.hasCodeAt(L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS)) {
8791
+ return {
8792
+ protocol: "interop-bundle",
8793
+ source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
8794
+ };
8795
+ }
8796
+ return {
8797
+ protocol: "legacy-withdrawal",
8798
+ source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
8799
+ };
8800
+ }
8801
+
8802
+ // src/adapters/ethers/resources/withdrawals/services/protocol.ts
8803
+ function createWithdrawalProtocolService(client, override) {
8804
+ let cached;
8805
+ async function hasCodeAt(address) {
8806
+ try {
8807
+ const code = await client.l2.getCode(address);
8808
+ return !!code && code !== "0x";
8809
+ } catch {
8810
+ return false;
8811
+ }
8812
+ }
8813
+ async function protocolVersion() {
8814
+ try {
8815
+ return await client.getChainProtocolVersion();
8816
+ } catch {
8817
+ return void 0;
8818
+ }
8819
+ }
8820
+ function detect() {
8821
+ cached ??= detectWithdrawalProtocol(
8822
+ {
8823
+ protocolVersion,
8824
+ hasCodeAt
8825
+ },
8826
+ override
8827
+ ).catch((e) => {
8828
+ cached = void 0;
8829
+ throw e;
8830
+ });
8831
+ return cached;
8832
+ }
8833
+ return {
8834
+ detect,
8835
+ async protocol() {
8836
+ return (await detect()).protocol;
8837
+ },
8838
+ refresh() {
8839
+ cached = void 0;
8840
+ }
8841
+ };
8842
+ }
8142
8843
 
8143
8844
  // src/adapters/ethers/resources/withdrawals/services/finalization.ts
8144
- var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
8845
+ var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
8145
8846
  var IL1NullifierMini = [
8146
8847
  "function isWithdrawalFinalized(uint256,uint256,uint256) view returns (bool)"
8147
8848
  ];
8148
- function createFinalizationServices(client) {
8849
+ function createFinalizationServices(client, protocolService = createWithdrawalProtocolService(client)) {
8149
8850
  const { l1, l2, signer } = client;
8150
- return {
8151
- async fetchFinalizeDepositParams(l2TxHash) {
8152
- const parsed = await wrapAs8(
8153
- "RPC",
8154
- OP_WITHDRAWALS.finalize.fetchParams.receipt,
8155
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
8156
- {
8157
- ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
8158
- message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
8851
+ async function finalizationTarget(protocol) {
8852
+ const { l1Nullifier } = await client.ensureAddresses();
8853
+ if (protocol === "legacy-withdrawal") return l1Nullifier;
8854
+ const nullifier = new ethers.Contract(l1Nullifier, IL1NullifierV32_default, l1);
8855
+ const handler = await wrapAs9(
8856
+ "CONTRACT",
8857
+ OP_WITHDRAWALS.finalize.fetchParams.receipt,
8858
+ () => nullifier.l1InteropHandler(),
8859
+ {
8860
+ ctx: { where: "L1Nullifier.l1InteropHandler", l1Nullifier },
8861
+ message: "Failed to resolve the L1 interop handler. The chain reports protocol v32+, but its L1Nullifier does not expose `l1InteropHandler()`."
8862
+ }
8863
+ );
8864
+ return handler;
8865
+ }
8866
+ async function fetchMessageAndProof(l2TxHash) {
8867
+ const raw = await wrapAs9(
8868
+ "RPC",
8869
+ OP_WITHDRAWALS.finalize.fetchParams.receipt,
8870
+ () => client.zks.getReceiptWithL2ToL1(l2TxHash),
8871
+ {
8872
+ ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
8873
+ message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
8874
+ }
8875
+ );
8876
+ if (!raw) {
8877
+ throw createError("STATE", {
8878
+ resource: "withdrawals",
8879
+ operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
8880
+ message: "L2 receipt not found.",
8881
+ context: { l2TxHash }
8882
+ });
8883
+ }
8884
+ const ev = await wrapAs9(
8885
+ "INTERNAL",
8886
+ OP_WITHDRAWALS.finalize.fetchParams.findMessage,
8887
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
8888
+ () => Promise.resolve(findL1MessageSentLog(raw, { index: 0 })),
8889
+ {
8890
+ ctx: { l2TxHash, index: 0 },
8891
+ message: "Failed to locate L1MessageSent event in L2 receipt."
8892
+ }
8893
+ );
8894
+ const message = await wrapAs9(
8895
+ "INTERNAL",
8896
+ OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
8897
+ () => Promise.resolve(ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
8898
+ {
8899
+ ctx: { where: "decode L1MessageSent", data: ev.data },
8900
+ message: "Failed to decode withdrawal message."
8901
+ }
8902
+ );
8903
+ const idx = await wrapAs9(
8904
+ "INTERNAL",
8905
+ OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
8906
+ () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
8907
+ {
8908
+ ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
8909
+ message: "Failed to derive messenger log index."
8910
+ }
8911
+ );
8912
+ const proof = await wrapAs9(
8913
+ "RPC",
8914
+ OP_WITHDRAWALS.finalize.fetchParams.proof,
8915
+ () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
8916
+ {
8917
+ ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
8918
+ message: "Failed to fetch L2\u2192L1 log proof."
8919
+ }
8920
+ );
8921
+ const { chainId } = await wrapAs9(
8922
+ "RPC",
8923
+ OP_WITHDRAWALS.finalize.fetchParams.network,
8924
+ () => l2.getNetwork(),
8925
+ { ctx: { where: "l2.getNetwork" }, message: "Failed to read L2 network." }
8926
+ );
8927
+ const txNumberInBatch = Number(raw.transactionIndex ?? 0);
8928
+ const l2Sender = l1MessageSentSender(ev);
8929
+ return { raw, message, proof, chainId: BigInt(chainId), txNumberInBatch, l2Sender };
8930
+ }
8931
+ async function fetchFinalization(l2TxHash) {
8932
+ const protocol = await protocolService.protocol();
8933
+ const { raw, message, proof, chainId, txNumberInBatch, l2Sender } = await fetchMessageAndProof(l2TxHash);
8934
+ const target = await finalizationTarget(protocol);
8935
+ if (protocol === "legacy-withdrawal") {
8936
+ const params2 = {
8937
+ chainId,
8938
+ l2BatchNumber: proof.batchNumber,
8939
+ l2MessageIndex: proof.id,
8940
+ l2Sender,
8941
+ l2TxNumberInBatch: txNumberInBatch,
8942
+ message,
8943
+ merkleProof: proof.proof
8944
+ };
8945
+ return {
8946
+ target,
8947
+ finalization: { protocol, params: params2 },
8948
+ key: {
8949
+ chainIdL2: chainId,
8950
+ l2BatchNumber: proof.batchNumber,
8951
+ l2MessageIndex: proof.id
8159
8952
  }
8160
- );
8161
- if (!parsed) {
8162
- throw createError("STATE", {
8163
- resource: "withdrawals",
8164
- operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
8165
- message: "L2 receipt not found.",
8166
- context: { l2TxHash }
8167
- });
8953
+ };
8954
+ }
8955
+ const { interopCenter } = await client.ensureAddresses();
8956
+ const params = buildWithdrawalFinalization({
8957
+ messageData: message,
8958
+ sourceChainId: chainId,
8959
+ txNumberInBatch,
8960
+ proof: { batchNumber: proof.batchNumber, id: proof.id, proof: proof.proof },
8961
+ // Prefer the hash the InteropCenter emitted over recomputing it.
8962
+ bundleHash: parseBundleHashFromLogs(raw.logs ?? [], interopCenter),
8963
+ interopCenter
8964
+ });
8965
+ return {
8966
+ target,
8967
+ finalization: { protocol, params },
8968
+ key: {
8969
+ chainIdL2: chainId,
8970
+ l2BatchNumber: proof.batchNumber,
8971
+ l2MessageIndex: proof.id,
8972
+ bundleHash: params.bundleHash
8168
8973
  }
8169
- const ev = await wrapAs8(
8170
- "INTERNAL",
8171
- OP_WITHDRAWALS.finalize.fetchParams.findMessage,
8172
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
8173
- () => Promise.resolve(findL1MessageSentLog(parsed, { index: 0 })),
8974
+ };
8975
+ }
8976
+ async function withdrawalOutcome(finalization) {
8977
+ const target = await finalizationTarget(finalization.protocol);
8978
+ if (finalization.protocol === "legacy-withdrawal") {
8979
+ const c = new ethers.Contract(target, IL1NullifierMini, l1);
8980
+ const done = await wrapAs9(
8981
+ "RPC",
8982
+ OP_WITHDRAWALS.finalize.isFinalized,
8983
+ () => c.isWithdrawalFinalized(
8984
+ finalization.params.chainId,
8985
+ finalization.params.l2BatchNumber,
8986
+ finalization.params.l2MessageIndex
8987
+ ),
8174
8988
  {
8175
- ctx: { l2TxHash, index: 0 },
8176
- message: "Failed to locate L1MessageSent event in L2 receipt."
8989
+ ctx: { where: "isWithdrawalFinalized", params: finalization.params },
8990
+ message: "Failed to read finalization status."
8177
8991
  }
8178
8992
  );
8179
- const message = await wrapAs8(
8180
- "INTERNAL",
8181
- OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
8182
- () => Promise.resolve(ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
8993
+ return done ? "finalized" : "pending";
8994
+ }
8995
+ const { bundleHash } = finalization.params;
8996
+ const handler = new ethers.Contract(target, IInteropHandler_default, l1);
8997
+ const status = Number(
8998
+ await wrapAs9(
8999
+ "RPC",
9000
+ OP_WITHDRAWALS.finalize.isFinalized,
9001
+ () => handler.bundleStatus(bundleHash),
8183
9002
  {
8184
- ctx: { where: "decode L1MessageSent", data: ev.data },
8185
- message: "Failed to decode withdrawal message."
9003
+ ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
9004
+ message: "Failed to read bundle status."
8186
9005
  }
8187
- );
8188
- const raw = await wrapAs8(
9006
+ )
9007
+ );
9008
+ if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
9009
+ const callStatus = Number(
9010
+ await wrapAs9(
8189
9011
  "RPC",
8190
- OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
8191
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
9012
+ OP_WITHDRAWALS.finalize.isFinalized,
9013
+ () => handler.callStatus(bundleHash, 0),
8192
9014
  {
8193
- ctx: { where: "getReceiptWithL2ToL1 (raw)", l2TxHash },
8194
- message: "Failed to fetch raw L2 receipt."
9015
+ ctx: { where: "L1InteropHandler.callStatus", bundleHash },
9016
+ message: "Failed to read bundle call status."
8195
9017
  }
8196
- );
8197
- if (!raw) {
8198
- throw createError("STATE", {
9018
+ )
9019
+ );
9020
+ return classifyWithdrawalOutcome(status, callStatus);
9021
+ }
9022
+ async function isWithdrawalFinalized(finalization) {
9023
+ return await withdrawalOutcome(finalization) === "finalized";
9024
+ }
9025
+ return {
9026
+ fetchFinalization,
9027
+ isWithdrawalFinalized,
9028
+ withdrawalOutcome,
9029
+ async fetchFinalizeDepositParams(l2TxHash) {
9030
+ const resolved = await fetchFinalization(l2TxHash);
9031
+ if (resolved.finalization.protocol !== "legacy-withdrawal") {
9032
+ throw createError("VALIDATION", {
8199
9033
  resource: "withdrawals",
8200
- operation: OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
8201
- message: "Raw L2 receipt not found.",
8202
- context: { l2TxHash }
9034
+ operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
9035
+ message: "This chain finalizes withdrawals through the L1 interop handler; `finalizeDeposit` params do not exist. Use `fetchFinalization` instead.",
9036
+ context: { l2TxHash, protocol: resolved.finalization.protocol }
8203
9037
  });
8204
9038
  }
8205
- const idx = await wrapAs8(
8206
- "INTERNAL",
8207
- OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
8208
- () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
8209
- {
8210
- ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
8211
- message: "Failed to derive messenger log index."
8212
- }
8213
- );
8214
- const proof = await wrapAs8(
8215
- "RPC",
8216
- OP_WITHDRAWALS.finalize.fetchParams.proof,
8217
- () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
8218
- {
8219
- ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
8220
- message: "Failed to fetch L2\u2192L1 log proof."
8221
- }
8222
- );
8223
- const { chainId } = await wrapAs8(
8224
- "RPC",
8225
- OP_WITHDRAWALS.finalize.fetchParams.network,
8226
- () => l2.getNetwork(),
8227
- {
8228
- ctx: { where: "l2.getNetwork" },
8229
- message: "Failed to read L2 network."
8230
- }
8231
- );
8232
- const txIndex = Number(parsed.transactionIndex ?? 0);
8233
- const params = {
8234
- chainId: BigInt(chainId),
8235
- l2BatchNumber: proof.batchNumber,
8236
- l2MessageIndex: proof.id,
8237
- l2Sender: parsed.to,
8238
- l2TxNumberInBatch: txIndex,
8239
- message,
8240
- merkleProof: proof.proof
8241
- };
8242
- const { l1Nullifier } = await client.ensureAddresses();
8243
- return { params, nullifier: l1Nullifier };
9039
+ return { params: resolved.finalization.params, nullifier: resolved.target };
8244
9040
  },
8245
- async simulateFinalizeReadiness(params) {
8246
- const { l1Nullifier } = await client.ensureAddresses();
9041
+ async simulateFinalizeReadiness(finalization) {
9042
+ const target = await finalizationTarget(finalization.protocol);
8247
9043
  const done = await (async () => {
8248
9044
  try {
8249
- const cMini = new ethers.Contract(l1Nullifier, IL1NullifierMini, l1);
8250
- const isFinalized = await wrapAs8(
8251
- "RPC",
8252
- OP_WITHDRAWALS.finalize.readiness.isFinalized,
8253
- () => cMini.isWithdrawalFinalized(
8254
- params.chainId,
8255
- params.l2BatchNumber,
8256
- params.l2MessageIndex
8257
- ),
8258
- {
8259
- ctx: { where: "isWithdrawalFinalized", params },
8260
- message: "Failed to read finalization status."
8261
- }
8262
- );
8263
- return Boolean(isFinalized);
9045
+ return await isWithdrawalFinalized(finalization);
8264
9046
  } catch {
8265
9047
  return false;
8266
9048
  }
8267
9049
  })();
8268
9050
  if (done) return { kind: "FINALIZED" };
8269
- const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, l1);
8270
9051
  try {
8271
- await c.finalizeDeposit.staticCall(params);
9052
+ if (finalization.protocol === "legacy-withdrawal") {
9053
+ const c = new ethers.Contract(target, IL1Nullifier_default, l1);
9054
+ await c.finalizeDeposit.staticCall(finalization.params);
9055
+ } else {
9056
+ const handler = new ethers.Contract(target, IInteropHandler_default, l1);
9057
+ await handler.executeBundle.staticCall(
9058
+ finalization.params.bundle,
9059
+ finalization.params.proof
9060
+ );
9061
+ }
8272
9062
  return { kind: "READY" };
8273
9063
  } catch (e) {
8274
9064
  return classifyReadinessFromRevert(e);
8275
9065
  }
8276
9066
  },
8277
- async isWithdrawalFinalized(key) {
8278
- const { l1Nullifier } = await client.ensureAddresses();
8279
- const c = new ethers.Contract(l1Nullifier, IL1NullifierMini, l1);
8280
- return await wrapAs8(
8281
- "RPC",
8282
- OP_WITHDRAWALS.finalize.isFinalized,
8283
- () => c.isWithdrawalFinalized(key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex),
8284
- {
8285
- ctx: { where: "isWithdrawalFinalized", key },
8286
- message: "Failed to read finalization status."
8287
- }
8288
- );
8289
- },
8290
- async estimateFinalization(params) {
8291
- const { l1Nullifier } = await client.ensureAddresses();
8292
- const signer2 = client.getL1Signer();
8293
- const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, signer2);
8294
- const gasLimit = await wrapAs8(
9067
+ async estimateFinalization(finalization) {
9068
+ const target = await finalizationTarget(finalization.protocol);
9069
+ const l1Signer = client.getL1Signer();
9070
+ const gasLimit = await wrapAs9(
8295
9071
  "RPC",
8296
9072
  OP_WITHDRAWALS.finalize.estimate,
8297
- () => c.finalizeDeposit.estimateGas(params),
9073
+ () => {
9074
+ if (finalization.protocol === "legacy-withdrawal") {
9075
+ const c = new ethers.Contract(target, IL1Nullifier_default, l1Signer);
9076
+ return c.finalizeDeposit.estimateGas(finalization.params);
9077
+ }
9078
+ const handler = new ethers.Contract(target, IInteropHandler_default, l1Signer);
9079
+ return handler.executeBundle.estimateGas(
9080
+ finalization.params.bundle,
9081
+ finalization.params.proof
9082
+ );
9083
+ },
8298
9084
  {
8299
- ctx: {
8300
- where: "estimateGas(finalizeDeposit)",
8301
- chainIdL2: params.chainId,
8302
- l2BatchNumber: params.l2BatchNumber,
8303
- l2MessageIndex: params.l2MessageIndex,
8304
- l1Nullifier
8305
- },
8306
- message: "Failed to estimate gas for finalizeDeposit."
9085
+ ctx: { where: "estimateGas(finalize)", protocol: finalization.protocol, target },
9086
+ message: "Failed to estimate gas for withdrawal finalization."
8307
9087
  }
8308
9088
  );
8309
- const feeData = await wrapAs8("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
9089
+ const feeData = await wrapAs9("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
8310
9090
  ctx: { where: "l1.getFeeData" },
8311
- message: "Failed to estimate fee data for finalizeDeposit."
9091
+ message: "Failed to estimate fee data for withdrawal finalization."
8312
9092
  });
8313
9093
  const maxFeePerGas = feeData.maxFeePerGas ?? feeData.gasPrice ?? // legacy-style gas price if present
8314
9094
  (() => {
@@ -8319,33 +9099,49 @@ function createFinalizationServices(client) {
8319
9099
  context: { feeData }
8320
9100
  });
8321
9101
  })();
8322
- const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
8323
9102
  return {
8324
9103
  gasLimit,
8325
9104
  maxFeePerGas,
8326
- maxPriorityFeePerGas
9105
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 0n
8327
9106
  };
8328
9107
  },
8329
- async finalizeDeposit(params) {
8330
- const { l1Nullifier } = await client.ensureAddresses();
8331
- const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, signer);
9108
+ async finalize(finalization) {
9109
+ const target = await finalizationTarget(finalization.protocol);
8332
9110
  try {
8333
- const receipt = await c.finalizeDeposit(params);
8334
- const hash = receipt.hash;
9111
+ const sent = await (async () => {
9112
+ if (finalization.protocol === "legacy-withdrawal") {
9113
+ const c = new ethers.Contract(target, IL1Nullifier_default, signer);
9114
+ return await c.finalizeDeposit(finalization.params);
9115
+ }
9116
+ const handler = new ethers.Contract(target, IInteropHandler_default, signer);
9117
+ return await handler.executeBundle(
9118
+ finalization.params.bundle,
9119
+ finalization.params.proof
9120
+ );
9121
+ })();
9122
+ const hash = sent.hash;
8335
9123
  return {
8336
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
8337
9124
  hash,
8338
9125
  wait: async () => {
8339
9126
  try {
8340
- return await receipt.wait();
9127
+ const receipt = await sent.wait();
9128
+ if (!receipt) {
9129
+ throw createError("EXECUTION", {
9130
+ resource: "withdrawals",
9131
+ operation: OP_WITHDRAWALS.finalize.wait,
9132
+ message: "Withdrawal finalization transaction produced no receipt.",
9133
+ context: { txHash: hash, protocol: finalization.protocol }
9134
+ });
9135
+ }
9136
+ return receipt;
8341
9137
  } catch (e) {
8342
9138
  throw toZKsyncError(
8343
9139
  "EXECUTION",
8344
9140
  {
8345
9141
  resource: "withdrawals",
8346
9142
  operation: OP_WITHDRAWALS.finalize.wait,
8347
- message: "Failed while waiting for finalizeDeposit transaction.",
8348
- context: { txHash: hash }
9143
+ message: "Failed while waiting for the withdrawal finalization transaction.",
9144
+ context: { txHash: hash, protocol: finalization.protocol }
8349
9145
  },
8350
9146
  e
8351
9147
  );
@@ -8358,13 +9154,8 @@ function createFinalizationServices(client) {
8358
9154
  {
8359
9155
  resource: "withdrawals",
8360
9156
  operation: OP_WITHDRAWALS.finalize.send,
8361
- message: "Failed to send finalizeDeposit transaction.",
8362
- context: {
8363
- chainIdL2: params.chainId,
8364
- l2BatchNumber: params.l2BatchNumber,
8365
- l2MessageIndex: params.l2MessageIndex,
8366
- l1Nullifier
8367
- }
9157
+ message: "Failed to send the withdrawal finalization transaction.",
9158
+ context: { protocol: finalization.protocol, target }
8368
9159
  },
8369
9160
  e
8370
9161
  );
@@ -8373,6 +9164,23 @@ function createFinalizationServices(client) {
8373
9164
  };
8374
9165
  }
8375
9166
 
9167
+ // src/core/resources/withdrawals/status.ts
9168
+ function phaseFromReadiness(r) {
9169
+ switch (r.kind) {
9170
+ case "FINALIZED":
9171
+ return { phase: "FINALIZED" };
9172
+ case "READY":
9173
+ return { phase: "READY_TO_FINALIZE" };
9174
+ case "NOT_READY":
9175
+ return { phase: "PENDING", reason: formatReason(r.reason, r.detail) };
9176
+ case "UNFINALIZABLE":
9177
+ return { phase: "UNFINALIZABLE", reason: formatReason(r.reason, r.detail) };
9178
+ default:
9179
+ return assertNever(r);
9180
+ }
9181
+ }
9182
+ var formatReason = (reason, detail) => detail ? `${reason}: ${detail}` : reason;
9183
+
8376
9184
  // src/adapters/ethers/resources/withdrawals/index.ts
8377
9185
  var ROUTES2 = {
8378
9186
  base: routeEthBase(),
@@ -8380,15 +9188,28 @@ var ROUTES2 = {
8380
9188
  "erc20-nonbase": routeErc20NonBase2()
8381
9189
  // AssetRouter.withdraw for non-base ERC-20s
8382
9190
  };
8383
- function createWithdrawalsResource(client, tokens, contracts) {
8384
- const svc = createFinalizationServices(client);
9191
+ var INTEROP_ROUTES = {
9192
+ base: routeInteropBundle(),
9193
+ "erc20-nonbase": routeInteropBundle()
9194
+ };
9195
+ function routeStrategy(protocol, route) {
9196
+ return protocol === "interop-bundle" ? INTEROP_ROUTES[route] : ROUTES2[route];
9197
+ }
9198
+ function createWithdrawalsResource(client, tokens, contracts, options) {
9199
+ const protocolService = createWithdrawalProtocolService(
9200
+ client,
9201
+ options?.protocol
9202
+ );
9203
+ const svc = createFinalizationServices(client, protocolService);
8385
9204
  const { wrap: wrap7, toResult: toResult3 } = createErrorHandlers("withdrawals");
8386
9205
  const tokensResource = tokens ?? createTokensResource(client);
8387
9206
  const contractsResource = contracts ?? createContractsResource(client);
8388
9207
  async function buildPlan(p) {
8389
- const ctx = await commonCtx2(p, client, tokensResource, contractsResource);
8390
- await ROUTES2[ctx.route].preflight?.(p, ctx);
8391
- const { steps, approvals, fees } = await ROUTES2[ctx.route].build(p, ctx);
9208
+ const protocol = await protocolService.protocol();
9209
+ const ctx = await commonCtx2(p, client, tokensResource, contractsResource, protocol);
9210
+ const strategy = routeStrategy(protocol, ctx.route);
9211
+ await strategy.preflight?.(p, ctx);
9212
+ const { steps, approvals, fees } = await strategy.build(p, ctx);
8392
9213
  return {
8393
9214
  route: ctx.route,
8394
9215
  summary: {
@@ -8532,24 +9353,22 @@ function createWithdrawalsResource(client, tokens, contracts) {
8532
9353
  if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
8533
9354
  let pack;
8534
9355
  try {
8535
- pack = await svc.fetchFinalizeDepositParams(l2TxHash);
9356
+ pack = await svc.fetchFinalization(l2TxHash);
8536
9357
  } catch {
8537
9358
  return { phase: "PENDING", l2TxHash };
8538
9359
  }
8539
- const key = {
8540
- chainIdL2: pack.params.chainId,
8541
- l2BatchNumber: pack.params.l2BatchNumber,
8542
- l2MessageIndex: pack.params.l2MessageIndex
8543
- };
9360
+ const key = pack.key;
8544
9361
  try {
8545
- const done = await svc.isWithdrawalFinalized(key);
8546
- if (done) return { phase: "FINALIZED", l2TxHash, key };
9362
+ const outcome = await svc.withdrawalOutcome(pack.finalization);
9363
+ if (outcome === "finalized") return { phase: "FINALIZED", l2TxHash, key };
9364
+ if (outcome === "failed") {
9365
+ return { phase: "UNFINALIZABLE", l2TxHash, key, reason: "bundle-cancelled" };
9366
+ }
8547
9367
  } catch {
8548
9368
  }
8549
- const readiness = await svc.simulateFinalizeReadiness(pack.params);
8550
- if (readiness.kind === "FINALIZED") return { phase: "FINALIZED", l2TxHash, key };
8551
- if (readiness.kind === "READY") return { phase: "READY_TO_FINALIZE", l2TxHash, key };
8552
- return { phase: "PENDING", l2TxHash, key };
9369
+ const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
9370
+ const { phase, reason } = phaseFromReadiness(readiness);
9371
+ return { phase, reason, l2TxHash, key };
8553
9372
  },
8554
9373
  {
8555
9374
  message: "Internal error while checking withdrawal status.",
@@ -8593,6 +9412,14 @@ function createWithdrawalsResource(client, tokens, contracts) {
8593
9412
  const deadline = opts.timeoutMs ? Date.now() + opts.timeoutMs : void 0;
8594
9413
  while (true) {
8595
9414
  const s = await status(l2Hash);
9415
+ if (s.phase === "UNFINALIZABLE") {
9416
+ throw createError("STATE", {
9417
+ resource: "withdrawals",
9418
+ operation: OP_WITHDRAWALS.wait,
9419
+ message: "Withdrawal can never be finalized.",
9420
+ context: { l2TxHash: l2Hash, reason: s.reason }
9421
+ });
9422
+ }
8596
9423
  if (opts.for === "ready") {
8597
9424
  if (s.phase === "READY_TO_FINALIZE" || s.phase === "FINALIZED") return null;
8598
9425
  } else {
@@ -8629,7 +9456,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
8629
9456
  async () => {
8630
9457
  const pack = await (async () => {
8631
9458
  try {
8632
- return await svc.fetchFinalizeDepositParams(l2TxHash);
9459
+ return await svc.fetchFinalization(l2TxHash);
8633
9460
  } catch (e) {
8634
9461
  throw createError("STATE", {
8635
9462
  resource: "withdrawals",
@@ -8640,21 +9467,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
8640
9467
  });
8641
9468
  }
8642
9469
  })();
8643
- const { params } = pack;
8644
- const key = {
8645
- chainIdL2: params.chainId,
8646
- l2BatchNumber: params.l2BatchNumber,
8647
- l2MessageIndex: params.l2MessageIndex
8648
- };
9470
+ const { finalization } = pack;
8649
9471
  try {
8650
- const done = await svc.isWithdrawalFinalized(key);
8651
- if (done) {
9472
+ const outcome = await svc.withdrawalOutcome(finalization);
9473
+ if (outcome === "finalized" || outcome === "failed") {
8652
9474
  const statusNow = await status(l2TxHash);
8653
9475
  return { status: statusNow };
8654
9476
  }
8655
9477
  } catch {
8656
9478
  }
8657
- const readiness = await svc.simulateFinalizeReadiness(params);
9479
+ const readiness = await svc.simulateFinalizeReadiness(finalization);
8658
9480
  if (readiness.kind === "FINALIZED") {
8659
9481
  const statusNow = await status(l2TxHash);
8660
9482
  return { status: statusNow };
@@ -8668,7 +9490,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
8668
9490
  });
8669
9491
  }
8670
9492
  try {
8671
- const tx = await svc.finalizeDeposit(params);
9493
+ const tx = await svc.finalize(finalization);
8672
9494
  finalizeCache.set(l2TxHash, tx.hash);
8673
9495
  const rcpt = await tx.wait();
8674
9496
  const statusNow = await status(l2TxHash);
@@ -8677,7 +9499,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
8677
9499
  const statusNow = await status(l2TxHash);
8678
9500
  if (statusNow.phase === "FINALIZED") return { status: statusNow };
8679
9501
  try {
8680
- const again = await svc.simulateFinalizeReadiness(params);
9502
+ const again = await svc.simulateFinalizeReadiness(finalization);
8681
9503
  if (again.kind === "NOT_READY") {
8682
9504
  throw createError("STATE", {
8683
9505
  resource: "withdrawals",
@@ -8736,74 +9558,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
8736
9558
  };
8737
9559
  }
8738
9560
 
8739
- // src/core/resources/interop/attributes/call.ts
8740
- function createCallAttributes(codec) {
8741
- const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
8742
- const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
8743
- return {
8744
- indirectCall,
8745
- interopCallValue
8746
- };
8747
- }
8748
-
8749
- // src/core/resources/interop/attributes/bundle.ts
8750
- function createBundleAttributes(codec) {
8751
- const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
8752
- const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
8753
- const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
8754
- return {
8755
- executionAddress,
8756
- unbundlerAddress,
8757
- useFixedFee
8758
- };
8759
- }
8760
-
8761
- // src/core/resources/interop/attributes/resource.ts
8762
- function createAttributesResource(codec) {
8763
- return {
8764
- call: createCallAttributes(codec),
8765
- bundle: createBundleAttributes(codec)
8766
- };
8767
- }
8768
-
8769
- // src/adapters/ethers/resources/interop/attributes/resource.ts
8770
- function getInteropAttributes(params, ctx) {
8771
- const bundleAttributes = [];
8772
- if (params.execution?.only) {
8773
- bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
8774
- }
8775
- if (params.unbundling?.by) {
8776
- bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
8777
- }
8778
- bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
8779
- const callAttributes = params.actions.map((action) => {
8780
- switch (action.type) {
8781
- case "sendNative": {
8782
- const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
8783
- if (baseMatches) {
8784
- return [ctx.attributes.call.interopCallValue(action.amount)];
8785
- }
8786
- return [ctx.attributes.call.indirectCall(action.amount)];
8787
- }
8788
- case "call":
8789
- if (action.value && action.value > 0n) {
8790
- return [ctx.attributes.call.interopCallValue(action.value)];
8791
- }
8792
- return [];
8793
- case "sendErc20":
8794
- return [ctx.attributes.call.indirectCall(0n)];
8795
- default:
8796
- assertNever(action);
8797
- }
8798
- });
8799
- return { bundleAttributes, callAttributes };
8800
- }
8801
- function createEthersAttributesResource(opts = {}) {
8802
- const iface = opts.iface ?? new ethers.Interface(IERC7786Attributes_default);
8803
- const encode2 = (fn, args) => iface.encodeFunctionData(fn, args);
8804
- return createAttributesResource({ encode: encode2 });
8805
- }
8806
-
8807
9561
  // src/core/types/flows/interop.ts
8808
9562
  function isInteropMessageProof(obj) {
8809
9563
  if (typeof obj !== "object" || obj === null) return false;
@@ -8980,24 +9734,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
8980
9734
  }
8981
9735
  };
8982
9736
  }
8983
- var PREFIX_EVM_CHAIN = ethers.getBytes("0x00010000");
8984
- var PREFIX_EVM_ADDRESS = ethers.getBytes("0x000100000014");
8985
- function formatInteropEvmChain(chainId) {
8986
- const chainRef = ethers.toBeArray(chainId);
8987
- const chainRefLength = ethers.getBytes(ethers.toBeHex(chainRef.length, 1));
8988
- const payload = ethers.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
8989
- return ethers.hexlify(payload);
8990
- }
8991
- function formatInteropEvmAddress(address) {
8992
- const normalized = ethers.getAddress(address);
8993
- const addrBytes = ethers.getBytes(normalized);
8994
- const payload = ethers.concat([PREFIX_EVM_ADDRESS, addrBytes]);
8995
- return ethers.hexlify(payload);
8996
- }
8997
- var interopCodec = {
8998
- formatChain: formatInteropEvmChain,
8999
- formatAddress: formatInteropEvmAddress
9000
- };
9001
9737
  function getErc20Tokens(params) {
9002
9738
  const erc20Tokens = /* @__PURE__ */ new Map();
9003
9739
  for (const action of params.actions) {
@@ -9153,7 +9889,7 @@ function routeIndirect() {
9153
9889
  resolveErc20AssetIds(erc20Tokens, ctx),
9154
9890
  buildFeeInfo(params, ctx, params.actions.length)
9155
9891
  ]);
9156
- const attributes = getInteropAttributes(params, ctx);
9892
+ const attributes2 = getInteropAttributes(params, ctx);
9157
9893
  const starterData = await getStarterData(params, ctx, erc20AssetIds);
9158
9894
  const bundle = buildIndirectBundle(
9159
9895
  params,
@@ -9164,7 +9900,7 @@ function routeIndirect() {
9164
9900
  l2NativeTokenVault: ctx.l2NativeTokenVault,
9165
9901
  codec: interopCodec
9166
9902
  },
9167
- attributes,
9903
+ attributes2,
9168
9904
  starterData,
9169
9905
  feeInfo
9170
9906
  );
@@ -9287,7 +10023,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
9287
10023
  assertProtocolVersion(srcChainId, srcProtocolVersion);
9288
10024
  assertProtocolVersion(dstChainId, dstProtocolVersion);
9289
10025
  }
9290
- async function commonCtx3(dstProvider, params, client, tokens, contracts, attributes) {
10026
+ async function commonCtx3(dstProvider, params, client, tokens, contracts, attributes2) {
9291
10027
  const sender = await client.signer.getAddress();
9292
10028
  const chainId = (await client.l2.getNetwork()).chainId;
9293
10029
  const dstChainId = (await dstProvider.getNetwork()).chainId;
@@ -9324,7 +10060,7 @@ async function commonCtx3(dstProvider, params, client, tokens, contracts, attrib
9324
10060
  l2NativeTokenVault,
9325
10061
  baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
9326
10062
  ifaces: { interopCenter: interopCenterIface, interopHandler: interopHandlerIface },
9327
- attributes,
10063
+ attributes: attributes2,
9328
10064
  gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
9329
10065
  };
9330
10066
  }
@@ -9980,7 +10716,7 @@ var ROUTES3 = {
9980
10716
  direct: routeDirect(),
9981
10717
  indirect: routeIndirect()
9982
10718
  };
9983
- function createInteropResource(client, config, tokens, contracts, attributes) {
10719
+ function createInteropResource(client, config, tokens, contracts, attributes2) {
9984
10720
  let gwProviderCache;
9985
10721
  function requireConfig() {
9986
10722
  if (!config)
@@ -10211,7 +10947,7 @@ function createEthersSdk(client, options) {
10211
10947
  const interop = createInteropResource(client, options?.interop, tokens, contracts);
10212
10948
  return {
10213
10949
  deposits: createDepositsResource(client, tokens, contracts),
10214
- withdrawals: createWithdrawalsResource(client, tokens, contracts),
10950
+ withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
10215
10951
  tokens,
10216
10952
  contracts,
10217
10953
  interop