@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
|
@@ -8175,15 +8175,107 @@ function routeEthDirect() {
|
|
|
8175
8175
|
}
|
|
8176
8176
|
};
|
|
8177
8177
|
}
|
|
8178
|
+
|
|
8179
|
+
// src/core/codec/ntv.ts
|
|
8180
|
+
function createNTVCodec(deps) {
|
|
8181
|
+
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
8182
|
+
const encoded = deps.encode(
|
|
8183
|
+
["uint256", "address", "address"],
|
|
8184
|
+
[originChainId, ntvAddress, tokenAddress]
|
|
8185
|
+
);
|
|
8186
|
+
return deps.keccak256(encoded);
|
|
8187
|
+
}
|
|
8188
|
+
return {
|
|
8189
|
+
encodeAssetId
|
|
8190
|
+
};
|
|
8191
|
+
}
|
|
8192
|
+
|
|
8193
|
+
// src/adapters/viem/resources/deposits/routes/approval.ts
|
|
8194
|
+
function errorText(error) {
|
|
8195
|
+
const parts = [];
|
|
8196
|
+
let current = error;
|
|
8197
|
+
for (let depth = 0; current && depth < 8; depth++) {
|
|
8198
|
+
const record = current;
|
|
8199
|
+
for (const key of ["name", "shortMessage", "message", "details"]) {
|
|
8200
|
+
const value = record[key];
|
|
8201
|
+
if (typeof value === "string") parts.push(value);
|
|
8202
|
+
}
|
|
8203
|
+
current = record.cause;
|
|
8204
|
+
}
|
|
8205
|
+
return parts.join("\n");
|
|
8206
|
+
}
|
|
8207
|
+
function isNoReturnApproveSimulationError(error) {
|
|
8208
|
+
const text = errorText(error);
|
|
8209
|
+
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));
|
|
8210
|
+
}
|
|
8211
|
+
async function buildApprovalRequest({
|
|
8212
|
+
ctx,
|
|
8213
|
+
token,
|
|
8214
|
+
spender,
|
|
8215
|
+
amount
|
|
8216
|
+
}) {
|
|
8217
|
+
try {
|
|
8218
|
+
const sim = await ctx.client.l1.simulateContract({
|
|
8219
|
+
address: token,
|
|
8220
|
+
abi: IERC20_default,
|
|
8221
|
+
functionName: "approve",
|
|
8222
|
+
args: [spender, amount],
|
|
8223
|
+
account: ctx.client.account
|
|
8224
|
+
});
|
|
8225
|
+
return { ...sim.request };
|
|
8226
|
+
} catch (error) {
|
|
8227
|
+
if (!isNoReturnApproveSimulationError(error)) {
|
|
8228
|
+
throw error;
|
|
8229
|
+
}
|
|
8230
|
+
return {
|
|
8231
|
+
address: token,
|
|
8232
|
+
abi: IERC20_default,
|
|
8233
|
+
functionName: "approve",
|
|
8234
|
+
args: [spender, amount],
|
|
8235
|
+
account: ctx.client.account
|
|
8236
|
+
};
|
|
8237
|
+
}
|
|
8238
|
+
}
|
|
8239
|
+
|
|
8240
|
+
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
8178
8241
|
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
8179
8242
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8243
|
+
var ntvCodec = createNTVCodec({
|
|
8244
|
+
encode: (types, values) => viem.encodeAbiParameters(
|
|
8245
|
+
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
8246
|
+
values
|
|
8247
|
+
),
|
|
8248
|
+
keccak256: viem.keccak256
|
|
8249
|
+
});
|
|
8250
|
+
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
8251
|
+
if (!input.ctx.resolvedToken) {
|
|
8252
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
8253
|
+
}
|
|
8254
|
+
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
8255
|
+
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
8256
|
+
l1ChainId,
|
|
8257
|
+
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
8258
|
+
input.token
|
|
8259
|
+
);
|
|
8260
|
+
const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
|
|
8261
|
+
const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
|
|
8262
|
+
if (isL1Origin) {
|
|
8263
|
+
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
8264
|
+
}
|
|
8265
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
8266
|
+
input.amount,
|
|
8267
|
+
input.receiver,
|
|
8268
|
+
input.token
|
|
8269
|
+
);
|
|
8270
|
+
return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
|
|
8271
|
+
}
|
|
8180
8272
|
async function getPriorityGasModel(input) {
|
|
8181
8273
|
try {
|
|
8182
8274
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
8183
8275
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
8184
8276
|
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
8185
|
-
const isFirstBridge = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID
|
|
8186
|
-
const erc20MetadataOriginChainId = isFirstBridge ? l1ChainId : input.ctx.resolvedToken.originChainId;
|
|
8277
|
+
const isFirstBridge = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID;
|
|
8278
|
+
const erc20MetadataOriginChainId = isFirstBridge ? l1ChainId : input.ctx.resolvedToken.originChainId !== 0n ? input.ctx.resolvedToken.originChainId : await l1NativeTokenVault.read.originChainId([input.ctx.resolvedToken.assetId]);
|
|
8187
8279
|
const erc20Metadata = await l1NativeTokenVault.read.getERC20Getters([
|
|
8188
8280
|
input.token,
|
|
8189
8281
|
erc20MetadataOriginChainId
|
|
@@ -8266,10 +8358,15 @@ function routeErc20NonBase() {
|
|
|
8266
8358
|
const secondBridgeCalldata = await wrapAs3(
|
|
8267
8359
|
"INTERNAL",
|
|
8268
8360
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
8269
|
-
() =>
|
|
8361
|
+
() => encodeSecondBridgeErc20DepositCalldata({
|
|
8362
|
+
ctx,
|
|
8363
|
+
token: p.token,
|
|
8364
|
+
amount: p.amount,
|
|
8365
|
+
receiver
|
|
8366
|
+
}),
|
|
8270
8367
|
{
|
|
8271
8368
|
ctx: {
|
|
8272
|
-
where: "
|
|
8369
|
+
where: "encodeSecondBridgeErc20DepositCalldata",
|
|
8273
8370
|
token: p.token,
|
|
8274
8371
|
amount: p.amount.toString()
|
|
8275
8372
|
},
|
|
@@ -8314,15 +8411,14 @@ function routeErc20NonBase() {
|
|
|
8314
8411
|
}
|
|
8315
8412
|
);
|
|
8316
8413
|
if (depositAllowance < p.amount) {
|
|
8317
|
-
const
|
|
8414
|
+
const approveTx = await wrapAs3(
|
|
8318
8415
|
"CONTRACT",
|
|
8319
8416
|
OP_DEPOSITS.nonbase.estGas,
|
|
8320
|
-
() =>
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
account: ctx.client.account
|
|
8417
|
+
() => buildApprovalRequest({
|
|
8418
|
+
ctx,
|
|
8419
|
+
token: p.token,
|
|
8420
|
+
spender: assetRouter,
|
|
8421
|
+
amount: p.amount
|
|
8326
8422
|
}),
|
|
8327
8423
|
{
|
|
8328
8424
|
ctx: { where: "l1.simulateContract", to: p.token },
|
|
@@ -8334,7 +8430,7 @@ function routeErc20NonBase() {
|
|
|
8334
8430
|
key: `approve:${p.token}:${assetRouter}`,
|
|
8335
8431
|
kind: "approve",
|
|
8336
8432
|
description: `Approve deposit token for amount`,
|
|
8337
|
-
tx:
|
|
8433
|
+
tx: approveTx
|
|
8338
8434
|
});
|
|
8339
8435
|
}
|
|
8340
8436
|
if (!baseIsEth) {
|
|
@@ -8353,15 +8449,14 @@ function routeErc20NonBase() {
|
|
|
8353
8449
|
}
|
|
8354
8450
|
);
|
|
8355
8451
|
if (baseAllowance < mintValue) {
|
|
8356
|
-
const
|
|
8452
|
+
const approveBaseTx = await wrapAs3(
|
|
8357
8453
|
"CONTRACT",
|
|
8358
8454
|
OP_DEPOSITS.nonbase.estGas,
|
|
8359
|
-
() =>
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
account: ctx.client.account
|
|
8455
|
+
() => buildApprovalRequest({
|
|
8456
|
+
ctx,
|
|
8457
|
+
token: baseToken,
|
|
8458
|
+
spender: assetRouter,
|
|
8459
|
+
amount: mintValue
|
|
8365
8460
|
}),
|
|
8366
8461
|
{
|
|
8367
8462
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -8373,7 +8468,7 @@ function routeErc20NonBase() {
|
|
|
8373
8468
|
key: `approve:${baseToken}:${assetRouter}`,
|
|
8374
8469
|
kind: "approve",
|
|
8375
8470
|
description: `Approve base token for mintValue`,
|
|
8376
|
-
tx:
|
|
8471
|
+
tx: approveBaseTx
|
|
8377
8472
|
});
|
|
8378
8473
|
}
|
|
8379
8474
|
}
|
|
@@ -8467,25 +8562,9 @@ function routeErc20NonBase() {
|
|
|
8467
8562
|
}
|
|
8468
8563
|
};
|
|
8469
8564
|
}
|
|
8470
|
-
|
|
8471
|
-
// src/core/codec/ntv.ts
|
|
8472
|
-
function createNTVCodec(deps) {
|
|
8473
|
-
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
8474
|
-
const encoded = deps.encode(
|
|
8475
|
-
["uint256", "address", "address"],
|
|
8476
|
-
[originChainId, ntvAddress, tokenAddress]
|
|
8477
|
-
);
|
|
8478
|
-
return deps.keccak256(encoded);
|
|
8479
|
-
}
|
|
8480
|
-
return {
|
|
8481
|
-
encodeAssetId
|
|
8482
|
-
};
|
|
8483
|
-
}
|
|
8484
|
-
|
|
8485
|
-
// src/adapters/viem/resources/deposits/routes/eth-nonbase.ts
|
|
8486
8565
|
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
8487
8566
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8488
|
-
var
|
|
8567
|
+
var ntvCodec2 = createNTVCodec({
|
|
8489
8568
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
8490
8569
|
types.map((type, index) => ({ type, name: `arg${index}` })),
|
|
8491
8570
|
values
|
|
@@ -8497,7 +8576,7 @@ async function getPriorityGasModel2(input) {
|
|
|
8497
8576
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
8498
8577
|
const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
|
|
8499
8578
|
const originChainId = input.ctx.resolvedToken.originChainId !== 0n ? input.ctx.resolvedToken.originChainId : BigInt(await input.ctx.client.l1.getChainId());
|
|
8500
|
-
const resolvedAssetId = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID2 ?
|
|
8579
|
+
const resolvedAssetId = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID2 ? ntvCodec2.encodeAssetId(originChainId, L2_NATIVE_TOKEN_VAULT_ADDRESS, ETH_ADDRESS) : input.ctx.resolvedToken.assetId;
|
|
8501
8580
|
const erc20Metadata = await l1NativeTokenVault.read.getERC20Getters([
|
|
8502
8581
|
ETH_ADDRESS,
|
|
8503
8582
|
originChainId
|
|
@@ -8625,15 +8704,14 @@ function routeEthNonBase() {
|
|
|
8625
8704
|
);
|
|
8626
8705
|
const needsApprove = allowance < mintValue;
|
|
8627
8706
|
if (needsApprove) {
|
|
8628
|
-
const
|
|
8707
|
+
const approveTx = await wrapAs4(
|
|
8629
8708
|
"CONTRACT",
|
|
8630
8709
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
8631
|
-
() =>
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
account: ctx.client.account
|
|
8710
|
+
() => buildApprovalRequest({
|
|
8711
|
+
ctx,
|
|
8712
|
+
token: baseToken,
|
|
8713
|
+
spender: ctx.l1AssetRouter,
|
|
8714
|
+
amount: mintValue
|
|
8637
8715
|
}),
|
|
8638
8716
|
{
|
|
8639
8717
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -8645,7 +8723,7 @@ function routeEthNonBase() {
|
|
|
8645
8723
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
8646
8724
|
kind: "approve",
|
|
8647
8725
|
description: `Approve base token for fees (mintValue)`,
|
|
8648
|
-
tx:
|
|
8726
|
+
tx: approveTx
|
|
8649
8727
|
});
|
|
8650
8728
|
}
|
|
8651
8729
|
const secondBridgeCalldata = await wrapAs4(
|
|
@@ -8825,15 +8903,14 @@ function routeErc20Base() {
|
|
|
8825
8903
|
);
|
|
8826
8904
|
const needsApprove = allowance < mintValue;
|
|
8827
8905
|
if (needsApprove) {
|
|
8828
|
-
const
|
|
8906
|
+
const approveTx = await wrapAs5(
|
|
8829
8907
|
"CONTRACT",
|
|
8830
8908
|
OP_DEPOSITS.base.estGas,
|
|
8831
|
-
() =>
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
account: ctx.client.account
|
|
8909
|
+
() => buildApprovalRequest({
|
|
8910
|
+
ctx,
|
|
8911
|
+
token: baseToken,
|
|
8912
|
+
spender: ctx.l1AssetRouter,
|
|
8913
|
+
amount: mintValue
|
|
8837
8914
|
}),
|
|
8838
8915
|
{
|
|
8839
8916
|
ctx: { where: "l1.simulateContract", to: baseToken },
|
|
@@ -8845,7 +8922,7 @@ function routeErc20Base() {
|
|
|
8845
8922
|
key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
|
|
8846
8923
|
kind: "approve",
|
|
8847
8924
|
description: "Approve base token for mintValue",
|
|
8848
|
-
tx:
|
|
8925
|
+
tx: approveTx
|
|
8849
8926
|
});
|
|
8850
8927
|
}
|
|
8851
8928
|
const req = buildDirectRequestStruct({
|
|
@@ -9017,7 +9094,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
9017
9094
|
return { l2Receipt, l2TxHash };
|
|
9018
9095
|
}
|
|
9019
9096
|
var { wrapAs: wrapAs6 } = createErrorHandlers("tokens");
|
|
9020
|
-
var
|
|
9097
|
+
var ntvCodec3 = createNTVCodec({
|
|
9021
9098
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
9022
9099
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
9023
9100
|
values
|
|
@@ -9131,7 +9208,7 @@ function createTokensResource(client) {
|
|
|
9131
9208
|
return wrapAs6("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
9132
9209
|
const baseAssetId = await getBaseTokenAssetId();
|
|
9133
9210
|
const l1ChainId = await getL1ChainId();
|
|
9134
|
-
const ethAssetId =
|
|
9211
|
+
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
9135
9212
|
l1ChainId,
|
|
9136
9213
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
9137
9214
|
ETH_ADDRESS
|