@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildDirectRequestStruct, createContractsResource, createDepositsResource, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createViemSdk, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-
|
|
1
|
+
export { buildDirectRequestStruct, createContractsResource, createDepositsResource, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createViemSdk, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-GBS7KQFU.js';
|
|
2
2
|
import '../../chunk-6LYAENO6.js';
|
|
3
3
|
import '../../chunk-3HHUZXSV.js';
|
|
4
4
|
export { createViemClient as createClient, createViemClient } from '../../chunk-CK5UFAZK.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Address } from '../../../../../core/types/primitives';
|
|
2
|
+
import type { BuildCtx } from '../context';
|
|
3
|
+
import type { ViemPlanWriteRequest } from './types';
|
|
4
|
+
type BuildApprovalRequestInput = {
|
|
5
|
+
ctx: BuildCtx;
|
|
6
|
+
token: Address;
|
|
7
|
+
spender: Address;
|
|
8
|
+
amount: bigint;
|
|
9
|
+
};
|
|
10
|
+
export declare function buildApprovalRequest({ ctx, token, spender, amount, }: BuildApprovalRequestInput): Promise<ViemPlanWriteRequest>;
|
|
11
|
+
export {};
|
|
@@ -6729,8 +6729,73 @@ function routeEthDirect() {
|
|
|
6729
6729
|
}
|
|
6730
6730
|
};
|
|
6731
6731
|
}
|
|
6732
|
+
|
|
6733
|
+
// src/adapters/viem/resources/deposits/routes/approval.ts
|
|
6734
|
+
function errorText(error) {
|
|
6735
|
+
const parts = [];
|
|
6736
|
+
let current = error;
|
|
6737
|
+
for (let depth = 0; current && depth < 8; depth++) {
|
|
6738
|
+
const record = current;
|
|
6739
|
+
for (const key of ["name", "shortMessage", "message", "details"]) {
|
|
6740
|
+
const value = record[key];
|
|
6741
|
+
if (typeof value === "string") parts.push(value);
|
|
6742
|
+
}
|
|
6743
|
+
current = record.cause;
|
|
6744
|
+
}
|
|
6745
|
+
return parts.join("\n");
|
|
6746
|
+
}
|
|
6747
|
+
function isNoReturnApproveSimulationError(error) {
|
|
6748
|
+
const text = errorText(error);
|
|
6749
|
+
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));
|
|
6750
|
+
}
|
|
6751
|
+
async function buildApprovalRequest({
|
|
6752
|
+
ctx,
|
|
6753
|
+
token,
|
|
6754
|
+
spender,
|
|
6755
|
+
amount
|
|
6756
|
+
}) {
|
|
6757
|
+
try {
|
|
6758
|
+
const sim = await ctx.client.l1.simulateContract({
|
|
6759
|
+
address: token,
|
|
6760
|
+
abi: IERC20_default,
|
|
6761
|
+
functionName: "approve",
|
|
6762
|
+
args: [spender, amount],
|
|
6763
|
+
account: ctx.client.account
|
|
6764
|
+
});
|
|
6765
|
+
return { ...sim.request };
|
|
6766
|
+
} catch (error) {
|
|
6767
|
+
if (!isNoReturnApproveSimulationError(error)) {
|
|
6768
|
+
throw error;
|
|
6769
|
+
}
|
|
6770
|
+
return {
|
|
6771
|
+
address: token,
|
|
6772
|
+
abi: IERC20_default,
|
|
6773
|
+
functionName: "approve",
|
|
6774
|
+
args: [spender, amount],
|
|
6775
|
+
account: ctx.client.account
|
|
6776
|
+
};
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
|
|
6780
|
+
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
6732
6781
|
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
6733
6782
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
6783
|
+
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
6784
|
+
if (!input.ctx.resolvedToken) {
|
|
6785
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
6786
|
+
}
|
|
6787
|
+
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
6788
|
+
const isL1Origin = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID || input.ctx.resolvedToken.originChainId === 0n || input.ctx.resolvedToken.originChainId === l1ChainId;
|
|
6789
|
+
if (isL1Origin) {
|
|
6790
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
6791
|
+
}
|
|
6792
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
6793
|
+
input.amount,
|
|
6794
|
+
input.receiver,
|
|
6795
|
+
input.token
|
|
6796
|
+
);
|
|
6797
|
+
return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
|
|
6798
|
+
}
|
|
6734
6799
|
async function getPriorityGasModel(input) {
|
|
6735
6800
|
try {
|
|
6736
6801
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
@@ -6820,10 +6885,15 @@ function routeErc20NonBase() {
|
|
|
6820
6885
|
const secondBridgeCalldata = await wrapAs3(
|
|
6821
6886
|
"INTERNAL",
|
|
6822
6887
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
6823
|
-
() =>
|
|
6888
|
+
() => encodeSecondBridgeErc20DepositCalldata({
|
|
6889
|
+
ctx,
|
|
6890
|
+
token: p.token,
|
|
6891
|
+
amount: p.amount,
|
|
6892
|
+
receiver
|
|
6893
|
+
}),
|
|
6824
6894
|
{
|
|
6825
6895
|
ctx: {
|
|
6826
|
-
where: "
|
|
6896
|
+
where: "encodeSecondBridgeErc20DepositCalldata",
|
|
6827
6897
|
token: p.token,
|
|
6828
6898
|
amount: p.amount.toString()
|
|
6829
6899
|
},
|
|
@@ -6868,15 +6938,14 @@ function routeErc20NonBase() {
|
|
|
6868
6938
|
}
|
|
6869
6939
|
);
|
|
6870
6940
|
if (depositAllowance < p.amount) {
|
|
6871
|
-
const
|
|
6941
|
+
const approveTx = await wrapAs3(
|
|
6872
6942
|
"CONTRACT",
|
|
6873
6943
|
OP_DEPOSITS.nonbase.estGas,
|
|
6874
|
-
() =>
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
account: ctx.client.account
|
|
6944
|
+
() => buildApprovalRequest({
|
|
6945
|
+
ctx,
|
|
6946
|
+
token: p.token,
|
|
6947
|
+
spender: assetRouter,
|
|
6948
|
+
amount: p.amount
|
|
6880
6949
|
}),
|
|
6881
6950
|
{
|
|
6882
6951
|
ctx: { where: "l1.simulateContract", to: p.token },
|
|
@@ -6888,7 +6957,7 @@ function routeErc20NonBase() {
|
|
|
6888
6957
|
key: `approve:${p.token}:${assetRouter}`,
|
|
6889
6958
|
kind: "approve",
|
|
6890
6959
|
description: `Approve deposit token for amount`,
|
|
6891
|
-
tx:
|
|
6960
|
+
tx: approveTx
|
|
6892
6961
|
});
|
|
6893
6962
|
}
|
|
6894
6963
|
if (!baseIsEth) {
|
|
@@ -6907,15 +6976,14 @@ function routeErc20NonBase() {
|
|
|
6907
6976
|
}
|
|
6908
6977
|
);
|
|
6909
6978
|
if (baseAllowance < mintValue) {
|
|
6910
|
-
const
|
|
6979
|
+
const approveBaseTx = await wrapAs3(
|
|
6911
6980
|
"CONTRACT",
|
|
6912
6981
|
OP_DEPOSITS.nonbase.estGas,
|
|
6913
|
-
() =>
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
account: ctx.client.account
|
|
6982
|
+
() => buildApprovalRequest({
|
|
6983
|
+
ctx,
|
|
6984
|
+
token: baseToken,
|
|
6985
|
+
spender: assetRouter,
|
|
6986
|
+
amount: mintValue
|
|
6919
6987
|
}),
|
|
6920
6988
|
{
|
|
6921
6989
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -6927,7 +6995,7 @@ function routeErc20NonBase() {
|
|
|
6927
6995
|
key: `approve:${baseToken}:${assetRouter}`,
|
|
6928
6996
|
kind: "approve",
|
|
6929
6997
|
description: `Approve base token for mintValue`,
|
|
6930
|
-
tx:
|
|
6998
|
+
tx: approveBaseTx
|
|
6931
6999
|
});
|
|
6932
7000
|
}
|
|
6933
7001
|
}
|
|
@@ -7179,15 +7247,14 @@ function routeEthNonBase() {
|
|
|
7179
7247
|
);
|
|
7180
7248
|
const needsApprove = allowance < mintValue;
|
|
7181
7249
|
if (needsApprove) {
|
|
7182
|
-
const
|
|
7250
|
+
const approveTx = await wrapAs4(
|
|
7183
7251
|
"CONTRACT",
|
|
7184
7252
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7185
|
-
() =>
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
account: ctx.client.account
|
|
7253
|
+
() => buildApprovalRequest({
|
|
7254
|
+
ctx,
|
|
7255
|
+
token: baseToken,
|
|
7256
|
+
spender: ctx.l1AssetRouter,
|
|
7257
|
+
amount: mintValue
|
|
7191
7258
|
}),
|
|
7192
7259
|
{
|
|
7193
7260
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -7199,7 +7266,7 @@ function routeEthNonBase() {
|
|
|
7199
7266
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
7200
7267
|
kind: "approve",
|
|
7201
7268
|
description: `Approve base token for fees (mintValue)`,
|
|
7202
|
-
tx:
|
|
7269
|
+
tx: approveTx
|
|
7203
7270
|
});
|
|
7204
7271
|
}
|
|
7205
7272
|
const secondBridgeCalldata = await wrapAs4(
|
|
@@ -7379,15 +7446,14 @@ function routeErc20Base() {
|
|
|
7379
7446
|
);
|
|
7380
7447
|
const needsApprove = allowance < mintValue;
|
|
7381
7448
|
if (needsApprove) {
|
|
7382
|
-
const
|
|
7449
|
+
const approveTx = await wrapAs5(
|
|
7383
7450
|
"CONTRACT",
|
|
7384
7451
|
OP_DEPOSITS.base.estGas,
|
|
7385
|
-
() =>
|
|
7386
|
-
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
account: ctx.client.account
|
|
7452
|
+
() => buildApprovalRequest({
|
|
7453
|
+
ctx,
|
|
7454
|
+
token: baseToken,
|
|
7455
|
+
spender: ctx.l1AssetRouter,
|
|
7456
|
+
amount: mintValue
|
|
7391
7457
|
}),
|
|
7392
7458
|
{
|
|
7393
7459
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -7399,7 +7465,7 @@ function routeErc20Base() {
|
|
|
7399
7465
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
7400
7466
|
kind: "approve",
|
|
7401
7467
|
description: "Approve base token for mintValue",
|
|
7402
|
-
tx:
|
|
7468
|
+
tx: approveTx
|
|
7403
7469
|
});
|
|
7404
7470
|
}
|
|
7405
7471
|
const req = buildDirectRequestStruct({
|