@matterlabs/zksync-js 0.0.24 → 0.0.26
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/index.cjs +250 -94
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +2 -2
- package/dist/adapters/ethers/resources/deposits/services/fee.d.ts +1 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +23 -3
- package/dist/adapters/ethers/sdk.cjs +250 -94
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +2 -2
- package/dist/adapters/viem/index.cjs +280 -133
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +2 -2
- package/dist/adapters/viem/resources/deposits/services/fee.d.ts +1 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +22 -2
- package/dist/adapters/viem/sdk.cjs +280 -133
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +2 -2
- package/dist/{chunk-5S63J6DW.js → chunk-FMBQ7PVA.js} +58 -10
- package/dist/{chunk-QMMFUWRV.js → chunk-VVDJFIXV.js} +224 -130
- package/dist/{chunk-B6P24GL5.js → chunk-YWUBX7YE.js} +194 -88
- package/dist/core/resources/deposits/gas.d.ts +11 -1
- package/dist/core/resources/deposits/priority.d.ts +46 -0
- package/package.json +1 -1
|
@@ -7483,7 +7483,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
7483
7483
|
function wrap8(operation, fn, opts) {
|
|
7484
7484
|
return run("INTERNAL", operation, fn, opts);
|
|
7485
7485
|
}
|
|
7486
|
-
function
|
|
7486
|
+
function wrapAs12(kind, operation, fn, opts) {
|
|
7487
7487
|
return run(kind, operation, fn, opts);
|
|
7488
7488
|
}
|
|
7489
7489
|
async function toResult3(operation, fn, opts) {
|
|
@@ -7504,7 +7504,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
7504
7504
|
return { ok: false, error: shaped };
|
|
7505
7505
|
}
|
|
7506
7506
|
}
|
|
7507
|
-
return { wrap: wrap8, wrapAs:
|
|
7507
|
+
return { wrap: wrap8, wrapAs: wrapAs12, toResult: toResult3 };
|
|
7508
7508
|
}
|
|
7509
7509
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
7510
7510
|
}
|
|
@@ -7975,6 +7975,7 @@ function isEraVmChain(chainIdL2) {
|
|
|
7975
7975
|
|
|
7976
7976
|
// src/core/resources/deposits/gas.ts
|
|
7977
7977
|
var CREATE_REESTIMATE_BUFFER = 15n;
|
|
7978
|
+
var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
7978
7979
|
var maxBigInt = (a, b) => a > b ? a : b;
|
|
7979
7980
|
function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
|
|
7980
7981
|
return gasLimit * (100n + bufferPct) / 100n;
|
|
@@ -8025,15 +8026,39 @@ async function fetchFees(estimator) {
|
|
|
8025
8026
|
const gp = await estimator.getGasPrice();
|
|
8026
8027
|
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
8027
8028
|
} catch {
|
|
8028
|
-
return
|
|
8029
|
+
return void 0;
|
|
8030
|
+
}
|
|
8031
|
+
}
|
|
8032
|
+
async function quoteL1Fees(input) {
|
|
8033
|
+
const { estimator, overrides } = input;
|
|
8034
|
+
const maxFeeOverride = overrides?.maxFeePerGas;
|
|
8035
|
+
const tipOverride = overrides?.maxPriorityFeePerGas;
|
|
8036
|
+
if (maxFeeOverride != null && tipOverride != null) {
|
|
8037
|
+
return { maxFeePerGas: maxFeeOverride, maxPriorityFeePerGas: tipOverride };
|
|
8038
|
+
}
|
|
8039
|
+
const market = await fetchFees(estimator);
|
|
8040
|
+
if (maxFeeOverride != null) {
|
|
8041
|
+
const tip = market?.maxPriorityFeePerGas ?? 0n;
|
|
8042
|
+
return {
|
|
8043
|
+
maxFeePerGas: maxFeeOverride,
|
|
8044
|
+
maxPriorityFeePerGas: tip < maxFeeOverride ? tip : maxFeeOverride
|
|
8045
|
+
};
|
|
8046
|
+
}
|
|
8047
|
+
if (market == null) {
|
|
8048
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
8029
8049
|
}
|
|
8050
|
+
if (tipOverride != null) {
|
|
8051
|
+
const headroom = market.maxFeePerGas > market.maxPriorityFeePerGas ? market.maxFeePerGas - market.maxPriorityFeePerGas : 0n;
|
|
8052
|
+
return { maxFeePerGas: headroom + tipOverride, maxPriorityFeePerGas: tipOverride };
|
|
8053
|
+
}
|
|
8054
|
+
return market;
|
|
8030
8055
|
}
|
|
8031
8056
|
async function quoteL1Gas(input) {
|
|
8032
8057
|
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
8033
8058
|
let market;
|
|
8034
8059
|
const getMarket = async () => {
|
|
8035
8060
|
if (market) return market;
|
|
8036
|
-
market = await fetchFees(estimator);
|
|
8061
|
+
market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
8037
8062
|
return market;
|
|
8038
8063
|
};
|
|
8039
8064
|
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
@@ -8055,7 +8080,7 @@ async function quoteL1Gas(input) {
|
|
|
8055
8080
|
}
|
|
8056
8081
|
async function quoteL2Gas(input) {
|
|
8057
8082
|
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
8058
|
-
const market = await fetchFees(estimator);
|
|
8083
|
+
const market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
8059
8084
|
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
8060
8085
|
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
8061
8086
|
const explicit = overrideGasLimit ?? txGasLimit;
|
|
@@ -8097,10 +8122,28 @@ async function quoteL2Gas(input) {
|
|
|
8097
8122
|
}
|
|
8098
8123
|
|
|
8099
8124
|
// src/core/resources/deposits/priority.ts
|
|
8125
|
+
var ZK_CHAIN_PRICING_GETTERS_ABI = [
|
|
8126
|
+
{
|
|
8127
|
+
type: "function",
|
|
8128
|
+
name: "getZKsyncOS",
|
|
8129
|
+
stateMutability: "view",
|
|
8130
|
+
inputs: [],
|
|
8131
|
+
outputs: [{ name: "", type: "bool" }]
|
|
8132
|
+
},
|
|
8133
|
+
{
|
|
8134
|
+
type: "function",
|
|
8135
|
+
name: "getPubdataPricingMode",
|
|
8136
|
+
stateMutability: "view",
|
|
8137
|
+
inputs: [],
|
|
8138
|
+
outputs: [{ name: "", type: "uint8" }]
|
|
8139
|
+
}
|
|
8140
|
+
];
|
|
8141
|
+
var PUBDATA_PRICING_MODE_ROLLUP = 0;
|
|
8100
8142
|
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
8101
8143
|
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
8102
8144
|
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
8103
8145
|
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
8146
|
+
var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
|
|
8104
8147
|
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
8105
8148
|
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
8106
8149
|
function applyL1ToL2Alias(address) {
|
|
@@ -8147,6 +8190,16 @@ function clampPriorityL2GasLimit(input) {
|
|
|
8147
8190
|
})
|
|
8148
8191
|
);
|
|
8149
8192
|
}
|
|
8193
|
+
function resolveBaseTokenPriorityL2GasLimit(input) {
|
|
8194
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
8195
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
8196
|
+
}
|
|
8197
|
+
if (!input.chargesPubdata) return input.priorityFloorGasLimit;
|
|
8198
|
+
return maxBigInt2(
|
|
8199
|
+
input.priorityFloorGasLimit,
|
|
8200
|
+
applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
|
|
8201
|
+
);
|
|
8202
|
+
}
|
|
8150
8203
|
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
8151
8204
|
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
8152
8205
|
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
@@ -8157,8 +8210,6 @@ function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
|
8157
8210
|
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
8158
8211
|
);
|
|
8159
8212
|
}
|
|
8160
|
-
|
|
8161
|
-
// src/adapters/viem/estimator.ts
|
|
8162
8213
|
function toCoreTx(tx) {
|
|
8163
8214
|
return {
|
|
8164
8215
|
to: tx.to,
|
|
@@ -8217,6 +8268,7 @@ function viemToGasEstimator(client) {
|
|
|
8217
8268
|
from: tx.from,
|
|
8218
8269
|
to: tx.to,
|
|
8219
8270
|
data: tx.data,
|
|
8271
|
+
...tx.value != null ? { value: viem.toHex(tx.value) } : {},
|
|
8220
8272
|
type: ZKSYNC_OS_PRIORITY_TX_TYPE
|
|
8221
8273
|
}
|
|
8222
8274
|
]
|
|
@@ -8255,6 +8307,7 @@ function viemToGasEstimator(client) {
|
|
|
8255
8307
|
}
|
|
8256
8308
|
|
|
8257
8309
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
8310
|
+
var { wrapAs } = createErrorHandlers("deposits");
|
|
8258
8311
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
8259
8312
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
8260
8313
|
if (!leg) return void 0;
|
|
@@ -8264,6 +8317,60 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
8264
8317
|
return void 0;
|
|
8265
8318
|
}
|
|
8266
8319
|
}
|
|
8320
|
+
async function resolvePriorityTxL2Sender(ctx) {
|
|
8321
|
+
try {
|
|
8322
|
+
const code = await ctx.client.l1.getCode({ address: ctx.sender });
|
|
8323
|
+
if (!code || code === "0x") return ctx.sender;
|
|
8324
|
+
} catch {
|
|
8325
|
+
}
|
|
8326
|
+
return applyL1ToL2Alias(ctx.sender);
|
|
8327
|
+
}
|
|
8328
|
+
var chainPricingCache = /* @__PURE__ */ new WeakMap();
|
|
8329
|
+
var isContractRevert = (err) => err instanceof viem.BaseError && err.walk((e) => e instanceof viem.ContractFunctionRevertedError) != null;
|
|
8330
|
+
async function readChainPricing(ctx) {
|
|
8331
|
+
const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
|
|
8332
|
+
if (cached) return cached;
|
|
8333
|
+
try {
|
|
8334
|
+
const zkChain = await ctx.client.l1.readContract({
|
|
8335
|
+
address: ctx.bridgehub,
|
|
8336
|
+
abi: IBridgehub_default,
|
|
8337
|
+
functionName: "getZKChain",
|
|
8338
|
+
args: [ctx.chainIdL2]
|
|
8339
|
+
});
|
|
8340
|
+
const read = (functionName) => ctx.client.l1.readContract({
|
|
8341
|
+
address: zkChain,
|
|
8342
|
+
abi: ZK_CHAIN_PRICING_GETTERS_ABI,
|
|
8343
|
+
functionName
|
|
8344
|
+
});
|
|
8345
|
+
let zksyncOS;
|
|
8346
|
+
try {
|
|
8347
|
+
zksyncOS = await read("getZKsyncOS");
|
|
8348
|
+
} catch (err) {
|
|
8349
|
+
if (!isContractRevert(err)) throw err;
|
|
8350
|
+
zksyncOS = false;
|
|
8351
|
+
}
|
|
8352
|
+
const chargesPubdata = zksyncOS && Number(await read("getPubdataPricingMode")) === PUBDATA_PRICING_MODE_ROLLUP;
|
|
8353
|
+
const pricing = { zksyncOS, chargesPubdata };
|
|
8354
|
+
const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
|
|
8355
|
+
perClient.set(ctx.chainIdL2, pricing);
|
|
8356
|
+
chainPricingCache.set(ctx.client, perClient);
|
|
8357
|
+
return pricing;
|
|
8358
|
+
} catch {
|
|
8359
|
+
return void 0;
|
|
8360
|
+
}
|
|
8361
|
+
}
|
|
8362
|
+
async function quoteL1Fees2(input) {
|
|
8363
|
+
const { ctx } = input;
|
|
8364
|
+
return wrapAs(
|
|
8365
|
+
"RPC",
|
|
8366
|
+
"deposits.fees.l1",
|
|
8367
|
+
() => quoteL1Fees({
|
|
8368
|
+
estimator: viemToGasEstimator(ctx.client.l1),
|
|
8369
|
+
overrides: ctx.gasOverrides
|
|
8370
|
+
}),
|
|
8371
|
+
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
8372
|
+
);
|
|
8373
|
+
}
|
|
8267
8374
|
async function quoteL1Gas2(input) {
|
|
8268
8375
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
8269
8376
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -8288,6 +8395,26 @@ async function quoteL2Gas2(input) {
|
|
|
8288
8395
|
stateOverrides: input.stateOverrides
|
|
8289
8396
|
});
|
|
8290
8397
|
}
|
|
8398
|
+
async function determineBaseL2GasLimit(input) {
|
|
8399
|
+
const { ctx } = input;
|
|
8400
|
+
if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
|
|
8401
|
+
const [pricing, from] = await Promise.all([
|
|
8402
|
+
readChainPricing(ctx),
|
|
8403
|
+
resolvePriorityTxL2Sender(ctx)
|
|
8404
|
+
]);
|
|
8405
|
+
if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
|
|
8406
|
+
return resolveBaseTokenPriorityL2GasLimit({
|
|
8407
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
8408
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
8409
|
+
chargesPubdata: pricing?.chargesPubdata ?? true,
|
|
8410
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
|
|
8411
|
+
from,
|
|
8412
|
+
to: input.l2Contract,
|
|
8413
|
+
data: input.l2Calldata,
|
|
8414
|
+
value: input.l2Value
|
|
8415
|
+
})
|
|
8416
|
+
});
|
|
8417
|
+
}
|
|
8291
8418
|
async function determineNonBaseL2Gas(input) {
|
|
8292
8419
|
const { ctx, l1Token, route } = input;
|
|
8293
8420
|
const fallbackQuote = () => quoteL2Gas2({
|
|
@@ -8366,13 +8493,10 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
8366
8493
|
}
|
|
8367
8494
|
|
|
8368
8495
|
// src/adapters/viem/resources/deposits/services/fee.ts
|
|
8369
|
-
var { wrapAs } = createErrorHandlers("deposits");
|
|
8496
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
8370
8497
|
async function quoteL2BaseCost(input) {
|
|
8371
|
-
const { ctx, l2GasLimit } = input;
|
|
8372
|
-
|
|
8373
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
8374
|
-
const gasPrice = fees.maxFeePerGas ?? fees.gasPrice ?? await estimator.getGasPrice();
|
|
8375
|
-
return wrapAs(
|
|
8498
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
8499
|
+
return wrapAs2(
|
|
8376
8500
|
"RPC",
|
|
8377
8501
|
"deposits.fees.l2BaseCost",
|
|
8378
8502
|
async () => {
|
|
@@ -8380,7 +8504,7 @@ async function quoteL2BaseCost(input) {
|
|
|
8380
8504
|
address: ctx.bridgehub,
|
|
8381
8505
|
abi: IBridgehub_default,
|
|
8382
8506
|
functionName: "l2TransactionBaseCost",
|
|
8383
|
-
args: [ctx.chainIdL2,
|
|
8507
|
+
args: [ctx.chainIdL2, l1GasPrice, l2GasLimit, ctx.gasPerPubdata]
|
|
8384
8508
|
});
|
|
8385
8509
|
},
|
|
8386
8510
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
@@ -8475,7 +8599,7 @@ function getPriorityTxGasBreakdown(input) {
|
|
|
8475
8599
|
}
|
|
8476
8600
|
|
|
8477
8601
|
// src/adapters/viem/resources/deposits/routes/eth.ts
|
|
8478
|
-
var { wrapAs:
|
|
8602
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
8479
8603
|
var EMPTY_BYTES2 = "0x";
|
|
8480
8604
|
function routeEthDirect() {
|
|
8481
8605
|
return {
|
|
@@ -8490,13 +8614,19 @@ function routeEthDirect() {
|
|
|
8490
8614
|
l2Calldata,
|
|
8491
8615
|
gasPerPubdata: ctx.gasPerPubdata
|
|
8492
8616
|
});
|
|
8493
|
-
const quotedL2GasLimit =
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
}),
|
|
8617
|
+
const quotedL2GasLimit = await determineBaseL2GasLimit({
|
|
8618
|
+
ctx,
|
|
8619
|
+
l2Contract,
|
|
8620
|
+
l2Value,
|
|
8498
8621
|
l2Calldata,
|
|
8499
|
-
|
|
8622
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
8623
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
8624
|
+
chainIdL2: ctx.chainIdL2,
|
|
8625
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
8626
|
+
}),
|
|
8627
|
+
l2Calldata,
|
|
8628
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
8629
|
+
})
|
|
8500
8630
|
});
|
|
8501
8631
|
const l2GasParams = await quoteL2Gas2({
|
|
8502
8632
|
ctx,
|
|
@@ -8506,7 +8636,12 @@ function routeEthDirect() {
|
|
|
8506
8636
|
if (!l2GasParams) {
|
|
8507
8637
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
8508
8638
|
}
|
|
8509
|
-
const
|
|
8639
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
8640
|
+
const baseCost = await quoteL2BaseCost({
|
|
8641
|
+
ctx,
|
|
8642
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
8643
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
8644
|
+
});
|
|
8510
8645
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
8511
8646
|
const req = buildDirectRequestStruct({
|
|
8512
8647
|
chainId: ctx.chainIdL2,
|
|
@@ -8517,7 +8652,7 @@ function routeEthDirect() {
|
|
|
8517
8652
|
l2Contract,
|
|
8518
8653
|
l2Value
|
|
8519
8654
|
});
|
|
8520
|
-
const sim = await
|
|
8655
|
+
const sim = await wrapAs3(
|
|
8521
8656
|
"RPC",
|
|
8522
8657
|
OP_DEPOSITS.eth.estGas,
|
|
8523
8658
|
() => ctx.client.l1.simulateContract({
|
|
@@ -8543,22 +8678,19 @@ function routeEthDirect() {
|
|
|
8543
8678
|
data,
|
|
8544
8679
|
value: mintValue,
|
|
8545
8680
|
from: ctx.sender,
|
|
8546
|
-
...ctx.gasOverrides
|
|
8681
|
+
...ctx.gasOverrides,
|
|
8682
|
+
...l1Fees
|
|
8547
8683
|
};
|
|
8548
8684
|
const l1Gas = await quoteL1Gas2({
|
|
8549
8685
|
ctx,
|
|
8550
8686
|
tx: l1TxCandidate,
|
|
8551
8687
|
overrides: ctx.gasOverrides
|
|
8552
8688
|
});
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
maxFeePerGas: l1Gas.maxFeePerGas,
|
|
8559
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
8560
|
-
};
|
|
8561
|
-
}
|
|
8689
|
+
const bridgeTx = {
|
|
8690
|
+
...sim.request,
|
|
8691
|
+
...l1Fees,
|
|
8692
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
8693
|
+
};
|
|
8562
8694
|
const steps = [
|
|
8563
8695
|
{
|
|
8564
8696
|
key: "bridgehub:direct",
|
|
@@ -8646,7 +8778,7 @@ async function buildApprovalRequest({
|
|
|
8646
8778
|
}
|
|
8647
8779
|
|
|
8648
8780
|
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
8649
|
-
var { wrapAs:
|
|
8781
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
8650
8782
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8651
8783
|
var ntvCodec = createNTVCodec({
|
|
8652
8784
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -8737,7 +8869,7 @@ function routeErc20NonBase() {
|
|
|
8737
8869
|
return {
|
|
8738
8870
|
// TODO: do we even need these validations?
|
|
8739
8871
|
async preflight(p, ctx) {
|
|
8740
|
-
await
|
|
8872
|
+
await wrapAs4(
|
|
8741
8873
|
"VALIDATION",
|
|
8742
8874
|
OP_DEPOSITS.nonbase.assertNotEthAsset,
|
|
8743
8875
|
() => {
|
|
@@ -8748,7 +8880,7 @@ function routeErc20NonBase() {
|
|
|
8748
8880
|
{ ctx: { token: p.token } }
|
|
8749
8881
|
);
|
|
8750
8882
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
8751
|
-
await
|
|
8883
|
+
await wrapAs4(
|
|
8752
8884
|
"VALIDATION",
|
|
8753
8885
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
8754
8886
|
() => {
|
|
@@ -8765,7 +8897,7 @@ function routeErc20NonBase() {
|
|
|
8765
8897
|
const assetRouter = ctx.l1AssetRouter;
|
|
8766
8898
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
8767
8899
|
const receiver = p.to ?? ctx.sender;
|
|
8768
|
-
const secondBridgeCalldata = await
|
|
8900
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
8769
8901
|
"INTERNAL",
|
|
8770
8902
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
8771
8903
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -8803,11 +8935,16 @@ function routeErc20NonBase() {
|
|
|
8803
8935
|
}
|
|
8804
8936
|
});
|
|
8805
8937
|
if (!l2Gas) throw new Error("Failed to establish L2 gas parameters.");
|
|
8806
|
-
const
|
|
8938
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
8939
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
8940
|
+
ctx,
|
|
8941
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
8942
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
8943
|
+
});
|
|
8807
8944
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
8808
8945
|
const approvals = [];
|
|
8809
8946
|
const steps = [];
|
|
8810
|
-
const depositAllowance = await
|
|
8947
|
+
const depositAllowance = await wrapAs4(
|
|
8811
8948
|
"CONTRACT",
|
|
8812
8949
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
8813
8950
|
() => ctx.client.l1.readContract({
|
|
@@ -8822,7 +8959,7 @@ function routeErc20NonBase() {
|
|
|
8822
8959
|
}
|
|
8823
8960
|
);
|
|
8824
8961
|
if (depositAllowance < p.amount) {
|
|
8825
|
-
const approveTx = await
|
|
8962
|
+
const approveTx = await wrapAs4(
|
|
8826
8963
|
"CONTRACT",
|
|
8827
8964
|
OP_DEPOSITS.nonbase.estGas,
|
|
8828
8965
|
() => buildApprovalRequest({
|
|
@@ -8845,7 +8982,7 @@ function routeErc20NonBase() {
|
|
|
8845
8982
|
});
|
|
8846
8983
|
}
|
|
8847
8984
|
if (!baseIsEth) {
|
|
8848
|
-
const baseAllowance = await
|
|
8985
|
+
const baseAllowance = await wrapAs4(
|
|
8849
8986
|
"CONTRACT",
|
|
8850
8987
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
8851
8988
|
() => ctx.client.l1.readContract({
|
|
@@ -8860,7 +8997,7 @@ function routeErc20NonBase() {
|
|
|
8860
8997
|
}
|
|
8861
8998
|
);
|
|
8862
8999
|
if (baseAllowance < mintValue) {
|
|
8863
|
-
const approveBaseTx = await
|
|
9000
|
+
const approveBaseTx = await wrapAs4(
|
|
8864
9001
|
"CONTRACT",
|
|
8865
9002
|
OP_DEPOSITS.nonbase.estGas,
|
|
8866
9003
|
() => buildApprovalRequest({
|
|
@@ -8905,7 +9042,8 @@ function routeErc20NonBase() {
|
|
|
8905
9042
|
data: calldata,
|
|
8906
9043
|
value: msgValue,
|
|
8907
9044
|
from: ctx.sender,
|
|
8908
|
-
...ctx.gasOverrides
|
|
9045
|
+
...ctx.gasOverrides,
|
|
9046
|
+
...l1Fees
|
|
8909
9047
|
};
|
|
8910
9048
|
const l1Gas = await quoteL1Gas2({
|
|
8911
9049
|
ctx,
|
|
@@ -8925,7 +9063,7 @@ function routeErc20NonBase() {
|
|
|
8925
9063
|
account: ctx.client.account
|
|
8926
9064
|
};
|
|
8927
9065
|
} else {
|
|
8928
|
-
const sim = await
|
|
9066
|
+
const sim = await wrapAs4(
|
|
8929
9067
|
"CONTRACT",
|
|
8930
9068
|
OP_DEPOSITS.nonbase.estGas,
|
|
8931
9069
|
() => ctx.client.l1.simulateContract({
|
|
@@ -8943,14 +9081,11 @@ function routeErc20NonBase() {
|
|
|
8943
9081
|
);
|
|
8944
9082
|
bridgeTx = { ...sim.request };
|
|
8945
9083
|
}
|
|
8946
|
-
|
|
8947
|
-
bridgeTx
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
8952
|
-
};
|
|
8953
|
-
}
|
|
9084
|
+
bridgeTx = {
|
|
9085
|
+
...bridgeTx,
|
|
9086
|
+
...l1Fees,
|
|
9087
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9088
|
+
};
|
|
8954
9089
|
steps.push({
|
|
8955
9090
|
key: "bridgehub:two-bridges:erc20-nonbase",
|
|
8956
9091
|
kind: "bridgehub:two-bridges",
|
|
@@ -8973,7 +9108,7 @@ function routeErc20NonBase() {
|
|
|
8973
9108
|
}
|
|
8974
9109
|
};
|
|
8975
9110
|
}
|
|
8976
|
-
var { wrapAs:
|
|
9111
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
8977
9112
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8978
9113
|
var ntvCodec2 = createNTVCodec({
|
|
8979
9114
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -9057,7 +9192,7 @@ function routeEthNonBase() {
|
|
|
9057
9192
|
return {
|
|
9058
9193
|
// TODO: do we even need these validations?
|
|
9059
9194
|
async preflight(p, ctx) {
|
|
9060
|
-
await
|
|
9195
|
+
await wrapAs5(
|
|
9061
9196
|
"VALIDATION",
|
|
9062
9197
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
9063
9198
|
() => {
|
|
@@ -9067,7 +9202,7 @@ function routeEthNonBase() {
|
|
|
9067
9202
|
},
|
|
9068
9203
|
{ ctx: { token: p.token } }
|
|
9069
9204
|
);
|
|
9070
|
-
await
|
|
9205
|
+
await wrapAs5(
|
|
9071
9206
|
"VALIDATION",
|
|
9072
9207
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
9073
9208
|
() => {
|
|
@@ -9077,7 +9212,7 @@ function routeEthNonBase() {
|
|
|
9077
9212
|
},
|
|
9078
9213
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
9079
9214
|
);
|
|
9080
|
-
const ethBal = await
|
|
9215
|
+
const ethBal = await wrapAs5(
|
|
9081
9216
|
"RPC",
|
|
9082
9217
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
9083
9218
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -9086,7 +9221,7 @@ function routeEthNonBase() {
|
|
|
9086
9221
|
message: "Failed to read L1 ETH balance."
|
|
9087
9222
|
}
|
|
9088
9223
|
);
|
|
9089
|
-
await
|
|
9224
|
+
await wrapAs5(
|
|
9090
9225
|
"VALIDATION",
|
|
9091
9226
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
9092
9227
|
() => {
|
|
@@ -9119,11 +9254,16 @@ function routeEthNonBase() {
|
|
|
9119
9254
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
9120
9255
|
});
|
|
9121
9256
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
9122
|
-
const
|
|
9257
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
9258
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
9259
|
+
ctx,
|
|
9260
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
9261
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
9262
|
+
});
|
|
9123
9263
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
9124
9264
|
const approvals = [];
|
|
9125
9265
|
const steps = [];
|
|
9126
|
-
const allowance = await
|
|
9266
|
+
const allowance = await wrapAs5(
|
|
9127
9267
|
"CONTRACT",
|
|
9128
9268
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
9129
9269
|
() => ctx.client.l1.readContract({
|
|
@@ -9139,7 +9279,7 @@ function routeEthNonBase() {
|
|
|
9139
9279
|
);
|
|
9140
9280
|
const needsApprove = allowance < mintValue;
|
|
9141
9281
|
if (needsApprove) {
|
|
9142
|
-
const approveTx = await
|
|
9282
|
+
const approveTx = await wrapAs5(
|
|
9143
9283
|
"CONTRACT",
|
|
9144
9284
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
9145
9285
|
() => buildApprovalRequest({
|
|
@@ -9161,7 +9301,7 @@ function routeEthNonBase() {
|
|
|
9161
9301
|
tx: approveTx
|
|
9162
9302
|
});
|
|
9163
9303
|
}
|
|
9164
|
-
const secondBridgeCalldata = await
|
|
9304
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
9165
9305
|
"INTERNAL",
|
|
9166
9306
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
9167
9307
|
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
@@ -9203,7 +9343,7 @@ function routeEthNonBase() {
|
|
|
9203
9343
|
args: [requestStruct]
|
|
9204
9344
|
});
|
|
9205
9345
|
} else {
|
|
9206
|
-
const sim = await
|
|
9346
|
+
const sim = await wrapAs5(
|
|
9207
9347
|
"CONTRACT",
|
|
9208
9348
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
9209
9349
|
() => ctx.client.l1.simulateContract({
|
|
@@ -9231,7 +9371,8 @@ function routeEthNonBase() {
|
|
|
9231
9371
|
data: calldata,
|
|
9232
9372
|
value: bridgehubValue,
|
|
9233
9373
|
from: ctx.sender,
|
|
9234
|
-
...ctx.gasOverrides
|
|
9374
|
+
...ctx.gasOverrides,
|
|
9375
|
+
...l1Fees
|
|
9235
9376
|
};
|
|
9236
9377
|
const l1Gas = await quoteL1Gas2({
|
|
9237
9378
|
ctx,
|
|
@@ -9239,14 +9380,11 @@ function routeEthNonBase() {
|
|
|
9239
9380
|
overrides: ctx.gasOverrides,
|
|
9240
9381
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
9241
9382
|
});
|
|
9242
|
-
|
|
9243
|
-
bridgeTx
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
9248
|
-
};
|
|
9249
|
-
}
|
|
9383
|
+
bridgeTx = {
|
|
9384
|
+
...bridgeTx,
|
|
9385
|
+
...l1Fees,
|
|
9386
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9387
|
+
};
|
|
9250
9388
|
steps.push({
|
|
9251
9389
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
9252
9390
|
kind: "bridgehub:two-bridges",
|
|
@@ -9269,12 +9407,12 @@ function routeEthNonBase() {
|
|
|
9269
9407
|
}
|
|
9270
9408
|
};
|
|
9271
9409
|
}
|
|
9272
|
-
var { wrapAs:
|
|
9410
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
9273
9411
|
var EMPTY_BYTES3 = "0x";
|
|
9274
9412
|
function routeErc20Base() {
|
|
9275
9413
|
return {
|
|
9276
9414
|
async preflight(p, ctx) {
|
|
9277
|
-
await
|
|
9415
|
+
await wrapAs6(
|
|
9278
9416
|
"VALIDATION",
|
|
9279
9417
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
9280
9418
|
() => {
|
|
@@ -9285,7 +9423,7 @@ function routeErc20Base() {
|
|
|
9285
9423
|
{ ctx: { token: p.token } }
|
|
9286
9424
|
);
|
|
9287
9425
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
9288
|
-
await
|
|
9426
|
+
await wrapAs6(
|
|
9289
9427
|
"VALIDATION",
|
|
9290
9428
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
9291
9429
|
() => {
|
|
@@ -9308,13 +9446,19 @@ function routeErc20Base() {
|
|
|
9308
9446
|
l2Calldata,
|
|
9309
9447
|
gasPerPubdata: ctx.gasPerPubdata
|
|
9310
9448
|
});
|
|
9311
|
-
const quotedL2GasLimit =
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
9315
|
-
}),
|
|
9449
|
+
const quotedL2GasLimit = await determineBaseL2GasLimit({
|
|
9450
|
+
ctx,
|
|
9451
|
+
l2Contract,
|
|
9452
|
+
l2Value,
|
|
9316
9453
|
l2Calldata,
|
|
9317
|
-
|
|
9454
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
9455
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
9456
|
+
chainIdL2: ctx.chainIdL2,
|
|
9457
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
9458
|
+
}),
|
|
9459
|
+
l2Calldata,
|
|
9460
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
9461
|
+
})
|
|
9318
9462
|
});
|
|
9319
9463
|
const l2Gas = await quoteL2Gas2({
|
|
9320
9464
|
ctx,
|
|
@@ -9322,11 +9466,16 @@ function routeErc20Base() {
|
|
|
9322
9466
|
overrideGasLimit: quotedL2GasLimit
|
|
9323
9467
|
});
|
|
9324
9468
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
9325
|
-
const
|
|
9469
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
9470
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
9471
|
+
ctx,
|
|
9472
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
9473
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
9474
|
+
});
|
|
9326
9475
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
9327
9476
|
const approvals = [];
|
|
9328
9477
|
const steps = [];
|
|
9329
|
-
const allowance = await
|
|
9478
|
+
const allowance = await wrapAs6(
|
|
9330
9479
|
"CONTRACT",
|
|
9331
9480
|
OP_DEPOSITS.base.allowance,
|
|
9332
9481
|
() => ctx.client.l1.readContract({
|
|
@@ -9342,7 +9491,7 @@ function routeErc20Base() {
|
|
|
9342
9491
|
);
|
|
9343
9492
|
const needsApprove = allowance < mintValue;
|
|
9344
9493
|
if (needsApprove) {
|
|
9345
|
-
const approveTx = await
|
|
9494
|
+
const approveTx = await wrapAs6(
|
|
9346
9495
|
"CONTRACT",
|
|
9347
9496
|
OP_DEPOSITS.base.estGas,
|
|
9348
9497
|
() => buildApprovalRequest({
|
|
@@ -9391,7 +9540,7 @@ function routeErc20Base() {
|
|
|
9391
9540
|
args: [req]
|
|
9392
9541
|
});
|
|
9393
9542
|
} else {
|
|
9394
|
-
const sim = await
|
|
9543
|
+
const sim = await wrapAs6(
|
|
9395
9544
|
"RPC",
|
|
9396
9545
|
OP_DEPOSITS.base.estGas,
|
|
9397
9546
|
() => ctx.client.l1.simulateContract({
|
|
@@ -9419,7 +9568,8 @@ function routeErc20Base() {
|
|
|
9419
9568
|
data: calldata,
|
|
9420
9569
|
value: 0n,
|
|
9421
9570
|
from: ctx.sender,
|
|
9422
|
-
...ctx.gasOverrides
|
|
9571
|
+
...ctx.gasOverrides,
|
|
9572
|
+
...l1Fees
|
|
9423
9573
|
};
|
|
9424
9574
|
const l1Gas = await quoteL1Gas2({
|
|
9425
9575
|
ctx,
|
|
@@ -9427,14 +9577,11 @@ function routeErc20Base() {
|
|
|
9427
9577
|
overrides: ctx.gasOverrides,
|
|
9428
9578
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
9429
9579
|
});
|
|
9430
|
-
|
|
9431
|
-
bridgeTx
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
9436
|
-
};
|
|
9437
|
-
}
|
|
9580
|
+
bridgeTx = {
|
|
9581
|
+
...bridgeTx,
|
|
9582
|
+
...l1Fees,
|
|
9583
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9584
|
+
};
|
|
9438
9585
|
steps.push({
|
|
9439
9586
|
key: "bridgehub:direct:erc20-base",
|
|
9440
9587
|
kind: "bridgehub:direct",
|
|
@@ -9532,7 +9679,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
9532
9679
|
}
|
|
9533
9680
|
return { l2Receipt, l2TxHash };
|
|
9534
9681
|
}
|
|
9535
|
-
var { wrapAs:
|
|
9682
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
9536
9683
|
var ntvCodec3 = createNTVCodec({
|
|
9537
9684
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
9538
9685
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -9547,7 +9694,7 @@ function createTokensResource(client) {
|
|
|
9547
9694
|
let wethL2Promise = null;
|
|
9548
9695
|
async function getL1ChainId() {
|
|
9549
9696
|
if (!l2NtvL1ChainIdPromise) {
|
|
9550
|
-
l2NtvL1ChainIdPromise =
|
|
9697
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
9551
9698
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9552
9699
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
9553
9700
|
});
|
|
@@ -9556,7 +9703,7 @@ function createTokensResource(client) {
|
|
|
9556
9703
|
}
|
|
9557
9704
|
async function getBaseTokenAssetId() {
|
|
9558
9705
|
if (!baseTokenAssetIdPromise) {
|
|
9559
|
-
baseTokenAssetIdPromise =
|
|
9706
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
9560
9707
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9561
9708
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
9562
9709
|
return assetId;
|
|
@@ -9566,7 +9713,7 @@ function createTokensResource(client) {
|
|
|
9566
9713
|
}
|
|
9567
9714
|
async function getWethL1() {
|
|
9568
9715
|
if (!wethL1Promise) {
|
|
9569
|
-
wethL1Promise =
|
|
9716
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
9570
9717
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9571
9718
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
9572
9719
|
return weth;
|
|
@@ -9576,7 +9723,7 @@ function createTokensResource(client) {
|
|
|
9576
9723
|
}
|
|
9577
9724
|
async function getWethL2() {
|
|
9578
9725
|
if (!wethL2Promise) {
|
|
9579
|
-
wethL2Promise =
|
|
9726
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
9580
9727
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9581
9728
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
9582
9729
|
return weth;
|
|
@@ -9585,7 +9732,7 @@ function createTokensResource(client) {
|
|
|
9585
9732
|
return wethL2Promise;
|
|
9586
9733
|
}
|
|
9587
9734
|
async function toL2Address(l1Token) {
|
|
9588
|
-
return
|
|
9735
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
9589
9736
|
const normalized = normalizeL1Token(l1Token);
|
|
9590
9737
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9591
9738
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -9598,7 +9745,7 @@ function createTokensResource(client) {
|
|
|
9598
9745
|
});
|
|
9599
9746
|
}
|
|
9600
9747
|
async function toL1Address(l2Token) {
|
|
9601
|
-
return
|
|
9748
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
9602
9749
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
9603
9750
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
9604
9751
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -9619,32 +9766,32 @@ function createTokensResource(client) {
|
|
|
9619
9766
|
});
|
|
9620
9767
|
}
|
|
9621
9768
|
async function assetIdOfL1(l1Token) {
|
|
9622
|
-
return
|
|
9769
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
9623
9770
|
const normalized = normalizeL1Token(l1Token);
|
|
9624
9771
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9625
9772
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
9626
9773
|
});
|
|
9627
9774
|
}
|
|
9628
9775
|
async function assetIdOfL2(l2Token) {
|
|
9629
|
-
return
|
|
9776
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
9630
9777
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9631
9778
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
9632
9779
|
});
|
|
9633
9780
|
}
|
|
9634
9781
|
async function l2TokenFromAssetId(assetId) {
|
|
9635
|
-
return
|
|
9782
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
9636
9783
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9637
9784
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
9638
9785
|
});
|
|
9639
9786
|
}
|
|
9640
9787
|
async function l1TokenFromAssetId(assetId) {
|
|
9641
|
-
return
|
|
9788
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
9642
9789
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9643
9790
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
9644
9791
|
});
|
|
9645
9792
|
}
|
|
9646
9793
|
async function originChainId(assetId) {
|
|
9647
|
-
return
|
|
9794
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
9648
9795
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9649
9796
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
9650
9797
|
});
|
|
@@ -9653,7 +9800,7 @@ function createTokensResource(client) {
|
|
|
9653
9800
|
return getBaseTokenAssetId();
|
|
9654
9801
|
}
|
|
9655
9802
|
async function isChainEthBased() {
|
|
9656
|
-
return
|
|
9803
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
9657
9804
|
const baseAssetId = await getBaseTokenAssetId();
|
|
9658
9805
|
const l1ChainId = await getL1ChainId();
|
|
9659
9806
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -9671,7 +9818,7 @@ function createTokensResource(client) {
|
|
|
9671
9818
|
return getWethL2();
|
|
9672
9819
|
}
|
|
9673
9820
|
async function computeL2BridgedAddress(args) {
|
|
9674
|
-
return
|
|
9821
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
9675
9822
|
const normalized = normalizeL1Token(args.l1Token);
|
|
9676
9823
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9677
9824
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -9682,7 +9829,7 @@ function createTokensResource(client) {
|
|
|
9682
9829
|
});
|
|
9683
9830
|
}
|
|
9684
9831
|
async function resolve(ref, opts) {
|
|
9685
|
-
return
|
|
9832
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
9686
9833
|
let chain;
|
|
9687
9834
|
let address;
|
|
9688
9835
|
if (typeof ref === "string") {
|
|
@@ -10270,12 +10417,12 @@ function buildFeeBreakdown2(p) {
|
|
|
10270
10417
|
}
|
|
10271
10418
|
|
|
10272
10419
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
10273
|
-
var { wrapAs:
|
|
10420
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
10274
10421
|
function routeEthBase() {
|
|
10275
10422
|
return {
|
|
10276
10423
|
async build(p, ctx) {
|
|
10277
10424
|
const steps = [];
|
|
10278
|
-
const data = await
|
|
10425
|
+
const data = await wrapAs8(
|
|
10279
10426
|
"INTERNAL",
|
|
10280
10427
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
10281
10428
|
() => Promise.resolve(
|
|
@@ -10325,14 +10472,14 @@ function routeEthBase() {
|
|
|
10325
10472
|
}
|
|
10326
10473
|
};
|
|
10327
10474
|
}
|
|
10328
|
-
var { wrapAs:
|
|
10475
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
10329
10476
|
function routeErc20NonBase2() {
|
|
10330
10477
|
return {
|
|
10331
10478
|
// TODO: add preflight validations here
|
|
10332
10479
|
async build(p, ctx) {
|
|
10333
10480
|
const steps = [];
|
|
10334
10481
|
const approvals = [];
|
|
10335
|
-
const current = await
|
|
10482
|
+
const current = await wrapAs9(
|
|
10336
10483
|
"CONTRACT",
|
|
10337
10484
|
OP_WITHDRAWALS.erc20.allowance,
|
|
10338
10485
|
() => ctx.client.l2.readContract({
|
|
@@ -10371,7 +10518,7 @@ function routeErc20NonBase2() {
|
|
|
10371
10518
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
10372
10519
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
10373
10520
|
}
|
|
10374
|
-
const approveSim = await
|
|
10521
|
+
const approveSim = await wrapAs9(
|
|
10375
10522
|
"CONTRACT",
|
|
10376
10523
|
OP_WITHDRAWALS.erc20.estGas,
|
|
10377
10524
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10398,7 +10545,7 @@ function routeErc20NonBase2() {
|
|
|
10398
10545
|
tx: approveTx
|
|
10399
10546
|
});
|
|
10400
10547
|
}
|
|
10401
|
-
const assetId = (await
|
|
10548
|
+
const assetId = (await wrapAs9(
|
|
10402
10549
|
"CONTRACT",
|
|
10403
10550
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10404
10551
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10449,7 +10596,7 @@ function routeErc20NonBase2() {
|
|
|
10449
10596
|
...withdrawGas
|
|
10450
10597
|
};
|
|
10451
10598
|
} else {
|
|
10452
|
-
const sim = await
|
|
10599
|
+
const sim = await wrapAs9(
|
|
10453
10600
|
"CONTRACT",
|
|
10454
10601
|
OP_WITHDRAWALS.erc20.estGas,
|
|
10455
10602
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10611,7 +10758,7 @@ function buildWithdrawalBundle(input) {
|
|
|
10611
10758
|
}
|
|
10612
10759
|
|
|
10613
10760
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
10614
|
-
var { wrapAs:
|
|
10761
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
10615
10762
|
var attributes = createViemAttributesResource();
|
|
10616
10763
|
function saltFor(sender, nonce) {
|
|
10617
10764
|
return viem.keccak256(
|
|
@@ -10636,7 +10783,7 @@ function routeInteropBundle() {
|
|
|
10636
10783
|
if (isBaseToken) {
|
|
10637
10784
|
assetId = ctx.baseTokenAssetId;
|
|
10638
10785
|
} else {
|
|
10639
|
-
assetId = (await
|
|
10786
|
+
assetId = (await wrapAs10(
|
|
10640
10787
|
"CONTRACT",
|
|
10641
10788
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10642
10789
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10651,7 +10798,7 @@ function routeInteropBundle() {
|
|
|
10651
10798
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
10652
10799
|
}
|
|
10653
10800
|
)).result;
|
|
10654
|
-
const current = await
|
|
10801
|
+
const current = await wrapAs10(
|
|
10655
10802
|
"CONTRACT",
|
|
10656
10803
|
OP_WITHDRAWALS.erc20.allowance,
|
|
10657
10804
|
() => ctx.client.l2.readContract({
|
|
@@ -10700,7 +10847,7 @@ function routeInteropBundle() {
|
|
|
10700
10847
|
});
|
|
10701
10848
|
}
|
|
10702
10849
|
}
|
|
10703
|
-
const nonce = await
|
|
10850
|
+
const nonce = await wrapAs10(
|
|
10704
10851
|
"RPC",
|
|
10705
10852
|
OP_WITHDRAWALS.prepare,
|
|
10706
10853
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -10936,7 +11083,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
10936
11083
|
}
|
|
10937
11084
|
};
|
|
10938
11085
|
}
|
|
10939
|
-
var { wrapAs:
|
|
11086
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
10940
11087
|
var IL1NullifierMini = [
|
|
10941
11088
|
{
|
|
10942
11089
|
type: "function",
|
|
@@ -10954,7 +11101,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10954
11101
|
async function finalizationTarget(protocol) {
|
|
10955
11102
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
10956
11103
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
10957
|
-
return await
|
|
11104
|
+
return await wrapAs11(
|
|
10958
11105
|
"CONTRACT",
|
|
10959
11106
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10960
11107
|
() => client.l1.readContract({
|
|
@@ -10969,7 +11116,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10969
11116
|
);
|
|
10970
11117
|
}
|
|
10971
11118
|
async function fetchMessageAndProof(l2TxHash) {
|
|
10972
|
-
const raw = await
|
|
11119
|
+
const raw = await wrapAs11(
|
|
10973
11120
|
"RPC",
|
|
10974
11121
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10975
11122
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -10986,7 +11133,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10986
11133
|
context: { l2TxHash }
|
|
10987
11134
|
});
|
|
10988
11135
|
}
|
|
10989
|
-
const ev = await
|
|
11136
|
+
const ev = await wrapAs11(
|
|
10990
11137
|
"INTERNAL",
|
|
10991
11138
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
10992
11139
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -10996,7 +11143,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10996
11143
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
10997
11144
|
}
|
|
10998
11145
|
);
|
|
10999
|
-
const message = await
|
|
11146
|
+
const message = await wrapAs11(
|
|
11000
11147
|
"INTERNAL",
|
|
11001
11148
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
11002
11149
|
() => {
|
|
@@ -11008,7 +11155,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11008
11155
|
message: "Failed to decode withdrawal message."
|
|
11009
11156
|
}
|
|
11010
11157
|
);
|
|
11011
|
-
const idx = await
|
|
11158
|
+
const idx = await wrapAs11(
|
|
11012
11159
|
"INTERNAL",
|
|
11013
11160
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
11014
11161
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -11017,7 +11164,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11017
11164
|
message: "Failed to derive messenger log index."
|
|
11018
11165
|
}
|
|
11019
11166
|
);
|
|
11020
|
-
const proof = await
|
|
11167
|
+
const proof = await wrapAs11(
|
|
11021
11168
|
"RPC",
|
|
11022
11169
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
11023
11170
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -11026,7 +11173,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11026
11173
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
11027
11174
|
}
|
|
11028
11175
|
);
|
|
11029
|
-
const chainId = await
|
|
11176
|
+
const chainId = await wrapAs11(
|
|
11030
11177
|
"RPC",
|
|
11031
11178
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
11032
11179
|
() => client.l2.getChainId(),
|
|
@@ -11084,7 +11231,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11084
11231
|
async function withdrawalOutcome(finalization) {
|
|
11085
11232
|
const target = await finalizationTarget(finalization.protocol);
|
|
11086
11233
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
11087
|
-
const done = await
|
|
11234
|
+
const done = await wrapAs11(
|
|
11088
11235
|
"RPC",
|
|
11089
11236
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11090
11237
|
() => client.l1.readContract({
|
|
@@ -11106,7 +11253,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11106
11253
|
}
|
|
11107
11254
|
const { bundleHash } = finalization.params;
|
|
11108
11255
|
const status = Number(
|
|
11109
|
-
await
|
|
11256
|
+
await wrapAs11(
|
|
11110
11257
|
"RPC",
|
|
11111
11258
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11112
11259
|
() => client.l1.readContract({
|
|
@@ -11123,7 +11270,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11123
11270
|
);
|
|
11124
11271
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
11125
11272
|
const callStatus = Number(
|
|
11126
|
-
await
|
|
11273
|
+
await wrapAs11(
|
|
11127
11274
|
"RPC",
|
|
11128
11275
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11129
11276
|
() => client.l1.readContract({
|
|
@@ -11194,7 +11341,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11194
11341
|
},
|
|
11195
11342
|
async estimateFinalization(finalization) {
|
|
11196
11343
|
const target = await finalizationTarget(finalization.protocol);
|
|
11197
|
-
const gasLimit = await
|
|
11344
|
+
const gasLimit = await wrapAs11(
|
|
11198
11345
|
"RPC",
|
|
11199
11346
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11200
11347
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -11222,7 +11369,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11222
11369
|
let maxFeePerGas;
|
|
11223
11370
|
let maxPriorityFeePerGas;
|
|
11224
11371
|
try {
|
|
11225
|
-
const fee = await
|
|
11372
|
+
const fee = await wrapAs11(
|
|
11226
11373
|
"RPC",
|
|
11227
11374
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11228
11375
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -11241,7 +11388,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11241
11388
|
})();
|
|
11242
11389
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
11243
11390
|
} catch {
|
|
11244
|
-
const gasPrice = await
|
|
11391
|
+
const gasPrice = await wrapAs11(
|
|
11245
11392
|
"RPC",
|
|
11246
11393
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11247
11394
|
() => client.l1.getGasPrice(),
|