Skip to content

Commit

Permalink
Polygon gas updates (#2459)
Browse files Browse the repository at this point in the history
* update polygon gas oracle

* polygon working
  • Loading branch information
brunobar79 committed Oct 8, 2021
1 parent 22cee6f commit 04fa134
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/handlers/gasPrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const ethGasStationGetGasPrices = () =>
});

/**
* Configuration for Matic GAS Station API
* Configuration for Polygon GAS Station API
* @type RainbowFetchClient instance
*/
const maticGasstationApi = new RainbowFetchClient({
baseURL: 'https://gasstation-mainnet.matic.network',
const polygonGasStationApi = new RainbowFetchClient({
baseURL: 'https://gpoly.blockscan.com',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
Expand All @@ -44,10 +44,10 @@ const maticGasstationApi = new RainbowFetchClient({
});

/**
* @desc get Matic gas prices
* @desc get Polygon gas prices
* @return {Promise}
*/
export const maticGasStationGetGasPrices = () => maticGasstationApi.get(`/`);
export const polygonGasStationGetGasPrices = () => polygonGasStationApi.get(`/gasapi.ashx?apikey=key&method=gasoracle`);

/**
* Configuration for Etherscan API
Expand Down Expand Up @@ -76,11 +76,11 @@ export const etherscanGetGasPrices = () =>
});

/**
* @desc get matic time estimates
* @desc get Polygon time estimates
* @params {data}
* @return {Promise}
*/
export const maticGetGasEstimates = data => {
export const polygonGetGasEstimates = data => {
return {
...data,
avgWait: 0.5,
Expand Down
14 changes: 7 additions & 7 deletions src/parsers/gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ const parseGasPricesEthGasStation = data => ({
true
),
});
const parseGasPricesMaticGasStation = data => {
const maticGasPriceBumpFactor = 1.15;
const parseGasPricesPolygonGasStation = data => {
const polygonGasPriceBumpFactor = 1.05;
return {
[CUSTOM]: null,
[FAST]: defaultGasPriceFormat(
FAST,
0.2,
Math.ceil((Number(data.fastest) / 10) * maticGasPriceBumpFactor),
Math.ceil((Number(data.fastest)) * polygonGasPriceBumpFactor),
true
),
[NORMAL]: defaultGasPriceFormat(
NORMAL,
0.5,
Math.ceil((Number(data.fast) / 10) * maticGasPriceBumpFactor),
Math.ceil((Number(data.fast)) * polygonGasPriceBumpFactor),
true
),
[SLOW]: defaultGasPriceFormat(
SLOW,
1,
Math.ceil((Number(data.average) / 10) * maticGasPriceBumpFactor) / 10,
Math.ceil((Number(data.average)) * polygonGasPriceBumpFactor),
true
),
};
Expand All @@ -90,8 +90,8 @@ export const parseGasPrices = (
switch (source) {
case gasUtils.GAS_PRICE_SOURCES.ETH_GAS_STATION:
return parseGasPricesEthGasStation(data);
case gasUtils.GAS_PRICE_SOURCES.MATIC_GAS_STATION:
return parseGasPricesMaticGasStation(data);
case gasUtils.GAS_PRICE_SOURCES.POLYGON_GAS_STATION:
return parseGasPricesPolygonGasStation(data);
default:
return parseGasPricesEtherscan(data);
}
Expand Down
18 changes: 10 additions & 8 deletions src/redux/gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
etherscanGetGasPrices,
ethGasStationGetGasPrices,
getEstimatedTimeForGasPrice,
maticGasStationGetGasPrices,
maticGetGasEstimates,
polygonGasStationGetGasPrices,
polygonGetGasEstimates,
} from '@rainbow-me/handlers/gasPrices';
import { getProviderForNetwork, isL2Network } from '@rainbow-me/handlers/web3';
import networkTypes from '@rainbow-me/helpers/networkTypes';
Expand Down Expand Up @@ -98,13 +98,15 @@ export const gasPricesStartPolling = (network = networkTypes.mainnet) => async (
dispatch(gasPricesStopPolling());

const getPolygonGasPrices = async () => {
const { data: maticGasStationPrices } = await maticGasStationGetGasPrices();

const { data : { result }} = await polygonGasStationGetGasPrices();
// Override required to make it compatible with other responses
maticGasStationPrices['average'] = maticGasStationPrices['standard'];
delete maticGasStationPrices['standard'];
const polygonGasStationPrices = {};
polygonGasStationPrices['slow'] = Math.ceil(Number(result['SafeGasPrice']));
polygonGasStationPrices['average'] = Math.ceil(result['SafeGasPrice']);
polygonGasStationPrices['fast'] = Math.ceil(result['ProposeGasPrice']);
polygonGasStationPrices['fastest'] = Math.ceil(result['FastGasPrice']);

return maticGetGasEstimates(maticGasStationPrices);
return polygonGetGasEstimates(polygonGasStationPrices);
};

const getArbitrumGasPrices = async () => {
Expand Down Expand Up @@ -149,7 +151,7 @@ export const gasPricesStartPolling = (network = networkTypes.mainnet) => async (
let adjustedGasPrices;
let source = GAS_PRICE_SOURCES.ETHERSCAN;
if (network === networkTypes.polygon) {
source = GAS_PRICE_SOURCES.MATIC_GAS_STATION;
source = GAS_PRICE_SOURCES.POLYGON_GAS_STATION;
adjustedGasPrices = await getPolygonGasPrices();
} else if (network === networkTypes.arbitrum) {
source = GAS_PRICE_SOURCES.ARBITRUM_NODE;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const GAS_PRICE_SOURCES = {
ARBITRUM_NODE: 'arbitrumNode',
ETH_GAS_STATION: 'ethGasStation',
ETHERSCAN: 'etherscan',
MATIC_GAS_STATION: 'maticGasStation',
POLYGON_GAS_STATION: 'polygonGasStation',
OPTIMISM_NODE: 'optimismNode',
};

Expand Down

0 comments on commit 04fa134

Please sign in to comment.