@matterlabs/zksync-js 0.0.13 → 0.0.14
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 +13 -4
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +7 -6
- package/dist/adapters/ethers/index.cjs +501 -242
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +10 -9
- package/dist/adapters/ethers/resources/deposits/routes/priority.d.ts +12 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +4 -0
- package/dist/adapters/ethers/resources/interop/index.d.ts +14 -14
- package/dist/adapters/ethers/resources/interop/resolvers.d.ts +3 -8
- package/dist/adapters/ethers/resources/interop/routes/types.d.ts +2 -1
- package/dist/adapters/ethers/resources/interop/services/erc20.d.ts +10 -0
- package/dist/adapters/ethers/resources/interop/services/fee.d.ts +12 -0
- package/dist/adapters/ethers/resources/interop/services/finalization/index.d.ts +1 -1
- package/dist/adapters/ethers/resources/interop/services/finalization/polling.d.ts +1 -1
- package/dist/adapters/ethers/resources/interop/types.d.ts +6 -14
- package/dist/adapters/ethers/sdk.cjs +912 -252
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.d.ts +6 -1
- package/dist/adapters/ethers/sdk.js +8 -7
- package/dist/adapters/viem/client.cjs +8 -4
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.js +7 -6
- package/dist/adapters/viem/index.cjs +315 -73
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +10 -9
- package/dist/adapters/viem/resources/deposits/routes/priority.d.ts +13 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +4 -0
- package/dist/adapters/viem/sdk.cjs +307 -69
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +7 -7
- package/dist/{chunk-E3KP7XCG.js → chunk-3HHUZXSV.js} +1 -1
- package/dist/{chunk-UDBRUBEK.js → chunk-5RRJDPAJ.js} +2 -2
- package/dist/{chunk-EDWBCPO3.js → chunk-75IOOODG.js} +253 -53
- package/dist/{chunk-R5WRFPK2.js → chunk-7CAVFIMW.js} +5 -4
- package/dist/chunk-BWKWWLY4.js +9 -0
- package/dist/{chunk-4S4XDA4N.js → chunk-DYJKK5FW.js} +17 -15
- package/dist/{chunk-5L6EYUJB.js → chunk-EOBXYHTZ.js} +35 -7
- package/dist/{chunk-53MC5BR2.js → chunk-HP3EWKJL.js} +1 -1
- package/dist/{chunk-HI64OOAR.js → chunk-J47RI3G7.js} +1 -1
- package/dist/{chunk-RI73VJSH.js → chunk-JY62QO3W.js} +44 -21
- package/dist/{chunk-QQ2OR434.js → chunk-MT4X5FEO.js} +18 -2
- package/dist/{chunk-2RIARDXZ.js → chunk-OTXPSNNC.js} +5 -4
- package/dist/{chunk-5R7L5NM5.js → chunk-XDRCN4FC.js} +2 -2
- package/dist/{chunk-JHO2UQ5F.js → chunk-XKRNLFET.js} +394 -200
- package/dist/core/constants.cjs +17 -1
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +9 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +52 -24
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +6 -5
- package/dist/core/internal/abis/IERC7786Attributes.d.ts +21 -11
- package/dist/core/internal/abis/IInteropCenter.d.ts +4 -0
- package/dist/core/resources/deposits/priority.d.ts +37 -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/interop/plan.d.ts +11 -3
- package/dist/core/rpc/types.d.ts +1 -0
- package/dist/core/rpc/zks.d.ts +5 -1
- package/dist/core/types/errors.d.ts +5 -0
- package/dist/core/types/flows/interop.d.ts +11 -18
- package/dist/index.cjs +69 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -5
- package/package.json +1 -1
|
@@ -37,7 +37,15 @@ var TX_OVERHEAD_GAS = 10000n;
|
|
|
37
37
|
var TX_MEMORY_OVERHEAD_GAS = 10n;
|
|
38
38
|
var DEFAULT_PUBDATA_BYTES = 155n;
|
|
39
39
|
var DEFAULT_ABI_BYTES = 400n;
|
|
40
|
-
var SAFE_L1_BRIDGE_GAS =
|
|
40
|
+
var SAFE_L1_BRIDGE_GAS = 3000000n;
|
|
41
|
+
var L1_TX_INTRINSIC_L2_GAS = 167157n;
|
|
42
|
+
var L1_TX_INTRINSIC_PUBDATA = 88n;
|
|
43
|
+
var L1_TX_MIN_L2_GAS_BASE = 173484n;
|
|
44
|
+
var L1_TX_DELTA_544_ENCODING_BYTES = 1656n;
|
|
45
|
+
var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
|
|
46
|
+
var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
|
|
47
|
+
var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
|
|
48
|
+
var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
|
|
41
49
|
|
|
42
50
|
// src/core/utils/number.ts
|
|
43
51
|
var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
|
|
@@ -401,6 +409,11 @@ var OP_INTEROP = {
|
|
|
401
409
|
wait: {
|
|
402
410
|
poll: "interop.svc.wait:poll",
|
|
403
411
|
timeout: "interop.svc.wait:timeout"
|
|
412
|
+
},
|
|
413
|
+
fees: {
|
|
414
|
+
zkInteropFee: "interop.svc.fees:zkInteropFee",
|
|
415
|
+
zkToken: "interop.svc.fees:zkToken",
|
|
416
|
+
protocolFee: "interop.svc.fees:protocolFee"
|
|
404
417
|
}
|
|
405
418
|
}
|
|
406
419
|
};
|
|
@@ -2259,20 +2272,425 @@ var IL1NullifierABI = [
|
|
|
2259
2272
|
type: "function"
|
|
2260
2273
|
},
|
|
2261
2274
|
{
|
|
2262
|
-
inputs: [
|
|
2263
|
-
{
|
|
2264
|
-
internalType: "address",
|
|
2265
|
-
name: "_token",
|
|
2266
|
-
type: "address"
|
|
2267
|
-
}
|
|
2268
|
-
],
|
|
2269
|
-
name: "transferTokenToNTV",
|
|
2270
|
-
outputs: [],
|
|
2271
|
-
stateMutability: "nonpayable",
|
|
2272
|
-
type: "function"
|
|
2275
|
+
inputs: [
|
|
2276
|
+
{
|
|
2277
|
+
internalType: "address",
|
|
2278
|
+
name: "_token",
|
|
2279
|
+
type: "address"
|
|
2280
|
+
}
|
|
2281
|
+
],
|
|
2282
|
+
name: "transferTokenToNTV",
|
|
2283
|
+
outputs: [],
|
|
2284
|
+
stateMutability: "nonpayable",
|
|
2285
|
+
type: "function"
|
|
2286
|
+
}
|
|
2287
|
+
];
|
|
2288
|
+
var IL1Nullifier_default = IL1NullifierABI;
|
|
2289
|
+
|
|
2290
|
+
// src/core/internal/abis/IL2AssetRouter.ts
|
|
2291
|
+
var IL2AssetRouterABI = [
|
|
2292
|
+
{
|
|
2293
|
+
type: "function",
|
|
2294
|
+
name: "BASE_TOKEN_ASSET_ID",
|
|
2295
|
+
inputs: [],
|
|
2296
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
2297
|
+
stateMutability: "view"
|
|
2298
|
+
},
|
|
2299
|
+
{
|
|
2300
|
+
type: "function",
|
|
2301
|
+
name: "BRIDGE_HUB",
|
|
2302
|
+
inputs: [],
|
|
2303
|
+
outputs: [{ name: "", type: "address", internalType: "contract IBridgehub" }],
|
|
2304
|
+
stateMutability: "view"
|
|
2305
|
+
},
|
|
2306
|
+
{
|
|
2307
|
+
type: "function",
|
|
2308
|
+
name: "L1_ASSET_ROUTER",
|
|
2309
|
+
inputs: [],
|
|
2310
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2311
|
+
stateMutability: "view"
|
|
2312
|
+
},
|
|
2313
|
+
{
|
|
2314
|
+
type: "function",
|
|
2315
|
+
name: "L1_CHAIN_ID",
|
|
2316
|
+
inputs: [],
|
|
2317
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
2318
|
+
stateMutability: "view"
|
|
2319
|
+
},
|
|
2320
|
+
{
|
|
2321
|
+
type: "function",
|
|
2322
|
+
name: "L2_LEGACY_SHARED_BRIDGE",
|
|
2323
|
+
inputs: [],
|
|
2324
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2325
|
+
stateMutability: "view"
|
|
2326
|
+
},
|
|
2327
|
+
{
|
|
2328
|
+
type: "function",
|
|
2329
|
+
name: "acceptOwnership",
|
|
2330
|
+
inputs: [],
|
|
2331
|
+
outputs: [],
|
|
2332
|
+
stateMutability: "nonpayable"
|
|
2333
|
+
},
|
|
2334
|
+
{
|
|
2335
|
+
type: "function",
|
|
2336
|
+
name: "assetDeploymentTracker",
|
|
2337
|
+
inputs: [{ name: "assetId", type: "bytes32", internalType: "bytes32" }],
|
|
2338
|
+
outputs: [{ name: "assetDeploymentTracker", type: "address", internalType: "address" }],
|
|
2339
|
+
stateMutability: "view"
|
|
2340
|
+
},
|
|
2341
|
+
{
|
|
2342
|
+
type: "function",
|
|
2343
|
+
name: "assetHandlerAddress",
|
|
2344
|
+
inputs: [{ name: "assetId", type: "bytes32", internalType: "bytes32" }],
|
|
2345
|
+
outputs: [{ name: "assetHandlerAddress", type: "address", internalType: "address" }],
|
|
2346
|
+
stateMutability: "view"
|
|
2347
|
+
},
|
|
2348
|
+
{
|
|
2349
|
+
type: "function",
|
|
2350
|
+
name: "eraChainId",
|
|
2351
|
+
inputs: [],
|
|
2352
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
2353
|
+
stateMutability: "view"
|
|
2354
|
+
},
|
|
2355
|
+
{
|
|
2356
|
+
type: "function",
|
|
2357
|
+
name: "finalizeDeposit",
|
|
2358
|
+
inputs: [
|
|
2359
|
+
{ name: "", type: "uint256", internalType: "uint256" },
|
|
2360
|
+
{ name: "_assetId", type: "bytes32", internalType: "bytes32" },
|
|
2361
|
+
{ name: "_transferData", type: "bytes", internalType: "bytes" }
|
|
2362
|
+
],
|
|
2363
|
+
outputs: [],
|
|
2364
|
+
stateMutability: "payable"
|
|
2365
|
+
},
|
|
2366
|
+
{
|
|
2367
|
+
type: "function",
|
|
2368
|
+
name: "finalizeDeposit",
|
|
2369
|
+
inputs: [
|
|
2370
|
+
{ name: "_l1Sender", type: "address", internalType: "address" },
|
|
2371
|
+
{ name: "_l2Receiver", type: "address", internalType: "address" },
|
|
2372
|
+
{ name: "_l1Token", type: "address", internalType: "address" },
|
|
2373
|
+
{ name: "_amount", type: "uint256", internalType: "uint256" },
|
|
2374
|
+
{ name: "_data", type: "bytes", internalType: "bytes" }
|
|
2375
|
+
],
|
|
2376
|
+
outputs: [],
|
|
2377
|
+
stateMutability: "payable"
|
|
2378
|
+
},
|
|
2379
|
+
{
|
|
2380
|
+
type: "function",
|
|
2381
|
+
name: "finalizeDepositLegacyBridge",
|
|
2382
|
+
inputs: [
|
|
2383
|
+
{ name: "_l1Sender", type: "address", internalType: "address" },
|
|
2384
|
+
{ name: "_l2Receiver", type: "address", internalType: "address" },
|
|
2385
|
+
{ name: "_l1Token", type: "address", internalType: "address" },
|
|
2386
|
+
{ name: "_amount", type: "uint256", internalType: "uint256" },
|
|
2387
|
+
{ name: "_data", type: "bytes", internalType: "bytes" }
|
|
2388
|
+
],
|
|
2389
|
+
outputs: [],
|
|
2390
|
+
stateMutability: "nonpayable"
|
|
2391
|
+
},
|
|
2392
|
+
{
|
|
2393
|
+
type: "function",
|
|
2394
|
+
name: "initL2",
|
|
2395
|
+
inputs: [
|
|
2396
|
+
{ name: "_l1ChainId", type: "uint256", internalType: "uint256" },
|
|
2397
|
+
{ name: "_eraChainId", type: "uint256", internalType: "uint256" },
|
|
2398
|
+
{ name: "_l1AssetRouter", type: "address", internalType: "address" },
|
|
2399
|
+
{ name: "_legacySharedBridge", type: "address", internalType: "address" },
|
|
2400
|
+
{ name: "_baseTokenAssetId", type: "bytes32", internalType: "bytes32" },
|
|
2401
|
+
{ name: "_aliasedOwner", type: "address", internalType: "address" }
|
|
2402
|
+
],
|
|
2403
|
+
outputs: [],
|
|
2404
|
+
stateMutability: "nonpayable"
|
|
2405
|
+
},
|
|
2406
|
+
{
|
|
2407
|
+
type: "function",
|
|
2408
|
+
name: "l1Bridge",
|
|
2409
|
+
inputs: [],
|
|
2410
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2411
|
+
stateMutability: "view"
|
|
2412
|
+
},
|
|
2413
|
+
{
|
|
2414
|
+
type: "function",
|
|
2415
|
+
name: "l1TokenAddress",
|
|
2416
|
+
inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
|
|
2417
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2418
|
+
stateMutability: "view"
|
|
2419
|
+
},
|
|
2420
|
+
{
|
|
2421
|
+
type: "function",
|
|
2422
|
+
name: "l2TokenAddress",
|
|
2423
|
+
inputs: [{ name: "_l1Token", type: "address", internalType: "address" }],
|
|
2424
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2425
|
+
stateMutability: "view"
|
|
2426
|
+
},
|
|
2427
|
+
{
|
|
2428
|
+
type: "function",
|
|
2429
|
+
name: "owner",
|
|
2430
|
+
inputs: [],
|
|
2431
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2432
|
+
stateMutability: "view"
|
|
2433
|
+
},
|
|
2434
|
+
{
|
|
2435
|
+
type: "function",
|
|
2436
|
+
name: "pause",
|
|
2437
|
+
inputs: [],
|
|
2438
|
+
outputs: [],
|
|
2439
|
+
stateMutability: "nonpayable"
|
|
2440
|
+
},
|
|
2441
|
+
{
|
|
2442
|
+
type: "function",
|
|
2443
|
+
name: "paused",
|
|
2444
|
+
inputs: [],
|
|
2445
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
2446
|
+
stateMutability: "view"
|
|
2447
|
+
},
|
|
2448
|
+
{
|
|
2449
|
+
type: "function",
|
|
2450
|
+
name: "pendingOwner",
|
|
2451
|
+
inputs: [],
|
|
2452
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2453
|
+
stateMutability: "view"
|
|
2454
|
+
},
|
|
2455
|
+
{
|
|
2456
|
+
type: "function",
|
|
2457
|
+
name: "renounceOwnership",
|
|
2458
|
+
inputs: [],
|
|
2459
|
+
outputs: [],
|
|
2460
|
+
stateMutability: "nonpayable"
|
|
2461
|
+
},
|
|
2462
|
+
{
|
|
2463
|
+
type: "function",
|
|
2464
|
+
name: "setAssetHandlerAddress",
|
|
2465
|
+
inputs: [
|
|
2466
|
+
{ name: "_originChainId", type: "uint256", internalType: "uint256" },
|
|
2467
|
+
{ name: "_assetId", type: "bytes32", internalType: "bytes32" },
|
|
2468
|
+
{ name: "_assetHandlerAddress", type: "address", internalType: "address" }
|
|
2469
|
+
],
|
|
2470
|
+
outputs: [],
|
|
2471
|
+
stateMutability: "nonpayable"
|
|
2472
|
+
},
|
|
2473
|
+
{
|
|
2474
|
+
type: "function",
|
|
2475
|
+
name: "setAssetHandlerAddressThisChain",
|
|
2476
|
+
inputs: [
|
|
2477
|
+
{ name: "_assetRegistrationData", type: "bytes32", internalType: "bytes32" },
|
|
2478
|
+
{ name: "_assetHandlerAddress", type: "address", internalType: "address" }
|
|
2479
|
+
],
|
|
2480
|
+
outputs: [],
|
|
2481
|
+
stateMutability: "nonpayable"
|
|
2482
|
+
},
|
|
2483
|
+
{
|
|
2484
|
+
type: "function",
|
|
2485
|
+
name: "setLegacyTokenAssetHandler",
|
|
2486
|
+
inputs: [{ name: "_assetId", type: "bytes32", internalType: "bytes32" }],
|
|
2487
|
+
outputs: [],
|
|
2488
|
+
stateMutability: "nonpayable"
|
|
2489
|
+
},
|
|
2490
|
+
{
|
|
2491
|
+
type: "function",
|
|
2492
|
+
name: "transferOwnership",
|
|
2493
|
+
inputs: [{ name: "newOwner", type: "address", internalType: "address" }],
|
|
2494
|
+
outputs: [],
|
|
2495
|
+
stateMutability: "nonpayable"
|
|
2496
|
+
},
|
|
2497
|
+
{
|
|
2498
|
+
type: "function",
|
|
2499
|
+
name: "unpause",
|
|
2500
|
+
inputs: [],
|
|
2501
|
+
outputs: [],
|
|
2502
|
+
stateMutability: "nonpayable"
|
|
2503
|
+
},
|
|
2504
|
+
{
|
|
2505
|
+
type: "function",
|
|
2506
|
+
name: "updateL2",
|
|
2507
|
+
inputs: [
|
|
2508
|
+
{ name: "_l1ChainId", type: "uint256", internalType: "uint256" },
|
|
2509
|
+
{ name: "_eraChainId", type: "uint256", internalType: "uint256" },
|
|
2510
|
+
{ name: "_l1AssetRouter", type: "address", internalType: "address" },
|
|
2511
|
+
{ name: "_legacySharedBridge", type: "address", internalType: "address" },
|
|
2512
|
+
{ name: "_baseTokenAssetId", type: "bytes32", internalType: "bytes32" }
|
|
2513
|
+
],
|
|
2514
|
+
outputs: [],
|
|
2515
|
+
stateMutability: "nonpayable"
|
|
2516
|
+
},
|
|
2517
|
+
{
|
|
2518
|
+
type: "function",
|
|
2519
|
+
name: "withdraw",
|
|
2520
|
+
inputs: [
|
|
2521
|
+
{ name: "_assetId", type: "bytes32", internalType: "bytes32" },
|
|
2522
|
+
{ name: "_assetData", type: "bytes", internalType: "bytes" }
|
|
2523
|
+
],
|
|
2524
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
2525
|
+
stateMutability: "nonpayable"
|
|
2526
|
+
},
|
|
2527
|
+
{
|
|
2528
|
+
type: "function",
|
|
2529
|
+
name: "withdraw",
|
|
2530
|
+
inputs: [
|
|
2531
|
+
{ name: "_l1Receiver", type: "address", internalType: "address" },
|
|
2532
|
+
{ name: "_l2Token", type: "address", internalType: "address" },
|
|
2533
|
+
{ name: "_amount", type: "uint256", internalType: "uint256" }
|
|
2534
|
+
],
|
|
2535
|
+
outputs: [],
|
|
2536
|
+
stateMutability: "nonpayable"
|
|
2537
|
+
},
|
|
2538
|
+
{
|
|
2539
|
+
type: "function",
|
|
2540
|
+
name: "withdrawLegacyBridge",
|
|
2541
|
+
inputs: [
|
|
2542
|
+
{ name: "_l1Receiver", type: "address", internalType: "address" },
|
|
2543
|
+
{ name: "_l2Token", type: "address", internalType: "address" },
|
|
2544
|
+
{ name: "_amount", type: "uint256", internalType: "uint256" },
|
|
2545
|
+
{ name: "_sender", type: "address", internalType: "address" }
|
|
2546
|
+
],
|
|
2547
|
+
outputs: [],
|
|
2548
|
+
stateMutability: "nonpayable"
|
|
2549
|
+
},
|
|
2550
|
+
{
|
|
2551
|
+
type: "event",
|
|
2552
|
+
name: "AssetDeploymentTrackerRegistered",
|
|
2553
|
+
inputs: [
|
|
2554
|
+
{ name: "assetId", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2555
|
+
{ name: "additionalData", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2556
|
+
{
|
|
2557
|
+
name: "assetDeploymentTracker",
|
|
2558
|
+
type: "address",
|
|
2559
|
+
indexed: false,
|
|
2560
|
+
internalType: "address"
|
|
2561
|
+
}
|
|
2562
|
+
],
|
|
2563
|
+
anonymous: false
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
type: "event",
|
|
2567
|
+
name: "AssetHandlerRegistered",
|
|
2568
|
+
inputs: [
|
|
2569
|
+
{ name: "assetId", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2570
|
+
{
|
|
2571
|
+
name: "_assetHandlerAddress",
|
|
2572
|
+
type: "address",
|
|
2573
|
+
indexed: true,
|
|
2574
|
+
internalType: "address"
|
|
2575
|
+
}
|
|
2576
|
+
],
|
|
2577
|
+
anonymous: false
|
|
2578
|
+
},
|
|
2579
|
+
{
|
|
2580
|
+
type: "event",
|
|
2581
|
+
name: "BridgehubDepositBaseTokenInitiated",
|
|
2582
|
+
inputs: [
|
|
2583
|
+
{ name: "chainId", type: "uint256", indexed: true, internalType: "uint256" },
|
|
2584
|
+
{ name: "from", type: "address", indexed: true, internalType: "address" },
|
|
2585
|
+
{ name: "assetId", type: "bytes32", indexed: false, internalType: "bytes32" },
|
|
2586
|
+
{ name: "amount", type: "uint256", indexed: false, internalType: "uint256" }
|
|
2587
|
+
],
|
|
2588
|
+
anonymous: false
|
|
2589
|
+
},
|
|
2590
|
+
{
|
|
2591
|
+
type: "event",
|
|
2592
|
+
name: "BridgehubDepositInitiated",
|
|
2593
|
+
inputs: [
|
|
2594
|
+
{ name: "chainId", type: "uint256", indexed: true, internalType: "uint256" },
|
|
2595
|
+
{ name: "txDataHash", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2596
|
+
{ name: "from", type: "address", indexed: true, internalType: "address" },
|
|
2597
|
+
{ name: "assetId", type: "bytes32", indexed: false, internalType: "bytes32" },
|
|
2598
|
+
{ name: "bridgeMintCalldata", type: "bytes", indexed: false, internalType: "bytes" }
|
|
2599
|
+
],
|
|
2600
|
+
anonymous: false
|
|
2601
|
+
},
|
|
2602
|
+
{
|
|
2603
|
+
type: "event",
|
|
2604
|
+
name: "BridgehubWithdrawalInitiated",
|
|
2605
|
+
inputs: [
|
|
2606
|
+
{ name: "chainId", type: "uint256", indexed: false, internalType: "uint256" },
|
|
2607
|
+
{ name: "sender", type: "address", indexed: true, internalType: "address" },
|
|
2608
|
+
{ name: "assetId", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2609
|
+
{ name: "assetDataHash", type: "bytes32", indexed: false, internalType: "bytes32" }
|
|
2610
|
+
],
|
|
2611
|
+
anonymous: false
|
|
2612
|
+
},
|
|
2613
|
+
{
|
|
2614
|
+
type: "event",
|
|
2615
|
+
name: "DepositFinalizedAssetRouter",
|
|
2616
|
+
inputs: [
|
|
2617
|
+
{ name: "chainId", type: "uint256", indexed: true, internalType: "uint256" },
|
|
2618
|
+
{ name: "assetId", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2619
|
+
{ name: "assetData", type: "bytes", indexed: false, internalType: "bytes" }
|
|
2620
|
+
],
|
|
2621
|
+
anonymous: false
|
|
2622
|
+
},
|
|
2623
|
+
{
|
|
2624
|
+
type: "event",
|
|
2625
|
+
name: "Initialized",
|
|
2626
|
+
inputs: [{ name: "version", type: "uint8", indexed: false, internalType: "uint8" }],
|
|
2627
|
+
anonymous: false
|
|
2628
|
+
},
|
|
2629
|
+
{
|
|
2630
|
+
type: "event",
|
|
2631
|
+
name: "OwnershipTransferStarted",
|
|
2632
|
+
inputs: [
|
|
2633
|
+
{ name: "previousOwner", type: "address", indexed: true, internalType: "address" },
|
|
2634
|
+
{ name: "newOwner", type: "address", indexed: true, internalType: "address" }
|
|
2635
|
+
],
|
|
2636
|
+
anonymous: false
|
|
2637
|
+
},
|
|
2638
|
+
{
|
|
2639
|
+
type: "event",
|
|
2640
|
+
name: "OwnershipTransferred",
|
|
2641
|
+
inputs: [
|
|
2642
|
+
{ name: "previousOwner", type: "address", indexed: true, internalType: "address" },
|
|
2643
|
+
{ name: "newOwner", type: "address", indexed: true, internalType: "address" }
|
|
2644
|
+
],
|
|
2645
|
+
anonymous: false
|
|
2646
|
+
},
|
|
2647
|
+
{
|
|
2648
|
+
type: "event",
|
|
2649
|
+
name: "Paused",
|
|
2650
|
+
inputs: [{ name: "account", type: "address", indexed: false, internalType: "address" }],
|
|
2651
|
+
anonymous: false
|
|
2652
|
+
},
|
|
2653
|
+
{
|
|
2654
|
+
type: "event",
|
|
2655
|
+
name: "Unpaused",
|
|
2656
|
+
inputs: [{ name: "account", type: "address", indexed: false, internalType: "address" }],
|
|
2657
|
+
anonymous: false
|
|
2658
|
+
},
|
|
2659
|
+
{
|
|
2660
|
+
type: "event",
|
|
2661
|
+
name: "WithdrawalInitiatedAssetRouter",
|
|
2662
|
+
inputs: [
|
|
2663
|
+
{ name: "chainId", type: "uint256", indexed: false, internalType: "uint256" },
|
|
2664
|
+
{ name: "l2Sender", type: "address", indexed: true, internalType: "address" },
|
|
2665
|
+
{ name: "assetId", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
2666
|
+
{ name: "assetData", type: "bytes", indexed: false, internalType: "bytes" }
|
|
2667
|
+
],
|
|
2668
|
+
anonymous: false
|
|
2669
|
+
},
|
|
2670
|
+
{ type: "error", name: "AmountMustBeGreaterThanZero", inputs: [] },
|
|
2671
|
+
{
|
|
2672
|
+
type: "error",
|
|
2673
|
+
name: "AssetIdNotSupported",
|
|
2674
|
+
inputs: [{ name: "assetId", type: "bytes32", internalType: "bytes32" }]
|
|
2675
|
+
},
|
|
2676
|
+
{ type: "error", name: "EmptyAddress", inputs: [] },
|
|
2677
|
+
{
|
|
2678
|
+
type: "error",
|
|
2679
|
+
name: "InvalidCaller",
|
|
2680
|
+
inputs: [{ name: "", type: "address", internalType: "address" }]
|
|
2681
|
+
},
|
|
2682
|
+
{ type: "error", name: "InvalidNTVBurnData", inputs: [] },
|
|
2683
|
+
{ type: "error", name: "NotInitializedReentrancyGuard", inputs: [] },
|
|
2684
|
+
{ type: "error", name: "Reentrancy", inputs: [] },
|
|
2685
|
+
{ type: "error", name: "SlotOccupied", inputs: [] },
|
|
2686
|
+
{ type: "error", name: "TokenNotLegacy", inputs: [] },
|
|
2687
|
+
{
|
|
2688
|
+
type: "error",
|
|
2689
|
+
name: "Unauthorized",
|
|
2690
|
+
inputs: [{ name: "caller", type: "address", internalType: "address" }]
|
|
2273
2691
|
}
|
|
2274
2692
|
];
|
|
2275
|
-
var
|
|
2693
|
+
var IL2AssetRouter_default = IL2AssetRouterABI;
|
|
2276
2694
|
|
|
2277
2695
|
// src/core/internal/abis/L1NativeTokenVault.ts
|
|
2278
2696
|
var L1NativeTokenVaultABI = [
|
|
@@ -3267,56 +3685,69 @@ var IERC20_default = IERC20ABI;
|
|
|
3267
3685
|
// src/core/internal/abis/IERC7786Attributes.ts
|
|
3268
3686
|
var IERC7786AttributesABI = [
|
|
3269
3687
|
{
|
|
3688
|
+
type: "function",
|
|
3689
|
+
name: "executionAddress",
|
|
3270
3690
|
inputs: [
|
|
3271
3691
|
{
|
|
3272
|
-
internalType: "bytes",
|
|
3273
3692
|
name: "_executionAddress",
|
|
3274
|
-
type: "bytes"
|
|
3693
|
+
type: "bytes",
|
|
3694
|
+
internalType: "bytes"
|
|
3275
3695
|
}
|
|
3276
3696
|
],
|
|
3277
|
-
name: "executionAddress",
|
|
3278
3697
|
outputs: [],
|
|
3279
|
-
stateMutability: "pure"
|
|
3280
|
-
type: "function"
|
|
3698
|
+
stateMutability: "pure"
|
|
3281
3699
|
},
|
|
3282
3700
|
{
|
|
3701
|
+
type: "function",
|
|
3702
|
+
name: "indirectCall",
|
|
3283
3703
|
inputs: [
|
|
3284
3704
|
{
|
|
3285
|
-
internalType: "uint256",
|
|
3286
3705
|
name: "_indirectCallMessageValue",
|
|
3287
|
-
type: "uint256"
|
|
3706
|
+
type: "uint256",
|
|
3707
|
+
internalType: "uint256"
|
|
3288
3708
|
}
|
|
3289
3709
|
],
|
|
3290
|
-
name: "indirectCall",
|
|
3291
3710
|
outputs: [],
|
|
3292
|
-
stateMutability: "pure"
|
|
3293
|
-
type: "function"
|
|
3711
|
+
stateMutability: "pure"
|
|
3294
3712
|
},
|
|
3295
3713
|
{
|
|
3714
|
+
type: "function",
|
|
3715
|
+
name: "interopCallValue",
|
|
3296
3716
|
inputs: [
|
|
3297
3717
|
{
|
|
3298
|
-
internalType: "uint256",
|
|
3299
3718
|
name: "_interopCallValue",
|
|
3300
|
-
type: "uint256"
|
|
3719
|
+
type: "uint256",
|
|
3720
|
+
internalType: "uint256"
|
|
3301
3721
|
}
|
|
3302
3722
|
],
|
|
3303
|
-
name: "interopCallValue",
|
|
3304
3723
|
outputs: [],
|
|
3305
|
-
stateMutability: "pure"
|
|
3306
|
-
type: "function"
|
|
3724
|
+
stateMutability: "pure"
|
|
3307
3725
|
},
|
|
3308
3726
|
{
|
|
3727
|
+
type: "function",
|
|
3728
|
+
name: "unbundlerAddress",
|
|
3309
3729
|
inputs: [
|
|
3310
3730
|
{
|
|
3311
|
-
internalType: "bytes",
|
|
3312
3731
|
name: "_unbundlerAddress",
|
|
3313
|
-
type: "bytes"
|
|
3732
|
+
type: "bytes",
|
|
3733
|
+
internalType: "bytes"
|
|
3314
3734
|
}
|
|
3315
3735
|
],
|
|
3316
|
-
name: "unbundlerAddress",
|
|
3317
3736
|
outputs: [],
|
|
3318
|
-
stateMutability: "pure"
|
|
3319
|
-
|
|
3737
|
+
stateMutability: "pure"
|
|
3738
|
+
},
|
|
3739
|
+
{
|
|
3740
|
+
type: "function",
|
|
3741
|
+
name: "useFixedFee",
|
|
3742
|
+
inputs: [
|
|
3743
|
+
{
|
|
3744
|
+
name: "_useFixed",
|
|
3745
|
+
type: "bool",
|
|
3746
|
+
internalType: "bool"
|
|
3747
|
+
}
|
|
3748
|
+
],
|
|
3749
|
+
outputs: [],
|
|
3750
|
+
stateMutability: "pure"
|
|
3320
3751
|
}
|
|
3321
3752
|
];
|
|
3322
3753
|
var IERC7786Attributes_default = IERC7786AttributesABI;
|
|
@@ -4164,6 +4595,11 @@ var IInteropCenterABI = [
|
|
|
4164
4595
|
type: "uint256",
|
|
4165
4596
|
internalType: "uint256"
|
|
4166
4597
|
},
|
|
4598
|
+
{
|
|
4599
|
+
name: "destinationBaseTokenAssetId",
|
|
4600
|
+
type: "bytes32",
|
|
4601
|
+
internalType: "bytes32"
|
|
4602
|
+
},
|
|
4167
4603
|
{
|
|
4168
4604
|
name: "interopBundleSalt",
|
|
4169
4605
|
type: "bytes32",
|
|
@@ -5547,11 +5983,10 @@ async function quoteL1Gas(input) {
|
|
|
5547
5983
|
const est = await estimator.estimateGas(tx);
|
|
5548
5984
|
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
5549
5985
|
return makeGasQuote({ gasLimit: buffered, maxFeePerGas, maxPriorityFeePerGas });
|
|
5550
|
-
} catch
|
|
5986
|
+
} catch {
|
|
5551
5987
|
if (fallbackGasLimit != null) {
|
|
5552
5988
|
return makeGasQuote({ gasLimit: fallbackGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
5553
5989
|
}
|
|
5554
|
-
console.warn("L1 gas estimation failed", err);
|
|
5555
5990
|
return void 0;
|
|
5556
5991
|
}
|
|
5557
5992
|
}
|
|
@@ -5589,8 +6024,7 @@ async function quoteL2Gas(input) {
|
|
|
5589
6024
|
maxFeePerGas,
|
|
5590
6025
|
gasPerPubdata: pp
|
|
5591
6026
|
});
|
|
5592
|
-
} catch
|
|
5593
|
-
console.warn("L2 gas estimation failed", err);
|
|
6027
|
+
} catch {
|
|
5594
6028
|
return makeGasQuote({
|
|
5595
6029
|
gasLimit: l2GasLimit ?? 0n,
|
|
5596
6030
|
maxFeePerGas,
|
|
@@ -5708,7 +6142,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
5708
6142
|
throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
5709
6143
|
}
|
|
5710
6144
|
}
|
|
5711
|
-
function
|
|
6145
|
+
function wrap7(operation, fn, opts) {
|
|
5712
6146
|
return run("INTERNAL", operation, fn, opts);
|
|
5713
6147
|
}
|
|
5714
6148
|
function wrapAs9(kind, operation, fn, opts) {
|
|
@@ -5716,7 +6150,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
5716
6150
|
}
|
|
5717
6151
|
async function toResult3(operation, fn, opts) {
|
|
5718
6152
|
try {
|
|
5719
|
-
const value = await
|
|
6153
|
+
const value = await wrap7(operation, fn, opts);
|
|
5720
6154
|
return { ok: true, value };
|
|
5721
6155
|
} catch (e) {
|
|
5722
6156
|
const shaped = isZKsyncError(e) ? e : toZKsyncError2(
|
|
@@ -5732,7 +6166,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
5732
6166
|
return { ok: false, error: shaped };
|
|
5733
6167
|
}
|
|
5734
6168
|
}
|
|
5735
|
-
return { wrap:
|
|
6169
|
+
return { wrap: wrap7, wrapAs: wrapAs9, toResult: toResult3 };
|
|
5736
6170
|
}
|
|
5737
6171
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
5738
6172
|
}
|
|
@@ -5936,8 +6370,22 @@ async function determineNonBaseL2Gas(input) {
|
|
|
5936
6370
|
try {
|
|
5937
6371
|
const l2TokenAddress = input.knownL2Token ?? (ctx.tokens ? await ctx.tokens.toL2Address(l1Token) : await (await ctx.contracts.l2NativeTokenVault()).l2TokenAddress(l1Token));
|
|
5938
6372
|
if (l2TokenAddress === ZERO_L2_TOKEN_ADDRESS) {
|
|
6373
|
+
if (input.undeployedGasLimit != null) {
|
|
6374
|
+
return quoteL2Gas2({
|
|
6375
|
+
ctx,
|
|
6376
|
+
route,
|
|
6377
|
+
overrideGasLimit: input.undeployedGasLimit
|
|
6378
|
+
});
|
|
6379
|
+
}
|
|
5939
6380
|
return fallbackQuote();
|
|
5940
6381
|
}
|
|
6382
|
+
if (input.priorityFloorGasLimit != null) {
|
|
6383
|
+
return quoteL2Gas2({
|
|
6384
|
+
ctx,
|
|
6385
|
+
route,
|
|
6386
|
+
overrideGasLimit: input.priorityFloorGasLimit
|
|
6387
|
+
});
|
|
6388
|
+
}
|
|
5941
6389
|
const modelTx = {
|
|
5942
6390
|
to: input.modelTx?.to ?? ctx.sender,
|
|
5943
6391
|
from: input.modelTx?.from ?? ctx.sender,
|
|
@@ -5953,8 +6401,7 @@ async function determineNonBaseL2Gas(input) {
|
|
|
5953
6401
|
return fallbackQuote();
|
|
5954
6402
|
}
|
|
5955
6403
|
return gas;
|
|
5956
|
-
} catch
|
|
5957
|
-
console.warn("Failed to determine non-base deposit L2 gas; defaulting to safe gas limit.", err);
|
|
6404
|
+
} catch {
|
|
5958
6405
|
return fallbackQuote();
|
|
5959
6406
|
}
|
|
5960
6407
|
}
|
|
@@ -5971,7 +6418,9 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
5971
6418
|
route: "eth-nonbase",
|
|
5972
6419
|
l1Token: input.ctx.resolvedToken?.l1 ?? FORMAL_ETH_ADDRESS,
|
|
5973
6420
|
knownL2Token: input.ctx.resolvedToken?.l2,
|
|
5974
|
-
modelTx: input.modelTx
|
|
6421
|
+
modelTx: input.modelTx,
|
|
6422
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6423
|
+
undeployedGasLimit: input.undeployedGasLimit
|
|
5975
6424
|
});
|
|
5976
6425
|
}
|
|
5977
6426
|
|
|
@@ -6003,41 +6452,112 @@ function buildFeeBreakdown(p) {
|
|
|
6003
6452
|
};
|
|
6004
6453
|
}
|
|
6005
6454
|
|
|
6455
|
+
// src/core/resources/deposits/priority.ts
|
|
6456
|
+
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6457
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 6n;
|
|
6458
|
+
var maxBigInt = (a, b) => a > b ? a : b;
|
|
6459
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6460
|
+
function derivePriorityTxGasBreakdown(input) {
|
|
6461
|
+
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
6462
|
+
const minBodyGas = maxBigInt(
|
|
6463
|
+
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
6464
|
+
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
6465
|
+
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
6466
|
+
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
6467
|
+
L1_TX_MIN_L2_GAS_BASE
|
|
6468
|
+
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
6469
|
+
const overhead = maxBigInt(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
6470
|
+
const derivedBodyGas = minBodyGas;
|
|
6471
|
+
return {
|
|
6472
|
+
encodedLength: input.encodedLength,
|
|
6473
|
+
minBodyGas,
|
|
6474
|
+
overhead,
|
|
6475
|
+
derivedBodyGas,
|
|
6476
|
+
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
6477
|
+
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
6478
|
+
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
6479
|
+
};
|
|
6480
|
+
}
|
|
6481
|
+
function derivePriorityBodyGasEstimateCap(input) {
|
|
6482
|
+
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
6483
|
+
}
|
|
6484
|
+
|
|
6485
|
+
// src/adapters/ethers/resources/deposits/routes/priority.ts
|
|
6486
|
+
var EMPTY_BYTES = "0x";
|
|
6487
|
+
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
6488
|
+
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)";
|
|
6489
|
+
function hexByteLength(hex) {
|
|
6490
|
+
return BigInt(Math.max(hex.length - 2, 0) / 2);
|
|
6491
|
+
}
|
|
6492
|
+
function getPriorityTxEncodedLength(input) {
|
|
6493
|
+
const encoded = ethers.AbiCoder.defaultAbiCoder().encode(
|
|
6494
|
+
[L2_CANONICAL_TRANSACTION_TUPLE],
|
|
6495
|
+
[
|
|
6496
|
+
[
|
|
6497
|
+
0n,
|
|
6498
|
+
BigInt(input.sender),
|
|
6499
|
+
BigInt(input.l2Contract),
|
|
6500
|
+
0n,
|
|
6501
|
+
input.gasPerPubdata,
|
|
6502
|
+
0n,
|
|
6503
|
+
0n,
|
|
6504
|
+
0n,
|
|
6505
|
+
0n,
|
|
6506
|
+
input.l2Value,
|
|
6507
|
+
ZERO_RESERVED_WORDS,
|
|
6508
|
+
input.l2Calldata,
|
|
6509
|
+
EMPTY_BYTES,
|
|
6510
|
+
input.factoryDepsHashes ?? [],
|
|
6511
|
+
EMPTY_BYTES,
|
|
6512
|
+
EMPTY_BYTES
|
|
6513
|
+
]
|
|
6514
|
+
]
|
|
6515
|
+
);
|
|
6516
|
+
return hexByteLength(encoded);
|
|
6517
|
+
}
|
|
6518
|
+
function getPriorityTxGasBreakdown(input) {
|
|
6519
|
+
return derivePriorityTxGasBreakdown({
|
|
6520
|
+
encodedLength: getPriorityTxEncodedLength(input),
|
|
6521
|
+
gasPerPubdata: input.gasPerPubdata,
|
|
6522
|
+
factoryDepsCount: BigInt(input.factoryDepsHashes?.length ?? 0)
|
|
6523
|
+
});
|
|
6524
|
+
}
|
|
6525
|
+
|
|
6006
6526
|
// src/adapters/ethers/resources/deposits/routes/eth.ts
|
|
6527
|
+
var EMPTY_BYTES2 = "0x";
|
|
6007
6528
|
function routeEthDirect() {
|
|
6008
6529
|
return {
|
|
6009
6530
|
async build(p, ctx) {
|
|
6010
6531
|
const bh = await ctx.contracts.bridgehub();
|
|
6011
|
-
const
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6532
|
+
const l2Contract = p.to ?? ctx.sender;
|
|
6533
|
+
const l2Value = p.amount;
|
|
6534
|
+
const l2Calldata = EMPTY_BYTES2;
|
|
6535
|
+
const priorityFloorBreakdown = getPriorityTxGasBreakdown({
|
|
6536
|
+
sender: ctx.sender,
|
|
6537
|
+
l2Contract,
|
|
6538
|
+
l2Value,
|
|
6539
|
+
l2Calldata,
|
|
6540
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
6541
|
+
});
|
|
6542
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? priorityFloorBreakdown.derivedL2GasLimit;
|
|
6017
6543
|
const l2GasParams = await quoteL2Gas2({
|
|
6018
6544
|
ctx,
|
|
6019
6545
|
route: "eth-base",
|
|
6020
|
-
|
|
6021
|
-
overrideGasLimit: ctx.l2GasLimit,
|
|
6022
|
-
stateOverrides: {
|
|
6023
|
-
[ctx.sender]: {
|
|
6024
|
-
balance: "0xffffffffffffffffffff"
|
|
6025
|
-
}
|
|
6026
|
-
}
|
|
6546
|
+
overrideGasLimit: quotedL2GasLimit
|
|
6027
6547
|
});
|
|
6028
6548
|
if (!l2GasParams) {
|
|
6029
6549
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
6030
6550
|
}
|
|
6031
6551
|
const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
|
|
6032
|
-
const mintValue = baseCost + ctx.operatorTip +
|
|
6552
|
+
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
6033
6553
|
const req = buildDirectRequestStruct({
|
|
6034
6554
|
chainId: ctx.chainIdL2,
|
|
6035
6555
|
mintValue,
|
|
6036
6556
|
l2GasLimit: l2GasParams.gasLimit,
|
|
6037
6557
|
gasPerPubdata: ctx.gasPerPubdata,
|
|
6038
6558
|
refundRecipient: ctx.refundRecipient,
|
|
6039
|
-
l2Contract
|
|
6040
|
-
l2Value
|
|
6559
|
+
l2Contract,
|
|
6560
|
+
l2Value
|
|
6041
6561
|
});
|
|
6042
6562
|
const data = bh.interface.encodeFunctionData("requestL2TransactionDirect", [req]);
|
|
6043
6563
|
const l1TxCandidate = {
|
|
@@ -6087,6 +6607,53 @@ var ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000
|
|
|
6087
6607
|
|
|
6088
6608
|
// src/adapters/ethers/resources/deposits/routes/erc20-nonbase.ts
|
|
6089
6609
|
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
6610
|
+
var ZERO_L2_TOKEN_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
6611
|
+
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
6612
|
+
async function getPriorityGasModel(input) {
|
|
6613
|
+
try {
|
|
6614
|
+
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
6615
|
+
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
6616
|
+
const { chainId: l1ChainId } = await input.ctx.client.l1.getNetwork();
|
|
6617
|
+
const isFirstBridge = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID || input.ctx.resolvedToken.originChainId === 0n;
|
|
6618
|
+
const erc20MetadataOriginChainId = isFirstBridge ? BigInt(l1ChainId) : input.ctx.resolvedToken.originChainId;
|
|
6619
|
+
const erc20Metadata = await l1NativeTokenVault.getERC20Getters(
|
|
6620
|
+
input.token,
|
|
6621
|
+
erc20MetadataOriginChainId
|
|
6622
|
+
);
|
|
6623
|
+
const bridgeMintCalldata = ethers.AbiCoder.defaultAbiCoder().encode(
|
|
6624
|
+
["address", "address", "address", "uint256", "bytes"],
|
|
6625
|
+
[input.ctx.sender, input.receiver, input.token, input.amount, erc20Metadata]
|
|
6626
|
+
);
|
|
6627
|
+
const l2Calldata = isFirstBridge ? new ethers.Interface(IL2AssetRouter_default).encodeFunctionData(
|
|
6628
|
+
"finalizeDeposit(address,address,address,uint256,bytes)",
|
|
6629
|
+
[input.ctx.sender, input.receiver, input.token, input.amount, erc20Metadata]
|
|
6630
|
+
) : await (() => {
|
|
6631
|
+
return l1AssetRouter.getDepositCalldata(
|
|
6632
|
+
input.ctx.sender,
|
|
6633
|
+
input.ctx.resolvedToken.assetId,
|
|
6634
|
+
bridgeMintCalldata
|
|
6635
|
+
);
|
|
6636
|
+
})();
|
|
6637
|
+
const priorityFloorBreakdown = getPriorityTxGasBreakdown({
|
|
6638
|
+
sender: input.ctx.l1AssetRouter,
|
|
6639
|
+
l2Contract: L2_ASSET_ROUTER_ADDRESS,
|
|
6640
|
+
l2Value: 0n,
|
|
6641
|
+
l2Calldata,
|
|
6642
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
6643
|
+
});
|
|
6644
|
+
const model = {
|
|
6645
|
+
priorityFloorGasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
6646
|
+
};
|
|
6647
|
+
if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS2) {
|
|
6648
|
+
model.undeployedGasLimit = derivePriorityBodyGasEstimateCap({
|
|
6649
|
+
minBodyGas: priorityFloorBreakdown.minBodyGas
|
|
6650
|
+
}) + priorityFloorBreakdown.overhead;
|
|
6651
|
+
}
|
|
6652
|
+
return model;
|
|
6653
|
+
} catch {
|
|
6654
|
+
return {};
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6090
6657
|
function routeErc20NonBase() {
|
|
6091
6658
|
return {
|
|
6092
6659
|
async preflight(p, ctx) {
|
|
@@ -6107,11 +6674,29 @@ function routeErc20NonBase() {
|
|
|
6107
6674
|
const l1Signer = ctx.client.getL1Signer();
|
|
6108
6675
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
6109
6676
|
const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
|
|
6677
|
+
const receiver = p.to ?? ctx.sender;
|
|
6678
|
+
const secondBridgeCalldata = await wrapAs2(
|
|
6679
|
+
"INTERNAL",
|
|
6680
|
+
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
6681
|
+
() => Promise.resolve(encodeSecondBridgeErc20Args(p.token, p.amount, receiver)),
|
|
6682
|
+
{
|
|
6683
|
+
ctx: { where: "encodeSecondBridgeErc20Args" },
|
|
6684
|
+
message: "Failed to encode bridging calldata."
|
|
6685
|
+
}
|
|
6686
|
+
);
|
|
6687
|
+
const priorityGasModel = await getPriorityGasModel({
|
|
6688
|
+
ctx,
|
|
6689
|
+
token: p.token,
|
|
6690
|
+
amount: p.amount,
|
|
6691
|
+
receiver
|
|
6692
|
+
});
|
|
6110
6693
|
const l2GasParams = await determineErc20L2Gas({
|
|
6111
6694
|
ctx,
|
|
6112
6695
|
l1Token: p.token,
|
|
6696
|
+
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
6697
|
+
undeployedGasLimit: priorityGasModel.undeployedGasLimit,
|
|
6113
6698
|
modelTx: {
|
|
6114
|
-
to:
|
|
6699
|
+
to: receiver,
|
|
6115
6700
|
from: ctx.sender,
|
|
6116
6701
|
data: "0x",
|
|
6117
6702
|
value: 0n
|
|
@@ -6173,15 +6758,6 @@ function routeErc20NonBase() {
|
|
|
6173
6758
|
});
|
|
6174
6759
|
}
|
|
6175
6760
|
}
|
|
6176
|
-
const secondBridgeCalldata = await wrapAs2(
|
|
6177
|
-
"INTERNAL",
|
|
6178
|
-
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
6179
|
-
() => Promise.resolve(encodeSecondBridgeErc20Args(p.token, p.amount, p.to ?? ctx.sender)),
|
|
6180
|
-
{
|
|
6181
|
-
ctx: { where: "encodeSecondBridgeErc20Args" },
|
|
6182
|
-
message: "Failed to encode bridging calldata."
|
|
6183
|
-
}
|
|
6184
|
-
);
|
|
6185
6761
|
const requestStruct = {
|
|
6186
6762
|
chainId: ctx.chainIdL2,
|
|
6187
6763
|
mintValue,
|
|
@@ -6238,7 +6814,68 @@ function routeErc20NonBase() {
|
|
|
6238
6814
|
}
|
|
6239
6815
|
};
|
|
6240
6816
|
}
|
|
6817
|
+
|
|
6818
|
+
// src/core/codec/ntv.ts
|
|
6819
|
+
function createNTVCodec(deps) {
|
|
6820
|
+
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
6821
|
+
const encoded = deps.encode(
|
|
6822
|
+
["uint256", "address", "address"],
|
|
6823
|
+
[originChainId, ntvAddress, tokenAddress]
|
|
6824
|
+
);
|
|
6825
|
+
return deps.keccak256(encoded);
|
|
6826
|
+
}
|
|
6827
|
+
return {
|
|
6828
|
+
encodeAssetId
|
|
6829
|
+
};
|
|
6830
|
+
}
|
|
6831
|
+
|
|
6832
|
+
// src/adapters/ethers/resources/deposits/routes/eth-nonbase.ts
|
|
6241
6833
|
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
6834
|
+
var ZERO_L2_TOKEN_ADDRESS3 = "0x0000000000000000000000000000000000000000";
|
|
6835
|
+
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
6836
|
+
var ntvCodec = createNTVCodec({
|
|
6837
|
+
encode: (types, values) => ethers.AbiCoder.defaultAbiCoder().encode(types, values),
|
|
6838
|
+
keccak256: (data) => ethers.keccak256(data)
|
|
6839
|
+
});
|
|
6840
|
+
async function getPriorityGasModel2(input) {
|
|
6841
|
+
try {
|
|
6842
|
+
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
6843
|
+
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
6844
|
+
const originChainId = input.ctx.resolvedToken.originChainId !== 0n ? input.ctx.resolvedToken.originChainId : BigInt((await input.ctx.client.l1.getNetwork()).chainId);
|
|
6845
|
+
const resolvedAssetId = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID2 ? ntvCodec.encodeAssetId(originChainId, L2_NATIVE_TOKEN_VAULT_ADDRESS, ETH_ADDRESS) : input.ctx.resolvedToken.assetId;
|
|
6846
|
+
const erc20Metadata = await l1NativeTokenVault.getERC20Getters(
|
|
6847
|
+
ETH_ADDRESS,
|
|
6848
|
+
originChainId
|
|
6849
|
+
);
|
|
6850
|
+
const bridgeMintCalldata = ethers.AbiCoder.defaultAbiCoder().encode(
|
|
6851
|
+
["address", "address", "address", "uint256", "bytes"],
|
|
6852
|
+
[input.ctx.sender, input.receiver, ETH_ADDRESS, input.amount, erc20Metadata]
|
|
6853
|
+
);
|
|
6854
|
+
const l2Calldata = await l1AssetRouter.getDepositCalldata(
|
|
6855
|
+
input.ctx.sender,
|
|
6856
|
+
resolvedAssetId,
|
|
6857
|
+
bridgeMintCalldata
|
|
6858
|
+
);
|
|
6859
|
+
const priorityFloorBreakdown = getPriorityTxGasBreakdown({
|
|
6860
|
+
sender: input.ctx.l1AssetRouter,
|
|
6861
|
+
l2Contract: L2_ASSET_ROUTER_ADDRESS,
|
|
6862
|
+
l2Value: 0n,
|
|
6863
|
+
l2Calldata,
|
|
6864
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
6865
|
+
});
|
|
6866
|
+
const model = {
|
|
6867
|
+
priorityFloorGasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
6868
|
+
};
|
|
6869
|
+
if (input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS3) {
|
|
6870
|
+
model.undeployedGasLimit = derivePriorityBodyGasEstimateCap({
|
|
6871
|
+
minBodyGas: priorityFloorBreakdown.minBodyGas
|
|
6872
|
+
}) + priorityFloorBreakdown.overhead;
|
|
6873
|
+
}
|
|
6874
|
+
return model;
|
|
6875
|
+
} catch {
|
|
6876
|
+
return {};
|
|
6877
|
+
}
|
|
6878
|
+
}
|
|
6242
6879
|
function routeEthNonBase() {
|
|
6243
6880
|
return {
|
|
6244
6881
|
async preflight(p, ctx) {
|
|
@@ -6287,15 +6924,23 @@ function routeEthNonBase() {
|
|
|
6287
6924
|
async build(p, ctx) {
|
|
6288
6925
|
const l1Signer = ctx.client.getL1Signer();
|
|
6289
6926
|
const baseToken = ctx.baseTokenL1;
|
|
6927
|
+
const receiver = p.to ?? ctx.sender;
|
|
6928
|
+
const priorityGasModel = await getPriorityGasModel2({
|
|
6929
|
+
ctx,
|
|
6930
|
+
amount: p.amount,
|
|
6931
|
+
receiver
|
|
6932
|
+
});
|
|
6290
6933
|
const l2TxModel = {
|
|
6291
|
-
to:
|
|
6934
|
+
to: receiver,
|
|
6292
6935
|
from: ctx.sender,
|
|
6293
6936
|
data: "0x",
|
|
6294
6937
|
value: 0n
|
|
6295
6938
|
};
|
|
6296
6939
|
const l2GasParams = await determineEthNonBaseL2Gas({
|
|
6297
6940
|
ctx,
|
|
6298
|
-
modelTx: l2TxModel
|
|
6941
|
+
modelTx: l2TxModel,
|
|
6942
|
+
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
6943
|
+
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
6299
6944
|
});
|
|
6300
6945
|
if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
|
|
6301
6946
|
const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
|
|
@@ -6329,12 +6974,12 @@ function routeEthNonBase() {
|
|
|
6329
6974
|
const secondBridgeCalldata = await wrapAs3(
|
|
6330
6975
|
"INTERNAL",
|
|
6331
6976
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
6332
|
-
() => Promise.resolve(encodeSecondBridgeEthArgs(p.amount,
|
|
6977
|
+
() => Promise.resolve(encodeSecondBridgeEthArgs(p.amount, receiver)),
|
|
6333
6978
|
{
|
|
6334
6979
|
ctx: {
|
|
6335
6980
|
where: "encodeSecondBridgeEthArgs",
|
|
6336
6981
|
amount: p.amount.toString(),
|
|
6337
|
-
to:
|
|
6982
|
+
to: receiver
|
|
6338
6983
|
}
|
|
6339
6984
|
}
|
|
6340
6985
|
);
|
|
@@ -6395,6 +7040,7 @@ function routeEthNonBase() {
|
|
|
6395
7040
|
};
|
|
6396
7041
|
}
|
|
6397
7042
|
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
7043
|
+
var EMPTY_BYTES3 = "0x";
|
|
6398
7044
|
function routeErc20Base() {
|
|
6399
7045
|
return {
|
|
6400
7046
|
async preflight(p, ctx) {
|
|
@@ -6425,17 +7071,21 @@ function routeErc20Base() {
|
|
|
6425
7071
|
async build(p, ctx) {
|
|
6426
7072
|
const l1Signer = ctx.client.getL1Signer();
|
|
6427
7073
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
6428
|
-
const
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
7074
|
+
const l2Contract = p.to ?? ctx.sender;
|
|
7075
|
+
const l2Value = p.amount;
|
|
7076
|
+
const l2Calldata = EMPTY_BYTES3;
|
|
7077
|
+
const priorityFloorBreakdown = getPriorityTxGasBreakdown({
|
|
7078
|
+
sender: ctx.sender,
|
|
7079
|
+
l2Contract,
|
|
7080
|
+
l2Value,
|
|
7081
|
+
l2Calldata,
|
|
7082
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
7083
|
+
});
|
|
7084
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? priorityFloorBreakdown.derivedL2GasLimit;
|
|
6434
7085
|
const l2GasParams = await quoteL2Gas2({
|
|
6435
7086
|
ctx,
|
|
6436
7087
|
route: "erc20-base",
|
|
6437
|
-
|
|
6438
|
-
overrideGasLimit: ctx.l2GasLimit
|
|
7088
|
+
overrideGasLimit: quotedL2GasLimit
|
|
6439
7089
|
});
|
|
6440
7090
|
if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
|
|
6441
7091
|
const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
|
|
@@ -6474,8 +7124,8 @@ function routeErc20Base() {
|
|
|
6474
7124
|
l2GasLimit: l2GasParams.gasLimit,
|
|
6475
7125
|
gasPerPubdata: ctx.gasPerPubdata,
|
|
6476
7126
|
refundRecipient: ctx.refundRecipient,
|
|
6477
|
-
l2Contract
|
|
6478
|
-
l2Value
|
|
7127
|
+
l2Contract,
|
|
7128
|
+
l2Value
|
|
6479
7129
|
});
|
|
6480
7130
|
const bridgehub = await ctx.contracts.bridgehub();
|
|
6481
7131
|
const data = bridgehub.interface.encodeFunctionData("requestL2TransactionDirect", [
|
|
@@ -6522,25 +7172,9 @@ function routeErc20Base() {
|
|
|
6522
7172
|
}
|
|
6523
7173
|
};
|
|
6524
7174
|
}
|
|
6525
|
-
|
|
6526
|
-
// src/core/codec/ntv.ts
|
|
6527
|
-
function createNTVCodec(deps) {
|
|
6528
|
-
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
6529
|
-
const encoded = deps.encode(
|
|
6530
|
-
["uint256", "address", "address"],
|
|
6531
|
-
[originChainId, ntvAddress, tokenAddress]
|
|
6532
|
-
);
|
|
6533
|
-
return deps.keccak256(encoded);
|
|
6534
|
-
}
|
|
6535
|
-
return {
|
|
6536
|
-
encodeAssetId
|
|
6537
|
-
};
|
|
6538
|
-
}
|
|
6539
|
-
|
|
6540
|
-
// src/adapters/ethers/resources/tokens/tokens.ts
|
|
6541
7175
|
var { wrapAs: wrapAs5 } = createErrorHandlers("tokens");
|
|
6542
7176
|
var abi = ethers.AbiCoder.defaultAbiCoder();
|
|
6543
|
-
var
|
|
7177
|
+
var ntvCodec2 = createNTVCodec({
|
|
6544
7178
|
encode: (types, values) => abi.encode(types, values),
|
|
6545
7179
|
keccak256: (data) => ethers.ethers.keccak256(data)
|
|
6546
7180
|
});
|
|
@@ -6659,7 +7293,7 @@ function createTokensResource(client) {
|
|
|
6659
7293
|
return wrapAs5("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
6660
7294
|
const baseAssetId = await getBaseTokenAssetId();
|
|
6661
7295
|
const l1ChainId = await getL1ChainId();
|
|
6662
|
-
const ethAssetId =
|
|
7296
|
+
const ethAssetId = ntvCodec2.encodeAssetId(
|
|
6663
7297
|
l1ChainId,
|
|
6664
7298
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
6665
7299
|
ETH_ADDRESS
|
|
@@ -7670,7 +8304,7 @@ var ROUTES2 = {
|
|
|
7670
8304
|
};
|
|
7671
8305
|
function createWithdrawalsResource(client, tokens, contracts) {
|
|
7672
8306
|
const svc = createFinalizationServices(client);
|
|
7673
|
-
const { wrap:
|
|
8307
|
+
const { wrap: wrap7, toResult: toResult3 } = createErrorHandlers("withdrawals");
|
|
7674
8308
|
const tokensResource = tokens ?? createTokensResource(client);
|
|
7675
8309
|
const contractsResource = contracts ?? createContractsResource(client);
|
|
7676
8310
|
async function buildPlan(p) {
|
|
@@ -7691,7 +8325,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
7691
8325
|
};
|
|
7692
8326
|
}
|
|
7693
8327
|
const finalizeCache = /* @__PURE__ */ new Map();
|
|
7694
|
-
const quote = (p) =>
|
|
8328
|
+
const quote = (p) => wrap7(
|
|
7695
8329
|
OP_WITHDRAWALS.quote,
|
|
7696
8330
|
async () => {
|
|
7697
8331
|
const plan = await buildPlan(p);
|
|
@@ -7713,7 +8347,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
7713
8347
|
ctx: { token: p.token, where: "withdrawals.tryQuote" }
|
|
7714
8348
|
}
|
|
7715
8349
|
);
|
|
7716
|
-
const prepare = (p) =>
|
|
8350
|
+
const prepare = (p) => wrap7(OP_WITHDRAWALS.prepare, () => buildPlan(p), {
|
|
7717
8351
|
message: "Internal error while preparing a withdrawal plan.",
|
|
7718
8352
|
ctx: { token: p.token, where: "withdrawals.prepare" }
|
|
7719
8353
|
});
|
|
@@ -7721,7 +8355,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
7721
8355
|
message: "Internal error while preparing a withdrawal plan.",
|
|
7722
8356
|
ctx: { token: p.token, where: "withdrawals.tryPrepare" }
|
|
7723
8357
|
});
|
|
7724
|
-
const create = (p) =>
|
|
8358
|
+
const create = (p) => wrap7(
|
|
7725
8359
|
OP_WITHDRAWALS.create,
|
|
7726
8360
|
async () => {
|
|
7727
8361
|
const plan = await prepare(p);
|
|
@@ -7792,7 +8426,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
7792
8426
|
message: "Internal error while creating withdrawal transactions.",
|
|
7793
8427
|
ctx: { token: p.token, amount: p.amount, to: p.to, where: "withdrawals.tryCreate" }
|
|
7794
8428
|
});
|
|
7795
|
-
const status = (h) =>
|
|
8429
|
+
const status = (h) => wrap7(
|
|
7796
8430
|
OP_WITHDRAWALS.status,
|
|
7797
8431
|
async () => {
|
|
7798
8432
|
const l2TxHash = typeof h === "string" ? h : "l2TxHash" in h && h.l2TxHash ? h.l2TxHash : "0x";
|
|
@@ -7847,7 +8481,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
7847
8481
|
const wait = (h, opts = {
|
|
7848
8482
|
for: "l2",
|
|
7849
8483
|
pollMs: 5500
|
|
7850
|
-
}) =>
|
|
8484
|
+
}) => wrap7(
|
|
7851
8485
|
OP_WITHDRAWALS.wait,
|
|
7852
8486
|
async () => {
|
|
7853
8487
|
const l2Hash = typeof h === "string" ? h : "l2TxHash" in h && h.l2TxHash ? h.l2TxHash : "0x";
|
|
@@ -7912,7 +8546,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
|
|
|
7912
8546
|
}
|
|
7913
8547
|
}
|
|
7914
8548
|
);
|
|
7915
|
-
const finalize = (l2TxHash) =>
|
|
8549
|
+
const finalize = (l2TxHash) => wrap7(
|
|
7916
8550
|
OP_WITHDRAWALS.finalize.send,
|
|
7917
8551
|
async () => {
|
|
7918
8552
|
const pack = await (async () => {
|
|
@@ -8038,9 +8672,11 @@ function createCallAttributes(codec) {
|
|
|
8038
8672
|
function createBundleAttributes(codec) {
|
|
8039
8673
|
const executionAddress = (executor) => codec.encode("executionAddress", [executor]);
|
|
8040
8674
|
const unbundlerAddress = (addr) => codec.encode("unbundlerAddress", [addr]);
|
|
8675
|
+
const useFixedFee = (enabled) => codec.encode("useFixedFee", [enabled]);
|
|
8041
8676
|
return {
|
|
8042
8677
|
executionAddress,
|
|
8043
|
-
unbundlerAddress
|
|
8678
|
+
unbundlerAddress,
|
|
8679
|
+
useFixedFee
|
|
8044
8680
|
};
|
|
8045
8681
|
}
|
|
8046
8682
|
|
|
@@ -8061,6 +8697,7 @@ function getInteropAttributes(params, ctx) {
|
|
|
8061
8697
|
if (params.unbundling?.by) {
|
|
8062
8698
|
bundleAttributes.push(ctx.attributes.bundle.unbundlerAddress(params.unbundling.by));
|
|
8063
8699
|
}
|
|
8700
|
+
bundleAttributes.push(ctx.attributes.bundle.useFixedFee(params.fee?.useFixed ?? false));
|
|
8064
8701
|
const callAttributes = params.actions.map((action) => {
|
|
8065
8702
|
switch (action.type) {
|
|
8066
8703
|
case "sendNative": {
|
|
@@ -8090,11 +8727,6 @@ function createEthersAttributesResource(opts = {}) {
|
|
|
8090
8727
|
}
|
|
8091
8728
|
|
|
8092
8729
|
// src/core/types/flows/interop.ts
|
|
8093
|
-
function isInteropExpectedRoot(obj) {
|
|
8094
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
8095
|
-
const root = obj;
|
|
8096
|
-
return isBigint(root.rootChainId) && isBigint(root.batchNumber) && isHash(root.expectedRoot);
|
|
8097
|
-
}
|
|
8098
8730
|
function isInteropMessageProof(obj) {
|
|
8099
8731
|
if (typeof obj !== "object" || obj === null) return false;
|
|
8100
8732
|
const proof = obj;
|
|
@@ -8103,7 +8735,7 @@ function isInteropMessageProof(obj) {
|
|
|
8103
8735
|
function isInteropFinalizationInfo(obj) {
|
|
8104
8736
|
if (typeof obj !== "object" || obj === null) return false;
|
|
8105
8737
|
const info = obj;
|
|
8106
|
-
return isHash66(info.l2SrcTxHash) && isHash66(info.bundleHash) && isBigint(info.dstChainId) && isHash(info.encodedData) &&
|
|
8738
|
+
return isHash66(info.l2SrcTxHash) && isHash66(info.bundleHash) && isBigint(info.dstChainId) && isHash(info.encodedData) && isInteropMessageProof(info.proof);
|
|
8107
8739
|
}
|
|
8108
8740
|
|
|
8109
8741
|
// src/core/resources/interop/route.ts
|
|
@@ -8156,7 +8788,7 @@ function preflightDirect(params, ctx) {
|
|
|
8156
8788
|
}
|
|
8157
8789
|
}
|
|
8158
8790
|
}
|
|
8159
|
-
function buildDirectBundle(params, ctx, attrs) {
|
|
8791
|
+
function buildDirectBundle(params, ctx, attrs, interopFeeInfo) {
|
|
8160
8792
|
const totalActionValue = sumActionMsgValue(params.actions);
|
|
8161
8793
|
const starters = params.actions.map((action, index) => {
|
|
8162
8794
|
const to = ctx.codec.formatAddress(action.to);
|
|
@@ -8174,7 +8806,8 @@ function buildDirectBundle(params, ctx, attrs) {
|
|
|
8174
8806
|
dstChain: ctx.codec.formatChain(ctx.dstChainId),
|
|
8175
8807
|
starters,
|
|
8176
8808
|
bundleAttributes: attrs.bundleAttributes,
|
|
8177
|
-
approvals: [],
|
|
8809
|
+
approvals: interopFeeInfo.approval ? [interopFeeInfo.approval] : [],
|
|
8810
|
+
interopFee: interopFeeInfo.fee,
|
|
8178
8811
|
quoteExtras: {
|
|
8179
8812
|
totalActionValue,
|
|
8180
8813
|
bridgedTokenTotal: 0n
|
|
@@ -8219,7 +8852,7 @@ function preflightIndirect(params, ctx) {
|
|
|
8219
8852
|
}
|
|
8220
8853
|
}
|
|
8221
8854
|
}
|
|
8222
|
-
function buildIndirectBundle(params, ctx, attrs, starterData) {
|
|
8855
|
+
function buildIndirectBundle(params, ctx, attrs, starterData, interopFeeInfo) {
|
|
8223
8856
|
const totalActionValue = sumActionMsgValue(params.actions);
|
|
8224
8857
|
const bridgedTokenTotal = sumErc20Amounts(params.actions);
|
|
8225
8858
|
const approvalMap = /* @__PURE__ */ new Map();
|
|
@@ -8238,6 +8871,7 @@ function buildIndirectBundle(params, ctx, attrs, starterData) {
|
|
|
8238
8871
|
}
|
|
8239
8872
|
}
|
|
8240
8873
|
const approvals = Array.from(approvalMap.values());
|
|
8874
|
+
if (interopFeeInfo.approval) approvals.push(interopFeeInfo.approval);
|
|
8241
8875
|
const starters = params.actions.map((action, index) => {
|
|
8242
8876
|
const callAttributes = attrs.callAttributes[index] ?? [];
|
|
8243
8877
|
if (starterData[index]?.assetRouterPayload) {
|
|
@@ -8261,6 +8895,7 @@ function buildIndirectBundle(params, ctx, attrs, starterData) {
|
|
|
8261
8895
|
starters,
|
|
8262
8896
|
bundleAttributes: attrs.bundleAttributes,
|
|
8263
8897
|
approvals,
|
|
8898
|
+
interopFee: interopFeeInfo.fee,
|
|
8264
8899
|
quoteExtras: {
|
|
8265
8900
|
totalActionValue,
|
|
8266
8901
|
bridgedTokenTotal
|
|
@@ -8307,6 +8942,29 @@ function buildEnsureTokenSteps(erc20Tokens, ctx) {
|
|
|
8307
8942
|
}
|
|
8308
8943
|
}));
|
|
8309
8944
|
}
|
|
8945
|
+
async function buildApproveSteps(approvals, ctx) {
|
|
8946
|
+
const steps = [];
|
|
8947
|
+
for (const approval of approvals) {
|
|
8948
|
+
const erc20 = new ethers.Contract(approval.token, IERC20_default, ctx.client.l2);
|
|
8949
|
+
const currentAllowance = await erc20.allowance(ctx.sender, approval.spender);
|
|
8950
|
+
if (currentAllowance < approval.amount) {
|
|
8951
|
+
steps.push({
|
|
8952
|
+
key: `approve:${approval.token}:${approval.spender}`,
|
|
8953
|
+
kind: "approve",
|
|
8954
|
+
description: `Approve ${approval.spender} to spend ${approval.amount} of ${approval.token}`,
|
|
8955
|
+
tx: {
|
|
8956
|
+
to: approval.token,
|
|
8957
|
+
data: erc20.interface.encodeFunctionData("approve", [
|
|
8958
|
+
approval.spender,
|
|
8959
|
+
approval.amount
|
|
8960
|
+
]),
|
|
8961
|
+
...ctx.gasOverrides
|
|
8962
|
+
}
|
|
8963
|
+
});
|
|
8964
|
+
}
|
|
8965
|
+
}
|
|
8966
|
+
return steps;
|
|
8967
|
+
}
|
|
8310
8968
|
async function resolveErc20AssetIds(erc20Tokens, ctx) {
|
|
8311
8969
|
const assetIds = /* @__PURE__ */ new Map();
|
|
8312
8970
|
if (erc20Tokens.length === 0) return assetIds;
|
|
@@ -8360,6 +9018,44 @@ async function getStarterData(params, ctx, erc20AssetIds) {
|
|
|
8360
9018
|
}
|
|
8361
9019
|
return starterData;
|
|
8362
9020
|
}
|
|
9021
|
+
var { wrap: wrap2 } = createErrorHandlers("interop");
|
|
9022
|
+
async function buildFeeInfo(params, ctx, numStarters) {
|
|
9023
|
+
const useFixed = params.fee?.useFixed ?? false;
|
|
9024
|
+
const interopCenter = new ethers.Contract(ctx.interopCenter, IInteropCenter_default, ctx.client.l2);
|
|
9025
|
+
if (useFixed) {
|
|
9026
|
+
const zkFeePerCall = await wrap2(
|
|
9027
|
+
OP_INTEROP.svc.fees.zkInteropFee,
|
|
9028
|
+
() => interopCenter.ZK_INTEROP_FEE(),
|
|
9029
|
+
{ message: "Failed to fetch ZK interop fee from InteropCenter." }
|
|
9030
|
+
);
|
|
9031
|
+
const zkFeeTotal = zkFeePerCall * BigInt(numStarters);
|
|
9032
|
+
const zkTokenAddress = await wrap2(
|
|
9033
|
+
OP_INTEROP.svc.fees.zkToken,
|
|
9034
|
+
() => interopCenter.zkToken(),
|
|
9035
|
+
{ message: "Failed to fetch ZK token address from InteropCenter." }
|
|
9036
|
+
);
|
|
9037
|
+
const approval = {
|
|
9038
|
+
token: zkTokenAddress,
|
|
9039
|
+
spender: ctx.interopCenter,
|
|
9040
|
+
amount: zkFeeTotal
|
|
9041
|
+
};
|
|
9042
|
+
return {
|
|
9043
|
+
approval,
|
|
9044
|
+
fee: { token: zkTokenAddress, amount: zkFeeTotal }
|
|
9045
|
+
};
|
|
9046
|
+
} else {
|
|
9047
|
+
const protocolFeePerCall = await wrap2(
|
|
9048
|
+
OP_INTEROP.svc.fees.protocolFee,
|
|
9049
|
+
() => interopCenter.interopProtocolFee(),
|
|
9050
|
+
{ message: "Failed to fetch interop protocol fee from InteropCenter." }
|
|
9051
|
+
);
|
|
9052
|
+
const totalFee = protocolFeePerCall * BigInt(numStarters);
|
|
9053
|
+
return {
|
|
9054
|
+
approval: null,
|
|
9055
|
+
fee: { token: ctx.baseTokens.src, amount: totalFee }
|
|
9056
|
+
};
|
|
9057
|
+
}
|
|
9058
|
+
}
|
|
8363
9059
|
|
|
8364
9060
|
// src/adapters/ethers/resources/interop/routes/indirect.ts
|
|
8365
9061
|
function routeIndirect() {
|
|
@@ -8375,7 +9071,10 @@ function routeIndirect() {
|
|
|
8375
9071
|
async build(params, ctx) {
|
|
8376
9072
|
const steps = [];
|
|
8377
9073
|
const erc20Tokens = getErc20Tokens(params);
|
|
8378
|
-
const erc20AssetIds = await
|
|
9074
|
+
const [erc20AssetIds, feeInfo] = await Promise.all([
|
|
9075
|
+
resolveErc20AssetIds(erc20Tokens, ctx),
|
|
9076
|
+
buildFeeInfo(params, ctx, params.actions.length)
|
|
9077
|
+
]);
|
|
8379
9078
|
const attributes = getInteropAttributes(params, ctx);
|
|
8380
9079
|
const starterData = await getStarterData(params, ctx, erc20AssetIds);
|
|
8381
9080
|
const bundle = buildIndirectBundle(
|
|
@@ -8388,32 +9087,11 @@ function routeIndirect() {
|
|
|
8388
9087
|
codec: interopCodec
|
|
8389
9088
|
},
|
|
8390
9089
|
attributes,
|
|
8391
|
-
starterData
|
|
9090
|
+
starterData,
|
|
9091
|
+
feeInfo
|
|
8392
9092
|
);
|
|
8393
9093
|
steps.push(...buildEnsureTokenSteps(erc20Tokens, ctx));
|
|
8394
|
-
|
|
8395
|
-
const erc20 = new ethers.Contract(approval.token, IERC20_default, ctx.client.l2);
|
|
8396
|
-
const currentAllowance = await erc20.allowance(
|
|
8397
|
-
ctx.sender,
|
|
8398
|
-
ctx.l2NativeTokenVault
|
|
8399
|
-
);
|
|
8400
|
-
if (currentAllowance < approval.amount) {
|
|
8401
|
-
const approveData = erc20.interface.encodeFunctionData("approve", [
|
|
8402
|
-
ctx.l2NativeTokenVault,
|
|
8403
|
-
approval.amount
|
|
8404
|
-
]);
|
|
8405
|
-
steps.push({
|
|
8406
|
-
key: `approve:${approval.token}:${ctx.l2NativeTokenVault}`,
|
|
8407
|
-
kind: "approve",
|
|
8408
|
-
description: `Approve ${ctx.l2NativeTokenVault} to spend ${approval.amount} of ${approval.token}`,
|
|
8409
|
-
tx: {
|
|
8410
|
-
to: approval.token,
|
|
8411
|
-
data: approveData,
|
|
8412
|
-
...ctx.gasOverrides
|
|
8413
|
-
}
|
|
8414
|
-
});
|
|
8415
|
-
}
|
|
8416
|
-
}
|
|
9094
|
+
steps.push(...await buildApproveSteps(bundle.approvals, ctx));
|
|
8417
9095
|
const data = ctx.ifaces.interopCenter.encodeFunctionData("sendBundle", [
|
|
8418
9096
|
bundle.dstChain,
|
|
8419
9097
|
bundle.starters,
|
|
@@ -8426,14 +9104,15 @@ function routeIndirect() {
|
|
|
8426
9104
|
tx: {
|
|
8427
9105
|
to: ctx.interopCenter,
|
|
8428
9106
|
data,
|
|
8429
|
-
value: bundle.quoteExtras.totalActionValue,
|
|
9107
|
+
value: bundle.quoteExtras.totalActionValue + feeInfo.fee.amount,
|
|
8430
9108
|
...ctx.gasOverrides
|
|
8431
9109
|
}
|
|
8432
9110
|
});
|
|
8433
9111
|
return {
|
|
8434
9112
|
steps,
|
|
8435
9113
|
approvals: bundle.approvals,
|
|
8436
|
-
quoteExtras: bundle.quoteExtras
|
|
9114
|
+
quoteExtras: bundle.quoteExtras,
|
|
9115
|
+
interopFee: feeInfo.fee
|
|
8437
9116
|
};
|
|
8438
9117
|
}
|
|
8439
9118
|
};
|
|
@@ -8450,10 +9129,10 @@ function routeDirect() {
|
|
|
8450
9129
|
l2AssetRouter: ctx.l2AssetRouter,
|
|
8451
9130
|
l2NativeTokenVault: ctx.l2NativeTokenVault});
|
|
8452
9131
|
},
|
|
8453
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
8454
9132
|
async build(params, ctx) {
|
|
8455
9133
|
const steps = [];
|
|
8456
9134
|
const attrs = getInteropAttributes(params, ctx);
|
|
9135
|
+
const feeInfo = await buildFeeInfo(params, ctx, params.actions.length);
|
|
8457
9136
|
const built = buildDirectBundle(
|
|
8458
9137
|
params,
|
|
8459
9138
|
{
|
|
@@ -8463,8 +9142,10 @@ function routeDirect() {
|
|
|
8463
9142
|
l2NativeTokenVault: ctx.l2NativeTokenVault,
|
|
8464
9143
|
codec: interopCodec
|
|
8465
9144
|
},
|
|
8466
|
-
attrs
|
|
9145
|
+
attrs,
|
|
9146
|
+
feeInfo
|
|
8467
9147
|
);
|
|
9148
|
+
steps.push(...await buildApproveSteps(built.approvals, ctx));
|
|
8468
9149
|
const data = ctx.ifaces.interopCenter.encodeFunctionData("sendBundle", [
|
|
8469
9150
|
built.dstChain,
|
|
8470
9151
|
built.starters,
|
|
@@ -8474,19 +9155,19 @@ function routeDirect() {
|
|
|
8474
9155
|
key: "sendBundle",
|
|
8475
9156
|
kind: "interop.center",
|
|
8476
9157
|
description: `Send interop bundle (direct route; ${params.actions.length} actions)`,
|
|
8477
|
-
//
|
|
8478
|
-
// all calls (sendNative.amount + call.value).
|
|
9158
|
+
// msg.value = forwarded action value + protocol fee.
|
|
8479
9159
|
tx: {
|
|
8480
9160
|
to: ctx.interopCenter,
|
|
8481
9161
|
data,
|
|
8482
|
-
value: built.quoteExtras.totalActionValue,
|
|
9162
|
+
value: built.quoteExtras.totalActionValue + feeInfo.fee.amount,
|
|
8483
9163
|
...ctx.gasOverrides
|
|
8484
9164
|
}
|
|
8485
9165
|
});
|
|
8486
9166
|
return {
|
|
8487
9167
|
steps,
|
|
8488
9168
|
approvals: built.approvals,
|
|
8489
|
-
quoteExtras: built.quoteExtras
|
|
9169
|
+
quoteExtras: built.quoteExtras,
|
|
9170
|
+
interopFee: feeInfo.fee
|
|
8490
9171
|
};
|
|
8491
9172
|
}
|
|
8492
9173
|
};
|
|
@@ -8566,7 +9247,7 @@ function getTopics() {
|
|
|
8566
9247
|
};
|
|
8567
9248
|
return { topics, centerIface };
|
|
8568
9249
|
}
|
|
8569
|
-
var { wrap:
|
|
9250
|
+
var { wrap: wrap3 } = createErrorHandlers("interop");
|
|
8570
9251
|
var DEFAULT_BLOCKS_RANGE_SIZE = 1e4;
|
|
8571
9252
|
var DEFAULT_MAX_BLOCKS_BACK = 2e4;
|
|
8572
9253
|
var SAFE_BLOCKS_RANGE_SIZE = 1e3;
|
|
@@ -8579,7 +9260,7 @@ function parseMaxBlockRangeLimit(error) {
|
|
|
8579
9260
|
return Number.isInteger(limit) && limit > 0 ? limit : null;
|
|
8580
9261
|
}
|
|
8581
9262
|
async function getTxReceipt(provider, txHash) {
|
|
8582
|
-
const receipt = await
|
|
9263
|
+
const receipt = await wrap3(
|
|
8583
9264
|
OP_INTEROP.svc.status.sourceReceipt,
|
|
8584
9265
|
() => provider.getTransactionReceipt(txHash),
|
|
8585
9266
|
{
|
|
@@ -8600,7 +9281,7 @@ async function getTxReceipt(provider, txHash) {
|
|
|
8600
9281
|
async function getLogs(provider, address, topics, opts) {
|
|
8601
9282
|
const maxBlocksBack = opts?.maxBlocksBack ?? DEFAULT_MAX_BLOCKS_BACK;
|
|
8602
9283
|
const initialChunkSize = opts?.logChunkSize ?? DEFAULT_BLOCKS_RANGE_SIZE;
|
|
8603
|
-
return await
|
|
9284
|
+
return await wrap3(
|
|
8604
9285
|
OP_INTEROP.svc.status.dstLogs,
|
|
8605
9286
|
async () => {
|
|
8606
9287
|
const currentBlock = await provider.getBlockNumber();
|
|
@@ -8647,7 +9328,7 @@ async function getLogs(provider, address, topics, opts) {
|
|
|
8647
9328
|
);
|
|
8648
9329
|
}
|
|
8649
9330
|
async function getInteropRoot(provider, rootChainId, batchNumber) {
|
|
8650
|
-
return await
|
|
9331
|
+
return await wrap3(
|
|
8651
9332
|
OP_INTEROP.svc.status.getRoot,
|
|
8652
9333
|
async () => {
|
|
8653
9334
|
const rootStorage = new ethers.Contract(
|
|
@@ -8665,7 +9346,7 @@ async function getInteropRoot(provider, rootChainId, batchNumber) {
|
|
|
8665
9346
|
}
|
|
8666
9347
|
|
|
8667
9348
|
// src/adapters/ethers/resources/interop/services/finalization/bundle.ts
|
|
8668
|
-
var { wrap:
|
|
9349
|
+
var { wrap: wrap4 } = createErrorHandlers("interop");
|
|
8669
9350
|
async function getBundleStatus(client, dstProvider, topics, bundleHash, opts) {
|
|
8670
9351
|
const { interopHandler } = await client.ensureAddresses();
|
|
8671
9352
|
const bundleLogs = await getLogs(dstProvider, interopHandler, [null, bundleHash], opts);
|
|
@@ -8697,7 +9378,7 @@ async function executeBundle(client, dstProvider, info, opts) {
|
|
|
8697
9378
|
context: { bundleHash }
|
|
8698
9379
|
});
|
|
8699
9380
|
}
|
|
8700
|
-
const signer = await
|
|
9381
|
+
const signer = await wrap4(OP_INTEROP.exec.sendStep, () => client.signerFor(dstProvider), {
|
|
8701
9382
|
message: "Failed to resolve destination signer."
|
|
8702
9383
|
});
|
|
8703
9384
|
const { interopHandler } = await client.ensureAddresses();
|
|
@@ -8859,11 +9540,6 @@ function getBundleEncodedData(messageData) {
|
|
|
8859
9540
|
return `0x${messageData.slice(4)}`;
|
|
8860
9541
|
}
|
|
8861
9542
|
function buildFinalizationInfo(ids, bundleInfo, proof, messageData) {
|
|
8862
|
-
const expectedRoot = {
|
|
8863
|
-
rootChainId: bundleInfo.sourceChainId,
|
|
8864
|
-
batchNumber: proof.batchNumber,
|
|
8865
|
-
expectedRoot: proof.root
|
|
8866
|
-
};
|
|
8867
9543
|
const messageProof = {
|
|
8868
9544
|
chainId: bundleInfo.sourceChainId,
|
|
8869
9545
|
l1BatchNumber: proof.batchNumber,
|
|
@@ -8879,7 +9555,6 @@ function buildFinalizationInfo(ids, bundleInfo, proof, messageData) {
|
|
|
8879
9555
|
l2SrcTxHash: ids.l2SrcTxHash,
|
|
8880
9556
|
bundleHash: bundleInfo.bundleHash,
|
|
8881
9557
|
dstChainId: bundleInfo.dstChainId,
|
|
8882
|
-
expectedRoot,
|
|
8883
9558
|
proof: messageProof,
|
|
8884
9559
|
encodedData: getBundleEncodedData(messageData)
|
|
8885
9560
|
};
|
|
@@ -8902,7 +9577,7 @@ function decodeL1MessageData(log) {
|
|
|
8902
9577
|
}
|
|
8903
9578
|
|
|
8904
9579
|
// src/adapters/ethers/resources/interop/services/finalization/polling.ts
|
|
8905
|
-
var { wrap:
|
|
9580
|
+
var { wrap: wrap5 } = createErrorHandlers("interop");
|
|
8906
9581
|
function isProofNotReadyError(error) {
|
|
8907
9582
|
return isZKsyncError(error, {
|
|
8908
9583
|
operation: "zksrpc.getL2ToL1LogProof",
|
|
@@ -8939,30 +9614,26 @@ async function waitForProof(client, l2SrcTxHash, logIndex, blockNumber, pollMs,
|
|
|
8939
9614
|
});
|
|
8940
9615
|
}
|
|
8941
9616
|
try {
|
|
8942
|
-
return await client.zks.getL2ToL1LogProof(l2SrcTxHash, logIndex);
|
|
9617
|
+
return await client.zks.getL2ToL1LogProof(l2SrcTxHash, logIndex, "messageRoot" /* MessageRoot */);
|
|
8943
9618
|
} catch (error) {
|
|
8944
9619
|
if (!isProofNotReadyError(error)) throw error;
|
|
8945
9620
|
}
|
|
8946
9621
|
await sleep(pollMs);
|
|
8947
9622
|
}
|
|
8948
9623
|
}
|
|
8949
|
-
async function waitForRoot(provider,
|
|
9624
|
+
async function waitForRoot(provider, chainId, batchNumber, pollMs, deadline) {
|
|
8950
9625
|
while (true) {
|
|
8951
9626
|
if (Date.now() > deadline) {
|
|
8952
9627
|
throw createError("TIMEOUT", {
|
|
8953
9628
|
resource: "interop",
|
|
8954
9629
|
operation: OP_INTEROP.svc.wait.timeout,
|
|
8955
9630
|
message: "Timed out waiting for interop root to become available.",
|
|
8956
|
-
context: {
|
|
9631
|
+
context: { chainId, batchNumber }
|
|
8957
9632
|
});
|
|
8958
9633
|
}
|
|
8959
9634
|
let interopRoot = null;
|
|
8960
9635
|
try {
|
|
8961
|
-
const root = await getInteropRoot(
|
|
8962
|
-
provider,
|
|
8963
|
-
expectedRoot.rootChainId,
|
|
8964
|
-
expectedRoot.batchNumber
|
|
8965
|
-
);
|
|
9636
|
+
const root = await getInteropRoot(provider, chainId, batchNumber);
|
|
8966
9637
|
if (root !== ZERO_HASH) {
|
|
8967
9638
|
interopRoot = root;
|
|
8968
9639
|
}
|
|
@@ -8971,18 +9642,7 @@ async function waitForRoot(provider, expectedRoot, pollMs, deadline) {
|
|
|
8971
9642
|
interopRoot = null;
|
|
8972
9643
|
}
|
|
8973
9644
|
if (interopRoot) {
|
|
8974
|
-
|
|
8975
|
-
return;
|
|
8976
|
-
}
|
|
8977
|
-
throw createError("STATE", {
|
|
8978
|
-
resource: "interop",
|
|
8979
|
-
operation: OP_INTEROP.wait,
|
|
8980
|
-
message: "Interop root mismatch.",
|
|
8981
|
-
context: {
|
|
8982
|
-
expected: expectedRoot.expectedRoot,
|
|
8983
|
-
got: interopRoot
|
|
8984
|
-
}
|
|
8985
|
-
});
|
|
9645
|
+
return interopRoot;
|
|
8986
9646
|
}
|
|
8987
9647
|
await sleep(pollMs);
|
|
8988
9648
|
}
|
|
@@ -8997,7 +9657,7 @@ async function waitForTxReceipt(client, txHash, pollMs, deadline) {
|
|
|
8997
9657
|
context: { txHash }
|
|
8998
9658
|
});
|
|
8999
9659
|
}
|
|
9000
|
-
const receipt = await
|
|
9660
|
+
const receipt = await wrap5(
|
|
9001
9661
|
OP_INTEROP.svc.status.sourceReceipt,
|
|
9002
9662
|
() => client.zks.getReceiptWithL2ToL1(txHash),
|
|
9003
9663
|
{
|
|
@@ -9011,7 +9671,7 @@ async function waitForTxReceipt(client, txHash, pollMs, deadline) {
|
|
|
9011
9671
|
await sleep(pollMs);
|
|
9012
9672
|
}
|
|
9013
9673
|
}
|
|
9014
|
-
async function waitForFinalization(client, dstProvider, input, opts) {
|
|
9674
|
+
async function waitForFinalization(client, dstProvider, gwProvider, input, opts) {
|
|
9015
9675
|
const { topics, centerIface } = getTopics();
|
|
9016
9676
|
const pollMs = opts?.pollMs ?? DEFAULT_POLL_MS;
|
|
9017
9677
|
const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
@@ -9060,7 +9720,16 @@ async function waitForFinalization(client, dstProvider, input, opts) {
|
|
|
9060
9720
|
proof,
|
|
9061
9721
|
bundleInfo.l1MessageData
|
|
9062
9722
|
);
|
|
9063
|
-
|
|
9723
|
+
if (proof.gatewayBlockNumber == null) {
|
|
9724
|
+
throw createError("STATE", {
|
|
9725
|
+
resource: "interop",
|
|
9726
|
+
operation: OP_INTEROP.svc.wait.timeout,
|
|
9727
|
+
message: "Proof missing gatewayBlockNumber required for interop finalization.",
|
|
9728
|
+
context: { l2SrcTxHash: ids.l2SrcTxHash }
|
|
9729
|
+
});
|
|
9730
|
+
}
|
|
9731
|
+
const { chainId: gwChainId } = await gwProvider.getNetwork();
|
|
9732
|
+
await waitForRoot(dstProvider, gwChainId, proof.gatewayBlockNumber, pollMs, deadline);
|
|
9064
9733
|
return finalizationInfo;
|
|
9065
9734
|
}
|
|
9066
9735
|
|
|
@@ -9106,8 +9775,8 @@ function createInteropFinalizationServices(client) {
|
|
|
9106
9775
|
status(dstProvider, input, opts) {
|
|
9107
9776
|
return getStatus(client, dstProvider, input, opts);
|
|
9108
9777
|
},
|
|
9109
|
-
wait(dstProvider, input, opts) {
|
|
9110
|
-
return waitForFinalization(client, dstProvider, input, opts);
|
|
9778
|
+
wait(dstProvider, gwProvider, input, opts) {
|
|
9779
|
+
return waitForFinalization(client, dstProvider, gwProvider, input, opts);
|
|
9111
9780
|
},
|
|
9112
9781
|
async finalize(dstProvider, info, opts) {
|
|
9113
9782
|
const execResult = await executeBundle(client, dstProvider, info, opts);
|
|
@@ -9119,27 +9788,34 @@ function createInteropFinalizationServices(client) {
|
|
|
9119
9788
|
}
|
|
9120
9789
|
};
|
|
9121
9790
|
}
|
|
9122
|
-
function
|
|
9123
|
-
return typeof
|
|
9124
|
-
}
|
|
9125
|
-
function resolveWaitableInput(waitableInput) {
|
|
9126
|
-
const input = waitableInput;
|
|
9127
|
-
return {
|
|
9128
|
-
dstProvider: resolveDstProvider(waitableInput.dstChain),
|
|
9129
|
-
waitable: input.waitable ? input.waitable : waitableInput
|
|
9130
|
-
};
|
|
9791
|
+
function resolveChainRef(ref) {
|
|
9792
|
+
return typeof ref === "string" ? new ethers.JsonRpcProvider(ref) : ref;
|
|
9131
9793
|
}
|
|
9132
9794
|
|
|
9133
9795
|
// src/adapters/ethers/resources/interop/index.ts
|
|
9134
|
-
var { wrap:
|
|
9796
|
+
var { wrap: wrap6, toResult: toResult2 } = createErrorHandlers("interop");
|
|
9135
9797
|
var ROUTES3 = {
|
|
9136
9798
|
direct: routeDirect(),
|
|
9137
9799
|
indirect: routeIndirect()
|
|
9138
9800
|
};
|
|
9139
|
-
function createInteropResource(client, tokens, contracts, attributes) {
|
|
9801
|
+
function createInteropResource(client, config, tokens, contracts, attributes) {
|
|
9802
|
+
let gwProviderCache;
|
|
9803
|
+
function requireConfig() {
|
|
9804
|
+
if (!config)
|
|
9805
|
+
throw createError("STATE", {
|
|
9806
|
+
resource: "interop",
|
|
9807
|
+
operation: "interop.init",
|
|
9808
|
+
message: "Interop is not configured. Pass gwChain in createEthersSdk options."
|
|
9809
|
+
});
|
|
9810
|
+
return config;
|
|
9811
|
+
}
|
|
9812
|
+
function getGwProvider() {
|
|
9813
|
+
if (!gwProviderCache) gwProviderCache = resolveChainRef(requireConfig().gwChain);
|
|
9814
|
+
return gwProviderCache;
|
|
9815
|
+
}
|
|
9140
9816
|
const svc = createInteropFinalizationServices(client);
|
|
9141
|
-
const tokensResource = createTokensResource(client);
|
|
9142
|
-
const contractsResource = createContractsResource(client);
|
|
9817
|
+
const tokensResource = tokens ?? createTokensResource(client);
|
|
9818
|
+
const contractsResource = contracts ?? createContractsResource(client);
|
|
9143
9819
|
const attributesResource = createEthersAttributesResource();
|
|
9144
9820
|
async function buildPlanWithCtx(dstProvider, params) {
|
|
9145
9821
|
const ctx = await commonCtx3(
|
|
@@ -9160,11 +9836,11 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9160
9836
|
baseTokenDst: ctx.baseTokens.dst
|
|
9161
9837
|
}
|
|
9162
9838
|
});
|
|
9163
|
-
await
|
|
9839
|
+
await wrap6(OP_INTEROP.routes[route].preflight, () => ROUTES3[route].preflight?.(params, ctx), {
|
|
9164
9840
|
message: "Interop preflight failed.",
|
|
9165
9841
|
ctx: { where: `routes.${route}.preflight` }
|
|
9166
9842
|
});
|
|
9167
|
-
const { steps, approvals, quoteExtras } = await
|
|
9843
|
+
const { steps, approvals, quoteExtras, interopFee } = await wrap6(
|
|
9168
9844
|
OP_INTEROP.routes[route].build,
|
|
9169
9845
|
() => ROUTES3[route].build(params, ctx),
|
|
9170
9846
|
{
|
|
@@ -9176,7 +9852,8 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9176
9852
|
route,
|
|
9177
9853
|
approvalsNeeded: approvals,
|
|
9178
9854
|
totalActionValue: quoteExtras.totalActionValue,
|
|
9179
|
-
bridgedTokenTotal: quoteExtras.bridgedTokenTotal
|
|
9855
|
+
bridgedTokenTotal: quoteExtras.bridgedTokenTotal,
|
|
9856
|
+
interopFee
|
|
9180
9857
|
};
|
|
9181
9858
|
return { plan: { route, summary, steps }, ctx };
|
|
9182
9859
|
}
|
|
@@ -9184,20 +9861,23 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9184
9861
|
const { plan } = await buildPlanWithCtx(dstProvider, params);
|
|
9185
9862
|
return plan;
|
|
9186
9863
|
}
|
|
9187
|
-
const quote = (params) =>
|
|
9188
|
-
const plan = await buildPlan(
|
|
9864
|
+
const quote = (dstChain, params) => wrap6(OP_INTEROP.quote, async () => {
|
|
9865
|
+
const plan = await buildPlan(resolveChainRef(dstChain), params);
|
|
9189
9866
|
return plan.summary;
|
|
9190
9867
|
});
|
|
9191
|
-
const tryQuote = (params) => toResult2(OP_INTEROP.tryQuote, () => quote(params));
|
|
9192
|
-
const prepare = (params) =>
|
|
9868
|
+
const tryQuote = (dstChain, params) => toResult2(OP_INTEROP.tryQuote, () => quote(dstChain, params));
|
|
9869
|
+
const prepare = (dstChain, params) => wrap6(OP_INTEROP.prepare, () => buildPlan(resolveChainRef(dstChain), params), {
|
|
9193
9870
|
message: "Internal error while preparing an interop plan.",
|
|
9194
9871
|
ctx: { where: "interop.prepare" }
|
|
9195
9872
|
});
|
|
9196
|
-
const tryPrepare = (params) => toResult2(
|
|
9197
|
-
|
|
9873
|
+
const tryPrepare = (dstChain, params) => toResult2(
|
|
9874
|
+
OP_INTEROP.tryPrepare,
|
|
9875
|
+
() => prepare(dstChain, params)
|
|
9876
|
+
);
|
|
9877
|
+
const create = (dstChain, params) => wrap6(
|
|
9198
9878
|
OP_INTEROP.create,
|
|
9199
9879
|
async () => {
|
|
9200
|
-
const { plan, ctx } = await buildPlanWithCtx(
|
|
9880
|
+
const { plan, ctx } = await buildPlanWithCtx(resolveChainRef(dstChain), params);
|
|
9201
9881
|
const signer = ctx.client.signerFor(ctx.client.l2);
|
|
9202
9882
|
const srcProvider = ctx.client.l2;
|
|
9203
9883
|
const from = await signer.getAddress();
|
|
@@ -9259,7 +9939,6 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9259
9939
|
const last = Object.values(stepHashes).pop();
|
|
9260
9940
|
return {
|
|
9261
9941
|
kind: "interop",
|
|
9262
|
-
dstChain: params.dstChain,
|
|
9263
9942
|
stepHashes,
|
|
9264
9943
|
plan,
|
|
9265
9944
|
l2SrcTxHash: last ?? "0x"
|
|
@@ -9270,46 +9949,27 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9270
9949
|
ctx: { where: "interop.create" }
|
|
9271
9950
|
}
|
|
9272
9951
|
);
|
|
9273
|
-
const tryCreate = (params) => toResult2(
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
}
|
|
9280
|
-
};
|
|
9281
|
-
const wait = (h, opts) => {
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9287
|
-
return { ...info, dstChain: h.dstChain };
|
|
9288
|
-
},
|
|
9289
|
-
{
|
|
9290
|
-
message: "Internal error while waiting for interop finalization.",
|
|
9291
|
-
ctx: { where: "interop.wait" }
|
|
9292
|
-
}
|
|
9293
|
-
);
|
|
9294
|
-
};
|
|
9295
|
-
const tryWait = (h, opts) => toResult2(OP_INTEROP.tryWait, () => wait(h, opts));
|
|
9296
|
-
const finalize = (h, opts) => wrap5(
|
|
9952
|
+
const tryCreate = (dstChain, params) => toResult2(
|
|
9953
|
+
OP_INTEROP.tryCreate,
|
|
9954
|
+
() => create(dstChain, params)
|
|
9955
|
+
);
|
|
9956
|
+
const status = (dstChain, h, opts) => wrap6(OP_INTEROP.status, () => svc.status(resolveChainRef(dstChain), h, opts), {
|
|
9957
|
+
message: "Internal error while checking interop status.",
|
|
9958
|
+
ctx: { where: "interop.status" }
|
|
9959
|
+
});
|
|
9960
|
+
const wait = (dstChain, h, opts) => wrap6(OP_INTEROP.wait, () => svc.wait(resolveChainRef(dstChain), getGwProvider(), h, opts), {
|
|
9961
|
+
message: "Internal error while waiting for interop finalization.",
|
|
9962
|
+
ctx: { where: "interop.wait" }
|
|
9963
|
+
});
|
|
9964
|
+
const tryWait = (dstChain, h, opts) => toResult2(OP_INTEROP.tryWait, () => wait(dstChain, h, opts));
|
|
9965
|
+
const finalize = (dstChain, h, opts) => wrap6(
|
|
9297
9966
|
OP_INTEROP.finalize,
|
|
9298
9967
|
async () => {
|
|
9968
|
+
const dstProvider = resolveChainRef(dstChain);
|
|
9299
9969
|
if (isInteropFinalizationInfo(h)) {
|
|
9300
|
-
|
|
9301
|
-
throw createError("STATE", {
|
|
9302
|
-
resource: "interop",
|
|
9303
|
-
operation: OP_INTEROP.finalize,
|
|
9304
|
-
message: "Missing dstChain in interop finalization info.",
|
|
9305
|
-
context: { input: h }
|
|
9306
|
-
});
|
|
9307
|
-
}
|
|
9308
|
-
const dstProvider2 = resolveDstProvider(h.dstChain);
|
|
9309
|
-
return svc.finalize(dstProvider2, h, opts);
|
|
9970
|
+
return svc.finalize(dstProvider, h, opts);
|
|
9310
9971
|
}
|
|
9311
|
-
const
|
|
9312
|
-
const info = await svc.wait(dstProvider, waitable);
|
|
9972
|
+
const info = await svc.wait(dstProvider, getGwProvider(), h);
|
|
9313
9973
|
return svc.finalize(dstProvider, info, opts);
|
|
9314
9974
|
},
|
|
9315
9975
|
{
|
|
@@ -9317,7 +9977,7 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9317
9977
|
ctx: { where: "interop.finalize" }
|
|
9318
9978
|
}
|
|
9319
9979
|
);
|
|
9320
|
-
const tryFinalize = (h, opts) => toResult2(OP_INTEROP.tryFinalize, () => finalize(h, opts));
|
|
9980
|
+
const tryFinalize = (dstChain, h, opts) => toResult2(OP_INTEROP.tryFinalize, () => finalize(dstChain, h, opts));
|
|
9321
9981
|
return {
|
|
9322
9982
|
quote,
|
|
9323
9983
|
tryQuote,
|
|
@@ -9334,10 +9994,10 @@ function createInteropResource(client, tokens, contracts, attributes) {
|
|
|
9334
9994
|
}
|
|
9335
9995
|
|
|
9336
9996
|
// src/adapters/ethers/sdk.ts
|
|
9337
|
-
function createEthersSdk(client) {
|
|
9997
|
+
function createEthersSdk(client, options) {
|
|
9338
9998
|
const tokens = createTokensResource(client);
|
|
9339
9999
|
const contracts = createContractsResource(client);
|
|
9340
|
-
const interop = createInteropResource(client);
|
|
10000
|
+
const interop = createInteropResource(client, options?.interop, tokens, contracts);
|
|
9341
10001
|
return {
|
|
9342
10002
|
deposits: createDepositsResource(client, tokens, contracts),
|
|
9343
10003
|
withdrawals: createWithdrawalsResource(client, tokens, contracts),
|