2021-06-08 17:25:48 +02:00
|
|
|
import { addHexPrefix } from 'ethereumjs-util';
|
2021-06-08 22:15:28 +02:00
|
|
|
|
|
|
|
const ONE_HUNDRED_THOUSAND = 100000;
|
2022-07-19 18:07:13 +02:00
|
|
|
const MIN_GAS_LIMIT_DEC = '21000';
|
|
|
|
|
|
|
|
export const MIN_GAS_LIMIT_HEX = parseInt(MIN_GAS_LIMIT_DEC, 10).toString(16);
|
2021-06-08 17:25:48 +02:00
|
|
|
|
|
|
|
export const GAS_LIMITS = {
|
|
|
|
// maximum gasLimit of a simple send
|
2021-10-19 21:31:56 +02:00
|
|
|
SIMPLE: addHexPrefix(MIN_GAS_LIMIT_HEX),
|
2021-06-08 17:25:48 +02:00
|
|
|
// a base estimate for token transfers.
|
2021-06-08 22:15:28 +02:00
|
|
|
BASE_TOKEN_ESTIMATE: addHexPrefix(ONE_HUNDRED_THOUSAND.toString(16)),
|
2021-06-08 17:25:48 +02:00
|
|
|
};
|
2021-07-08 22:23:00 +02:00
|
|
|
|
2022-05-25 22:54:05 +02:00
|
|
|
/**
|
2022-07-27 15:28:05 +02:00
|
|
|
* @typedef {object} GasEstimateTypes
|
2023-01-27 19:28:03 +01:00
|
|
|
* @property {'fee-market'} FEE_MARKET - A gas estimate for a fee market transaction generated by our gas estimation API.
|
|
|
|
* @property {'legacy'} LEGACY - A gas estimate for a legacy Transaction generated by our gas estimation API.
|
|
|
|
* @property {'eth_gasPrice'} ETH_GAS_PRICE - A gas estimate provided by the Ethereum node via eth_gasPrice.
|
2022-05-25 22:54:05 +02:00
|
|
|
* @property {'none'} NONE - No gas estimate available.
|
|
|
|
*/
|
|
|
|
|
2021-07-08 22:23:00 +02:00
|
|
|
/**
|
|
|
|
* These are already declared in @metamask/controllers but importing them from
|
|
|
|
* that module and re-exporting causes the UI bundle size to expand beyond 4MB
|
2022-05-25 22:54:05 +02:00
|
|
|
*
|
2022-11-24 20:59:07 +01:00
|
|
|
* (TODO: This comment was added before @metamask/controllers was split up —
|
|
|
|
* revisit now that @metamask/gas-fee-controller is available)
|
|
|
|
*
|
2022-05-25 22:54:05 +02:00
|
|
|
* @type {GasEstimateTypes}
|
2021-07-08 22:23:00 +02:00
|
|
|
*/
|
2023-01-27 19:28:03 +01:00
|
|
|
export enum GasEstimateTypes {
|
|
|
|
feeMarket = 'fee-market',
|
|
|
|
legacy = 'legacy',
|
|
|
|
ethGasPrice = 'eth_gasPrice',
|
|
|
|
none = 'none',
|
|
|
|
}
|
2021-07-12 18:16:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These represent gas recommendation levels presented in the UI
|
|
|
|
*/
|
2023-01-27 19:28:03 +01:00
|
|
|
export enum GasRecommendations {
|
|
|
|
low = 'low',
|
|
|
|
medium = 'medium',
|
|
|
|
high = 'high',
|
|
|
|
}
|
2021-07-14 18:45:37 +02:00
|
|
|
|
2021-11-18 20:08:29 +01:00
|
|
|
/**
|
|
|
|
* These represent types of gas estimation
|
|
|
|
*/
|
2023-01-27 19:28:03 +01:00
|
|
|
export enum PriorityLevels {
|
|
|
|
tenPercentIncreased = 'tenPercentIncreased',
|
|
|
|
low = 'low',
|
|
|
|
medium = 'medium',
|
|
|
|
high = 'high',
|
|
|
|
custom = 'custom',
|
|
|
|
dAppSuggested = 'dappSuggested',
|
2023-06-08 12:26:18 +02:00
|
|
|
dappSuggestedHigh = 'dappSuggestedHigh',
|
2023-01-27 19:28:03 +01:00
|
|
|
}
|
2021-11-18 20:08:29 +01:00
|
|
|
|
2021-11-06 01:59:23 +01:00
|
|
|
/**
|
|
|
|
* Represents the user customizing their gas preference
|
|
|
|
*/
|
|
|
|
export const CUSTOM_GAS_ESTIMATE = 'custom';
|
|
|
|
|
2021-07-14 18:45:37 +02:00
|
|
|
/**
|
|
|
|
* These represent the different edit modes presented in the UI
|
|
|
|
*/
|
2023-01-27 19:28:03 +01:00
|
|
|
export enum EditGasModes {
|
|
|
|
speedUp = 'speed-up',
|
|
|
|
cancel = 'cancel',
|
|
|
|
modifyInPlace = 'modify-in-place',
|
|
|
|
swaps = 'swaps',
|
|
|
|
}
|
2022-01-07 20:18:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents levels for `networkCongestion` (calculated along with gas fee
|
|
|
|
* estimates; represents a number between 0 and 1) that we use to render the
|
|
|
|
* network status slider on the send transaction screen and inform users when
|
|
|
|
* gas fees are high
|
|
|
|
*/
|
2023-01-27 19:28:03 +01:00
|
|
|
export enum NetworkCongestionThresholds {
|
|
|
|
notBusy = 0,
|
|
|
|
stable = 0.33,
|
|
|
|
busy = 0.66,
|
|
|
|
}
|
2023-02-01 18:53:21 +01:00
|
|
|
|
|
|
|
export interface TxGasFees {
|
|
|
|
/** Maxmimum number of units of gas to use for this transaction. */
|
|
|
|
gasLimit: string;
|
|
|
|
/** Price per gas for legacy txs */
|
|
|
|
gasPrice: string;
|
|
|
|
/**
|
|
|
|
* Maximum amount per gas to pay for the transaction, including the priority
|
|
|
|
* fee.
|
|
|
|
*/
|
|
|
|
maxFeePerGas: string;
|
|
|
|
/** Maximum amount per gas to give to validator as incentive. */
|
|
|
|
maxPriorityFeePerGas: string;
|
|
|
|
/** Which estimate level was used */
|
|
|
|
estimateUsed: string;
|
|
|
|
/** Which estimate level that the API suggested. */
|
|
|
|
estimateSuggested: string;
|
|
|
|
/** The default estimate for gas. */
|
|
|
|
defaultGasEstimates: string;
|
|
|
|
/** same as gasLimit? */
|
|
|
|
gas: string;
|
|
|
|
/** Original estimate for gas. */
|
|
|
|
originalGasEstimate: string;
|
|
|
|
/** The gas limit supplied by user. */
|
|
|
|
userEditedGasLimit: string;
|
|
|
|
/** Estimate level user selected. */
|
|
|
|
userFeeLevel: string;
|
|
|
|
}
|