zksync-web3
Advanced tools
Comparing version 0.7.3 to 0.7.4
@@ -66,2 +66,16 @@ import { BigNumber, BigNumberish, ethers, BytesLike } from 'ethers'; | ||
_fillCustomData(data: Eip712Meta): Eip712Meta; | ||
getWithdrawTx(transaction: { | ||
token: Address; | ||
amount: BigNumberish; | ||
to?: Address; | ||
bridgeAddress?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.providers.TransactionRequest>; | ||
estimateGasWithdraw(transaction: { | ||
token: Address; | ||
amount: BigNumberish; | ||
to?: Address; | ||
bridgeAddress?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<BigNumber>; | ||
withdraw(transaction: { | ||
@@ -74,3 +88,3 @@ token: Address; | ||
}): Promise<TransactionResponse>; | ||
transfer(tx: { | ||
getTransferTx(tx: { | ||
to: Address; | ||
@@ -80,2 +94,14 @@ amount: BigNumberish; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.providers.TransactionRequest>; | ||
estimateGasTransfer(transaction: { | ||
to: Address; | ||
amount: BigNumberish; | ||
token?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<BigNumber>; | ||
transfer(transaction: { | ||
to: Address; | ||
amount: BigNumberish; | ||
token?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse>; | ||
@@ -82,0 +108,0 @@ sendTransaction(tx: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionResponse>; |
@@ -83,3 +83,3 @@ "use strict"; | ||
async deposit(transaction) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
const bridgeContracts = await this.getL1BridgeContracts(); | ||
@@ -97,3 +97,3 @@ if (transaction.bridgeAddress) { | ||
(_e = overrides.gasPrice) !== null && _e !== void 0 ? _e : (overrides.gasPrice = await this._providerL1().getGasPrice()); | ||
(_f = overrides.gasLimit) !== null && _f !== void 0 ? _f : (overrides.gasLimit = ethers_1.BigNumber.from(utils_1.RECOMMENDED_GAS_LIMIT.ETH_DEPOSIT)); | ||
(_f = overrides.gasLimit) !== null && _f !== void 0 ? _f : (overrides.gasLimit = ethers_1.BigNumber.from(utils_1.RECOMMENDED_GAS_LIMIT.DEPOSIT)); | ||
const baseCost = ethers_1.BigNumber.from(0); | ||
@@ -128,3 +128,3 @@ // TODO | ||
.catch(() => ethers_1.BigNumber.from(0)); | ||
const recommendedGasLimit = (_k = utils_1.RECOMMENDED_GAS_LIMIT.ERC20_DEPOSIT[token]) !== null && _k !== void 0 ? _k : utils_1.RECOMMENDED_GAS_LIMIT.ERC20_DEFAULT_DEPOSIT; | ||
const recommendedGasLimit = utils_1.RECOMMENDED_GAS_LIMIT.DEPOSIT; | ||
overrides.gasLimit = gasEstimate.gte(recommendedGasLimit) ? gasEstimate : recommendedGasLimit; | ||
@@ -199,3 +199,3 @@ } | ||
} | ||
async withdraw(transaction) { | ||
async getWithdrawTx(transaction) { | ||
var _a, _b; | ||
@@ -210,22 +210,37 @@ const { ...tx } = transaction; | ||
const bridge = typechain_1.IL2BridgeFactory.connect(tx.bridgeAddress, this._signerL2()); | ||
const txResponse = await bridge.withdraw(tx.to, tx.token, tx.amount, tx.overrides); | ||
return bridge.populateTransaction.withdraw(tx.to, tx.token, tx.amount, tx.overrides); | ||
} | ||
async estimateGasWithdraw(transaction) { | ||
const withdrawTx = await this.getWithdrawTx(transaction); | ||
return await this._providerL2().estimateGas(withdrawTx); | ||
} | ||
async withdraw(transaction) { | ||
const withdrawTx = await this.getWithdrawTx(transaction); | ||
const txResponse = await this.sendTransaction(withdrawTx); | ||
return this._providerL2()._wrapTransaction(txResponse); | ||
} | ||
async transfer(tx) { | ||
let response; | ||
async getTransferTx(tx) { | ||
if (tx.token == null || tx.token == utils_1.ETH_ADDRESS) { | ||
response = await this.sendTransaction({ | ||
return { | ||
...(await ethers_1.ethers.utils.resolveProperties(tx.overrides)), | ||
to: tx.to, | ||
value: tx.amount | ||
}); | ||
}; | ||
} | ||
else { | ||
const token = typechain_1.IERC20Factory.connect(tx.token, this._signerL2()); | ||
response = await token.transfer(tx.to, tx.amount, tx.overrides); | ||
return await token.populateTransaction.transfer(tx.to, tx.amount, tx.overrides); | ||
} | ||
return this._providerL2()._wrapTransaction(response); | ||
} | ||
async estimateGasTransfer(transaction) { | ||
const withdrawTx = await this.getTransferTx(transaction); | ||
return await this._providerL2().estimateGas(withdrawTx); | ||
} | ||
async transfer(transaction) { | ||
const withdrawTx = await this.getTransferTx(transaction); | ||
const txResponse = await this.sendTransaction(withdrawTx); | ||
return this._providerL2()._wrapTransaction(txResponse); | ||
} | ||
}; | ||
} | ||
exports.AdapterL2 = AdapterL2; |
@@ -40,2 +40,16 @@ import { ethers } from 'ethers'; | ||
_fillCustomData(data: import("./types").Eip712Meta): import("./types").Eip712Meta; | ||
getWithdrawTx(transaction: { | ||
token: string; | ||
amount: ethers.BigNumberish; | ||
to?: string; | ||
bridgeAddress?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.providers.TransactionRequest>; | ||
estimateGasWithdraw(transaction: { | ||
token: string; | ||
amount: ethers.BigNumberish; | ||
to?: string; | ||
bridgeAddress?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.BigNumber>; | ||
withdraw(transaction: { | ||
@@ -48,3 +62,3 @@ token: string; | ||
}): Promise<TransactionResponse>; | ||
transfer(tx: { | ||
getTransferTx(tx: { | ||
to: string; | ||
@@ -54,2 +68,14 @@ amount: ethers.BigNumberish; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.providers.TransactionRequest>; | ||
estimateGasTransfer(transaction: { | ||
to: string; | ||
amount: ethers.BigNumberish; | ||
token?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.BigNumber>; | ||
transfer(transaction: { | ||
to: string; | ||
amount: ethers.BigNumberish; | ||
token?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse>; | ||
@@ -56,0 +82,0 @@ sendTransaction(tx: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionResponse>; |
@@ -16,10 +16,4 @@ import { utils, ethers, BytesLike } from 'ethers'; | ||
export declare const RECOMMENDED_GAS_LIMIT: { | ||
ETH_DEPOSIT: number; | ||
ERC20_DEPOSIT: any; | ||
ERC20_DEFAULT_DEPOSIT: number; | ||
WITHDRAW: number; | ||
DEPOSIT: number; | ||
EXECUTE: number; | ||
DEPLOY_CONTRACT: number; | ||
ADD_TOKEN: number; | ||
TRANSFER: number; | ||
ERC20_APPROVE: number; | ||
@@ -26,0 +20,0 @@ }; |
@@ -18,11 +18,5 @@ "use strict"; | ||
exports.RECOMMENDED_GAS_LIMIT = { | ||
ETH_DEPOSIT: 600000, | ||
ERC20_DEPOSIT: require('../../misc/DepositERC20GasLimits.json'), | ||
ERC20_DEFAULT_DEPOSIT: 600000, | ||
WITHDRAW: 620000, | ||
// TODO: make better estimates | ||
DEPOSIT: 600000, | ||
EXECUTE: 620000, | ||
DEPLOY_CONTRACT: 720000, | ||
// TODO: Estimate these values. | ||
ADD_TOKEN: 300000, | ||
TRANSFER: 300000, | ||
ERC20_APPROVE: 50000 | ||
@@ -29,0 +23,0 @@ }; |
@@ -17,2 +17,16 @@ import { EIP712Signer } from './signer'; | ||
_fillCustomData(data: import("./types").Eip712Meta): import("./types").Eip712Meta; | ||
getWithdrawTx(transaction: { | ||
token: string; | ||
amount: ethers.BigNumberish; | ||
to?: string; | ||
bridgeAddress?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.providers.TransactionRequest>; | ||
estimateGasWithdraw(transaction: { | ||
token: string; | ||
amount: ethers.BigNumberish; | ||
to?: string; | ||
bridgeAddress?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.BigNumber>; | ||
withdraw(transaction: { | ||
@@ -25,3 +39,3 @@ token: string; | ||
}): Promise<TransactionResponse>; | ||
transfer(tx: { | ||
getTransferTx(tx: { | ||
to: string; | ||
@@ -31,2 +45,14 @@ amount: ethers.BigNumberish; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.providers.TransactionRequest>; | ||
estimateGasTransfer(transaction: { | ||
to: string; | ||
amount: ethers.BigNumberish; | ||
token?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<ethers.BigNumber>; | ||
transfer(transaction: { | ||
to: string; | ||
amount: ethers.BigNumberish; | ||
token?: string; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse>; | ||
@@ -33,0 +59,0 @@ sendTransaction(tx: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionResponse>; |
{ | ||
"name": "zksync-web3", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"main": "build/src/index.js", | ||
@@ -9,3 +9,2 @@ "types": "build/src/index.d.ts", | ||
"abi/", | ||
"misc/", | ||
"src/", | ||
@@ -12,0 +11,0 @@ "typechain/" |
@@ -143,3 +143,3 @@ import { BigNumber, BigNumberish, ethers, BytesLike } from 'ethers'; | ||
overrides.gasPrice ??= await this._providerL1().getGasPrice(); | ||
overrides.gasLimit ??= BigNumber.from(RECOMMENDED_GAS_LIMIT.ETH_DEPOSIT); | ||
overrides.gasLimit ??= BigNumber.from(RECOMMENDED_GAS_LIMIT.DEPOSIT); | ||
@@ -181,4 +181,3 @@ const baseCost = BigNumber.from(0); | ||
.catch(() => BigNumber.from(0)); | ||
const recommendedGasLimit = | ||
RECOMMENDED_GAS_LIMIT.ERC20_DEPOSIT[token] ?? RECOMMENDED_GAS_LIMIT.ERC20_DEFAULT_DEPOSIT; | ||
const recommendedGasLimit = RECOMMENDED_GAS_LIMIT.DEPOSIT; | ||
overrides.gasLimit = gasEstimate.gte(recommendedGasLimit) ? gasEstimate : recommendedGasLimit; | ||
@@ -288,3 +287,3 @@ } | ||
async withdraw(transaction: { | ||
async getWithdrawTx(transaction: { | ||
token: Address; | ||
@@ -295,3 +294,3 @@ amount: BigNumberish; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse> { | ||
}): Promise<ethers.providers.TransactionRequest> { | ||
const { ...tx } = transaction; | ||
@@ -307,7 +306,29 @@ tx.to ??= await this.getAddress(); | ||
const bridge = IL2BridgeFactory.connect(tx.bridgeAddress!, this._signerL2()); | ||
const txResponse = await bridge.withdraw(tx.to, tx.token, tx.amount, tx.overrides); | ||
return bridge.populateTransaction.withdraw(tx.to, tx.token, tx.amount, tx.overrides); | ||
} | ||
async estimateGasWithdraw(transaction: { | ||
token: Address; | ||
amount: BigNumberish; | ||
to?: Address; | ||
bridgeAddress?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<BigNumber> { | ||
const withdrawTx = await this.getWithdrawTx(transaction); | ||
return await this._providerL2().estimateGas(withdrawTx); | ||
} | ||
async withdraw(transaction: { | ||
token: Address; | ||
amount: BigNumberish; | ||
to?: Address; | ||
bridgeAddress?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse> { | ||
const withdrawTx = await this.getWithdrawTx(transaction); | ||
const txResponse = await this.sendTransaction(withdrawTx); | ||
return this._providerL2()._wrapTransaction(txResponse); | ||
} | ||
async transfer(tx: { | ||
async getTransferTx(tx: { | ||
to: Address; | ||
@@ -317,17 +338,36 @@ amount: BigNumberish; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse> { | ||
let response: ethers.providers.TransactionResponse; | ||
}): Promise<ethers.providers.TransactionRequest> { | ||
if (tx.token == null || tx.token == ETH_ADDRESS) { | ||
response = await this.sendTransaction({ | ||
return { | ||
...(await ethers.utils.resolveProperties(tx.overrides)), | ||
to: tx.to, | ||
value: tx.amount | ||
}); | ||
}; | ||
} else { | ||
const token = IERC20Factory.connect(tx.token, this._signerL2()); | ||
response = await token.transfer(tx.to, tx.amount, tx.overrides); | ||
return await token.populateTransaction.transfer(tx.to, tx.amount, tx.overrides); | ||
} | ||
return this._providerL2()._wrapTransaction(response); | ||
} | ||
async estimateGasTransfer(transaction: { | ||
to: Address; | ||
amount: BigNumberish; | ||
token?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<BigNumber> { | ||
const withdrawTx = await this.getTransferTx(transaction); | ||
return await this._providerL2().estimateGas(withdrawTx); | ||
} | ||
async transfer(transaction: { | ||
to: Address; | ||
amount: BigNumberish; | ||
token?: Address; | ||
overrides?: ethers.CallOverrides; | ||
}): Promise<TransactionResponse> { | ||
const withdrawTx = await this.getTransferTx(transaction); | ||
const txResponse = await this.sendTransaction(withdrawTx); | ||
return this._providerL2()._wrapTransaction(txResponse); | ||
} | ||
}; | ||
} |
@@ -22,11 +22,5 @@ import { utils, ethers, BigNumber, BigNumberish, BytesLike } from 'ethers'; | ||
export const RECOMMENDED_GAS_LIMIT = { | ||
ETH_DEPOSIT: 600_000, | ||
ERC20_DEPOSIT: require('../../misc/DepositERC20GasLimits.json'), | ||
ERC20_DEFAULT_DEPOSIT: 600_000, | ||
WITHDRAW: 620_000, | ||
// TODO: make better estimates | ||
DEPOSIT: 600_000, | ||
EXECUTE: 620_000, | ||
DEPLOY_CONTRACT: 720_000, | ||
// TODO: Estimate these values. | ||
ADD_TOKEN: 300_000, | ||
TRANSFER: 300_000, | ||
ERC20_APPROVE: 50_000 | ||
@@ -33,0 +27,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
416351
13225
53