@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
@@ -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) {
@@ -10060,19 +10690,151 @@ function isL1MessageSentLog(log, opts) {
10060
10690
  const preferAddr = extractPreferAddress(opts);
10061
10691
  return log.address.toLowerCase() === preferAddr && (topic === TOPIC_L1_MESSAGE_SENT_LEG.toLowerCase() || topic === TOPIC_L1_MESSAGE_SENT_NEW.toLowerCase());
10062
10692
  }
10693
+ var SENDER_TOPIC = /^0x0{24}([0-9a-fA-F]{40})$/;
10694
+ function l1MessageSentSender(log) {
10695
+ const sender = SENDER_TOPIC.exec(log.topics?.[1] ?? "")?.[1];
10696
+ if (!sender) {
10697
+ throw new Error("L1MessageSent log has no valid sender topic.");
10698
+ }
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
+ };
10794
+ }
10063
10795
 
10064
- // src/core/resources/withdrawals/logs.ts
10065
- function messengerLogIndex(raw, opts) {
10066
- const index = opts?.index;
10067
- const messenger = (opts?.messenger).toLowerCase();
10068
- const arr = Array.isArray(raw?.l2ToL1Logs) ? raw.l2ToL1Logs : [];
10069
- const hits = arr.map((lg, i) => ({ i, lg })).filter(({ lg }) => (lg?.sender ?? "").toLowerCase() === messenger);
10070
- if (!hits.length) {
10071
- 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
+ }
10072
10806
  }
10073
- 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
+ };
10074
10836
  }
10075
- var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
10837
+ var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
10076
10838
  var IL1NullifierMini = [
10077
10839
  {
10078
10840
  type: "function",
@@ -10086,183 +10848,279 @@ var IL1NullifierMini = [
10086
10848
  outputs: [{ type: "bool" }]
10087
10849
  }
10088
10850
  ];
10089
- function createFinalizationServices(client) {
10090
- return {
10091
- async fetchFinalizeDepositParams(l2TxHash) {
10092
- const parsed = await wrapAs9(
10093
- "RPC",
10094
- OP_WITHDRAWALS.finalize.fetchParams.receipt,
10095
- () => client.zks.getReceiptWithL2ToL1(l2TxHash),
10096
- {
10097
- ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
10098
- 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
10099
10958
  }
10100
- );
10101
- if (!parsed) {
10102
- throw createError("STATE", {
10103
- resource: "withdrawals",
10104
- operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
10105
- message: "L2 receipt not found.",
10106
- context: { l2TxHash }
10107
- });
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
10108
10979
  }
10109
- const ev = await wrapAs9(
10110
- "INTERNAL",
10111
- OP_WITHDRAWALS.finalize.fetchParams.findMessage,
10112
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
10113
- () => 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
+ }),
10114
10998
  {
10115
- ctx: { l2TxHash, index: 0 },
10116
- message: "Failed to locate L1MessageSent event in L2 receipt."
10999
+ ctx: { where: "isWithdrawalFinalized", params: finalization.params },
11000
+ message: "Failed to read finalization status."
10117
11001
  }
10118
11002
  );
10119
- const message = await wrapAs9(
10120
- "INTERNAL",
10121
- OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
10122
- () => {
10123
- const [decoded] = viem.decodeAbiParameters([{ type: "bytes" }], ev.data);
10124
- return decoded;
10125
- },
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
+ }),
10126
11016
  {
10127
- ctx: { where: "decode L1MessageSent", data: ev.data },
10128
- message: "Failed to decode withdrawal message."
11017
+ ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
11018
+ message: "Failed to read bundle status."
10129
11019
  }
10130
- );
10131
- const raw = await wrapAs9(
11020
+ )
11021
+ );
11022
+ if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
11023
+ const callStatus = Number(
11024
+ await wrapAs10(
10132
11025
  "RPC",
10133
- OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
10134
- () => 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
+ }),
10135
11033
  {
10136
- ctx: { where: "getReceiptWithL2ToL1 (raw)", l2TxHash },
10137
- message: "Failed to fetch raw L2 receipt."
11034
+ ctx: { where: "L1InteropHandler.callStatus", bundleHash },
11035
+ message: "Failed to read bundle call status."
10138
11036
  }
10139
- );
10140
- if (!raw) {
10141
- 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", {
10142
11052
  resource: "withdrawals",
10143
- operation: OP_WITHDRAWALS.finalize.fetchParams.rawReceipt,
10144
- message: "Raw L2 receipt not found.",
10145
- 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 }
10146
11056
  });
10147
11057
  }
10148
- const idx = await wrapAs9(
10149
- "INTERNAL",
10150
- OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
10151
- () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
10152
- {
10153
- ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
10154
- message: "Failed to derive messenger log index."
10155
- }
10156
- );
10157
- const proof = await wrapAs9(
10158
- "RPC",
10159
- OP_WITHDRAWALS.finalize.fetchParams.proof,
10160
- () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
10161
- {
10162
- ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
10163
- message: "Failed to fetch L2\u2192L1 log proof."
10164
- }
10165
- );
10166
- const chainId = await wrapAs9(
10167
- "RPC",
10168
- OP_WITHDRAWALS.finalize.fetchParams.network,
10169
- () => client.l2.getChainId(),
10170
- { ctx: { where: "l2.getChainId" }, message: "Failed to read L2 chain id." }
10171
- );
10172
- const txIndex = Number(parsed.transactionIndex ?? 0);
10173
- const params = {
10174
- chainId: BigInt(chainId),
10175
- l2BatchNumber: proof.batchNumber,
10176
- l2MessageIndex: proof.id,
10177
- l2Sender: parsed.to,
10178
- l2TxNumberInBatch: txIndex,
10179
- message,
10180
- merkleProof: proof.proof
10181
- };
10182
- const { l1Nullifier } = await client.ensureAddresses();
10183
- return { params, nullifier: l1Nullifier };
11058
+ return { params: resolved.finalization.params, nullifier: resolved.target };
10184
11059
  },
10185
- async simulateFinalizeReadiness(params) {
10186
- const { l1Nullifier } = await client.ensureAddresses();
11060
+ async simulateFinalizeReadiness(finalization) {
11061
+ const target = await finalizationTarget(finalization.protocol);
10187
11062
  const done = await (async () => {
10188
11063
  try {
10189
- const result = await wrapAs9(
10190
- "RPC",
10191
- OP_WITHDRAWALS.finalize.readiness.isFinalized,
10192
- () => client.l1.readContract({
10193
- address: l1Nullifier,
10194
- abi: IL1NullifierMini,
10195
- functionName: "isWithdrawalFinalized",
10196
- args: [params.chainId, params.l2BatchNumber, params.l2MessageIndex]
10197
- }),
10198
- {
10199
- ctx: { where: "isWithdrawalFinalized", params },
10200
- message: "Failed to read finalization status."
10201
- }
10202
- );
10203
- return result;
11064
+ return await isWithdrawalFinalized(finalization);
10204
11065
  } catch {
10205
11066
  return false;
10206
11067
  }
10207
11068
  })();
10208
11069
  if (done) return { kind: "FINALIZED" };
10209
11070
  try {
10210
- await client.l1.simulateContract({
10211
- address: l1Nullifier,
10212
- abi: IL1Nullifier_default,
10213
- functionName: "finalizeDeposit",
10214
- args: [params],
10215
- account: client.account
10216
- });
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
+ }
10217
11088
  return { kind: "READY" };
10218
11089
  } catch (e) {
10219
11090
  return classifyReadinessFromRevert(e);
10220
11091
  }
10221
11092
  },
