Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a71c93e
First draft of gas fee controller
danjm Jun 14, 2021
c4a2606
Second draft of gas fee controller
danjm Jun 16, 2021
7886180
Third draft of gas fee controller
danjm Jun 17, 2021
2be94cb
Delete use of legacy gas fee
danjm Jun 18, 2021
ba8e275
Track whether polling should be instantiated or stopped with tokens
danjm Jun 18, 2021
179dee6
Network controller getEIP1559Compatibility can be called whenever a n…
danjm Jun 18, 2021
55d3607
update tests (#495)
rickycodes Jun 18, 2021
16075b0
Fetch estimate using eth_gasPrice if on a custom network
danjm Jun 21, 2021
b70d323
getGasFeeEstimatesAndStartPolling returns poll token, and a new one i…
danjm Jun 21, 2021
0a8a248
Add getTimeEstimate to GasFee controller
danjm Jun 21, 2021
cb88478
export GasFeeController
rickycodes Jun 21, 2021
1ccd62a
Add public method for calling and returning gas estimates without pol…
danjm Jun 23, 2021
dbf9f6c
Fix return of fetchLegacyGasPriceEstimate
danjm Jun 23, 2021
16b313b
Proper error handling and fallback for _fetchGasFeeEstimateData
danjm Jun 23, 2021
a782c9d
Include estimated time bounds in gas fee state
danjm Jun 23, 2021
32b2930
rename
rickycodes Jun 23, 2021
97e9e8f
Add GasFeeController.test.ts
rickycodes Jun 23, 2021
47f3659
remove TODO
rickycodes Jun 24, 2021
9971e68
Add result token length test
rickycodes Jun 24, 2021
91a2cd2
Add estimates property test
rickycodes Jun 24, 2021
0dec6e7
Add should fail to re-initialize test
rickycodes Jun 24, 2021
e4e962e
remove console.log
rickycodes Jun 24, 2021
afdc385
do not modify state directly
rickycodes Jun 24, 2021
fd4bd64
Use before/afterEach and fix messenger
rickycodes Jun 24, 2021
b1c5631
check gasFeeEstimates properties
rickycodes Jun 24, 2021
3646d62
check that state is empty to start
rickycodes Jun 24, 2021
51dad0d
Add one additional property check
rickycodes Jun 24, 2021
4ac4ffe
Adding TokenListController to fetch the token list from token service…
NiranjanaBinoy Jun 28, 2021
c1ca513
address feedback
rickycodes Jun 30, 2021
0458679
add mock server for eip1559
rickycodes Jun 15, 2021
728c039
get tests working again
rickycodes Jun 30, 2021
cd90799
Use heroku endpoint
rickycodes Jun 30, 2021
8d570bb
Handle fetch correctly in gasfeecontroller unit tests, using nock
danjm Jun 30, 2021
2e2b1a7
gasFee controller calculateTimeEstimate handles decimals, by way of u…
danjm Jun 30, 2021
1516d87
Lint fix
danjm Jun 30, 2021
6eac11c
Fix dec to gwi (#504)
brad-decker Jul 1, 2021
3df6baf
use ethjs-unit for unit conversions (#506)
brad-decker Jul 1, 2021
117d898
Add metaswaps API and normalize all gas fee units to dec gwei (#507)
brad-decker Jul 1, 2021
b4eebac
update types to be more identifiable (#508)
brad-decker Jul 2, 2021
6fbf024
use LegacyGasFeeEstimate type
brad-decker Jul 2, 2021
5d2908e
handle hex prefixed
brad-decker Jul 5, 2021
283fc88
baseFee -> baseFeePerGas
brad-decker Jul 5, 2021
cf82e70
make more configurable (#513)
brad-decker Jul 6, 2021
8d04cc5
use optional chaining
brad-decker Jul 6, 2021
41cdace
update test case wording
brad-decker Jul 7, 2021
3a42d98
use testdata instead of programmatic testing
brad-decker Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Third draft of gas fee controller
  • Loading branch information
danjm authored and brad-decker committed Jul 7, 2021
commit 788618077cc14332fa8b539547bbc3bfacfa933c
32 changes: 12 additions & 20 deletions src/gas/GasFee.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ interface LegacyGasFee {
gasPrice: string; // a GWEI hex number
}

/**
* @type Eip1559GasFee
*
* Data necessary to provide an estimate of a gas fee with a specific tip
*
* @property minWaitTimeEstimate - The fastest the transaction will take, in milliseconds
* @property maxWaitTimeEstimate - The slowest the transaction will take, in milliseconds
* @property suggestedMaxPriorityFeePerGas - A suggested "tip", a GWEI hex number
* @property suggestedMaxFeePerGas - A suggested max fee, the most a user will pay. a GWEI hex number
* @property calculatedTotalMinFee - suggestedMaxPriorityFeePerGas + estimatedNextBlockBaseFee
*/

/**
* @type LegacyGasPriceEstimates
*
Expand All @@ -45,12 +33,22 @@ interface LegacyGasPriceEstimates {
high: LegacyGasFee;
}

/**
* @type Eip1559GasFee
*
* Data necessary to provide an estimate of a gas fee with a specific tip
*
* @property minWaitTimeEstimate - The fastest the transaction will take, in milliseconds
* @property maxWaitTimeEstimate - The slowest the transaction will take, in milliseconds
* @property suggestedMaxPriorityFeePerGas - A suggested "tip", a GWEI hex number
* @property suggestedMaxFeePerGas - A suggested max fee, the most a user will pay. a GWEI hex number
*/

interface Eip1559GasFee {
minWaitTimeEstimate: number; // a time duration in milliseconds
maxWaitTimeEstimate: number; // a time duration in milliseconds
suggestedMaxPriorityFeePerGas: string; // a GWEI hex number
suggestedMaxFeePerGas: string; // a GWEI hex number
calculatedTotalMinFee: string; // a GWEI hex number
}

/**
Expand All @@ -62,19 +60,13 @@ interface Eip1559GasFee {
* @property medium - A GasFee for a recommended combination of tip and maxFee
* @property high - A GasFee for a high combination of tip and maxFee
* @property estimatedNextBlockBaseFee - An estimate of what the base fee will be for the pending/next block. A GWEI hex number
* @property lastBlockBaseFee - The base fee for the most recent block. A GWEI hex number
* @property lastBlockMinPriorityFee - The lowest tip that succeeded in the most recent block. A GWEI hex number
* @property lastBlockMaxPriorityFee - The highest tip that succeeded in the most recent block. A GWEI hex number
*/

export interface GasFeeEstimates {
low: Eip1559GasFee;
medium: Eip1559GasFee;
high: Eip1559GasFee;
estimatedNextBlockBaseFee: string;
lastBlockBaseFee: string;
lastBlockMinPriorityFee: string;
lastBlockMaxPriorityFee: string;
estimatedBaseFee: string;
}

const metadata = {
Expand Down
55 changes: 10 additions & 45 deletions src/gas/gas-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,173 +4,138 @@ import { GasFeeEstimates } from './GasFee.controller';

// const GAS_FEE_API = 'https://gas-fee-api-goes-here';

const mockApiResponses = [
const mockEIP1559ApiResponses = [
{
low: {
minWaitTimeEstimate: 120000,
maxWaitTimeEstimate: 300000,
suggestedMaxPriorityFeePerGas: '1',
suggestedMaxFeePerGas: '35',
calculatedTotalMinFee: '31',
},
medium: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 30000,
suggestedMaxPriorityFeePerGas: '2',
suggestedMaxFeePerGas: '40',
calculatedTotalMinFee: '32',
},
high: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 150000,
suggestedMaxPriorityFeePerGas: '3',
suggestedMaxFeePerGas: '60',
calculatedTotalMinFee: '33',
},
estimatedNextBlockBaseFee: '30',
lastBlockBaseFee: '28',
lastBlockMinPriorityFee: '1',
lastBlockMaxPriorityFee: '9',
estimatedBaseFee: '30',
},
{
low: {
minWaitTimeEstimate: 180000,
maxWaitTimeEstimate: 360000,
suggestedMaxPriorityFeePerGas: '1',
suggestedMaxFeePerGas: '40',
calculatedTotalMinFee: '33',
},
medium: {
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 60000,
suggestedMaxPriorityFeePerGas: '2',
suggestedMaxFeePerGas: '45',
calculatedTotalMinFee: '34',
},
high: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 150000,
suggestedMaxPriorityFeePerGas: '3',
suggestedMaxFeePerGas: '65',
calculatedTotalMinFee: '35',
},
estimatedNextBlockBaseFee: '32',
lastBlockBaseFee: '30',
lastBlockMinPriorityFee: '1',
lastBlockMaxPriorityFee: '10',
estimatedBaseFee: '32',
},
{
low: {
minWaitTimeEstimate: 60000,
maxWaitTimeEstimate: 240000,
suggestedMaxPriorityFeePerGas: '1',
suggestedMaxFeePerGas: '42',
calculatedTotalMinFee: '36',
},
medium: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 30000,
suggestedMaxPriorityFeePerGas: '3',
suggestedMaxFeePerGas: '47',
calculatedTotalMinFee: '38',
},
high: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 150000,
suggestedMaxPriorityFeePerGas: '4',
suggestedMaxFeePerGas: '67',
calculatedTotalMinFee: '39',
},
estimatedNextBlockBaseFee: '35',
lastBlockBaseFee: '32',
lastBlockMinPriorityFee: '1',
lastBlockMaxPriorityFee: '10',
estimatedBaseFee: '35',
},
{
low: {
minWaitTimeEstimate: 180000,
maxWaitTimeEstimate: 300000,
suggestedMaxPriorityFeePerGas: '3',
suggestedMaxFeePerGas: '53',
calculatedTotalMinFee: '53',
},
medium: {
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 60000,
suggestedMaxPriorityFeePerGas: '7',
suggestedMaxFeePerGas: '70',
calculatedTotalMinFee: '57',
},
high: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 150000,
suggestedMaxPriorityFeePerGas: '10',
suggestedMaxFeePerGas: '100',
calculatedTotalMinFee: '60',
},
estimatedNextBlockBaseFee: '50',
lastBlockBaseFee: '35',
lastBlockMinPriorityFee: '2',
lastBlockMaxPriorityFee: '15',
estimatedBaseFee: '50',
},
{
low: {
minWaitTimeEstimate: 120000,
maxWaitTimeEstimate: 360000,
suggestedMaxPriorityFeePerGas: '1',
suggestedMaxFeePerGas: '35',
calculatedTotalMinFee: '31',
},
medium: {
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 60000,
suggestedMaxPriorityFeePerGas: '3',
suggestedMaxFeePerGas: '40',
calculatedTotalMinFee: '33',
},
high: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 150000,
suggestedMaxPriorityFeePerGas: '4',
suggestedMaxFeePerGas: '60',
calculatedTotalMinFee: '34',
},
estimatedNextBlockBaseFee: '30',
lastBlockBaseFee: '50',
lastBlockMinPriorityFee: '4',
lastBlockMaxPriorityFee: '25',
estimatedBaseFee: '30',
},
{
low: {
minWaitTimeEstimate: 60000,
maxWaitTimeEstimate: 600000,
suggestedMaxPriorityFeePerGas: '1',
suggestedMaxFeePerGas: '35',
calculatedTotalMinFee: '31',
},
medium: {
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 60000,
suggestedMaxPriorityFeePerGas: '1.8',
suggestedMaxFeePerGas: '38',
calculatedTotalMinFee: '29.8',
},
high: {
minWaitTimeEstimate: 0,
maxWaitTimeEstimate: 150000,
suggestedMaxPriorityFeePerGas: '2',
suggestedMaxFeePerGas: '50',
calculatedTotalMinFee: '30',
},
estimatedNextBlockBaseFee: '28',
lastBlockBaseFee: '28',
lastBlockMinPriorityFee: '1',
lastBlockMaxPriorityFee: '7',
estimatedBaseFee: '28',
},
];

const getMockApiResponse = (): GasFeeEstimates =>
mockApiResponses[Math.floor(Math.random() * 6)];
const getMockApiResponse = (): GasFeeEstimates => {
return mockEIP1559ApiResponses[Math.floor(Math.random() * 6)];
};

export function fetchGasEstimates(): Promise<GasFeeEstimates> {
// return handleFetch(GAS_FEE_API)
Expand Down