on master help sign in
txns: refactor TX flow --> EIP1559

This change refactors L1 transactions to use EIP1559 params: max Confirmed working as expected on mainnet with WalletConnect via Trust Wallet for iOS: https://etherscan.io/tx/0xf17f3795456f2489e98fa3494cba53b13e5acf79fbf02a8751f8a0752a747ca2 TODO: - test Metamask - test other flows besides Accept Transfer - test behavior without auth token - clean up legacy Transaction usage (probably no longer needed)

commit016cde36858230200f5fb3ee58d617c146f6f19e authortomholford <tomholford@users.noreply.github.com> dateSun 16 Oct 2022, 20:41 (4 years ago) parent50637ac
10 files changed+126−135
src/components/InlineEthereumTransaction.jsx+3−3 src/components/L2/Dropdowns/FeeDropdown.tsx+5−4 src/lib/WalletConnect.ts+5−4 src/lib/constants.ts+3 src/lib/getSuggestedGasPrice.js+24−8 src/lib/metamask.ts+4−4 src/lib/reticket.js+6−5 src/lib/txn.ts+69−100 src/lib/useEthereumTransaction.js+3−3 src/lib/useGasPrice.js+4−4
src/components/InlineEthereumTransaction.jsx+3−3
@@ -42,8 +42,8 @@ export default function InlineEthereumTransaction({
4242 completed,
4343 reset,
4444 error,
45− gasPrice,
46− setGasPrice,
45+ gasPrice, // Type: GasPriceData
46+ setGasPrice, // Type: (g: GasPriceData) => void
4747 resetGasPrice,
4848 txHashes,
4949 nonce,
@@ -109,7 +109,7 @@ export default function InlineEthereumTransaction({
109109 safeFromWei(
110110 safeToWei(
111111 toBN(gasLimit)
112− .mul(toBN(gasPrice))
112+ .mul(toBN(gasPrice.price))
113113 .mul(toBN(numTxs)),
114114 'gwei'
115115 ),
src/components/L2/Dropdowns/FeeDropdown.tsx+5−4
@@ -5,13 +5,14 @@ import useGasPrice from 'lib/useGasPrice';
55
66import Dropdown from './Dropdown';
77import './FeeDropdown.scss';
8+import { defaultGasValues } from 'lib/getSuggestedGasPrice';
89
910const PRICE_LABELS = ['Fast', 'Normal', 'Slow'];
1011
1112export interface GasPriceData {
1213 price: number;
1314 wait: string;
14− maxFeePerGas: number;
15+ maxFeePerGas: string; // hex
1516 maxPriorityFeePerGas: number;
1617 suggestedBaseFeePerGas: number;
1718}
@@ -23,7 +24,7 @@ export const formatDisplay = ({ price, wait }: GasPriceData) =>
2324export default function FeeDropdown({
2425 setGasPrice,
2526}: {
26− setGasPrice: (g: number) => void;
27+ setGasPrice: (g: GasPriceData) => void;
2728}) {
2829 const { suggestedGasPrices }: { suggestedGasPrices: {
2930 fast: GasPriceData,
@@ -42,7 +43,7 @@ export default function FeeDropdown({
4243 const cleanedValue = e.target.value.replace(/[^0-9]/g, '');
4344 const cleanedNum = Number(cleanedValue);
4445 setCustom(cleanedValue);
45− setGasPrice(cleanedNum);
46+ setGasPrice(defaultGasValues(cleanedNum).average);
4647
4748 let customWait = 'Unknown';
4849
@@ -74,7 +75,7 @@ export default function FeeDropdown({
7475 const selectPrice = useCallback(
7576 (value: GasPriceData) => () => {
7677 setSelected(value);
77− setGasPrice(value.price);
78+ setGasPrice(value);
7879 setOpen(false);
7980 },
8081 [setGasPrice, setSelected, setOpen]
src/lib/WalletConnect.ts+5−4
@@ -1,12 +1,13 @@
11import { ITxData } from '@walletconnect/types';
2−import { JsonTx, Transaction } from '@ethereumjs/tx';
2+import { JsonTx, Transaction, FeeMarketEIP1559Transaction as EIP1559Transaction } from '@ethereumjs/tx';
33import { stripHexPrefix } from './utils/address';
44import { FakeSignableTx, FakeSignResult } from './txn';
55import Web3 from 'web3';
6+import { EIP1559_TRANSACTION_TYPE } from './constants';
67
78type SignWalletConnectTransactionArgs = {
89 from: string;
9− txn: Transaction;
10+ txn: Transaction | EIP1559Transaction;
1011 txnSigner: (txn: ITxData) => Promise<string>;
1112 txnSender: (txn: ITxData) => Promise<string>;
1213};
@@ -24,7 +25,7 @@ const walletConnectSignTransaction = async ({
2425 gas: string;
2526 } = txn.toJSON();
2627 wcFormattedTx.from = from;
27− wcFormattedTx.gas = txn.gasLimit.toString();
28+ wcFormattedTx.type = `0x${EIP1559_TRANSACTION_TYPE}`;
2829
2930 let signature;
3031 try {
@@ -42,7 +43,7 @@ const walletConnectSignTransaction = async ({
4243 }
4344 }
4445 const serializedTx = Buffer.from(stripHexPrefix(signature), 'hex');
45− const signedTx = Transaction.fromSerializedTx(serializedTx);
46+ const signedTx = EIP1559Transaction.fromSerializedTx(serializedTx);
4647
4748 return signedTx;
4849};
src/lib/constants.ts+3
@@ -224,10 +224,13 @@ const LOCKUP_TOOLTIP =
224224// the initial network key revision is always 1
225225const INITIAL_NETWORK_KEY_REVISION = 1;
226226
227+const EIP1559_TRANSACTION_TYPE = 2;
228+
227229export {
228230 CHECK_BLOCK_EVERY_MS,
229231 DEFAULT_GAS_PRICE_GWEI,
230232 DEFAULT_HD_PATH,
233+ EIP1559_TRANSACTION_TYPE,
231234 ETH_ZERO_ADDR,
232235 ETH_ZERO_ADDR_SHORT,
233236 LINEAR_STAR_RELEASE,
src/lib/getSuggestedGasPrice.js+24−8
@@ -1,24 +1,40 @@
11import { NETWORK_TYPES } from './network';
22import { DEFAULT_GAS_PRICE_GWEI, MAX_GAS_PRICE_GWEI } from './constants';
33import { formatWait } from 'components/L2/Dropdowns/FeeDropdown';
4+import Web3 from 'web3';
45
56// ethgasstation returns values in floating point, one order of magitude
67// more than gwei. see: https://docs.ethgasstation.info
78// we don't want to charge users more than the gas tank funds
89const minGas = gas => Math.min(Math.ceil(gas), MAX_GAS_PRICE_GWEI);
910
11+const feeToInt = (f) => f < 1 ? 1 : Math.round(f);
12+
13+const feeToWei = (fee) => Web3.utils.toHex(Web3.utils.toWei(String(fee), 'gwei' ))
14+
15+const calculateMaxFee = (baseFee, maxPriorityFee) => feeToWei(Math.round((2 * baseFee) + maxPriorityFee))
16+
1017export const defaultGasValues = value => ({
1118 fast: {
1219 price: value,
1320 wait: '1',
21+ maxFeePerGas: value,
22+ maxPriorityFeePerGas: 1,
23+ suggestedBaseFeePerGas: value > 2 ? value -1 : 1,
1424 },
1525 average: {
1626 price: value,
1727 wait: '1',
28+ maxFeePerGas: value,
29+ maxPriorityFeePerGas: 1,
30+ suggestedBaseFeePerGas: value > 2 ? value -1 : 1,
1831 },
1932 low: {
2033 price: value,
2134 wait: '1',
35+ maxFeePerGas: value,
36+ maxPriorityFeePerGas: 1,
37+ suggestedBaseFeePerGas: value > 2 ? value -1 : 1,
2238 },
2339});
2440
@@ -58,28 +74,28 @@ export default async function getSuggestedGasPrice(networkType) {
5874
5975 const suggestedBaseFeePerGas = Number(etherscanGasJson.result.suggestBaseFee);
6076
61− // Calculations inspired by:
62− // https://github.com/liquality/chainify/blob/6e8243e8daf4dc219dcfd7df144ead3ff6183b26/packages/evm/lib/fee/EIP1559FeeApiProvider/ethereum.ts#L5
77+ // Calculations derived from:
78+ // https://www.blocknative.com/blog/eip-1559-fees
6379 return {
6480 fast: {
6581 price: minGas(etherscanGasJson.result.FastGasPrice),
6682 wait: formatWait(ethgasstationGasJson.fastWait),
67− maxFeePerGas: minGas(etherscanGasJson.result.FastGasPrice),
68− maxPriorityFeePerGas: (etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas),
83+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas),
84+ maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas)),
6985 suggestedBaseFeePerGas
7086 },
7187 average: {
7288 price: minGas(etherscanGasJson.result.ProposeGasPrice),
7389 wait: formatWait(ethgasstationGasJson.avgWait),
74− maxFeePerGas: minGas(etherscanGasJson.result.ProposeGasPrice),
75− maxPriorityFeePerGas: (etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
90+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
91+ maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
7692 suggestedBaseFeePerGas
7793 },
7894 low: {
7995 price: minGas(etherscanGasJson.result.SafeGasPrice),
8096 wait: formatWait(ethgasstationGasJson.safeLowWait),
81− maxFeePerGas: minGas(etherscanGasJson.result.SafeGasPrice),
82− maxPriorityFeePerGas: (etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas),
97+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas),
98+ maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
8399 suggestedBaseFeePerGas
84100 },
85101 };
src/lib/metamask.ts+4−4
@@ -17,16 +17,16 @@ export const metamaskSignTransaction = async (txn: FakeSignableTx) => {
1717};
1818
1919const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
20− const { data, gasLimit, gasPrice, nonce, to, from } = txn;
21− if (!(data && gasLimit && gasPrice && nonce && to && from)) {
20+ const { data, gasLimit, gasPrice, nonce, to, from } = txn; // TODO
21+ if (!(data && gasLimit && gasPrice && nonce && to && from)) { // TODO
2222 throw new Error('Unable to send Metamask TX, something is missing');
2323 }
2424
25− // web3-eth/TransactionConfig type
25+ // https://docs.metamask.io/guide/sending-transactions.html#transaction-parameters
2626 const metamaskFormattedTxn = {
2727 data: data.toString(),
2828 gasLimit,
29− gasPrice,
29+ gasPrice, // TODO
3030 nonce: Number(nonce).toString(),
3131 to: to.toString(),
3232 from: toHex(from),
src/lib/reticket.js+6−5
@@ -146,9 +146,10 @@ export async function reticketPointBetweenWallets({
146146
147147 progress(TRANSACTION_PROGRESS.SIGNING);
148148
149− const gasPriceGwei = (
149+ const gasPriceData = (
150150 await getSuggestedGasPrice(networkType)
151− ).average.price.toFixed();
151+ ).average;
152+ const gasPriceGwei = gasPriceData.price.toFixed();
152153 const chainId = await web3.eth.net.getId();
153154 const gasPriceWeiBN = toBN(safeToWei(gasPriceGwei, 'gwei'));
154155 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
@@ -169,7 +170,7 @@ export async function reticketPointBetweenWallets({
169170 txn: txs[i],
170171 nonce: inviteNonce + i,
171172 chainId,
172− gasPrice: gasPriceGwei,
173+ gasPriceData,
173174 gasLimit: txs[i].gas,
174175 txnSigner,
175176 txnSender,
@@ -240,7 +241,7 @@ export async function reticketPointBetweenWallets({
240241 txn,
241242 chainId,
242243 networkType,
243− gasPrice: gasPriceGwei,
244+ gasPriceData,
244245 gasLimit,
245246 nonce: inviteNonce,
246247 });
@@ -270,7 +271,7 @@ export async function reticketPointBetweenWallets({
270271 txn,
271272 chainId,
272273 networkType,
273− gasPrice: gasPriceGwei,
274+ gasPriceData,
274275 gasLimit,
275276 nonce: inviteNonce,
276277 });
src/lib/txn.ts+69−100
@@ -1,20 +1,17 @@
1−import Common, { Chain, Hardfork } from '@ethereumjs/common';
2−import { JsonTx, Transaction } from '@ethereumjs/tx';
1+import { Common, Chain, Hardfork } from '@ethereumjs/common';
2+import { JsonTx, Transaction, FeeMarketEIP1559Transaction as EIP1559Transaction, TxOptions, TxData, FeeMarketEIP1559TxData as EIP1559TxData } from '@ethereumjs/tx';
33import { ITxData } from '@walletconnect/types';
4−import { toHex } from 'web3-utils';
5−import { safeFromWei, safeToWei } from './lib';
4+import { toHex, toWei } from 'web3-utils';
65import retry from 'async-retry';
7−
86import { NETWORK_TYPES } from './network';
9−import { ledgerSignTransaction } from './ledger';
10−import { trezorSignTransaction } from './trezor';
117import { walletConnectSignTransaction } from './WalletConnect';
128import { metamaskSignTransaction } from './metamask';
139import { addHexPrefix } from './utils/address';
14−import { CHECK_BLOCK_EVERY_MS, WALLET_TYPES } from './constants';
10+import { CHECK_BLOCK_EVERY_MS, EIP1559_TRANSACTION_TYPE, WALLET_TYPES } from './constants';
1511import Web3 from 'web3';
16−import { TransactionReceipt } from 'web3-core';
12+import { TransactionConfig, TransactionReceipt } from 'web3-core';
1713import BridgeWallet from './types/BridgeWallet';
14+import { GasPriceData } from 'components/L2/Dropdowns/FeeDropdown';
1815
1916const RETRY_OPTIONS = {
2017 retries: 99999,
@@ -23,12 +20,12 @@ const RETRY_OPTIONS = {
2320 randomize: false,
2421};
2522
26−type SignableTx = Transaction & {
23+type SignableTx = (Transaction | EIP1559Transaction) & {
2724 nonce: string;
2825 chainId: string;
29− gasPrice: string;
30− gasLimit: string;
31− from: string;
26+ gasPrice?: string; // TODO: is this still needed?
27+ gasLimit: string; // TODO: is this still needed?
28+ from?: string;
3229};
3330
3431// catch-all type: Metamask passes an obj shaped like ITxData, WC passes JsonTx + from
@@ -39,13 +36,10 @@ export type FakeSignableTx =
3936
4037type TxSender = (txn: FakeSignableTx, web3: Web3) => Promise<string>; // Metamask requires Web3 (txhash)
4138
42−type SignedTx = {
43− serialize: () => string;
44−};
45−
46−export type FakeSignedTx = SignedTx & {
39+export type FakeSignedTx = {
4740 txn: FakeSignableTx;
4841 send: TxSender;
42+ serialize: () => string;
4943};
5044
5145const FakeSignResult = (txn: FakeSignableTx, send: TxSender): FakeSignedTx => {
@@ -61,107 +55,81 @@ const FakeSignResult = (txn: FakeSignableTx, send: TxSender): FakeSignedTx => {
6155interface signTransactionProps {
6256 wallet: BridgeWallet;
6357 walletType: symbol;
64− walletHdPath: string;
58+ walletHdPath: string; // TODO: is this still needed?
6559 networkType: symbol;
66− txn: Transaction;
60+ txn: Transaction | EIP1559Transaction;
6761 nonce: number | string;
6862 chainId: number | string;
69− gasPrice: string;
70− gasLimit: string;
63+ gasPriceData: GasPriceData;
64+ gasLimit: number;
7165 txnSigner?: (args: ITxData) => Promise<string>;
7266 txnSender?: (args: ITxData) => Promise<string>;
7367}
7468
69+const _web3 = () => {
70+ const ENDPOINT = `https://mainnet.infura.io/v3/${import.meta.env.VITE_INFURA_ENDPOINT}`;
71+ return new Web3(new Web3.providers.HttpProvider(ENDPOINT));
72+}
73+
74+const estimateGasLimit = async (utx: TransactionConfig) => {
75+ const web3 = _web3();
76+ const estimate = await web3.eth.estimateGas(utx);
77+ console.log(estimate);
78+ return web3.utils.toBN(estimate).muln(120).divn(100); // 20% cushion
79+}
80+
81+const getMaxFeePerGas = async () => {
82+ const web3 = _web3();
83+ const fee = await web3.eth.getGasPrice();
84+ return (Number(fee) * 1.20).toFixed(0); // 20% cushion
85+}
86+
7587const signTransaction = async ({
7688 wallet,
7789 walletType,
78− walletHdPath,
90+ walletHdPath, // TODO
7991 networkType,
8092 txn,
8193 nonce, // number
8294 chainId, // number
83− gasPrice, // string, in gwei
84− gasLimit, // string | number
95+ gasPriceData, // GasPriceData
96+ gasLimit, // TODO: do we need the default values anymore? now that the estiamte is loaded dynamically
8597 txnSigner, // optionally inject a transaction signing function,
8698 txnSender, // and a sending function, for wallets that need these passed in.
8799}: signTransactionProps) => {
88− // TODO: require these in txn object
89− nonce = toHex(nonce);
90− chainId = toHex(chainId);
91− gasPrice = toHex(safeToWei(gasPrice, 'gwei'));
92− gasLimit = toHex(gasLimit);
100+ console.log('txn', txn);
93101 const from = wallet.address;
102+ const estimate = await estimateGasLimit({...txn, from });
103+ const maxFeePerGas = await getMaxFeePerGas();
94104
95− const txParams = { nonce, chainId, gasPrice, gasLimit, from };
105+ const txParams: EIP1559TxData = {
106+ data: toHex(txn.data),
107+ to: toHex(txn.to),
108+ gasLimit: toHex(estimate),
109+ maxFeePerGas: toHex(maxFeePerGas),
110+ maxPriorityFeePerGas: toHex(toWei(Math.round(gasPriceData.maxPriorityFeePerGas).toFixed(0), 'gwei')),
111+ nonce: toHex(nonce),
112+ chainId: toHex(chainId),
113+ type: toHex(EIP1559_TRANSACTION_TYPE),
114+ }
96115
97− // NB (jtobin)
98− //
99− // Ledger does not seem to handle EIP-155 automatically. When using a Ledger,
100− // if the block number is at least FORK_BLKNUM = 2675000, one needs to
101− // pre-set the ECDSA signature parameters with r = 0, s = 0, and v = chainId
102− // prior to signing.
103− //
104− // The easiest way to handle this is to just branch on the network, since
105− // mainnet and Ropsten have obviously passed FORK_BLKNUM. This is somewhat
106− // awkward when dealing with offline transactions, since we might want to
107− // test them on a local network as well.
108− //
109− // The best thing to do is probably to add an 'advanced' tab to offline
110− // transaction generation where one can disable the defaulted-on EIP-155
111− // settings in this case. This is pretty low-priority, but is a
112− // comprehensive solution.
113− //
114− // See:
115− //
116− // See https://github.com/LedgerHQ/ledgerjs/issues/43#issuecomment-366984725
117− //
118− // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
116+ const utx: SignableTx = Object.assign(txn, txParams);
117+
118+ // TODO: Ropsten will sunset Q4 2022, need to replace w/ support for Goerli
119+ const chain =
120+ networkType === NETWORK_TYPES.ROPSTEN ? Chain.Ropsten : Chain.Mainnet;
119121
120− const eip155Params = {
121− r: '0x00',
122− s: '0x00',
123− v: chainId,
122+ const txConfig: TxOptions = {
123+ freeze: false,
124+ common: new Common({
125+ chain,
126+ hardfork: Hardfork.Merge,
127+ })
124128 };
125129
126− const defaultEip155Networks = [
127− NETWORK_TYPES.MAINNET,
128− NETWORK_TYPES.ROPSTEN,
129− NETWORK_TYPES.OFFLINE,
130− ];
131−
132− const needEip155Params =
133− walletType === WALLET_TYPES.LEDGER &&
134− defaultEip155Networks.includes(networkType);
135−
136− const signingParams = needEip155Params
137− ? Object.assign(txParams, eip155Params)
138− : txParams;
139−
140− const utx: SignableTx = Object.assign(txn, signingParams);
141−
142− const txConfig: any = { freeze: false };
143− // we must specify the chain *either* in the Common object,
144− // *or* eip155 style, but never both!
145− //
146− if (!needEip155Params) {
147− const chain =
148− networkType === NETWORK_TYPES.ROPSTEN ? Chain.Ropsten : Chain.Mainnet;
149− txConfig.common = new Common({
150− chain: chain,
151− hardfork: Hardfork.MuirGlacier,
152− });
153− }
154−
155− let stx: Transaction | FakeSignedTx = Transaction.fromTxData(utx, txConfig);
130+ let stx = EIP1559Transaction.fromTxData(txParams, txConfig)
156131
157− //TODO should try-catch and display error message to user,
158− // ie ledger's "pls enable contract data"
159− // needs to maybe happen at call-site though
160− if (walletType === WALLET_TYPES.LEDGER) {
161− await ledgerSignTransaction(stx, walletHdPath);
162− } else if (walletType === WALLET_TYPES.TREZOR) {
163− await trezorSignTransaction(stx, walletHdPath);
164− } else if (walletType === WALLET_TYPES.METAMASK) {
132+ if (walletType === WALLET_TYPES.METAMASK) {
165133 return metamaskSignTransaction(utx);
166134 } else if (walletType === WALLET_TYPES.WALLET_CONNECT) {
167135 if (!(txnSender && txnSigner)) {
@@ -184,11 +152,12 @@ const signTransaction = async ({
184152
185153const sendSignedTransaction = (
186154 web3: Web3,
187− stx: Transaction | FakeSignedTx,
155+ // TODO: do we still need legacy TX type? elsewhere too
156+ stx: Transaction | EIP1559Transaction | FakeSignedTx,
188157 doubtNonceError: boolean
189158): Promise<string> => {
190159 // if we couldn't sign it, we depend on the given sender function
191− if (!(stx instanceof Transaction)) {
160+ if (!(stx instanceof Transaction || stx instanceof EIP1559Transaction)) { // TODO
192161 if (doubtNonceError) {
193162 console.log('why doubting nonce error? tank unavailable without rawtx.');
194163 }
@@ -252,7 +221,7 @@ const waitForTransactionConfirm = (web3: Web3, txHash: string) => {
252221// returns a Promise that resolves when all stxs have been sent & confirmed
253222const sendAndAwaitAll = (
254223 web3: Web3,
255− stxs: Transaction[] | FakeSignedTx[],
224+ stxs: Transaction[] | EIP1559Transaction[] | FakeSignedTx[],
256225 doubtNonceError: boolean
257226) => {
258227 return Promise.all(
@@ -265,7 +234,7 @@ const sendAndAwaitAll = (
265234
266235const sendAndAwaitAllSerial = (
267236 web3: Web3,
268− stxs: Array<Transaction> | Array<FakeSignedTx>,
237+ stxs: Array<Transaction> | Array<EIP1559Transaction> | Array<FakeSignedTx>,
269238 doubtNonceError: boolean
270239) => {
271240 // tsc complains that stxs.reduce() is not callable
@@ -282,7 +251,7 @@ const sendAndAwaitAllSerial = (
282251
283252const sendTransactionsAndAwaitConfirm = async (
284253 web3: Web3,
285− signedTxs: Array<Transaction> | Array<FakeSignedTx>,
254+ signedTxs: Array<Transaction> | Array<EIP1559Transaction> | Array<FakeSignedTx>,
286255 usedTank: boolean
287256) =>
288257 Promise.all(signedTxs.map(tx => sendSignedTransaction(web3, tx, usedTank)));
src/lib/useEthereumTransaction.js+3−3
@@ -135,7 +135,7 @@ export default function useEthereumTransaction(
135135 txn: utx,
136136 nonce: nonce + i,
137137 chainId,
138− gasPrice: gasPrice.toFixed(0),
138+ gasPriceData: gasPrice,
139139 gasLimit,
140140 txnSigner,
141141 txnSender,
@@ -181,7 +181,7 @@ export default function useEthereumTransaction(
181181 const rawTxs = signedTransactions.map(stx => hexify(stx.serialize()));
182182
183183 const costGwei = toBN(gasLimit)
184− .mul(toBN(gasPrice))
184+ .mul(toBN(gasPrice.price))
185185 .mul(toBN(rawTxs.length));
186186 const cost = safeToWei(costGwei, 'gwei');
187187 let usedTank = false;
@@ -229,7 +229,7 @@ export default function useEthereumTransaction(
229229 receipts.reduce(
230230 (acc, receipt) =>
231231 toBN(receipt.gasUsed)
232− .mul(toBN(gasPrice))
232+ .mul(toBN(gasPrice.price))
233233 .add(acc),
234234 toBN(0)
235235 ),
src/lib/useGasPrice.js+4−4
@@ -20,7 +20,7 @@ export default function useGasPrice(initialGasPrice = DEFAULT_GAS_PRICE_GWEI) {
2020 const [suggestedGasPrices, setSuggestedGasPrices] = useState(
2121 defaultGasValues(initialGasPrice)
2222 ); // fast, average, low. In gwei
23− const [gasPrice, setGasPrice] = useState(initialGasPrice); // gwei
23+ const [gasPrice, setGasPrice] = useState(defaultGasValues(initialGasPrice).average); // GasPriceData
2424
2525 const fetchPrices = useCallback(async () => {
2626 if (!mounted) {
@@ -32,17 +32,17 @@ export default function useGasPrice(initialGasPrice = DEFAULT_GAS_PRICE_GWEI) {
3232
3333 // TODO: BN
3434 setSuggestedGasPrices(suggestedGasPrices);
35− setGasPrice(suggestedGasPrices.average.price);
35+ setGasPrice(suggestedGasPrices.average);
3636 }, [mounted]);
3737
3838 useEffect(() => {
3939 setMounted(true);
40− fetchPrices()
40+ fetchPrices();
4141 return () => (setMounted(false));
4242 }, [mounted, networkType]);
4343
4444 const resetGasPrice = useCallback(
45− () => setGasPrice(suggestedGasPrices.average.price),
45+ () => setGasPrice(suggestedGasPrices.average),
4646 [suggestedGasPrices]
4747 );
4848