10222
- async isWithdrawalFinalized(key) {
10223
- const { l1Nullifier } = await client.ensureAddresses();
10224
- return await wrapAs9(
10225
- "RPC",
10226
- OP_WITHDRAWALS.finalize.isFinalized,
10227
- () => client.l1.readContract({
10228
- address: l1Nullifier,
10229
- abi: IL1NullifierMini,
10230
- functionName: "isWithdrawalFinalized",
10231
- args: [key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex]
10232
- }),
10233
- {
10234
- ctx: { where: "isWithdrawalFinalized", key },
10235
- message: "Failed to read finalization status."
10236
- }
10237
- );
10238
- },
10239
- async estimateFinalization(params) {
10240
- const { l1Nullifier } = await client.ensureAddresses();
10241
- const gasLimit = await wrapAs9(
11093
+ async estimateFinalization(finalization) {
11094
+ const target = await finalizationTarget(finalization.protocol);
11095
+ const gasLimit = await wrapAs10(
10242
11096
  "RPC",
10243
11097
  OP_WITHDRAWALS.finalize.estimate,
10244
- () => client.l1.estimateContractGas({
10245
- address: l1Nullifier,
11098
+ () => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
11099
+ address: target,
10246
11100
  abi: IL1Nullifier_default,
10247
11101
  functionName: "finalizeDeposit",
10248
- 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],
10249
11109
  account: client.account
10250
11110
  }),
10251
11111
  {
10252
11112
  ctx: {
10253
- where: "estimateContractGas(finalizeDeposit)",
10254
- chainIdL2: params.chainId,
10255
- l2BatchNumber: params.l2BatchNumber,
10256
- l2MessageIndex: params.l2MessageIndex,
10257
- l1Nullifier
11113
+ where: "estimateContractGas(finalize)",
11114
+ protocol: finalization.protocol,
11115
+ target
10258
11116
  },
10259
- message: "Failed to estimate gas for finalizeDeposit."
11117
+ message: "Failed to estimate gas for withdrawal finalization."
10260
11118
  }
10261
11119
  );
10262
11120
  let maxFeePerGas;
10263
11121
  let maxPriorityFeePerGas;
10264
11122
  try {
10265
- const fee = await wrapAs9(
11123
+ const fee = await wrapAs10(
10266
11124
  "RPC",
10267
11125
  OP_WITHDRAWALS.finalize.estimate,
10268
11126
  () => client.l1.estimateFeesPerGas(),
@@ -10281,32 +11139,34 @@ function createFinalizationServices(client) {
10281
11139
  })();
10282
11140
  maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
10283
11141
  } catch {
10284
- const gasPrice = await wrapAs9(
11142
+ const gasPrice = await wrapAs10(
10285
11143
  "RPC",
10286
11144
  OP_WITHDRAWALS.finalize.estimate,
10287
11145
  () => client.l1.getGasPrice(),
10288
11146
  {
10289
11147
  ctx: { where: "getGasPrice" },
10290
- message: "Failed to read gas price for finalizeDeposit."
11148
+ message: "Failed to read gas price for withdrawal finalization."
10291
11149
  }
10292
11150
  );
10293
11151
  maxFeePerGas = gasPrice;
10294
11152
  maxPriorityFeePerGas = 0n;
10295
11153
  }
10296
- return {
10297
- gasLimit,
10298
- maxFeePerGas,
10299
- maxPriorityFeePerGas
10300
- };
11154
+ return { gasLimit, maxFeePerGas, maxPriorityFeePerGas };
10301
11155
  },
10302
- async finalizeDeposit(params) {
10303
- const { l1Nullifier } = await client.ensureAddresses();
11156
+ async finalize(finalization) {
11157
+ const target = await finalizationTarget(finalization.protocol);
10304
11158
  try {
10305
- const hash = await client.l1Wallet.writeContract({
10306
- address: l1Nullifier,
11159
+ const hash = finalization.protocol === "legacy-withdrawal" ? await client.l1Wallet.writeContract({
11160
+ address: target,
10307
11161
  abi: IL1Nullifier_default,
10308
11162
  functionName: "finalizeDeposit",
10309
- 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],
10310
11170
  account: client.account
10311
11171
  });
10312
11172
  return {
@@ -10320,8 +11180,8 @@ function createFinalizationServices(client) {
10320
11180
  {
10321
11181
  resource: "withdrawals",
10322
11182
  operation: OP_WITHDRAWALS.finalize.wait,
10323
- message: "Failed while waiting for finalizeDeposit transaction.",
10324
- context: { txHash: hash }
11183
+ message: "Failed while waiting for the withdrawal finalization transaction.",
11184
+ context: { txHash: hash, protocol: finalization.protocol }
10325
11185
  },
10326
11186
  e
10327
11187
  );
@@ -10334,13 +11194,8 @@ function createFinalizationServices(client) {
10334
11194
  {
10335
11195
  resource: "withdrawals",
10336
11196
  operation: OP_WITHDRAWALS.finalize.send,
10337
- message: "Failed to send finalizeDeposit transaction.",
10338
- context: {
10339
- chainIdL2: params.chainId,
10340
- l2BatchNumber: params.l2BatchNumber,
10341
- l2MessageIndex: params.l2MessageIndex,
10342
- l1Nullifier
10343
- }
11197
+ message: "Failed to send the withdrawal finalization transaction.",
11198
+ context: { protocol: finalization.protocol, target }
10344
11199
  },
10345
11200
  e
10346
11201
  );
@@ -10349,6 +11204,23 @@ function createFinalizationServices(client) {
10349
11204
  };
10350
11205
  }
10351
11206
 
11207
+ // src/core/resources/withdrawals/status.ts
11208
+ function phaseFromReadiness(r) {
11209
+ switch (r.kind) {
11210
+ case "FINALIZED":
11211
+ return { phase: "FINALIZED" };
11212
+ case "READY":
11213
+ return { phase: "READY_TO_FINALIZE" };
11214
+ case "NOT_READY":
11215
+ return { phase: "PENDING", reason: formatReason(r.reason, r.detail) };
11216
+ case "UNFINALIZABLE":
11217
+ return { phase: "UNFINALIZABLE", reason: formatReason(r.reason, r.detail) };
11218
+ default:
11219
+ return assertNever(r);
11220
+ }
11221
+ }
11222
+ var formatReason = (reason, detail) => detail ? `${reason}: ${detail}` : reason;
11223
+
10352
11224
  // src/adapters/viem/resources/withdrawals/index.ts
10353
11225
  var ROUTES2 = {
10354
11226
  base: routeEthBase(),
@@ -10356,15 +11228,28 @@ var ROUTES2 = {
10356
11228
  "erc20-nonbase": routeErc20NonBase2()
10357
11229
  // AssetRouter.withdraw for non-base ERC-20s
10358
11230
  };
10359
- function createWithdrawalsResource(client, tokens, contracts) {
10360
- 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);
10361
11244
  const { wrap: wrap8, toResult: toResult3 } = createErrorHandlers("withdrawals");
10362
11245
  const tokensResource = tokens ?? createTokensResource(client);
10363
11246
  const contractsResource = contracts ?? createContractsResource(client);
10364
11247
  async function buildPlan(p) {
10365
- const ctx = await commonCtx2(p, client, tokensResource, contractsResource);
10366
- await ROUTES2[ctx.route].preflight?.(p, ctx);
10367
- 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);
10368
11253
  return {
10369
11254
  route: ctx.route,
10370
11255
  summary: {
@@ -10531,24 +11416,22 @@ function createWithdrawalsResource(client, tokens, contracts) {
10531
11416
  if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
10532
11417
  let pack;
10533
11418
  try {
10534
- pack = await svc.fetchFinalizeDepositParams(l2TxHash);
11419
+ pack = await svc.fetchFinalization(l2TxHash);
10535
11420
  } catch {
10536
11421
  return { phase: "PENDING", l2TxHash };
10537
11422
  }
10538
- const key = {
10539
- chainIdL2: pack.params.chainId,
10540
- l2BatchNumber: pack.params.l2BatchNumber,
10541
- l2MessageIndex: pack.params.l2MessageIndex
10542
- };
11423
+ const key = pack.key;
10543
11424
  try {
10544
- const done = await svc.isWithdrawalFinalized(key);
10545
- 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
+ }
10546
11430
  } catch {
10547
11431
  }
10548
- const readiness = await svc.simulateFinalizeReadiness(pack.params);
10549
- if (readiness.kind === "FINALIZED") return { phase: "FINALIZED", l2TxHash, key };
10550
- if (readiness.kind === "READY") return { phase: "READY_TO_FINALIZE", l2TxHash, key };
10551
- return { phase: "PENDING", l2TxHash, key };
11432
+ const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
11433
+ const { phase, reason } = phaseFromReadiness(readiness);
11434
+ return { phase, reason, l2TxHash, key };
10552
11435
  },
10553
11436
  {
10554
11437
  message: "Internal error while checking withdrawal status.",
@@ -10596,6 +11479,14 @@ function createWithdrawalsResource(client, tokens, contracts) {
10596
11479
  const deadline = opts.timeoutMs ? Date.now() + opts.timeoutMs : void 0;
10597
11480
  while (true) {
10598
11481
  const s = await status(l2Hash);
11482
+ if (s.phase === "UNFINALIZABLE") {
11483
+ throw createError("STATE", {
11484
+ resource: "withdrawals",
11485
+ operation: OP_WITHDRAWALS.wait,
11486
+ message: "Withdrawal can never be finalized.",
11487
+ context: { l2TxHash: l2Hash, reason: s.reason }
11488
+ });
11489
+ }
10599
11490
  if (opts.for === "ready") {
10600
11491
  if (s.phase === "READY_TO_FINALIZE" || s.phase === "FINALIZED") return null;
10601
11492
  } else {
@@ -10632,7 +11523,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
10632
11523
  async () => {
10633
11524
  const pack = await (async () => {
10634
11525
  try {
10635
- return await svc.fetchFinalizeDepositParams(l2TxHash);
11526
+ return await svc.fetchFinalization(l2TxHash);
10636
11527
  } catch (e) {
10637
11528
  throw createError("STATE", {
10638
11529
  resource: "withdrawals",
@@ -10643,21 +11534,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
10643
11534
  });
10644
11535
  }
10645
11536
  })();
10646
- const { params } = pack;
10647
- const key = {
10648
- chainIdL2: params.chainId,
10649
- l2BatchNumber: params.l2BatchNumber,
10650
- l2MessageIndex: params.l2MessageIndex
10651
- };
11537
+ const { finalization } = pack;
10652
11538
  try {
10653
- const done = await svc.isWithdrawalFinalized(key);
10654
- if (done) {
11539
+ const outcome = await svc.withdrawalOutcome(finalization);
11540
+ if (outcome === "finalized" || outcome === "failed") {
10655
11541
  const statusNow = await status(l2TxHash);
10656
11542
  return { status: statusNow };
10657
11543
  }
10658
11544
  } catch {
10659
11545
  }
10660
- const readiness = await svc.simulateFinalizeReadiness(params);
11546
+ const readiness = await svc.simulateFinalizeReadiness(finalization);
10661
11547
  if (readiness.kind === "FINALIZED") {
10662
11548
  const statusNow = await status(l2TxHash);
10663
11549
  return { status: statusNow };
@@ -10671,7 +11557,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
10671
11557
  });
10672
11558
  }
10673
11559
  try {
10674
- const tx = await svc.finalizeDeposit(params);
11560
+ const tx = await svc.finalize(finalization);
10675
11561
  finalizeCache.set(l2TxHash, tx.hash);
10676
11562
  const rcpt = await tx.wait();
10677
11563
  const statusNow = await status(l2TxHash);
@@ -10680,7 +11566,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
10680
11566
  const statusNow = await status(l2TxHash);
10681
11567
  if (statusNow.phase === "FINALIZED") return { status: statusNow };
10682
11568
  try {
10683
- const again = await svc.simulateFinalizeReadiness(params);
11569
+ const again = await svc.simulateFinalizeReadiness(finalization);
10684
11570
  if (again.kind === "NOT_READY") {
10685
11571
  throw createError("STATE", {
10686
11572
  resource: "withdrawals",
@@ -10739,77 +11625,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
10739
11625
  };
10740
11626
  }
10741
11627
 
10742
- // src/core/resources/interop/attributes/call.ts
10743
- function createCallAttributes(codec) {
10744
- const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
10745
- const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
10746
- return {
10747
- indirectCall,
10748
- interopCallValue
10749
- };
10750
- }
10751
-
10752
- // src/core/resources/interop/attributes/bundle.ts
10753
- function createBundleAttributes(codec) {
10754
- const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
10755
- const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
10756
- const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
10757
- return {
10758
- executionAddress,
10759
- unbundlerAddress,
10760
- useFixedFee
10761
- };
10762
- }
10763
-
10764
- // src/core/resources/interop/attributes/resource.ts
10765
- function createAttributesResource(codec) {
10766
- return {
10767
- call: createCallAttributes(codec),
10768
- bundle: createBundleAttributes(codec)
10769
- };
10770
- }
10771
-
10772
- // src/adapters/viem/resources/interop/attributes/resource.ts
10773
- function getInteropAttributes(params, ctx) {
10774
- const bundleAttributes = [];
10775
- if (params.execution?.only) {
10776
- bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
10777
- }
10778
- if (params.unbundling?.by) {
10779
- bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
10780
- }
10781
- bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
10782
- const callAttributes = params.actions.map((action) => {
10783
- switch (action.type) {
10784
- case "sendNative": {
10785
- const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
10786
- if (baseMatches) {
10787
- return [ctx.attributes.call.interopCallValue(action.amount)];
10788
- }
10789
- return [ctx.attributes.call.indirectCall(action.amount)];
10790
- }
10791
- case "call":
10792
- if (action.value && action.value > 0n) {
10793
- return [ctx.attributes.call.interopCallValue(action.value)];
10794
- }
10795
- return [];
10796
- case "sendErc20":
10797
- return [ctx.attributes.call.indirectCall(0n)];
10798
- default:
10799
- assertNever(action);
10800
- }
10801
- });
10802
- return { bundleAttributes, callAttributes };
10803
- }
10804
- function createViemAttributesResource() {
10805
- const encode = (fn, args) => viem.encodeFunctionData({
10806
- abi: IERC7786Attributes_default,
10807
- functionName: fn,
10808
- args
10809
- });
10810
- return createAttributesResource({ encode });
10811
- }
10812
-
10813
11628
  // src/core/types/flows/interop.ts
10814
11629
  function isInteropMessageProof(obj) {
10815
11630
  if (typeof obj !== "object" || obj === null) return false;
@@ -10986,24 +11801,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
10986
11801
  }
10987
11802
  };
10988
11803
  }
10989
- var PREFIX_EVM_CHAIN = viem.toBytes("0x00010000");
10990
- var PREFIX_EVM_ADDRESS = viem.toBytes("0x000100000014");
10991
- function formatInteropEvmChain(chainId) {
10992
- const chainRef = viem.toBytes(viem.toHex(chainId));
10993
- const chainRefLength = viem.toBytes(viem.toHex(chainRef.length, { size: 1 }));
10994
- const payload = viem.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
10995
- return viem.toHex(payload);
10996
- }
10997
- function formatInteropEvmAddress(address) {
10998
- const normalized = viem.getAddress(address);
10999
- const addrBytes = viem.toBytes(normalized);
11000
- const payload = viem.concat([PREFIX_EVM_ADDRESS, addrBytes]);
11001
- return viem.toHex(payload);
11002
- }
11003
- var interopCodec = {
11004
- formatChain: formatInteropEvmChain,
11005
- formatAddress: formatInteropEvmAddress
11006
- };
11007
11804
  function getErc20Tokens(params) {
11008
11805
  const erc20Tokens = /* @__PURE__ */ new Map();
11009
11806
  for (const action of params.actions) {
@@ -11185,7 +11982,7 @@ function routeIndirect() {
11185
11982
  resolveErc20AssetIds(erc20Tokens, ctx),
11186
11983
  buildFeeInfo(params, ctx, params.actions.length)
11187
11984
  ]);
11188
- const attributes = getInteropAttributes(params, ctx);
11985
+ const attributes2 = getInteropAttributes(params, ctx);
11189
11986
  const starterData = await getStarterData(params, ctx, erc20AssetIds);
11190
11987
  const bundle = buildIndirectBundle(
11191
11988
  params,
@@ -11196,7 +11993,7 @@ function routeIndirect() {
11196
11993
  l2NativeTokenVault: ctx.l2NativeTokenVault,
11197
11994
  codec: interopCodec
11198
11995
  },
11199
- attributes,
11996
+ attributes2,
11200
11997
  starterData,
11201
11998
  feeInfo
11202
11999
  );
@@ -11316,7 +12113,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
11316
12113
  assertProtocolVersion(srcChainId, srcProtocolVersion);
11317
12114
  assertProtocolVersion(dstChainId, dstProtocolVersion);
11318
12115
  }
11319
- async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes) {
12116
+ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, attributes2) {
11320
12117
  const sender = client.account.address;
11321
12118
  const chainId = BigInt(await client.l2.getChainId());
11322
12119
  const dstChainId = BigInt(await dstPublicClient.getChainId());
@@ -11350,7 +12147,7 @@ async function commonCtx3(dstPublicClient, params, client, tokens, contracts, at
11350
12147
  l2AssetRouter,
11351
12148
  l2NativeTokenVault,
11352
12149
  baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
11353
- attributes,
12150
+ attributes: attributes2,
11354
12151
  gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
11355
12152
  };
11356
12153
  }
@@ -12050,7 +12847,7 @@ var ROUTES3 = {
12050
12847
  direct: routeDirect(),
12051
12848
  indirect: routeIndirect()
12052
12849
  };
12053
- function createInteropResource(client, config, tokens, contracts, attributes) {
12850
+ function createInteropResource(client, config, tokens, contracts, attributes2) {
12054
12851
  let gwProviderCache;
12055
12852
  function requireConfig() {
12056
12853
  if (!config)
@@ -12068,7 +12865,7 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
12068
12865
  const svc = createInteropFinalizationServices(client);
12069
12866
  const tokensResource = tokens ?? createTokensResource(client);
12070
12867
  const contractsResource = contracts ?? createContractsResource(client);
12071
- const attributesResource = attributes ?? createViemAttributesResource();
12868
+ const attributesResource = attributes2 ?? createViemAttributesResource();
12072
12869
  async function buildPlanWithCtx(dstPublicClient, params) {
12073
12870
  const ctx = await commonCtx3(
12074
12871
  dstPublicClient,
@@ -12288,7 +13085,7 @@ function createViemSdk(client, options) {
12288
13085
  const interop = createInteropResource(client, options?.interop, tokens, contracts);
12289
13086
  return {
12290
13087
  deposits: createDepositsResource(client, tokens, contracts),
12291
- withdrawals: createWithdrawalsResource(client, tokens, contracts),
13088
+ withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
12292
13089
  tokens,
12293
13090
  contracts,
12294
13091
  interop
@@ -12307,6 +13104,7 @@ exports.createInteropResource = createInteropResource;
12307
13104
  exports.createTokensResource = createTokensResource;
12308
13105
  exports.createViemClient = createViemClient;
12309
13106
  exports.createViemSdk = createViemSdk;
13107
+ exports.createWithdrawalProtocolService = createWithdrawalProtocolService;
12310
13108
  exports.createWithdrawalsResource = createWithdrawalsResource;
12311
13109
  exports.decodeRevert = decodeRevert;
12312
13110
  exports.encodeNativeTokenVaultTransferData = encodeNativeTokenVaultTransferData;