@matterlabs/zksync-js 0.0.16 → 0.0.18
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 +52 -17
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +2 -2
- package/dist/adapters/ethers/resources/interop/index.d.ts +3 -2
- package/dist/adapters/ethers/resources/interop/services/finalization/bundle.d.ts +2 -1
- package/dist/adapters/ethers/resources/interop/services/finalization/index.d.ts +2 -1
- package/dist/adapters/ethers/sdk.cjs +52 -17
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +2 -2
- package/dist/adapters/viem/index.cjs +128 -49
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +2 -2
- package/dist/adapters/viem/resources/deposits/routes/approval.d.ts +11 -0
- package/dist/adapters/viem/resources/interop/index.d.ts +3 -2
- package/dist/adapters/viem/resources/interop/services/finalization/bundle.d.ts +2 -1
- package/dist/adapters/viem/resources/interop/services/finalization/index.d.ts +2 -1
- package/dist/adapters/viem/sdk.cjs +128 -49
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +2 -2
- package/dist/{chunk-NLUCYVMX.js → chunk-6LYAENO6.js} +3 -6
- package/dist/{chunk-3KH5PCD6.js → chunk-GBS7KQFU.js} +126 -44
- package/dist/{chunk-5HG2DUYW.js → chunk-U72MNQIY.js} +50 -12
- package/dist/core/resources/deposits/priority.d.ts +1 -1
- package/package.json +5 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { createEthersSdk } from '../../chunk-
|
|
1
|
+
export { createEthersSdk } from '../../chunk-U72MNQIY.js';
|
|
2
2
|
import '../../chunk-NJK325XV.js';
|
|
3
|
-
import '../../chunk-
|
|
3
|
+
import '../../chunk-6LYAENO6.js';
|
|
4
4
|
import '../../chunk-3HHUZXSV.js';
|
|
5
5
|
import '../../chunk-JSBMIT4S.js';
|
|
6
6
|
import '../../chunk-UEKFQAOS.js';
|
|
@@ -7979,8 +7979,8 @@ function buildFeeBreakdown(p) {
|
|
|
7979
7979
|
|
|
7980
7980
|
// src/core/resources/deposits/priority.ts
|
|
7981
7981
|
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
7982
|
-
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER =
|
|
7983
|
-
var
|
|
7982
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
7983
|
+
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
7984
7984
|
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
7985
7985
|
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
7986
7986
|
function derivePriorityTxGasBreakdown(input) {
|
|
@@ -8008,10 +8008,7 @@ function derivePriorityBodyGasEstimateCap(input) {
|
|
|
8008
8008
|
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
8009
8009
|
}
|
|
8010
8010
|
function applyPriorityL2GasLimitBuffer(input) {
|
|
8011
|
-
|
|
8012
|
-
return input.gasLimit;
|
|
8013
|
-
}
|
|
8014
|
-
return input.gasLimit * (100n + ERAVM_PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
8011
|
+
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
8015
8012
|
}
|
|
8016
8013
|
var EMPTY_BYTES = "0x";
|
|
8017
8014
|
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
@@ -8178,8 +8175,73 @@ function routeEthDirect() {
|
|
|
8178
8175
|
}
|
|
8179
8176
|
};
|
|
8180
8177
|
}
|
|
8178
|
+
|
|
8179
|
+
// src/adapters/viem/resources/deposits/routes/approval.ts
|
|
8180
|
+
function errorText(error) {
|
|
8181
|
+
const parts = [];
|
|
8182
|
+
let current = error;
|
|
8183
|
+
for (let depth = 0; current && depth < 8; depth++) {
|
|
8184
|
+
const record = current;
|
|
8185
|
+
for (const key of ["name", "shortMessage", "message", "details"]) {
|
|
8186
|
+
const value = record[key];
|
|
8187
|
+
if (typeof value === "string") parts.push(value);
|
|
8188
|
+
}
|
|
8189
|
+
current = record.cause;
|
|
8190
|
+
}
|
|
8191
|
+
return parts.join("\n");
|
|
8192
|
+
}
|
|
8193
|
+
function isNoReturnApproveSimulationError(error) {
|
|
8194
|
+
const text = errorText(error);
|
|
8195
|
+
return /approve/i.test(text) && (/returned no data/i.test(text) || /return(?:ed)? data[^\n]*0x/i.test(text) || /0x[^\n]*no data/i.test(text));
|
|
8196
|
+
}
|
|
8197
|
+
async function buildApprovalRequest({
|
|
8198
|
+
ctx,
|
|
8199
|
+
token,
|
|
8200
|
+
spender,
|
|
8201
|
+
amount
|
|
8202
|
+
}) {
|
|
8203
|
+
try {
|
|
8204
|
+
const sim = await ctx.client.l1.simulateContract({
|
|
8205
|
+
address: token,
|
|
8206
|
+
abi: IERC20_default,
|
|
8207
|
+
functionName: "approve",
|
|
8208
|
+
args: [spender, amount],
|
|
8209
|
+
account: ctx.client.account
|
|
8210
|
+
});
|
|
8211
|
+
return { ...sim.request };
|
|
8212
|
+
} catch (error) {
|
|
8213
|
+
if (!isNoReturnApproveSimulationError(error)) {
|
|
8214
|
+
throw error;
|
|
8215
|
+
}
|
|
8216
|
+
return {
|
|
8217
|
+
address: token,
|
|
8218
|
+
abi: IERC20_default,
|
|
8219
|
+
functionName: "approve",
|
|
8220
|
+
args: [spender, amount],
|
|
8221
|
+
account: ctx.client.account
|
|
8222
|
+
};
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
8225
|
+
|
|
8226
|
+
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
8181
8227
|
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
8182
8228
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8229
|
+
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
8230
|
+
if (!input.ctx.resolvedToken) {
|
|
8231
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
8232
|
+
}
|
|
8233
|
+
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
8234
|
+
const isL1Origin = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID || input.ctx.resolvedToken.originChainId === 0n || input.ctx.resolvedToken.originChainId === l1ChainId;
|
|
8235
|
+
if (isL1Origin) {
|
|
8236
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
8237
|
+
}
|
|
8238
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
8239
|
+
input.amount,
|
|
8240
|
+
input.receiver,
|
|
8241
|
+
input.token
|
|
8242
|
+
);
|
|
8243
|
+
return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
|
|
8244
|
+
}
|
|
8183
8245
|
async function getPriorityGasModel(input) {
|
|
8184
8246
|
try {
|
|
8185
8247
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
@@ -8269,10 +8331,15 @@ function routeErc20NonBase() {
|
|
|
8269
8331
|
const secondBridgeCalldata = await wrapAs3(
|
|
8270
8332
|
"INTERNAL",
|
|
8271
8333
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
8272
|
-
() =>
|
|
8334
|
+
() => encodeSecondBridgeErc20DepositCalldata({
|
|
8335
|
+
ctx,
|
|
8336
|
+
token: p.token,
|
|
8337
|
+
amount: p.amount,
|
|
8338
|
+
receiver
|
|
8339
|
+
}),
|
|
8273
8340
|
{
|
|
8274
8341
|
ctx: {
|
|
8275
|
-
where: "
|
|
8342
|
+
where: "encodeSecondBridgeErc20DepositCalldata",
|
|
8276
8343
|
token: p.token,
|
|
8277
8344
|
amount: p.amount.toString()
|
|
8278
8345
|
},
|
|
@@ -8317,15 +8384,14 @@ function routeErc20NonBase() {
|
|
|
8317
8384
|
}
|
|
8318
8385
|
);
|
|
8319
8386
|
if (depositAllowance < p.amount) {
|
|
8320
|
-
const
|
|
8387
|
+
const approveTx = await wrapAs3(
|
|
8321
8388
|
"CONTRACT",
|
|
8322
8389
|
OP_DEPOSITS.nonbase.estGas,
|
|
8323
|
-
() =>
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
account: ctx.client.account
|
|
8390
|
+
() => buildApprovalRequest({
|
|
8391
|
+
ctx,
|
|
8392
|
+
token: p.token,
|
|
8393
|
+
spender: assetRouter,
|
|
8394
|
+
amount: p.amount
|
|
8329
8395
|
}),
|
|
8330
8396
|
{
|
|
8331
8397
|
ctx: { where: "l1.simulateContract", to: p.token },
|
|
@@ -8337,7 +8403,7 @@ function routeErc20NonBase() {
|
|
|
8337
8403
|
key: `approve:${p.token}:${assetRouter}`,
|
|
8338
8404
|
kind: "approve",
|
|
8339
8405
|
description: `Approve deposit token for amount`,
|
|
8340
|
-
tx:
|
|
8406
|
+
tx: approveTx
|
|
8341
8407
|
});
|
|
8342
8408
|
}
|
|
8343
8409
|
if (!baseIsEth) {
|
|
@@ -8356,15 +8422,14 @@ function routeErc20NonBase() {
|
|
|
8356
8422
|
}
|
|
8357
8423
|
);
|
|
8358
8424
|
if (baseAllowance < mintValue) {
|
|
8359
|
-
const
|
|
8425
|
+
const approveBaseTx = await wrapAs3(
|
|
8360
8426
|
"CONTRACT",
|
|
8361
8427
|
OP_DEPOSITS.nonbase.estGas,
|
|
8362
|
-
() =>
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
account: ctx.client.account
|
|
8428
|
+
() => buildApprovalRequest({
|
|
8429
|
+
ctx,
|
|
8430
|
+
token: baseToken,
|
|
8431
|
+
spender: assetRouter,
|
|
8432
|
+
amount: mintValue
|
|
8368
8433
|
}),
|
|
8369
8434
|
{
|
|
8370
8435
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -8376,7 +8441,7 @@ function routeErc20NonBase() {
|
|
|
8376
8441
|
key: `approve:${baseToken}:${assetRouter}`,
|
|
8377
8442
|
kind: "approve",
|
|
8378
8443
|
description: `Approve base token for mintValue`,
|
|
8379
|
-
tx:
|
|
8444
|
+
tx: approveBaseTx
|
|
8380
8445
|
});
|
|
8381
8446
|
}
|
|
8382
8447
|
}
|
|
@@ -8628,15 +8693,14 @@ function routeEthNonBase() {
|
|
|
8628
8693
|
);
|
|
8629
8694
|
const needsApprove = allowance < mintValue;
|
|
8630
8695
|
if (needsApprove) {
|
|
8631
|
-
const
|
|
8696
|
+
const approveTx = await wrapAs4(
|
|
8632
8697
|
"CONTRACT",
|
|
8633
8698
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
8634
|
-
() =>
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
account: ctx.client.account
|
|
8699
|
+
() => buildApprovalRequest({
|
|
8700
|
+
ctx,
|
|
8701
|
+
token: baseToken,
|
|
8702
|
+
spender: ctx.l1AssetRouter,
|
|
8703
|
+
amount: mintValue
|
|
8640
8704
|
}),
|
|
8641
8705
|
{
|
|
8642
8706
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -8648,7 +8712,7 @@ function routeEthNonBase() {
|
|
|
8648
8712
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
8649
8713
|
kind: "approve",
|
|
8650
8714
|
description: `Approve base token for fees (mintValue)`,
|
|
8651
|
-
tx:
|
|
8715
|
+
tx: approveTx
|
|
8652
8716
|
});
|
|
8653
8717
|
}
|
|
8654
8718
|
const secondBridgeCalldata = await wrapAs4(
|
|
@@ -8828,15 +8892,14 @@ function routeErc20Base() {
|
|
|
8828
8892
|
);
|
|
8829
8893
|
const needsApprove = allowance < mintValue;
|
|
8830
8894
|
if (needsApprove) {
|
|
8831
|
-
const
|
|
8895
|
+
const approveTx = await wrapAs5(
|
|
8832
8896
|
"CONTRACT",
|
|
8833
8897
|
OP_DEPOSITS.base.estGas,
|
|
8834
|
-
() =>
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
account: ctx.client.account
|
|
8898
|
+
() => buildApprovalRequest({
|
|
8899
|
+
ctx,
|
|
8900
|
+
token: baseToken,
|
|
8901
|
+
spender: ctx.l1AssetRouter,
|
|
8902
|
+
amount: mintValue
|
|
8840
8903
|
}),
|
|
8841
8904
|
{
|
|
8842
8905
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -8848,7 +8911,7 @@ function routeErc20Base() {
|
|
|
8848
8911
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
8849
8912
|
kind: "approve",
|
|
8850
8913
|
description: "Approve base token for mintValue",
|
|
8851
|
-
tx:
|
|
8914
|
+
tx: approveTx
|
|
8852
8915
|
});
|
|
8853
8916
|
}
|
|
8854
8917
|
const req = buildDirectRequestStruct({
|
|
@@ -11155,13 +11218,23 @@ function routeIndirect() {
|
|
|
11155
11218
|
}
|
|
11156
11219
|
function routeDirect() {
|
|
11157
11220
|
return {
|
|
11158
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
11159
11221
|
async preflight(params, ctx) {
|
|
11160
11222
|
preflightDirect(params, {
|
|
11161
11223
|
dstChainId: ctx.dstChainId,
|
|
11162
11224
|
baseTokens: ctx.baseTokens,
|
|
11163
11225
|
l2AssetRouter: ctx.l2AssetRouter,
|
|
11164
11226
|
l2NativeTokenVault: ctx.l2NativeTokenVault});
|
|
11227
|
+
for (const action of params.actions) {
|
|
11228
|
+
const bytecode = await ctx.dstPublicClient.getCode({ address: action.to });
|
|
11229
|
+
if (!bytecode || bytecode === "0x") {
|
|
11230
|
+
throw createError("VALIDATION", {
|
|
11231
|
+
resource: "interop",
|
|
11232
|
+
operation: OP_INTEROP.routes.direct.preflight,
|
|
11233
|
+
message: `Destination address ${action.to} is not a contract on the destination chain. The receiver must be a contract that implements the IERC7786Recipient interface (receiveMessage).`,
|
|
11234
|
+
context: { to: action.to, action: action.type }
|
|
11235
|
+
});
|
|
11236
|
+
}
|
|
11237
|
+
}
|
|
11165
11238
|
},
|
|
11166
11239
|
async build(params, ctx) {
|
|
11167
11240
|
const steps = [];
|
|
@@ -11421,7 +11494,7 @@ async function getBundleStatus(client, dstProvider, topics, bundleHash, opts) {
|
|
|
11421
11494
|
}
|
|
11422
11495
|
return { phase: "SENT" };
|
|
11423
11496
|
}
|
|
11424
|
-
async function executeBundle(client, dstProvider, info, opts) {
|
|
11497
|
+
async function executeBundle(client, dstProvider, info, opts, txOverrides) {
|
|
11425
11498
|
const { topics } = getTopics();
|
|
11426
11499
|
const { bundleHash, encodedData, proof } = info;
|
|
11427
11500
|
const dstStatus = await getBundleStatus(client, dstProvider, topics, bundleHash, opts);
|
|
@@ -11450,7 +11523,10 @@ async function executeBundle(client, dstProvider, info, opts) {
|
|
|
11450
11523
|
functionName: "executeBundle",
|
|
11451
11524
|
args: [encodedData, proof],
|
|
11452
11525
|
account: client.account,
|
|
11453
|
-
chain: dstProvider.chain ?? null
|
|
11526
|
+
chain: dstProvider.chain ?? null,
|
|
11527
|
+
gas: txOverrides?.gasLimit,
|
|
11528
|
+
maxFeePerGas: txOverrides?.maxFeePerGas,
|
|
11529
|
+
maxPriorityFeePerGas: txOverrides?.maxPriorityFeePerGas
|
|
11454
11530
|
});
|
|
11455
11531
|
return {
|
|
11456
11532
|
hash,
|
|
@@ -11907,8 +11983,8 @@ function createInteropFinalizationServices(client) {
|
|
|
11907
11983
|
wait(dstProvider, gwProvider, input, opts) {
|
|
11908
11984
|
return waitForFinalization(client, dstProvider, gwProvider, input, opts);
|
|
11909
11985
|
},
|
|
11910
|
-
async finalize(dstProvider, info, opts) {
|
|
11911
|
-
const execResult = await executeBundle(client, dstProvider, info, opts);
|
|
11986
|
+
async finalize(dstProvider, info, opts, txOverrides) {
|
|
11987
|
+
const execResult = await executeBundle(client, dstProvider, info, opts, txOverrides);
|
|
11912
11988
|
await execResult.wait();
|
|
11913
11989
|
return {
|
|
11914
11990
|
bundleHash: info.bundleHash,
|
|
@@ -12136,22 +12212,25 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
|
|
|
12136
12212
|
ctx: { where: "interop.wait" }
|
|
12137
12213
|
});
|
|
12138
12214
|
const tryWait = (dstChain, h, opts) => toResult2(OP_INTEROP.tryWait, () => wait(dstChain, h, opts));
|
|
12139
|
-
const finalize = (dstChain, h, opts) => wrap7(
|
|
12215
|
+
const finalize = (dstChain, h, opts, txOverrides) => wrap7(
|
|
12140
12216
|
OP_INTEROP.finalize,
|
|
12141
12217
|
async () => {
|
|
12142
12218
|
const dstProvider = resolveChainRef(dstChain);
|
|
12143
12219
|
if (isInteropFinalizationInfo(h)) {
|
|
12144
|
-
return svc.finalize(dstProvider, h, opts);
|
|
12220
|
+
return svc.finalize(dstProvider, h, opts, txOverrides);
|
|
12145
12221
|
}
|
|
12146
12222
|
const info = await svc.wait(dstProvider, getGwProvider(), h);
|
|
12147
|
-
return svc.finalize(dstProvider, info, opts);
|
|
12223
|
+
return svc.finalize(dstProvider, info, opts, txOverrides);
|
|
12148
12224
|
},
|
|
12149
12225
|
{
|
|
12150
12226
|
message: "Failed to finalize/execute interop bundle on destination.",
|
|
12151
12227
|
ctx: { where: "interop.finalize" }
|
|
12152
12228
|
}
|
|
12153
12229
|
);
|
|
12154
|
-
const tryFinalize = (dstChain, h, opts
|
|
12230
|
+
const tryFinalize = (dstChain, h, opts, txOverrides) => toResult2(
|
|
12231
|
+
OP_INTEROP.tryFinalize,
|
|
12232
|
+
() => finalize(dstChain, h, opts, txOverrides)
|
|
12233
|
+
);
|
|
12155
12234
|
const interopGetRoot = (dstChain, rootChainId, batchNumber) => wrap7(
|
|
12156
12235
|
OP_INTEROP.svc.status.getRoot,
|
|
12157
12236
|
() => getInteropRoot(resolveChainRef(dstChain), rootChainId, batchNumber),
|