MaximumGasPrice contract

This commit is contained in:
Michael Zhu 2020-03-03 15:25:35 -08:00
parent 15f75a08d5
commit 2b1545145b
7 changed files with 61 additions and 1 deletions

View File

@ -0,0 +1,52 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;
contract MaximumGasPrice {
// 20 Gwei
uint256 constant private DEFAULT_MAX_GAS_PRICE = 20 * (10 ** 9);
/// @dev Checks that the current transaction's gas price is less than
/// the default maximum value of 20 Gwei.
function checkGasPrice()
external
view
{
require(
tx.gasprice <= DEFAULT_MAX_GAS_PRICE,
"MaximumGasPrice/GAS_PRICE_EXCEEDS_20_GWEI"
);
}
/// @dev Checks that the current transaction's gas price is less than
/// the specified maximum value.
/// @param data Encodes the maximum gas price.
function checkGasPrice(bytes calldata data)
external
view
{
(uint256 maxGasPrice) = abi.decode(data, (uint256));
require(
tx.gasprice <= maxGasPrice,
"MaximumGasPrice/GAS_PRICE_EXCEEDS_MAXIMUM"
);
}
}

View File

@ -38,7 +38,7 @@
"docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"abis": "./test/generated-artifacts/@(LibAssetDataTransfer|LibAssetDataTransferRichErrors|LibWethUtilsRichErrors|MixinWethUtils).json",
"abis": "./test/generated-artifacts/@(LibAssetDataTransfer|LibAssetDataTransferRichErrors|LibWethUtilsRichErrors|MaximumGasPrice|MixinWethUtils).json",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
},
"repository": {

View File

@ -8,9 +8,11 @@ import { ContractArtifact } from 'ethereum-types';
import * as LibAssetDataTransfer from '../generated-artifacts/LibAssetDataTransfer.json';
import * as LibAssetDataTransferRichErrors from '../generated-artifacts/LibAssetDataTransferRichErrors.json';
import * as LibWethUtilsRichErrors from '../generated-artifacts/LibWethUtilsRichErrors.json';
import * as MaximumGasPrice from '../generated-artifacts/MaximumGasPrice.json';
import * as MixinWethUtils from '../generated-artifacts/MixinWethUtils.json';
export const artifacts = {
LibAssetDataTransfer: LibAssetDataTransfer as ContractArtifact,
MaximumGasPrice: MaximumGasPrice as ContractArtifact,
MixinWethUtils: MixinWethUtils as ContractArtifact,
LibAssetDataTransferRichErrors: LibAssetDataTransferRichErrors as ContractArtifact,
LibWethUtilsRichErrors: LibWethUtilsRichErrors as ContractArtifact,

View File

@ -6,4 +6,5 @@
export * from '../generated-wrappers/lib_asset_data_transfer';
export * from '../generated-wrappers/lib_asset_data_transfer_rich_errors';
export * from '../generated-wrappers/lib_weth_utils_rich_errors';
export * from '../generated-wrappers/maximum_gas_price';
export * from '../generated-wrappers/mixin_weth_utils';

View File

@ -8,9 +8,11 @@ import { ContractArtifact } from 'ethereum-types';
import * as LibAssetDataTransfer from '../test/generated-artifacts/LibAssetDataTransfer.json';
import * as LibAssetDataTransferRichErrors from '../test/generated-artifacts/LibAssetDataTransferRichErrors.json';
import * as LibWethUtilsRichErrors from '../test/generated-artifacts/LibWethUtilsRichErrors.json';
import * as MaximumGasPrice from '../test/generated-artifacts/MaximumGasPrice.json';
import * as MixinWethUtils from '../test/generated-artifacts/MixinWethUtils.json';
export const artifacts = {
LibAssetDataTransfer: LibAssetDataTransfer as ContractArtifact,
MaximumGasPrice: MaximumGasPrice as ContractArtifact,
MixinWethUtils: MixinWethUtils as ContractArtifact,
LibAssetDataTransferRichErrors: LibAssetDataTransferRichErrors as ContractArtifact,
LibWethUtilsRichErrors: LibWethUtilsRichErrors as ContractArtifact,

View File

@ -6,4 +6,5 @@
export * from '../test/generated-wrappers/lib_asset_data_transfer';
export * from '../test/generated-wrappers/lib_asset_data_transfer_rich_errors';
export * from '../test/generated-wrappers/lib_weth_utils_rich_errors';
export * from '../test/generated-wrappers/maximum_gas_price';
export * from '../test/generated-wrappers/mixin_weth_utils';

View File

@ -6,10 +6,12 @@
"generated-artifacts/LibAssetDataTransfer.json",
"generated-artifacts/LibAssetDataTransferRichErrors.json",
"generated-artifacts/LibWethUtilsRichErrors.json",
"generated-artifacts/MaximumGasPrice.json",
"generated-artifacts/MixinWethUtils.json",
"test/generated-artifacts/LibAssetDataTransfer.json",
"test/generated-artifacts/LibAssetDataTransferRichErrors.json",
"test/generated-artifacts/LibWethUtilsRichErrors.json",
"test/generated-artifacts/MaximumGasPrice.json",
"test/generated-artifacts/MixinWethUtils.json"
],
"exclude": ["./deploy/solc/solc_bin"]