@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
|
@@ -6299,7 +6299,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6299
6299
|
function wrap7(operation, fn, opts) {
|
|
6300
6300
|
return run("INTERNAL", operation, fn, opts);
|
|
6301
6301
|
}
|
|
6302
|
-
function
|
|
6302
|
+
function wrapAs12(kind, operation, fn, opts) {
|
|
6303
6303
|
return run(kind, operation, fn, opts);
|
|
6304
6304
|
}
|
|
6305
6305
|
async function toResult3(operation, fn, opts) {
|
|
@@ -6320,7 +6320,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6320
6320
|
return { ok: false, error: shaped };
|
|
6321
6321
|
}
|
|
6322
6322
|
}
|
|
6323
|
-
return { wrap: wrap7, wrapAs:
|
|
6323
|
+
return { wrap: wrap7, wrapAs: wrapAs12, toResult: toResult3 };
|
|
6324
6324
|
}
|
|
6325
6325
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
6326
6326
|
}
|
|
@@ -6469,6 +6469,7 @@ function isEraVmChain(chainIdL2) {
|
|
|
6469
6469
|
|
|
6470
6470
|
// src/core/resources/deposits/gas.ts
|
|
6471
6471
|
var CREATE_REESTIMATE_BUFFER = 15n;
|
|
6472
|
+
var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
6472
6473
|
var maxBigInt = (a, b) => a > b ? a : b;
|
|
6473
6474
|
function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
|
|
6474
6475
|
return gasLimit * (100n + bufferPct) / 100n;
|
|
@@ -6519,15 +6520,39 @@ async function fetchFees(estimator) {
|
|
|
6519
6520
|
const gp = await estimator.getGasPrice();
|
|
6520
6521
|
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
6521
6522
|
} catch {
|
|
6522
|
-
return
|
|
6523
|
+
return void 0;
|
|
6524
|
+
}
|
|
6525
|
+
}
|
|
6526
|
+
async function quoteL1Fees(input) {
|
|
6527
|
+
const { estimator, overrides } = input;
|
|
6528
|
+
const maxFeeOverride = overrides?.maxFeePerGas;
|
|
6529
|
+
const tipOverride = overrides?.maxPriorityFeePerGas;
|
|
6530
|
+
if (maxFeeOverride != null && tipOverride != null) {
|
|
6531
|
+
return { maxFeePerGas: maxFeeOverride, maxPriorityFeePerGas: tipOverride };
|
|
6532
|
+
}
|
|
6533
|
+
const market = await fetchFees(estimator);
|
|
6534
|
+
if (maxFeeOverride != null) {
|
|
6535
|
+
const tip = market?.maxPriorityFeePerGas ?? 0n;
|
|
6536
|
+
return {
|
|
6537
|
+
maxFeePerGas: maxFeeOverride,
|
|
6538
|
+
maxPriorityFeePerGas: tip < maxFeeOverride ? tip : maxFeeOverride
|
|
6539
|
+
};
|
|
6540
|
+
}
|
|
6541
|
+
if (market == null) {
|
|
6542
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
6523
6543
|
}
|
|
6544
|
+
if (tipOverride != null) {
|
|
6545
|
+
const headroom = market.maxFeePerGas > market.maxPriorityFeePerGas ? market.maxFeePerGas - market.maxPriorityFeePerGas : 0n;
|
|
6546
|
+
return { maxFeePerGas: headroom + tipOverride, maxPriorityFeePerGas: tipOverride };
|
|
6547
|
+
}
|
|
6548
|
+
return market;
|
|
6524
6549
|
}
|
|
6525
6550
|
async function quoteL1Gas(input) {
|
|
6526
6551
|
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
6527
6552
|
let market;
|
|
6528
6553
|
const getMarket = async () => {
|
|
6529
6554
|
if (market) return market;
|
|
6530
|
-
market = await fetchFees(estimator);
|
|
6555
|
+
market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
6531
6556
|
return market;
|
|
6532
6557
|
};
|
|
6533
6558
|
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
@@ -6549,7 +6574,7 @@ async function quoteL1Gas(input) {
|
|
|
6549
6574
|
}
|
|
6550
6575
|
async function quoteL2Gas(input) {
|
|
6551
6576
|
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
6552
|
-
const market = await fetchFees(estimator);
|
|
6577
|
+
const market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
6553
6578
|
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
6554
6579
|
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
6555
6580
|
const explicit = overrideGasLimit ?? txGasLimit;
|
|
@@ -6591,10 +6616,28 @@ async function quoteL2Gas(input) {
|
|
|
6591
6616
|
}
|
|
6592
6617
|
|
|
6593
6618
|
// src/core/resources/deposits/priority.ts
|
|
6619
|
+
var ZK_CHAIN_PRICING_GETTERS_ABI = [
|
|
6620
|
+
{
|
|
6621
|
+
type: "function",
|
|
6622
|
+
name: "getZKsyncOS",
|
|
6623
|
+
stateMutability: "view",
|
|
6624
|
+
inputs: [],
|
|
6625
|
+
outputs: [{ name: "", type: "bool" }]
|
|
6626
|
+
},
|
|
6627
|
+
{
|
|
6628
|
+
type: "function",
|
|
6629
|
+
name: "getPubdataPricingMode",
|
|
6630
|
+
stateMutability: "view",
|
|
6631
|
+
inputs: [],
|
|
6632
|
+
outputs: [{ name: "", type: "uint8" }]
|
|
6633
|
+
}
|
|
6634
|
+
];
|
|
6635
|
+
var PUBDATA_PRICING_MODE_ROLLUP = 0;
|
|
6594
6636
|
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6595
6637
|
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
6596
6638
|
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
6597
6639
|
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
6640
|
+
var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
|
|
6598
6641
|
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
6599
6642
|
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6600
6643
|
function applyL1ToL2Alias(address) {
|
|
@@ -6641,6 +6684,16 @@ function clampPriorityL2GasLimit(input) {
|
|
|
6641
6684
|
})
|
|
6642
6685
|
);
|
|
6643
6686
|
}
|
|
6687
|
+
function resolveBaseTokenPriorityL2GasLimit(input) {
|
|
6688
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
6689
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
6690
|
+
}
|
|
6691
|
+
if (!input.chargesPubdata) return input.priorityFloorGasLimit;
|
|
6692
|
+
return maxBigInt2(
|
|
6693
|
+
input.priorityFloorGasLimit,
|
|
6694
|
+
applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
|
|
6695
|
+
);
|
|
6696
|
+
}
|
|
6644
6697
|
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
6645
6698
|
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
6646
6699
|
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
@@ -6651,8 +6704,6 @@ function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
|
6651
6704
|
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
6652
6705
|
);
|
|
6653
6706
|
}
|
|
6654
|
-
|
|
6655
|
-
// src/adapters/viem/estimator.ts
|
|
6656
6707
|
function toCoreTx(tx) {
|
|
6657
6708
|
return {
|
|
6658
6709
|
to: tx.to,
|
|
@@ -6711,6 +6762,7 @@ function viemToGasEstimator(client) {
|
|
|
6711
6762
|
from: tx.from,
|
|
6712
6763
|
to: tx.to,
|
|
6713
6764
|
data: tx.data,
|
|
6765
|
+
...tx.value != null ? { value: viem.toHex(tx.value) } : {},
|
|
6714
6766
|
type: ZKSYNC_OS_PRIORITY_TX_TYPE
|
|
6715
6767
|
}
|
|
6716
6768
|
]
|
|
@@ -6749,6 +6801,7 @@ function viemToGasEstimator(client) {
|
|
|
6749
6801
|
}
|
|
6750
6802
|
|
|
6751
6803
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
6804
|
+
var { wrapAs } = createErrorHandlers("deposits");
|
|
6752
6805
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
6753
6806
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
6754
6807
|
if (!leg) return void 0;
|
|
@@ -6758,6 +6811,60 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
6758
6811
|
return void 0;
|
|
6759
6812
|
}
|
|
6760
6813
|
}
|
|
6814
|
+
async function resolvePriorityTxL2Sender(ctx) {
|
|
6815
|
+
try {
|
|
6816
|
+
const code = await ctx.client.l1.getCode({ address: ctx.sender });
|
|
6817
|
+
if (!code || code === "0x") return ctx.sender;
|
|
6818
|
+
} catch {
|
|
6819
|
+
}
|
|
6820
|
+
return applyL1ToL2Alias(ctx.sender);
|
|
6821
|
+
}
|
|
6822
|
+
var chainPricingCache = /* @__PURE__ */ new WeakMap();
|
|
6823
|
+
var isContractRevert = (err) => err instanceof viem.BaseError && err.walk((e) => e instanceof viem.ContractFunctionRevertedError) != null;
|
|
6824
|
+
async function readChainPricing(ctx) {
|
|
6825
|
+
const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
|
|
6826
|
+
if (cached) return cached;
|
|
6827
|
+
try {
|
|
6828
|
+
const zkChain = await ctx.client.l1.readContract({
|
|
6829
|
+
address: ctx.bridgehub,
|
|
6830
|
+
abi: IBridgehub_default,
|
|
6831
|
+
functionName: "getZKChain",
|
|
6832
|
+
args: [ctx.chainIdL2]
|
|
6833
|
+
});
|
|
6834
|
+
const read = (functionName) => ctx.client.l1.readContract({
|
|
6835
|
+
address: zkChain,
|
|
6836
|
+
abi: ZK_CHAIN_PRICING_GETTERS_ABI,
|
|
6837
|
+
functionName
|
|
6838
|
+
});
|
|
6839
|
+
let zksyncOS;
|
|
6840
|
+
try {
|
|
6841
|
+
zksyncOS = await read("getZKsyncOS");
|
|
6842
|
+
} catch (err) {
|
|
6843
|
+
if (!isContractRevert(err)) throw err;
|
|
6844
|
+
zksyncOS = false;
|
|
6845
|
+
}
|
|
6846
|
+
const chargesPubdata = zksyncOS && Number(await read("getPubdataPricingMode")) === PUBDATA_PRICING_MODE_ROLLUP;
|
|
6847
|
+
const pricing = { zksyncOS, chargesPubdata };
|
|
6848
|
+
const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
|
|
6849
|
+
perClient.set(ctx.chainIdL2, pricing);
|
|
6850
|
+
chainPricingCache.set(ctx.client, perClient);
|
|
6851
|
+
return pricing;
|
|
6852
|
+
} catch {
|
|
6853
|
+
return void 0;
|
|
6854
|
+
}
|
|
6855
|
+
}
|
|
6856
|
+
async function quoteL1Fees2(input) {
|
|
6857
|
+
const { ctx } = input;
|
|
6858
|
+
return wrapAs(
|
|
6859
|
+
"RPC",
|
|
6860
|
+
"deposits.fees.l1",
|
|
6861
|
+
() => quoteL1Fees({
|
|
6862
|
+
estimator: viemToGasEstimator(ctx.client.l1),
|
|
6863
|
+
overrides: ctx.gasOverrides
|
|
6864
|
+
}),
|
|
6865
|
+
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
6866
|
+
);
|
|
6867
|
+
}
|
|
6761
6868
|
async function quoteL1Gas2(input) {
|
|
6762
6869
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
6763
6870
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -6782,6 +6889,26 @@ async function quoteL2Gas2(input) {
|
|
|
6782
6889
|
stateOverrides: input.stateOverrides
|
|
6783
6890
|
});
|
|
6784
6891
|
}
|
|
6892
|
+
async function determineBaseL2GasLimit(input) {
|
|
6893
|
+
const { ctx } = input;
|
|
6894
|
+
if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
|
|
6895
|
+
const [pricing, from] = await Promise.all([
|
|
6896
|
+
readChainPricing(ctx),
|
|
6897
|
+
resolvePriorityTxL2Sender(ctx)
|
|
6898
|
+
]);
|
|
6899
|
+
if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
|
|
6900
|
+
return resolveBaseTokenPriorityL2GasLimit({
|
|
6901
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6902
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
6903
|
+
chargesPubdata: pricing?.chargesPubdata ?? true,
|
|
6904
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
|
|
6905
|
+
from,
|
|
6906
|
+
to: input.l2Contract,
|
|
6907
|
+
data: input.l2Calldata,
|
|
6908
|
+
value: input.l2Value
|
|
6909
|
+
})
|
|
6910
|
+
});
|
|
6911
|
+
}
|
|
6785
6912
|
async function determineNonBaseL2Gas(input) {
|
|
6786
6913
|
const { ctx, l1Token, route } = input;
|
|
6787
6914
|
const fallbackQuote = () => quoteL2Gas2({
|
|
@@ -6860,13 +6987,10 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
6860
6987
|
}
|
|
6861
6988
|
|
|
6862
6989
|
// src/adapters/viem/resources/deposits/services/fee.ts
|
|
6863
|
-
var { wrapAs } = createErrorHandlers("deposits");
|
|
6990
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
6864
6991
|
async function quoteL2BaseCost(input) {
|
|
6865
|
-
const { ctx, l2GasLimit } = input;
|
|
6866
|
-
|
|
6867
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
6868
|
-
const gasPrice = fees.maxFeePerGas ?? fees.gasPrice ?? await estimator.getGasPrice();
|
|
6869
|
-
return wrapAs(
|
|
6992
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
6993
|
+
return wrapAs2(
|
|
6870
6994
|
"RPC",
|
|
6871
6995
|
"deposits.fees.l2BaseCost",
|
|
6872
6996
|
async () => {
|
|
@@ -6874,7 +6998,7 @@ async function quoteL2BaseCost(input) {
|
|
|
6874
6998
|
address: ctx.bridgehub,
|
|
6875
6999
|
abi: IBridgehub_default,
|
|
6876
7000
|
functionName: "l2TransactionBaseCost",
|
|
6877
|
-
args: [ctx.chainIdL2,
|
|
7001
|
+
args: [ctx.chainIdL2, l1GasPrice, l2GasLimit, ctx.gasPerPubdata]
|
|
6878
7002
|
});
|
|
6879
7003
|
},
|
|
6880
7004
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
@@ -6969,7 +7093,7 @@ function getPriorityTxGasBreakdown(input) {
|
|
|
6969
7093
|
}
|
|
6970
7094
|
|
|
6971
7095
|
// src/adapters/viem/resources/deposits/routes/eth.ts
|
|
6972
|
-
var { wrapAs:
|
|
7096
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
6973
7097
|
var EMPTY_BYTES2 = "0x";
|
|
6974
7098
|
function routeEthDirect() {
|
|
6975
7099
|
return {
|
|
@@ -6984,13 +7108,19 @@ function routeEthDirect() {
|
|
|
6984
7108
|
l2Calldata,
|
|
6985
7109
|
gasPerPubdata: ctx.gasPerPubdata
|
|
6986
7110
|
});
|
|
6987
|
-
const quotedL2GasLimit =
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
}),
|
|
7111
|
+
const quotedL2GasLimit = await determineBaseL2GasLimit({
|
|
7112
|
+
ctx,
|
|
7113
|
+
l2Contract,
|
|
7114
|
+
l2Value,
|
|
6992
7115
|
l2Calldata,
|
|
6993
|
-
|
|
7116
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7117
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7118
|
+
chainIdL2: ctx.chainIdL2,
|
|
7119
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7120
|
+
}),
|
|
7121
|
+
l2Calldata,
|
|
7122
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
7123
|
+
})
|
|
6994
7124
|
});
|
|
6995
7125
|
const l2GasParams = await quoteL2Gas2({
|
|
6996
7126
|
ctx,
|
|
@@ -7000,7 +7130,12 @@ function routeEthDirect() {
|
|
|
7000
7130
|
if (!l2GasParams) {
|
|
7001
7131
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
7002
7132
|
}
|
|
7003
|
-
const
|
|
7133
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7134
|
+
const baseCost = await quoteL2BaseCost({
|
|
7135
|
+
ctx,
|
|
7136
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
7137
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7138
|
+
});
|
|
7004
7139
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
7005
7140
|
const req = buildDirectRequestStruct({
|
|
7006
7141
|
chainId: ctx.chainIdL2,
|
|
@@ -7011,7 +7146,7 @@ function routeEthDirect() {
|
|
|
7011
7146
|
l2Contract,
|
|
7012
7147
|
l2Value
|
|
7013
7148
|
});
|
|
7014
|
-
const sim = await
|
|
7149
|
+
const sim = await wrapAs3(
|
|
7015
7150
|
"RPC",
|
|
7016
7151
|
OP_DEPOSITS.eth.estGas,
|
|
7017
7152
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7037,22 +7172,19 @@ function routeEthDirect() {
|
|
|
7037
7172
|
data,
|
|
7038
7173
|
value: mintValue,
|
|
7039
7174
|
from: ctx.sender,
|
|
7040
|
-
...ctx.gasOverrides
|
|
7175
|
+
...ctx.gasOverrides,
|
|
7176
|
+
...l1Fees
|
|
7041
7177
|
};
|
|
7042
7178
|
const l1Gas = await quoteL1Gas2({
|
|
7043
7179
|
ctx,
|
|
7044
7180
|
tx: l1TxCandidate,
|
|
7045
7181
|
overrides: ctx.gasOverrides
|
|
7046
7182
|
});
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
maxFeePerGas: l1Gas.maxFeePerGas,
|
|
7053
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7054
|
-
};
|
|
7055
|
-
}
|
|
7183
|
+
const bridgeTx = {
|
|
7184
|
+
...sim.request,
|
|
7185
|
+
...l1Fees,
|
|
7186
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7187
|
+
};
|
|
7056
7188
|
const steps = [
|
|
7057
7189
|
{
|
|
7058
7190
|
key: "bridgehub:direct",
|
|
@@ -7140,7 +7272,7 @@ async function buildApprovalRequest({
|
|
|
7140
7272
|
}
|
|
7141
7273
|
|
|
7142
7274
|
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
7143
|
-
var { wrapAs:
|
|
7275
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
7144
7276
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7145
7277
|
var ntvCodec = createNTVCodec({
|
|
7146
7278
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -7231,7 +7363,7 @@ function routeErc20NonBase() {
|
|
|
7231
7363
|
return {
|
|
7232
7364
|
// TODO: do we even need these validations?
|
|
7233
7365
|
async preflight(p, ctx) {
|
|
7234
|
-
await
|
|
7366
|
+
await wrapAs4(
|
|
7235
7367
|
"VALIDATION",
|
|
7236
7368
|
OP_DEPOSITS.nonbase.assertNotEthAsset,
|
|
7237
7369
|
() => {
|
|
@@ -7242,7 +7374,7 @@ function routeErc20NonBase() {
|
|
|
7242
7374
|
{ ctx: { token: p.token } }
|
|
7243
7375
|
);
|
|
7244
7376
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7245
|
-
await
|
|
7377
|
+
await wrapAs4(
|
|
7246
7378
|
"VALIDATION",
|
|
7247
7379
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
7248
7380
|
() => {
|
|
@@ -7259,7 +7391,7 @@ function routeErc20NonBase() {
|
|
|
7259
7391
|
const assetRouter = ctx.l1AssetRouter;
|
|
7260
7392
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
7261
7393
|
const receiver = p.to ?? ctx.sender;
|
|
7262
|
-
const secondBridgeCalldata = await
|
|
7394
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
7263
7395
|
"INTERNAL",
|
|
7264
7396
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
7265
7397
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -7297,11 +7429,16 @@ function routeErc20NonBase() {
|
|
|
7297
7429
|
}
|
|
7298
7430
|
});
|
|
7299
7431
|
if (!l2Gas) throw new Error("Failed to establish L2 gas parameters.");
|
|
7300
|
-
const
|
|
7432
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7433
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7434
|
+
ctx,
|
|
7435
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7436
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7437
|
+
});
|
|
7301
7438
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
7302
7439
|
const approvals = [];
|
|
7303
7440
|
const steps = [];
|
|
7304
|
-
const depositAllowance = await
|
|
7441
|
+
const depositAllowance = await wrapAs4(
|
|
7305
7442
|
"CONTRACT",
|
|
7306
7443
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
7307
7444
|
() => ctx.client.l1.readContract({
|
|
@@ -7316,7 +7453,7 @@ function routeErc20NonBase() {
|
|
|
7316
7453
|
}
|
|
7317
7454
|
);
|
|
7318
7455
|
if (depositAllowance < p.amount) {
|
|
7319
|
-
const approveTx = await
|
|
7456
|
+
const approveTx = await wrapAs4(
|
|
7320
7457
|
"CONTRACT",
|
|
7321
7458
|
OP_DEPOSITS.nonbase.estGas,
|
|
7322
7459
|
() => buildApprovalRequest({
|
|
@@ -7339,7 +7476,7 @@ function routeErc20NonBase() {
|
|
|
7339
7476
|
});
|
|
7340
7477
|
}
|
|
7341
7478
|
if (!baseIsEth) {
|
|
7342
|
-
const baseAllowance = await
|
|
7479
|
+
const baseAllowance = await wrapAs4(
|
|
7343
7480
|
"CONTRACT",
|
|
7344
7481
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
7345
7482
|
() => ctx.client.l1.readContract({
|
|
@@ -7354,7 +7491,7 @@ function routeErc20NonBase() {
|
|
|
7354
7491
|
}
|
|
7355
7492
|
);
|
|
7356
7493
|
if (baseAllowance < mintValue) {
|
|
7357
|
-
const approveBaseTx = await
|
|
7494
|
+
const approveBaseTx = await wrapAs4(
|
|
7358
7495
|
"CONTRACT",
|
|
7359
7496
|
OP_DEPOSITS.nonbase.estGas,
|
|
7360
7497
|
() => buildApprovalRequest({
|
|
@@ -7399,7 +7536,8 @@ function routeErc20NonBase() {
|
|
|
7399
7536
|
data: calldata,
|
|
7400
7537
|
value: msgValue,
|
|
7401
7538
|
from: ctx.sender,
|
|
7402
|
-
...ctx.gasOverrides
|
|
7539
|
+
...ctx.gasOverrides,
|
|
7540
|
+
...l1Fees
|
|
7403
7541
|
};
|
|
7404
7542
|
const l1Gas = await quoteL1Gas2({
|
|
7405
7543
|
ctx,
|
|
@@ -7419,7 +7557,7 @@ function routeErc20NonBase() {
|
|
|
7419
7557
|
account: ctx.client.account
|
|
7420
7558
|
};
|
|
7421
7559
|
} else {
|
|
7422
|
-
const sim = await
|
|
7560
|
+
const sim = await wrapAs4(
|
|
7423
7561
|
"CONTRACT",
|
|
7424
7562
|
OP_DEPOSITS.nonbase.estGas,
|
|
7425
7563
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7437,14 +7575,11 @@ function routeErc20NonBase() {
|
|
|
7437
7575
|
);
|
|
7438
7576
|
bridgeTx = { ...sim.request };
|
|
7439
7577
|
}
|
|
7440
|
-
|
|
7441
|
-
bridgeTx
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7446
|
-
};
|
|
7447
|
-
}
|
|
7578
|
+
bridgeTx = {
|
|
7579
|
+
...bridgeTx,
|
|
7580
|
+
...l1Fees,
|
|
7581
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7582
|
+
};
|
|
7448
7583
|
steps.push({
|
|
7449
7584
|
key: "bridgehub:two-bridges:erc20-nonbase",
|
|
7450
7585
|
kind: "bridgehub:two-bridges",
|
|
@@ -7467,7 +7602,7 @@ function routeErc20NonBase() {
|
|
|
7467
7602
|
}
|
|
7468
7603
|
};
|
|
7469
7604
|
}
|
|
7470
|
-
var { wrapAs:
|
|
7605
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
7471
7606
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7472
7607
|
var ntvCodec2 = createNTVCodec({
|
|
7473
7608
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -7551,7 +7686,7 @@ function routeEthNonBase() {
|
|
|
7551
7686
|
return {
|
|
7552
7687
|
// TODO: do we even need these validations?
|
|
7553
7688
|
async preflight(p, ctx) {
|
|
7554
|
-
await
|
|
7689
|
+
await wrapAs5(
|
|
7555
7690
|
"VALIDATION",
|
|
7556
7691
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
7557
7692
|
() => {
|
|
@@ -7561,7 +7696,7 @@ function routeEthNonBase() {
|
|
|
7561
7696
|
},
|
|
7562
7697
|
{ ctx: { token: p.token } }
|
|
7563
7698
|
);
|
|
7564
|
-
await
|
|
7699
|
+
await wrapAs5(
|
|
7565
7700
|
"VALIDATION",
|
|
7566
7701
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
7567
7702
|
() => {
|
|
@@ -7571,7 +7706,7 @@ function routeEthNonBase() {
|
|
|
7571
7706
|
},
|
|
7572
7707
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
7573
7708
|
);
|
|
7574
|
-
const ethBal = await
|
|
7709
|
+
const ethBal = await wrapAs5(
|
|
7575
7710
|
"RPC",
|
|
7576
7711
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
7577
7712
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -7580,7 +7715,7 @@ function routeEthNonBase() {
|
|
|
7580
7715
|
message: "Failed to read L1 ETH balance."
|
|
7581
7716
|
}
|
|
7582
7717
|
);
|
|
7583
|
-
await
|
|
7718
|
+
await wrapAs5(
|
|
7584
7719
|
"VALIDATION",
|
|
7585
7720
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
7586
7721
|
() => {
|
|
@@ -7613,11 +7748,16 @@ function routeEthNonBase() {
|
|
|
7613
7748
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
7614
7749
|
});
|
|
7615
7750
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
7616
|
-
const
|
|
7751
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7752
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7753
|
+
ctx,
|
|
7754
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7755
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7756
|
+
});
|
|
7617
7757
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
7618
7758
|
const approvals = [];
|
|
7619
7759
|
const steps = [];
|
|
7620
|
-
const allowance = await
|
|
7760
|
+
const allowance = await wrapAs5(
|
|
7621
7761
|
"CONTRACT",
|
|
7622
7762
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
7623
7763
|
() => ctx.client.l1.readContract({
|
|
@@ -7633,7 +7773,7 @@ function routeEthNonBase() {
|
|
|
7633
7773
|
);
|
|
7634
7774
|
const needsApprove = allowance < mintValue;
|
|
7635
7775
|
if (needsApprove) {
|
|
7636
|
-
const approveTx = await
|
|
7776
|
+
const approveTx = await wrapAs5(
|
|
7637
7777
|
"CONTRACT",
|
|
7638
7778
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7639
7779
|
() => buildApprovalRequest({
|
|
@@ -7655,7 +7795,7 @@ function routeEthNonBase() {
|
|
|
7655
7795
|
tx: approveTx
|
|
7656
7796
|
});
|
|
7657
7797
|
}
|
|
7658
|
-
const secondBridgeCalldata = await
|
|
7798
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
7659
7799
|
"INTERNAL",
|
|
7660
7800
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
7661
7801
|
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
@@ -7697,7 +7837,7 @@ function routeEthNonBase() {
|
|
|
7697
7837
|
args: [requestStruct]
|
|
7698
7838
|
});
|
|
7699
7839
|
} else {
|
|
7700
|
-
const sim = await
|
|
7840
|
+
const sim = await wrapAs5(
|
|
7701
7841
|
"CONTRACT",
|
|
7702
7842
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7703
7843
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7725,7 +7865,8 @@ function routeEthNonBase() {
|
|
|
7725
7865
|
data: calldata,
|
|
7726
7866
|
value: bridgehubValue,
|
|
7727
7867
|
from: ctx.sender,
|
|
7728
|
-
...ctx.gasOverrides
|
|
7868
|
+
...ctx.gasOverrides,
|
|
7869
|
+
...l1Fees
|
|
7729
7870
|
};
|
|
7730
7871
|
const l1Gas = await quoteL1Gas2({
|
|
7731
7872
|
ctx,
|
|
@@ -7733,14 +7874,11 @@ function routeEthNonBase() {
|
|
|
7733
7874
|
overrides: ctx.gasOverrides,
|
|
7734
7875
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
7735
7876
|
});
|
|
7736
|
-
|
|
7737
|
-
bridgeTx
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7742
|
-
};
|
|
7743
|
-
}
|
|
7877
|
+
bridgeTx = {
|
|
7878
|
+
...bridgeTx,
|
|
7879
|
+
...l1Fees,
|
|
7880
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7881
|
+
};
|
|
7744
7882
|
steps.push({
|
|
7745
7883
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
7746
7884
|
kind: "bridgehub:two-bridges",
|
|
@@ -7763,12 +7901,12 @@ function routeEthNonBase() {
|
|
|
7763
7901
|
}
|
|
7764
7902
|
};
|
|
7765
7903
|
}
|
|
7766
|
-
var { wrapAs:
|
|
7904
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
7767
7905
|
var EMPTY_BYTES3 = "0x";
|
|
7768
7906
|
function routeErc20Base() {
|
|
7769
7907
|
return {
|
|
7770
7908
|
async preflight(p, ctx) {
|
|
7771
|
-
await
|
|
7909
|
+
await wrapAs6(
|
|
7772
7910
|
"VALIDATION",
|
|
7773
7911
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
7774
7912
|
() => {
|
|
@@ -7779,7 +7917,7 @@ function routeErc20Base() {
|
|
|
7779
7917
|
{ ctx: { token: p.token } }
|
|
7780
7918
|
);
|
|
7781
7919
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7782
|
-
await
|
|
7920
|
+
await wrapAs6(
|
|
7783
7921
|
"VALIDATION",
|
|
7784
7922
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
7785
7923
|
() => {
|
|
@@ -7802,13 +7940,19 @@ function routeErc20Base() {
|
|
|
7802
7940
|
l2Calldata,
|
|
7803
7941
|
gasPerPubdata: ctx.gasPerPubdata
|
|
7804
7942
|
});
|
|
7805
|
-
const quotedL2GasLimit =
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
}),
|
|
7943
|
+
const quotedL2GasLimit = await determineBaseL2GasLimit({
|
|
7944
|
+
ctx,
|
|
7945
|
+
l2Contract,
|
|
7946
|
+
l2Value,
|
|
7810
7947
|
l2Calldata,
|
|
7811
|
-
|
|
7948
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7949
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7950
|
+
chainIdL2: ctx.chainIdL2,
|
|
7951
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7952
|
+
}),
|
|
7953
|
+
l2Calldata,
|
|
7954
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
7955
|
+
})
|
|
7812
7956
|
});
|
|
7813
7957
|
const l2Gas = await quoteL2Gas2({
|
|
7814
7958
|
ctx,
|
|
@@ -7816,11 +7960,16 @@ function routeErc20Base() {
|
|
|
7816
7960
|
overrideGasLimit: quotedL2GasLimit
|
|
7817
7961
|
});
|
|
7818
7962
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
7819
|
-
const
|
|
7963
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7964
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7965
|
+
ctx,
|
|
7966
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7967
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7968
|
+
});
|
|
7820
7969
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
7821
7970
|
const approvals = [];
|
|
7822
7971
|
const steps = [];
|
|
7823
|
-
const allowance = await
|
|
7972
|
+
const allowance = await wrapAs6(
|
|
7824
7973
|
"CONTRACT",
|
|
7825
7974
|
OP_DEPOSITS.base.allowance,
|
|
7826
7975
|
() => ctx.client.l1.readContract({
|
|
@@ -7836,7 +7985,7 @@ function routeErc20Base() {
|
|
|
7836
7985
|
);
|
|
7837
7986
|
const needsApprove = allowance < mintValue;
|
|
7838
7987
|
if (needsApprove) {
|
|
7839
|
-
const approveTx = await
|
|
7988
|
+
const approveTx = await wrapAs6(
|
|
7840
7989
|
"CONTRACT",
|
|
7841
7990
|
OP_DEPOSITS.base.estGas,
|
|
7842
7991
|
() => buildApprovalRequest({
|
|
@@ -7885,7 +8034,7 @@ function routeErc20Base() {
|
|
|
7885
8034
|
args: [req]
|
|
7886
8035
|
});
|
|
7887
8036
|
} else {
|
|
7888
|
-
const sim = await
|
|
8037
|
+
const sim = await wrapAs6(
|
|
7889
8038
|
"RPC",
|
|
7890
8039
|
OP_DEPOSITS.base.estGas,
|
|
7891
8040
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7913,7 +8062,8 @@ function routeErc20Base() {
|
|
|
7913
8062
|
data: calldata,
|
|
7914
8063
|
value: 0n,
|
|
7915
8064
|
from: ctx.sender,
|
|
7916
|
-
...ctx.gasOverrides
|
|
8065
|
+
...ctx.gasOverrides,
|
|
8066
|
+
...l1Fees
|
|
7917
8067
|
};
|
|
7918
8068
|
const l1Gas = await quoteL1Gas2({
|
|
7919
8069
|
ctx,
|
|
@@ -7921,14 +8071,11 @@ function routeErc20Base() {
|
|
|
7921
8071
|
overrides: ctx.gasOverrides,
|
|
7922
8072
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
7923
8073
|
});
|
|
7924
|
-
|
|
7925
|
-
bridgeTx
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7930
|
-
};
|
|
7931
|
-
}
|
|
8074
|
+
bridgeTx = {
|
|
8075
|
+
...bridgeTx,
|
|
8076
|
+
...l1Fees,
|
|
8077
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
8078
|
+
};
|
|
7932
8079
|
steps.push({
|
|
7933
8080
|
key: "bridgehub:direct:erc20-base",
|
|
7934
8081
|
kind: "bridgehub:direct",
|
|
@@ -8026,7 +8173,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
8026
8173
|
}
|
|
8027
8174
|
return { l2Receipt, l2TxHash };
|
|
8028
8175
|
}
|
|
8029
|
-
var { wrapAs:
|
|
8176
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
8030
8177
|
var ntvCodec3 = createNTVCodec({
|
|
8031
8178
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
8032
8179
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -8041,7 +8188,7 @@ function createTokensResource(client) {
|
|
|
8041
8188
|
let wethL2Promise = null;
|
|
8042
8189
|
async function getL1ChainId() {
|
|
8043
8190
|
if (!l2NtvL1ChainIdPromise) {
|
|
8044
|
-
l2NtvL1ChainIdPromise =
|
|
8191
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
8045
8192
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8046
8193
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
8047
8194
|
});
|
|
@@ -8050,7 +8197,7 @@ function createTokensResource(client) {
|
|
|
8050
8197
|
}
|
|
8051
8198
|
async function getBaseTokenAssetId() {
|
|
8052
8199
|
if (!baseTokenAssetIdPromise) {
|
|
8053
|
-
baseTokenAssetIdPromise =
|
|
8200
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
8054
8201
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8055
8202
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
8056
8203
|
return assetId;
|
|
@@ -8060,7 +8207,7 @@ function createTokensResource(client) {
|
|
|
8060
8207
|
}
|
|
8061
8208
|
async function getWethL1() {
|
|
8062
8209
|
if (!wethL1Promise) {
|
|
8063
|
-
wethL1Promise =
|
|
8210
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
8064
8211
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8065
8212
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
8066
8213
|
return weth;
|
|
@@ -8070,7 +8217,7 @@ function createTokensResource(client) {
|
|
|
8070
8217
|
}
|
|
8071
8218
|
async function getWethL2() {
|
|
8072
8219
|
if (!wethL2Promise) {
|
|
8073
|
-
wethL2Promise =
|
|
8220
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
8074
8221
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8075
8222
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
8076
8223
|
return weth;
|
|
@@ -8079,7 +8226,7 @@ function createTokensResource(client) {
|
|
|
8079
8226
|
return wethL2Promise;
|
|
8080
8227
|
}
|
|
8081
8228
|
async function toL2Address(l1Token) {
|
|
8082
|
-
return
|
|
8229
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
8083
8230
|
const normalized = normalizeL1Token(l1Token);
|
|
8084
8231
|
const chainId = BigInt(await client.l2.getChainId());
|
|
8085
8232
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -8092,7 +8239,7 @@ function createTokensResource(client) {
|
|
|
8092
8239
|
});
|
|
8093
8240
|
}
|
|
8094
8241
|
async function toL1Address(l2Token) {
|
|
8095
|
-
return
|
|
8242
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
8096
8243
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
8097
8244
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
8098
8245
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -8113,32 +8260,32 @@ function createTokensResource(client) {
|
|
|
8113
8260
|
});
|
|
8114
8261
|
}
|
|
8115
8262
|
async function assetIdOfL1(l1Token) {
|
|
8116
|
-
return
|
|
8263
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
8117
8264
|
const normalized = normalizeL1Token(l1Token);
|
|
8118
8265
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8119
8266
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
8120
8267
|
});
|
|
8121
8268
|
}
|
|
8122
8269
|
async function assetIdOfL2(l2Token) {
|
|
8123
|
-
return
|
|
8270
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
8124
8271
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8125
8272
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
8126
8273
|
});
|
|
8127
8274
|
}
|
|
8128
8275
|
async function l2TokenFromAssetId(assetId) {
|
|
8129
|
-
return
|
|
8276
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
8130
8277
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8131
8278
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
8132
8279
|
});
|
|
8133
8280
|
}
|
|
8134
8281
|
async function l1TokenFromAssetId(assetId) {
|
|
8135
|
-
return
|
|
8282
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
8136
8283
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8137
8284
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
8138
8285
|
});
|
|
8139
8286
|
}
|
|
8140
8287
|
async function originChainId(assetId) {
|
|
8141
|
-
return
|
|
8288
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
8142
8289
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8143
8290
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
8144
8291
|
});
|
|
@@ -8147,7 +8294,7 @@ function createTokensResource(client) {
|
|
|
8147
8294
|
return getBaseTokenAssetId();
|
|
8148
8295
|
}
|
|
8149
8296
|
async function isChainEthBased() {
|
|
8150
|
-
return
|
|
8297
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
8151
8298
|
const baseAssetId = await getBaseTokenAssetId();
|
|
8152
8299
|
const l1ChainId = await getL1ChainId();
|
|
8153
8300
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -8165,7 +8312,7 @@ function createTokensResource(client) {
|
|
|
8165
8312
|
return getWethL2();
|
|
8166
8313
|
}
|
|
8167
8314
|
async function computeL2BridgedAddress(args) {
|
|
8168
|
-
return
|
|
8315
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
8169
8316
|
const normalized = normalizeL1Token(args.l1Token);
|
|
8170
8317
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8171
8318
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -8176,7 +8323,7 @@ function createTokensResource(client) {
|
|
|
8176
8323
|
});
|
|
8177
8324
|
}
|
|
8178
8325
|
async function resolve(ref, opts) {
|
|
8179
|
-
return
|
|
8326
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
8180
8327
|
let chain;
|
|
8181
8328
|
let address;
|
|
8182
8329
|
if (typeof ref === "string") {
|
|
@@ -8764,12 +8911,12 @@ function buildFeeBreakdown2(p) {
|
|
|
8764
8911
|
}
|
|
8765
8912
|
|
|
8766
8913
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
8767
|
-
var { wrapAs:
|
|
8914
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
8768
8915
|
function routeEthBase() {
|
|
8769
8916
|
return {
|
|
8770
8917
|
async build(p, ctx) {
|
|
8771
8918
|
const steps = [];
|
|
8772
|
-
const data = await
|
|
8919
|
+
const data = await wrapAs8(
|
|
8773
8920
|
"INTERNAL",
|
|
8774
8921
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
8775
8922
|
() => Promise.resolve(
|
|
@@ -8819,14 +8966,14 @@ function routeEthBase() {
|
|
|
8819
8966
|
}
|
|
8820
8967
|
};
|
|
8821
8968
|
}
|
|
8822
|
-
var { wrapAs:
|
|
8969
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
8823
8970
|
function routeErc20NonBase2() {
|
|
8824
8971
|
return {
|
|
8825
8972
|
// TODO: add preflight validations here
|
|
8826
8973
|
async build(p, ctx) {
|
|
8827
8974
|
const steps = [];
|
|
8828
8975
|
const approvals = [];
|
|
8829
|
-
const current = await
|
|
8976
|
+
const current = await wrapAs9(
|
|
8830
8977
|
"CONTRACT",
|
|
8831
8978
|
OP_WITHDRAWALS.erc20.allowance,
|
|
8832
8979
|
() => ctx.client.l2.readContract({
|
|
@@ -8865,7 +9012,7 @@ function routeErc20NonBase2() {
|
|
|
8865
9012
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
8866
9013
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
8867
9014
|
}
|
|
8868
|
-
const approveSim = await
|
|
9015
|
+
const approveSim = await wrapAs9(
|
|
8869
9016
|
"CONTRACT",
|
|
8870
9017
|
OP_WITHDRAWALS.erc20.estGas,
|
|
8871
9018
|
() => ctx.client.l2.simulateContract({
|
|
@@ -8892,7 +9039,7 @@ function routeErc20NonBase2() {
|
|
|
8892
9039
|
tx: approveTx
|
|
8893
9040
|
});
|
|
8894
9041
|
}
|
|
8895
|
-
const assetId = (await
|
|
9042
|
+
const assetId = (await wrapAs9(
|
|
8896
9043
|
"CONTRACT",
|
|
8897
9044
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
8898
9045
|
() => ctx.client.l2.simulateContract({
|
|
@@ -8943,7 +9090,7 @@ function routeErc20NonBase2() {
|
|
|
8943
9090
|
...withdrawGas
|
|
8944
9091
|
};
|
|
8945
9092
|
} else {
|
|
8946
|
-
const sim = await
|
|
9093
|
+
const sim = await wrapAs9(
|
|
8947
9094
|
"CONTRACT",
|
|
8948
9095
|
OP_WITHDRAWALS.erc20.estGas,
|
|
8949
9096
|
() => ctx.client.l2.simulateContract({
|
|
@@ -9105,7 +9252,7 @@ function buildWithdrawalBundle(input) {
|
|
|
9105
9252
|
}
|
|
9106
9253
|
|
|
9107
9254
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
9108
|
-
var { wrapAs:
|
|
9255
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
9109
9256
|
var attributes = createViemAttributesResource();
|
|
9110
9257
|
function saltFor(sender, nonce) {
|
|
9111
9258
|
return viem.keccak256(
|
|
@@ -9130,7 +9277,7 @@ function routeInteropBundle() {
|
|
|
9130
9277
|
if (isBaseToken) {
|
|
9131
9278
|
assetId = ctx.baseTokenAssetId;
|
|
9132
9279
|
} else {
|
|
9133
|
-
assetId = (await
|
|
9280
|
+
assetId = (await wrapAs10(
|
|
9134
9281
|
"CONTRACT",
|
|
9135
9282
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
9136
9283
|
() => ctx.client.l2.simulateContract({
|
|
@@ -9145,7 +9292,7 @@ function routeInteropBundle() {
|
|
|
9145
9292
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
9146
9293
|
}
|
|
9147
9294
|
)).result;
|
|
9148
|
-
const current = await
|
|
9295
|
+
const current = await wrapAs10(
|
|
9149
9296
|
"CONTRACT",
|
|
9150
9297
|
OP_WITHDRAWALS.erc20.allowance,
|
|
9151
9298
|
() => ctx.client.l2.readContract({
|
|
@@ -9194,7 +9341,7 @@ function routeInteropBundle() {
|
|
|
9194
9341
|
});
|
|
9195
9342
|
}
|
|
9196
9343
|
}
|
|
9197
|
-
const nonce = await
|
|
9344
|
+
const nonce = await wrapAs10(
|
|
9198
9345
|
"RPC",
|
|
9199
9346
|
OP_WITHDRAWALS.prepare,
|
|
9200
9347
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -9430,7 +9577,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
9430
9577
|
}
|
|
9431
9578
|
};
|
|
9432
9579
|
}
|
|
9433
|
-
var { wrapAs:
|
|
9580
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
9434
9581
|
var IL1NullifierMini = [
|
|
9435
9582
|
{
|
|
9436
9583
|
type: "function",
|
|
@@ -9448,7 +9595,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9448
9595
|
async function finalizationTarget(protocol) {
|
|
9449
9596
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
9450
9597
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
9451
|
-
return await
|
|
9598
|
+
return await wrapAs11(
|
|
9452
9599
|
"CONTRACT",
|
|
9453
9600
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9454
9601
|
() => client.l1.readContract({
|
|
@@ -9463,7 +9610,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9463
9610
|
);
|
|
9464
9611
|
}
|
|
9465
9612
|
async function fetchMessageAndProof(l2TxHash) {
|
|
9466
|
-
const raw = await
|
|
9613
|
+
const raw = await wrapAs11(
|
|
9467
9614
|
"RPC",
|
|
9468
9615
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9469
9616
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -9480,7 +9627,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9480
9627
|
context: { l2TxHash }
|
|
9481
9628
|
});
|
|
9482
9629
|
}
|
|
9483
|
-
const ev = await
|
|
9630
|
+
const ev = await wrapAs11(
|
|
9484
9631
|
"INTERNAL",
|
|
9485
9632
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
9486
9633
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -9490,7 +9637,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9490
9637
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
9491
9638
|
}
|
|
9492
9639
|
);
|
|
9493
|
-
const message = await
|
|
9640
|
+
const message = await wrapAs11(
|
|
9494
9641
|
"INTERNAL",
|
|
9495
9642
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9496
9643
|
() => {
|
|
@@ -9502,7 +9649,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9502
9649
|
message: "Failed to decode withdrawal message."
|
|
9503
9650
|
}
|
|
9504
9651
|
);
|
|
9505
|
-
const idx = await
|
|
9652
|
+
const idx = await wrapAs11(
|
|
9506
9653
|
"INTERNAL",
|
|
9507
9654
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
9508
9655
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -9511,7 +9658,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9511
9658
|
message: "Failed to derive messenger log index."
|
|
9512
9659
|
}
|
|
9513
9660
|
);
|
|
9514
|
-
const proof = await
|
|
9661
|
+
const proof = await wrapAs11(
|
|
9515
9662
|
"RPC",
|
|
9516
9663
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
9517
9664
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -9520,7 +9667,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9520
9667
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
9521
9668
|
}
|
|
9522
9669
|
);
|
|
9523
|
-
const chainId = await
|
|
9670
|
+
const chainId = await wrapAs11(
|
|
9524
9671
|
"RPC",
|
|
9525
9672
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
9526
9673
|
() => client.l2.getChainId(),
|
|
@@ -9578,7 +9725,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9578
9725
|
async function withdrawalOutcome(finalization) {
|
|
9579
9726
|
const target = await finalizationTarget(finalization.protocol);
|
|
9580
9727
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
9581
|
-
const done = await
|
|
9728
|
+
const done = await wrapAs11(
|
|
9582
9729
|
"RPC",
|
|
9583
9730
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9584
9731
|
() => client.l1.readContract({
|
|
@@ -9600,7 +9747,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9600
9747
|
}
|
|
9601
9748
|
const { bundleHash } = finalization.params;
|
|
9602
9749
|
const status = Number(
|
|
9603
|
-
await
|
|
9750
|
+
await wrapAs11(
|
|
9604
9751
|
"RPC",
|
|
9605
9752
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9606
9753
|
() => client.l1.readContract({
|
|
@@ -9617,7 +9764,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9617
9764
|
);
|
|
9618
9765
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
9619
9766
|
const callStatus = Number(
|
|
9620
|
-
await
|
|
9767
|
+
await wrapAs11(
|
|
9621
9768
|
"RPC",
|
|
9622
9769
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9623
9770
|
() => client.l1.readContract({
|
|
@@ -9688,7 +9835,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9688
9835
|
},
|
|
9689
9836
|
async estimateFinalization(finalization) {
|
|
9690
9837
|
const target = await finalizationTarget(finalization.protocol);
|
|
9691
|
-
const gasLimit = await
|
|
9838
|
+
const gasLimit = await wrapAs11(
|
|
9692
9839
|
"RPC",
|
|
9693
9840
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9694
9841
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -9716,7 +9863,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9716
9863
|
let maxFeePerGas;
|
|
9717
9864
|
let maxPriorityFeePerGas;
|
|
9718
9865
|
try {
|
|
9719
|
-
const fee = await
|
|
9866
|
+
const fee = await wrapAs11(
|
|
9720
9867
|
"RPC",
|
|
9721
9868
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9722
9869
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -9735,7 +9882,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9735
9882
|
})();
|
|
9736
9883
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
9737
9884
|
} catch {
|
|
9738
|
-
const gasPrice = await
|
|
9885
|
+
const gasPrice = await wrapAs11(
|
|
9739
9886
|
"RPC",
|
|
9740
9887
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9741
9888
|
() => client.l1.getGasPrice(),
|