Compare commits

..

2 Commits

3 changed files with 35 additions and 9 deletions

@ -1,6 +1,6 @@
{ {
"name": "@tornado/tornado-oracles", "name": "@tornado/tornado-oracles",
"version": "1.3.2", "version": "1.4.0",
"description": "Gas oracle for Tornado-specific transactions", "description": "Gas oracle for Tornado-specific transactions",
"main": "./lib/index.js", "main": "./lib/index.js",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",

@ -46,17 +46,21 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
* Estimate gas price, gas limit and l1Fee for sidechain (if exists) * Estimate gas price, gas limit and l1Fee for sidechain (if exists)
* @param {TransactionData} [tx] Transaction data in web3 / ethers format * @param {TransactionData} [tx] Transaction data in web3 / ethers format
* @param {TxType} [txType=other] Tornado transaction type: withdrawal by user, withdrawal by relayer or 'other' * @param {TxType} [txType=other] Tornado transaction type: withdrawal by user, withdrawal by relayer or 'other'
* @param {number} [bumpGasLimitPercent] Gas limit bump percent to prioritize transaction (recenlty used)
* @param {number} [bumpGasPricePercent] Gas price bump percent to prioritize transaction (rarely used)
* @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559) * @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
* @returns {Promise<GetGasParamsRes>} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee' * @returns {Promise<GetGasParamsRes>} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee'
*/ */
async getGasParams( async getGasParams(
tx?: TransactionData, tx?: TransactionData,
txType: TxType = 'other', txType: TxType = 'other',
bumpGasLimitPercent?: number,
bumpGasPricePercent?: number,
speed: LegacyGasPriceKey = 'fast', speed: LegacyGasPriceKey = 'fast',
): Promise<GetGasParamsRes> { ): Promise<GetGasParamsRes> {
const [gasPrice, gasLimit, l1Fee] = await Promise.all([ const [gasPrice, gasLimit, l1Fee] = await Promise.all([
this.getGasPrice(txType, speed), this.getGasPrice(txType, speed, bumpGasPricePercent),
this.getGasLimit(tx, txType), this.getGasLimit(tx, txType, bumpGasLimitPercent),
this.fetchL1OptimismFee(tx), this.fetchL1OptimismFee(tx),
]); ]);
@ -67,15 +71,25 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
* Estimates next block gas for signed, unsigned or incomplete Tornado transaction * Estimates next block gas for signed, unsigned or incomplete Tornado transaction
* @param {TransactionData} [tx] Transaction data in web3 / ethers format * @param {TransactionData} [tx] Transaction data in web3 / ethers format
* @param {TxType} [txType=other] Tornado transaction type: withdrawal by user, withdrawal by relayer or 'other' * @param {TxType} [txType=other] Tornado transaction type: withdrawal by user, withdrawal by relayer or 'other'
* @param {number} [bumpGasLimitPercent] Gas limit bump percent to prioritize transaction (recenlty used)
* @param {number} [bumpGasPricePercent] Gas price bump percent to prioritize transaction (rarely used)
* @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559) * @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
* @returns {Promise<HexadecimalStringifiedNumber>} Gas value in WEI (hex-format) * @returns {Promise<HexadecimalStringifiedNumber>} Gas value in WEI (hex-format)
*/ */
async getGas( async getGas(
tx?: TransactionData, tx?: TransactionData,
txType: TxType = 'other', txType: TxType = 'other',
bumpGasLimitPercent?: number,
bumpGasPricePercent?: number,
speed: LegacyGasPriceKey = 'fast', speed: LegacyGasPriceKey = 'fast',
): Promise<HexadecimalStringifiedNumber> { ): Promise<HexadecimalStringifiedNumber> {
const { gasPrice, gasLimit, l1Fee } = await this.getGasParams(tx, txType, speed); const { gasPrice, gasLimit, l1Fee } = await this.getGasParams(
tx,
txType,
bumpGasLimitPercent,
bumpGasPricePercent,
speed,
);
const gas = BigNumber.from(gasPrice).mul(gasLimit).add(l1Fee); const gas = BigNumber.from(gasPrice).mul(gasLimit).add(l1Fee);
return gas.toHexString(); return gas.toHexString();
@ -84,8 +98,8 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
/** /**
* Estimate next block gas price * Estimate next block gas price
* @param {TxType} type Tornado transaction type (to select correct default bump percent) * @param {TxType} type Tornado transaction type (to select correct default bump percent)
* @param {LegacyGasPriceKey} speed Preferred transaction speed, if uses legacy gas (before EIP-1559) * @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
* @param {number} bumpPercent Gas bump percent to prioritize transaction * @param {number} [bumpPercent=0] Gas bump percent to prioritize transaction
* @returns {Promise<GasPriceParams>} Estimated gas price info in WEI (hexed) - legacy object with gasPrice property or * @returns {Promise<GasPriceParams>} Estimated gas price info in WEI (hexed) - legacy object with gasPrice property or
* EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties * EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties
*/ */
@ -111,7 +125,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
async getGasPrice( async getGasPrice(
type: TxType = 'other', type: TxType = 'other',
speed: LegacyGasPriceKey = 'fast', speed: LegacyGasPriceKey = 'fast',
bumpPercent: number = 0, bumpPercent?: number,
): Promise<HexadecimalStringifiedNumber> { ): Promise<HexadecimalStringifiedNumber> {
const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent); const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent);
return calculateGasPriceInWei(gasPriceParams).toHexString(); return calculateGasPriceInWei(gasPriceParams).toHexString();

@ -35,8 +35,20 @@ export interface TransactionData {
} }
export interface ITornadoFeeOracle { export interface ITornadoFeeOracle {
getGasParams: (tx?: TransactionData, txType?: TxType, speed?: LegacyGasPriceKey) => Promise<GetGasParamsRes>; getGasParams: (
getGas: (tx?: TransactionData, type?: TxType) => Promise<HexadecimalStringifiedNumber>; tx?: TransactionData,
txType?: TxType,
bumpGasLimitPercent?: number,
bumpGasPricePercent?: number,
speed?: LegacyGasPriceKey,
) => Promise<GetGasParamsRes>;
getGas: (
tx?: TransactionData,
type?: TxType,
bumpGasLimitPercent?: number,
bumpGasPricePercent?: number,
speed?: LegacyGasPriceKey,
) => Promise<HexadecimalStringifiedNumber>;
getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>; getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>;
getGasPrice: ( getGasPrice: (
type?: TxType, type?: TxType,