@matterlabs/zksync-js 0.0.17 → 0.0.19
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 +55 -24
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +1 -1
- package/dist/adapters/ethers/sdk.cjs +53 -24
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +1 -1
- package/dist/adapters/viem/index.cjs +133 -56
- 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 +133 -56
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +1 -1
- package/dist/{chunk-ONCNOWNC.js → chunk-3T5V4HKS.js} +120 -41
- package/dist/{chunk-J2RPWU2R.js → chunk-5H3VTIYD.js} +39 -8
- package/package.json +6 -4
|
@@ -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-3T5V4HKS.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,15 +6729,107 @@ function routeEthDirect() {
|
|
|
6729
6729
|
}
|
|
6730
6730
|
};
|
|
6731
6731
|
}
|
|
6732
|
+
|
|
6733
|
+
// src/core/codec/ntv.ts
|
|
6734
|
+
function createNTVCodec(deps) {
|
|
6735
|
+
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
6736
|
+
const encoded = deps.encode(
|
|
6737
|
+
["uint256", "address", "address"],
|
|
6738
|
+
[originChainId, ntvAddress, tokenAddress]
|
|
6739
|
+
);
|
|
6740
|
+
return deps.keccak256(encoded);
|
|
6741
|
+
}
|
|
6742
|
+
return {
|
|
6743
|
+
encodeAssetId
|
|
6744
|
+
};
|
|
6745
|
+
}
|
|
6746
|
+
|
|
6747
|
+
// src/adapters/viem/resources/deposits/routes/approval.ts
|
|
6748
|
+
function errorText(error) {
|
|
6749
|
+
const parts = [];
|
|
6750
|
+
let current = error;
|
|
6751
|
+
for (let depth = 0; current && depth < 8; depth++) {
|
|
6752
|
+
const record = current;
|
|
6753
|
+
for (const key of ["name", "shortMessage", "message", "details"]) {
|
|
6754
|
+
const value = record[key];
|
|
6755
|
+
if (typeof value === "string") parts.push(value);
|
|
6756
|
+
}
|
|
6757
|
+
current = record.cause;
|
|
6758
|
+
}
|
|
6759
|
+
return parts.join("\n");
|
|
6760
|
+
}
|
|
6761
|
+
function isNoReturnApproveSimulationError(error) {
|
|
6762
|
+
const text = errorText(error);
|
|
6763
|
+
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));
|
|
6764
|
+
}
|
|
6765
|
+
async function buildApprovalRequest({
|
|
6766
|
+
ctx,
|
|
6767
|
+
token,
|
|
6768
|
+
spender,
|
|
6769
|
+
amount
|
|
6770
|
+
}) {
|
|
6771
|
+
try {
|
|
6772
|
+
const sim = await ctx.client.l1.simulateContract({
|
|
6773
|
+
address: token,
|
|
6774
|
+
abi: IERC20_default,
|
|
6775
|
+
functionName: "approve",
|
|
6776
|
+
args: [spender, amount],
|
|
6777
|
+
account: ctx.client.account
|
|
6778
|
+
});
|
|
6779
|
+
return { ...sim.request };
|
|
6780
|
+
} catch (error) {
|
|
6781
|
+
if (!isNoReturnApproveSimulationError(error)) {
|
|
6782
|
+
throw error;
|
|
6783
|
+
}
|
|
6784
|
+
return {
|
|
6785
|
+
address: token,
|
|
6786
|
+
abi: IERC20_default,
|
|
6787
|
+
functionName: "approve",
|
|
6788
|
+
args: [spender, amount],
|
|
6789
|
+
account: ctx.client.account
|
|
6790
|
+
};
|
|
6791
|
+
}
|
|
6792
|
+
}
|
|
6793
|
+
|
|
6794
|
+
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
6732
6795
|
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
6733
6796
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
6797
|
+
var ntvCodec = createNTVCodec({
|
|
6798
|
+
encode: (types, values) => viem.encodeAbiParameters(
|
|
6799
|
+
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
6800
|
+
values
|
|
6801
|
+
),
|
|
6802
|
+
keccak256: viem.keccak256
|
|
6803
|
+
});
|
|
6804
|
+
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
6805
|
+
if (!input.ctx.resolvedToken) {
|
|
6806
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
6807
|
+
}
|
|
6808
|
+
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
6809
|
+
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
6810
|
+
l1ChainId,
|
|
6811
|
+
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
6812
|
+
input.token
|
|
6813
|
+
);
|
|
6814
|
+
const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
|
|
6815
|
+
const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
|
|
6816
|
+
if (isL1Origin) {
|
|
6817
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
6818
|
+
}
|
|
6819
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
6820
|
+
input.amount,
|
|
6821
|
+
input.receiver,
|
|
6822
|
+
input.token
|
|
6823
|
+
);
|
|
6824
|
+
return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
|
|
6825
|
+
}
|
|
6734
6826
|
async function getPriorityGasModel(input) {
|
|
6735
6827
|
try {
|
|
6736
6828
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
6737
6829
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
6738
6830
|
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
6739
|
-
const isFirstBridge = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID
|
|
6740
|
-
const erc20MetadataOriginChainId = isFirstBridge ? l1ChainId : input.ctx.resolvedToken.originChainId;
|
|
6831
|
+
const isFirstBridge = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID;
|
|
6832
|
+
const erc20MetadataOriginChainId = isFirstBridge ? l1ChainId : input.ctx.resolvedToken.originChainId !== 0n ? input.ctx.resolvedToken.originChainId : await l1NativeTokenVault.read.originChainId([input.ctx.resolvedToken.assetId]);
|
|
6741
6833
|
const erc20Metadata = await l1NativeTokenVault.read.getERC20Getters([
|
|
6742
6834
|
input.token,
|
|
6743
6835
|
erc20MetadataOriginChainId
|
|
@@ -6820,10 +6912,15 @@ function routeErc20NonBase() {
|
|
|
6820
6912
|
const secondBridgeCalldata = await wrapAs3(
|
|
6821
6913
|
"INTERNAL",
|
|
6822
6914
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
6823
|
-
() =>
|
|
6915
|
+
() => encodeSecondBridgeErc20DepositCalldata({
|
|
6916
|
+
ctx,
|
|
6917
|
+
token: p.token,
|
|
6918
|
+
amount: p.amount,
|
|
6919
|
+
receiver
|
|
6920
|
+
}),
|
|
6824
6921
|
{
|
|
6825
6922
|
ctx: {
|
|
6826
|
-
where: "
|
|
6923
|
+
where: "encodeSecondBridgeErc20DepositCalldata",
|
|
6827
6924
|
token: p.token,
|
|
6828
6925
|
amount: p.amount.toString()
|
|
6829
6926
|
},
|
|
@@ -6868,15 +6965,14 @@ function routeErc20NonBase() {
|
|
|
6868
6965
|
}
|
|
6869
6966
|
);
|
|
6870
6967
|
if (depositAllowance < p.amount) {
|
|
6871
|
-
const
|
|
6968
|
+
const approveTx = await wrapAs3(
|
|
6872
6969
|
"CONTRACT",
|
|
6873
6970
|
OP_DEPOSITS.nonbase.estGas,
|
|
6874
|
-
() =>
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
account: ctx.client.account
|
|
6971
|
+
() => buildApprovalRequest({
|
|
6972
|
+
ctx,
|
|
6973
|
+
token: p.token,
|
|
6974
|
+
spender: assetRouter,
|
|
6975
|
+
amount: p.amount
|
|
6880
6976
|
}),
|
|
6881
6977
|
{
|
|
6882
6978
|
ctx: { where: "l1.simulateContract", to: p.token },
|
|
@@ -6888,7 +6984,7 @@ function routeErc20NonBase() {
|
|
|
6888
6984
|
key: `approve:${p.token}:${assetRouter}`,
|
|
6889
6985
|
kind: "approve",
|
|
6890
6986
|
description: `Approve deposit token for amount`,
|
|
6891
|
-
tx:
|
|
6987
|
+
tx: approveTx
|
|
6892
6988
|
});
|
|
6893
6989
|
}
|
|
6894
6990
|
if (!baseIsEth) {
|
|
@@ -6907,15 +7003,14 @@ function routeErc20NonBase() {
|
|
|
6907
7003
|
}
|
|
6908
7004
|
);
|
|
6909
7005
|
if (baseAllowance < mintValue) {
|
|
6910
|
-
const
|
|
7006
|
+
const approveBaseTx = await wrapAs3(
|
|
6911
7007
|
"CONTRACT",
|
|
6912
7008
|
OP_DEPOSITS.nonbase.estGas,
|
|
6913
|
-
() =>
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
account: ctx.client.account
|
|
7009
|
+
() => buildApprovalRequest({
|
|
7010
|
+
ctx,
|
|
7011
|
+
token: baseToken,
|
|
7012
|
+
spender: assetRouter,
|
|
7013
|
+
amount: mintValue
|
|
6919
7014
|
}),
|
|
6920
7015
|
{
|
|
6921
7016
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -6927,7 +7022,7 @@ function routeErc20NonBase() {
|
|
|
6927
7022
|
key: `approve:${baseToken}:${assetRouter}`,
|
|
6928
7023
|
kind: "approve",
|
|
6929
7024
|
description: `Approve base token for mintValue`,
|
|
6930
|
-
tx:
|
|
7025
|
+
tx: approveBaseTx
|
|
6931
7026
|
});
|
|
6932
7027
|
}
|
|
6933
7028
|
}
|
|
@@ -7021,25 +7116,9 @@ function routeErc20NonBase() {
|
|
|
7021
7116
|
}
|
|
7022
7117
|
};
|
|
7023
7118
|
}
|
|
7024
|
-
|
|
7025
|
-
// src/core/codec/ntv.ts
|
|
7026
|
-
function createNTVCodec(deps) {
|
|
7027
|
-
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
7028
|
-
const encoded = deps.encode(
|
|
7029
|
-
["uint256", "address", "address"],
|
|
7030
|
-
[originChainId, ntvAddress, tokenAddress]
|
|
7031
|
-
);
|
|
7032
|
-
return deps.keccak256(encoded);
|
|
7033
|
-
}
|
|
7034
|
-
return {
|
|
7035
|
-
encodeAssetId
|
|
7036
|
-
};
|
|
7037
|
-
}
|
|
7038
|
-
|
|
7039
|
-
// src/adapters/viem/resources/deposits/routes/eth-nonbase.ts
|
|
7040
7119
|
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
7041
7120
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7042
|
-
var
|
|
7121
|
+
var ntvCodec2 = createNTVCodec({
|
|
7043
7122
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
7044
7123
|
types.map((type, index) => ({ type, name: `arg${index}` })),
|
|
7045
7124
|
values
|
|
@@ -7051,7 +7130,7 @@ async function getPriorityGasModel2(input) {
|
|
|
7051
7130
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
7052
7131
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
7053
7132
|
const originChainId = input.ctx.resolvedToken.originChainId !== 0n ? input.ctx.resolvedToken.originChainId : BigInt(await input.ctx.client.l1.getChainId());
|
|
7054
|
-
const resolvedAssetId = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID2 ?
|
|
7133
|
+
const resolvedAssetId = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID2 ? ntvCodec2.encodeAssetId(originChainId, L2_NATIVE_TOKEN_VAULT_ADDRESS, ETH_ADDRESS) : input.ctx.resolvedToken.assetId;
|
|
7055
7134
|
const erc20Metadata = await l1NativeTokenVault.read.getERC20Getters([
|
|
7056
7135
|
ETH_ADDRESS,
|
|
7057
7136
|
originChainId
|
|
@@ -7179,15 +7258,14 @@ function routeEthNonBase() {
|
|
|
7179
7258
|
);
|
|
7180
7259
|
const needsApprove = allowance < mintValue;
|
|
7181
7260
|
if (needsApprove) {
|
|
7182
|
-
const
|
|
7261
|
+
const approveTx = await wrapAs4(
|
|
7183
7262
|
"CONTRACT",
|
|
7184
7263
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7185
|
-
() =>
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
account: ctx.client.account
|
|
7264
|
+
() => buildApprovalRequest({
|
|
7265
|
+
ctx,
|
|
7266
|
+
token: baseToken,
|
|
7267
|
+
spender: ctx.l1AssetRouter,
|
|
7268
|
+
amount: mintValue
|
|
7191
7269
|
}),
|
|
7192
7270
|
{
|
|
7193
7271
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -7199,7 +7277,7 @@ function routeEthNonBase() {
|
|
|
7199
7277
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
7200
7278
|
kind: "approve",
|
|
7201
7279
|
description: `Approve base token for fees (mintValue)`,
|
|
7202
|
-
tx:
|
|
7280
|
+
tx: approveTx
|
|
7203
7281
|
});
|
|
7204
7282
|
}
|
|
7205
7283
|
const secondBridgeCalldata = await wrapAs4(
|
|
@@ -7379,15 +7457,14 @@ function routeErc20Base() {
|
|
|
7379
7457
|
);
|
|
7380
7458
|
const needsApprove = allowance < mintValue;
|
|
7381
7459
|
if (needsApprove) {
|
|
7382
|
-
const
|
|
7460
|
+
const approveTx = await wrapAs5(
|
|
7383
7461
|
"CONTRACT",
|
|
7384
7462
|
OP_DEPOSITS.base.estGas,
|
|
7385
|
-
() =>
|
|
7386
|
-
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
account: ctx.client.account
|
|
7463
|
+
() => buildApprovalRequest({
|
|
7464
|
+
ctx,
|
|
7465
|
+
token: baseToken,
|
|
7466
|
+
spender: ctx.l1AssetRouter,
|
|
7467
|
+
amount: mintValue
|
|
7391
7468
|
}),
|
|
7392
7469
|
{
|
|
7393
7470
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -7399,7 +7476,7 @@ function routeErc20Base() {
|
|
|
7399
7476
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
7400
7477
|
kind: "approve",
|
|
7401
7478
|
description: "Approve base token for mintValue",
|
|
7402
|
-
tx:
|
|
7479
|
+
tx: approveTx
|
|
7403
7480
|
});
|
|
7404
7481
|
}
|
|
7405
7482
|
const req = buildDirectRequestStruct({
|
|
@@ -7571,7 +7648,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
7571
7648
|
return { l2Receipt, l2TxHash };
|
|
7572
7649
|
}
|
|
7573
7650
|
var { wrapAs: wrapAs6 } = createErrorHandlers("tokens");
|
|
7574
|
-
var
|
|
7651
|
+
var ntvCodec3 = createNTVCodec({
|
|
7575
7652
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
7576
7653
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
7577
7654
|
values
|
|
@@ -7685,7 +7762,7 @@ function createTokensResource(client) {
|
|
|
7685
7762
|
return wrapAs6("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
7686
7763
|
const baseAssetId = await getBaseTokenAssetId();
|
|
7687
7764
|
const l1ChainId = await getL1ChainId();
|
|
7688
|
-
const ethAssetId =
|
|
7765
|
+
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
7689
7766
|
l1ChainId,
|
|
7690
7767
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
7691
7768
|
ETH_ADDRESS
|