@matterlabs/zksync-js 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/ethers/client.cjs +31 -8
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.d.ts +11 -0
- package/dist/adapters/ethers/client.js +6 -5
- package/dist/adapters/ethers/index.cjs +1194 -364
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.d.ts +2 -1
- package/dist/adapters/ethers/index.js +10 -8
- package/dist/adapters/ethers/resources/deposits/context.d.ts +2 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +3 -0
- package/dist/adapters/ethers/resources/withdrawals/context.d.ts +12 -1
- package/dist/adapters/ethers/resources/withdrawals/index.d.ts +17 -1
- package/dist/adapters/ethers/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
- package/dist/adapters/ethers/resources/withdrawals/services/finalization.d.ts +35 -17
- package/dist/adapters/ethers/resources/withdrawals/services/protocol.d.ts +11 -0
- package/dist/adapters/ethers/sdk.cjs +1166 -370
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.d.ts +3 -1
- package/dist/adapters/ethers/sdk.js +8 -7
- package/dist/adapters/viem/client.cjs +44 -7
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.d.ts +11 -0
- package/dist/adapters/viem/client.js +6 -5
- package/dist/adapters/viem/index.cjs +1237 -383
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.d.ts +2 -1
- package/dist/adapters/viem/index.js +10 -8
- package/dist/adapters/viem/resources/deposits/context.d.ts +2 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +3 -0
- package/dist/adapters/viem/resources/withdrawals/context.d.ts +12 -1
- package/dist/adapters/viem/resources/withdrawals/index.d.ts +17 -1
- package/dist/adapters/viem/resources/withdrawals/routes/interop-bundle.d.ts +2 -0
- package/dist/adapters/viem/resources/withdrawals/services/finalization.d.ts +36 -18
- package/dist/adapters/viem/resources/withdrawals/services/protocol.d.ts +11 -0
- package/dist/adapters/viem/sdk.cjs +1191 -385
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.d.ts +3 -1
- package/dist/adapters/viem/sdk.js +8 -7
- package/dist/{chunk-UEKFQAOS.js → chunk-2DDJFHHD.js} +304 -9
- package/dist/{chunk-MT4X5FEO.js → chunk-3IPSDGHO.js} +19 -1
- package/dist/{chunk-JSBMIT4S.js → chunk-4GPIHYVF.js} +1 -1
- package/dist/{chunk-SBGBYZJM.js → chunk-4M7VNYGC.js} +2 -2
- package/dist/{chunk-CK5UFAZK.js → chunk-6WIAMFIW.js} +37 -3
- package/dist/chunk-JJ523MOL.js +157 -0
- package/dist/{chunk-7GZDTLHX.js → chunk-NVOFHV3A.js} +666 -304
- package/dist/{chunk-LGTYM5XP.js → chunk-OEUDZFXH.js} +1 -1
- package/dist/{chunk-NJK325XV.js → chunk-TUN6NH5D.js} +2 -2
- package/dist/chunk-UMPAKZCQ.js +19 -0
- package/dist/{chunk-24TE2NNJ.js → chunk-URHDNDFN.js} +24 -4
- package/dist/{chunk-2CGBLD5H.js → chunk-V2TDNGI5.js} +642 -288
- package/dist/{chunk-IDXSGCGF.js → chunk-WPCZNITC.js} +63 -50
- package/dist/{chunk-TYYUG5GA.js → chunk-X2JJDQ4O.js} +1 -1
- package/dist/core/abi.d.ts +1 -0
- package/dist/core/adapters/interfaces.d.ts +2 -0
- package/dist/core/constants.cjs +18 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +17 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +504 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.js +6 -4
- package/dist/core/internal/abis/IERC7786Attributes.d.ts +10 -0
- package/dist/core/internal/abis/IL1NullifierV32.d.ts +221 -0
- package/dist/core/internal/abis/IL2AssetRouter.d.ts +0 -14
- package/dist/core/resources/deposits/priority.d.ts +30 -0
- package/dist/core/resources/interop/attributes/bundle.d.ts +1 -0
- package/dist/core/resources/interop/attributes/resource.d.ts +1 -0
- package/dist/core/resources/protocol/semver.d.ts +18 -0
- package/dist/core/resources/withdrawals/bundle.d.ts +80 -0
- package/dist/core/resources/withdrawals/finalization.d.ts +142 -0
- package/dist/core/resources/withdrawals/protocol.d.ts +55 -0
- package/dist/core/types/flows/withdrawals.d.ts +30 -0
- package/dist/index.cjs +320 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -37,6 +37,7 @@ var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
|
37
37
|
var L2_INTEROP_CENTER_ADDRESS = "0x000000000000000000000000000000000001000d";
|
|
38
38
|
var L2_INTEROP_HANDLER_ADDRESS = "0x000000000000000000000000000000000001000e";
|
|
39
39
|
var L2_INTEROP_ROOT_STORAGE_ADDRESS = "0x0000000000000000000000000000000000010008";
|
|
40
|
+
var L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS = "0x0000000000000000000000000000000000010015";
|
|
40
41
|
var L2_MESSAGE_VERIFICATION_ADDRESS = "0x0000000000000000000000000000000000010009";
|
|
41
42
|
var BUNDLE_IDENTIFIER = "0x01";
|
|
42
43
|
var TOPIC_L1_MESSAGE_SENT_NEW = k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
@@ -57,6 +58,14 @@ var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
|
|
|
57
58
|
var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
|
|
58
59
|
var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
|
|
59
60
|
var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
|
|
61
|
+
var L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS = 21000n;
|
|
62
|
+
var L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS = 40n;
|
|
63
|
+
var L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS = 351n;
|
|
64
|
+
var MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS = 1n << 35n;
|
|
65
|
+
var L1_TX_NATIVE_PER_GAS = 100000000n;
|
|
66
|
+
var ZKSYNC_OS_PRIORITY_TX_TYPE = "0x7f";
|
|
67
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS = 140000n;
|
|
68
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES = 300n;
|
|
60
69
|
|
|
61
70
|
// src/core/utils/addr.ts
|
|
62
71
|
function isAddress(x) {
|
|
@@ -3490,6 +3499,294 @@ var IL1NullifierABI = [
|
|
|
3490
3499
|
];
|
|
3491
3500
|
var IL1Nullifier_default = IL1NullifierABI;
|
|
3492
3501
|
|
|
3502
|
+
// src/core/internal/abis/IL1NullifierV32.ts
|
|
3503
|
+
var IL1NullifierV32ABI = [
|
|
3504
|
+
{
|
|
3505
|
+
anonymous: false,
|
|
3506
|
+
inputs: [
|
|
3507
|
+
{
|
|
3508
|
+
indexed: true,
|
|
3509
|
+
internalType: "uint256",
|
|
3510
|
+
name: "chainId",
|
|
3511
|
+
type: "uint256"
|
|
3512
|
+
},
|
|
3513
|
+
{
|
|
3514
|
+
indexed: true,
|
|
3515
|
+
internalType: "bytes32",
|
|
3516
|
+
name: "txDataHash",
|
|
3517
|
+
type: "bytes32"
|
|
3518
|
+
},
|
|
3519
|
+
{
|
|
3520
|
+
indexed: true,
|
|
3521
|
+
internalType: "bytes32",
|
|
3522
|
+
name: "l2DepositTxHash",
|
|
3523
|
+
type: "bytes32"
|
|
3524
|
+
}
|
|
3525
|
+
],
|
|
3526
|
+
name: "BridgehubDepositFinalized",
|
|
3527
|
+
type: "event"
|
|
3528
|
+
},
|
|
3529
|
+
{
|
|
3530
|
+
inputs: [],
|
|
3531
|
+
name: "BRIDGE_HUB",
|
|
3532
|
+
outputs: [
|
|
3533
|
+
{
|
|
3534
|
+
internalType: "contract IL1Bridgehub",
|
|
3535
|
+
name: "",
|
|
3536
|
+
type: "address"
|
|
3537
|
+
}
|
|
3538
|
+
],
|
|
3539
|
+
stateMutability: "view",
|
|
3540
|
+
type: "function"
|
|
3541
|
+
},
|
|
3542
|
+
{
|
|
3543
|
+
inputs: [],
|
|
3544
|
+
name: "l1AssetRouter",
|
|
3545
|
+
outputs: [
|
|
3546
|
+
{
|
|
3547
|
+
internalType: "contract IL1AssetRouter",
|
|
3548
|
+
name: "",
|
|
3549
|
+
type: "address"
|
|
3550
|
+
}
|
|
3551
|
+
],
|
|
3552
|
+
stateMutability: "view",
|
|
3553
|
+
type: "function"
|
|
3554
|
+
},
|
|
3555
|
+
{
|
|
3556
|
+
// The contract that took over withdrawal finalization from the nullifier's own (removed)
|
|
3557
|
+
// `finalizeDeposit`.
|
|
3558
|
+
inputs: [],
|
|
3559
|
+
name: "l1InteropHandler",
|
|
3560
|
+
outputs: [
|
|
3561
|
+
{
|
|
3562
|
+
internalType: "address",
|
|
3563
|
+
name: "",
|
|
3564
|
+
type: "address"
|
|
3565
|
+
}
|
|
3566
|
+
],
|
|
3567
|
+
stateMutability: "view",
|
|
3568
|
+
type: "function"
|
|
3569
|
+
},
|
|
3570
|
+
{
|
|
3571
|
+
inputs: [],
|
|
3572
|
+
name: "l1NativeTokenVault",
|
|
3573
|
+
outputs: [
|
|
3574
|
+
{
|
|
3575
|
+
internalType: "contract IL1NativeTokenVault",
|
|
3576
|
+
name: "",
|
|
3577
|
+
type: "address"
|
|
3578
|
+
}
|
|
3579
|
+
],
|
|
3580
|
+
stateMutability: "view",
|
|
3581
|
+
type: "function"
|
|
3582
|
+
},
|
|
3583
|
+
{
|
|
3584
|
+
inputs: [
|
|
3585
|
+
{
|
|
3586
|
+
internalType: "uint256",
|
|
3587
|
+
name: "_chainId",
|
|
3588
|
+
type: "uint256"
|
|
3589
|
+
},
|
|
3590
|
+
{
|
|
3591
|
+
internalType: "bytes32",
|
|
3592
|
+
name: "_l2TxHash",
|
|
3593
|
+
type: "bytes32"
|
|
3594
|
+
}
|
|
3595
|
+
],
|
|
3596
|
+
name: "depositHappened",
|
|
3597
|
+
outputs: [
|
|
3598
|
+
{
|
|
3599
|
+
internalType: "bytes32",
|
|
3600
|
+
name: "",
|
|
3601
|
+
type: "bytes32"
|
|
3602
|
+
}
|
|
3603
|
+
],
|
|
3604
|
+
stateMutability: "view",
|
|
3605
|
+
type: "function"
|
|
3606
|
+
},
|
|
3607
|
+
{
|
|
3608
|
+
inputs: [
|
|
3609
|
+
{
|
|
3610
|
+
internalType: "uint256",
|
|
3611
|
+
name: "_chainId",
|
|
3612
|
+
type: "uint256"
|
|
3613
|
+
},
|
|
3614
|
+
{
|
|
3615
|
+
internalType: "bytes32",
|
|
3616
|
+
name: "_txDataHash",
|
|
3617
|
+
type: "bytes32"
|
|
3618
|
+
},
|
|
3619
|
+
{
|
|
3620
|
+
internalType: "bytes32",
|
|
3621
|
+
name: "_txHash",
|
|
3622
|
+
type: "bytes32"
|
|
3623
|
+
}
|
|
3624
|
+
],
|
|
3625
|
+
name: "bridgehubConfirmL2TransactionForwarded",
|
|
3626
|
+
outputs: [],
|
|
3627
|
+
stateMutability: "nonpayable",
|
|
3628
|
+
type: "function"
|
|
3629
|
+
},
|
|
3630
|
+
{
|
|
3631
|
+
inputs: [
|
|
3632
|
+
{
|
|
3633
|
+
components: [
|
|
3634
|
+
{
|
|
3635
|
+
internalType: "uint256",
|
|
3636
|
+
name: "_chainId",
|
|
3637
|
+
type: "uint256"
|
|
3638
|
+
},
|
|
3639
|
+
{
|
|
3640
|
+
internalType: "address",
|
|
3641
|
+
name: "_depositSender",
|
|
3642
|
+
type: "address"
|
|
3643
|
+
},
|
|
3644
|
+
{
|
|
3645
|
+
internalType: "uint16",
|
|
3646
|
+
name: "_l2TxNumberInBatch",
|
|
3647
|
+
type: "uint16"
|
|
3648
|
+
},
|
|
3649
|
+
{
|
|
3650
|
+
internalType: "enum TxStatus",
|
|
3651
|
+
name: "_txStatus",
|
|
3652
|
+
type: "uint8"
|
|
3653
|
+
},
|
|
3654
|
+
{
|
|
3655
|
+
internalType: "bytes32",
|
|
3656
|
+
name: "_assetId",
|
|
3657
|
+
type: "bytes32"
|
|
3658
|
+
},
|
|
3659
|
+
{
|
|
3660
|
+
internalType: "bytes",
|
|
3661
|
+
name: "_assetData",
|
|
3662
|
+
type: "bytes"
|
|
3663
|
+
},
|
|
3664
|
+
{
|
|
3665
|
+
internalType: "bytes32",
|
|
3666
|
+
name: "_l2TxHash",
|
|
3667
|
+
type: "bytes32"
|
|
3668
|
+
},
|
|
3669
|
+
{
|
|
3670
|
+
internalType: "uint256",
|
|
3671
|
+
name: "_l2BatchNumber",
|
|
3672
|
+
type: "uint256"
|
|
3673
|
+
},
|
|
3674
|
+
{
|
|
3675
|
+
internalType: "uint256",
|
|
3676
|
+
name: "_l2MessageIndex",
|
|
3677
|
+
type: "uint256"
|
|
3678
|
+
},
|
|
3679
|
+
{
|
|
3680
|
+
internalType: "bytes32[]",
|
|
3681
|
+
name: "_merkleProof",
|
|
3682
|
+
type: "bytes32[]"
|
|
3683
|
+
}
|
|
3684
|
+
],
|
|
3685
|
+
internalType: "struct ConfirmTransferResultData",
|
|
3686
|
+
name: "_confirmTransferResultData",
|
|
3687
|
+
type: "tuple"
|
|
3688
|
+
}
|
|
3689
|
+
],
|
|
3690
|
+
name: "bridgeConfirmTransferResult",
|
|
3691
|
+
outputs: [],
|
|
3692
|
+
stateMutability: "nonpayable",
|
|
3693
|
+
type: "function"
|
|
3694
|
+
},
|
|
3695
|
+
{
|
|
3696
|
+
inputs: [
|
|
3697
|
+
{
|
|
3698
|
+
internalType: "uint256",
|
|
3699
|
+
name: "_chainId",
|
|
3700
|
+
type: "uint256"
|
|
3701
|
+
},
|
|
3702
|
+
{
|
|
3703
|
+
internalType: "address",
|
|
3704
|
+
name: "_depositSender",
|
|
3705
|
+
type: "address"
|
|
3706
|
+
},
|
|
3707
|
+
{
|
|
3708
|
+
internalType: "bytes32",
|
|
3709
|
+
name: "_assetId",
|
|
3710
|
+
type: "bytes32"
|
|
3711
|
+
},
|
|
3712
|
+
{
|
|
3713
|
+
internalType: "bytes",
|
|
3714
|
+
name: "_assetData",
|
|
3715
|
+
type: "bytes"
|
|
3716
|
+
},
|
|
3717
|
+
{
|
|
3718
|
+
internalType: "bytes32",
|
|
3719
|
+
name: "_l2TxHash",
|
|
3720
|
+
type: "bytes32"
|
|
3721
|
+
},
|
|
3722
|
+
{
|
|
3723
|
+
internalType: "uint256",
|
|
3724
|
+
name: "_l2BatchNumber",
|
|
3725
|
+
type: "uint256"
|
|
3726
|
+
},
|
|
3727
|
+
{
|
|
3728
|
+
internalType: "uint256",
|
|
3729
|
+
name: "_l2MessageIndex",
|
|
3730
|
+
type: "uint256"
|
|
3731
|
+
},
|
|
3732
|
+
{
|
|
3733
|
+
internalType: "uint16",
|
|
3734
|
+
name: "_l2TxNumberInBatch",
|
|
3735
|
+
type: "uint16"
|
|
3736
|
+
},
|
|
3737
|
+
{
|
|
3738
|
+
internalType: "bytes32[]",
|
|
3739
|
+
name: "_merkleProof",
|
|
3740
|
+
type: "bytes32[]"
|
|
3741
|
+
}
|
|
3742
|
+
],
|
|
3743
|
+
name: "bridgeRecoverFailedTransfer",
|
|
3744
|
+
outputs: [],
|
|
3745
|
+
stateMutability: "nonpayable",
|
|
3746
|
+
type: "function"
|
|
3747
|
+
},
|
|
3748
|
+
{
|
|
3749
|
+
inputs: [
|
|
3750
|
+
{
|
|
3751
|
+
internalType: "contract IL1NativeTokenVault",
|
|
3752
|
+
name: "_nativeTokenVault",
|
|
3753
|
+
type: "address"
|
|
3754
|
+
}
|
|
3755
|
+
],
|
|
3756
|
+
name: "setL1NativeTokenVault",
|
|
3757
|
+
outputs: [],
|
|
3758
|
+
stateMutability: "nonpayable",
|
|
3759
|
+
type: "function"
|
|
3760
|
+
},
|
|
3761
|
+
{
|
|
3762
|
+
inputs: [
|
|
3763
|
+
{
|
|
3764
|
+
internalType: "address",
|
|
3765
|
+
name: "_l1AssetRouter",
|
|
3766
|
+
type: "address"
|
|
3767
|
+
}
|
|
3768
|
+
],
|
|
3769
|
+
name: "setL1AssetRouter",
|
|
3770
|
+
outputs: [],
|
|
3771
|
+
stateMutability: "nonpayable",
|
|
3772
|
+
type: "function"
|
|
3773
|
+
},
|
|
3774
|
+
{
|
|
3775
|
+
inputs: [
|
|
3776
|
+
{
|
|
3777
|
+
internalType: "address",
|
|
3778
|
+
name: "_l1InteropHandler",
|
|
3779
|
+
type: "address"
|
|
3780
|
+
}
|
|
3781
|
+
],
|
|
3782
|
+
name: "setL1InteropHandler",
|
|
3783
|
+
outputs: [],
|
|
3784
|
+
stateMutability: "nonpayable",
|
|
3785
|
+
type: "function"
|
|
3786
|
+
}
|
|
3787
|
+
];
|
|
3788
|
+
var IL1NullifierV32_default = IL1NullifierV32ABI;
|
|
3789
|
+
|
|
3493
3790
|
// src/core/internal/abis/IL2AssetRouter.ts
|
|
3494
3791
|
var IL2AssetRouterABI = [
|
|
3495
3792
|
{
|
|
@@ -3613,13 +3910,6 @@ var IL2AssetRouterABI = [
|
|
|
3613
3910
|
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
3614
3911
|
stateMutability: "view"
|
|
3615
3912
|
},
|
|
3616
|
-
{
|
|
3617
|
-
type: "function",
|
|
3618
|
-
name: "l1TokenAddress",
|
|
3619
|
-
inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
|
|
3620
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
3621
|
-
stateMutability: "view"
|
|
3622
|
-
},
|
|
3623
3913
|
{
|
|
3624
3914
|
type: "function",
|
|
3625
3915
|
name: "l2TokenAddress",
|
|
@@ -5023,6 +5313,19 @@ var IERC7786AttributesABI = [
|
|
|
5023
5313
|
outputs: [],
|
|
5024
5314
|
stateMutability: "pure"
|
|
5025
5315
|
},
|
|
5316
|
+
{
|
|
5317
|
+
type: "function",
|
|
5318
|
+
name: "interopBundleSalt",
|
|
5319
|
+
inputs: [
|
|
5320
|
+
{
|
|
5321
|
+
name: "_salt",
|
|
5322
|
+
type: "bytes32",
|
|
5323
|
+
internalType: "bytes32"
|
|
5324
|
+
}
|
|
5325
|
+
],
|
|
5326
|
+
outputs: [],
|
|
5327
|
+
stateMutability: "pure"
|
|
5328
|
+
},
|
|
5026
5329
|
{
|
|
5027
5330
|
type: "function",
|
|
5028
5331
|
name: "unbundlerAddress",
|
|
@@ -7537,7 +7840,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
7537
7840
|
function wrap8(operation, fn, opts) {
|
|
7538
7841
|
return run("INTERNAL", operation, fn, opts);
|
|
7539
7842
|
}
|
|
7540
|
-
function
|
|
7843
|
+
function wrapAs11(kind, operation, fn, opts) {
|
|
7541
7844
|
return run(kind, operation, fn, opts);
|
|
7542
7845
|
}
|
|
7543
7846
|
async function toResult3(operation, fn, opts) {
|
|
@@ -7558,7 +7861,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
7558
7861
|
return { ok: false, error: shaped };
|
|
7559
7862
|
}
|
|
7560
7863
|
}
|
|
7561
|
-
return { wrap: wrap8, wrapAs:
|
|
7864
|
+
return { wrap: wrap8, wrapAs: wrapAs11, toResult: toResult3 };
|
|
7562
7865
|
}
|
|
7563
7866
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
7564
7867
|
}
|
|
@@ -7702,10 +8005,24 @@ function classifyReadinessFromRevert(e) {
|
|
|
7702
8005
|
// src/adapters/ethers/errors/error-ops.ts
|
|
7703
8006
|
var { toZKsyncError, createErrorHandlers } = createErrorOps(decodeRevert);
|
|
7704
8007
|
|
|
8008
|
+
// src/core/resources/protocol/semver.ts
|
|
8009
|
+
var SEMVER_MINOR_OFFSET = 32n;
|
|
8010
|
+
var SEMVER_MAJOR_OFFSET = 64n;
|
|
8011
|
+
var U32_MASK = 0xffffffffn;
|
|
8012
|
+
function unpackSemver(packed) {
|
|
8013
|
+
const patch = Number(packed & U32_MASK);
|
|
8014
|
+
const minor = Number(packed >> SEMVER_MINOR_OFFSET & U32_MASK);
|
|
8015
|
+
const major = Number(packed >> SEMVER_MAJOR_OFFSET & U32_MASK);
|
|
8016
|
+
return [major, minor, patch];
|
|
8017
|
+
}
|
|
8018
|
+
|
|
7705
8019
|
// src/adapters/ethers/client.ts
|
|
7706
8020
|
var { wrapAs, wrap } = createErrorHandlers("client");
|
|
7707
8021
|
var ChainTypeManagerABI = [
|
|
7708
|
-
"function getSemverProtocolVersion() view returns (uint32,uint32,uint32)"
|
|
8022
|
+
"function getSemverProtocolVersion() view returns (uint32,uint32,uint32)",
|
|
8023
|
+
// Per-chain version. `getSemverProtocolVersion` reports the CTM's own (latest) version, which
|
|
8024
|
+
// runs ahead of individual chains mid-upgrade — so capability gating must use this one.
|
|
8025
|
+
"function getProtocolVersion(uint256 _chainId) view returns (uint256)"
|
|
7709
8026
|
];
|
|
7710
8027
|
function createEthersClient(args) {
|
|
7711
8028
|
const { l1, l2, signer } = args;
|
|
@@ -7864,6 +8181,21 @@ function createEthersClient(args) {
|
|
|
7864
8181
|
);
|
|
7865
8182
|
return semver;
|
|
7866
8183
|
}
|
|
8184
|
+
async function getChainProtocolVersion(chainId) {
|
|
8185
|
+
try {
|
|
8186
|
+
const targetChainId = chainId ?? (await l2.getNetwork()).chainId;
|
|
8187
|
+
const { bridgehub } = await ensureAddresses();
|
|
8188
|
+
const bh = new ethers.Contract(bridgehub, IBridgehub_default, l1);
|
|
8189
|
+
const chainTypeManager = await bh.chainTypeManager(targetChainId);
|
|
8190
|
+
if (chainTypeManager.toLowerCase() === FORMAL_ETH_ADDRESS) return void 0;
|
|
8191
|
+
const ctm = new ethers.Contract(chainTypeManager, ChainTypeManagerABI, l1);
|
|
8192
|
+
const packed = await ctm.getProtocolVersion(targetChainId);
|
|
8193
|
+
if (packed === 0n) return void 0;
|
|
8194
|
+
return unpackSemver(packed);
|
|
8195
|
+
} catch {
|
|
8196
|
+
return void 0;
|
|
8197
|
+
}
|
|
8198
|
+
}
|
|
7867
8199
|
function signerFor(target) {
|
|
7868
8200
|
if (target === "l1") {
|
|
7869
8201
|
return boundSigner.provider === l1 ? boundSigner : boundSigner.connect(l1);
|
|
@@ -7888,6 +8220,7 @@ function createEthersClient(args) {
|
|
|
7888
8220
|
refresh,
|
|
7889
8221
|
baseToken,
|
|
7890
8222
|
getProtocolVersion,
|
|
8223
|
+
getChainProtocolVersion,
|
|
7891
8224
|
signerFor
|
|
7892
8225
|
};
|
|
7893
8226
|
return client;
|
|
@@ -7964,7 +8297,7 @@ function toGasOverrides(overrides) {
|
|
|
7964
8297
|
|
|
7965
8298
|
// src/adapters/ethers/resources/deposits/context.ts
|
|
7966
8299
|
async function commonCtx(p, client, tokens, contracts) {
|
|
7967
|
-
const { bridgehub, l1AssetRouter } = await contracts.addresses();
|
|
8300
|
+
const { bridgehub, l1AssetRouter, l1NativeTokenVault } = await contracts.addresses();
|
|
7968
8301
|
const { chainId } = await client.l2.getNetwork();
|
|
7969
8302
|
const sender = await client.signer.getAddress();
|
|
7970
8303
|
const gasPerPubdata = p.gasPerPubdata ?? 800n;
|
|
@@ -7992,6 +8325,7 @@ async function commonCtx(p, client, tokens, contracts) {
|
|
|
7992
8325
|
baseTokenL1,
|
|
7993
8326
|
baseIsEth,
|
|
7994
8327
|
l1AssetRouter,
|
|
8328
|
+
l1NativeTokenVault,
|
|
7995
8329
|
route,
|
|
7996
8330
|
bridgehub,
|
|
7997
8331
|
chainIdL2: BigInt(chainId),
|
|
@@ -8229,6 +8563,15 @@ function ethersToGasEstimator(provider) {
|
|
|
8229
8563
|
}
|
|
8230
8564
|
return await provider.estimateGas(ethTx);
|
|
8231
8565
|
},
|
|
8566
|
+
async estimatePriorityTxGas(tx) {
|
|
8567
|
+
if (!("send" in provider)) {
|
|
8568
|
+
throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
|
|
8569
|
+
}
|
|
8570
|
+
const result = await provider.send("eth_estimateGas", [
|
|
8571
|
+
{ from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
|
|
8572
|
+
]);
|
|
8573
|
+
return BigInt(result);
|
|
8574
|
+
},
|
|
8232
8575
|
async estimateFeesPerGas() {
|
|
8233
8576
|
const fd = await provider.getFeeData();
|
|
8234
8577
|
return {
|
|
@@ -8277,9 +8620,79 @@ async function quoteL2BaseCost2(input) {
|
|
|
8277
8620
|
);
|
|
8278
8621
|
}
|
|
8279
8622
|
|
|
8623
|
+
// src/core/resources/deposits/priority.ts
|
|
8624
|
+
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
8625
|
+
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
8626
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
8627
|
+
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
8628
|
+
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
8629
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
8630
|
+
function applyL1ToL2Alias(address) {
|
|
8631
|
+
return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
|
|
8632
|
+
}
|
|
8633
|
+
function derivePriorityTxGasBreakdown(input) {
|
|
8634
|
+
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
8635
|
+
const minBodyGas = maxBigInt2(
|
|
8636
|
+
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
8637
|
+
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
8638
|
+
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
8639
|
+
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
8640
|
+
L1_TX_MIN_L2_GAS_BASE
|
|
8641
|
+
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
8642
|
+
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
8643
|
+
const derivedBodyGas = minBodyGas;
|
|
8644
|
+
return {
|
|
8645
|
+
encodedLength: input.encodedLength,
|
|
8646
|
+
minBodyGas,
|
|
8647
|
+
overhead,
|
|
8648
|
+
derivedBodyGas,
|
|
8649
|
+
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
8650
|
+
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
8651
|
+
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
8652
|
+
};
|
|
8653
|
+
}
|
|
8654
|
+
function derivePriorityBodyGasEstimateCap(input) {
|
|
8655
|
+
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
8656
|
+
}
|
|
8657
|
+
function applyPriorityL2GasLimitBuffer(input) {
|
|
8658
|
+
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
8659
|
+
}
|
|
8660
|
+
function minimalPriorityTxL2Gas(input) {
|
|
8661
|
+
const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
|
|
8662
|
+
const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
|
|
8663
|
+
return maxBigInt2(intrinsic, pubdata);
|
|
8664
|
+
}
|
|
8665
|
+
function clampPriorityL2GasLimit(input) {
|
|
8666
|
+
return maxBigInt2(
|
|
8667
|
+
input.gasLimit,
|
|
8668
|
+
minimalPriorityTxL2Gas({
|
|
8669
|
+
calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
|
|
8670
|
+
gasPerPubdata: input.gasPerPubdata
|
|
8671
|
+
})
|
|
8672
|
+
);
|
|
8673
|
+
}
|
|
8674
|
+
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
8675
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
8676
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
8677
|
+
}
|
|
8678
|
+
const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
|
|
8679
|
+
return maxBigInt2(
|
|
8680
|
+
input.priorityFloorGasLimit,
|
|
8681
|
+
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
8682
|
+
);
|
|
8683
|
+
}
|
|
8684
|
+
|
|
8280
8685
|
// src/adapters/ethers/resources/deposits/services/gas.ts
|
|
8281
8686
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
8282
8687
|
var ZERO_L2_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
8688
|
+
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
8689
|
+
if (!leg) return void 0;
|
|
8690
|
+
try {
|
|
8691
|
+
return await ethersToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
|
|
8692
|
+
} catch {
|
|
8693
|
+
return void 0;
|
|
8694
|
+
}
|
|
8695
|
+
}
|
|
8283
8696
|
async function quoteL1Gas2(input) {
|
|
8284
8697
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
8285
8698
|
const estimator = ethersToGasEstimator(ctx.client.l1);
|
|
@@ -8333,7 +8746,12 @@ async function determineNonBaseL2Gas(input) {
|
|
|
8333
8746
|
return quoteL2Gas2({
|
|
8334
8747
|
ctx,
|
|
8335
8748
|
route,
|
|
8336
|
-
overrideGasLimit:
|
|
8749
|
+
overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
|
|
8750
|
+
chainIdL2: ctx.chainIdL2,
|
|
8751
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
8752
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
8753
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
|
|
8754
|
+
})
|
|
8337
8755
|
});
|
|
8338
8756
|
}
|
|
8339
8757
|
const modelTx = {
|
|
@@ -8370,6 +8788,7 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
8370
8788
|
knownL2Token: input.ctx.resolvedToken?.l2,
|
|
8371
8789
|
modelTx: input.modelTx,
|
|
8372
8790
|
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
8791
|
+
priorityTxL2Leg: input.priorityTxL2Leg,
|
|
8373
8792
|
undeployedGasLimit: input.undeployedGasLimit
|
|
8374
8793
|
});
|
|
8375
8794
|
}
|
|
@@ -8401,40 +8820,6 @@ function buildFeeBreakdown(p) {
|
|
|
8401
8820
|
l2
|
|
8402
8821
|
};
|
|
8403
8822
|
}
|
|
8404
|
-
|
|
8405
|
-
// src/core/resources/deposits/priority.ts
|
|
8406
|
-
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
8407
|
-
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
8408
|
-
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
8409
|
-
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
8410
|
-
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
8411
|
-
function derivePriorityTxGasBreakdown(input) {
|
|
8412
|
-
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
8413
|
-
const minBodyGas = maxBigInt2(
|
|
8414
|
-
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
8415
|
-
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
8416
|
-
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
8417
|
-
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
8418
|
-
L1_TX_MIN_L2_GAS_BASE
|
|
8419
|
-
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
8420
|
-
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
8421
|
-
const derivedBodyGas = minBodyGas;
|
|
8422
|
-
return {
|
|
8423
|
-
encodedLength: input.encodedLength,
|
|
8424
|
-
minBodyGas,
|
|
8425
|
-
overhead,
|
|
8426
|
-
derivedBodyGas,
|
|
8427
|
-
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
8428
|
-
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
8429
|
-
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
8430
|
-
};
|
|
8431
|
-
}
|
|
8432
|
-
function derivePriorityBodyGasEstimateCap(input) {
|
|
8433
|
-
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
8434
|
-
}
|
|
8435
|
-
function applyPriorityL2GasLimitBuffer(input) {
|
|
8436
|
-
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
8437
|
-
}
|
|
8438
8823
|
var EMPTY_BYTES = "0x";
|
|
8439
8824
|
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
8440
8825
|
var L2_CANONICAL_TRANSACTION_TUPLE = "tuple(uint256 txType,uint256 from,uint256 to,uint256 gasLimit,uint256 gasPerPubdataByteLimit,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,uint256 paymaster,uint256 nonce,uint256 value,uint256[4] reserved,bytes data,bytes signature,uint256[] factoryDeps,bytes paymasterInput,bytes reservedDynamic)";
|
|
@@ -8491,9 +8876,13 @@ function routeEthDirect() {
|
|
|
8491
8876
|
l2Calldata,
|
|
8492
8877
|
gasPerPubdata: ctx.gasPerPubdata
|
|
8493
8878
|
});
|
|
8494
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
8495
|
-
|
|
8496
|
-
|
|
8879
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
8880
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
8881
|
+
chainIdL2: ctx.chainIdL2,
|
|
8882
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
8883
|
+
}),
|
|
8884
|
+
l2Calldata,
|
|
8885
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
8497
8886
|
});
|
|
8498
8887
|
const l2GasParams = await quoteL2Gas2({
|
|
8499
8888
|
ctx,
|
|
@@ -8580,26 +8969,18 @@ var ntvCodec = createNTVCodec({
|
|
|
8580
8969
|
keccak256: (data) => ethers.keccak256(data)
|
|
8581
8970
|
});
|
|
8582
8971
|
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
const { chainId } = await input.ctx.client.l1.getNetwork();
|
|
8587
|
-
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
8588
|
-
BigInt(chainId),
|
|
8972
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
8973
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
|
|
8974
|
+
BigInt((await input.ctx.client.l1.getNetwork()).chainId),
|
|
8589
8975
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
8590
8976
|
input.token
|
|
8591
8977
|
);
|
|
8592
|
-
const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
|
|
8593
|
-
const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
|
|
8594
|
-
if (isL1Origin) {
|
|
8595
|
-
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
8596
|
-
}
|
|
8597
8978
|
const transferData = encodeNativeTokenVaultTransferData(
|
|
8598
8979
|
input.amount,
|
|
8599
8980
|
input.receiver,
|
|
8600
8981
|
input.token
|
|
8601
8982
|
);
|
|
8602
|
-
return encodeSecondBridgeDataV1(
|
|
8983
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
8603
8984
|
}
|
|
8604
8985
|
async function getPriorityGasModel(input) {
|
|
8605
8986
|
try {
|
|
@@ -8634,9 +9015,18 @@ async function getPriorityGasModel(input) {
|
|
|
8634
9015
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8635
9016
|
});
|
|
8636
9017
|
const model = {
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
9018
|
+
priorityTxL2Leg: {
|
|
9019
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
9020
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
9021
|
+
data: l2Calldata
|
|
9022
|
+
},
|
|
9023
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
9024
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
9025
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
9026
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
9027
|
+
}),
|
|
9028
|
+
l2Calldata,
|
|
9029
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8640
9030
|
})
|
|
8641
9031
|
};
|
|
8642
9032
|
if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS2) {
|
|
@@ -8694,6 +9084,7 @@ function routeErc20NonBase() {
|
|
|
8694
9084
|
ctx,
|
|
8695
9085
|
l1Token: p.token,
|
|
8696
9086
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
9087
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
8697
9088
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit,
|
|
8698
9089
|
modelTx: {
|
|
8699
9090
|
to: receiver,
|
|
@@ -8708,25 +9099,29 @@ function routeErc20NonBase() {
|
|
|
8708
9099
|
const approvals = [];
|
|
8709
9100
|
const steps = [];
|
|
8710
9101
|
const assetRouter = ctx.l1AssetRouter;
|
|
9102
|
+
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
8711
9103
|
const erc20Deposit = new ethers.Contract(p.token, IERC20_default, l1Signer);
|
|
8712
9104
|
const allowanceToken = await wrapAs3(
|
|
8713
9105
|
"RPC",
|
|
8714
9106
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
8715
|
-
() => erc20Deposit.allowance(ctx.sender,
|
|
9107
|
+
() => erc20Deposit.allowance(ctx.sender, nativeTokenVault),
|
|
8716
9108
|
{
|
|
8717
|
-
ctx: { where: "erc20.allowance", token: p.token, spender:
|
|
9109
|
+
ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
|
|
8718
9110
|
message: "Failed to read deposit-token allowance."
|
|
8719
9111
|
}
|
|
8720
9112
|
);
|
|
8721
9113
|
if (allowanceToken < p.amount) {
|
|
8722
|
-
approvals.push({ token: p.token, spender:
|
|
9114
|
+
approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
|
|
8723
9115
|
steps.push({
|
|
8724
|
-
key: `approve:${p.token}:${
|
|
9116
|
+
key: `approve:${p.token}:${nativeTokenVault}`,
|
|
8725
9117
|
kind: "approve",
|
|
8726
|
-
description: `Approve ${p.amount} for
|
|
9118
|
+
description: `Approve ${p.amount} for the native token vault (deposit token)`,
|
|
8727
9119
|
tx: {
|
|
8728
9120
|
to: p.token,
|
|
8729
|
-
data: erc20Deposit.interface.encodeFunctionData("approve", [
|
|
9121
|
+
data: erc20Deposit.interface.encodeFunctionData("approve", [
|
|
9122
|
+
nativeTokenVault,
|
|
9123
|
+
p.amount
|
|
9124
|
+
]),
|
|
8730
9125
|
from: ctx.sender,
|
|
8731
9126
|
...ctx.gasOverrides
|
|
8732
9127
|
}
|
|
@@ -8737,21 +9132,24 @@ function routeErc20NonBase() {
|
|
|
8737
9132
|
const allowanceBase = await wrapAs3(
|
|
8738
9133
|
"RPC",
|
|
8739
9134
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
8740
|
-
() => erc20Base.allowance(ctx.sender,
|
|
9135
|
+
() => erc20Base.allowance(ctx.sender, nativeTokenVault),
|
|
8741
9136
|
{
|
|
8742
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender:
|
|
9137
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
|
|
8743
9138
|
message: "Failed to read base-token allowance."
|
|
8744
9139
|
}
|
|
8745
9140
|
);
|
|
8746
9141
|
if (allowanceBase < mintValue) {
|
|
8747
|
-
approvals.push({ token: baseToken, spender:
|
|
9142
|
+
approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
|
|
8748
9143
|
steps.push({
|
|
8749
|
-
key: `approve:${baseToken}:${
|
|
9144
|
+
key: `approve:${baseToken}:${nativeTokenVault}`,
|
|
8750
9145
|
kind: "approve",
|
|
8751
9146
|
description: `Approve base token for mintValue`,
|
|
8752
9147
|
tx: {
|
|
8753
9148
|
to: baseToken,
|
|
8754
|
-
data: erc20Base.interface.encodeFunctionData("approve", [
|
|
9149
|
+
data: erc20Base.interface.encodeFunctionData("approve", [
|
|
9150
|
+
nativeTokenVault,
|
|
9151
|
+
mintValue
|
|
9152
|
+
]),
|
|
8755
9153
|
from: ctx.sender,
|
|
8756
9154
|
...ctx.gasOverrides
|
|
8757
9155
|
}
|
|
@@ -8848,9 +9246,18 @@ async function getPriorityGasModel2(input) {
|
|
|
8848
9246
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8849
9247
|
});
|
|
8850
9248
|
const model = {
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
9249
|
+
priorityTxL2Leg: {
|
|
9250
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
9251
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
9252
|
+
data: l2Calldata
|
|
9253
|
+
},
|
|
9254
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
9255
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
9256
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
9257
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
9258
|
+
}),
|
|
9259
|
+
l2Calldata,
|
|
9260
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8854
9261
|
})
|
|
8855
9262
|
};
|
|
8856
9263
|
if (input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS3) {
|
|
@@ -8927,6 +9334,7 @@ function routeEthNonBase() {
|
|
|
8927
9334
|
ctx,
|
|
8928
9335
|
modelTx: l2TxModel,
|
|
8929
9336
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
9337
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
8930
9338
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
8931
9339
|
});
|
|
8932
9340
|
if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
|
|
@@ -8938,21 +9346,24 @@ function routeEthNonBase() {
|
|
|
8938
9346
|
const allowance = await wrapAs4(
|
|
8939
9347
|
"RPC",
|
|
8940
9348
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
8941
|
-
() => erc20Base.allowance(ctx.sender, ctx.
|
|
9349
|
+
() => erc20Base.allowance(ctx.sender, ctx.l1NativeTokenVault),
|
|
8942
9350
|
{
|
|
8943
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
9351
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
8944
9352
|
message: "Failed to read base-token allowance."
|
|
8945
9353
|
}
|
|
8946
9354
|
);
|
|
8947
9355
|
if (allowance < mintValue) {
|
|
8948
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
9356
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
8949
9357
|
steps.push({
|
|
8950
|
-
key: `approve:${baseToken}:${ctx.
|
|
9358
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
8951
9359
|
kind: "approve",
|
|
8952
9360
|
description: `Approve base token for fees (mintValue)`,
|
|
8953
9361
|
tx: {
|
|
8954
9362
|
to: baseToken,
|
|
8955
|
-
data: erc20Base.interface.encodeFunctionData("approve", [
|
|
9363
|
+
data: erc20Base.interface.encodeFunctionData("approve", [
|
|
9364
|
+
ctx.l1NativeTokenVault,
|
|
9365
|
+
mintValue
|
|
9366
|
+
]),
|
|
8956
9367
|
from: ctx.sender,
|
|
8957
9368
|
...ctx.gasOverrides
|
|
8958
9369
|
}
|
|
@@ -9068,9 +9479,13 @@ function routeErc20Base() {
|
|
|
9068
9479
|
l2Calldata,
|
|
9069
9480
|
gasPerPubdata: ctx.gasPerPubdata
|
|
9070
9481
|
});
|
|
9071
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
9072
|
-
|
|
9073
|
-
|
|
9482
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
9483
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
9484
|
+
chainIdL2: ctx.chainIdL2,
|
|
9485
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
9486
|
+
}),
|
|
9487
|
+
l2Calldata,
|
|
9488
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
9074
9489
|
});
|
|
9075
9490
|
const l2GasParams = await quoteL2Gas2({
|
|
9076
9491
|
ctx,
|
|
@@ -9087,21 +9502,24 @@ function routeErc20Base() {
|
|
|
9087
9502
|
const allowance = await wrapAs5(
|
|
9088
9503
|
"RPC",
|
|
9089
9504
|
OP_DEPOSITS.base.allowance,
|
|
9090
|
-
() => erc20.allowance(ctx.sender, ctx.
|
|
9505
|
+
() => erc20.allowance(ctx.sender, ctx.l1NativeTokenVault),
|
|
9091
9506
|
{
|
|
9092
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
9507
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
9093
9508
|
message: "Failed to read base-token allowance."
|
|
9094
9509
|
}
|
|
9095
9510
|
);
|
|
9096
9511
|
if (allowance < mintValue) {
|
|
9097
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
9512
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
9098
9513
|
steps.push({
|
|
9099
|
-
key: `approve:${baseToken}:${ctx.
|
|
9514
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
9100
9515
|
kind: "approve",
|
|
9101
9516
|
description: "Approve base token for mintValue",
|
|
9102
9517
|
tx: {
|
|
9103
9518
|
to: baseToken,
|
|
9104
|
-
data: erc20.interface.encodeFunctionData("approve", [
|
|
9519
|
+
data: erc20.interface.encodeFunctionData("approve", [
|
|
9520
|
+
ctx.l1NativeTokenVault,
|
|
9521
|
+
mintValue
|
|
9522
|
+
]),
|
|
9105
9523
|
from: ctx.sender,
|
|
9106
9524
|
...ctx.gasOverrides
|
|
9107
9525
|
}
|
|
@@ -9235,8 +9653,17 @@ function createTokensResource(client) {
|
|
|
9235
9653
|
const { chainId } = await client.l2.getNetwork();
|
|
9236
9654
|
return await client.baseToken(BigInt(chainId));
|
|
9237
9655
|
}
|
|
9238
|
-
const {
|
|
9239
|
-
const
|
|
9656
|
+
const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
|
|
9657
|
+
const assetId = await l2NativeTokenVault.assetId(l2Token);
|
|
9658
|
+
if (BigInt(assetId) === 0n) {
|
|
9659
|
+
throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
|
|
9660
|
+
}
|
|
9661
|
+
const l1Token = await l1NativeTokenVault.tokenAddress(assetId);
|
|
9662
|
+
if (BigInt(l1Token) === 0n) {
|
|
9663
|
+
throw new Error(
|
|
9664
|
+
`Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
|
|
9665
|
+
);
|
|
9666
|
+
}
|
|
9240
9667
|
return l1Token;
|
|
9241
9668
|
});
|
|
9242
9669
|
}
|
|
@@ -9744,7 +10171,7 @@ function pickWithdrawRoute(args) {
|
|
|
9744
10171
|
}
|
|
9745
10172
|
|
|
9746
10173
|
// src/adapters/ethers/resources/withdrawals/context.ts
|
|
9747
|
-
async function commonCtx2(p, client, tokens, contracts) {
|
|
10174
|
+
async function commonCtx2(p, client, tokens, contracts, protocol) {
|
|
9748
10175
|
const sender = await client.signer.getAddress();
|
|
9749
10176
|
const {
|
|
9750
10177
|
bridgehub,
|
|
@@ -9752,10 +10179,12 @@ async function commonCtx2(p, client, tokens, contracts) {
|
|
|
9752
10179
|
l1Nullifier,
|
|
9753
10180
|
l2AssetRouter,
|
|
9754
10181
|
l2NativeTokenVault,
|
|
9755
|
-
l2BaseTokenSystem
|
|
10182
|
+
l2BaseTokenSystem,
|
|
10183
|
+
interopCenter
|
|
9756
10184
|
} = await contracts.addresses();
|
|
9757
10185
|
const { chainId } = await client.l2.getNetwork();
|
|
9758
10186
|
const chainIdL2 = BigInt(chainId);
|
|
10187
|
+
const l1ChainId = BigInt((await client.l1.getNetwork()).chainId);
|
|
9759
10188
|
const resolvedToken = await tokens.resolve(p.token, { chain: "l2" });
|
|
9760
10189
|
const baseTokenAssetId = resolvedToken.baseTokenAssetId;
|
|
9761
10190
|
const baseTokenL1 = await tokens.l1TokenFromAssetId(baseTokenAssetId);
|
|
@@ -9777,6 +10206,9 @@ async function commonCtx2(p, client, tokens, contracts) {
|
|
|
9777
10206
|
l2AssetRouter,
|
|
9778
10207
|
l2NativeTokenVault,
|
|
9779
10208
|
l2BaseTokenSystem,
|
|
10209
|
+
interopCenter,
|
|
10210
|
+
protocol,
|
|
10211
|
+
l1ChainId,
|
|
9780
10212
|
baseIsEth,
|
|
9781
10213
|
gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
|
|
9782
10214
|
};
|
|
@@ -10013,7 +10445,269 @@ function routeErc20NonBase2() {
|
|
|
10013
10445
|
});
|
|
10014
10446
|
const fees = buildFeeBreakdown2({
|
|
10015
10447
|
feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
|
|
10016
|
-
l2Gas: withdrawGas
|
|
10448
|
+
l2Gas: withdrawGas
|
|
10449
|
+
});
|
|
10450
|
+
return { steps, approvals, fees };
|
|
10451
|
+
}
|
|
10452
|
+
};
|
|
10453
|
+
}
|
|
10454
|
+
var PREFIX_EVM_CHAIN = ethers.getBytes("0x00010000");
|
|
10455
|
+
var PREFIX_EVM_ADDRESS = ethers.getBytes("0x000100000014");
|
|
10456
|
+
function formatInteropEvmChain(chainId) {
|
|
10457
|
+
const chainRef = ethers.toBeArray(chainId);
|
|
10458
|
+
const chainRefLength = ethers.getBytes(ethers.toBeHex(chainRef.length, 1));
|
|
10459
|
+
const payload = ethers.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
|
|
10460
|
+
return ethers.hexlify(payload);
|
|
10461
|
+
}
|
|
10462
|
+
function formatInteropEvmAddress(address) {
|
|
10463
|
+
const normalized = ethers.getAddress(address);
|
|
10464
|
+
const addrBytes = ethers.getBytes(normalized);
|
|
10465
|
+
const payload = ethers.concat([PREFIX_EVM_ADDRESS, addrBytes]);
|
|
10466
|
+
return ethers.hexlify(payload);
|
|
10467
|
+
}
|
|
10468
|
+
var interopCodec = {
|
|
10469
|
+
formatChain: formatInteropEvmChain,
|
|
10470
|
+
formatAddress: formatInteropEvmAddress
|
|
10471
|
+
};
|
|
10472
|
+
|
|
10473
|
+
// src/core/resources/interop/attributes/call.ts
|
|
10474
|
+
function createCallAttributes(codec) {
|
|
10475
|
+
const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
|
|
10476
|
+
const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
|
|
10477
|
+
return {
|
|
10478
|
+
indirectCall,
|
|
10479
|
+
interopCallValue
|
|
10480
|
+
};
|
|
10481
|
+
}
|
|
10482
|
+
|
|
10483
|
+
// src/core/resources/interop/attributes/bundle.ts
|
|
10484
|
+
function createBundleAttributes(codec) {
|
|
10485
|
+
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
10486
|
+
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
10487
|
+
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
10488
|
+
const interopBundleSalt = (salt) => codec.encode("interopBundleSalt", [salt]);
|
|
10489
|
+
return {
|
|
10490
|
+
executionAddress,
|
|
10491
|
+
unbundlerAddress,
|
|
10492
|
+
useFixedFee,
|
|
10493
|
+
interopBundleSalt
|
|
10494
|
+
};
|
|
10495
|
+
}
|
|
10496
|
+
|
|
10497
|
+
// src/core/resources/interop/attributes/resource.ts
|
|
10498
|
+
function createAttributesResource(codec) {
|
|
10499
|
+
return {
|
|
10500
|
+
call: createCallAttributes(codec),
|
|
10501
|
+
bundle: createBundleAttributes(codec)
|
|
10502
|
+
};
|
|
10503
|
+
}
|
|
10504
|
+
|
|
10505
|
+
// src/adapters/ethers/resources/interop/attributes/resource.ts
|
|
10506
|
+
function getInteropAttributes(params, ctx) {
|
|
10507
|
+
const bundleAttributes = [];
|
|
10508
|
+
if (params.execution?.only) {
|
|
10509
|
+
bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
|
|
10510
|
+
}
|
|
10511
|
+
if (params.unbundling?.by) {
|
|
10512
|
+
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
10513
|
+
}
|
|
10514
|
+
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
10515
|
+
const callAttributes = params.actions.map((action) => {
|
|
10516
|
+
switch (action.type) {
|
|
10517
|
+
case "sendNative": {
|
|
10518
|
+
const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
|
|
10519
|
+
if (baseMatches) {
|
|
10520
|
+
return [ctx.attributes.call.interopCallValue(action.amount)];
|
|
10521
|
+
}
|
|
10522
|
+
return [ctx.attributes.call.indirectCall(action.amount)];
|
|
10523
|
+
}
|
|
10524
|
+
case "call":
|
|
10525
|
+
if (action.value && action.value > 0n) {
|
|
10526
|
+
return [ctx.attributes.call.interopCallValue(action.value)];
|
|
10527
|
+
}
|
|
10528
|
+
return [];
|
|
10529
|
+
case "sendErc20":
|
|
10530
|
+
return [ctx.attributes.call.indirectCall(0n)];
|
|
10531
|
+
default:
|
|
10532
|
+
assertNever(action);
|
|
10533
|
+
}
|
|
10534
|
+
});
|
|
10535
|
+
return { bundleAttributes, callAttributes };
|
|
10536
|
+
}
|
|
10537
|
+
function createEthersAttributesResource(opts = {}) {
|
|
10538
|
+
const iface = opts.iface ?? new ethers.Interface(IERC7786Attributes_default);
|
|
10539
|
+
const encode2 = (fn, args) => iface.encodeFunctionData(fn, args);
|
|
10540
|
+
return createAttributesResource({ encode: encode2 });
|
|
10541
|
+
}
|
|
10542
|
+
|
|
10543
|
+
// src/core/resources/withdrawals/bundle.ts
|
|
10544
|
+
function buildWithdrawalBundle(input) {
|
|
10545
|
+
const {
|
|
10546
|
+
assetId,
|
|
10547
|
+
amount,
|
|
10548
|
+
l1Receiver,
|
|
10549
|
+
l2Token,
|
|
10550
|
+
isBaseToken,
|
|
10551
|
+
l1ChainId,
|
|
10552
|
+
l2AssetRouter,
|
|
10553
|
+
salt,
|
|
10554
|
+
codec,
|
|
10555
|
+
attributes: attributes2,
|
|
10556
|
+
transferData
|
|
10557
|
+
} = input;
|
|
10558
|
+
const burnData = transferData.encodeBridgeBurnData(amount, l1Receiver, l2Token);
|
|
10559
|
+
const depositData = transferData.encodeAssetRouterDepositData(assetId, burnData);
|
|
10560
|
+
const indirectCallMessageValue = isBaseToken ? amount : 0n;
|
|
10561
|
+
const starter = [
|
|
10562
|
+
codec.formatAddress(l2AssetRouter),
|
|
10563
|
+
depositData,
|
|
10564
|
+
[attributes2.indirectCall(indirectCallMessageValue), attributes2.interopCallValue(0n)]
|
|
10565
|
+
];
|
|
10566
|
+
return {
|
|
10567
|
+
destinationChain: codec.formatChain(l1ChainId),
|
|
10568
|
+
starters: [starter],
|
|
10569
|
+
// No `atomicBundle` attribute: L2 -> L1 withdrawals are non-atomic and are published to L1 as a
|
|
10570
|
+
// `BUNDLE_IDENTIFIER`-prefixed message, which is what the L1 handler proves inclusion of.
|
|
10571
|
+
bundleAttributes: [attributes2.interopBundleSalt(salt)],
|
|
10572
|
+
value: indirectCallMessageValue
|
|
10573
|
+
};
|
|
10574
|
+
}
|
|
10575
|
+
|
|
10576
|
+
// src/adapters/ethers/resources/withdrawals/routes/interop-bundle.ts
|
|
10577
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
10578
|
+
var attributes = createEthersAttributesResource();
|
|
10579
|
+
function saltFor(sender, nonce) {
|
|
10580
|
+
return ethers.keccak256(
|
|
10581
|
+
ethers.AbiCoder.defaultAbiCoder().encode(["address", "uint256"], [sender, BigInt(nonce)])
|
|
10582
|
+
);
|
|
10583
|
+
}
|
|
10584
|
+
function routeInteropBundle() {
|
|
10585
|
+
return {
|
|
10586
|
+
async build(p, ctx) {
|
|
10587
|
+
const steps = [];
|
|
10588
|
+
const approvals = [];
|
|
10589
|
+
const isBaseToken = ctx.route === "base";
|
|
10590
|
+
const l1Receiver = p.to ?? ctx.sender;
|
|
10591
|
+
let assetId;
|
|
10592
|
+
let allowanceSufficient = true;
|
|
10593
|
+
if (isBaseToken) {
|
|
10594
|
+
assetId = ctx.baseTokenAssetId;
|
|
10595
|
+
} else {
|
|
10596
|
+
assetId = await wrapAs9(
|
|
10597
|
+
"CONTRACT",
|
|
10598
|
+
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10599
|
+
async () => {
|
|
10600
|
+
const ntv = await ctx.contracts.l2NativeTokenVault();
|
|
10601
|
+
return await ntv.getFunction("ensureTokenIsRegistered").staticCall(p.token);
|
|
10602
|
+
},
|
|
10603
|
+
{
|
|
10604
|
+
ctx: { where: "L2NativeTokenVault.ensureTokenIsRegistered", token: p.token },
|
|
10605
|
+
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
10606
|
+
}
|
|
10607
|
+
);
|
|
10608
|
+
const erc20 = new ethers.Contract(p.token, IERC20_default, ctx.client.l2);
|
|
10609
|
+
const current = await wrapAs9(
|
|
10610
|
+
"CONTRACT",
|
|
10611
|
+
OP_WITHDRAWALS.erc20.allowance,
|
|
10612
|
+
() => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
|
|
10613
|
+
{
|
|
10614
|
+
ctx: {
|
|
10615
|
+
where: "erc20.allowance",
|
|
10616
|
+
chain: "L2",
|
|
10617
|
+
token: p.token,
|
|
10618
|
+
spender: ctx.l2NativeTokenVault
|
|
10619
|
+
},
|
|
10620
|
+
message: "Failed to read L2 ERC-20 allowance."
|
|
10621
|
+
}
|
|
10622
|
+
);
|
|
10623
|
+
allowanceSufficient = current >= p.amount;
|
|
10624
|
+
if (!allowanceSufficient) {
|
|
10625
|
+
approvals.push({ token: p.token, spender: ctx.l2NativeTokenVault, amount: p.amount });
|
|
10626
|
+
const approveTx = {
|
|
10627
|
+
to: p.token,
|
|
10628
|
+
data: erc20.interface.encodeFunctionData("approve", [ctx.l2NativeTokenVault, p.amount]),
|
|
10629
|
+
from: ctx.sender
|
|
10630
|
+
};
|
|
10631
|
+
const approveGas = await quoteL2Gas4({ ctx, tx: approveTx });
|
|
10632
|
+
if (approveGas) {
|
|
10633
|
+
approveTx.gasLimit = approveGas.gasLimit;
|
|
10634
|
+
approveTx.maxFeePerGas = approveGas.maxFeePerGas;
|
|
10635
|
+
approveTx.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
10636
|
+
}
|
|
10637
|
+
steps.push({
|
|
10638
|
+
key: `approve:l2:${p.token}:${ctx.l2NativeTokenVault}`,
|
|
10639
|
+
kind: "approve:l2",
|
|
10640
|
+
description: `Approve ${p.amount} to NativeTokenVault`,
|
|
10641
|
+
tx: approveTx
|
|
10642
|
+
});
|
|
10643
|
+
}
|
|
10644
|
+
}
|
|
10645
|
+
const nonce = await wrapAs9(
|
|
10646
|
+
"RPC",
|
|
10647
|
+
OP_WITHDRAWALS.prepare,
|
|
10648
|
+
() => ctx.client.l2.getTransactionCount(ctx.sender, "pending"),
|
|
10649
|
+
{
|
|
10650
|
+
ctx: { where: "l2.getTransactionCount", sender: ctx.sender },
|
|
10651
|
+
message: "Failed to read L2 nonce for the interop bundle salt."
|
|
10652
|
+
}
|
|
10653
|
+
);
|
|
10654
|
+
const bundle = buildWithdrawalBundle({
|
|
10655
|
+
assetId,
|
|
10656
|
+
amount: p.amount,
|
|
10657
|
+
l1Receiver,
|
|
10658
|
+
l2Token: isBaseToken ? FORMAL_ETH_ADDRESS : p.token,
|
|
10659
|
+
isBaseToken,
|
|
10660
|
+
l1ChainId: ctx.l1ChainId,
|
|
10661
|
+
l2AssetRouter: ctx.l2AssetRouter,
|
|
10662
|
+
salt: saltFor(ctx.sender, nonce),
|
|
10663
|
+
codec: interopCodec,
|
|
10664
|
+
attributes: {
|
|
10665
|
+
indirectCall: attributes.call.indirectCall,
|
|
10666
|
+
interopCallValue: attributes.call.interopCallValue,
|
|
10667
|
+
interopBundleSalt: attributes.bundle.interopBundleSalt
|
|
10668
|
+
},
|
|
10669
|
+
transferData: {
|
|
10670
|
+
encodeBridgeBurnData: (amount, receiver, token) => encodeNativeTokenVaultTransferData(amount, receiver, token),
|
|
10671
|
+
encodeAssetRouterDepositData: (id, data2) => encodeSecondBridgeDataV1(id, data2)
|
|
10672
|
+
}
|
|
10673
|
+
});
|
|
10674
|
+
const interopCenter = await ctx.contracts.interopCenter();
|
|
10675
|
+
const data = await wrapAs9(
|
|
10676
|
+
"INTERNAL",
|
|
10677
|
+
OP_WITHDRAWALS.erc20.encodeWithdraw,
|
|
10678
|
+
() => Promise.resolve(
|
|
10679
|
+
interopCenter.interface.encodeFunctionData("sendBundle", [
|
|
10680
|
+
bundle.destinationChain,
|
|
10681
|
+
bundle.starters,
|
|
10682
|
+
bundle.bundleAttributes
|
|
10683
|
+
])
|
|
10684
|
+
),
|
|
10685
|
+
{
|
|
10686
|
+
ctx: { where: "InteropCenter.sendBundle", assetId },
|
|
10687
|
+
message: "Failed to encode sendBundle calldata."
|
|
10688
|
+
}
|
|
10689
|
+
);
|
|
10690
|
+
const sendTx = {
|
|
10691
|
+
to: ctx.interopCenter,
|
|
10692
|
+
data,
|
|
10693
|
+
from: ctx.sender,
|
|
10694
|
+
value: bundle.value
|
|
10695
|
+
};
|
|
10696
|
+
const sendGas = allowanceSufficient ? await quoteL2Gas4({ ctx, tx: sendTx }) : void 0;
|
|
10697
|
+
if (sendGas) {
|
|
10698
|
+
sendTx.gasLimit = sendGas.gasLimit;
|
|
10699
|
+
sendTx.maxFeePerGas = sendGas.maxFeePerGas;
|
|
10700
|
+
sendTx.maxPriorityFeePerGas = sendGas.maxPriorityFeePerGas;
|
|
10701
|
+
}
|
|
10702
|
+
steps.push({
|
|
10703
|
+
key: "interop-center:send-bundle",
|
|
10704
|
+
kind: "interop-center:send-bundle",
|
|
10705
|
+
description: "Burn on L2 & send L2\u2192L1 withdrawal bundle",
|
|
10706
|
+
tx: sendTx
|
|
10707
|
+
});
|
|
10708
|
+
const fees = buildFeeBreakdown2({
|
|
10709
|
+
feeToken: ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2),
|
|
10710
|
+
l2Gas: sendGas
|
|
10017
10711
|
});
|
|
10018
10712
|
return { steps, approvals, fees };
|
|
10019
10713
|
}
|
|
@@ -10067,176 +10761,379 @@ function messengerLogIndex(raw, opts) {
|
|
|
10067
10761
|
}
|
|
10068
10762
|
return (hits[index] ?? hits[0]).i;
|
|
10069
10763
|
}
|
|
10764
|
+
function keccakHex(data) {
|
|
10765
|
+
return `0x${utils.bytesToHex(sha3.keccak_256(utils.hexToBytes(data.slice(2))))}`;
|
|
10766
|
+
}
|
|
10767
|
+
function stripBundleIdentifier(messageData) {
|
|
10768
|
+
const prefix = `0x${messageData.slice(2, 4)}`;
|
|
10769
|
+
if (prefix !== BUNDLE_IDENTIFIER) {
|
|
10770
|
+
throw createError("STATE", {
|
|
10771
|
+
resource: "withdrawals",
|
|
10772
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
10773
|
+
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.",
|
|
10774
|
+
context: { prefix, expected: BUNDLE_IDENTIFIER }
|
|
10775
|
+
});
|
|
10776
|
+
}
|
|
10777
|
+
return `0x${messageData.slice(4)}`;
|
|
10778
|
+
}
|
|
10779
|
+
function parseBundleHashFromLogs(logs, interopCenter = L2_INTEROP_CENTER_ADDRESS) {
|
|
10780
|
+
const center = interopCenter.toLowerCase();
|
|
10781
|
+
for (const log of logs) {
|
|
10782
|
+
if (log.address?.toLowerCase() !== center) continue;
|
|
10783
|
+
if (log.topics?.length !== 1) continue;
|
|
10784
|
+
if (!log.data || (log.data.length - 2) / 64 < 3) continue;
|
|
10785
|
+
return `0x${log.data.slice(66, 130)}`;
|
|
10786
|
+
}
|
|
10787
|
+
return void 0;
|
|
10788
|
+
}
|
|
10789
|
+
function buildWithdrawalFinalization(input) {
|
|
10790
|
+
const { messageData, sourceChainId, txNumberInBatch, proof } = input;
|
|
10791
|
+
const bundle = stripBundleIdentifier(messageData);
|
|
10792
|
+
return {
|
|
10793
|
+
bundle,
|
|
10794
|
+
bundleHash: input.bundleHash ?? keccakHex(bundle),
|
|
10795
|
+
proof: {
|
|
10796
|
+
chainId: sourceChainId,
|
|
10797
|
+
l1BatchNumber: proof.batchNumber,
|
|
10798
|
+
l2MessageIndex: proof.id,
|
|
10799
|
+
message: {
|
|
10800
|
+
txNumberInBatch,
|
|
10801
|
+
sender: input.interopCenter ?? L2_INTEROP_CENTER_ADDRESS,
|
|
10802
|
+
data: messageData
|
|
10803
|
+
},
|
|
10804
|
+
proof: proof.proof
|
|
10805
|
+
}
|
|
10806
|
+
};
|
|
10807
|
+
}
|
|
10808
|
+
function classifyWithdrawalOutcome(bundleStatus, callStatus) {
|
|
10809
|
+
if (bundleStatus === 2 /* FullyExecuted */) return "finalized";
|
|
10810
|
+
if (bundleStatus !== 3 /* Unbundled */) return "pending";
|
|
10811
|
+
switch (callStatus) {
|
|
10812
|
+
case 1 /* Executed */:
|
|
10813
|
+
return "finalized";
|
|
10814
|
+
case 2 /* Cancelled */:
|
|
10815
|
+
return "failed";
|
|
10816
|
+
default:
|
|
10817
|
+
return "pending";
|
|
10818
|
+
}
|
|
10819
|
+
}
|
|
10820
|
+
|
|
10821
|
+
// src/core/resources/withdrawals/protocol.ts
|
|
10822
|
+
var MIN_INTEROP_WITHDRAWAL_MINOR = 32;
|
|
10823
|
+
function protocolFromVersion(version) {
|
|
10824
|
+
const [, minor] = version;
|
|
10825
|
+
return minor >= MIN_INTEROP_WITHDRAWAL_MINOR ? "interop-bundle" : "legacy-withdrawal";
|
|
10826
|
+
}
|
|
10827
|
+
async function detectWithdrawalProtocol(probes, override) {
|
|
10828
|
+
if (override) {
|
|
10829
|
+
return { protocol: override, source: { via: "override" } };
|
|
10830
|
+
}
|
|
10831
|
+
const version = await probes.protocolVersion();
|
|
10832
|
+
if (version) {
|
|
10833
|
+
return { protocol: protocolFromVersion(version), source: { via: "protocol-version", version } };
|
|
10834
|
+
}
|
|
10835
|
+
if (await probes.hasCodeAt(L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS)) {
|
|
10836
|
+
return {
|
|
10837
|
+
protocol: "interop-bundle",
|
|
10838
|
+
source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
|
|
10839
|
+
};
|
|
10840
|
+
}
|
|
10841
|
+
return {
|
|
10842
|
+
protocol: "legacy-withdrawal",
|
|
10843
|
+
source: { via: "code-probe", address: L2_INTEROP_ATTRIBUTE_PARSER_ADDRESS }
|
|
10844
|
+
};
|
|
10845
|
+
}
|
|
10846
|
+
|
|
10847
|
+
// src/adapters/ethers/resources/withdrawals/services/protocol.ts
|
|
10848
|
+
function createWithdrawalProtocolService(client, override) {
|
|
10849
|
+
let cached;
|
|
10850
|
+
async function hasCodeAt(address) {
|
|
10851
|
+
try {
|
|
10852
|
+
const code = await client.l2.getCode(address);
|
|
10853
|
+
return !!code && code !== "0x";
|
|
10854
|
+
} catch {
|
|
10855
|
+
return false;
|
|
10856
|
+
}
|
|
10857
|
+
}
|
|
10858
|
+
async function protocolVersion() {
|
|
10859
|
+
try {
|
|
10860
|
+
return await client.getChainProtocolVersion();
|
|
10861
|
+
} catch {
|
|
10862
|
+
return void 0;
|
|
10863
|
+
}
|
|
10864
|
+
}
|
|
10865
|
+
function detect() {
|
|
10866
|
+
cached ??= detectWithdrawalProtocol(
|
|
10867
|
+
{
|
|
10868
|
+
protocolVersion,
|
|
10869
|
+
hasCodeAt
|
|
10870
|
+
},
|
|
10871
|
+
override
|
|
10872
|
+
).catch((e) => {
|
|
10873
|
+
cached = void 0;
|
|
10874
|
+
throw e;
|
|
10875
|
+
});
|
|
10876
|
+
return cached;
|
|
10877
|
+
}
|
|
10878
|
+
return {
|
|
10879
|
+
detect,
|
|
10880
|
+
async protocol() {
|
|
10881
|
+
return (await detect()).protocol;
|
|
10882
|
+
},
|
|
10883
|
+
refresh() {
|
|
10884
|
+
cached = void 0;
|
|
10885
|
+
}
|
|
10886
|
+
};
|
|
10887
|
+
}
|
|
10070
10888
|
|
|
10071
10889
|
// src/adapters/ethers/resources/withdrawals/services/finalization.ts
|
|
10072
|
-
var { wrapAs:
|
|
10890
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
10073
10891
|
var IL1NullifierMini = [
|
|
10074
10892
|
"function isWithdrawalFinalized(uint256,uint256,uint256) view returns (bool)"
|
|
10075
10893
|
];
|
|
10076
|
-
function createFinalizationServices(client) {
|
|
10894
|
+
function createFinalizationServices(client, protocolService = createWithdrawalProtocolService(client)) {
|
|
10077
10895
|
const { l1, l2, signer } = client;
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10896
|
+
async function finalizationTarget(protocol) {
|
|
10897
|
+
const { l1Nullifier } = await client.ensureAddresses();
|
|
10898
|
+
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
10899
|
+
const nullifier = new ethers.Contract(l1Nullifier, IL1NullifierV32_default, l1);
|
|
10900
|
+
const handler = await wrapAs10(
|
|
10901
|
+
"CONTRACT",
|
|
10902
|
+
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10903
|
+
() => nullifier.l1InteropHandler(),
|
|
10904
|
+
{
|
|
10905
|
+
ctx: { where: "L1Nullifier.l1InteropHandler", l1Nullifier },
|
|
10906
|
+
message: "Failed to resolve the L1 interop handler. The chain reports protocol v32+, but its L1Nullifier does not expose `l1InteropHandler()`."
|
|
10907
|
+
}
|
|
10908
|
+
);
|
|
10909
|
+
return handler;
|
|
10910
|
+
}
|
|
10911
|
+
async function fetchMessageAndProof(l2TxHash) {
|
|
10912
|
+
const raw = await wrapAs10(
|
|
10913
|
+
"RPC",
|
|
10914
|
+
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10915
|
+
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
10916
|
+
{
|
|
10917
|
+
ctx: { where: "getReceiptWithL2ToL1", l2TxHash },
|
|
10918
|
+
message: "Failed to fetch L2 receipt (with L2\u2192L1 logs)."
|
|
10919
|
+
}
|
|
10920
|
+
);
|
|
10921
|
+
if (!raw) {
|
|
10922
|
+
throw createError("STATE", {
|
|
10923
|
+
resource: "withdrawals",
|
|
10924
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10925
|
+
message: "L2 receipt not found.",
|
|
10926
|
+
context: { l2TxHash }
|
|
10927
|
+
});
|
|
10928
|
+
}
|
|
10929
|
+
const ev = await wrapAs10(
|
|
10930
|
+
"INTERNAL",
|
|
10931
|
+
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
10932
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
10933
|
+
() => Promise.resolve(findL1MessageSentLog(raw, { index: 0 })),
|
|
10934
|
+
{
|
|
10935
|
+
ctx: { l2TxHash, index: 0 },
|
|
10936
|
+
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
10937
|
+
}
|
|
10938
|
+
);
|
|
10939
|
+
const message = await wrapAs10(
|
|
10940
|
+
"INTERNAL",
|
|
10941
|
+
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
10942
|
+
() => Promise.resolve(ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
|
|
10943
|
+
{
|
|
10944
|
+
ctx: { where: "decode L1MessageSent", data: ev.data },
|
|
10945
|
+
message: "Failed to decode withdrawal message."
|
|
10946
|
+
}
|
|
10947
|
+
);
|
|
10948
|
+
const idx = await wrapAs10(
|
|
10949
|
+
"INTERNAL",
|
|
10950
|
+
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
10951
|
+
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
10952
|
+
{
|
|
10953
|
+
ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
|
|
10954
|
+
message: "Failed to derive messenger log index."
|
|
10955
|
+
}
|
|
10956
|
+
);
|
|
10957
|
+
const proof = await wrapAs10(
|
|
10958
|
+
"RPC",
|
|
10959
|
+
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
10960
|
+
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
10961
|
+
{
|
|
10962
|
+
ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
|
|
10963
|
+
message: "Failed to fetch L2\u2192L1 log proof."
|
|
10964
|
+
}
|
|
10965
|
+
);
|
|
10966
|
+
const { chainId } = await wrapAs10(
|
|
10967
|
+
"RPC",
|
|
10968
|
+
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
10969
|
+
() => l2.getNetwork(),
|
|
10970
|
+
{ ctx: { where: "l2.getNetwork" }, message: "Failed to read L2 network." }
|
|
10971
|
+
);
|
|
10972
|
+
const txNumberInBatch = Number(raw.transactionIndex ?? 0);
|
|
10973
|
+
const l2Sender = l1MessageSentSender(ev);
|
|
10974
|
+
return { raw, message, proof, chainId: BigInt(chainId), txNumberInBatch, l2Sender };
|
|
10975
|
+
}
|
|
10976
|
+
async function fetchFinalization(l2TxHash) {
|
|
10977
|
+
const protocol = await protocolService.protocol();
|
|
10978
|
+
const { raw, message, proof, chainId, txNumberInBatch, l2Sender } = await fetchMessageAndProof(l2TxHash);
|
|
10979
|
+
const target = await finalizationTarget(protocol);
|
|
10980
|
+
if (protocol === "legacy-withdrawal") {
|
|
10981
|
+
const params2 = {
|
|
10982
|
+
chainId,
|
|
10983
|
+
l2BatchNumber: proof.batchNumber,
|
|
10984
|
+
l2MessageIndex: proof.id,
|
|
10985
|
+
l2Sender,
|
|
10986
|
+
l2TxNumberInBatch: txNumberInBatch,
|
|
10987
|
+
message,
|
|
10988
|
+
merkleProof: proof.proof
|
|
10989
|
+
};
|
|
10990
|
+
return {
|
|
10991
|
+
target,
|
|
10992
|
+
finalization: { protocol, params: params2 },
|
|
10993
|
+
key: {
|
|
10994
|
+
chainIdL2: chainId,
|
|
10995
|
+
l2BatchNumber: proof.batchNumber,
|
|
10996
|
+
l2MessageIndex: proof.id
|
|
10087
10997
|
}
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10998
|
+
};
|
|
10999
|
+
}
|
|
11000
|
+
const { interopCenter } = await client.ensureAddresses();
|
|
11001
|
+
const params = buildWithdrawalFinalization({
|
|
11002
|
+
messageData: message,
|
|
11003
|
+
sourceChainId: chainId,
|
|
11004
|
+
txNumberInBatch,
|
|
11005
|
+
proof: { batchNumber: proof.batchNumber, id: proof.id, proof: proof.proof },
|
|
11006
|
+
// Prefer the hash the InteropCenter emitted over recomputing it.
|
|
11007
|
+
bundleHash: parseBundleHashFromLogs(raw.logs ?? [], interopCenter),
|
|
11008
|
+
interopCenter
|
|
11009
|
+
});
|
|
11010
|
+
return {
|
|
11011
|
+
target,
|
|
11012
|
+
finalization: { protocol, params },
|
|
11013
|
+
key: {
|
|
11014
|
+
chainIdL2: chainId,
|
|
11015
|
+
l2BatchNumber: proof.batchNumber,
|
|
11016
|
+
l2MessageIndex: proof.id,
|
|
11017
|
+
bundleHash: params.bundleHash
|
|
10096
11018
|
}
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
11019
|
+
};
|
|
11020
|
+
}
|
|
11021
|
+
async function withdrawalOutcome(finalization) {
|
|
11022
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
11023
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
11024
|
+
const c = new ethers.Contract(target, IL1NullifierMini, l1);
|
|
11025
|
+
const done = await wrapAs10(
|
|
11026
|
+
"RPC",
|
|
11027
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11028
|
+
() => c.isWithdrawalFinalized(
|
|
11029
|
+
finalization.params.chainId,
|
|
11030
|
+
finalization.params.l2BatchNumber,
|
|
11031
|
+
finalization.params.l2MessageIndex
|
|
11032
|
+
),
|
|
10102
11033
|
{
|
|
10103
|
-
ctx: {
|
|
10104
|
-
message: "Failed to
|
|
11034
|
+
ctx: { where: "isWithdrawalFinalized", params: finalization.params },
|
|
11035
|
+
message: "Failed to read finalization status."
|
|
10105
11036
|
}
|
|
10106
11037
|
);
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
11038
|
+
return done ? "finalized" : "pending";
|
|
11039
|
+
}
|
|
11040
|
+
const { bundleHash } = finalization.params;
|
|
11041
|
+
const handler = new ethers.Contract(target, IInteropHandler_default, l1);
|
|
11042
|
+
const status = Number(
|
|
11043
|
+
await wrapAs10(
|
|
11044
|
+
"RPC",
|
|
11045
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11046
|
+
() => handler.bundleStatus(bundleHash),
|
|
10111
11047
|
{
|
|
10112
|
-
ctx: { where: "
|
|
10113
|
-
message: "Failed to
|
|
11048
|
+
ctx: { where: "L1InteropHandler.bundleStatus", bundleHash },
|
|
11049
|
+
message: "Failed to read bundle status."
|
|
10114
11050
|
}
|
|
10115
|
-
)
|
|
10116
|
-
|
|
11051
|
+
)
|
|
11052
|
+
);
|
|
11053
|
+
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
11054
|
+
const callStatus = Number(
|
|
11055
|
+
await wrapAs10(
|
|
10117
11056
|
"RPC",
|
|
10118
|
-
OP_WITHDRAWALS.finalize.
|
|
10119
|
-
() =>
|
|
11057
|
+
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11058
|
+
() => handler.callStatus(bundleHash, 0),
|
|
10120
11059
|
{
|
|
10121
|
-
ctx: { where: "
|
|
10122
|
-
message: "Failed to
|
|
11060
|
+
ctx: { where: "L1InteropHandler.callStatus", bundleHash },
|
|
11061
|
+
message: "Failed to read bundle call status."
|
|
10123
11062
|
}
|
|
10124
|
-
)
|
|
10125
|
-
|
|
10126
|
-
|
|
11063
|
+
)
|
|
11064
|
+
);
|
|
11065
|
+
return classifyWithdrawalOutcome(status, callStatus);
|
|
11066
|
+
}
|
|
11067
|
+
async function isWithdrawalFinalized(finalization) {
|
|
11068
|
+
return await withdrawalOutcome(finalization) === "finalized";
|
|
11069
|
+
}
|
|
11070
|
+
return {
|
|
11071
|
+
fetchFinalization,
|
|
11072
|
+
isWithdrawalFinalized,
|
|
11073
|
+
withdrawalOutcome,
|
|
11074
|
+
async fetchFinalizeDepositParams(l2TxHash) {
|
|
11075
|
+
const resolved = await fetchFinalization(l2TxHash);
|
|
11076
|
+
if (resolved.finalization.protocol !== "legacy-withdrawal") {
|
|
11077
|
+
throw createError("VALIDATION", {
|
|
10127
11078
|
resource: "withdrawals",
|
|
10128
|
-
operation: OP_WITHDRAWALS.finalize.fetchParams.
|
|
10129
|
-
message: "
|
|
10130
|
-
context: { l2TxHash }
|
|
11079
|
+
operation: OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
11080
|
+
message: "This chain finalizes withdrawals through the L1 interop handler; `finalizeDeposit` params do not exist. Use `fetchFinalization` instead.",
|
|
11081
|
+
context: { l2TxHash, protocol: resolved.finalization.protocol }
|
|
10131
11082
|
});
|
|
10132
11083
|
}
|
|
10133
|
-
|
|
10134
|
-
"INTERNAL",
|
|
10135
|
-
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
10136
|
-
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
10137
|
-
{
|
|
10138
|
-
ctx: { where: "derive messenger log index", l2TxHash, receipt: raw },
|
|
10139
|
-
message: "Failed to derive messenger log index."
|
|
10140
|
-
}
|
|
10141
|
-
);
|
|
10142
|
-
const proof = await wrapAs9(
|
|
10143
|
-
"RPC",
|
|
10144
|
-
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
10145
|
-
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
10146
|
-
{
|
|
10147
|
-
ctx: { where: "get L2\u2192L1 log proof", l2TxHash, messengerLogIndex: idx },
|
|
10148
|
-
message: "Failed to fetch L2\u2192L1 log proof."
|
|
10149
|
-
}
|
|
10150
|
-
);
|
|
10151
|
-
const { chainId } = await wrapAs9(
|
|
10152
|
-
"RPC",
|
|
10153
|
-
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
10154
|
-
() => l2.getNetwork(),
|
|
10155
|
-
{
|
|
10156
|
-
ctx: { where: "l2.getNetwork" },
|
|
10157
|
-
message: "Failed to read L2 network."
|
|
10158
|
-
}
|
|
10159
|
-
);
|
|
10160
|
-
const txIndex = Number(parsed.transactionIndex ?? 0);
|
|
10161
|
-
const params = {
|
|
10162
|
-
chainId: BigInt(chainId),
|
|
10163
|
-
l2BatchNumber: proof.batchNumber,
|
|
10164
|
-
l2MessageIndex: proof.id,
|
|
10165
|
-
l2Sender: l1MessageSentSender(ev),
|
|
10166
|
-
l2TxNumberInBatch: txIndex,
|
|
10167
|
-
message,
|
|
10168
|
-
merkleProof: proof.proof
|
|
10169
|
-
};
|
|
10170
|
-
const { l1Nullifier } = await client.ensureAddresses();
|
|
10171
|
-
return { params, nullifier: l1Nullifier };
|
|
11084
|
+
return { params: resolved.finalization.params, nullifier: resolved.target };
|
|
10172
11085
|
},
|
|
10173
|
-
async simulateFinalizeReadiness(
|
|
10174
|
-
const
|
|
11086
|
+
async simulateFinalizeReadiness(finalization) {
|
|
11087
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
10175
11088
|
const done = await (async () => {
|
|
10176
11089
|
try {
|
|
10177
|
-
|
|
10178
|
-
const isFinalized = await wrapAs9(
|
|
10179
|
-
"RPC",
|
|
10180
|
-
OP_WITHDRAWALS.finalize.readiness.isFinalized,
|
|
10181
|
-
() => cMini.isWithdrawalFinalized(
|
|
10182
|
-
params.chainId,
|
|
10183
|
-
params.l2BatchNumber,
|
|
10184
|
-
params.l2MessageIndex
|
|
10185
|
-
),
|
|
10186
|
-
{
|
|
10187
|
-
ctx: { where: "isWithdrawalFinalized", params },
|
|
10188
|
-
message: "Failed to read finalization status."
|
|
10189
|
-
}
|
|
10190
|
-
);
|
|
10191
|
-
return Boolean(isFinalized);
|
|
11090
|
+
return await isWithdrawalFinalized(finalization);
|
|
10192
11091
|
} catch {
|
|
10193
11092
|
return false;
|
|
10194
11093
|
}
|
|
10195
11094
|
})();
|
|
10196
11095
|
if (done) return { kind: "FINALIZED" };
|
|
10197
|
-
const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, l1);
|
|
10198
11096
|
try {
|
|
10199
|
-
|
|
11097
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
11098
|
+
const c = new ethers.Contract(target, IL1Nullifier_default, l1);
|
|
11099
|
+
await c.finalizeDeposit.staticCall(finalization.params);
|
|
11100
|
+
} else {
|
|
11101
|
+
const handler = new ethers.Contract(target, IInteropHandler_default, l1);
|
|
11102
|
+
await handler.executeBundle.staticCall(
|
|
11103
|
+
finalization.params.bundle,
|
|
11104
|
+
finalization.params.proof
|
|
11105
|
+
);
|
|
11106
|
+
}
|
|
10200
11107
|
return { kind: "READY" };
|
|
10201
11108
|
} catch (e) {
|
|
10202
11109
|
return classifyReadinessFromRevert(e);
|
|
10203
11110
|
}
|
|
10204
11111
|
},
|
|
10205
|
-
async
|
|
10206
|
-
const
|
|
10207
|
-
const
|
|
10208
|
-
|
|
10209
|
-
"RPC",
|
|
10210
|
-
OP_WITHDRAWALS.finalize.isFinalized,
|
|
10211
|
-
() => c.isWithdrawalFinalized(key.chainIdL2, key.l2BatchNumber, key.l2MessageIndex),
|
|
10212
|
-
{
|
|
10213
|
-
ctx: { where: "isWithdrawalFinalized", key },
|
|
10214
|
-
message: "Failed to read finalization status."
|
|
10215
|
-
}
|
|
10216
|
-
);
|
|
10217
|
-
},
|
|
10218
|
-
async estimateFinalization(params) {
|
|
10219
|
-
const { l1Nullifier } = await client.ensureAddresses();
|
|
10220
|
-
const signer2 = client.getL1Signer();
|
|
10221
|
-
const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, signer2);
|
|
10222
|
-
const gasLimit = await wrapAs9(
|
|
11112
|
+
async estimateFinalization(finalization) {
|
|
11113
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
11114
|
+
const l1Signer = client.getL1Signer();
|
|
11115
|
+
const gasLimit = await wrapAs10(
|
|
10223
11116
|
"RPC",
|
|
10224
11117
|
OP_WITHDRAWALS.finalize.estimate,
|
|
10225
|
-
() =>
|
|
11118
|
+
() => {
|
|
11119
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
11120
|
+
const c = new ethers.Contract(target, IL1Nullifier_default, l1Signer);
|
|
11121
|
+
return c.finalizeDeposit.estimateGas(finalization.params);
|
|
11122
|
+
}
|
|
11123
|
+
const handler = new ethers.Contract(target, IInteropHandler_default, l1Signer);
|
|
11124
|
+
return handler.executeBundle.estimateGas(
|
|
11125
|
+
finalization.params.bundle,
|
|
11126
|
+
finalization.params.proof
|
|
11127
|
+
);
|
|
11128
|
+
},
|
|
10226
11129
|
{
|
|
10227
|
-
ctx: {
|
|
10228
|
-
|
|
10229
|
-
chainIdL2: params.chainId,
|
|
10230
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
10231
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
10232
|
-
l1Nullifier
|
|
10233
|
-
},
|
|
10234
|
-
message: "Failed to estimate gas for finalizeDeposit."
|
|
11130
|
+
ctx: { where: "estimateGas(finalize)", protocol: finalization.protocol, target },
|
|
11131
|
+
message: "Failed to estimate gas for withdrawal finalization."
|
|
10235
11132
|
}
|
|
10236
11133
|
);
|
|
10237
|
-
const feeData = await
|
|
11134
|
+
const feeData = await wrapAs10("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
|
|
10238
11135
|
ctx: { where: "l1.getFeeData" },
|
|
10239
|
-
message: "Failed to estimate fee data for
|
|
11136
|
+
message: "Failed to estimate fee data for withdrawal finalization."
|
|
10240
11137
|
});
|
|
10241
11138
|
const maxFeePerGas = feeData.maxFeePerGas ?? feeData.gasPrice ?? // legacy-style gas price if present
|
|
10242
11139
|
(() => {
|
|
@@ -10247,33 +11144,49 @@ function createFinalizationServices(client) {
|
|
|
10247
11144
|
context: { feeData }
|
|
10248
11145
|
});
|
|
10249
11146
|
})();
|
|
10250
|
-
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? 0n;
|
|
10251
11147
|
return {
|
|
10252
11148
|
gasLimit,
|
|
10253
11149
|
maxFeePerGas,
|
|
10254
|
-
maxPriorityFeePerGas
|
|
11150
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 0n
|
|
10255
11151
|
};
|
|
10256
11152
|
},
|
|
10257
|
-
async
|
|
10258
|
-
const
|
|
10259
|
-
const c = new ethers.Contract(l1Nullifier, IL1Nullifier_default, signer);
|
|
11153
|
+
async finalize(finalization) {
|
|
11154
|
+
const target = await finalizationTarget(finalization.protocol);
|
|
10260
11155
|
try {
|
|
10261
|
-
const
|
|
10262
|
-
|
|
11156
|
+
const sent = await (async () => {
|
|
11157
|
+
if (finalization.protocol === "legacy-withdrawal") {
|
|
11158
|
+
const c = new ethers.Contract(target, IL1Nullifier_default, signer);
|
|
11159
|
+
return await c.finalizeDeposit(finalization.params);
|
|
11160
|
+
}
|
|
11161
|
+
const handler = new ethers.Contract(target, IInteropHandler_default, signer);
|
|
11162
|
+
return await handler.executeBundle(
|
|
11163
|
+
finalization.params.bundle,
|
|
11164
|
+
finalization.params.proof
|
|
11165
|
+
);
|
|
11166
|
+
})();
|
|
11167
|
+
const hash = sent.hash;
|
|
10263
11168
|
return {
|
|
10264
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
10265
11169
|
hash,
|
|
10266
11170
|
wait: async () => {
|
|
10267
11171
|
try {
|
|
10268
|
-
|
|
11172
|
+
const receipt = await sent.wait();
|
|
11173
|
+
if (!receipt) {
|
|
11174
|
+
throw createError("EXECUTION", {
|
|
11175
|
+
resource: "withdrawals",
|
|
11176
|
+
operation: OP_WITHDRAWALS.finalize.wait,
|
|
11177
|
+
message: "Withdrawal finalization transaction produced no receipt.",
|
|
11178
|
+
context: { txHash: hash, protocol: finalization.protocol }
|
|
11179
|
+
});
|
|
11180
|
+
}
|
|
11181
|
+
return receipt;
|
|
10269
11182
|
} catch (e) {
|
|
10270
11183
|
throw toZKsyncError(
|
|
10271
11184
|
"EXECUTION",
|
|
10272
11185
|
{
|
|
10273
11186
|
resource: "withdrawals",
|
|
10274
11187
|
operation: OP_WITHDRAWALS.finalize.wait,
|
|
10275
|
-
message: "Failed while waiting for
|
|
10276
|
-
context: { txHash: hash }
|
|
11188
|
+
message: "Failed while waiting for the withdrawal finalization transaction.",
|
|
11189
|
+
context: { txHash: hash, protocol: finalization.protocol }
|
|
10277
11190
|
},
|
|
10278
11191
|
e
|
|
10279
11192
|
);
|
|
@@ -10286,13 +11199,8 @@ function createFinalizationServices(client) {
|
|
|
10286
11199
|
{
|
|
10287
11200
|
resource: "withdrawals",
|
|
10288
11201
|
operation: OP_WITHDRAWALS.finalize.send,
|
|
10289
|
-
message: "Failed to send
|
|
10290
|
-
context: {
|
|
10291
|
-
chainIdL2: params.chainId,
|
|
10292
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
10293
|
-
l2MessageIndex: params.l2MessageIndex,
|
|
10294
|
-
l1Nullifier
|
|
10295
|
-
}
|
|
11202
|
+
message: "Failed to send the withdrawal finalization transaction.",
|
|
11203
|
+
context: { protocol: finalization.protocol, target }
|
|
10296
11204
|
},
|
|
10297
11205
|
e
|
|
10298
11206
|
);
|
|
@@ -10325,15 +11233,28 @@ var ROUTES2 = {
|
|
|
10325
11233
|
"erc20-nonbase": routeErc20NonBase2()
|
|
10326
11234
|
// AssetRouter.withdraw for non-base ERC-20s
|
|
10327
11235
|
};
|
|
10328
|
-
|
|
10329
|
-
|
|
11236
|
+
var INTEROP_ROUTES = {
|
|
11237
|
+
base: routeInteropBundle(),
|
|
11238
|
+
"erc20-nonbase": routeInteropBundle()
|
|
11239
|
+
};
|
|
11240
|
+
function routeStrategy(protocol, route) {
|
|
11241
|
+
return protocol === "interop-bundle" ? INTEROP_ROUTES[route] : ROUTES2[route];
|
|
11242
|
+
}
|
|
11243
|
+
function createWithdrawalsResource(client, tokens, contracts, options) {
|
|
11244
|
+
const protocolService = createWithdrawalProtocolService(
|
|
11245
|
+
client,
|
|
11246
|
+
options?.protocol
|
|
11247
|
+
);
|
|
11248
|
+
const svc = createFinalizationServices(client, protocolService);
|
|
10330
11249
|
const { wrap: wrap8, toResult: toResult3 } = createErrorHandlers("withdrawals");
|
|
10331
11250
|
const tokensResource = tokens ?? createTokensResource(client);
|
|
10332
11251
|
const contractsResource = contracts ?? createContractsResource(client);
|
|
10333
11252
|
async function buildPlan(p) {
|
|
10334
|
-
const
|
|
10335
|
-
await
|
|
10336
|
-
const
|
|
11253
|
+
const protocol = await protocolService.protocol();
|
|
11254
|
+
const ctx = await commonCtx2(p, client, tokensResource, contractsResource, protocol);
|
|
11255
|
+
const strategy = routeStrategy(protocol, ctx.route);
|
|
11256
|
+
await strategy.preflight?.(p, ctx);
|
|
11257
|
+
const { steps, approvals, fees } = await strategy.build(p, ctx);
|
|
10337
11258
|
return {
|
|
10338
11259
|
route: ctx.route,
|
|
10339
11260
|
summary: {
|
|
@@ -10477,21 +11398,20 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
10477
11398
|
if (!l2Rcpt) return { phase: "L2_PENDING", l2TxHash };
|
|
10478
11399
|
let pack;
|
|
10479
11400
|
try {
|
|
10480
|
-
pack = await svc.
|
|
11401
|
+
pack = await svc.fetchFinalization(l2TxHash);
|
|
10481
11402
|
} catch {
|
|
10482
11403
|
return { phase: "PENDING", l2TxHash };
|
|
10483
11404
|
}
|
|
10484
|
-
const key =
|
|
10485
|
-
chainIdL2: pack.params.chainId,
|
|
10486
|
-
l2BatchNumber: pack.params.l2BatchNumber,
|
|
10487
|
-
l2MessageIndex: pack.params.l2MessageIndex
|
|
10488
|
-
};
|
|
11405
|
+
const key = pack.key;
|
|
10489
11406
|
try {
|
|
10490
|
-
const
|
|
10491
|
-
if (
|
|
11407
|
+
const outcome = await svc.withdrawalOutcome(pack.finalization);
|
|
11408
|
+
if (outcome === "finalized") return { phase: "FINALIZED", l2TxHash, key };
|
|
11409
|
+
if (outcome === "failed") {
|
|
11410
|
+
return { phase: "UNFINALIZABLE", l2TxHash, key, reason: "bundle-cancelled" };
|
|
11411
|
+
}
|
|
10492
11412
|
} catch {
|
|
10493
11413
|
}
|
|
10494
|
-
const readiness = await svc.simulateFinalizeReadiness(pack.
|
|
11414
|
+
const readiness = await svc.simulateFinalizeReadiness(pack.finalization);
|
|
10495
11415
|
const { phase, reason } = phaseFromReadiness(readiness);
|
|
10496
11416
|
return { phase, reason, l2TxHash, key };
|
|
10497
11417
|
},
|
|
@@ -10581,7 +11501,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
10581
11501
|
async () => {
|
|
10582
11502
|
const pack = await (async () => {
|
|
10583
11503
|
try {
|
|
10584
|
-
return await svc.
|
|
11504
|
+
return await svc.fetchFinalization(l2TxHash);
|
|
10585
11505
|
} catch (e) {
|
|
10586
11506
|
throw createError("STATE", {
|
|
10587
11507
|
resource: "withdrawals",
|
|
@@ -10592,21 +11512,16 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
10592
11512
|
});
|
|
10593
11513
|
}
|
|
10594
11514
|
})();
|
|
10595
|
-
const {
|
|
10596
|
-
const key = {
|
|
10597
|
-
chainIdL2: params.chainId,
|
|
10598
|
-
l2BatchNumber: params.l2BatchNumber,
|
|
10599
|
-
l2MessageIndex: params.l2MessageIndex
|
|
10600
|
-
};
|
|
11515
|
+
const { finalization } = pack;
|
|
10601
11516
|
try {
|
|
10602
|
-
const
|
|
10603
|
-
if (
|
|
11517
|
+
const outcome = await svc.withdrawalOutcome(finalization);
|
|
11518
|
+
if (outcome === "finalized" || outcome === "failed") {
|
|
10604
11519
|
const statusNow = await status(l2TxHash);
|
|
10605
11520
|
return { status: statusNow };
|
|
10606
11521
|
}
|
|
10607
11522
|
} catch {
|
|
10608
11523
|
}
|
|
10609
|
-
const readiness = await svc.simulateFinalizeReadiness(
|
|
11524
|
+
const readiness = await svc.simulateFinalizeReadiness(finalization);
|
|
10610
11525
|
if (readiness.kind === "FINALIZED") {
|
|
10611
11526
|
const statusNow = await status(l2TxHash);
|
|
10612
11527
|
return { status: statusNow };
|
|
@@ -10620,7 +11535,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
10620
11535
|
});
|
|
10621
11536
|
}
|
|
10622
11537
|
try {
|
|
10623
|
-
const tx = await svc.
|
|
11538
|
+
const tx = await svc.finalize(finalization);
|
|
10624
11539
|
finalizeCache.set(l2TxHash, tx.hash);
|
|
10625
11540
|
const rcpt = await tx.wait();
|
|
10626
11541
|
const statusNow = await status(l2TxHash);
|
|
@@ -10629,7 +11544,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
10629
11544
|
const statusNow = await status(l2TxHash);
|
|
10630
11545
|
if (statusNow.phase === "FINALIZED") return { status: statusNow };
|
|
10631
11546
|
try {
|
|
10632
|
-
const again = await svc.simulateFinalizeReadiness(
|
|
11547
|
+
const again = await svc.simulateFinalizeReadiness(finalization);
|
|
10633
11548
|
if (again.kind === "NOT_READY") {
|
|
10634
11549
|
throw createError("STATE", {
|
|
10635
11550
|
resource: "withdrawals",
|
|
@@ -10688,74 +11603,6 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
10688
11603
|
};
|
|
10689
11604
|
}
|
|
10690
11605
|
|
|
10691
|
-
// src/core/resources/interop/attributes/call.ts
|
|
10692
|
-
function createCallAttributes(codec) {
|
|
10693
|
-
const indirectCall = (messageValue) => codec.encode("indirectCall", [messageValue]);
|
|
10694
|
-
const interopCallValue = (bridgedAmount) => codec.encode("interopCallValue", [bridgedAmount]);
|
|
10695
|
-
return {
|
|
10696
|
-
indirectCall,
|
|
10697
|
-
interopCallValue
|
|
10698
|
-
};
|
|
10699
|
-
}
|
|
10700
|
-
|
|
10701
|
-
// src/core/resources/interop/attributes/bundle.ts
|
|
10702
|
-
function createBundleAttributes(codec) {
|
|
10703
|
-
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
10704
|
-
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
10705
|
-
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
10706
|
-
return {
|
|
10707
|
-
executionAddress,
|
|
10708
|
-
unbundlerAddress,
|
|
10709
|
-
useFixedFee
|
|
10710
|
-
};
|
|
10711
|
-
}
|
|
10712
|
-
|
|
10713
|
-
// src/core/resources/interop/attributes/resource.ts
|
|
10714
|
-
function createAttributesResource(codec) {
|
|
10715
|
-
return {
|
|
10716
|
-
call: createCallAttributes(codec),
|
|
10717
|
-
bundle: createBundleAttributes(codec)
|
|
10718
|
-
};
|
|
10719
|
-
}
|
|
10720
|
-
|
|
10721
|
-
// src/adapters/ethers/resources/interop/attributes/resource.ts
|
|
10722
|
-
function getInteropAttributes(params, ctx) {
|
|
10723
|
-
const bundleAttributes = [];
|
|
10724
|
-
if (params.execution?.only) {
|
|
10725
|
-
bundleAttributes.push(ctx.attributes.bundle.executionAddress(params.execution.only));
|
|
10726
|
-
}
|
|
10727
|
-
if (params.unbundling?.by) {
|
|
10728
|
-
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
10729
|
-
}
|
|
10730
|
-
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
10731
|
-
const callAttributes = params.actions.map((action) => {
|
|
10732
|
-
switch (action.type) {
|
|
10733
|
-
case "sendNative": {
|
|
10734
|
-
const baseMatches = ctx.baseTokens.src.toLowerCase() === ctx.baseTokens.dst.toLowerCase();
|
|
10735
|
-
if (baseMatches) {
|
|
10736
|
-
return [ctx.attributes.call.interopCallValue(action.amount)];
|
|
10737
|
-
}
|
|
10738
|
-
return [ctx.attributes.call.indirectCall(action.amount)];
|
|
10739
|
-
}
|
|
10740
|
-
case "call":
|
|
10741
|
-
if (action.value && action.value > 0n) {
|
|
10742
|
-
return [ctx.attributes.call.interopCallValue(action.value)];
|
|
10743
|
-
}
|
|
10744
|
-
return [];
|
|
10745
|
-
case "sendErc20":
|
|
10746
|
-
return [ctx.attributes.call.indirectCall(0n)];
|
|
10747
|
-
default:
|
|
10748
|
-
assertNever(action);
|
|
10749
|
-
}
|
|
10750
|
-
});
|
|
10751
|
-
return { bundleAttributes, callAttributes };
|
|
10752
|
-
}
|
|
10753
|
-
function createEthersAttributesResource(opts = {}) {
|
|
10754
|
-
const iface = opts.iface ?? new ethers.Interface(IERC7786Attributes_default);
|
|
10755
|
-
const encode2 = (fn, args) => iface.encodeFunctionData(fn, args);
|
|
10756
|
-
return createAttributesResource({ encode: encode2 });
|
|
10757
|
-
}
|
|
10758
|
-
|
|
10759
11606
|
// src/core/types/flows/interop.ts
|
|
10760
11607
|
function isInteropMessageProof(obj) {
|
|
10761
11608
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -10932,24 +11779,6 @@ function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
|
|
|
10932
11779
|
}
|
|
10933
11780
|
};
|
|
10934
11781
|
}
|
|
10935
|
-
var PREFIX_EVM_CHAIN = ethers.getBytes("0x00010000");
|
|
10936
|
-
var PREFIX_EVM_ADDRESS = ethers.getBytes("0x000100000014");
|
|
10937
|
-
function formatInteropEvmChain(chainId) {
|
|
10938
|
-
const chainRef = ethers.toBeArray(chainId);
|
|
10939
|
-
const chainRefLength = ethers.getBytes(ethers.toBeHex(chainRef.length, 1));
|
|
10940
|
-
const payload = ethers.concat([PREFIX_EVM_CHAIN, chainRefLength, chainRef, new Uint8Array([0])]);
|
|
10941
|
-
return ethers.hexlify(payload);
|
|
10942
|
-
}
|
|
10943
|
-
function formatInteropEvmAddress(address) {
|
|
10944
|
-
const normalized = ethers.getAddress(address);
|
|
10945
|
-
const addrBytes = ethers.getBytes(normalized);
|
|
10946
|
-
const payload = ethers.concat([PREFIX_EVM_ADDRESS, addrBytes]);
|
|
10947
|
-
return ethers.hexlify(payload);
|
|
10948
|
-
}
|
|
10949
|
-
var interopCodec = {
|
|
10950
|
-
formatChain: formatInteropEvmChain,
|
|
10951
|
-
formatAddress: formatInteropEvmAddress
|
|
10952
|
-
};
|
|
10953
11782
|
function getErc20Tokens(params) {
|
|
10954
11783
|
const erc20Tokens = /* @__PURE__ */ new Map();
|
|
10955
11784
|
for (const action of params.actions) {
|
|
@@ -11105,7 +11934,7 @@ function routeIndirect() {
|
|
|
11105
11934
|
resolveErc20AssetIds(erc20Tokens, ctx),
|
|
11106
11935
|
buildFeeInfo(params, ctx, params.actions.length)
|
|
11107
11936
|
]);
|
|
11108
|
-
const
|
|
11937
|
+
const attributes2 = getInteropAttributes(params, ctx);
|
|
11109
11938
|
const starterData = await getStarterData(params, ctx, erc20AssetIds);
|
|
11110
11939
|
const bundle = buildIndirectBundle(
|
|
11111
11940
|
params,
|
|
@@ -11116,7 +11945,7 @@ function routeIndirect() {
|
|
|
11116
11945
|
l2NativeTokenVault: ctx.l2NativeTokenVault,
|
|
11117
11946
|
codec: interopCodec
|
|
11118
11947
|
},
|
|
11119
|
-
|
|
11948
|
+
attributes2,
|
|
11120
11949
|
starterData,
|
|
11121
11950
|
feeInfo
|
|
11122
11951
|
);
|
|
@@ -11239,7 +12068,7 @@ async function assertInteropProtocolVersion(client, srcChainId, dstChainId) {
|
|
|
11239
12068
|
assertProtocolVersion(srcChainId, srcProtocolVersion);
|
|
11240
12069
|
assertProtocolVersion(dstChainId, dstProtocolVersion);
|
|
11241
12070
|
}
|
|
11242
|
-
async function commonCtx3(dstProvider, params, client, tokens, contracts,
|
|
12071
|
+
async function commonCtx3(dstProvider, params, client, tokens, contracts, attributes2) {
|
|
11243
12072
|
const sender = await client.signer.getAddress();
|
|
11244
12073
|
const chainId = (await client.l2.getNetwork()).chainId;
|
|
11245
12074
|
const dstChainId = (await dstProvider.getNetwork()).chainId;
|
|
@@ -11276,7 +12105,7 @@ async function commonCtx3(dstProvider, params, client, tokens, contracts, attrib
|
|
|
11276
12105
|
l2NativeTokenVault,
|
|
11277
12106
|
baseTokens: { src: srcBaseToken, dst: dstBaseToken, matches: baseMatches },
|
|
11278
12107
|
ifaces: { interopCenter: interopCenterIface, interopHandler: interopHandlerIface },
|
|
11279
|
-
attributes,
|
|
12108
|
+
attributes: attributes2,
|
|
11280
12109
|
gasOverrides: params.txOverrides ? toGasOverrides(params.txOverrides) : void 0
|
|
11281
12110
|
};
|
|
11282
12111
|
}
|
|
@@ -11932,7 +12761,7 @@ var ROUTES3 = {
|
|
|
11932
12761
|
direct: routeDirect(),
|
|
11933
12762
|
indirect: routeIndirect()
|
|
11934
12763
|
};
|
|
11935
|
-
function createInteropResource(client, config, tokens, contracts,
|
|
12764
|
+
function createInteropResource(client, config, tokens, contracts, attributes2) {
|
|
11936
12765
|
let gwProviderCache;
|
|
11937
12766
|
function requireConfig() {
|
|
11938
12767
|
if (!config)
|
|
@@ -11950,7 +12779,7 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
|
|
|
11950
12779
|
const svc = createInteropFinalizationServices(client);
|
|
11951
12780
|
const tokensResource = tokens ?? createTokensResource(client);
|
|
11952
12781
|
const contractsResource = contracts ?? createContractsResource(client);
|
|
11953
|
-
const attributesResource =
|
|
12782
|
+
const attributesResource = attributes2 ?? createEthersAttributesResource();
|
|
11954
12783
|
async function buildPlanWithCtx(dstProvider, params) {
|
|
11955
12784
|
const ctx = await commonCtx3(
|
|
11956
12785
|
dstProvider,
|
|
@@ -12163,7 +12992,7 @@ function createEthersSdk(client, options) {
|
|
|
12163
12992
|
const interop = createInteropResource(client, options?.interop, tokens, contracts);
|
|
12164
12993
|
return {
|
|
12165
12994
|
deposits: createDepositsResource(client, tokens, contracts),
|
|
12166
|
-
withdrawals: createWithdrawalsResource(client, tokens, contracts),
|
|
12995
|
+
withdrawals: createWithdrawalsResource(client, tokens, contracts, options?.withdrawals),
|
|
12167
12996
|
tokens,
|
|
12168
12997
|
contracts,
|
|
12169
12998
|
interop
|
|
@@ -12181,6 +13010,7 @@ exports.createFinalizationServices = createFinalizationServices;
|
|
|
12181
13010
|
exports.createInteropFinalizationServices = createInteropFinalizationServices;
|
|
12182
13011
|
exports.createInteropResource = createInteropResource;
|
|
12183
13012
|
exports.createTokensResource = createTokensResource;
|
|
13013
|
+
exports.createWithdrawalProtocolService = createWithdrawalProtocolService;
|
|
12184
13014
|
exports.createWithdrawalsResource = createWithdrawalsResource;
|
|
12185
13015
|
exports.decodeRevert = decodeRevert;
|
|
12186
13016
|
exports.encodeNativeTokenVaultTransferData = encodeNativeTokenVaultTransferData;
|