@matterlabs/zksync-js 0.0.21 → 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 (70) 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 +1009 -274
  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 +976 -272
  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 +1060 -294
  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 +1014 -293
  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-LGTYM5XP.js → chunk-32N6TI6K.js} +1 -1
  37. package/dist/{chunk-IDXSGCGF.js → chunk-3SPDWWRD.js} +7 -22
  38. package/dist/{chunk-7GZDTLHX.js → chunk-4K4LOCQJ.js} +559 -256
  39. package/dist/{chunk-UEKFQAOS.js → chunk-AMRHBZIY.js} +304 -2
  40. package/dist/{chunk-2CGBLD5H.js → chunk-CP4SQ5PM.js} +527 -239
  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 +504 -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/types/flows/withdrawals.d.ts +30 -0
  67. package/dist/index.cjs +304 -0
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.js +4 -4
  70. package/package.json +1 -1
@@ -32,6 +32,7 @@ var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
32
32
  var L2_INTEROP_CENTER_ADDRESS = "0x000000000000000000000000000000000001000d";
33
33
  var L2_INTEROP_HANDLER_ADDRESS = "0x000000000000000000000000000000000001000e";
34
34
  var L2_INTEROP_ROOT_STORAGE_ADDRESS = "0x0000000000000000000000000000000000010008";
35
+ var L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS = "0x0000000000000000000000000000000000010015";
35
36
  var L2_MESSAGE_VERIFICATION_ADDRESS = "0x0000000000000000000000000000000000010009";
36
37
  var BUNDLE_IDENTIFIER = "0x01";
37
38
  var TOPIC_L1_MESSAGE_SENT_NEW = k256hex("L1MessageSent(uint256,bytes32,bytes)");
@@ -3497,6 +3498,294 @@ var IL1NullifierABI = [
3497
3498
  ];
3498
3499
  var IL1Nullifier_default = IL1NullifierABI;
3499
3500
 
3501
+ // src/core/internal/abis/IL1NullifierV32.ts
3502
+ var IL1NullifierV32ABI = [
3503
+ {
3504
+ anonymous: false,
3505
+ inputs: [
3506
+ {
3507
+ indexed: true,
3508
+ internalType: "uint256",
3509
+ name: "chainId",
3510
+ type: "uint256"
3511
+ },
3512
+ {
3513
+ indexed: true,
3514
+ internalType: "bytes32",
3515
+ name: "txDataHash",
3516
+ type: "bytes32"
3517
+ },
3518
+ {
3519
+ indexed: true,
3520
+ internalType: "bytes32",
3521
+ name: "l2DepositTxHash",
3522
+ type: "bytes32"
3523
+ }
3524
+ ],
3525
+ name: "BridgehubDepositFinalized",
3526
+ type: "event"
3527
+ },
3528
+ {
3529
+ inputs: [],
3530
+ name: "BRIDGE_HUB",
3531
+ outputs: [
3532
+ {
3533
+ internalType: "contract IL1Bridgehub",
3534
+ name: "",
3535
+ type: "address"
3536
+ }
3537
+ ],
3538
+ stateMutability: "view",
3539
+ type: "function"
3540
+ },
3541
+ {
3542
+ inputs: [],
3543
+ name: "l1AssetRouter",
3544
+ outputs: [
3545
+ {
3546
+ internalType: "contract IL1AssetRouter",
3547
+ name: "",
3548
+ type: "address"
3549
+ }
3550
+ ],
3551
+ stateMutability: "view",
3552
+ type: "function"
3553
+ },
3554
+ {
3555
+ // The contract that took over withdrawal finalization from the nullifier's own (removed)
3556
+ // `finalizeDeposit`.
3557
+ inputs: [],
3558
+ name: "l1InteropHandler",
3559
+ outputs: [
3560
+ {
3561
+ internalType: "address",
3562
+ name: "",
3563
+ type: "address"
3564
+ }
3565
+ ],
3566
+ stateMutability: "view",
3567
+ type: "function"
3568
+ },
3569
+ {
3570
+ inputs: [],
3571
+ name: "l1NativeTokenVault",
3572
+ outputs: [
3573
+ {
3574
+ internalType: "contract IL1NativeTokenVault",
3575
+ name: "",
3576
+ type: "address"
3577
+ }
3578
+ ],
3579
+ stateMutability: "view",
3580
+ type: "function"
3581
+ },
3582
+ {
3583
+ inputs: [
3584
+ {
3585
+ internalType: "uint256",
3586
+ name: "_chainId",
3587
+ type: "uint256"
3588
+ },
3589
+ {
3590
+ internalType: "bytes32",
3591
+ name: "_l2TxHash",
3592
+ type: "bytes32"
3593
+ }
3594
+ ],
3595
+ name: "depositHappened",
3596
+ outputs: [
3597
+ {
3598
+ internalType: "bytes32",
3599
+ name: "",
3600
+ type: "bytes32"
3601
+ }
3602
+ ],
3603
+ stateMutability: "view",
3604
+ type: "function"
3605
+ },
3606
+ {
3607
+ inputs: [
3608
+ {
3609
+ internalType: "uint256",
3610
+ name: "_chainId",
3611
+ type: "uint256"
3612
+ },
3613
+ {
3614
+ internalType: "bytes32",
3615
+ name: "_txDataHash",
3616
+ type: "bytes32"
3617
+ },
3618
+ {
3619
+ internalType: "bytes32",
3620
+ name: "_txHash",
3621
+ type: "bytes32"
3622
+ }
3623
+ ],
3624
+ name: "bridgehubConfirmL2TransactionForwarded",
3625
+ outputs: [],
3626
+ stateMutability: "nonpayable",
3627
+ type: "function"
3628
+ },
3629
+ {
3630
+ inputs: [
3631
+ {
3632
+ components: [
3633
+ {
3634
+ internalType: "uint256",
3635
+ name: "_chainId",
3636
+ type: "uint256"
3637
+ },
3638
+ {
3639
+ internalType: "address",
3640
+ name: "_depositSender",
3641
+ type: "address"
3642
+ },
3643
+ {
3644
+ internalType: "uint16",
3645
+ name: "_l2TxNumberInBatch",
3646
+ type: "uint16"
3647
+ },
3648
+ {
3649
+ internalType: "enum TxStatus",
3650
+ name: "_txStatus",
3651
+ type: "uint8"
3652
+ },
3653
+ {
3654
+ internalType: "bytes32",
3655
+ name: "_assetId",
3656
+ type: "bytes32"
3657
+ },
3658
+ {
3659
+ internalType: "bytes",
3660
+ name: "_assetData",
3661
+ type: "bytes"
3662
+ },
3663
+ {
3664
+ internalType: "bytes32",
3665
+ name: "_l2TxHash",
3666
+ type: "bytes32"
3667
+ },
3668
+ {
3669
+ internalType: "uint256",
3670
+ name: "_l2BatchNumber",
3671
+ type: "uint256"
3672
+ },
3673
+ {
3674
+ internalType: "uint256",
3675
+ name: "_l2MessageIndex",
3676
+ type: "uint256"
3677
+ },
3678
+ {
3679
+ internalType: "bytes32[]",
3680
+ name: "_merkleProof",
3681
+ type: "bytes32[]"
3682
+ }
3683
+ ],
3684
+ internalType: "struct ConfirmTransferResultData",
3685
+ name: "_confirmTransferResultData",
3686
+ type: "tuple"
3687
+ }
3688
+ ],
3689
+ name: "bridgeConfirmTransferResult",
3690
+ outputs: [],
3691
+ stateMutability: "nonpayable",
3692
+ type: "function"
3693
+ },
3694
+ {
3695
+ inputs: [
3696
+ {
3697
+ internalType: "uint256",
3698
+ name: "_chainId",
3699
+ type: "uint256"
3700
+ },
3701
+ {
3702
+ internalType: "address",
3703
+ name: "_depositSender",
3704
+ type: "address"
3705
+ },
3706
+ {
3707
+ internalType: "bytes32",
3708
+ name: "_assetId",
3709
+ type: "bytes32"
3710
+ },
3711
+ {
3712
+ internalType: "bytes",
3713
+ name: "_assetData",
3714
+ type: "bytes"
3715
+ },
3716
+ {
3717
+ internalType: "bytes32",
3718
+ name: "_l2TxHash",
3719
+ type: "bytes32"
3720
+ },
3721
+ {
3722
+ internalType: "uint256",
3723
+ name: "_l2BatchNumber",
3724
+ type: "uint256"
3725
+ },
3726
+ {
3727
+ internalType: "uint256",
3728
+ name: "_l2MessageIndex",
3729
+ type: "uint256"
3730
+ },
3731
+ {
3732
+ internalType: "uint16",
3733
+ name: "_l2TxNumberInBatch",
3734
+ type: "uint16"
3735
+ },
3736
+ {
3737
+ internalType: "bytes32[]",
3738
+ name: "_merkleProof",
3739
+ type: "bytes32[]"
3740
+ }
3741
+ ],
3742
+ name: "bridgeRecoverFailedTransfer",
3743
+ outputs: [],
3744
+ stateMutability: "nonpayable",
3745
+ type: "function"
3746
+ },
3747
+ {
3748
+ inputs: [
3749
+ {
3750
+ internalType: "contract IL1NativeTokenVault",
3751
+ name: "_nativeTokenVault",
3752
+ type: "address"
3753
+ }
3754
+ ],
3755
+ name: "setL1NativeTokenVault",
3756
+ outputs: [],
3757
+ stateMutability: "nonpayable",
3758
+ type: "function"
3759
+ },
3760
+ {
3761
+ inputs: [
3762
+ {
3763
+ internalType: "address",
3764
+ name: "_l1AssetRouter",
3765
+ type: "address"
3766
+ }
3767
+ ],
3768
+ name: "setL1AssetRouter",
3769
+ outputs: [],
3770
+ stateMutability: "nonpayable",
3771
+ type: "function"
3772
+ },
3773
+ {
3774
+ inputs: [
3775
+ {
3776
+ internalType: "address",
3777
+ name: "_l1InteropHandler",
3778
+ type: "address"
3779
+ }
3780
+ ],
3781
+ name: "setL1InteropHandler",
3782
+ outputs: [],
3783
+ stateMutability: "nonpayable",
3784
+ type: "function"
3785
+ }
3786
+ ];
3787
+ var IL1NullifierV32_default = IL1NullifierV32ABI;
3788
+
3500
3789
  // src/core/internal/abis/IL2AssetRouter.ts
