import { BigNumber as EthersBigNumber } from '@ethersproject/bignumber' ; import { TransactionRequest } from '@ethersproject/providers' ; import { formatEther } from '@ethersproject/units' ; import BigNumber from 'bignumber.js' ; import { addHexPrefix } from 'ethereumjs-util' ; import { DEFAULT_ASSET_DECIMAL } from '@config' ; import { BigifySupported , Bigish , ITxGasLimit , ITxGasPrice , ITxNonce , ITxObject , ITxValue } from '@types' ; import { bigify } from './bigify' ; import { fromWei , gasPriceToBase , toTokenBase , toWei , Wei } from './units' ; export const makeTransaction = ( t ) : TransactionRequest => { const { from , ... tx } = t ; return { ... tx , nonce : new BigNumber ( t . nonce , 10 ) . toNumber ( ) } ; } ; export const inputGasPriceToHex = ( gasPriceGwei ) : ITxGasPrice => addHexPrefix ( gasPriceToBase ( gasPriceGwei ) . toString ( 16 ) ) as ITxGasPrice ; export const inputGasLimitToHex = ( gasLimit ) : ITxGasLimit => addHexPrefix ( bigify ( gasLimit ) . toString ( 16 ) ) as ITxGasLimit ; export const inputValueToHex = ( valueEther ) : ITxValue => addHexPrefix ( toTokenBase ( valueEther , DEFAULT_ASSET_DECIMAL ) . toString ( 16 ) ) as ITxValue ; export const inputNonceToHex = ( nonce ) : ITxNonce => addHexPrefix ( bigify ( nonce ) . toString ( 16 ) ) as ITxNonce ; export const hexNonceToViewable = ( nonceHex ) : string => hexToString ( nonceHex ) ; export const hexToString = ( hexValue ) : string => bigify ( hexValue ) . toString ( ) ; export const hexWeiToString = ( hexWeiValue ) : string => Wei ( hexWeiValue ) . toString ( ) ; export const bigNumGasPriceToViewableGwei = ( gasPriceWeiBigNum ) : string => fromWei ( toWei ( bigify ( gasPriceWeiBigNum ) . toString ( ) , 0 ) , 'gwei' ) ; export const bigNumGasLimitToViewable = ( gasLimitBigNum ) : string => bigify ( gasLimitBigNum ) . toString ( ) ; export const bigNumValueToViewableEther = ( valueWeiBigNum ) : string => formatEther ( EthersBigNumber . from ( valueWeiBigNum . toString ( ) ) ) ;