Compare commits
2 Commits
583f3e90dd
...
342c34b07a
Author | SHA1 | Date | |
---|---|---|---|
342c34b07a | |||
57c24e21eb |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tornado/tornado-oracles",
|
||||
"version": "1.3.2",
|
||||
"version": "1.4.0",
|
||||
"description": "Gas oracle for Tornado-specific transactions",
|
||||
"main": "./lib/index.js",
|
||||
"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)
|
||||
* @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 {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)
|
||||
* @returns {Promise<GetGasParamsRes>} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee'
|
||||
*/
|
||||
async getGasParams(
|
||||
tx?: TransactionData,
|
||||
txType: TxType = 'other',
|
||||
bumpGasLimitPercent?: number,
|
||||
bumpGasPricePercent?: number,
|
||||
speed: LegacyGasPriceKey = 'fast',
|
||||
): Promise<GetGasParamsRes> {
|
||||
const [gasPrice, gasLimit, l1Fee] = await Promise.all([
|
||||
this.getGasPrice(txType, speed),
|
||||
this.getGasLimit(tx, txType),
|
||||
this.getGasPrice(txType, speed, bumpGasPricePercent),
|
||||
this.getGasLimit(tx, txType, bumpGasLimitPercent),
|
||||
this.fetchL1OptimismFee(tx),
|
||||
]);
|
||||
|
||||
@ -67,15 +71,25 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
||||
* Estimates next block gas for signed, unsigned or incomplete Tornado transaction
|
||||
* @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 {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)
|
||||
* @returns {Promise<HexadecimalStringifiedNumber>} Gas value in WEI (hex-format)
|
||||
*/
|
||||
async getGas(
|
||||
tx?: TransactionData,
|
||||
txType: TxType = 'other',
|
||||
bumpGasLimitPercent?: number,
|
||||
bumpGasPricePercent?: number,
|
||||
speed: LegacyGasPriceKey = 'fast',
|
||||
): 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);
|
||||
|
||||
return gas.toHexString();
|
||||
@ -84,8 +98,8 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
||||
/**
|
||||
* Estimate next block gas price
|
||||
* @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 {number} bumpPercent Gas bump percent to prioritize transaction
|
||||
* @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
|
||||
* @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
|
||||
* EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties
|
||||
*/
|
||||
@ -111,7 +125,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
||||
async getGasPrice(
|
||||
type: TxType = 'other',
|
||||
speed: LegacyGasPriceKey = 'fast',
|
||||
bumpPercent: number = 0,
|
||||
bumpPercent?: number,
|
||||
): Promise<HexadecimalStringifiedNumber> {
|
||||
const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent);
|
||||
return calculateGasPriceInWei(gasPriceParams).toHexString();
|
||||
|
16
src/types.ts
16
src/types.ts
@ -35,8 +35,20 @@ export interface TransactionData {
|
||||
}
|
||||
|
||||
export interface ITornadoFeeOracle {
|
||||
getGasParams: (tx?: TransactionData, txType?: TxType, speed?: LegacyGasPriceKey) => Promise<GetGasParamsRes>;
|
||||
getGas: (tx?: TransactionData, type?: TxType) => Promise<HexadecimalStringifiedNumber>;
|
||||
getGasParams: (
|
||||
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>;
|
||||
getGasPrice: (
|
||||
type?: TxType,
|
||||
|
Loading…
Reference in New Issue
Block a user