3501
3790
  var IL2AssetRouterABI = [
3502
3791
  {
@@ -5030,6 +5319,19 @@ var IERC7786AttributesABI = [
5030
5319
  outputs: [],
5031
5320
  stateMutability: "pure"
5032
5321
  },
5322
+ {
5323
+ type: "function",
5324
+ name: "interopBundleSalt",
5325
+ inputs: [
5326
+ {
5327
+ name: "_salt",
5328
+ type: "bytes32",
5329
+ internalType: "bytes32"
5330
+ }
5331
+ ],
5332
+ outputs: [],
5333
+ stateMutability: "pure"
5334
+ },
5033
5335
  {
5034
5336
  type: "function",
5035
5337
  name: "unbundlerAddress",
@@ -7180,7 +7482,7 @@ function createErrorOps(decodeRevert2) {
7180
7482
  function wrap8(operation, fn, opts) {
7181
7483
  return run("INTERNAL", operation, fn, opts);
7182
7484
  }
7183
- function wrapAs10(kind, operation, fn, opts) {
7485
+ function wrapAs11(kind, operation, fn, opts) {
7184
7486
  return run(kind, operation, fn, opts);
7185
7487
  }
7186
7488
  async function toResult3(operation, fn, opts) {
@@ -7201,7 +7503,7 @@ function createErrorOps(decodeRevert2) {
7201
7503
  return { ok: false, error: shaped };
7202
7504
  }
7203
7505
  }
7204
- return { wrap: wrap8, wrapAs: wrapAs10, toResult: toResult3 };
7506
+ return { wrap: wrap8, wrapAs: wrapAs11, toResult: toResult3 };
7205
7507
  }
7206
7508
  return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
7207
7509
  }
@@ -7345,6 +7647,17 @@ function classifyReadinessFromRevert(e) {
7345
7647
  // src/adapters/viem/errors/error-ops.ts
7346
7648
  var { toZKsyncError, createErrorHandlers } = createErrorOps(decodeRevert);
7347
7649
 
7650
+ // src/core/resources/protocol/semver.ts
7651
+ var SEMVER_MINOR_OFFSET = 32n;
7652
+ var SEMVER_MAJOR_OFFSET = 64n;
7653
+ var U32_MASK = 0xffffffffn;
7654
+ function unpackSemver(packed) {
7655
+ const patch = Number(packed & U32_MASK);
7656
+ const minor = Number(packed >> SEMVER_MINOR_OFFSET & U32_MASK);
7657
+ const major = Number(packed >> SEMVER_MAJOR_OFFSET & U32_MASK);
7658
+ return [major, minor, patch];
7659
+ }
7660
+
7348
7661
  // src/adapters/viem/client.ts
7349
7662
  var { wrap } = createErrorHandlers("client");
7350
7663
  var ChainTypeManagerABI = [
@@ -7354,6 +7667,15 @@ var ChainTypeManagerABI = [
7354
7667
  inputs: [],
7355
7668
  outputs: [{ type: "uint32" }, { type: "uint32" }, { type: "uint32" }],
7356
7669
  stateMutability: "view"
7670
+ },
7671
+ {
7672
+ // Per-chain version. `getSemverProtocolVersion` reports the CTM's own (latest) version, which
7673
+ // runs ahead of individual chains mid-upgrade — so capability gating must use this one.
7674
+ type: "function",
7675
+ name: "getProtocolVersion",
7676
+ inputs: [{ name: "_chainId", type: "uint256" }],
7677
+ outputs: [{ type: "uint256" }],
7678
+ stateMutability: "view"
7357
7679
  }
7358
7680
  ];
7359
7681
  function createViemClient(args) {
@@ -7494,6 +7816,29 @@ function createViemClient(args) {
7494
7816
  );
7495
7817
  return semver;
7496
7818
  }
7819
+ async function getChainProtocolVersion(chainId) {
7820
+ try {
7821
+ const targetChainId = chainId ?? BigInt(await l2.getChainId());
7822
+ const { bridgehub } = await ensureAddresses();
7823
+ const chainTypeManager = await l1.readContract({
7824
+ address: bridgehub,
7825
+ abi: IBridgehub_default,
7826
+ functionName: "chainTypeManager",
7827
+ args: [targetChainId]
7828
+ });
7829
+ if (chainTypeManager.toLowerCase() === FORMAL_ETH_ADDRESS.toLowerCase()) return void 0;
7830
+ const packed = await l1.readContract({
7831
+ address: chainTypeManager,
7832
+ abi: ChainTypeManagerABI,
7833
+ functionName: "getProtocolVersion",
7834
+ args: [targetChainId]
7835
+ });
7836
+ if (packed === 0n) return void 0;
7837
+ return unpackSemver(packed);
7838
+ } catch {
7839
+ return void 0;
7840
+ }
7841
+ }
7497
7842
  let lazyL2;
7498
7843
  function getL2Wallet() {
7499
7844
  if (l2Wallet) return l2Wallet;
@@ -7518,6 +7863,7 @@ function createViemClient(args) {
7518
7863
  refresh,
7519
7864
  baseToken,
7520
7865
  getProtocolVersion,
7866
+ getChainProtocolVersion,
7521
7867
  getL2Wallet
7522
7868
  };
7523
7869
  }
@@ -9691,7 +10037,7 @@ function pickWithdrawRoute(args) {
9691
10037
  }
9692
10038
 
9693
10039
  // src/adapters/viem/resources/withdrawals/context.ts
9694
- async function commonCtx2(p, client, tokens, contracts) {
10040
+ async function commonCtx2(p, client, tokens, contracts, protocol) {
9695
10041
  const sender = client.account.address;
9696
10042
  const {
9697
10043
  bridgehub,
@@ -9699,9 +10045,11 @@ async function commonCtx2(p, client, tokens, contracts) {
9699
10045
  l1Nullifier,
9700
10046
  l2AssetRouter,
9701
10047
  l2NativeTokenVault,
9702
- l2BaseTokenSystem
10048
+ l2BaseTokenSystem,
10049
+ interopCenter
9703
10050
  } = await contracts.addresses();
9704
10051
  const chainIdL2 = BigInt(await client.l2.getChainId());
10052
+ const l1ChainId = BigInt(await client.l1.getChainId());
9705
10053
  const resolvedToken = await tokens.resolve(p.token, { chain: "l2" });
9706
10054
  const baseTokenAssetId = resolvedToken.baseTokenAssetId;
9707
10055
  const baseTokenL1 = await tokens.l1TokenFromAssetId(baseTokenAssetId);
@@ -9723,6 +10071,9 @@ async function commonCtx2(p, client, tokens, contracts) {
9723
10071
  l2AssetRouter,
9724
10072
  l2NativeTokenVault,
9725
10073
  l2BaseTokenSystem,
10074
+ interopCenter,
10075
+ protocol,
10076
+ l1ChainId,
9726
10077
  baseIsEth,
9727
10078
  gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
9728
10079
  };
@@ -10032,6 +10383,285 @@ function routeErc20NonBase2() {
10032
10383
  }
10033
10384
  };
10034
10385
  }
10386
+ var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
10387
+ var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
10388
+ function formatInteropEvmChain(chainId) {
10389
+ const chainRef = viem.toBytes(viem.toHex(chainId));
10390
+ const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
10391
+ const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
10392
+ return viem.toHex(payload);
10393
+ }
10394
+ function formatInteropEvmAddress(address) {
10395
+ const normalized = viem.getAddress(address);
10396
+ const addrBytes = viem.toBytes(normalized);
10397
+ const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
10398
+ return viem.toHex(payload);
10399
+ }
10400
+ var interopCodec = {
10401
+ formatChain: formatInteropEvmChain,
10402
+ formatAddress: formatInteropEvmAddress
10403
+ };
10404
+
10405
+ // src/core/resources/interop/attributes/call.ts
10406
+ function createCallAttributes(codec) {
10407
+ const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
10408
+ const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
10409
+ return {
10410
+ indirectCall,
10411
+ interopCallValue
10412
+ };
10413
+ }
10414
+
10415
+ // src/core/resources/interop/attributes/bundle.ts
10416
+ function createBundleAttributes(codec) {
10417
+ const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
10418
+ const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
10419
+ const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
10420
+ const interopBundleSalt = (salt) => codec.encode("interopBundleSalt", [salt]);
10421
+ return {
10422
+ executionAddress,
10423
+ unbundlerAddress,
10424
+ useFixedFee,
10425
+ interopBundleSalt
10426
+ };
10427
+ }
10428
+
10429
+ // src/core/resources/interop/attributes/resource.ts
10430
+ function createAttributesResource(codec) {
10431
+ return {
10432
+ call: createCallAttributes(codec),
10433
+ bundle: createBundleAttributes(codec)
10434
+ };
10435
+ }
10436
+
10437
+ // src/adapters/viem/resources/interop/attributes/resource.ts
10438
+ function getInteropAttributes(params, ctx) {
10439
+ const bundleAttributes = [];
10440
+ if (params.execution?.only) {
10441
+ bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
10442
+ }
10443
+ if (params.unbundling?.by) {
10444
+ bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
10445
+ }
10446
+ bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
10447
+ const callAttributes = params.actions.map((action) => {
10448
+ switch (action.type) {
10449
+ case "sendNative": {
10450
+ const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
10451
+ if (baseMatches) {
10452
+ return [ctx.attributes.call.interopCallValue(action.amount)];
10453
+ }
10454
+ return [ctx.attributes.call.indirectCall(action.amount)];
10455
+ }
10456
+ case "call":
10457
+ if (action.value && action.value > 0n) {
10458
+ return [ctx.attributes.call.interopCallValue(action.value)];
10459
+ }
10460
+ return [];
10461
+ case "sendErc20":
10462
+ return [ctx.attributes.call.indirectCall(0n)];
10463
+ default:
10464
+ assertNever(action);
10465
+ }
10466
+ });
10467
+ return { bundleAttributes, callAttributes };
10468
+ }
10469
+ function createViemAttributesResource() {
10470
+ const encode = (fn, args) => viem.encodeFunctionData({
10471
+ abi: IERC7786Attributes_default,
10472
+ functionName: fn,
10473
+ args
10474
+ });
10475
+ return createAttributesResource({ encode });
10476
+ }
10477
+
10478
+ // src/core/resources/withdrawals/bundle.ts
10479
+ function buildWithdrawalBundle(input) {
10480
+ const {
10481
+ assetId,
10482
+ amount,
10483
+ l1Receiver,
10484
+ l2Token,
10485
+ isBaseToken,
10486
+ l1ChainId,
10487
+ l2AssetRouter,
10488
+ salt,
10489
+ codec,
10490
+ attributes: attributes2,
10491
+ transferData
10492
+ } = input;
10493
+ const burnData = transferData.encodeBridgeBurnData(amount, l1Receiver, l2Token);
10494
+ const depositData = transferData.encodeAssetRouterDepositData(assetId, burnData);
10495
+ const indirectCallMessageValue = isBaseToken ? amount : 0n;
10496
+ const starter = [
10497
+ codec.formatAddress(l2AssetRouter),
10498
+ depositData,
10499
+ [attributes2.indirectCall(indirectCallMessageValue), attributes2.interopCallValue(0n)]
10500
+ ];
10501
+ return {
10502
+ destinationChain: codec.formatChain(l1ChainId),
10503
+ starters: [starter],
10504
+ // No `atomicBundle` attribute: L2 -> L1 withdrawals are non-atomic and are published to L1 as a
10505
+ // `BUNDLE_IDENTIFIER`-prefixed message, which is what the L1 handler proves inclusion of.
10506
+ bundleAttributes: [attributes2.interopBundleSalt(salt)],
10507
+ value: indirectCallMessageValue
10508
+ };
10509
+ }
10510
+
10511
+ // src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
10512
+ var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
10513
+ var attributes = createViemAttributesResource();
10514
+ function saltFor(sender, nonce) {
10515
+ return viem.keccak256(
10516
+ viem.encodeAbiParameters(
10517
+ [
10518
+ { type: "address", name: "sender" },
10519
+ { type: "uint256", name: "nonce" }
10520
+ ],
10521
+ [sender, BigInt(nonce)]
10522
+ )
10523
+ );
10524
+ }
10525
+ function routeInteropBundle() {
10526
+ return {
10527
+ async build(p, ctx) {
10528
+ const steps = [];
10529
+ const approvals = [];
10530
+ const isBaseToken = ctx.route === "base";
10531
+ const l1Receiver = p.to ?? ctx.sender;
10532
+ let assetId;
10533
+ let allowanceSufficient = true;
10534
+ if (isBaseToken) {
10535
+ assetId = ctx.baseTokenAssetId;
10536
+ } else {
10537
+ assetId = (await wrapAs9(
10538
+ "CONTRACT",
10539
+ OP_WITHDRAWALS.erc20.ensureRegistered,
10540
+ () => ctx.client.l2.simulateContract({
10541
+ address: ctx.l2NativeTokenVault,
10542
+ abi: L2NativeTokenVault_default,
10543
+ functionName: "ensureTokenIsRegistered",
10544
+ args: [p.token],
10545
+ account: ctx.client.account
10546
+ }),
10547
+ {
10548
+ ctx: { where: "L2NativeTokenVault.ensureTokenIsRegistered", token: p.token },
10549
+ message: "Failed to ensure token is registered in L2NativeTokenVault."
10550
+ }
10551
+ )).result;
10552
+ const current = await wrapAs9(
10553
+ "CONTRACT",
10554
+ OP_WITHDRAWALS.erc20.allowance,
10555
+ () => ctx.client.l2.readContract({
10556
+ address: p.token,
10557
+ abi: IERC20_default,
10558
+ functionName: "allowance",
10559
+ args: [ctx.sender, ctx.l2NativeTokenVault],
10560
+ account: ctx.client.account
10561
+ }),
10562
+ {
10563
+ ctx: {
10564
+ where: "erc20.allowance",
10565
+ chain: "L2",
10566
+ token: p.token,
10567
+ spender: ctx.l2NativeTokenVault
10568
+ },
10569
+ message: "Failed to read L2 ERC-20 allowance."
10570
+ }
10571
+ );
10572
+ allowanceSufficient = current >= p.amount;
10573
+ if (!allowanceSufficient) {
10574
+ approvals.push({ token: p.token, spender: ctx.l2NativeTokenVault, amount: p.amount });
10575
+ const approveTxCandidate = {
10576
+ to: p.token,
10577
+ data: viem.encodeFunctionData({
10578
+ abi: IERC20_default,
10579
+ functionName: "approve",
10580
+ args: [ctx.l2NativeTokenVault, p.amount]
10581
+ }),
10582
+ value: 0n,
10583
+ from: ctx.sender
10584
+ };
10585
+ const approveGas = await quoteL2Gas4({ ctx, tx: approveTxCandidate });
10586
+ steps.push({
10587
+ key: `approve:l2:${p.token}:${ctx.l2NativeTokenVault}`,
10588
+ kind: "approve:l2",
10589
+ description: `Approve ${p.amount} to NativeTokenVault`,
10590
+ tx: {
10591
+ address: p.token,
10592
+ abi: IERC20_default,
10593
+ functionName: "approve",
10594
+ args: [ctx.l2NativeTokenVault, p.amount],
10595
+ account: ctx.client.account,
10596
+ ...approveGas
10597
+ }
10598
+ });
10599
+ }
10600
+ }
10601
+ const nonce = await wrapAs9(
10602
+ "RPC",
10603
+ OP_WITHDRAWALS.prepare,
10604
+ () => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
10605
+ {
10606
+ ctx: { where: "l2.getTransactionCount", sender: ctx.sender },
10607
+ message: "Failed to read L2 nonce for the interop bundle salt."
10608
+ }
10609
+ );
10610
+ const bundle = buildWithdrawalBundle({
10611
+ assetId,
10612
+ amount: p.amount,
10613
+ l1Receiver,
10614
+ l2Token: isBaseToken ? FORMAL_ETH_ADDRESS : p.token,
10615
+ isBaseToken,
10616
+ l1ChainId: ctx.l1ChainId,
10617
+ l2AssetRouter: ctx.l2AssetRouter,
10618
+ salt: saltFor(ctx.sender, nonce),
10619
+ codec: interopCodec,
10620
+ attributes: {
10621
+ indirectCall: attributes.call.indirectCall,
10622
+ interopCallValue: attributes.call.interopCallValue,
10623
+ interopBundleSalt: attributes.bundle.interopBundleSalt
10624
+ },
10625
+ transferData: {
10626
+ encodeBridgeBurnData: encodeNativeTokenVaultTransferData,
10627
+ encodeAssetRouterDepositData: encodeSecondBridgeDataV1
10628
+ }
10629
+ });
10630
+ const sendArgs = [bundle.destinationChain, bundle.starters, bundle.bundleAttributes];
10631
+ const sendTxCandidate = {
10632
+ to: ctx.interopCenter,
10633
+ data: viem.encodeFunctionData({
10634
+ abi: IInteropCenter_default,
10635
+ functionName: "sendBundle",
10636
+ args: sendArgs
10637
+ }),
10638
+ value: bundle.value,
10639
+ from: ctx.sender
10640
+ };
10641
+ const sendGas = allowanceSufficient ? await quoteL2Gas4({ ctx, tx: sendTxCandidate }) : void 0;
10642
+ const sendTx = {
10643
+ address: ctx.interopCenter,
10644
+ abi: IInteropCenter_default,
10645
+ functionName: "sendBundle",
10646
+ args: sendArgs,
10647
+ account: ctx.client.account,
10648
+ value: bundle.value,
10649
+ ...sendGas
10650
+ };
10651
+ steps.push({
10652
+ key: "interop-center:send-bundle",
10653
+ kind: "interop-center:send-bundle",
10654
+ description: "Burn on L2 & send L2\u2192L1 withdrawal bundle",
10655
+ tx: sendTx
10656
+ });
10657
+ const fees = buildFeeBreakdown2({
10658
+ feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
10659
+ l2Gas: sendGas
10660
+ });
10661
+ return { steps, approvals, fees };
10662
+ }
10663
+ };
10664
+ }
10035
10665
 
10036
10666
  // src/core/utils/events.ts
10037
10667
  function extractPreferAddress(opts) {
@@ -10066,21 +10696,145 @@ function l1MessageSentSender(log) {
10066
10696
  if (!sender) {
10067
10697
  throw new Error("L1MessageSent log has no valid sender topic.");
10068
10698
  }
10069
- return `0x${sender.toLowerCase()}`;
10699
+ return `0x${sender.toLowerCase()}`;
10700
+ }
10701
+
10702
+ // src/core/resources/withdrawals/logs.ts
10703
+ function messengerLogIndex(raw, opts) {
10704
+ const index = opts?.index;
10705
+ const messenger = (opts?.messenger).toLowerCase();
10706
+ const arr = Array.isArray(raw?.l2ToL1Logs) ? raw.l2ToL1Logs : [];
10707
+ const hits = arr.map((lg, i) => ({ i, lg })).filter(({ lg }) => (lg?.sender ?? "").toLowerCase() === messenger);
10708
+ if (!hits.length) {
10709
+ throw new Error("No L2->L1 messenger logs found in receipt.");
10710
+ }
10711
+ return (hits[index] ?? hits[0]).i;
10712
+ }
10713
+ function keccakHex(data) {
10714
+ return `0x${utils.bytesToHex(sha3.keccak_256(utils.hexToBytes(data.slice(2))))}`;
10715
+ }
10716
+ function stripBundleIdentifier(messageData) {
10717
+ const prefix = `0x${messageData.slice(2, 4)}`;
10718
+ if (prefix !== BUNDLE_IDENTIFIER) {
10719
+ throw createError("STATE", {
10720
+ resource: "withdrawals",
10721
+ operation: OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
10722
+ 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.",
10723
+ context: { prefix, expected: BUNDLE_IDENTIFIER }
10724
+ });
10725
+ }
10726
+ return `0x${messageData.slice(4)}`;
10727
+ }
10728
+ function parseBundleHashFromLogs(logs, interopCenter = L2_INTEROP_CENTER_ADDRESS) {
10729
+ const center = interopCenter.toLowerCase();
10730
+ for (const log of logs) {
10731
+ if (log.address?.toLowerCase() !== center) continue;
10732
+ if (log.topics?.length !== 1) continue;
10733
+ if (!log.data || (log.data.length - 2) / 64 < 3) continue;
10734
+ return `0x${log.data.slice(66, 130)}`;
10735
+ }
10736
+ return void 0;
10737
+ }
10738
+ function buildWithdrawalFinalization(input) {
10739
+ const { messageData, sourceChainId, txNumberInBatch, proof } = input;
10740
+ const bundle = stripBundleIdentifier(messageData);
10741
+ return {
10742
+ bundle,
10743
+ bundleHash: input.bundleHash ?? keccakHex(bundle),
10744
+ proof: {
10745
+ chainId: sourceChainId,
10746
+ l1BatchNumber: proof.batchNumber,
10747
+ l2MessageIndex: proof.id,
10748
+ message: {
10749
+ txNumberInBatch,
10750
+ sender: input.interopCenter ?? L2_INTEROP_CENTER_ADDRESS,
10751
+ data: messageData
10752
+ },
10753
+ proof: proof.proof
10754
+ }
10755
+ };
10756
+ }
10757
+ function classifyWithdrawalOutcome(bundleStatus, callStatus) {
10758
+ if (bundleStatus === 2 /* FullyExecuted */) return "finalized";
10759
+ if (bundleStatus !== 3 /* Unbundled */) return "pending";
10760
+ switch (callStatus) {
10761
+ case 1 /* Executed */:
10762
+ return "finalized";
10763
+ case 2 /* Cancelled */:
10764
+ return "failed";
10765
+ default:
10766
+ return "pending";
10767
+ }
10768
+ }
10769
+
10770
+ // src/core/resources/withdrawals/protocol.ts
10771
+ var MIN_INTEROP_WITHDRAWAL_MINOR = 32;
10772
+ function protocolFromVersion(version) {
10773
+ const [, minor] = version;
10774
+ return minor >= MIN_INTEROP_WITHDRAWAL_MINOR ? "interop-bundle" : "legacy-withdrawal";
10775
+ }
10776
+ async function detectWithdrawalProtocol(probes, override) {
10777
+ if (override) {
10778
+ return { protocol: override, source: { via: "override" } };
10779
+ }
10780
+ const version = await probes.protocolVersion();
10781
+ if (version) {
10782
+ return { protocol: protocolFromVersion(version), source: { via: "protocol-version", version } };
10783
+ }
10784
+ if (await probes.hasCodeAt(L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS)) {
10785
+ return {
10786
+ protocol: "interop-bundle",
10787
+ source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
10788
+ };
10789
+ }
10790
+ return {
10791
+ protocol: "legacy-withdrawal",
10792
+ source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
10793
+ };
10070
10794
  }
10071
10795
 
10072
- // src/core/resources/withdrawals/logs.ts
10073
- function messengerLogIndex(raw, opts) {
10074
- const index = opts?.index;
10075
- const messenger = (opts?.messenger).toLowerCase();
10076
- const arr = Array.isArray(raw?.l2ToL1Logs) ? raw.l2ToL1Logs : [];
10077
- const hits = arr.map((lg, i) => ({ i, lg })).filter(({ lg }) => (lg?.sender ?? "").toLowerCase() === messenger);
10078
- if (!hits.length) {
10079
- throw new Error("No L2->L1 messenger logs found in receipt.");
10796
+ // src/adapters/viem/resources/withdrawals/services/protocol.ts
10797
+ function createWithdrawalProtocolService(client, override) {
10798
+ let cached;
10799
+ async function hasCodeAt(address) {
10800
+ try {
10801
+ const code = await client.l2.getCode({ address });
10802
+ return !!code && code !== "0x";
10803
+ } catch {
10804
+ return false;
10805
+ }
10080
10806
  }
10081
- return (hits[index] ?? hits[0]).i;
10807
+ async function protocolVersion() {
10808
+ try {
10809
+ return await client.getChainProtocolVersion();
10810
+ } catch {
10811
+ return void 0;
10812
+ }
10813
+ }
10814
+ function detect() {
10815
+ cached ??= detectWithdrawalProtocol(
10816
+ {
10817
+ protocolVersion,
10818
+ hasCodeAt
10819
+ },
10820
+ override
10821
+ ).catch((e) => {
10822
+ cached = void 0;
10823
+ throw e;
10824
+ });
10825
+ return cached;
10826
+ }
10827
+ return {
10828
+ detect,
10829
+ async protocol() {
10830
+ return (await detect()).protocol;
10831
+ },
10832
+ refresh() {
10833
+ cached = void 0;
10834
+ }
10835
+ };
10082
10836
  }
10083
- var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
10837
+ var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
10084
10838
  var IL1NullifierMini = [
10085
10839
  {
10086
10840
  type: "function",
@@ -10094,183 +10848,279 @@ var IL1NullifierMini = [
10094
10848
  outputs: [{ type: "bool" }]
10095
10849
  }
10096
10850
  ];
10097
- function createFinalizationServices(client) {
10098
- return {
10099
- async fetchFinalizeDepositParams(l2TxHash) {
10100
- const parsed = await wrapAs9(
10101
- "RPC",
10102
- OP_WITHDRAWALS.finalize.fetchParams.receipt,
10103
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
10104
- {
10105
- ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
10106
- message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
10851
+ function createFinalizationServices(client, protocolService = createWithdrawalProtocolService(client)) {
10852
+ async function finalizationTarget(protocol) {
10853
+ const { l1Nullifier } = await client.ensureAddresses();
10854
+ if (protocol === "legacy-withdrawal") return l1Nullifier;
10855
+ return await wrapAs10(
10856
+ "CONTRACT",
10857
+ OP_WITHDRAWALS.finalize.fetchParams.receipt,
10858
+ () => client.l1.readContract({
10859
+ address: l1Nullifier,
10860
+ abi: IL1NullifierV32_default,
10861
+ functionName: "l1InteropHandler"
10862
+ }),
10863
+ {
10864
+ ctx: { where: "L1Nullifier.l1InteropHandler", l1Nullifier },
10865
+ message: "Failed to resolve the L1 interop handler. The chain reports protocol v32+, but its L1Nullifier does not expose `l1InteropHandler()`."
10866
+ }
10867
+ );
10868
+ }
10869
+ async function fetchMessageAndProof(l2TxHash) {
10870
+ const raw = await wrapAs10(
10871
+ "RPC",
10872
+ OP_WITHDRAWALS.finalize.fetchParams.receipt,
10873
+ () => client.zks.getReceiptWithL2ToL1(l2TxHash),
10874
+ {
10875
+ ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
10876
+ message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
10877
+ }
10878
+ );
10879
+ if (!raw) {
10880
+ throw createError("STATE", {
10881
+ resource: "withdrawals",
10882
+ operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
10883
+ message: "L2 receipt not found.",
10884
+ context: { l2TxHash }
10885
+ });
10886
+ }
10887
+ const ev = await wrapAs10(
10888
+ "INTERNAL",
10889
+ OP_WITHDRAWALS.finalize.fetchParams.findMessage,
10890
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
10891
+ () => Promise.resolve(findL1MessageSentLog(raw, { index: 0 })),
10892
+ {
10893
+ ctx: { l2TxHash, index: 0 },
10894
+ message: "Failed to locate L1MessageSent event in L2 receipt."
10895
+ }
10896
+ );
10897
+ const message = await wrapAs10(
10898
+ "INTERNAL",
10899
+ OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
10900
+ () => {
10901
+ const [decoded] = viem.decodeAbiParameters([{ type: "bytes" }], ev.data);
10902
+ return Promise.resolve(decoded);
10903
+ },
10904
+ {
10905
+ ctx: { where: "decode L1MessageSent", data: ev.data },
10906
+ message: "Failed to decode withdrawal message."
10907
+ }
10908
+ );
10909
+ const idx = await wrapAs10(
10910
+ "INTERNAL",
10911
+ OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
10912
+ () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
10913
+ {
10914
+ ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
10915
+ message: "Failed to derive messenger log index."
10916
+ }
10917
+ );
10918
+ const proof = await wrapAs10(
10919
+ "RPC",
10920
+ OP_WITHDRAWALS.finalize.fetchParams.proof,
10921
+ () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
10922
+ {
10923
+ ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
10924
+ message: "Failed to fetch L2\u2192L1 log proof."
10925
+ }
10926
+ );
10927
+ const chainId = await wrapAs10(
10928
+ "RPC",
10929
+ OP_WITHDRAWALS.finalize.fetchParams.network,
10930
+ () => client.l2.getChainId(),
10931
+ { ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
10932
+ );
10933
+ const txNumberInBatch = Number(raw.transactionIndex ?? 0);
10934
+ const l2Sender = l1MessageSentSender(ev);
10935
+ return { raw, message, proof, chainId: BigInt(chainId), txNumberInBatch, l2Sender };
10936
+ }
10937
+ async function fetchFinalization(l2TxHash) {
10938
+ const protocol = await protocolService.protocol();
10939
+ const { raw, message, proof, chainId, txNumberInBatch, l2Sender } = await fetchMessageAndProof(l2TxHash);
10940
+ const target = await finalizationTarget(protocol);
10941
+ if (protocol === "legacy-withdrawal") {
10942
+ const params2 = {
10943
+ chainId,
10944
+ l2BatchNumber: proof.batchNumber,
10945
+ l2MessageIndex: proof.id,
10946
+ l2Sender,
10947
+ l2TxNumberInBatch: txNumberInBatch,
10948
+ message,
10949
+ merkleProof: proof.proof
10950
+ };
10951
+ return {
10952
+ target,
10953
+ finalization: { protocol, params: params2 },
10954
+ key: {
10955
+ chainIdL2: chainId,
10956
+ l2BatchNumber: proof.batchNumber,
10957
+ l2MessageIndex: proof.id
10107
10958
  }
10108
- );
10109
- if (!parsed) {
10110
- throw createError("STATE", {
10111
- resource: "withdrawals",
10112
- operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
10113
- message: "L2 receipt not found.",
10114
- context: { l2TxHash }
10115
- });
10959
+ };
10960
+ }
10961
+ const { interopCenter } = await client.ensureAddresses();
10962
+ const params = buildWithdrawalFinalization({
10963
+ messageData: message,
10964
+ sourceChainId: chainId,
10965
+ txNumberInBatch,
10966
+ proof: { batchNumber: proof.batchNumber, id: proof.id, proof: proof.proof },
10967
+ // Prefer the hash the InteropCenter emitted over recomputing it.
10968
+ bundleHash: parseBundleHashFromLogs(raw.logs ?? [], interopCenter),
10969
+ interopCenter
10970
+ });
10971
+ return {
10972
+ target,
10973
+ finalization: { protocol, params },
10974
+ key: {
10975
+ chainIdL2: chainId,
10976
+ l2BatchNumber: proof.batchNumber,
10977
+ l2MessageIndex: proof.id,
10978
+ bundleHash: params.bundleHash
10116
10979
  }
10117
- const ev = await wrapAs9(
10118
- "INTERNAL",
10119
- OP_WITHDRAWALS.finalize.fetchParams.findMessage,
10120
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
10121
- () => Promise.resolve(findL1MessageSentLog(parsed, { index: 0 })),
10980
+ };
10981
+ }
10982
+ async function withdrawalOutcome(finalization) {
10983
+ const target = await finalizationTarget(finalization.protocol);
10984
+ if (finalization.protocol === "legacy-withdrawal") {
10985
+ const done = await wrapAs10(
10986
+ "RPC",
10987
+ OP_WITHDRAWALS.finalize.isFinalized,
10988
+ () => client.l1.readContract({
10989
+ address: target,
10990
+ abi: IL1NullifierMini,
10991
+ functionName: "isWithdrawalFinalized",
10992
+ args: [
10993
+ finalization.params.chainId,
10994
+ finalization.params.l2BatchNumber,
10995
+ finalization.params.l2MessageIndex
10996
+ ]
10997
+ }),
10122
10998
  {
10123
- ctx: { l2TxHash, index: 0 },
10124
- message: "Failed to locate L1MessageSent event in L2 receipt."
10999
+ ctx: { where: "isWithdrawalFinalized", params: finalization.params },
11000
+ message: "Failed to read finalization status."
10125
11001
  }
10126
11002
  );
10127
- const message = await wrapAs9(
10128
- "INTERNAL",
10129
- OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
10130
- () => {
10131
- const [decoded] = viem.decodeAbiParameters([{ type: "bytes" }], ev.data);
10132
- return decoded;
10133
- },
11003
+ return done ? "finalized" : "pending";
11004
+ }
11005
+ const { bundleHash } = finalization.params;
11006
+ const status = Number(
11007
+ await wrapAs10(
11008
+ "RPC",
11009
+ OP_WITHDRAWALS.finalize.isFinalized,
11010
+ () => client.l1.readContract({
11011
+ address: target,
11012
+ abi: IInteropHandler_default,
11013
+ functionName: "bundleStatus",
11014
+ args: [bundleHash]
11015
+ }),
10134
11016
  {
10135
- ctx: { where: "decode L1MessageSent", data: ev.data },
10136
- message: "Failed to decode withdrawal message."
11017
+ ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
11018
+ message: "Failed to read bundle status."
10137
11019
  }
10138
- );
10139
- const raw = await wrapAs9(
11020
+ )
11021
+ );
11022
+ if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
11023
+ const callStatus = Number(
11024
+ await wrapAs10(
10140
11025
  "RPC",
10141
- OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
10142
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
11026
+ OP_WITHDRAWALS.finalize.isFinalized,
11027
+ () => client.l1.readContract({
11028
+ address: target,
11029
+ abi: IInteropHandler_default,
11030
+ functionName: "callStatus",
11031
+ args: [bundleHash, 0n]
11032
+ }),
10143
11033
  {
10144
- ctx: { where: "getReceiptWithL2ToL1 (raw)", l2TxHash },
10145
- message: "Failed to fetch raw L2 receipt."
11034
+ ctx: { where: "L1InteropHandler.callStatus", bundleHash },
11035
+ message: "Failed to read bundle call status."
10146
11036
  }
10147
- );
10148
- if (!raw) {
10149
- throw createError("STATE", {
11037
+ )
11038
+ );
11039
+ return classifyWithdrawalOutcome(status, callStatus);
11040
+ }
11041
+ async function isWithdrawalFinalized(finalization) {
11042
+ return await withdrawalOutcome(finalization) === "finalized";
11043
+ }
11044
+ return {
11045
+ fetchFinalization,
11046
+ isWithdrawalFinalized,
11047
+ withdrawalOutcome,
11048
+ async fetchFinalizeDepositParams(l2TxHash) {
11049
+ const resolved = await fetchFinalization(l2TxHash);
11050
+ if (resolved.finalization.protocol !== "legacy-withdrawal") {
11051
+ throw createError("VALIDATION", {
10150
11052
  resource: "withdrawals",
10151
- operation: OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
10152
- message: "Raw L2 receipt not found.",
10153
- context: { l2TxHash }
11053
+ operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
11054
+ message: "This chain finalizes withdrawals through the L1 interop handler; `finalizeDeposit` params do not exist. Use `fetchFinalization` instead.",
11055
+ context: { l2TxHash, protocol: resolved.finalization.protocol }
10154
11056
  });
10155
11057
  }
10156
- const idx = await wrapAs9(
10157
- "INTERNAL",
10158
- OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
10159
- () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
10160
- {
10161
- ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
10162
- message: "Failed to derive messenger log index."
10163
- }
10164
- );
10165
- const proof = await wrapAs9(
10166
- "RPC",
10167
- OP_WITHDRAWALS.finalize.fetchParams.proof,
10168
- () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
10169
- {
10170
- ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
10171
- message: "Failed to fetch L2\u2192L1 log proof."
10172
- }
10173
- );
10174
- const chainId = await wrapAs9(
10175
- "RPC",
10176
- OP_WITHDRAWALS.finalize.fetchParams.network,
10177
- () => client.l2.getChainId(),
10178
- { ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
10179
- );
10180
- const txIndex = Number(parsed.transactionIndex ?? 0);
10181
- const params = {
10182
- chainId: BigInt(chainId),
10183
- l2BatchNumber: proof.batchNumber,
10184
- l2MessageIndex: proof.id,
10185
- l2Sender: l1MessageSentSender(ev),
10186
- l2TxNumberInBatch: txIndex,
10187
- message,
10188
- merkleProof: proof.proof
10189
- };
10190
- const { l1Nullifier } = await client.ensureAddresses();
10191
- return { params, nullifier: l1Nullifier };
11058
+ return { params: resolved.finalization.params, nullifier: resolved.target };
10192
11059
  },
10193
- async simulateFinalizeReadiness(params) {
10194
- const { l1Nullifier } = await client.ensureAddresses();
11060
+ async simulateFinalizeReadiness(finalization) {
11061
+ const target = await finalizationTarget(finalization.protocol);
10195
11062
  const done = await (async () => {
10196
11063
  try {
10197
- const result = await wrapAs9(
10198
- "RPC",
10199
- OP_WITHDRAWALS.finalize.readiness.isFinalized,
10200
- () => client.l1.readContract({
10201
- address: l1Nullifier,
10202
- abi: IL1NullifierMini,
10203
- functionName: "isWithdrawalFinalized",
10204
- args: [params.chainId, params.l2BatchNumber, params.l2MessageIndex]
10205
- }),
10206
- {
10207
- ctx: { where: "isWithdrawalFinalized", params },
10208
- message: "Failed to read finalization status."
10209
- }
10210
- );
10211
- return result;
11064
+ return await isWithdrawalFinalized(finalization);
10212
11065
  } catch {
10213
11066
  return false;
10214
11067
  }
10215
11068
  })();
10216
11069
  if (done) return { kind: "FINALIZED" };
10217
11070
  try {
10218
- await client.l1.simulateContract({
10219
- address: l1Nullifier,
10220
- abi: IL1Nullifier_default,
10221
- functionName: "finalizeDeposit",
10222
- args: [params],
10223
- account: client.account
10224
- });
11071
+ if (finalization.protocol === "legacy-withdrawal") {
11072
+ await client.l1.simulateContract({
11073
+ address: target,
11074
+ abi: IL1Nullifier_default,
11075
+ functionName: "finalizeDeposit",
11076
+ args: [finalization.params],
11077
+ account: client.account
11078
+ });
11079
+ } else {
11080
+ await client.l1.simulateContract({
11081
+ address: target,
11082
+ abi: IInteropHandler_default,
11083
+ functionName: "executeBundle",
11084
+ args: [finalization.params.bundle, finalization.params.proof],
11085
+ account: client.account
11086
+ });
11087
+ }
10225
11088
  return { kind: "READY" };
10226
11089
  } catch (e) {
10227
11090
  return classifyReadinessFromRevert(e);
10228
11091
  }
10229
11092
  },
10230
- async isWithdrawalFinalized(key) {
10231
- const { l1Nullifier } = await client.ensureAddresses();
10232
- return await wrapAs9(
10233
- "RPC",
10234
- OP_WITHDRAWALS.finalize.isFinalized,
10235
- () => client.l1.readContract({
10236
- address: l1Nullifier,
10237
- abi: IL1NullifierMini,
10238
- functionName: "isWithdrawalFinalized",
10239
- args: [key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex]
10240
- }),
10241
- {
10242
- ctx: { where: "isWithdrawalFinalized", key },
10243
- message: "Failed to read finalization status."
10244
- }
10245
- );
10246
- },
10247
- async estimateFinalization(params) {
10248
- const { l1Nullifier } = await client.ensureAddresses();
10249
- const gasLimit = await wrapAs9(
11093
+ async estimateFinalization(finalization) {
11094
+ const target = await finalizationTarget(finalization.protocol);
11095
+ const gasLimit = await wrapAs10(
10250
11096
  "RPC",
10251
11097
  OP_WITHDRAWALS.finalize.estimate,
10252
- () => client.l1.estimateContractGas({
10253
- address: l1Nullifier,
11098
+ () => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
11099
+ address: target,
10254
11100
  abi: IL1Nullifier_default,
10255
11101
  functionName: "finalizeDeposit",
10256
- args: [params],
11102
+ args: [finalization.params],
11103
+ account: client.account
11104
+ }) : client.l1.estimateContractGas({
11105
+ address: target,
11106
+ abi: IInteropHandler_default,
11107
+ functionName: "executeBundle",
11108
+ args: [finalization.params.bundle, finalization.params.proof],
10257
11109
  account: client.account
10258
11110
  }),
10259
11111
  {
10260
11112
  ctx: {
10261
- where: "estimateContractGas(finalizeDeposit)",
10262
- chainIdL2: params.chainId,
10263
- l2BatchNumber: params.l2BatchNumber,
10264
- l2MessageIndex: params.l2MessageIndex,
10265
- l1Nullifier
11113
+ where: "estimateContractGas(finalize)",
11114
+ protocol: finalization.protocol,
11115
+ target
10266
11116
  },
10267
- message: "Failed to estimate gas for finalizeDeposit."
11117
+ message: "Failed to estimate gas for withdrawal finalization."
10268
11118
  }
10269
11119
  );
10270
11120
  let maxFeePerGas;
10271
11121
  let maxPriorityFeePerGas;
10272
11122
  try {
10273
- const fee = await wrapAs9(
11123
+ const fee = await wrapAs10(
10274
11124
  "RPC",
10275
11125
  OP_WITHDRAWALS.finalize.estimate,
10276
11126
  () => client.l1.estimateFeesPerGas(),
@@ -10289,32 +11139,34 @@ function createFinalizationServices(client) {
10289
11139
  })();
10290
11140
  maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
10291
11141
  } catch {
10292
- const gasPrice = await wrapAs9(
11142
+ const gasPrice = await wrapAs10(
10293
11143
  "RPC",
10294
11144
  OP_WITHDRAWALS.finalize.estimate,
10295
11145
  () => client.l1.getGasPrice(),
10296
11146
  {
10297
11147
  ctx: { where: "getGasPrice" },
10298
- message: "Failed to read gas price for finalizeDeposit."
11148
+ message: "Failed to read gas price for withdrawal finalization."
10299
11149
  }
10300
11150
  );
10301
11151
  maxFeePerGas = gasPrice;
10302
11152
  maxPriorityFeePerGas = 0n;
10303
11153
  }
10304
- return {
10305
- gasLimit,
10306
- maxFeePerGas,
10307
- maxPriorityFeePerGas
10308
- };
11154
+ return { gasLimit, maxFeePerGas, maxPriorityFeePerGas };
10309
11155
  },
10310
- async finalizeDeposit(params) {
10311
- const { l1Nullifier } = await client.ensureAddresses();
11156
+ async finalize(finalization) {
11157
+ const target = await finalizationTarget(finalization.protocol);
10312
11158
  try {
10313
- const hash = await client.l1Wallet.writeContract({
10314
- address: l1Nullifier,
11159
+ const hash = finalization.protocol === "legacy-withdrawal" ? await client.l1Wallet.writeContract({
11160
+ address: target,
10315
11161
  abi: IL1Nullifier_default,
10316
11162
  functionName: "finalizeDeposit",
10317
- args: [params],
11163
+ args: [finalization.params],
11164
+ account: client.account
11165
+ }) : await client.l1Wallet.writeContract({
11166
+ address: target,
11167
+ abi: IInteropHandler_default,
11168
+ functionName: "executeBundle",
11169
+ args: [finalization.params.bundle, finalization.params.proof],
10318
11170
  account: client.account
10319
11171
  });
10320
11172
  return {
@@ -10328,8 +11180,8 @@ function createFinalizationServices(client) {
10328
11180
  {
10329
11181
  resource: "withdrawals",
10330
11182
  operation: OP_WITHDRAWALS.finalize.wait,
10331
- message: "Failed while waiting for finalizeDeposit transaction.",
10332
- context: { txHash: hash }
11183
+ message: "Failed while waiting for the withdrawal finalization transaction.",
11184
+ context: { txHash: hash, protocol: finalization.protocol }
10333
11185
  },
10334
11186
  e
10335
11187
  );
@@ -10342,13 +11194,8 @@ function createFinalizationServices(client) {
10342
11194
  {
10343
11195
  resource: "withdrawals",
10344
11196
  operation: OP_WITHDRAWALS.finalize.send,
10345
- message: "Failed to send finalizeDeposit transaction.",
10346
- context: {
10347
- chainIdL2: params.chainId,
10348
- l2BatchNumber: params.l2BatchNumber,
10349
- l2MessageIndex: params.l2MessageIndex,
10350
- l1Nullifier
10351
- }
11197
+ message: "Failed to send the withdrawal finalization transaction.",
11198
+ context: { protocol: finalization.protocol, target }
10352
11199
  },
10353
11200
  e
10354
11201
  );
@@ -10381,15 +11228,28 @@ var ROUTES2 = {
10381
11228
  "erc20-nonbase": routeErc20NonBase2()
10382
11229
  // AssetRouter.withdraw for non-base ERC-20s
10383
11230
  };
10384
- function createWithdrawalsResource(client, tokens, contracts) {
10385
- const svc = createFinalizationServices(client);
11231
+ var INTEROP_ROUTES = {
11232
+ base: routeInteropBundle(),
11233
+ "erc20-nonbase": routeInteropBundle()
11234
+ };
11235
+ function routeStrategy(protocol, route) {
11236
+ return protocol === "interop-bundle" ? INTEROP_ROUTES[route] : ROUTES2[route];
11237
+ }
11238
+ function createWithdrawalsResource(client, tokens, contracts, options) {
11239
+ const protocolService = createWithdrawalProtocolService(
11240
+ client,
11241
+ options?.protocol
11242
+ );
11243
+ const svc = createFinalizationServices(client, protocolService);
10386
11244
  const { wrap: wrap8, toResult: toResult3 } = createErrorHandlers("withdrawals");
10387
11245
  const tokensResource = tokens ?? createTokensResource(client);
10388
11246
  const contractsResource = contracts ?? createContractsResource(client);
10389
11247
  async function buildPlan(p) {
10390
- const ctx = await commonCtx2(p, client, tokensResource, contractsResource);
10391
- await ROUTES2[ctx.route].preflight?.(p, ctx);
10392
- const { steps, approvals, fees } = await ROUTES2[ctx.route].build(p, ctx);
11248
+ const protocol = await protocolService.protocol();
11249
+ const ctx = await commonCtx2(p, client, tokensResource, contractsResource, protocol);
11250
+ const strategy = routeStrategy(protocol, ctx.route);
11251
+ await strategy.preflight?.(p, ctx);
11252
+ const { steps, approvals, fees } = await strategy.build(p, ctx);
10393
11253
  return {
10394
11254
  route: ctx.route,
10395
11255
  summary: {
@@ -10556,21 +11416,20 @@ function createWithdrawalsResource(client, tokens, contracts) {
10556
11416
  if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
10557
11417
  let pack;
10558
11418
  try {
10559
- pack = await svc.fetchFinalizeDepositParams(l2TxHash);
11419
+ pack = await svc.fetchFinalization(l2TxHash);
10560
11420
  } catch {
10561
11421
  return { phase: "PENDING", l2TxHash };
10562
11422
  }
10563
- const key = {
10564
- chainIdL2: pack.params.chainId,
10565
- l2BatchNumber: pack.params.l2BatchNumber,
10566
- l2MessageIndex: pack.params.l2MessageIndex
10567
- };
11423
+ const key = pack.key;
10568
11424
  try {
10569
- const done = await svc.isWithdrawalFinalized(key);
10570
- if (done) return { phase: "FINALIZED", l2TxHash, key };
11425
+ const outcome = await svc.withdrawalOutcome(pack.finalization);
11426
+ if (outcome === "finalized") return { phase: "FINALIZED", l2TxHash, key };
11427
+ if (outcome === "failed") {
11428
+ return { phase: "UNFINALIZABLE", l2TxHash, key, reason: "bundle-cancelled" };
11429
+ }
10571
11430
  } catch {
10572
11431
  }
10573
- const readiness = await svc.simulateFinalizeReadiness(pack.params);
11432
+ const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
10574
11433
  const { phase, reason } = phaseFromReadiness(readiness);
10575
11434
  return { phase, reason, l2TxHash, key };
10576
11435
  },
@@ -10664,7 +11523,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
10664
11523
  async () => {
10665
11524
  const pack = await (async () => {
10666
11525
  try {
10667
- return await svc.fetchFinalizeDepositParams(l2TxHash);
11526
+ return await svc.fetchFinalization(l2TxHash);
10668
11527
  } catch (e) {
10669
11528
  throw createError("STATE", {
10670
11529
  resource: "withdrawals",
@@ -10675,21 +11534,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
10675
11534
  });
10676
11535
  }
10677
11536
  })();
10678
- const { params } = pack;
10679
- const key = {
10680
- chainIdL2: params.chainId,
10681
- l2BatchNumber: params.l2BatchNumber,
10682
- l2MessageIndex: params.l2MessageIndex
10683
- };
11537
+ const { finalization } = pack;
10684
11538
  try {
10685
- const done = await svc.isWithdrawalFinalized(key);
10686
- if (done) {
11539
+ const outcome = await svc.withdrawalOutcome(finalization);
11540
+ if (outcome === "finalized" || outcome === "failed") {
10687
11541
  const statusNow = await status(l2TxHash);
10688
11542
  return { status: statusNow };
10689
11543
  }
10690
11544
  } catch {
10691
11545
  }
10692
- const readiness = await svc.simulateFinalizeReadiness(params);
11546
+ const readiness = await svc.simulateFinalizeReadiness(finalization);
10693
11547
  if (readiness.kind === "FINALIZED") {
10694
11548
  const statusNow = await status(l2TxHash);
10695
11549
  return { status: statusNow };
@@ -10703,7 +11557,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
10703
11557
  });
10704
11558
  }
10705
11559
  try {
10706
- const tx = await svc.finalizeDeposit(params);
11560
+ const tx = await svc.finalize(finalization);
10707
11561
  finalizeCache.set(l2TxHash, tx.hash);
10708
11562
  const rcpt = await tx.wait();
10709
11563
  const statusNow = await status(l2TxHash);
@@ -10712,7 +11566,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
10712
11566
  const statusNow = await status(l2TxHash);
10713
11567
  if (statusNow.phase === "FINALIZED") return { status: statusNow };
10714
11568
  try {
10715
- const again = await svc.simulateFinalizeReadiness(params);
11569
+ const again = await svc.simulateFinalizeReadiness(finalization);
10716
11570
  if (again.kind === "NOT_READY") {
10717
11571
  throw createError("STATE", {
10718
11572
  resource: "withdrawals",
@@ -10771,77 +11625,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
10771
11625
  };
10772
11626
  }
10773
11627
 
10774
- // src/core/resources/interop/attributes/call.ts
10775
- function createCallAttributes(codec) {
10776
- const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
10777
- const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
10778
- return {
10779
- indirectCall,
10780
- interopCallValue
10781
- };
10782
- }
10783
-
10784
- // src/core/resources/interop/attributes/bundle.ts
10785
- function createBundleAttributes(codec) {
10786
- const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
10787
- const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
10788
- const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
10789
- return {
10790
- executionAddress,
10791
- unbundlerAddress,
10792
- useFixedFee
10793
- };
10794
- }
10795
-
10796
- // src/core/resources/interop/attributes/resource.ts
10797
- function createAttributesResource(codec) {
10798
- return {
10799
- call: createCallAttributes(codec),
10800
- bundle: createBundleAttributes(codec)
10801
- };
10802
- }
10803
-
10804
- // src/adapters/viem/resources/interop/attributes/resource.ts
10805
- function getInteropAttributes(params, ctx) {
10806
- const bundleAttributes = [];
10807
- if (params.execution?.only) {
10808
- bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
10809
- }
10810
- if (params.unbundling?.by) {
10811
- bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
10812
- }
10813
- bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
10814
- const callAttributes = params.actions.map((action) => {
10815
- switch (action.type) {
10816
- case "sendNative": {
10817
- const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
10818
- if (baseMatches) {
10819
- return [ctx.attributes.call.interopCallValue(action.amount)];
10820
- }
10821
- return [ctx.attributes.call.indirectCall(action.amount)];
10822
- }
10823
- case "call":
10824
- if (action.value && action.value > 0n) {
10825
- return [ctx.attributes.call.interopCallValue(action.value)];
10826
- }
10827
- return [];
10828
- case "sendErc20":
10829
- return [ctx.attributes.call.indirectCall(0n)];
10830
- default:
10831
- assertNever(action);
10832
- }
10833
- });
10834
- return { bundleAttributes, callAttributes };
10835
- }
10836
- function createViemAttributesResource() {
10837
- const encode = (fn, args) => viem.encodeFunctionData({
10838
- abi: IERC7786Attributes_default,
10839
- functionName: fn,
10840
- args
10841
- });
10842
- return createAttributesResource({ encode });
10843
- }
10844
-
10845
11628
  // src/core/types/flows/interop.ts
10846
11629
  function isInteropMessageProof(obj) {
10847
11630
  if (typeof obj !== "object" || obj === null) return false;
@@ -11018,24 +11801,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
11018
11801
  }
11019
11802
  };
11020
11803
  }
11021
- var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
11022
- var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
11023
- function formatInteropEvmChain(chainId) {
11024
- const chainRef = viem.toBytes(viem.toHex(chainId));
11025
- const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
11026
- const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
11027
- return viem.toHex(payload);
11028
- }
11029
- function formatInteropEvmAddress(address) {
11030
- const normalized = viem.getAddress(address);
11031
- const addrBytes = viem.toBytes(normalized);
11032
- const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
11033
- return viem.toHex(payload);
11034
- }
11035
- var interopCodec = {
11036
- formatChain: formatInteropEvmChain,
11037
- formatAddress: formatInteropEvmAddress
11038
- };
11039
11804
  function getErc20Tokens(params) {
11040
11805
  const erc20Tokens = /* @__PURE__ */ new Map();
11041
11806
  for (const action of params.actions) {
@@ -11217,7 +11982,7 @@ function routeIndirect() {
11217
11982
  resolveErc20AssetIds(erc20Tokens, ctx),
11218
11983
  buildFeeInfo(params, ctx, params.actions.length)
11219
11984
  ]);
11220
- const attributes = getInteropAttributes(params, ctx);
11985
+ const attributes2 = getInteropAttributes(params, ctx);
11221
11986
  const starterData = await getStarterData(params, ctx, erc20AssetIds);
11222
11987
  const bundle = buildIndirectBundle(
11223
11988
  params,
@@ -11228,7 +11993,7 @@ function routeIndirect() {
11228
11993
  l2NativeTokenVault: ctx.l2NativeTokenVault,
11229
11994
  codec: interopCodec
11230
11995
  },
11231
- attributes,
11996
+ attributes2,
11232
11997
  starterData,
11233
11998
  feeInfo
11234
11999
  );
@@ -11348,7 +12113,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
11348
12113
  assertProtocolVersion(srcChainId, srcProtocolVersion);
11349
12114
  assertProtocolVersion(dstChainId, dstProtocolVersion);
11350
12115
  }
11351
- async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes) {
12116
+ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes2) {
11352
12117
  const sender = client.account.address;
11353
12118
  const chainId = BigInt(await client.l2.getChainId());
11354
12119
  const dstChainId = BigInt(await dstPublicClient.getChainId());
@@ -11382,7 +12147,7 @@ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, at
11382
12147
  l2AssetRouter,
11383
12148
  l2NativeTokenVault,
11384
12149
  baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
11385
- attributes,
12150
+ attributes: attributes2,
11386
12151
  gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
11387
12152
  };
11388
12153
  }
@@ -12082,7 +12847,7 @@ var ROUTES3 = {
12082
12847
  direct: routeDirect(),
12083
12848
  indirect: routeIndirect()
12084
12849
  };
12085
- function createInteropResource(client, config, tokens, contracts, attributes) {
12850
+ function createInteropResource(client, config, tokens, contracts, attributes2) {
12086
12851
  let gwProviderCache;
12087
12852
  function requireConfig() {
12088
12853
  if (!config)
@@ -12100,7 +12865,7 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
12100
12865
  const svc = createInteropFinalizationServices(client);
12101
12866
  const tokensResource = tokens ?? createTokensResource(client);
12102
12867
  const contractsResource = contracts ?? createContractsResource(client);
12103
- const attributesResource = attributes ?? createViemAttributesResource();
12868
+ const attributesResource = attributes2 ?? createViemAttributesResource();
12104
12869
  async function buildPlanWithCtx(dstPublicClient, params) {
12105
12870
  const ctx = await commonCtx3(
12106
12871
  dstPublicClient,
@@ -12320,7 +13085,7 @@ function createViemSdk(client, options) {
12320
13085
  const interop = createInteropResource(client, options?.interop, tokens, contracts);
12321
13086
  return {
12322
13087
  deposits: createDepositsResource(client, tokens, contracts),
12323
- withdrawals: createWithdrawalsResource(client, tokens, contracts),
13088
+ withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
12324
13089
  tokens,
12325
13090
  contracts,
12326
13091
  interop
@@ -12339,6 +13104,7 @@ exports.createInteropResource = createInteropResource;
12339
13104
  exports.createTokensResource = createTokensResource;
12340
13105
  exports.createViemClient = createViemClient;
12341
13106
  exports.createViemSdk = createViemSdk;
13107
+ exports.createWithdrawalProtocolService = createWithdrawalProtocolService;
12342
13108
  exports.createWithdrawalsResource = createWithdrawalsResource;
12343
13109
  exports.decodeRevert = decodeRevert;
12344
13110
  exports.encodeNativeTokenVaultTransferData = encodeNativeTokenVaultTransferData;