4 Commits

Author SHA1 Message Date
Danil Kovtonyuk
89a69519b2 fix: test 2021-08-17 17:14:50 +10:00
Danil Kovtonyuk
3fce50efbb fix: constructor 2021-08-17 17:04:01 +10:00
Danil Kovtonyuk
9b0c229ace add polygon 2021-06-15 13:26:02 +03:00
Danil Kovtonyuk
a508e41652 fix: bscgas property 2021-06-10 23:33:59 +03:00
8 changed files with 52 additions and 19 deletions

View File

@@ -24,6 +24,12 @@ Current offchain list:
- https://bscgas.info/ - https://bscgas.info/
### Polygon (Matic) Network
Current offchain list:
- https://gasstation-mainnet.matic.network/
## Installation ## Installation
`npm i gas-price-oracle` `npm i gas-price-oracle`

View File

@@ -1,6 +1,6 @@
{ {
"name": "gas-price-oracle", "name": "gas-price-oracle",
"version": "0.3.1", "version": "0.3.4",
"description": "Gas Price Oracle library for Ethereum dApps.", "description": "Gas Price Oracle library for Ethereum dApps.",
"main": "lib/index.js", "main": "lib/index.js",
"homepage": "https://github.com/peppersec/gas-price-oracle", "homepage": "https://github.com/peppersec/gas-price-oracle",

View File

@@ -3,7 +3,7 @@ import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
const bscgas: OffChainOracle = { const bscgas: OffChainOracle = {
name: 'bscgas', name: 'bscgas',
url: 'https://bscgas.info/gas', url: 'https://bscgas.info/gas',
instantPropertyName: 'imediate', instantPropertyName: 'instant',
fastPropertyName: 'fast', fastPropertyName: 'fast',
standardPropertyName: 'standard', standardPropertyName: 'standard',
lowPropertyName: 'slow', lowPropertyName: 'slow',

View File

@@ -1,13 +1,16 @@
import { NetworkConfig } from '../types'; import { NetworkConfig } from '../types';
import mainnetOracles from './mainnet'; import mainnetOracles from './mainnet';
import binanceOracles from './binance'; import binanceOracles from './binance';
import polygonOracles from './polygon';
export enum ChainId { export enum ChainId {
MAINNET = 1, MAINNET = 1,
BINANCE = 56, BINANCE = 56,
POLYGON = 137,
} }
export const networks: NetworkConfig = { export const networks: NetworkConfig = {
[ChainId.MAINNET]: mainnetOracles, [ChainId.MAINNET]: mainnetOracles,
[ChainId.BINANCE]: binanceOracles, [ChainId.BINANCE]: binanceOracles,
[ChainId.POLYGON]: polygonOracles,
}; };

View File

@@ -11,16 +11,16 @@ const ethgasstation: OffChainOracle = {
additionalDataProperty: null, additionalDataProperty: null,
}; };
const zoltu: OffChainOracle = { // const zoltu: OffChainOracle = {
name: 'zoltu', // name: 'zoltu',
url: 'https://gas-oracle.zoltu.io/', // url: 'https://gas-oracle.zoltu.io/',
instantPropertyName: 'percentile_99', // instantPropertyName: 'percentile_99',
fastPropertyName: 'percentile_90', // fastPropertyName: 'percentile_90',
standardPropertyName: 'percentile_60', // standardPropertyName: 'percentile_60',
lowPropertyName: 'percentile_30', // lowPropertyName: 'percentile_30',
denominator: 1, // denominator: 1,
additionalDataProperty: null, // additionalDataProperty: null,
}; // };
const etherchain: OffChainOracle = { const etherchain: OffChainOracle = {
name: 'etherchain', name: 'etherchain',
@@ -79,7 +79,7 @@ export const offChainOracles: OffChainOracles = {
gasNow, gasNow,
poa, poa,
etherchain, etherchain,
zoltu, // zoltu,
}; };
export const onChainOracles: OnChainOracles = { export const onChainOracles: OnChainOracles = {

23
src/config/polygon.ts Normal file
View File

@@ -0,0 +1,23 @@
import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
const maticGasStation: OffChainOracle = {
name: 'maticGasStation',
url: 'https://gasstation-mainnet.matic.network',
instantPropertyName: 'fastest',
fastPropertyName: 'fast',
standardPropertyName: 'standard',
lowPropertyName: 'safeLow',
denominator: 1,
additionalDataProperty: null,
};
export const offChainOracles: OffChainOracles = {
maticGasStation,
};
export const onChainOracles: OnChainOracles = {};
export default {
offChainOracles,
onChainOracles,
};

View File

@@ -34,9 +34,13 @@ export class GasPriceOracle {
Object.assign(this.configuration, options); Object.assign(this.configuration, options);
} }
const { offChainOracles, onChainOracles } = networks[this.configuration.chainId]; const network = networks[this.configuration.chainId];
this.offChainOracles = { ...offChainOracles };
this.onChainOracles = { ...onChainOracles }; if (network) {
const { offChainOracles, onChainOracles } = network;
this.offChainOracles = { ...offChainOracles };
this.onChainOracles = { ...onChainOracles };
}
} }
async askOracle(oracle: OffChainOracle): Promise<GasPrice> { async askOracle(oracle: OffChainOracle): Promise<GasPrice> {

View File

@@ -207,9 +207,6 @@ describe('fetchMedianGasPriceOffChain', function () {
describe('askOracle', function () { describe('askOracle', function () {
it('all oracles should answer', async function () { it('all oracles should answer', async function () {
// TODO: remove after fix POA
delete offChainOracles['poa'];
for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) { for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) {
try { try {
const gas: GasPrice = await oracle.askOracle(o); const gas: GasPrice = await oracle.askOracle(o);