Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
fix: asset-swapper ethgasstation url option (#2617)
Browse files Browse the repository at this point in the history
* fix: asset-swapper order-utils version

* fix: asset-swapper specify ethgasstation url as option

* default to real EGS

* fix: bad package.json
  • Loading branch information
dekz authored Jul 1, 2020
1 parent 22408ec commit 676698a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/0x.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@0x/asset-swapper": "^4.5.0",
"@0x/base-contract": "^6.2.2",
"@0x/contract-wrappers": "^13.7.0",
"@0x/order-utils": "^10.3.0",
"@0x/order-utils": "^10.2.5",
"@0x/subproviders": "^6.1.0",
"@0x/types": "^3.1.3",
"@0x/typescript-typings": "^5.1.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/asset-swapper/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{
"note": "Fix worst case asset amount calculations.",
"pr": 2615
},
{
"note": "Specify EthGasStation url as an optional parameter"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/asset-swapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@0x/contract-addresses": "^4.10.0",
"@0x/contract-wrappers": "^13.7.0",
"@0x/json-schemas": "^5.0.8",
"@0x/order-utils": "^10.3.0",
"@0x/order-utils": "^10.2.5",
"@0x/orderbook": "^2.2.6",
"@0x/quote-server": "^2.0.2",
"@0x/utils": "^5.5.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/asset-swapper/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './types';
import { DEFAULT_GET_MARKET_ORDERS_OPTS } from './utils/market_operation_utils/constants';

const ETH_GAS_STATION_API_URL = 'https://ethgasstation.api.0x.org/api/ethgasAPI.json';
const ETH_GAS_STATION_API_URL = 'https://ethgasstation.info/api/ethgasAPI.json';
const NULL_BYTES = '0x';
const NULL_ERC20_ASSET_DATA = '0xf47261b00000000000000000000000000000000000000000000000000000000000000000';
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
Expand Down Expand Up @@ -43,6 +43,7 @@ const DEFAULT_SWAP_QUOTER_OPTS: SwapQuoterOpts = {
},
...DEFAULT_ORDER_PRUNER_OPTS,
samplerGasLimit: 250e6,
ethGasStationUrl: ETH_GAS_STATION_API_URL,
rfqt: {
takerApiKeyWhitelist: [],
makerAssetOfferings: {},
Expand Down
5 changes: 4 additions & 1 deletion packages/asset-swapper/src/swap_quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ export class SwapQuoter {
: (r => r !== undefined && r.skipBuyRequests === true)(constants.DEFAULT_SWAP_QUOTER_OPTS.rfqt);
this._contractAddresses = options.contractAddresses || getContractAddressesForChainOrThrow(chainId);
this._devUtilsContract = new DevUtilsContract(this._contractAddresses.devUtils, provider);
this._protocolFeeUtils = new ProtocolFeeUtils(constants.PROTOCOL_FEE_UTILS_POLLING_INTERVAL_IN_MS);
this._protocolFeeUtils = new ProtocolFeeUtils(
constants.PROTOCOL_FEE_UTILS_POLLING_INTERVAL_IN_MS,
options.ethGasStationUrl,
);
this._orderStateUtils = new OrderStateUtils(this._devUtilsContract);
this._quoteRequestor = new QuoteRequestor(
rfqt ? rfqt.makerAssetOfferings || {} : {},
Expand Down
1 change: 1 addition & 0 deletions packages/asset-swapper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export interface SwapQuoterOpts extends OrderPrunerOpts {
samplerGasLimit?: number;
liquidityProviderRegistryAddress?: string;
multiBridgeAddress?: string;
ethGasStationUrl?: string;
rfqt?: {
takerApiKeyWhitelist: string[];
makerAssetOfferings: RfqtMakerAssetOfferings;
Expand Down
10 changes: 8 additions & 2 deletions packages/asset-swapper/src/utils/protocol_fee_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import { SwapQuoterError } from '../types';
export class ProtocolFeeUtils {
public gasPriceEstimation: BigNumber;
private readonly _gasPriceHeart: any;
private readonly _ethGasStationUrl: string;

constructor(gasPricePollingIntervalInMs: number, initialGasPrice: BigNumber = constants.ZERO_AMOUNT) {
constructor(
gasPricePollingIntervalInMs: number,
ethGasStationUrl: string = constants.ETH_GAS_STATION_API_URL,
initialGasPrice: BigNumber = constants.ZERO_AMOUNT,
) {
this._gasPriceHeart = heartbeats.createHeart(gasPricePollingIntervalInMs);
this.gasPriceEstimation = initialGasPrice;
this._ethGasStationUrl = ethGasStationUrl;
this._initializeHeartBeat();
}

Expand All @@ -35,7 +41,7 @@ export class ProtocolFeeUtils {
// tslint:disable-next-line: prefer-function-over-method
private async _getGasPriceFromGasStationOrThrowAsync(): Promise<BigNumber> {
try {
const res = await fetch(constants.ETH_GAS_STATION_API_URL);
const res = await fetch(this._ethGasStationUrl);
const gasInfo = await res.json();
// Eth Gas Station result is gwei * 10
// tslint:disable-next-line:custom-no-magic-numbers
Expand Down
2 changes: 1 addition & 1 deletion packages/contract-wrappers-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@0x/contracts-test-utils": "^5.3.3",
"@0x/dev-utils": "^3.2.2",
"@0x/migrations": "^6.3.0",
"@0x/order-utils": "^10.3.0",
"@0x/order-utils": "^10.2.5",
"@0x/subproviders": "^6.1.0",
"@0x/ts-doc-gen": "^0.0.22",
"@0x/tslint-config": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/orderbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@0x/connect": "^6.0.8",
"@0x/contracts-dev-utils": "^1.3.4",
"@0x/mesh-rpc-client": "^7.0.4-beta-0xv3",
"@0x/order-utils": "^10.3.0",
"@0x/order-utils": "^10.2.5",
"@0x/utils": "^5.5.0"
},
"gitHead": "4f91bfd907996b2f4dd383778b50c479c2602b56"
Expand Down

0 comments on commit 676698a

Please sign in to comment.