Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zksync-ethers

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zksync-ethers - npm Package Compare versions

Comparing version 6.4.0 to 6.5.0

build/tests/integration/signer.test.d.ts

16

build/src/adapters.js

@@ -378,4 +378,4 @@ "use strict";

let l2GasLimit;
const bridgeContracts = await this.getL1BridgeContracts();
if (tx.bridgeAddress) {
const bridgeContracts = await this.getL1BridgeContracts();
const customBridgeData = tx.customBridgeData ??

@@ -393,3 +393,5 @@ (await bridgeContracts.weth.getAddress()) === tx.bridgeAddress

const baseCost = await zksyncContract.l2TransactionBaseCost(gasPriceForMessages, l2GasLimit, tx.gasPerPubdataByte);
const selfBalanceETH = await this.getBalanceL1();
const selfBalanceETH = tx.overrides.from
? await this._providerL1().getBalance(tx.overrides.from)
: await this.getBalanceL1();
// We could zero in, because the final fee will anyway be bigger than

@@ -413,3 +415,11 @@ if (baseCost >= selfBalanceETH + dummyAmount) {

amountForEstimate = dummyAmount;
if ((await this.getAllowanceL1(tx.token)) < amountForEstimate) {
let allowance;
if (tx.overrides.from) {
const erc20contract = typechain_1.IERC20__factory.connect(tx.token, this._providerL1());
allowance = await erc20contract.allowance(tx.overrides.from, await bridgeContracts.erc20.getAddress());
}
else {
allowance = await this.getAllowanceL1(tx.token);
}
if (allowance < amountForEstimate) {
throw new Error('Not enough allowance to cover the deposit!');

@@ -416,0 +426,0 @@ }

2

build/src/index.d.ts
export * as utils from './utils';
export * as types from './types';
export { EIP712Signer, Signer, L1Signer } from './signer';
export { EIP712Signer, Signer, L1Signer, L2VoidSigner, L1VoidSigner, } from './signer';
export { Wallet } from './wallet';
export { BrowserProvider, Provider } from './provider';
export { ContractFactory, Contract } from './contract';

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Contract = exports.ContractFactory = exports.Provider = exports.BrowserProvider = exports.Wallet = exports.L1Signer = exports.Signer = exports.EIP712Signer = exports.types = exports.utils = void 0;
exports.Contract = exports.ContractFactory = exports.Provider = exports.BrowserProvider = exports.Wallet = exports.L1VoidSigner = exports.L2VoidSigner = exports.L1Signer = exports.Signer = exports.EIP712Signer = exports.types = exports.utils = void 0;
exports.utils = __importStar(require("./utils"));

@@ -34,2 +34,4 @@ exports.types = __importStar(require("./types"));

Object.defineProperty(exports, "L1Signer", { enumerable: true, get: function () { return signer_1.L1Signer; } });
Object.defineProperty(exports, "L2VoidSigner", { enumerable: true, get: function () { return signer_1.L2VoidSigner; } });
Object.defineProperty(exports, "L1VoidSigner", { enumerable: true, get: function () { return signer_1.L1VoidSigner; } });
var wallet_1 = require("./wallet");

@@ -36,0 +38,0 @@ Object.defineProperty(exports, "Wallet", { enumerable: true, get: function () { return wallet_1.Wallet; } });

import { BigNumberish, BlockTag, BytesLike, ContractTransactionResponse, ethers, Overrides } from 'ethers';
import { Provider } from './provider';
import { Address, BalancesMap, FinalizeWithdrawalParams, FullDepositFee, PaymasterParams, PriorityOpResponse, Signature, TransactionRequest, TransactionResponse } from './types';
import { Address, BalancesMap, FinalizeWithdrawalParams, FullDepositFee, PaymasterParams, PriorityOpResponse, Signature, TransactionLike, TransactionRequest, TransactionResponse } from './types';
import { IL1Bridge, IL2Bridge, IZkSync } from '../typechain';

@@ -250,6 +250,4 @@ /**

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = signer.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -273,6 +271,4 @@ * });

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = signer.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -1020,2 +1016,267 @@ * paymasterParams: utils.getPaymasterParams(paymaster, {

}
declare const L2VoidSigner_base: {
new (...args: any[]): {
_providerL2(): Provider;
_signerL2(): ethers.Signer;
getBalance(token?: string | undefined, blockTag?: BlockTag): Promise<bigint>;
getAllBalances(): Promise<BalancesMap>;
getDeploymentNonce(): Promise<bigint>;
getL2BridgeContracts(): Promise<{
erc20: IL2Bridge;
weth: IL2Bridge;
}>;
_fillCustomData(data: import("./types").Eip712Meta): import("./types").Eip712Meta;
withdraw(transaction: {
token: string;
amount: BigNumberish;
to?: string | undefined;
bridgeAddress?: string | undefined;
paymasterParams?: PaymasterParams | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<TransactionResponse>;
transfer(transaction: {
to: string;
amount: BigNumberish;
token?: string | undefined;
paymasterParams?: PaymasterParams | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<TransactionResponse>;
sendTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionResponse>;
getAddress(): Promise<string>;
};
} & typeof ethers.VoidSigner;
/**
* A `L2VoidSigner` is an extension of {@link ethers.VoidSigner} class providing only L2 operations
*
* @see {@link L1VoidSigner} for L1 operations.
*/
export declare class L2VoidSigner extends L2VoidSigner_base {
provider: Provider;
_signerL2(): this;
_providerL2(): Provider;
/**
* Connects to the L2 network using the `provider`.
*
* @param provider The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L2VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
*
* let signer = new L2VoidSigner("<ADDRESS>");
* signer = signer.connect(provider);
*/
connect(provider: Provider): L2VoidSigner;
/**
* Designed for users who prefer a simplified approach by providing only the necessary data to create a valid transaction.
* The only required fields are `transaction.to` and either `transaction.data` or `transaction.value` (or both, if the method is payable).
* Any other fields that are not set will be prepared by this method.
*
* @param tx The transaction request that needs to be populated.
*
* @example
*
* import { Provider, L2VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const signer = new L2VoidSigner("<ADDRESS>", provider);
*
* const populatedTx = await signer.populateTransaction({
* to: Wallet.createRandom().address,
* value: 7_000_000n,
* maxFeePerGas: 3_500_000_000n,
* maxPriorityFeePerGas: 2_000_000_000n,
* customData: {
* gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
* factoryDeps: [],
* },
* });
*/
populateTransaction(tx: TransactionRequest): Promise<TransactionLike>;
}
declare const L1VoidSigner_base: {
new (...args: any[]): {
_providerL2(): Provider;
_providerL1(): ethers.Provider;
_signerL1(): ethers.Signer;
getMainContract(): Promise<IZkSync>;
getL1BridgeContracts(): Promise<{
erc20: IL1Bridge;
weth: IL1Bridge;
}>;
getBalanceL1(token?: string | undefined, blockTag?: BlockTag | undefined): Promise<bigint>;
getAllowanceL1(token: string, bridgeAddress?: string | undefined, blockTag?: BlockTag | undefined): Promise<bigint>;
l2TokenAddress(token: string): Promise<string>;
approveERC20(token: string, amount: BigNumberish, overrides?: (ethers.Overrides & {
bridgeAddress?: string | undefined;
}) | undefined): Promise<ethers.TransactionResponse>;
getBaseCost(params: {
gasLimit: BigNumberish;
gasPerPubdataByte?: BigNumberish | undefined;
gasPrice?: BigNumberish | undefined;
}): Promise<bigint>;
deposit(transaction: {
token: string;
amount: BigNumberish;
to?: string | undefined;
operatorTip?: BigNumberish | undefined;
bridgeAddress?: string | undefined;
approveERC20?: boolean | undefined;
l2GasLimit?: BigNumberish | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
refundRecipient?: string | undefined;
overrides?: ethers.Overrides | undefined;
approveOverrides?: ethers.Overrides | undefined;
customBridgeData?: BytesLike | undefined;
}): Promise<PriorityOpResponse>;
estimateGasDeposit(transaction: {
token: string;
amount: BigNumberish;
to?: string | undefined;
operatorTip?: BigNumberish | undefined;
bridgeAddress?: string | undefined;
customBridgeData?: BytesLike | undefined;
l2GasLimit?: BigNumberish | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
refundRecipient?: string | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<bigint>;
getDepositTx(transaction: {
token: string;
amount: BigNumberish;
to?: string | undefined;
operatorTip?: BigNumberish | undefined;
bridgeAddress?: string | undefined;
l2GasLimit?: BigNumberish | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
customBridgeData?: BytesLike | undefined;
refundRecipient?: string | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<any>;
getFullRequiredDepositFee(transaction: {
token: string;
to?: string | undefined;
bridgeAddress?: string | undefined;
customBridgeData?: BytesLike | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<FullDepositFee>;
_getWithdrawalLog(withdrawalHash: BytesLike, index?: number): Promise<{
log: import("./types").Log;
l1BatchTxId: number | null;
}>;
_getWithdrawalL2ToL1Log(withdrawalHash: BytesLike, index?: number): Promise<{
l2ToL1LogIndex: number;
l2ToL1Log: import("./types").L2ToL1Log;
}>;
finalizeWithdrawalParams(withdrawalHash: BytesLike, index?: number): Promise<FinalizeWithdrawalParams>;
finalizeWithdrawal(withdrawalHash: BytesLike, index?: number, overrides?: ethers.Overrides | undefined): Promise<ContractTransactionResponse>;
isWithdrawalFinalized(withdrawalHash: BytesLike, index?: number): Promise<boolean>;
claimFailedDeposit(depositHash: BytesLike, overrides?: ethers.Overrides | undefined): Promise<ContractTransactionResponse>;
requestExecute(transaction: {
contractAddress: string;
calldata: string;
l2GasLimit?: BigNumberish | undefined;
l2Value?: BigNumberish | undefined;
factoryDeps?: BytesLike[] | undefined;
operatorTip?: BigNumberish | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
refundRecipient?: string | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<PriorityOpResponse>;
estimateGasRequestExecute(transaction: {
contractAddress: string;
calldata: string;
l2GasLimit?: BigNumberish | undefined;
l2Value?: BigNumberish | undefined;
factoryDeps?: BytesLike[] | undefined;
operatorTip?: BigNumberish | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
refundRecipient?: string | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<bigint>;
getRequestExecuteTx(transaction: {
contractAddress: string;
calldata: string;
l2GasLimit?: BigNumberish | undefined;
l2Value?: BigNumberish | undefined;
factoryDeps?: BytesLike[] | undefined;
operatorTip?: BigNumberish | undefined;
gasPerPubdataByte?: BigNumberish | undefined;
refundRecipient?: string | undefined;
overrides?: ethers.Overrides | undefined;
}): Promise<ethers.TransactionRequest>;
sendTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionResponse>;
getAddress(): Promise<string>;
};
} & typeof ethers.VoidSigner;
/**
* A `L1VoidSigner` is an extension of {@link ethers.VoidSigner} class providing only L1 operations
*
* @see {@link L2VoidSigner} for L2 operations.
*/
export declare class L1VoidSigner extends L1VoidSigner_base {
providerL2?: Provider;
_providerL2(): Provider;
_providerL1(): ethers.Provider;
_signerL1(): this;
/**
* @param address The address of the account.
* @param providerL1 The provider instance for connecting to a L1 network.
* @param providerL2 The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L1VoidSigner, types } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const signer = new L1VoidSigner("<ADDRESS>", ethProvider, provider);
*/
constructor(address: string, providerL1?: ethers.Provider, providerL2?: Provider);
/**
* Connects to the L1 network using the `provider`.
*
* @param provider The provider instance for connecting to a L1 network.
*
* @example
*
* import { L1VoidSigner } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const ethProvider = ethers.getDefaultProvider("sepolia");
*
* let singer = new L1VoidSigner("<ADDRESS>);
* singer = singer.connect(ethProvider);
*/
connect(provider: ethers.Provider): L1VoidSigner;
/**
* Returns the balance of the account.
*
* @param [token] The token address to query balance for. Defaults to the native token.
* @param [blockTag='committed'] The block tag to get the balance at.
*
* @example
*
*
*/
getBalance(token?: Address, blockTag?: BlockTag): Promise<bigint>;
/**
* Connects to the L2 network using the `provider`.
*
* @param provider The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L1VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* let signer = new L1VoidSigner("<ADDRESS>");
* signer = signer.connectToL2(provider);
*/
connectToL2(provider: Provider): this;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.L1Signer = exports.Signer = exports.EIP712Signer = exports.EIP712_TYPES = void 0;
exports.L1VoidSigner = exports.L2VoidSigner = exports.L1Signer = exports.Signer = exports.EIP712Signer = exports.EIP712_TYPES = void 0;
const ethers_1 = require("ethers");

@@ -261,6 +261,4 @@ const utils_1 = require("./utils");

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = signer.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -284,6 +282,4 @@ * });

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = signer.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -917,2 +913,159 @@ * paymasterParams: utils.getPaymasterParams(paymaster, {

/* c8 ignore stop */
/**
* A `L2VoidSigner` is an extension of {@link ethers.VoidSigner} class providing only L2 operations
*
* @see {@link L1VoidSigner} for L1 operations.
*/
class L2VoidSigner extends (0, adapters_1.AdapterL2)(ethers_1.ethers.VoidSigner) {
_signerL2() {
return this;
}
_providerL2() {
return this.provider;
}
/**
* Connects to the L2 network using the `provider`.
*
* @param provider The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L2VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
*
* let signer = new L2VoidSigner("<ADDRESS>");
* signer = signer.connect(provider);
*/
connect(provider) {
return new L2VoidSigner(this.address, provider);
}
/**
* Designed for users who prefer a simplified approach by providing only the necessary data to create a valid transaction.
* The only required fields are `transaction.to` and either `transaction.data` or `transaction.value` (or both, if the method is payable).
* Any other fields that are not set will be prepared by this method.
*
* @param tx The transaction request that needs to be populated.
*
* @example
*
* import { Provider, L2VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const signer = new L2VoidSigner("<ADDRESS>", provider);
*
* const populatedTx = await signer.populateTransaction({
* to: Wallet.createRandom().address,
* value: 7_000_000n,
* maxFeePerGas: 3_500_000_000n,
* maxPriorityFeePerGas: 2_000_000_000n,
* customData: {
* gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
* factoryDeps: [],
* },
* });
*/
async populateTransaction(tx) {
if ((!tx.type || tx.type !== utils_1.EIP712_TX_TYPE) && !tx.customData) {
return (await super.populateTransaction(tx));
}
tx.type = utils_1.EIP712_TX_TYPE;
const populated = (await super.populateTransaction(tx));
populated.type = utils_1.EIP712_TX_TYPE;
populated.value ?? (populated.value = 0);
populated.data ?? (populated.data = '0x');
populated.customData = this._fillCustomData(tx.customData ?? {});
if (!populated.maxFeePerGas && !populated.maxPriorityFeePerGas) {
populated.gasPrice = await this.provider.getGasPrice();
}
return populated;
}
}
exports.L2VoidSigner = L2VoidSigner;
/**
* A `L1VoidSigner` is an extension of {@link ethers.VoidSigner} class providing only L1 operations
*
* @see {@link L2VoidSigner} for L2 operations.
*/
class L1VoidSigner extends (0, adapters_1.AdapterL1)(ethers_1.ethers.VoidSigner) {
_providerL2() {
if (!this.providerL2) {
throw new Error('L2 provider missing: use `connectToL2` to specify!');
}
return this.providerL2;
}
_providerL1() {
return this.provider;
}
_signerL1() {
return this;
}
/**
* @param address The address of the account.
* @param providerL1 The provider instance for connecting to a L1 network.
* @param providerL2 The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L1VoidSigner, types } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const signer = new L1VoidSigner("<ADDRESS>", ethProvider, provider);
*/
constructor(address, providerL1, providerL2) {
super(address, providerL1);
this.providerL2 = providerL2;
}
/**
* Connects to the L1 network using the `provider`.
*
* @param provider The provider instance for connecting to a L1 network.
*
* @example
*
* import { L1VoidSigner } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const ethProvider = ethers.getDefaultProvider("sepolia");
*
* let singer = new L1VoidSigner("<ADDRESS>);
* singer = singer.connect(ethProvider);
*/
connect(provider) {
return new L1VoidSigner(this.address, provider);
}
/**
* Returns the balance of the account.
*
* @param [token] The token address to query balance for. Defaults to the native token.
* @param [blockTag='committed'] The block tag to get the balance at.
*
* @example
*
*
*/
async getBalance(token, blockTag = 'committed') {
return await this._providerL2().getBalance(await this.getAddress(), blockTag, token);
}
/**
* Connects to the L2 network using the `provider`.
*
* @param provider The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L1VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* let signer = new L1VoidSigner("<ADDRESS>");
* signer = signer.connectToL2(provider);
*/
connectToL2(provider) {
this.providerL2 = provider;
return this;
}
}
exports.L1VoidSigner = L1VoidSigner;
//# sourceMappingURL=signer.js.map

@@ -851,6 +851,4 @@ import { EIP712Signer } from './signer';

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = await wallet.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -874,6 +872,4 @@ * });

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = await wallet.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -1025,2 +1021,19 @@ * paymasterParams: utils.getPaymasterParams(paymaster, {

* @param tx The transaction request that needs to be populated.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const populatedTx = await wallet.populateTransaction({
* type: utils.EIP712_TX_TYPE,
* to: RECEIVER,
* value: 7_000_000_000,
* });
*/

@@ -1034,2 +1047,19 @@ populateTransaction(tx: TransactionRequest): Promise<TransactionLike>;

* @throws {Error} If `transaction.from` is mismatched from the private key.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const tx = await wallet.signTransaction({
* type: utils.EIP712_TX_TYPE,
* to: Wallet.createRandom().address,
* value: ethers.parseEther('1'),
* });
*/

@@ -1043,2 +1073,24 @@ signTransaction(tx: TransactionRequest): Promise<string>;

* @throws {Error} If `transaction.from` is mismatched from the private key.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const tx = await wallet.sendTransaction({
* to: Wallet.createRandom().address,
* value: 7_000_000,
* maxFeePerGas: 3_500_000_000n,
* maxPriorityFeePerGas: 2_000_000_000n,
* customData: {
* gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
* },
* });
* await tx.wait();
*/

@@ -1045,0 +1097,0 @@ sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;

@@ -670,6 +670,4 @@ "use strict";

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = await wallet.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -693,6 +691,4 @@ * });

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = await wallet.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -862,2 +858,19 @@ * paymasterParams: utils.getPaymasterParams(paymaster, {

* @param tx The transaction request that needs to be populated.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const populatedTx = await wallet.populateTransaction({
* type: utils.EIP712_TX_TYPE,
* to: RECEIVER,
* value: 7_000_000_000,
* });
*/

@@ -885,2 +898,19 @@ async populateTransaction(tx) {

* @throws {Error} If `transaction.from` is mismatched from the private key.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const tx = await wallet.signTransaction({
* type: utils.EIP712_TX_TYPE,
* to: Wallet.createRandom().address,
* value: ethers.parseEther('1'),
* });
*/

@@ -901,2 +931,24 @@ async signTransaction(tx) {

* @throws {Error} If `transaction.from` is mismatched from the private key.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const tx = await wallet.sendTransaction({
* to: Wallet.createRandom().address,
* value: 7_000_000,
* maxFeePerGas: 3_500_000_000n,
* maxPriorityFeePerGas: 2_000_000_000n,
* customData: {
* gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
* },
* });
* await tx.wait();
*/

@@ -903,0 +955,0 @@ async sendTransaction(tx) {

@@ -670,2 +670,36 @@ "use strict";

}).timeout(10000);
it('should estimate a fee for ETH when `from` is used in overrides', async () => {
const feeData = {
baseCost: 311192000000000n,
l1GasLimit: 135759n,
l2GasLimit: '0x97f30',
maxFeePerGas: 1500000010n,
maxPriorityFeePerGas: 1500000000n,
};
const randomWallet = new src_1.Wallet(ethers_1.ethers.Wallet.createRandom().privateKey, provider, ethProvider);
const result = await randomWallet.getFullRequiredDepositFee({
token: src_1.utils.ETH_ADDRESS,
to: await wallet.getAddress(),
overrides: { from: ADDRESS },
});
expect(result).to.be.deepEqualExcluding(feeData, ['l1GasLimit']);
}).timeout(10000);
it('should estimate a fee for DAI when `from` is used in overrides', async () => {
const feeData = {
baseCost: 288992000000000n,
l1GasLimit: 253177n,
l2GasLimit: '0x8d1c0',
maxFeePerGas: 1500000010n,
maxPriorityFeePerGas: 1500000000n,
};
const randomWallet = new src_1.Wallet(ethers_1.ethers.Wallet.createRandom().privateKey, provider, ethProvider);
const tx = await wallet.approveERC20(DAI_L1, 5);
await tx.wait();
const result = await randomWallet.getFullRequiredDepositFee({
token: DAI_L1,
to: await wallet.getAddress(),
overrides: { from: ADDRESS },
});
expect(result).to.be.deep.equal(feeData);
}).timeout(10000);
});

@@ -672,0 +706,0 @@ describe('#withdraw()', () => {

{
"name": "zksync-ethers",
"version": "6.4.0",
"version": "6.5.0",
"main": "build/src/index.js",

@@ -5,0 +5,0 @@ "types": "build/src/index.d.ts",

@@ -579,4 +579,4 @@ import {

let l2GasLimit: bigint;
const bridgeContracts = await this.getL1BridgeContracts();
if (tx.bridgeAddress) {
const bridgeContracts = await this.getL1BridgeContracts();
const customBridgeData =

@@ -621,3 +621,5 @@ tx.customBridgeData ??

const selfBalanceETH = await this.getBalanceL1();
const selfBalanceETH = tx.overrides.from
? await this._providerL1().getBalance(tx.overrides.from)
: await this.getBalanceL1();

@@ -649,4 +651,16 @@ // We could zero in, because the final fee will anyway be bigger than

amountForEstimate = dummyAmount;
if ((await this.getAllowanceL1(tx.token)) < amountForEstimate) {
let allowance: bigint;
if (tx.overrides.from) {
const erc20contract = IERC20__factory.connect(
tx.token,
this._providerL1()
);
allowance = await erc20contract.allowance(
tx.overrides.from,
await bridgeContracts.erc20.getAddress()
);
} else {
allowance = await this.getAllowanceL1(tx.token);
}
if (allowance < amountForEstimate) {
throw new Error('Not enough allowance to cover the deposit!');

@@ -653,0 +667,0 @@ }

export * as utils from './utils';
export * as types from './types';
export {EIP712Signer, Signer, L1Signer} from './signer';
export {
EIP712Signer,
Signer,
L1Signer,
L2VoidSigner,
L1VoidSigner,
} from './signer';
export {Wallet} from './wallet';
export {BrowserProvider, Provider} from './provider';
export {ContractFactory, Contract} from './contract';

@@ -332,6 +332,4 @@ import {

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = signer.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -355,6 +353,4 @@ * });

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = signer.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -1136,1 +1132,186 @@ * paymasterParams: utils.getPaymasterParams(paymaster, {

/* c8 ignore stop */
/**
* A `L2VoidSigner` is an extension of {@link ethers.VoidSigner} class providing only L2 operations
*
* @see {@link L1VoidSigner} for L1 operations.
*/
export class L2VoidSigner extends AdapterL2(ethers.VoidSigner) {
public override provider!: Provider;
override _signerL2() {
return this;
}
override _providerL2(): Provider {
return this.provider;
}
/**
* Connects to the L2 network using the `provider`.
*
* @param provider The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L2VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
*
* let signer = new L2VoidSigner("<ADDRESS>");
* signer = signer.connect(provider);
*/
override connect(provider: Provider): L2VoidSigner {
return new L2VoidSigner(this.address, provider);
}
/**
* Designed for users who prefer a simplified approach by providing only the necessary data to create a valid transaction.
* The only required fields are `transaction.to` and either `transaction.data` or `transaction.value` (or both, if the method is payable).
* Any other fields that are not set will be prepared by this method.
*
* @param tx The transaction request that needs to be populated.
*
* @example
*
* import { Provider, L2VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const signer = new L2VoidSigner("<ADDRESS>", provider);
*
* const populatedTx = await signer.populateTransaction({
* to: Wallet.createRandom().address,
* value: 7_000_000n,
* maxFeePerGas: 3_500_000_000n,
* maxPriorityFeePerGas: 2_000_000_000n,
* customData: {
* gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
* factoryDeps: [],
* },
* });
*/
override async populateTransaction(
tx: TransactionRequest
): Promise<TransactionLike> {
if ((!tx.type || tx.type !== EIP712_TX_TYPE) && !tx.customData) {
return (await super.populateTransaction(tx)) as TransactionLike;
}
tx.type = EIP712_TX_TYPE;
const populated = (await super.populateTransaction(tx)) as TransactionLike;
populated.type = EIP712_TX_TYPE;
populated.value ??= 0;
populated.data ??= '0x';
populated.customData = this._fillCustomData(tx.customData ?? {});
if (!populated.maxFeePerGas && !populated.maxPriorityFeePerGas) {
populated.gasPrice = await this.provider.getGasPrice();
}
return populated;
}
}
/**
* A `L1VoidSigner` is an extension of {@link ethers.VoidSigner} class providing only L1 operations
*
* @see {@link L2VoidSigner} for L2 operations.
*/
export class L1VoidSigner extends AdapterL1(ethers.VoidSigner) {
public providerL2?: Provider;
override _providerL2(): Provider {
if (!this.providerL2) {
throw new Error('L2 provider missing: use `connectToL2` to specify!');
}
return this.providerL2;
}
override _providerL1(): ethers.Provider {
return this.provider as ethers.Provider;
}
override _signerL1() {
return this;
}
/**
* @param address The address of the account.
* @param providerL1 The provider instance for connecting to a L1 network.
* @param providerL2 The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L1VoidSigner, types } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const signer = new L1VoidSigner("<ADDRESS>", ethProvider, provider);
*/
constructor(
address: string,
providerL1?: ethers.Provider,
providerL2?: Provider
) {
super(address, providerL1);
this.providerL2 = providerL2;
}
/**
* Connects to the L1 network using the `provider`.
*
* @param provider The provider instance for connecting to a L1 network.
*
* @example
*
* import { L1VoidSigner } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const ethProvider = ethers.getDefaultProvider("sepolia");
*
* let singer = new L1VoidSigner("<ADDRESS>);
* singer = singer.connect(ethProvider);
*/
override connect(provider: ethers.Provider): L1VoidSigner {
return new L1VoidSigner(this.address, provider);
}
/**
* Returns the balance of the account.
*
* @param [token] The token address to query balance for. Defaults to the native token.
* @param [blockTag='committed'] The block tag to get the balance at.
*
* @example
*
*
*/
async getBalance(
token?: Address,
blockTag: BlockTag = 'committed'
): Promise<bigint> {
return await this._providerL2().getBalance(
await this.getAddress(),
blockTag,
token
);
}
/**
* Connects to the L2 network using the `provider`.
*
* @param provider The provider instance for connecting to a L2 network.
*
* @example
*
* import { Provider, L1VoidSigner, types } from "zksync-ethers";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* let signer = new L1VoidSigner("<ADDRESS>");
* signer = signer.connectToL2(provider);
*/
connectToL2(provider: Provider): this {
this.providerL2 = provider;
return this;
}
}

@@ -838,6 +838,4 @@ import {EIP712Signer} from './signer';

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = await wallet.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -861,6 +859,4 @@ * });

*
* const recipient = Wallet.createRandom();
*
* const transferHandle = await wallet.transfer({
* to: recipient.address,
* to: Wallet.createRandom().address,
* amount: ethers.parseEther("0.01"),

@@ -1062,2 +1058,19 @@ * paymasterParams: utils.getPaymasterParams(paymaster, {

* @param tx The transaction request that needs to be populated.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const populatedTx = await wallet.populateTransaction({
* type: utils.EIP712_TX_TYPE,
* to: RECEIVER,
* value: 7_000_000_000,
* });
*/

@@ -1090,2 +1103,19 @@ override async populateTransaction(

* @throws {Error} If `transaction.from` is mismatched from the private key.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const tx = await wallet.signTransaction({
* type: utils.EIP712_TX_TYPE,
* to: Wallet.createRandom().address,
* value: ethers.parseEther('1'),
* });
*/

@@ -1108,2 +1138,24 @@ override async signTransaction(tx: TransactionRequest): Promise<string> {

* @throws {Error} If `transaction.from` is mismatched from the private key.
*
* @example
*
* import { Wallet, Provider, utils } from "zksync-ethers";
* import { ethers } from "ethers";
*
* const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
*
* const provider = Provider.getDefaultProvider(types.Network.Sepolia);
* const ethProvider = ethers.getDefaultProvider("sepolia");
* const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
*
* const tx = await wallet.sendTransaction({
* to: Wallet.createRandom().address,
* value: 7_000_000,
* maxFeePerGas: 3_500_000_000n,
* maxPriorityFeePerGas: 2_000_000_000n,
* customData: {
* gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
* },
* });
* await tx.wait();
*/

@@ -1110,0 +1162,0 @@ override async sendTransaction(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc