@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.
- package/dist/adapters/ethers/index.cjs +23 -2
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +1 -1
- package/dist/adapters/ethers/sdk.cjs +23 -2
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +1 -1
- package/dist/adapters/viem/index.cjs +100 -34
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +1 -1
- package/dist/adapters/viem/resources/deposits/routes/approval.d.ts +11 -0
- package/dist/adapters/viem/sdk.cjs +100 -34
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +1 -1
- package/dist/{chunk-ONCNOWNC.js → chunk-GBS7KQFU.js} +100 -34
- package/dist/{chunk-J2RPWU2R.js → chunk-U72MNQIY.js} +23 -2
- package/package.json +5 -3
|
@@ -461,8 +461,73 @@ function routeEthDirect() {
|
|
|
461
461
|
}
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
|
+
|
|
465
|
+
// src/adapters/viem/resources/deposits/routes/approval.ts
|
|
466
|
+
function errorText(error) {
|
|
467
|
+
const parts = [];
|
|
468
|
+
let current = error;
|
|
469
|
+
for (let depth = 0; current && depth < 8; depth++) {
|
|
470
|
+
const record = current;
|
|
471
|
+
for (const key of ["name", "shortMessage", "message", "details"]) {
|
|
472
|
+
const value = record[key];
|
|
473
|
+
if (typeof value === "string") parts.push(value);
|
|
474
|
+
}
|
|
475
|
+
current = record.cause;
|
|
476
|
+
}
|
|
477
|
+
return parts.join("\n");
|
|
478
|
+
}
|
|
479
|
+
function isNoReturnApproveSimulationError(error) {
|
|
480
|
+
const text = errorText(error);
|
|
481
|
+
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));
|
|
482
|
+
}
|
|
483
|
+
async function buildApprovalRequest({
|
|
484
|
+
ctx,
|
|
485
|
+
token,
|
|
486
|
+
spender,
|
|
487
|
+
amount
|
|
488
|
+
}) {
|
|
489
|
+
try {
|
|
490
|
+
const sim = await ctx.client.l1.simulateContract({
|
|
491
|
+
address: token,
|
|
492
|
+
abi: IERC20_default,
|
|
493
|
+
functionName: "approve",
|
|
494
|
+
args: [spender, amount],
|
|
495
|
+
account: ctx.client.account
|
|
496
|
+
});
|
|
497
|
+
return { ...sim.request };
|
|
498
|
+
} catch (error) {
|
|
499
|
+
if (!isNoReturnApproveSimulationError(error)) {
|
|
500
|
+
throw error;
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
address: token,
|
|
504
|
+
abi: IERC20_default,
|
|
505
|
+
functionName: "approve",
|
|
506
|
+
args: [spender, amount],
|
|
507
|
+
account: ctx.client.account
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
464
513
|
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
465
514
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
515
|
+
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
516
|
+
if (!input.ctx.resolvedToken) {
|
|
517
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
518
|
+
}
|
|
519
|
+
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
520
|
+
const isL1Origin = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID || input.ctx.resolvedToken.originChainId === 0n || input.ctx.resolvedToken.originChainId === l1ChainId;
|
|
521
|
+
if (isL1Origin) {
|
|
522
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
523
|
+
}
|
|
524
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
525
|
+
input.amount,
|
|
526
|
+
input.receiver,
|
|
527
|
+
input.token
|
|
528
|
+
);
|
|
529
|
+
return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
|
|
530
|
+
}
|
|
466
531
|
async function getPriorityGasModel(input) {
|
|
467
532
|
try {
|
|
468
533
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
@@ -552,10 +617,15 @@ function routeErc20NonBase() {
|
|
|
552
617
|
const secondBridgeCalldata = await wrapAs3(
|
|
553
618
|
"INTERNAL",
|
|
554
619
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
555
|
-
() =>
|
|
620
|
+
() => encodeSecondBridgeErc20DepositCalldata({
|
|
621
|
+
ctx,
|
|
622
|
+
token: p.token,
|
|
623
|
+
amount: p.amount,
|
|
624
|
+
receiver
|
|
625
|
+
}),
|
|
556
626
|
{
|
|
557
627
|
ctx: {
|
|
558
|
-
where: "
|
|
628
|
+
where: "encodeSecondBridgeErc20DepositCalldata",
|
|
559
629
|
token: p.token,
|
|
560
630
|
amount: p.amount.toString()
|
|
561
631
|
},
|
|
@@ -600,15 +670,14 @@ function routeErc20NonBase() {
|
|
|
600
670
|
}
|
|
601
671
|
);
|
|
602
672
|
if (depositAllowance < p.amount) {
|
|
603
|
-
const
|
|
673
|
+
const approveTx = await wrapAs3(
|
|
604
674
|
"CONTRACT",
|
|
605
675
|
OP_DEPOSITS.nonbase.estGas,
|
|
606
|
-
() =>
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
account: ctx.client.account
|
|
676
|
+
() => buildApprovalRequest({
|
|
677
|
+
ctx,
|
|
678
|
+
token: p.token,
|
|
679
|
+
spender: assetRouter,
|
|
680
|
+
amount: p.amount
|
|
612
681
|
}),
|
|
613
682
|
{
|
|
614
683
|
ctx: { where: "l1.simulateContract", to: p.token },
|
|
@@ -620,7 +689,7 @@ function routeErc20NonBase() {
|
|
|
620
689
|
key: `approve:${p.token}:${assetRouter}`,
|
|
621
690
|
kind: "approve",
|
|
622
691
|
description: `Approve deposit token for amount`,
|
|
623
|
-
tx:
|
|
692
|
+
tx: approveTx
|
|
624
693
|
});
|
|
625
694
|
}
|
|
626
695
|
if (!baseIsEth) {
|
|
@@ -639,15 +708,14 @@ function routeErc20NonBase() {
|
|
|
639
708
|
}
|
|
640
709
|
);
|
|
641
710
|
if (baseAllowance < mintValue) {
|
|
642
|
-
const
|
|
711
|
+
const approveBaseTx = await wrapAs3(
|
|
643
712
|
"CONTRACT",
|
|
644
713
|
OP_DEPOSITS.nonbase.estGas,
|
|
645
|
-
() =>
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
account: ctx.client.account
|
|
714
|
+
() => buildApprovalRequest({
|
|
715
|
+
ctx,
|
|
716
|
+
token: baseToken,
|
|
717
|
+
spender: assetRouter,
|
|
718
|
+
amount: mintValue
|
|
651
719
|
}),
|
|
652
720
|
{
|
|
653
721
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -659,7 +727,7 @@ function routeErc20NonBase() {
|
|
|
659
727
|
key: `approve:${baseToken}:${assetRouter}`,
|
|
660
728
|
kind: "approve",
|
|
661
729
|
description: `Approve base token for mintValue`,
|
|
662
|
-
tx:
|
|
730
|
+
tx: approveBaseTx
|
|
663
731
|
});
|
|
664
732
|
}
|
|
665
733
|
}
|
|
@@ -895,15 +963,14 @@ function routeEthNonBase() {
|
|
|
895
963
|
);
|
|
896
964
|
const needsApprove = allowance < mintValue;
|
|
897
965
|
if (needsApprove) {
|
|
898
|
-
const
|
|
966
|
+
const approveTx = await wrapAs4(
|
|
899
967
|
"CONTRACT",
|
|
900
968
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
901
|
-
() =>
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
account: ctx.client.account
|
|
969
|
+
() => buildApprovalRequest({
|
|
970
|
+
ctx,
|
|
971
|
+
token: baseToken,
|
|
972
|
+
spender: ctx.l1AssetRouter,
|
|
973
|
+
amount: mintValue
|
|
907
974
|
}),
|
|
908
975
|
{
|
|
909
976
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -915,7 +982,7 @@ function routeEthNonBase() {
|
|
|
915
982
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
916
983
|
kind: "approve",
|
|
917
984
|
description: `Approve base token for fees (mintValue)`,
|
|
918
|
-
tx:
|
|
985
|
+
tx: approveTx
|
|
919
986
|
});
|
|
920
987
|
}
|
|
921
988
|
const secondBridgeCalldata = await wrapAs4(
|
|
@@ -1095,15 +1162,14 @@ function routeErc20Base() {
|
|
|
1095
1162
|
);
|
|
1096
1163
|
const needsApprove = allowance < mintValue;
|
|
1097
1164
|
if (needsApprove) {
|
|
1098
|
-
const
|
|
1165
|
+
const approveTx = await wrapAs5(
|
|
1099
1166
|
"CONTRACT",
|
|
1100
1167
|
OP_DEPOSITS.base.estGas,
|
|
1101
|
-
() =>
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
account: ctx.client.account
|
|
1168
|
+
() => buildApprovalRequest({
|
|
1169
|
+
ctx,
|
|
1170
|
+
token: baseToken,
|
|
1171
|
+
spender: ctx.l1AssetRouter,
|
|
1172
|
+
amount: mintValue
|
|
1107
1173
|
}),
|
|
1108
1174
|
{
|
|
1109
1175
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -1115,7 +1181,7 @@ function routeErc20Base() {
|
|
|
1115
1181
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
1116
1182
|
kind: "approve",
|
|
1117
1183
|
description: "Approve base token for mintValue",
|
|
1118
|
-
tx:
|
|
1184
|
+
tx: approveTx
|
|
1119
1185
|
});
|
|
1120
1186
|
}
|
|
1121
1187
|
const req = buildDirectRequestStruct({
|
|
@@ -456,6 +456,22 @@ function routeEthDirect() {
|
|
|
456
456
|
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
457
457
|
var ZERO_L2_TOKEN_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
458
458
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
459
|
+
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
460
|
+
if (!input.ctx.resolvedToken) {
|
|
461
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
462
|
+
}
|
|
463
|
+
const { chainId: l1ChainId } = await input.ctx.client.l1.getNetwork();
|
|
464
|
+
const isL1Origin = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID || input.ctx.resolvedToken.originChainId === 0n || input.ctx.resolvedToken.originChainId === BigInt(l1ChainId);
|
|
465
|
+
if (isL1Origin) {
|
|
466
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
467
|
+
}
|
|
468
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
469
|
+
input.amount,
|
|
470
|
+
input.receiver,
|
|
471
|
+
input.token
|
|
472
|
+
);
|
|
473
|
+
return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
|
|
474
|
+
}
|
|
459
475
|
async function getPriorityGasModel(input) {
|
|
460
476
|
try {
|
|
461
477
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
@@ -528,9 +544,14 @@ function routeErc20NonBase() {
|
|
|
528
544
|
const secondBridgeCalldata = await wrapAs2(
|
|
529
545
|
"INTERNAL",
|
|
530
546
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
531
|
-
() =>
|
|
547
|
+
() => encodeSecondBridgeErc20DepositCalldata({
|
|
548
|
+
ctx,
|
|
549
|
+
token: p.token,
|
|
550
|
+
amount: p.amount,
|
|
551
|
+
receiver
|
|
552
|
+
}),
|
|
532
553
|
{
|
|
533
|
-
ctx: { where: "
|
|
554
|
+
ctx: { where: "encodeSecondBridgeErc20DepositCalldata" },
|
|
534
555
|
message: "Failed to encode bridging calldata."
|
|
535
556
|
}
|
|
536
557
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterlabs/zksync-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -141,8 +141,10 @@
|
|
|
141
141
|
"docs:serve": "mdbook serve docs -p 3000",
|
|
142
142
|
"docs:build": "mdbook build docs",
|
|
143
143
|
"test": "bun test",
|
|
144
|
-
"test:e2e:ethers": "bun test ./src/adapters/ethers/e2e/*.e2e.ts",
|
|
145
|
-
"test:e2e:viem": "bun test ./src/adapters/viem/e2e/*.e2e.ts",
|
|
144
|
+
"test:e2e:ethers": "bun test ./src/adapters/ethers/e2e/*.e2e.ts --path-ignore-patterns='**/interop*'",
|
|
145
|
+
"test:e2e:viem": "bun test ./src/adapters/viem/e2e/*.e2e.ts --path-ignore-patterns='**/interop*'",
|
|
146
|
+
"test:e2e:interop:ethers": "bun test ./src/adapters/ethers/e2e/interop.e2e.ts",
|
|
147
|
+
"test:e2e:interop:viem": "bun test ./src/adapters/viem/e2e/interop.e2e.ts",
|
|
146
148
|
"test:watch": "bun test --watch",
|
|
147
149
|
"test:cov": "bun test --coverage",
|
|
148
150
|
"test:core": "bun test src/core",
|