Set function to get optimism l1 fee as public & bump version to 1.1.0

This commit is contained in:
Theo 2023-08-22 11:23:25 -07:00
parent 3c1352ea41
commit 40bf17177b
4 changed files with 10 additions and 11 deletions

1
.gitignore vendored

@ -91,3 +91,4 @@ sw.*
*.swp
test
TODO

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

@ -23,14 +23,15 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
* Because Optimism transaction published on Mainnet, for each OP transaction we need to calculate L1 security fee:
* https://community.optimism.io/docs/developers/build/transaction-fees/#priority-fee
* @param {TransactionData} tx Transaction data to estimate L1 additional fee
* @returns Fee in WEI (MATIC)
* @returns {Promise<string>} Fee in WEI (MATIC)
*/
private async fetchL1OptimismFee(tx?: TransactionData): Promise<BigNumber> {
if (this.chainId != ChainId.OPTIMISM) return BigNumber.from(0);
async fetchL1OptimismFee(tx?: TransactionData): Promise<string> {
if (this.chainId != ChainId.OPTIMISM) return BigNumber.from(0).toHexString();
const optimismL1FeeOracle = getOptimismL1FeeOracle(this.provider);
const l1Fee = await optimismL1FeeOracle.getL1Fee(serializeTx(tx));
return await optimismL1FeeOracle.getL1Fee(serializeTx(tx));
return l1Fee.toHexString();
}
/**
@ -40,11 +41,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
* @param {LegacyGasPriceKey} speed Preferred transaction speed, if uses legacy gas (before EIP-1559)
* @returns {Promise<string>} Gas value in WEI (hex-format)
*/
public async getGas(
tx?: TransactionData,
txType: TxType = 'other',
speed: LegacyGasPriceKey = 'fast',
): Promise<string> {
async getGas(tx?: TransactionData, txType: TxType = 'other', speed: LegacyGasPriceKey = 'fast'): Promise<string> {
const gasPrice = await this.getGasPrice(txType, speed);
let gas = BigNumber.from(0);
gas = gas.add(gasPrice);

@ -35,6 +35,7 @@ export interface ITornadoFeeOracle {
getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>;
getGasPrice: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<string>;
getGasLimit: (tx?: TransactionData, type?: TxType, bumpPercent?: number) => Promise<number>;
fetchL1OptimismFee: (tx?: TransactionData) => Promise<string>;
calculateRefundInETH: (tx?: TransactionData) => Promise<string>;
calculateRefundInToken: (
tokenPriceInEth: BigNumberish,