Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76f8cb036d | ||
|
|
64c5a68639 | ||
|
|
1dbd778166 | ||
|
|
47089200af | ||
|
|
4cf2521880 | ||
|
|
cd5bca4963 | ||
|
|
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.3",
|
||||||
"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",
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
"typescript": "^4.0.3"
|
"typescript": "^4.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.21.2",
|
||||||
"bignumber.js": "^9.0.0"
|
"bignumber.js": "^9.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
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 = {};
|
||||||
64
src/index.ts
64
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,13 +13,12 @@ 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 {
|
||||||
lastGasPrice: GasPrice;
|
lastGasPrice: GasPrice;
|
||||||
offChainOracles: OffChainOracles;
|
offChainOracles: OffChainOracles = {};
|
||||||
onChainOracles: OnChainOracles;
|
onChainOracles: OnChainOracles = {};
|
||||||
configuration: Config = {
|
configuration: Config = {
|
||||||
chainId: ChainId.MAINNET,
|
chainId: ChainId.MAINNET,
|
||||||
defaultRpc: 'https://api.mycryptoapi.com/eth',
|
defaultRpc: 'https://api.mycryptoapi.com/eth',
|
||||||
@@ -34,10 +36,14 @@ 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];
|
||||||
|
|
||||||
|
if (network) {
|
||||||
|
const { offChainOracles, onChainOracles } = network;
|
||||||
this.offChainOracles = { ...offChainOracles };
|
this.offChainOracles = { ...offChainOracles };
|
||||||
this.onChainOracles = { ...onChainOracles };
|
this.onChainOracles = { ...onChainOracles };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async askOracle(oracle: OffChainOracle): Promise<GasPrice> {
|
async askOracle(oracle: OffChainOracle): Promise<GasPrice> {
|
||||||
const {
|
const {
|
||||||
@@ -181,8 +187,38 @@ 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;
|
||||||
|
|
||||||
|
if (Object.keys(this.offChainOracles).length > 0) {
|
||||||
try {
|
try {
|
||||||
this.lastGasPrice = median
|
this.lastGasPrice = median
|
||||||
? await this.fetchMedianGasPriceOffChain()
|
? await this.fetchMedianGasPriceOffChain()
|
||||||
@@ -191,7 +227,9 @@ export class GasPriceOracle {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Failed to fetch gas prices from offchain oracles. Trying onchain ones...');
|
console.log('Failed to fetch gas prices from offchain oracles. Trying onchain ones...');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(this.onChainOracles).length > 0) {
|
||||||
try {
|
try {
|
||||||
const fastGas = await this.fetchGasPricesOnChain();
|
const fastGas = await this.fetchGasPricesOnChain();
|
||||||
this.lastGasPrice = {
|
this.lastGasPrice = {
|
||||||
@@ -202,7 +240,21 @@ 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 onchain oracles. Trying from default RPC...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const fastGas = await this.fetchGasPriceFromRpc();
|
||||||
|
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 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,8 +241,15 @@ 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));
|
||||||
|
|
||||||
|
chains.forEach(chainId => {
|
||||||
|
describe(`all ${ChainId[chainId]} oracles should answer`, function () {
|
||||||
|
oracle = new GasPriceOracle({ chainId });
|
||||||
|
({ offChainOracles } = oracle);
|
||||||
|
|
||||||
for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) {
|
for (const o of Object.values(offChainOracles) as Array<OffChainOracle>) {
|
||||||
|
it(`check ${o.name}`, async function () {
|
||||||
try {
|
try {
|
||||||
const gas: GasPrice = await oracle.askOracle(o);
|
const gas: GasPrice = await oracle.askOracle(o);
|
||||||
|
|
||||||
@@ -224,8 +266,10 @@ describe('askOracle', function () {
|
|||||||
console.error(`Failed to get data from ${o.name} oracle`);
|
console.error(`Failed to get data from ${o.name} oracle`);
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
after('after', function () {
|
after('after', function () {
|
||||||
|
|||||||
50
yarn.lock
50
yarn.lock
@@ -261,12 +261,12 @@ astral-regex@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
|
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
|
||||||
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==
|
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==
|
||||||
|
|
||||||
axios@^0.19.2:
|
axios@^0.21.2:
|
||||||
version "0.19.2"
|
version "0.21.2"
|
||||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
|
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.2.tgz#21297d5084b2aeeb422f5d38e7be4fbb82239017"
|
||||||
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
|
integrity sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==
|
||||||
dependencies:
|
dependencies:
|
||||||
follow-redirects "1.5.10"
|
follow-redirects "^1.14.0"
|
||||||
|
|
||||||
balanced-match@^1.0.0:
|
balanced-match@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
@@ -428,13 +428,6 @@ debug@3.2.6:
|
|||||||
dependencies:
|
dependencies:
|
||||||
ms "^2.1.1"
|
ms "^2.1.1"
|
||||||
|
|
||||||
debug@=3.1.0:
|
|
||||||
version "3.1.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
|
|
||||||
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
|
|
||||||
dependencies:
|
|
||||||
ms "2.0.0"
|
|
||||||
|
|
||||||
debug@^4.0.1, debug@^4.1.1:
|
debug@^4.0.1, debug@^4.1.1:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
|
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
|
||||||
@@ -757,12 +750,10 @@ flatted@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
|
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
|
||||||
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
|
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==
|
||||||
|
|
||||||
follow-redirects@1.5.10:
|
follow-redirects@^1.14.0:
|
||||||
version "1.5.10"
|
version "1.14.4"
|
||||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
|
||||||
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
|
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==
|
||||||
dependencies:
|
|
||||||
debug "=3.1.0"
|
|
||||||
|
|
||||||
fs.realpath@^1.0.0:
|
fs.realpath@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
@@ -800,9 +791,9 @@ get-stdin@^6.0.0:
|
|||||||
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
|
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
|
||||||
|
|
||||||
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0:
|
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0:
|
||||||
version "5.1.1"
|
version "5.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
|
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
|
||||||
integrity sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==
|
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
|
||||||
dependencies:
|
dependencies:
|
||||||
is-glob "^4.0.1"
|
is-glob "^4.0.1"
|
||||||
|
|
||||||
@@ -1033,9 +1024,9 @@ locate-path@^3.0.0:
|
|||||||
path-exists "^3.0.0"
|
path-exists "^3.0.0"
|
||||||
|
|
||||||
lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
|
lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
|
||||||
version "4.17.20"
|
version "4.17.21"
|
||||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||||
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
|
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||||
|
|
||||||
log-symbols@3.0.0:
|
log-symbols@3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
@@ -1116,11 +1107,6 @@ mockery@^2.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/mockery/-/mockery-2.1.0.tgz#5b0aef1ff564f0f8139445e165536c7909713470"
|
resolved "https://registry.yarnpkg.com/mockery/-/mockery-2.1.0.tgz#5b0aef1ff564f0f8139445e165536c7909713470"
|
||||||
integrity sha512-9VkOmxKlWXoDO/h1jDZaS4lH33aWfRiJiNT/tKj+8OGzrcFDLo8d0syGdbsc3Bc4GvRXPb+NMMvojotmuGJTvA==
|
integrity sha512-9VkOmxKlWXoDO/h1jDZaS4lH33aWfRiJiNT/tKj+8OGzrcFDLo8d0syGdbsc3Bc4GvRXPb+NMMvojotmuGJTvA==
|
||||||
|
|
||||||
ms@2.0.0:
|
|
||||||
version "2.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
|
||||||
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
|
|
||||||
|
|
||||||
ms@2.1.1:
|
ms@2.1.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
|
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
|
||||||
@@ -1609,9 +1595,9 @@ write@1.0.3:
|
|||||||
mkdirp "^0.5.1"
|
mkdirp "^0.5.1"
|
||||||
|
|
||||||
y18n@^4.0.0:
|
y18n@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"
|
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4"
|
||||||
integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==
|
integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==
|
||||||
|
|
||||||
yargs-parser@13.1.2, yargs-parser@^13.1.2:
|
yargs-parser@13.1.2, yargs-parser@^13.1.2:
|
||||||
version "13.1.2"
|
version "13.1.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user