@matterlabs/zksync-js 0.0.17 → 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.
@@ -1,4 +1,4 @@
1
- export { createEthersSdk } from '../../chunk-J2RPWU2R.js';
1
+ export { createEthersSdk } from '../../chunk-U72MNQIY.js';
2
2
  import '../../chunk-NJK325XV.js';
3
3
  import '../../chunk-6LYAENO6.js';
4
4
  import '../../chunk-3HHUZXSV.js';
@@ -8175,8 +8175,73 @@ function routeEthDirect() {
8175
8175
  }
8176
8176
  };
8177
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
8178
8227
  var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
8179
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
+ }
8180
8245
  async function getPriorityGasModel(input) {
8181
8246
  try {
8182
8247
  const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
@@ -8266,10 +8331,15 @@ function routeErc20NonBase() {
8266
8331
  const secondBridgeCalldata = await wrapAs3(
8267
8332
  "INTERNAL",
8268
8333
  OP_DEPOSITS.nonbase.encodeCalldata,
8269
- () => Promise.resolve(encodeSecondBridgeErc20Args(p.token, p.amount, receiver)),
8334
+ () => encodeSecondBridgeErc20DepositCalldata({
8335
+ ctx,
8336
+ token: p.token,
8337
+ amount: p.amount,
8338
+ receiver
8339
+ }),
8270
8340
  {
8271
8341
  ctx: {
8272
- where: "encodeSecondBridgeErc20Args",
8342
+ where: "encodeSecondBridgeErc20DepositCalldata",
8273
8343
  token: p.token,
8274
8344
  amount: p.amount.toString()
8275
8345
  },
@@ -8314,15 +8384,14 @@ function routeErc20NonBase() {
8314
8384
  }
8315
8385
  );
8316
8386
  if (depositAllowance < p.amount) {
8317
- const approveSim = await wrapAs3(
8387
+ const approveTx = await wrapAs3(
8318
8388
  "CONTRACT",
8319
8389
  OP_DEPOSITS.nonbase.estGas,
8320
- () => ctx.client.l1.simulateContract({
8321
- address: p.token,
8322
- abi: IERC20_default,
8323
- functionName: "approve",
8324
- args: [assetRouter, p.amount],
8325
- account: ctx.client.account
8390
+ () => buildApprovalRequest({
8391
+ ctx,
8392
+ token: p.token,
8393
+ spender: assetRouter,
8394
+ amount: p.amount
8326
8395
  }),
8327
8396
  {
8328
8397
  ctx: { where: "l1.simulateContract", to: p.token },
@@ -8334,7 +8403,7 @@ function routeErc20NonBase() {
8334
8403
  key: `approve:${p.token}:${assetRouter}`,
8335
8404
  kind: "approve",
8336
8405
  description: `Approve deposit token for amount`,
8337
- tx: { ...approveSim.request }
8406
+ tx: approveTx
8338
8407
  });
8339
8408
  }
8340
8409
  if (!baseIsEth) {
@@ -8353,15 +8422,14 @@ function routeErc20NonBase() {
8353
8422
  }
8354
8423
  );
8355
8424
  if (baseAllowance < mintValue) {
8356
- const approveBaseSim = await wrapAs3(
8425
+ const approveBaseTx = await wrapAs3(
8357
8426
  "CONTRACT",
8358
8427
  OP_DEPOSITS.nonbase.estGas,
8359
- () => ctx.client.l1.simulateContract({
8360
- address: baseToken,
8361
- abi: IERC20_default,
8362
- functionName: "approve",
8363
- args: [assetRouter, mintValue],
8364
- account: ctx.client.account
8428
+ () => buildApprovalRequest({
8429
+ ctx,
8430
+ token: baseToken,
8431
+ spender: assetRouter,
8432
+ amount: mintValue
8365
8433
  }),
8366
8434
  {
8367
8435
  ctx: { where: "l1.simulateContract", to: baseToken },
@@ -8373,7 +8441,7 @@ function routeErc20NonBase() {
8373
8441
  key: `approve:${baseToken}:${assetRouter}`,
8374
8442
  kind: "approve",
8375
8443
  description: `Approve base token for mintValue`,
8376
- tx: { ...approveBaseSim.request }
8444
+ tx: approveBaseTx
8377
8445
  });
8378
8446
  }
8379
8447
  }
@@ -8625,15 +8693,14 @@ function routeEthNonBase() {
8625
8693
  );
8626
8694
  const needsApprove = allowance < mintValue;
8627
8695
  if (needsApprove) {
8628
- const approveSim = await wrapAs4(
8696
+ const approveTx = await wrapAs4(
8629
8697
  "CONTRACT",
8630
8698
  OP_DEPOSITS.ethNonBase.estGas,
8631
- () => ctx.client.l1.simulateContract({
8632
- address: baseToken,
8633
- abi: IERC20_default,
8634
- functionName: "approve",
8635
- args: [ctx.l1AssetRouter, mintValue],
8636
- account: ctx.client.account
8699
+ () => buildApprovalRequest({
8700
+ ctx,
8701
+ token: baseToken,
8702
+ spender: ctx.l1AssetRouter,
8703
+ amount: mintValue
8637
8704
  }),
8638
8705
  {
8639
8706
  ctx: { where: "l1.simulateContract", to: baseToken },
@@ -8645,7 +8712,7 @@ function routeEthNonBase() {
8645
8712
  key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
8646
8713
  kind: "approve",
8647
8714
  description: `Approve base token for fees (mintValue)`,
8648
- tx: { ...approveSim.request }
8715
+ tx: approveTx
8649
8716
  });
8650
8717
  }
8651
8718
  const secondBridgeCalldata = await wrapAs4(
@@ -8825,15 +8892,14 @@ function routeErc20Base() {
8825
8892
  );
8826
8893
  const needsApprove = allowance < mintValue;
8827
8894
  if (needsApprove) {
8828
- const approveSim = await wrapAs5(
8895
+ const approveTx = await wrapAs5(
8829
8896
  "CONTRACT",
8830
8897
  OP_DEPOSITS.base.estGas,
8831
- () => ctx.client.l1.simulateContract({
8832
- address: baseToken,
8833
- abi: IERC20_default,
8834
- functionName: "approve",
8835
- args: [ctx.l1AssetRouter, mintValue],
8836
- account: ctx.client.account
8898
+ () => buildApprovalRequest({
8899
+ ctx,
8900
+ token: baseToken,
8901
+ spender: ctx.l1AssetRouter,
8902
+ amount: mintValue
8837
8903
  }),
8838
8904
  {
8839
8905
  ctx: { where: "l1.simulateContract", to: baseToken },
@@ -8845,7 +8911,7 @@ function routeErc20Base() {
8845
8911
  key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
8846
8912
  kind: "approve",
8847
8913
  description: "Approve base token for mintValue",
8848
- tx: { ...approveSim.request }
8914
+ tx: approveTx
8849
8915
  });
8850
8916
  }
8851
8917
  const req = buildDirectRequestStruct({