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