import { BigNumber } from 'ethers' ; import { transactionType , Configuration , Network } from '../types' ; const DEFAULT_SURPLUS = 30 ; const POLYGON_SURPLUS = 60 ; export const estimateGas = async ( tx , config , gasSurplus ? ) : Promise < BigNumber > => { const estimatedGas = await config . provider . estimateGas ( tx ) ; return estimatedGas . add ( estimatedGas . mul ( gasSurplus || DEFAULT_SURPLUS ) . div ( 100 ) ) ; } ; export const estimateGasByNetwork = async ( tx , config , gasSurplus ? ) : Promise < BigNumber > => { const estimatedGas = await config . provider . estimateGas ( tx ) ; const { network } = config ; if ( network === Network . polygon ) { return estimatedGas . add ( estimatedGas . mul ( POLYGON_SURPLUS ) . div ( 100 ) ) ; } return estimatedGas . add ( estimatedGas . mul ( gasSurplus || DEFAULT_SURPLUS ) . div ( 100 ) ) ; } ; export const getGasPrice = async ( config ) : Promise < BigNumber > => { const gasPrice = await config . provider . getGasPrice ( ) ; return gasPrice ; } ;