Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
isNil MAX gas gwei cached gas price
Browse files Browse the repository at this point in the history
  • Loading branch information
dekz committed May 20, 2020
1 parent 1608a50 commit 456a8be
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 88 deletions.
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# [1.4.0](https://github.com/0xProject/0x-api/compare/v1.3.0...v1.4.0) (2020-05-18)


### Bug Fixes

* re-allow unknown tokens to be queried in the swap/quote endpoint ([#226](https://github.com/0xProject/0x-api/issues/226)) ([1379e63](https://github.com/0xProject/0x-api/commit/1379e638693e030ab343adfa9893a6f42081ea01))

- re-allow unknown tokens to be queried in the swap/quote endpoint ([#226](https://github.com/0xProject/0x-api/issues/226)) ([1379e63](https://github.com/0xProject/0x-api/commit/1379e638693e030ab343adfa9893a6f42081ea01))

### Features

* add transaction watcher service ([#215](https://github.com/0xProject/0x-api/issues/215)) ([7bbb9c6](https://github.com/0xProject/0x-api/commit/7bbb9c6f0992ae2a9a9ae9f2fe6d59f99a8e121a))
* Improve RFQ-T logging ([#219](https://github.com/0xProject/0x-api/issues/219)) ([22b6b0c](https://github.com/0xProject/0x-api/commit/22b6b0c1fb15513bc1225ca5f3a8918639fe8f32))
- add transaction watcher service ([#215](https://github.com/0xProject/0x-api/issues/215)) ([7bbb9c6](https://github.com/0xProject/0x-api/commit/7bbb9c6f0992ae2a9a9ae9f2fe6d59f99a8e121a))
- Improve RFQ-T logging ([#219](https://github.com/0xProject/0x-api/issues/219)) ([22b6b0c](https://github.com/0xProject/0x-api/commit/22b6b0c1fb15513bc1225ca5f3a8918639fe8f32))

# [1.3.0](https://github.com/0xProject/0x-api/compare/v1.2.0...v1.3.0) (2020-05-11)

Expand Down
16 changes: 10 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ export const RFQT_SKIP_BUY_REQUESTS: boolean = _.isEmpty(process.env.RFQT_SKIP_B
: assertEnvVarType('RFQT_SKIP_BUY_REQUESTS', process.env.RFQT_SKIP_BUY_REQUESTS, EnvVarType.Boolean);

// Whitelisted 0x API keys that can use the meta-txn /submit endpoint
export const WHITELISTED_API_KEYS_META_TXN_SUBMIT: string[] =
process.env.WHITELISTED_API_KEYS_META_TXN_SUBMIT === undefined
export const META_TXN_SUBMIT_WHITELISTED_API_KEYS: string[] =
process.env.META_TXN_SUBMIT_WHITELISTED_API_KEYS === undefined
? []
: assertEnvVarType(
'WHITELISTED_API_KEYS_META_TXN_SUBMIT',
process.env.WHITELISTED_API_KEYS_META_TXN_SUBMIT,
'META_TXN_SUBMIT_WHITELISTED_API_KEYS',
process.env.META_TXN_SUBMIT_WHITELISTED_API_KEYS,
EnvVarType.APIKeys,
);

Expand All @@ -196,9 +196,13 @@ export const META_TXN_RELAY_EXPECTED_MINED_SEC: number = _.isEmpty(process.env.M
);
// Should TransactionWatcherSignerService sign transactions
// tslint:disable-next-line:boolean-naming
export const ENABLE_TRANSACTION_SIGNING: boolean = _.isEmpty(process.env.ENABLE_TRANSACTION_SIGNING)
export const META_TXN_SIGNING_ENABLED: boolean = _.isEmpty(process.env.META_TXN_SIGNING_ENABLED)
? true
: assertEnvVarType('ENABLE_TRANSACTION_SIGNING', process.env.ENABLE_TRANSACTION_SIGNING, EnvVarType.Boolean);
: assertEnvVarType('META_TXN_SIGNING_ENABLED', process.env.META_TXN_SIGNING_ENABLED, EnvVarType.Boolean);
// The maximum gas price (in gwei) the service will allow
export const META_TXN_MAX_GAS_PRICE_GWEI: BigNumber = _.isEmpty(process.env.META_TXN_MAX_GAS_PRICE_GWEI)
? new BigNumber(50)
: assertEnvVarType('META_TXN_MAX_GAS_PRICE_GWEI', process.env.META_TXN_MAX_GAS_PRICE_GWEI, EnvVarType.UnitAmount);

// Whether or not prometheus metrics should be enabled.
// tslint:disable-next-line:boolean-naming
Expand Down
10 changes: 5 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ export const META_TRANSACTION_DOCS_URL = 'https://0x.org/docs/api#meta_transacti
export const ETH_GAS_STATION_API_BASE_URL = 'https://ethgasstation.info';
export const UNSTICKING_TRANSACTION_GAS_MULTIPLIER = 1.1;
export const ETH_TRANSFER_GAS_LIMIT = 21000;
export const STUCK_TX_POLLING_INTERVAL_MS = 5 * 1000;
export const TX_HASH_RESPONSE_WAIT_TIME_MS = 100 * 1000;
export const STUCK_TX_POLLING_INTERVAL_MS = ONE_SECOND_MS * 5;
export const TX_HASH_RESPONSE_WAIT_TIME_MS = ONE_SECOND_MS * 100;
export const SUBMITTED_TX_DB_POLLING_INTERVAL_MS = 200;
export const PUBLIC_ADDRESS_FOR_ETH_CALLS = '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B';

// TransactionWatcher
// The expected time of a transaction to be mined according to ETHGasStation
// "Fast" gas price estimations multiplied by a safety margin.
export const DEFAULT_EXPECTED_MINED_SEC = 120 * 1.5;
export const TX_WATCHER_POLLING_INTERVAL_MS = 5 * 1000;
export const TX_WATCHER_POLLING_INTERVAL_MS = ONE_SECOND_MS * 5;
export const NUMBER_OF_BLOCKS_UNTIL_CONFIRMED = 3;
export const TX_WATCHER_UPDATE_METRICS_INTERVAL_MS = 30 * 1000;
export const TX_WATCHER_UPDATE_METRICS_INTERVAL_MS = ONE_SECOND_MS * 30;
export const ETH_DECIMALS = 18;
export const GWEI_DECIMALS = 9;
export const SIGNER_ETH_BALANCE_CONSIDERED_CRITICAL = 0.1;
export const META_TXN_MIN_SIGNER_ETH_BALANCE = 0.1;
export const SIGNER_STATUS_DB_KEY = 'signer_status';
export const SIGNER_KILL_SWITCH_KEY = 'signer_kill_switch_on';
2 changes: 1 addition & 1 deletion src/handlers/meta_transaction_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SwapQuoterError } from '@0x/asset-swapper';
import { BigNumber } from '@0x/utils';
import * as express from 'express';
import * as HttpStatus from 'http-status-codes';
import * as _ from 'lodash';
import * as isValidUUID from 'uuid-validate';

import { CHAIN_ID } from '../config';
Expand Down Expand Up @@ -236,6 +235,7 @@ export class MetaTransactionHandlers {
res.status(HttpStatus.OK).send({
ethereumTransactionHash,
signedEthereumTransaction,
zeroExTransactionHash,
});
} else {
const ethereumTxn = await this._metaTransactionService.generatePartialExecuteTransactionEthereumTransactionAsync(
Expand Down
16 changes: 11 additions & 5 deletions src/services/meta_transaction_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import {
ASSET_SWAPPER_MARKET_ORDERS_OPTS,
CHAIN_ID,
LIQUIDITY_POOL_REGISTRY_ADDRESS,
META_TXN_MAX_GAS_PRICE_GWEI,
META_TXN_RELAY_EXPECTED_MINED_SEC,
WHITELISTED_API_KEYS_META_TXN_SUBMIT,
META_TXN_SUBMIT_WHITELISTED_API_KEYS,
} from '../config';
import {
GWEI_DECIMALS,
ONE_GWEI,
ONE_SECOND_MS,
PUBLIC_ADDRESS_FOR_ETH_CALLS,
Expand Down Expand Up @@ -53,7 +55,7 @@ export class MetaTransactionService {
private readonly _kvRepository: Repository<KeyValueEntity>;

public static isEligibleForFreeMetaTxn(apiKey: string): boolean {
return WHITELISTED_API_KEYS_META_TXN_SUBMIT.includes(apiKey);
return META_TXN_SUBMIT_WHITELISTED_API_KEYS.includes(apiKey);
}
private static _calculateProtocolFee(numOrders: number, gasPrice: BigNumber): BigNumber {
return new BigNumber(150000).times(gasPrice).times(numOrders);
Expand Down Expand Up @@ -221,8 +223,11 @@ export class MetaTransactionService {
const gasPrice = zeroExTransaction.gasPrice;
const currentFastGasPrice = await ethGasStationUtils.getGasPriceOrThrowAsync();
// Make sure gasPrice is not 3X the current fast EthGasStation gas price
// tslint:disable-next-line:custom-no-magic-numbers
if (currentFastGasPrice.lt(gasPrice) && gasPrice.minus(currentFastGasPrice).gt(currentFastGasPrice.times(3))) {
if (
Web3Wrapper.toUnitAmount(gasPrice, GWEI_DECIMALS).gte(META_TXN_MAX_GAS_PRICE_GWEI) ||
// tslint:disable-next-line:custom-no-magic-numbers
(currentFastGasPrice.lt(gasPrice) && gasPrice.minus(currentFastGasPrice).gte(currentFastGasPrice.times(3)))
) {
throw new Error('Gas price too high');
}

Expand Down Expand Up @@ -314,6 +319,7 @@ export class MetaTransactionService {
return {
ethereumTransactionHash,
signedEthereumTransaction,
zeroExTransactionHash,
};
}
public async isSignerLiveAsync(): Promise<boolean> {
Expand Down Expand Up @@ -353,7 +359,7 @@ export class MetaTransactionService {
return utils.runWithTimeout(async () => {
while (true) {
const tx = await this._transactionEntityRepository.findOne(txEntity.refHash);
if (tx !== undefined && tx.txHash !== undefined && tx.signedTx !== undefined) {
if (!utils.isNil(tx) && !utils.isNil(tx.txHash) && !utils.isNil(tx.signedTx)) {
return { ethereumTransactionHash: tx.txHash, signedEthereumTransaction: tx.signedTx };
}

Expand Down
Loading

0 comments on commit 456a8be

Please sign in to comment.