gasnow gas price orace

This commit is contained in:
Alexey 2020-10-19 16:08:19 +03:00
parent 092d863bd2
commit a2a4e67845
4 changed files with 21 additions and 2 deletions

@ -8,10 +8,11 @@ Current offchain list:
- https://gas-oracle.zoltu.io/ - https://gas-oracle.zoltu.io/
- https://www.etherchain.org/api/gasPriceOracle - https://www.etherchain.org/api/gasPriceOracle
- https://gasprice.poa.network/ - https://gasprice.poa.network/
- https://www.gasnow.org/api/v3/gas/price
Current onchain list: Current onchain list:
- [chainlink](https://etherscan.io/address/0xA417221ef64b1549575C977764E651c9FAB50141) - [chainlink](https://etherscan.io/address/0x169e633a2d1e6c10dd91238ba11c4a708dfef37c#readContract)
## Installation ## Installation

@ -8,6 +8,7 @@ const ethgasstation: OffChainOracle = {
standardPropertyName: 'average', standardPropertyName: 'average',
lowPropertyName: 'safeLow', lowPropertyName: 'safeLow',
denominator: 10, denominator: 10,
additionalDataProperty: null,
}; };
const zoltu: OffChainOracle = { const zoltu: OffChainOracle = {
@ -18,6 +19,7 @@ const zoltu: OffChainOracle = {
standardPropertyName: 'percentile_60', standardPropertyName: 'percentile_60',
lowPropertyName: 'percentile_30', lowPropertyName: 'percentile_30',
denominator: 1, denominator: 1,
additionalDataProperty: null,
}; };
const etherchain: OffChainOracle = { const etherchain: OffChainOracle = {
@ -28,6 +30,7 @@ const etherchain: OffChainOracle = {
standardPropertyName: 'standard', standardPropertyName: 'standard',
lowPropertyName: 'safeLow', lowPropertyName: 'safeLow',
denominator: 1, denominator: 1,
additionalDataProperty: null,
}; };
const poa: OffChainOracle = { const poa: OffChainOracle = {
@ -38,6 +41,18 @@ const poa: OffChainOracle = {
standardPropertyName: 'standard', standardPropertyName: 'standard',
lowPropertyName: 'slow', lowPropertyName: 'slow',
denominator: 1, denominator: 1,
additionalDataProperty: null,
};
const gasNow: OffChainOracle = {
name: 'gasNow',
url: 'https://www.gasnow.org/api/v3/gas/price?utm_source=gas-price-oracle',
instantPropertyName: 'rapid',
fastPropertyName: 'fast',
standardPropertyName: 'standard',
lowPropertyName: 'slow',
denominator: 1e9,
additionalDataProperty: 'data',
}; };
const chainlink: OnChainOracle = { const chainlink: OnChainOracle = {
@ -49,6 +64,7 @@ const chainlink: OnChainOracle = {
export const offChainOracles: { [key: string]: OffChainOracle } = { export const offChainOracles: { [key: string]: OffChainOracle } = {
ethgasstation, ethgasstation,
gasNow,
poa, poa,
etherchain, etherchain,
zoltu, zoltu,

@ -27,10 +27,11 @@ export class GasPriceOracle {
standardPropertyName, standardPropertyName,
lowPropertyName, lowPropertyName,
denominator, denominator,
additionalDataProperty,
} = oracle; } = oracle;
const response = await axios.get(url, { timeout: this.configuration.timeout }); const response = await axios.get(url, { timeout: this.configuration.timeout });
if (response.status === 200) { if (response.status === 200) {
const gas = response.data; const gas = additionalDataProperty ? response.data[additionalDataProperty] : response.data;
if (Number(gas[fastPropertyName]) === 0) { if (Number(gas[fastPropertyName]) === 0) {
throw new Error(`${name} oracle provides corrupted values`); throw new Error(`${name} oracle provides corrupted values`);
} }

@ -6,6 +6,7 @@ export type OffChainOracle = {
standardPropertyName: string; standardPropertyName: string;
lowPropertyName: string; lowPropertyName: string;
denominator: number; denominator: number;
additionalDataProperty: string | null;
}; };
export type OnChainOracle = { export type OnChainOracle = {