Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6be967e8c9 | ||
|
|
b13a4252ab | ||
|
|
5036c65643 | ||
|
|
89a69519b2 | ||
|
|
3fce50efbb |
26
README.md
26
README.md
@@ -9,10 +9,8 @@ A library that has a collection of onchain and offchain gas price oracle URLs
|
|||||||
Current offchain list:
|
Current offchain list:
|
||||||
|
|
||||||
- https://ethgasstation.info/json/ethgasAPI.json
|
- https://ethgasstation.info/json/ethgasAPI.json
|
||||||
- https://gas-oracle.zoltu.io/
|
- https://etherchain.org/api/gasnow
|
||||||
- https://www.etherchain.org/api/gasPriceOracle
|
- https://blockscout.com/eth/mainnet/api/v1/gas-price-oracle
|
||||||
- https://gasprice.poa.network/
|
|
||||||
- https://www.gasnow.org/api/v3/gas/price
|
|
||||||
|
|
||||||
Current onchain list:
|
Current onchain list:
|
||||||
|
|
||||||
@@ -22,7 +20,13 @@ Current onchain list:
|
|||||||
|
|
||||||
Current offchain list:
|
Current offchain list:
|
||||||
|
|
||||||
- https://bscgas.info/
|
- https://ztake.org/
|
||||||
|
|
||||||
|
### xDAI Chain
|
||||||
|
|
||||||
|
Current offchain list:
|
||||||
|
|
||||||
|
- https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle
|
||||||
|
|
||||||
### Polygon (Matic) Network
|
### Polygon (Matic) Network
|
||||||
|
|
||||||
@@ -30,6 +34,18 @@ Current offchain list:
|
|||||||
|
|
||||||
- https://gasstation-mainnet.matic.network/
|
- https://gasstation-mainnet.matic.network/
|
||||||
|
|
||||||
|
### Arbitrum One
|
||||||
|
|
||||||
|
Current offchain list:
|
||||||
|
|
||||||
|
- https://ztake.org/
|
||||||
|
|
||||||
|
### Avalanche Mainnet
|
||||||
|
|
||||||
|
Current offchain list:
|
||||||
|
|
||||||
|
- https://ztake.org/
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
`npm i gas-price-oracle`
|
`npm i gas-price-oracle`
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gas-price-oracle",
|
"name": "gas-price-oracle",
|
||||||
"version": "0.3.3",
|
"version": "0.4.1",
|
||||||
"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",
|
||||||
|
|||||||
23
src/config/arbitrum.ts
Normal file
23
src/config/arbitrum.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
|
||||||
|
|
||||||
|
const ztake: OffChainOracle = {
|
||||||
|
name: 'ztake',
|
||||||
|
url: 'https://blockchains.ztake.org/api/h6WnmwNqw9CAJHzej5W4gD6LZ9n7v8EK/gasprice/arb/',
|
||||||
|
instantPropertyName: 'percentile_90',
|
||||||
|
fastPropertyName: 'percentile_80',
|
||||||
|
standardPropertyName: 'percentile_60',
|
||||||
|
lowPropertyName: 'percentile_30',
|
||||||
|
denominator: 1,
|
||||||
|
additionalDataProperty: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const offChainOracles: OffChainOracles = {
|
||||||
|
ztake,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const onChainOracles: OnChainOracles = {};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
offChainOracles,
|
||||||
|
onChainOracles,
|
||||||
|
};
|
||||||
23
src/config/avalanche.ts
Normal file
23
src/config/avalanche.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
|
||||||
|
|
||||||
|
const ztake: OffChainOracle = {
|
||||||
|
name: 'ztake',
|
||||||
|
url: 'https://blockchains.ztake.org/api/h6WnmwNqw9CAJHzej5W4gD6LZ9n7v8EK/gasprice/avax/',
|
||||||
|
instantPropertyName: 'percentile_90',
|
||||||
|
fastPropertyName: 'percentile_80',
|
||||||
|
standardPropertyName: 'percentile_60',
|
||||||
|
lowPropertyName: 'percentile_30',
|
||||||
|
denominator: 1,
|
||||||
|
additionalDataProperty: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const offChainOracles: OffChainOracles = {
|
||||||
|
ztake,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const onChainOracles: OnChainOracles = {};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
offChainOracles,
|
||||||
|
onChainOracles,
|
||||||
|
};
|
||||||
23
src/config/bsc.ts
Normal file
23
src/config/bsc.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
|
||||||
|
|
||||||
|
const ztake: OffChainOracle = {
|
||||||
|
name: 'ztake',
|
||||||
|
url: 'https://blockchains.ztake.org/api/h6WnmwNqw9CAJHzej5W4gD6LZ9n7v8EK/gasprice/bsc/',
|
||||||
|
instantPropertyName: 'percentile_90',
|
||||||
|
fastPropertyName: 'percentile_80',
|
||||||
|
standardPropertyName: 'percentile_60',
|
||||||
|
lowPropertyName: 'percentile_30',
|
||||||
|
denominator: 1,
|
||||||
|
additionalDataProperty: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const offChainOracles: OffChainOracles = {
|
||||||
|
ztake,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const onChainOracles: OnChainOracles = {};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
offChainOracles,
|
||||||
|
onChainOracles,
|
||||||
|
};
|
||||||
@@ -1,16 +1,26 @@
|
|||||||
import { NetworkConfig } from '../types';
|
import { NetworkConfig } from '../types';
|
||||||
|
|
||||||
import mainnetOracles from './mainnet';
|
import mainnetOracles from './mainnet';
|
||||||
import binanceOracles from './binance';
|
import bscOracles from './bsc';
|
||||||
|
import xdaiOracles from './xdai';
|
||||||
import polygonOracles from './polygon';
|
import polygonOracles from './polygon';
|
||||||
|
import arbitrumOracles from './arbitrum';
|
||||||
|
import avalancheOracles from './avalanche';
|
||||||
|
|
||||||
export enum ChainId {
|
export enum ChainId {
|
||||||
MAINNET = 1,
|
MAINNET = 1,
|
||||||
BINANCE = 56,
|
BSC = 56,
|
||||||
|
XDAI = 100,
|
||||||
POLYGON = 137,
|
POLYGON = 137,
|
||||||
|
ARBITRUM = 42161,
|
||||||
|
AVALANCHE = 43114,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const networks: NetworkConfig = {
|
export const NETWORKS: NetworkConfig = {
|
||||||
[ChainId.MAINNET]: mainnetOracles,
|
[ChainId.MAINNET]: mainnetOracles,
|
||||||
[ChainId.BINANCE]: binanceOracles,
|
[ChainId.BSC]: bscOracles,
|
||||||
|
[ChainId.XDAI]: xdaiOracles,
|
||||||
[ChainId.POLYGON]: polygonOracles,
|
[ChainId.POLYGON]: polygonOracles,
|
||||||
|
[ChainId.ARBITRUM]: arbitrumOracles,
|
||||||
|
[ChainId.AVALANCHE]: avalancheOracles,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,50 +11,28 @@ const ethgasstation: OffChainOracle = {
|
|||||||
additionalDataProperty: null,
|
additionalDataProperty: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const zoltu: OffChainOracle = {
|
|
||||||
name: 'zoltu',
|
|
||||||
url: 'https://gas-oracle.zoltu.io/',
|
|
||||||
instantPropertyName: 'percentile_99',
|
|
||||||
fastPropertyName: 'percentile_90',
|
|
||||||
standardPropertyName: 'percentile_60',
|
|
||||||
lowPropertyName: 'percentile_30',
|
|
||||||
denominator: 1,
|
|
||||||
additionalDataProperty: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const etherchain: OffChainOracle = {
|
const etherchain: OffChainOracle = {
|
||||||
name: 'etherchain',
|
name: 'etherchain',
|
||||||
url: 'https://www.etherchain.org/api/gasPriceOracle',
|
url: 'https://etherchain.org/api/gasnow',
|
||||||
instantPropertyName: 'fastest',
|
|
||||||
fastPropertyName: 'fast',
|
|
||||||
standardPropertyName: 'standard',
|
|
||||||
lowPropertyName: 'safeLow',
|
|
||||||
denominator: 1,
|
|
||||||
additionalDataProperty: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const poa: OffChainOracle = {
|
|
||||||
name: 'poa',
|
|
||||||
url: 'https://gasprice.poa.network/',
|
|
||||||
instantPropertyName: 'instant',
|
|
||||||
fastPropertyName: 'fast',
|
|
||||||
standardPropertyName: 'standard',
|
|
||||||
lowPropertyName: 'slow',
|
|
||||||
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',
|
instantPropertyName: 'rapid',
|
||||||
fastPropertyName: 'fast',
|
fastPropertyName: 'fast',
|
||||||
standardPropertyName: 'standard',
|
standardPropertyName: 'standard',
|
||||||
lowPropertyName: 'slow',
|
lowPropertyName: 'slow',
|
||||||
denominator: 1e9,
|
denominator: 1,
|
||||||
additionalDataProperty: 'data',
|
additionalDataProperty: 'data',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const blockscout: OffChainOracle = {
|
||||||
|
name: 'blockscout',
|
||||||
|
url: 'https://blockscout.com/eth/mainnet/api/v1/gas-price-oracle',
|
||||||
|
instantPropertyName: 'fast',
|
||||||
|
fastPropertyName: 'average',
|
||||||
|
standardPropertyName: 'slow',
|
||||||
|
lowPropertyName: 'slow',
|
||||||
|
denominator: 1,
|
||||||
|
additionalDataProperty: null,
|
||||||
|
};
|
||||||
|
|
||||||
const anyblock: OffChainOracle = {
|
const anyblock: OffChainOracle = {
|
||||||
name: 'anyblock',
|
name: 'anyblock',
|
||||||
url: 'https://api.anyblock.tools/ethereum/latest-minimum-gasprice',
|
url: 'https://api.anyblock.tools/ethereum/latest-minimum-gasprice',
|
||||||
@@ -76,10 +54,8 @@ const chainlink: OnChainOracle = {
|
|||||||
export const offChainOracles: OffChainOracles = {
|
export const offChainOracles: OffChainOracles = {
|
||||||
ethgasstation,
|
ethgasstation,
|
||||||
anyblock,
|
anyblock,
|
||||||
gasNow,
|
blockscout,
|
||||||
poa,
|
|
||||||
etherchain,
|
etherchain,
|
||||||
zoltu,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onChainOracles: OnChainOracles = {
|
export const onChainOracles: OnChainOracles = {
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
|
import { OffChainOracle, OffChainOracles, OnChainOracles } from '../types';
|
||||||
|
|
||||||
const bscgas: OffChainOracle = {
|
const blockscout: OffChainOracle = {
|
||||||
name: 'bscgas',
|
name: 'blockscout',
|
||||||
url: 'https://bscgas.info/gas',
|
url: 'https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle',
|
||||||
instantPropertyName: 'instant',
|
instantPropertyName: 'fast',
|
||||||
fastPropertyName: 'fast',
|
fastPropertyName: 'average',
|
||||||
standardPropertyName: 'standard',
|
standardPropertyName: 'slow',
|
||||||
lowPropertyName: 'slow',
|
lowPropertyName: 'slow',
|
||||||
denominator: 1,
|
denominator: 1,
|
||||||
additionalDataProperty: null,
|
additionalDataProperty: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const offChainOracles: OffChainOracles = {
|
export const offChainOracles: OffChainOracles = {
|
||||||
bscgas,
|
blockscout,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onChainOracles: OnChainOracles = {};
|
export const onChainOracles: OnChainOracles = {};
|
||||||
80
src/index.ts
80
src/index.ts
@@ -1,5 +1,8 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { ChainId, networks } from './config';
|
import BigNumber from 'bignumber.js';
|
||||||
|
|
||||||
|
import { ChainId, NETWORKS } from './config';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
Options,
|
Options,
|
||||||
@@ -10,7 +13,6 @@ import {
|
|||||||
OnChainOracles,
|
OnChainOracles,
|
||||||
OffChainOracles,
|
OffChainOracles,
|
||||||
} from './types';
|
} from './types';
|
||||||
import BigNumber from 'bignumber.js';
|
|
||||||
|
|
||||||
const defaultFastGas = 22;
|
const defaultFastGas = 22;
|
||||||
export class GasPriceOracle {
|
export class GasPriceOracle {
|
||||||
@@ -34,9 +36,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> {
|
||||||
@@ -181,19 +187,65 @@ export class GasPriceOracle {
|
|||||||
throw new Error('All oracles are down. Probably a network error.');
|
throw new Error('All oracles are down. Probably a network error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fetchGasPriceFromRpc(): Promise<number> {
|
||||||
|
const rpcUrl = this.configuration.defaultRpc;
|
||||||
|
const body = {
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 1337,
|
||||||
|
method: 'eth_gasPrice',
|
||||||
|
params: [],
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const response = await axios.post(rpcUrl!, body, { timeout: this.configuration.timeout });
|
||||||
|
if (response.status === 200) {
|
||||||
|
const { result } = response.data;
|
||||||
|
let fastGasPrice = new BigNumber(result);
|
||||||
|
if (fastGasPrice.isZero()) {
|
||||||
|
throw new Error(`Default RPC provides corrupted values`);
|
||||||
|
}
|
||||||
|
fastGasPrice = fastGasPrice.div(1e9);
|
||||||
|
return fastGasPrice.toNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Fetch gasPrice from default RPC failed..`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
throw new Error('Default RPC is down. Probably a network error.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async gasPrices(fallbackGasPrices?: GasPrice, median = true): Promise<GasPrice> {
|
async gasPrices(fallbackGasPrices?: GasPrice, median = true): Promise<GasPrice> {
|
||||||
this.lastGasPrice = this.lastGasPrice || fallbackGasPrices || this.configuration.defaultFallbackGasPrices;
|
this.lastGasPrice = this.lastGasPrice || fallbackGasPrices || this.configuration.defaultFallbackGasPrices;
|
||||||
try {
|
|
||||||
this.lastGasPrice = median
|
if (Object.keys(this.offChainOracles).length > 0) {
|
||||||
? await this.fetchMedianGasPriceOffChain()
|
try {
|
||||||
: await this.fetchGasPricesOffChain();
|
this.lastGasPrice = median
|
||||||
return this.lastGasPrice;
|
? await this.fetchMedianGasPriceOffChain()
|
||||||
} catch (e) {
|
: await this.fetchGasPricesOffChain();
|
||||||
console.log('Failed to fetch gas prices from offchain oracles. Trying onchain ones...');
|
return this.lastGasPrice;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Failed to fetch gas prices from offchain oracles. Trying onchain ones...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(this.onChainOracles).length > 0) {
|
||||||
|
try {
|
||||||
|
const fastGas = await this.fetchGasPricesOnChain();
|
||||||
|
this.lastGasPrice = {
|
||||||
|
instant: fastGas * 1.3,
|
||||||
|
fast: fastGas,
|
||||||
|
standard: fastGas * 0.85,
|
||||||
|
low: fastGas * 0.5,
|
||||||
|
};
|
||||||
|
return this.lastGasPrice;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Failed to fetch gas prices from onchain oracles. Trying from default RPC...');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fastGas = await this.fetchGasPricesOnChain();
|
const fastGas = await this.fetchGasPriceFromRpc();
|
||||||
this.lastGasPrice = {
|
this.lastGasPrice = {
|
||||||
instant: fastGas * 1.3,
|
instant: fastGas * 1.3,
|
||||||
fast: fastGas,
|
fast: fastGas,
|
||||||
@@ -202,7 +254,7 @@ export class GasPriceOracle {
|
|||||||
};
|
};
|
||||||
return this.lastGasPrice;
|
return this.lastGasPrice;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Failed to fetch gas prices from onchain oracles. Last known gas will be returned');
|
console.log('Failed to fetch gas prices from default RPC. Last known gas will be returned');
|
||||||
}
|
}
|
||||||
return this.lastGasPrice;
|
return this.lastGasPrice;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
import { GasPrice, OffChainOracle } from '../src/types';
|
|
||||||
import mockery from 'mockery';
|
|
||||||
import chai from 'chai';
|
import chai from 'chai';
|
||||||
|
import mockery from 'mockery';
|
||||||
|
|
||||||
|
import { ChainId, NETWORKS } from '../src/config';
|
||||||
import { GasPriceOracle } from '../src/index';
|
import { GasPriceOracle } from '../src/index';
|
||||||
|
|
||||||
|
import { GasPrice, OffChainOracle } from '../src/types';
|
||||||
|
|
||||||
chai.use(require('chai-as-promised'));
|
chai.use(require('chai-as-promised'));
|
||||||
chai.should();
|
chai.should();
|
||||||
|
|
||||||
let oracle = new GasPriceOracle();
|
let oracle = new GasPriceOracle();
|
||||||
let { onChainOracles, offChainOracles } = oracle;
|
let { onChainOracles, offChainOracles } = oracle;
|
||||||
|
|
||||||
@@ -119,6 +123,37 @@ describe('fetchGasPricesOnChain', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('fetchGasPriceFromRpc', function () {
|
||||||
|
it('should work', async function () {
|
||||||
|
const gas: number = await oracle.fetchGasPriceFromRpc();
|
||||||
|
gas.should.be.a('number');
|
||||||
|
gas.should.be.above(1);
|
||||||
|
gas.should.not.be.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with custom rpc', async function () {
|
||||||
|
const rpc = 'https://ethereum-rpc.trustwalletapp.com';
|
||||||
|
const oracle = new GasPriceOracle({ defaultRpc: rpc });
|
||||||
|
oracle.configuration.defaultRpc.should.be.equal(rpc);
|
||||||
|
const gas: number = await oracle.fetchGasPriceFromRpc();
|
||||||
|
|
||||||
|
gas.should.be.a('number');
|
||||||
|
|
||||||
|
gas.should.be.above(1);
|
||||||
|
gas.should.not.be.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if default rpc is down', async function () {
|
||||||
|
mockery.enable({ useCleanCache: true, warnOnUnregistered: false });
|
||||||
|
const { GasPriceOracle } = require('../src/index');
|
||||||
|
oracle = new GasPriceOracle();
|
||||||
|
await oracle
|
||||||
|
.fetchGasPriceFromRpc()
|
||||||
|
.should.be.rejectedWith('Default RPC is down. Probably a network error.');
|
||||||
|
mockery.disable();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('gasPrice', function () {
|
describe('gasPrice', function () {
|
||||||
it('should work', async function () {
|
it('should work', async function () {
|
||||||
const gas: GasPrice = await oracle.gasPrices();
|
const gas: GasPrice = await oracle.gasPrices();
|
||||||
@@ -206,25 +241,34 @@ describe('fetchMedianGasPriceOffChain', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('askOracle', function () {
|
describe('askOracle', function () {
|
||||||
it('all oracles should answer', async function () {
|
const chains = Object.keys(NETWORKS).map(id => Number(id));
|
||||||
for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) {
|
|
||||||
try {
|
|
||||||
const gas: GasPrice = await oracle.askOracle(o);
|
|
||||||
|
|
||||||
gas.instant.should.be.a('number');
|
chains.forEach(chainId => {
|
||||||
gas.fast.should.be.a('number');
|
describe(`all ${ChainId[chainId]} oracles should answer`, function () {
|
||||||
gas.standard.should.be.a('number');
|
oracle = new GasPriceOracle({ chainId });
|
||||||
gas.low.should.be.a('number');
|
({ offChainOracles } = oracle);
|
||||||
|
|
||||||
gas.instant.should.be.at.least(gas.fast); // greater than or equal to the given number.
|
for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) {
|
||||||
gas.fast.should.be.at.least(gas.standard);
|
it(`check ${o.name}`, async function () {
|
||||||
gas.standard.should.be.at.least(gas.low);
|
try {
|
||||||
gas.low.should.not.be.equal(0);
|
const gas: GasPrice = await oracle.askOracle(o);
|
||||||
} catch (e) {
|
|
||||||
console.error(`Failed to get data from ${o.name} oracle`);
|
gas.instant.should.be.a('number');
|
||||||
throw new Error(e);
|
gas.fast.should.be.a('number');
|
||||||
|
gas.standard.should.be.a('number');
|
||||||
|
gas.low.should.be.a('number');
|
||||||
|
|
||||||
|
gas.instant.should.be.at.least(gas.fast); // greater than or equal to the given number.
|
||||||
|
gas.fast.should.be.at.least(gas.standard);
|
||||||
|
gas.standard.should.be.at.least(gas.low);
|
||||||
|
gas.low.should.not.be.equal(0);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to get data from ${o.name} oracle`);
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user