@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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createViemSdk } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
1
|
+
export { createViemSdk } from '../../chunk-VVDJFIXV.js';
|
|
2
|
+
import '../../chunk-FMBQ7PVA.js';
|
|
3
3
|
import '../../chunk-BQ2YCWV2.js';
|
|
4
4
|
import '../../chunk-OEUDZFXH.js';
|
|
5
5
|
import '../../chunk-H5A6GU3D.js';
|
|
@@ -10,6 +10,7 @@ function isEraVmChain(chainIdL2) {
|
|
|
10
10
|
|
|
11
11
|
// src/core/resources/deposits/gas.ts
|
|
12
12
|
var CREATE_REESTIMATE_BUFFER = 15n;
|
|
13
|
+
var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
13
14
|
var maxBigInt = (a, b) => a > b ? a : b;
|
|
14
15
|
function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
|
|
15
16
|
return gasLimit * (100n + bufferPct) / 100n;
|
|
@@ -60,15 +61,39 @@ async function fetchFees(estimator) {
|
|
|
60
61
|
const gp = await estimator.getGasPrice();
|
|
61
62
|
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
62
63
|
} catch {
|
|
63
|
-
return
|
|
64
|
+
return void 0;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
67
|
+
async function quoteL1Fees(input) {
|
|
68
|
+
const { estimator, overrides } = input;
|
|
69
|
+
const maxFeeOverride = overrides?.maxFeePerGas;
|
|
70
|
+
const tipOverride = overrides?.maxPriorityFeePerGas;
|
|
71
|
+
if (maxFeeOverride != null && tipOverride != null) {
|
|
72
|
+
return { maxFeePerGas: maxFeeOverride, maxPriorityFeePerGas: tipOverride };
|
|
73
|
+
}
|
|
74
|
+
const market = await fetchFees(estimator);
|
|
75
|
+
if (maxFeeOverride != null) {
|
|
76
|
+
const tip = market?.maxPriorityFeePerGas ?? 0n;
|
|
77
|
+
return {
|
|
78
|
+
maxFeePerGas: maxFeeOverride,
|
|
79
|
+
maxPriorityFeePerGas: tip < maxFeeOverride ? tip : maxFeeOverride
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (market == null) {
|
|
83
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
84
|
+
}
|
|
85
|
+
if (tipOverride != null) {
|
|
86
|
+
const headroom = market.maxFeePerGas > market.maxPriorityFeePerGas ? market.maxFeePerGas - market.maxPriorityFeePerGas : 0n;
|
|
87
|
+
return { maxFeePerGas: headroom + tipOverride, maxPriorityFeePerGas: tipOverride };
|
|
88
|
+
}
|
|
89
|
+
return market;
|
|
90
|
+
}
|
|
66
91
|
async function quoteL1Gas(input) {
|
|
67
92
|
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
68
93
|
let market;
|
|
69
94
|
const getMarket = async () => {
|
|
70
95
|
if (market) return market;
|
|
71
|
-
market = await fetchFees(estimator);
|
|
96
|
+
market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
72
97
|
return market;
|
|
73
98
|
};
|
|
74
99
|
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
@@ -90,7 +115,7 @@ async function quoteL1Gas(input) {
|
|
|
90
115
|
}
|
|
91
116
|
async function quoteL2Gas(input) {
|
|
92
117
|
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
93
|
-
const market = await fetchFees(estimator);
|
|
118
|
+
const market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
94
119
|
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
95
120
|
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
96
121
|
const explicit = overrideGasLimit ?? txGasLimit;
|
|
@@ -131,12 +156,7 @@ async function quoteL2Gas(input) {
|
|
|
131
156
|
}
|
|
132
157
|
}
|
|
133
158
|
async function quoteL2BaseCost(input) {
|
|
134
|
-
const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata } = input;
|
|
135
|
-
const market = await fetchFees(estimator);
|
|
136
|
-
const l1GasPrice = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
137
|
-
if (l1GasPrice === 0n) {
|
|
138
|
-
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
139
|
-
}
|
|
159
|
+
const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata, l1GasPrice } = input;
|
|
140
160
|
const data = encode(IBridgehub_default, "l2TransactionBaseCost", [
|
|
141
161
|
chainIdL2,
|
|
142
162
|
l1GasPrice,
|
|
@@ -208,10 +228,28 @@ function toGasOverrides(overrides) {
|
|
|
208
228
|
}
|
|
209
229
|
|
|
210
230
|
// src/core/resources/deposits/priority.ts
|
|
231
|
+
var ZK_CHAIN_PRICING_GETTERS_ABI = [
|
|
232
|
+
{
|
|
233
|
+
type: "function",
|
|
234
|
+
name: "getZKsyncOS",
|
|
235
|
+
stateMutability: "view",
|
|
236
|
+
inputs: [],
|
|
237
|
+
outputs: [{ name: "", type: "bool" }]
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
type: "function",
|
|
241
|
+
name: "getPubdataPricingMode",
|
|
242
|
+
stateMutability: "view",
|
|
243
|
+
inputs: [],
|
|
244
|
+
outputs: [{ name: "", type: "uint8" }]
|
|
245
|
+
}
|
|
246
|
+
];
|
|
247
|
+
var PUBDATA_PRICING_MODE_ROLLUP = 0;
|
|
211
248
|
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
212
249
|
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
213
250
|
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
214
251
|
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
252
|
+
var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
|
|
215
253
|
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
216
254
|
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
217
255
|
function applyL1ToL2Alias(address) {
|
|
@@ -258,6 +296,16 @@ function clampPriorityL2GasLimit(input) {
|
|
|
258
296
|
})
|
|
259
297
|
);
|
|
260
298
|
}
|
|
299
|
+
function resolveBaseTokenPriorityL2GasLimit(input) {
|
|
300
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
301
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
302
|
+
}
|
|
303
|
+
if (!input.chargesPubdata) return input.priorityFloorGasLimit;
|
|
304
|
+
return maxBigInt2(
|
|
305
|
+
input.priorityFloorGasLimit,
|
|
306
|
+
applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
|
|
307
|
+
);
|
|
308
|
+
}
|
|
261
309
|
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
262
310
|
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
263
311
|
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
@@ -682,4 +730,4 @@ async function quoteL2Gas2(input) {
|
|
|
682
730
|
}
|
|
683
731
|
}
|
|
684
732
|
|
|
685
|
-
export { DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, ZERO_HASH, applyL1ToL2Alias, applyPriorityL2GasLimitBuffer, assertProtocolVersion, buildDirectBundle, buildFeeBreakdown, buildFinalizationInfo, buildIndirectBundle, clampPriorityL2GasLimit, createAttributesResource, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, isInteropFinalizationInfo, parseBundleReceiptInfo, parseBundleSentFromReceipt, pickInteropRoute, preflightDirect, preflightIndirect, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, resolveCreateDepositL1GasLimit, resolveIdsFromWaitable, resolveRegisteredTokenPriorityL2GasLimit, toGasOverrides };
|
|
733
|
+
export { DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, PUBDATA_PRICING_MODE_ROLLUP, ZERO_HASH, ZK_CHAIN_PRICING_GETTERS_ABI, applyL1ToL2Alias, applyPriorityL2GasLimitBuffer, assertProtocolVersion, buildDirectBundle, buildFeeBreakdown, buildFinalizationInfo, buildIndirectBundle, clampPriorityL2GasLimit, createAttributesResource, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, isInteropFinalizationInfo, parseBundleReceiptInfo, parseBundleSentFromReceipt, pickInteropRoute, preflightDirect, preflightIndirect, quoteL1Fees, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, resolveBaseTokenPriorityL2GasLimit, resolveCreateDepositL1GasLimit, resolveIdsFromWaitable, resolveRegisteredTokenPriorityL2GasLimit, toGasOverrides };
|